Skip to main content

systemprompt_models/modules/
api_paths.rs

1//! API path constants.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use systemprompt_identifiers::{AgentName, ClientId, ContentHash, PluginId, TenantId};
7
8#[derive(Debug, Clone, Copy)]
9pub struct ApiPaths;
10
11impl ApiPaths {
12    pub const GATEWAY_BASE: &'static str = "/v1";
13    pub const GATEWAY_PUBLIC_BASE: &'static str = "/api/public/gateway";
14
15    pub const API_BASE: &'static str = "/api";
16    pub const API_V1: &'static str = "/api/v1";
17    pub const CORE_BASE: &'static str = "/api/v1/core";
18    pub const AGENTS_BASE: &'static str = "/api/v1/agents";
19    pub const MCP_BASE: &'static str = "/api/v1/mcp";
20    pub const STREAM_BASE: &'static str = "/api/v1/stream";
21    pub const CONTENT_BASE: &'static str = "/api/v1/content";
22    pub const SYNC_BASE: &'static str = "/api/v1/sync";
23    pub const ANALYTICS_BASE: &'static str = "/api/v1/analytics";
24    pub const META_BASE: &'static str = "/api/v1/meta";
25    pub const SLACK_BASE: &'static str = "/api/v1/slack";
26    pub const TEAMS_BASE: &'static str = "/api/v1/teams";
27
28    pub const CORE_CONTEXTS: &'static str = "/api/v1/core/contexts";
29    pub const CORE_TASKS: &'static str = "/api/v1/core/tasks";
30    pub const CORE_ARTIFACTS: &'static str = "/api/v1/core/artifacts";
31
32    pub const AGENT_RUNS: &'static str = "/api/v1/agent-runs";
33
34    pub const AGENTS_REGISTRY: &'static str = "/api/v1/agents/registry";
35
36    pub const MCP_REGISTRY: &'static str = "/api/v1/mcp/registry";
37
38    pub const STREAM_CONTEXTS: &'static str = "/api/v1/stream/contexts";
39
40    pub const AUTH_ME: &'static str = "/api/v1/auth/me";
41
42    pub const OAUTH_BASE: &'static str = "/api/v1/core/oauth";
43    pub const OAUTH_AUTHORIZE: &'static str = "/api/v1/core/oauth/authorize";
44    pub const OAUTH_TOKEN: &'static str = "/api/v1/core/oauth/token";
45    pub const OAUTH_CLIENTS: &'static str = "/api/v1/core/oauth/clients";
46
47    pub const CORE_USERS: &'static str = "/api/v1/core/users";
48
49    pub const WEBHOOK: &'static str = "/api/v1/webhook";
50
51    pub const HEALTH: &'static str = "/api/v1/health";
52
53    pub const LIVEZ: &'static str = "/livez";
54
55    pub const READYZ: &'static str = "/readyz";
56    pub const DISCOVERY: &'static str = "/api/v1";
57
58    pub const WELLKNOWN_BASE: &'static str = "/.well-known";
59    pub const WELLKNOWN_AGENT_CARD: &'static str = "/.well-known/agent-card.json";
60    pub const WELLKNOWN_AGENT_CARDS: &'static str = "/.well-known/agent-cards";
61    pub const WELLKNOWN_OAUTH_SERVER: &'static str = "/.well-known/oauth-authorization-server";
62    pub const WELLKNOWN_OPENID_CONFIG: &'static str = "/.well-known/openid-configuration";
63    pub const WELLKNOWN_OAUTH_PROTECTED: &'static str = "/.well-known/oauth-protected-resource";
64    pub const WELLKNOWN_JWKS: &'static str = "/.well-known/jwks.json";
65    pub const WELLKNOWN_BRIDGE: &'static str = "/.well-known/systemprompt-bridge";
66
67    pub const A2A_CARD: &'static str = "/api/a2a/card";
68
69    pub const ASSETS_BASE: &'static str = "/assets";
70    pub const FILES_BASE: &'static str = "/files";
71    pub const GENERATED_BASE: &'static str = "/generated";
72    pub const IMAGES_BASE: &'static str = "/images";
73    pub const STATIC_BASE: &'static str = "/static";
74    pub const NEXT_BASE: &'static str = "/_next";
75    pub const DOCS_BASE: &'static str = "/docs";
76    pub const SWAGGER_BASE: &'static str = "/swagger";
77    pub const OPENAPI_BASE: &'static str = "/openapi";
78
79    pub const TRACK_BASE: &'static str = "/track";
80    pub const TRACK_ENGAGEMENT: &'static str = "/track/engagement";
81
82    pub const ADMIN_BASE: &'static str = "/api/v1/admin";
83
84    pub const MARKETPLACE_BASE: &'static str = "/api/v1/marketplace";
85
86    pub const CLOUD_TENANTS: &'static str = "/api/v1/tenants";
87
88    pub const BRIDGE_BASE: &'static str = "/v1/bridge";
89    pub const BRIDGE_PUBKEY: &'static str = "/v1/bridge/pubkey";
90    pub const BRIDGE_MANIFEST: &'static str = "/v1/bridge/manifest";
91    pub const BRIDGE_PLUGINS: &'static str = "/v1/bridge/plugins";
92    pub const BRIDGE_PLUGIN_FILE_ROUTE: &'static str = "/v1/bridge/plugins/{plugin_id}/{*path}";
93    pub const BRIDGE_LATEST: &'static str = "/v1/bridge/latest";
94    pub const BRIDGE_DOWNLOAD: &'static str = "/v1/bridge/download";
95    pub const BRIDGE_DOWNLOAD_ROUTE: &'static str = "/v1/bridge/download/{platform}";
96    pub const BRIDGE_WHOAMI: &'static str = "/v1/bridge/whoami";
97    pub const BRIDGE_PROFILE: &'static str = "/v1/bridge/profile";
98    pub const BRIDGE_PROFILE_ENABLED_HOSTS: &'static str = "/v1/bridge/profile/enabled_hosts";
99    pub const BRIDGE_PROFILE_HOST_MODEL_FILTER: &'static str =
100        "/v1/bridge/profile/host-model-filter";
101    pub const BRIDGE_PROFILE_USAGE: &'static str = "/v1/bridge/profile/usage";
102    pub const BRIDGE_DEVICE: &'static str = "/v1/bridge/device";
103    pub const BRIDGE_HEARTBEAT: &'static str = "/v1/bridge/heartbeat";
104    pub const BRIDGE_STREAM: &'static str = "/v1/bridge/stream";
105    pub const BRIDGE_NOTIFICATIONS: &'static str = "/v1/bridge/notifications";
106    pub const BRIDGE_NOTIFICATIONS_READ: &'static str = "/v1/bridge/notifications/read";
107    pub const BRIDGE_NOTIFICATIONS_SEEN: &'static str = "/v1/bridge/notifications/seen";
108    pub const BRIDGE_NOTIFICATIONS_ESCALATE_ROUTE: &'static str =
109        "/v1/bridge/notifications/{id}/escalate";
110    pub const BRIDGE_NOTIFICATIONS_SUBSCRIPTIONS: &'static str =
111        "/v1/bridge/notifications/subscriptions";
112    pub const BRIDGE_NOTIFICATIONS_SUBSCRIPTION_ROUTE: &'static str =
113        "/v1/bridge/notifications/subscriptions/{id}";
114    pub const BRIDGE_NOTIFICATIONS_STREAMS: &'static str = "/v1/bridge/notifications/streams";
115    pub const BRIDGE_DRIVE_MANIFEST: &'static str = "/v1/bridge/drive/manifest";
116    pub const BRIDGE_DRIVE_CHANGES: &'static str = "/v1/bridge/drive/changes";
117    pub const BRIDGE_DRIVE_BLOB: &'static str = "/v1/bridge/drive/blob";
118    pub const BRIDGE_DRIVE_BLOB_ROUTE: &'static str = "/v1/bridge/drive/blob/{sha256}";
119    pub const BRIDGE_DRIVE_COMMIT: &'static str = "/v1/bridge/drive/commit";
120    pub const BRIDGE_DRIVE_PRESENCE: &'static str = "/v1/bridge/drive/presence";
121    pub const BRIDGE_DRIVE_PROPOSALS: &'static str = "/v1/bridge/drive/proposals";
122    pub const BRIDGE_DRIVE_TOKEN: &'static str = "/v1/bridge/drive/token";
123    pub const DOCUMENTS: &'static str = "/api/v1/documents";
124    pub const DOCUMENT_FOLDERS: &'static str = "/api/v1/document-folders";
125    pub const UPLOADS: &'static str = "/api/v1/uploads";
126    pub const NOTIFICATIONS: &'static str = "/api/v1/notifications";
127    pub const NOTIFICATIONS_SEEN: &'static str = "/api/v1/notifications/seen";
128    pub const ADMIN_NOTIFICATIONS: &'static str = "/api/v1/admin/notifications";
129    pub const BRIDGE_AUTH_PAT: &'static str = "/v1/auth/bridge/pat";
130    pub const BRIDGE_AUTH_SESSION: &'static str = "/v1/auth/bridge/session";
131    pub const BRIDGE_AUTH_SESSION_PAT: &'static str = "/v1/auth/bridge/session-pat";
132    pub const BRIDGE_AUTH_OAUTH_CLIENT: &'static str = "/v1/auth/bridge/oauth-client";
133    pub const BRIDGE_AUTH_CAPABILITIES: &'static str = "/v1/auth/bridge/capabilities";
134    pub const BRIDGE_PERSONAL_KEYS: &'static str = "/v1/me/provider-credentials";
135    pub const OTEL: &'static str = "/otel";
136    pub const OTEL_REST_ROUTE: &'static str = "/otel/{*rest}";
137    pub const MCP: &'static str = "/mcp";
138    pub const PUBLIC_HOOKS: &'static str = "/api/public/hooks";
139    pub const PUBLIC_HOOKS_TRACK: &'static str = "/api/public/hooks/track";
140    pub const CONSUMER_RECEIPTS: &'static str = "/api/v1/consumer/receipts";
141    pub const CONSUMER_SESSION_BINDINGS: &'static str = "/api/v1/consumer/session-bindings";
142    pub const CONSUMER_DEVICE_ENROLLMENT: &'static str = "/api/v1/consumer-devices/enrollment";
143    pub const CONSUMER_BUNDLE_ROUTE: &'static str =
144        "/api/v1/consumer/resources/{resource}/publications/{publication}/bundle";
145
146    // Why: `/otel` and `/mcp` are route families, not single endpoints; the
147    // bare path and every path below it belong to the family and nothing that
148    // merely shares the prefix (`/otelx`, `/mcpx`) does. Stated once here so
149    // the server's routing and the bridge's credential scoping cannot disagree.
150    #[must_use]
151    pub fn is_otel(path: &str) -> bool {
152        Self::in_family(path, Self::OTEL)
153    }
154
155    #[must_use]
156    pub fn is_mcp(path: &str) -> bool {
157        Self::in_family(path, Self::MCP)
158    }
159
160    #[must_use]
161    pub fn is_public_hook(path: &str) -> bool {
162        path.len() > Self::PUBLIC_HOOKS.len() + 1 && Self::in_family(path, Self::PUBLIC_HOOKS)
163    }
164
165    fn in_family(path: &str, base: &str) -> bool {
166        path == base
167            || path
168                .strip_prefix(base)
169                .is_some_and(|rest| rest.starts_with('/'))
170    }
171
172    #[must_use]
173    pub fn mcp_server_slug(path: &str) -> Option<&str> {
174        let rest = path.strip_prefix(Self::MCP)?.strip_prefix('/')?;
175        let slug = rest.split('/').next()?;
176        (!slug.is_empty()).then_some(slug)
177    }
178
179    #[must_use]
180    pub fn gateway_relative(path: &'static str) -> &'static str {
181        path.strip_prefix(Self::GATEWAY_BASE).unwrap_or(path)
182    }
183
184    #[must_use]
185    pub fn api_v1_relative(path: &'static str) -> &'static str {
186        path.strip_prefix(Self::API_V1).unwrap_or(path)
187    }
188
189    pub fn bridge_plugin_file(plugin_id: &PluginId, relative_path: &str) -> String {
190        format!(
191            "{}/{}/{relative_path}",
192            Self::BRIDGE_PLUGINS,
193            plugin_id.as_str()
194        )
195    }
196
197    pub fn bridge_drive_blob(sha256: &ContentHash) -> String {
198        format!("{}/{}", Self::BRIDGE_DRIVE_BLOB, sha256.as_str())
199    }
200
201    pub fn bridge_plugin_archive(plugin_id: &PluginId, sha256: &str) -> String {
202        format!(
203            "{}/{}/archive/{sha256}",
204            Self::BRIDGE_PLUGINS,
205            plugin_id.as_str()
206        )
207    }
208
209    pub fn bridge_download(platform: &str) -> String {
210        format!("{}/{platform}", Self::BRIDGE_DOWNLOAD)
211    }
212
213    pub fn otel_under(base_url: &str) -> String {
214        format!("{}{}", base_url.trim_end_matches('/'), Self::OTEL)
215    }
216
217    pub fn tenant(tenant_id: &TenantId) -> String {
218        format!("{}/{}", Self::CLOUD_TENANTS, tenant_id.as_str())
219    }
220
221    pub fn tenant_status(tenant_id: &TenantId) -> String {
222        format!("{}/{}/status", Self::CLOUD_TENANTS, tenant_id.as_str())
223    }
224
225    pub fn tenant_registry_token(tenant_id: &TenantId) -> String {
226        format!(
227            "{}/{}/registry-token",
228            Self::CLOUD_TENANTS,
229            tenant_id.as_str()
230        )
231    }
232
233    pub fn tenant_deploy(tenant_id: &TenantId) -> String {
234        format!("{}/{}/deploy", Self::CLOUD_TENANTS, tenant_id.as_str())
235    }
236
237    pub fn tenant_secrets(tenant_id: &TenantId) -> String {
238        format!("{}/{}/secrets", Self::CLOUD_TENANTS, tenant_id.as_str())
239    }
240
241    pub fn tenant_rotate_credentials(tenant_id: &TenantId) -> String {
242        format!(
243            "{}/{}/rotate-credentials",
244            Self::CLOUD_TENANTS,
245            tenant_id.as_str()
246        )
247    }
248
249    pub fn mcp_server_endpoint(server_name: &str) -> String {
250        format!("{}/{}/mcp", Self::MCP_BASE, server_name)
251    }
252
253    pub fn oauth_client_location(client_id: &ClientId) -> String {
254        format!("{}/{}", Self::OAUTH_CLIENTS, client_id.as_str())
255    }
256
257    pub fn wellknown_agent_card_named(agent_name: &str) -> String {
258        format!("{}/{}", Self::WELLKNOWN_AGENT_CARDS, agent_name)
259    }
260
261    pub fn agent_endpoint(agent_name: &AgentName) -> String {
262        format!("{}/{}/", Self::AGENTS_BASE, agent_name.as_str())
263    }
264}