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;
49pub mod checkout;
50pub mod cli_session;
51pub mod constants;
52pub mod credentials;
53pub mod credentials_bootstrap;
54pub mod deploy;
55pub mod docker;
56pub mod error;
57pub mod oauth;
58pub mod paths;
59pub mod profile_authoring;
60pub mod secrets_env;
61pub mod tenants;
62
63pub use api_client::{
64    CheckoutEvent, CheckoutResponse, CloudApiClient, DeployResponse, ListSecretsResponse, Plan,
65    ProvisioningEvent, ProvisioningEventType, RegistryToken, StatusResponse, SubscriptionStatus,
66    Tenant, TenantInfo, TenantSecrets, TenantStatus, UserInfo, UserMeResponse,
67};
68pub use checkout::{
69    CheckoutCallbackResult, CheckoutTemplates, run_checkout_callback_flow, wait_for_provisioning,
70};
71pub use cli_session::{CliSession, LOCAL_SESSION_KEY, SessionIdentity, SessionKey, SessionStore};
72pub use constants::api::{PRODUCTION_URL, SANDBOX_URL};
73pub use credentials::CloudCredentials;
74pub use credentials_bootstrap::{CredentialsBootstrap, CredentialsBootstrapError};
75pub use deploy::DockerfileBuilder;
76pub use docker::{CommandRunner, CommandSpec, DockerCli, SystemCommandRunner};
77pub use error::{CloudError, CloudResult};
78pub use oauth::{OAuthTemplates, run_oauth_flow};
79pub use paths::{
80    CloudPath, CloudPaths, DiscoveredProject, ProfilePath, ProjectContext, ProjectPath,
81    UnifiedContext, expand_home, get_cloud_paths, resolve_path,
82};
83pub use tenants::{StoredTenant, TenantStore, TenantType};
84
85use clap::ValueEnum;
86
87#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
88pub enum Environment {
89    #[default]
90    Production,
91    Sandbox,
92}
93
94impl Environment {
95    #[must_use]
96    pub const fn api_url(&self) -> &'static str {
97        match self {
98            Self::Production => PRODUCTION_URL,
99            Self::Sandbox => SANDBOX_URL,
100        }
101    }
102}
103
104#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
105pub enum OAuthProvider {
106    Github,
107    Google,
108}
109
110impl OAuthProvider {
111    #[must_use]
112    pub const fn as_str(&self) -> &'static str {
113        match self {
114            Self::Github => "github",
115            Self::Google => "google",
116        }
117    }
118
119    #[must_use]
120    pub const fn display_name(&self) -> &'static str {
121        match self {
122            Self::Github => "GitHub",
123            Self::Google => "Google",
124        }
125    }
126}