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