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