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 roles;
97mod scope;
98mod section;
99mod service;
100mod session;
101mod slack;
102mod task;
103mod teams;
104mod tenant;
105mod trace;
106mod url;
107mod user;
108mod webhook;
109
110pub mod error;
111pub mod gateway_hash;
112pub mod headers;
113pub mod macros;
114
115pub use actor::{Actor, ActorKind, ActorKindTag};
116pub use agent::{AgentId, AgentName, ExternalAgentId};
117pub use agent_run::{AgentRunId, HostSessionId};
118pub use ai::{
119    AiGatewayPolicyId, AiQuotaBucketId, AiRequestId, AiSafetyFindingId, ConfigId, MessageId,
120};
121pub use auth::{
122    ApiKeyId, ApiKeySecret, CloudAuthToken, DeviceCertId, DeviceId, JwtToken, SessionToken,
123};
124pub use bridge::{
125    CommsMessageId, DeploymentOrganizationUuid, ElevatedJobId, HookSessionId, McpSessionId,
126};
127pub use client::{ClientId, ClientType};
128pub use client_session::ClientSessionId;
129pub use cloud::{CloudAppId, CloudUserId, PriceId};
130pub use connection::ConnectionId;
131pub use content::{CategoryId, ContentId, FileId, SkillId, SkillName, SourceId, TagId};
132pub use context::ContextId;
133pub use email::Email;
134pub use engagement::EngagementEventId;
135pub use events::EventOutboxId;
136pub use execution::{ArtifactId, ExecutionStepId, LogId, TokenId};
137pub use extension::ExtensionId;
138pub use gateway_boot::{DepartmentId, DepartmentName, ModelId, ProviderId, RouteId, SecretName};
139pub use gateway_conversation::GatewayConversationId;
140pub use hook::HookId;
141pub use instance::InstanceId;
142pub use jobs::{JobName, ScheduledJobId};
143pub use links::{CampaignId, LinkClickId, LinkId};
144pub use locale::LocaleCode;
145pub use managed::{
146    ConsumerInstallationId, DistributionId, InstallationReceiptId, InstallationSessionBindingId,
147    InventoryEntryId, ManagedReconciliationId, ManagedResourceId, ManagedSourceId, NativeSessionId,
148    PublicationId, PublicationReviewId, ResourceRevisionId, SourceSnapshotId, WithdrawalProposalId,
149};
150pub use marketplace::{LibraryArtifactId, MarketplaceId, MarketplaceRuleId, RuleName};
151pub use mcp::{AiToolCallId, McpExecutionId, McpServerId, McpToolName};
152pub use oauth::{AccessTokenId, AuthorizationCode, ChallengeId, RefreshTokenId};
153pub use path::ValidatedFilePath;
154pub use plugin::PluginId;
155pub use policy::{CallId, PolicyId, PolicyVersion, SecretPatternId};
156pub use profile::ProfileName;
157pub use provider_request::ProviderRequestId;
158pub use roles::RoleId;
159pub use scope::{ScopeDimension, validate_scope_dimension};
160pub use section::SectionId;
161pub use service::ServiceName;
162pub use session::{SessionId, SessionSource};
163pub use slack::{SlackChannelId, SlackUserId, SlackWorkspaceId};
164pub use task::TaskId;
165pub use teams::{TeamsAppId, TeamsConversationId, TeamsTenantId, TeamsUserId};
166pub use tenant::TenantId;
167pub use trace::TraceId;
168pub use url::ValidatedUrl;
169pub use user::UserId;
170pub use webhook::WebhookEndpointId;
171
172define_id!(RuleId, generate);
173pub use managed::ResourceInvocationId;