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//!
22//! ## Errors
23//!
24//! All public APIs return [`CloudResult<T>`] (i.e.
25//! `Result<T, CloudError>`). [`CloudError`] composes `reqwest`,
26//! `std::io`, `serde_json`, and the more specific
27//! [`CredentialsBootstrapError`] via `#[from]` so callers can use `?`
28//! transparently.
29//!
30//! ## Feature flags
31//!
32//! This crate has no Cargo features — every dependency is required at
33//! compile time. The `[package.metadata.docs.rs]` section in
34//! `Cargo.toml` enables `all-features = true` for parity with the
35//! rest of the workspace.
36
37pub mod api_client;
38pub mod auth;
39pub mod checkout;
40pub mod cli_session;
41pub mod constants;
42pub mod context;
43pub mod credentials;
44pub mod credentials_bootstrap;
45pub mod error;
46pub mod oauth;
47pub mod paths;
48pub mod tenants;
49
50pub use api_client::{
51    CheckoutEvent, CheckoutResponse, CloudApiClient, DeployResponse, ListSecretsResponse, Plan,
52    ProvisioningEvent, ProvisioningEventType, RegistryToken, StatusResponse, SubscriptionStatus,
53    Tenant, TenantInfo, TenantSecrets, TenantStatus, UserInfo, UserMeResponse,
54};
55pub use checkout::{
56    CheckoutCallbackResult, CheckoutTemplates, run_checkout_callback_flow, wait_for_provisioning,
57};
58pub use cli_session::{CliSession, LOCAL_SESSION_KEY, SessionKey, SessionStore};
59pub use constants::api::{PRODUCTION_URL, SANDBOX_URL};
60pub use context::{CloudContext, ResolvedTenant};
61pub use credentials::CloudCredentials;
62pub use credentials_bootstrap::{CredentialsBootstrap, CredentialsBootstrapError};
63pub use error::{CloudError, CloudResult};
64pub use oauth::{OAuthTemplates, run_oauth_flow};
65pub use paths::{
66    CloudPath, CloudPaths, DiscoveredProject, ProfilePath, ProjectContext, ProjectPath,
67    UnifiedContext, expand_home, get_cloud_paths, resolve_path,
68};
69pub use tenants::{StoredTenant, TenantStore, TenantType};
70
71use clap::ValueEnum;
72
73#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
74pub enum Environment {
75    #[default]
76    Production,
77    Sandbox,
78}
79
80impl Environment {
81    #[must_use]
82    pub const fn api_url(&self) -> &'static str {
83        match self {
84            Self::Production => PRODUCTION_URL,
85            Self::Sandbox => SANDBOX_URL,
86        }
87    }
88}
89
90#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
91pub enum OAuthProvider {
92    Github,
93    Google,
94}
95
96impl OAuthProvider {
97    #[must_use]
98    pub const fn as_str(&self) -> &'static str {
99        match self {
100            Self::Github => "github",
101            Self::Google => "google",
102        }
103    }
104
105    #[must_use]
106    pub const fn display_name(&self) -> &'static str {
107        match self {
108            Self::Github => "GitHub",
109            Self::Google => "Google",
110        }
111    }
112}