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`] / [`run_checkout_callback_flow`] — browser-driven OAuth
16//!   and Paddle checkout flows.
17//! - [`wait_for_provisioning`] — SSE + polling watcher for tenant provisioning
18//!   state.
19//! - [`CloudPaths`] — XDG-aware discovery of credentials, sessions, tenants,
20//!   and project files.
21//! - [`profile_authoring`] — pure [`Profile`](systemprompt_models::Profile)
22//!   construction for local and cloud deployment targets.
23//! - [`deploy`] — Dockerfile rendering ([`DockerfileBuilder`]) and validation
24//!   for the deployment image.
25//! - [`secrets_env`] — deploy-time mapping of `secrets.json` to environment
26//!   variables, including the signing-key PEM transport encoding.
27//! - [`DockerCli`] — Docker invocations behind a [`CommandRunner`] seam.
28//!
29//! ## Errors
30//!
31//! All public APIs return [`CloudResult<T>`] (i.e.
32//! `Result<T, CloudError>`). [`CloudError`] composes `reqwest`,
33//! `std::io`, `serde_json`, and the more specific
34//! [`CredentialsBootstrapError`] via `#[from]` so callers can use `?`
35//! transparently.
36//!
37//! ## Feature flags
38//!
39//! This crate has no Cargo features — every dependency is required at
40//! compile time. The `[package.metadata.docs.rs]` section in
41//! `Cargo.toml` enables `all-features = true` for parity with the
42//! rest of the workspace.
43//!
44//! Copyright (c) systemprompt.io — Business Source License 1.1.
45//! See <https://systemprompt.io> for licensing details.
46
47pub mod api_client;
48pub mod auth;
49mod callback_listener;
50pub mod checkout;
51pub mod cli_session;
52pub mod constants;
53pub mod credentials;
54pub mod credentials_bootstrap;
55pub mod deploy;
56pub mod docker;
57pub mod error;
58pub mod oauth;
59pub mod paths;
60pub mod profile_authoring;
61pub mod secrets_env;
62pub mod tenants;
63pub mod trusted_proxies;
64
65pub use api_client::{
66    CheckoutEvent, CheckoutResponse, CloudApiClient, DeployResponse, ListSecretsResponse, Plan,
67    ProvisioningEvent, ProvisioningEventType, RegistryToken, StatusResponse, SubscriptionStatus,
68    Tenant, TenantInfo, TenantSecrets, TenantStatus, UserInfo, UserMeResponse,
69};
70pub use checkout::{
71    CheckoutCallbackResult, CheckoutTemplates, run_checkout_callback_flow, wait_for_provisioning,
72};
73pub use cli_session::{CliSession, LOCAL_SESSION_KEY, SessionIdentity, SessionKey, SessionStore};
74pub use constants::api::{PRODUCTION_URL, SANDBOX_URL};
75pub use credentials::CloudCredentials;
76pub use credentials_bootstrap::{CredentialsBootstrap, CredentialsBootstrapError};
77pub use deploy::DockerfileBuilder;
78pub use docker::{CommandRunner, CommandSpec, DockerCli, SystemCommandRunner};
79pub use error::{CloudError, CloudResult};
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}