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