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