Skip to main content

systemprompt_cloud/
lib.rs

1//! # systemprompt-cloud
2//!
3//! Cloud API client, credentials management, OAuth login flow, and
4//! tenant orchestration for systemprompt.io Cloud deployments. This
5//! crate is the bridge between the local CLI/runtime and the
6//! systemprompt.io control plane.
7//!
8//! ## Public surface
9//!
10//! - [`CloudApiClient`] — bearer-token-authenticated REST client.
11//! - [`CloudCredentials`] / [`CredentialsBootstrap`] — on-disk and process-wide
12//!   cloud credentials.
13//! - [`StoredTenant`] / [`TenantStore`] — persistent tenants index.
14//! - [`CliSession`] / [`SessionStore`] — multi-tenant CLI sessions.
15//! - [`run_oauth_flow`] — browser-driven OAuth login flow.
16//! - [`clear_cloud_state`] — logout cleanup of credentials, tenants, and
17//!   tenant-scoped sessions.
18//! - [`CloudPaths`] — XDG-aware discovery of credentials, sessions, tenants,
19//!   and project files.
20//! - [`profile_authoring`] — pure [`Profile`](systemprompt_manifest::Profile)
21//!   construction for local and cloud deployment targets.
22//! - [`deploy`] — Dockerfile rendering ([`DockerfileBuilder`]) and validation
23//!   for the deployment image.
24//! - [`secrets_env`] — deploy-time mapping of `secrets.json` to environment
25//!   variables, including the signing-key PEM transport encoding.
26//! - [`DockerCli`] — Docker invocations behind a [`CommandRunner`] seam.
27//!
28//! ## Errors
29//!
30//! All public APIs return [`CloudResult<T>`] (i.e.
31//! `Result<T, CloudError>`). [`CloudError`] composes `reqwest`,
32//! `std::io`, `serde_json`, and the more specific
33//! [`CredentialsBootstrapError`] via `#[from]` so callers can use `?`
34//! transparently.
35//!
36//! ## Feature flags
37//!
38//! This crate has no Cargo features — every dependency is required at
39//! compile time. The `[package.metadata.docs.rs]` section in
40//! `Cargo.toml` enables `all-features = true` for parity with the
41//! rest of the workspace.
42//!
43//! Copyright (c) systemprompt.io — Business Source License 1.1.
44//! See <https://systemprompt.io> for licensing details.
45
46pub mod api_client;
47pub mod auth;
48mod callback_listener;
49pub mod cli_session;
50pub mod constants;
51pub mod credentials;
52pub mod credentials_bootstrap;
53pub mod deploy;
54pub mod docker;
55pub mod error;
56pub mod logout;
57pub mod oauth;
58pub mod paths;
59mod private_dir;
60pub mod profile_authoring;
61pub mod secrets_env;
62pub mod tenants;
63pub mod trusted_proxies;
64
65pub use api_client::{
66    CloudApiClient, CloudStatusResponse, CloudTenant, CloudTenantInfo, CloudTenantSecrets,
67    CloudTenantStatusResponse, CloudUserInfo, DeployResponse, RegistryToken, SubscriptionStatus,
68    UserMeResponse,
69};
70pub use cli_session::{
71    CliSession, LOCAL_SESSION_KEY, SessionBinding, SessionIdentity, SessionKey, SessionStore,
72};
73pub use constants::api::{PRODUCTION_URL, SANDBOX_URL};
74pub use credentials::CloudCredentials;
75pub use credentials_bootstrap::{CredentialsBootstrap, CredentialsBootstrapError};
76pub use deploy::DockerfileBuilder;
77pub use docker::{CommandRunner, CommandSpec, DockerCli, SystemCommandRunner};
78pub use error::{CloudError, CloudResult, DeploySource};
79pub use logout::{ClearedCloudState, clear_cloud_state};
80pub use oauth::{OAuthTemplates, run_oauth_flow};
81pub use paths::{
82    CloudPath, CloudPaths, DiscoveredProject, ProfilePath, ProjectContext, ProjectPath,
83    UnifiedContext, expand_home, get_cloud_paths, resolve_path,
84};
85pub use tenants::{StoredTenant, TenantStore, TenantType};
86
87use clap::ValueEnum;
88
89#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
90pub enum Environment {
91    #[default]
92    Production,
93    Sandbox,
94}
95
96impl Environment {
97    #[must_use]
98    pub const fn api_url(&self) -> &'static str {
99        match self {
100            Self::Production => PRODUCTION_URL,
101            Self::Sandbox => SANDBOX_URL,
102        }
103    }
104}
105
106#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
107pub enum OAuthProvider {
108    Github,
109    Google,
110}
111
112impl OAuthProvider {
113    #[must_use]
114    pub const fn as_str(&self) -> &'static str {
115        match self {
116            Self::Github => "github",
117            Self::Google => "google",
118        }
119    }
120
121    #[must_use]
122    pub const fn display_name(&self) -> &'static str {
123        match self {
124            Self::Github => "GitHub",
125            Self::Google => "Google",
126        }
127    }
128}