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 documents;
76mod email;
77mod engagement;
78mod events;
79mod execution;
80mod extension;
81mod gateway_boot;
82mod gateway_conversation;
83mod hook;
84mod instance;
85mod jobs;
86mod links;
87mod locale;
88mod managed;
89mod marketplace;
90mod mcp;
91mod oauth;
92mod path;
93mod plugin;
94mod policy;
95mod profile;
96mod provider_request;
97mod quota;
98mod roles;
99mod scope;
100mod section;
101mod service;
102mod session;
103mod slack;
104mod sso;
105mod task;
106mod teams;
107mod tenant;
108mod trace;
109mod url;
110mod user;
111mod webhook;
112
113pub mod error;
114pub mod gateway_hash;
115pub mod headers;
116pub mod macros;
117
118pub use actor::{Actor, ActorKind, ActorKindTag};
119pub use agent::{AgentId, AgentName, ExternalAgentId};
120pub use agent_run::{AgentRunId, AgentRunOriginId, HostSessionId};
121pub use ai::{
122    AiGatewayPolicyId, AiQuotaBucketId, AiRequestId, AiSafetyFindingId, ConfigId, MessageId,
123    QuotaSubjectId,
124};
125pub use auth::{
126    ApiKeyId, ApiKeySecret, CloudAuthToken, DeviceCertId, DeviceId, JwtToken, SessionToken,
127};
128pub use bridge::{
129    CommsMessageId, DeploymentOrganizationUuid, ElevatedJobId, HookSessionId, McpSessionId,
130};
131pub use client::{ClientId, ClientType};
132pub use client_session::ClientSessionId;
133pub use cloud::{CloudAppId, CloudPlanId, CloudUserId, EnterpriseLicenseId, PriceId};
134pub use connection::ConnectionId;
135pub use content::{CategoryId, ContentId, FileId, SkillId, SkillName, SourceId, TagId};
136pub use context::ContextId;
137pub use documents::{
138    ContentHash, DocumentAccessRequestId, DocumentCommentId, DocumentEditSessionId,
139    DocumentFolderId, DocumentId, DocumentNodeId, DocumentOpId, DocumentProposalId,
140    DocumentRevisionId, DocumentTemplateId, DocumentUploadId, DriveDeviceId,
141};
142pub use email::Email;
143pub use engagement::{AnalyticsEventId, EngagementEventId};
144pub use events::EventOutboxId;
145pub use execution::{ArtifactElementId, ArtifactId, ExecutionStepId, LogId, TokenId};
146pub use extension::ExtensionId;
147pub use gateway_boot::{
148    CredentialId, DepartmentId, DepartmentName, EndpointId, ModelId, ProviderId, RouteId,
149    SecretName,
150};
151pub use gateway_conversation::GatewayConversationId;
152pub use hook::HookId;
153pub use instance::{AdvisoryLockKey, InstanceId, LeaseKey};
154pub use jobs::{JobName, ScheduledJobId};
155pub use links::{CampaignId, LinkClickId, LinkId};
156pub use locale::LocaleCode;
157pub use managed::{
158    ConsumerInstallationId, DistributionId, InstallationReceiptId, InstallationSessionBindingId,
159    InventoryEntryId, ManagedReconciliationId, ManagedResourceId, ManagedSourceId, NativeSessionId,
160    PublicationId, PublicationReviewId, ResourceRevisionId, SourceSnapshotId, WithdrawalProposalId,
161};
162pub use marketplace::{LibraryArtifactId, MarketplaceId, MarketplaceRuleId, RuleName};
163pub use mcp::{
164    AiToolCallId, ConnectorAppId, ConnectorInstallationId, McpExecutionId, McpServerId, McpToolName,
165};
166pub use oauth::{
167    AccessTokenId, AuthorizationCode, ChallengeId, RefreshTokenFamilyId, RefreshTokenId,
168    SsoProviderId,
169};
170pub use path::ValidatedFilePath;
171pub use plugin::PluginId;
172pub use policy::{CallId, PolicyId, PolicyVersion, SecretPatternId};
173pub use profile::ProfileName;
174pub use provider_request::ProviderRequestId;
175pub use quota::{InvalidQuotaSubjectKind, QuotaSubjectKind};
176pub use roles::RoleId;
177pub use scope::{ScopeDimension, validate_scope_dimension};
178pub use section::SectionId;
179pub use service::ServiceName;
180pub use session::{SessionId, SessionSource};
181pub use slack::{SlackChannelId, SlackUserId, SlackWorkspaceId};
182pub use sso::{IdpTenantId, SsoAssertionId, SsoRequestId};
183pub use task::TaskId;
184pub use teams::{TeamsAppId, TeamsConversationId, TeamsTenantId, TeamsUserId};
185pub use tenant::TenantId;
186pub use trace::TraceId;
187pub use url::ValidatedUrl;
188pub use user::UserId;
189pub use webhook::WebhookEndpointId;
190
191define_id!(RuleId, generate);
192pub use managed::ResourceInvocationId;