Skip to main content

systemprompt_identifiers/
lib.rs

1//! Typed newtype identifiers for systemprompt.io.
2//!
3//! Every entity in the platform is referenced through a wrapper newtype
4//! rather than a raw `String`.
5//!
6//! This crate provides both the macros that generate those wrappers
7//! ([`define_id!`], [`define_token!`]) and the canonical concrete types
8//! (`UserId`, `AgentId`, `TaskId`, `TraceId`, `ContextId`, `SessionId`,
9//! `McpServerId`, ...).
10//!
11//! Boundary types for talking to the database — [`DbValue`], [`ToDbValue`],
12//! [`FromDbValue`], [`JsonRow`] — also live here so that identifier modules
13//! can interoperate without depending on the database crate.
14//!
15//! # Construction
16//!
17//! ```ignore
18//! use systemprompt_identifiers::{TaskId, UserId};
19//!
20//! // A value already known to be valid (a decoded DB row).
21//! let task = TaskId::new("task_abc");
22//!
23//! // A value from outside (header, path segment, JWT claim): validate it.
24//! let user = UserId::try_new(raw_sub)?;
25//!
26//! // Mint a fresh UUID-backed identifier.
27//! let fresh = UserId::generate();
28//! ```
29//!
30//! Validated identifiers (`ContextId`, `Email`, `ProfileName`, `ValidatedUrl`,
31//! `ValidatedFilePath`, `RoleId`, ...) expose **only** the fallible `try_new`
32//! constructor returning [`error::IdValidationError`]; there is no
33//! infallible `new` that could panic on runtime input. Values
34//! minted by the platform itself (`ContextId::generate`, `AgentName::system`)
35//! come from dedicated constructors.
36//!
37//! Checked identifiers (`UserId`, `ServiceName`, `AgentName`, `McpServerId`,
38//! `McpToolName`, `PluginId`, `SkillId`, ...) have both: `try_new` validates
39//! input from outside, `new` accepts a value already known valid (a decoded
40//! row, a configuration key validated at load). They implement no
41//! `From<String>`, and their `Deserialize`/`FromStr` validate.
42//!
43//! "Absent" is `Option<Id>`, never a sentinel value such as `"unset"`,
44//! `"unknown"` or the empty string.
45//!
46//! [`gateway_hash`] is the deterministic prefix hash that mints a
47//! [`GatewayConversationId`] identically on both sides of the bridge boundary.
48//!
49//! # Feature flags
50//!
51//! | Feature | Effect |
52//! |---------|--------|
53//! | (default) | Pure-Rust types only. |
54//! | `sqlx` | Derives `sqlx::Type` on every identifier, allowing direct binding in `query_as!` macros. |
55//!
56//! Copyright (c) systemprompt.io — Business Source License 1.1.
57//! See <https://systemprompt.io> for licensing details.
58
59pub mod db_value;
60
61pub use db_value::{DbValue, FromDbValue, JsonRow, ToDbValue, parse_database_datetime};
62
63mod actor;
64mod agent;
65mod agent_run;
66mod ai;
67mod auth;
68mod bridge;
69mod client;
70mod client_session;
71mod cloud;
72mod connection;
73mod content;
74mod context;
75mod email;
76mod engagement;
77mod events;
78mod execution;
79mod extension;
80mod gateway_boot;
81mod gateway_conversation;
82mod hook;
83mod instance;
84mod jobs;
85mod links;
86mod locale;
87mod managed;
88mod marketplace;
89mod mcp;
90mod oauth;
91mod path;
92mod plugin;
93mod policy;
94mod profile;
95mod provider_request;
96mod quota;
97mod roles;
98mod scope;
99mod section;
100mod service;
101mod session;
102mod slack;
103mod sso;
104mod task;
105mod teams;
106mod tenant;
107mod trace;
108mod url;
109mod user;
110mod webhook;
111
112pub mod error;
113pub mod gateway_hash;
114pub mod headers;
115pub mod macros;
116
117pub use actor::{Actor, ActorKind, ActorKindTag};
118pub use agent::{AgentId, AgentName, ExternalAgentId};
119pub use agent_run::{AgentRunId, AgentRunOriginId, HostSessionId};
120pub use ai::{
121    AiGatewayPolicyId, AiQuotaBucketId, AiRequestId, AiSafetyFindingId, ConfigId, MessageId,
122    QuotaSubjectId,
123};
124pub use auth::{
125    ApiKeyId, ApiKeySecret, CloudAuthToken, DeviceCertId, DeviceId, JwtToken, SessionToken,
126};
127pub use bridge::{
128    CommsMessageId, DeploymentOrganizationUuid, ElevatedJobId, HookSessionId, McpSessionId,
129};
130pub use client::{ClientId, ClientType};
131pub use client_session::ClientSessionId;
132pub use cloud::{CloudAppId, CloudPlanId, CloudUserId, EnterpriseLicenseId, PriceId};
133pub use connection::ConnectionId;
134pub use content::{CategoryId, ContentId, FileId, SkillId, SkillName, SourceId, TagId};
135pub use context::ContextId;
136pub use email::Email;
137pub use engagement::{AnalyticsEventId, EngagementEventId};
138pub use events::EventOutboxId;
139pub use execution::{ArtifactElementId, ArtifactId, ExecutionStepId, LogId, TokenId};
140pub use extension::ExtensionId;
141pub use gateway_boot::{
142    CredentialId, DepartmentId, DepartmentName, EndpointId, ModelId, ProviderId, RouteId,
143    SecretName,
144};
145pub use gateway_conversation::GatewayConversationId;
146pub use hook::HookId;
147pub use instance::{AdvisoryLockKey, InstanceId, LeaseKey};
148pub use jobs::{JobName, ScheduledJobId};
149pub use links::{CampaignId, LinkClickId, LinkId};
150pub use locale::LocaleCode;
151pub use managed::{
152    ConsumerInstallationId, DistributionId, InstallationReceiptId, InstallationSessionBindingId,
153    InventoryEntryId, ManagedReconciliationId, ManagedResourceId, ManagedSourceId, NativeSessionId,
154    PublicationId, PublicationReviewId, ResourceRevisionId, SourceSnapshotId, WithdrawalProposalId,
155};
156pub use marketplace::{LibraryArtifactId, MarketplaceId, MarketplaceRuleId, RuleName};
157pub use mcp::{
158    AiToolCallId, ConnectorAppId, ConnectorInstallationId, McpExecutionId, McpServerId, McpToolName,
159};
160pub use oauth::{
161    AccessTokenId, AuthorizationCode, ChallengeId, RefreshTokenFamilyId, RefreshTokenId,
162    SsoProviderId,
163};
164pub use path::ValidatedFilePath;
165pub use plugin::PluginId;
166pub use policy::{CallId, PolicyId, PolicyVersion, SecretPatternId};
167pub use profile::ProfileName;
168pub use provider_request::ProviderRequestId;
169pub use quota::{InvalidQuotaSubjectKind, QuotaSubjectKind};
170pub use roles::RoleId;
171pub use scope::{ScopeDimension, validate_scope_dimension};
172pub use section::SectionId;
173pub use service::ServiceName;
174pub use session::{SessionId, SessionSource};
175pub use slack::{SlackChannelId, SlackUserId, SlackWorkspaceId};
176pub use sso::{IdpTenantId, SsoAssertionId, SsoRequestId};
177pub use task::TaskId;
178pub use teams::{TeamsAppId, TeamsConversationId, TeamsTenantId, TeamsUserId};
179pub use tenant::TenantId;
180pub use trace::TraceId;
181pub use url::ValidatedUrl;
182pub use user::UserId;
183pub use webhook::WebhookEndpointId;
184
185define_id!(RuleId, generate);
186pub use managed::ResourceInvocationId;