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