Expand description
§systemprompt-ai
Provider-agnostic LLM integration for systemprompt.io.
systemprompt-ai is a domain layer crate that unifies Anthropic,
OpenAI, Gemini, and image-generation providers behind a single governed
pipeline with cost tracking, audit-trail persistence, and structured-output
validation.
It exposes:
AiService— top-level orchestration of generation, tool execution, structured output, planning, and Google-Search-grounded responses.ImageService— image generation and persistence.ImageStorage/StorageConfig— local file-system blob storage for generated images.- The
AiExtensionentrypoint that wires the crate into thesystemprompt-extensionframework. - Repository types (
AiRequestRepository,AiQuotaBucketRepository, …) for persisting request audit rows, quota buckets, gateway policies, and safety findings.
§Error model
All public service signatures return error::Result<T> (an alias for
Result<T, AiError>). AiError composes:
LlmProviderErrorfor provider-trait failuresRepositoryErrorfor persistence- common transport errors (
reqwest::Error,serde_json::Error,sqlx::Error,std::io::Error,regex::Error) - an
Internal(String)carve-out for cases where the upstream cause is stringified at the call site rather than typed
The provider-trait surface (AiProvider) used over the wire bridges to
the boxed ProviderResult
in
services::core::ai_service.
§Feature flags
This crate has no Cargo features — all functionality is always compiled.
[package.metadata.docs.rs] sets all-features = true for parity with
sibling crates that do.
Re-exports§
pub use services::core::AiService;pub use services::core::ImageService;pub use services::gateway::Finding;pub use services::gateway::GATEWAY_POLICIES_FILE;pub use services::gateway::GatewayPolicyConfig;pub use services::gateway::GatewayPolicyEntry;pub use services::gateway::GatewayPolicyIngestionService;pub use services::gateway::GatewayPolicySpec;pub use services::gateway::HeuristicScanner;pub use services::gateway::IngestOptions as GatewayPolicyIngestOptions;pub use services::gateway::IngestReport as GatewayPolicyIngestReport;pub use services::gateway::NullScanner;pub use services::gateway::QuotaWindow;pub use services::gateway::SafetyConfig;pub use services::gateway::SafetyScanner;pub use services::gateway::SafetyScannerRegistration;pub use services::gateway::Severity;pub use services::gateway::load_from_yaml as load_gateway_policies_from_yaml;pub use services::storage::ImageStorage;pub use services::storage::StorageConfig;pub use services::tools::NoopToolProvider;pub use models::image_generation::AspectRatio;pub use models::image_generation::GeneratedImageRecord;pub use models::image_generation::ImageGenerationRequest;pub use models::image_generation::ImageGenerationResponse;pub use models::image_generation::ImageResolution;pub use models::image_generation::ReferenceImage;pub use services::providers::GeminiImageProvider;pub use services::providers::ImageProvider;pub use services::providers::ImageProviderCapabilities;pub use repository::AiGatewayPolicyRepository;pub use repository::AiQuotaBucketRepository;pub use repository::AiRequestPayloadRepository;pub use repository::AiRequestRepository;pub use repository::AiSafetyFindingRepository;pub use repository::GatewayPolicyRow;pub use repository::IncrementParams;pub use repository::InsertSafetyFinding;pub use repository::QuotaBucketDelta;pub use repository::QuotaBucketState;pub use repository::UpsertPayloadParams;pub use services::tooled::ToolResultFormatter;
Modules§
- error
- Typed error hierarchy for the
systemprompt-aicrate. - models
- Domain data types for the AI crate.
- repository
- Repository layer for AI domain persistence.
- services
- Service orchestration layer for the AI domain crate.
Macros§
- register_
safety_ scanner - Register a
SafetyScannerimplementation with the gateway.
Structs§
- AiConfig
- AiExtension
- AiMessage
- AiRequest
- AiRequest
Builder - AiResponse
- Call
Tool Result - The result of a tool call operation.
- Generate
Response Params - Google
Search Params - McpTool
- Model
Config - Model
Preferences - Provider
Config - Sampling
Params - Search
Grounded Response - Structured
Output Options - Tool
Call - Tool
Execution
Enums§
Traits§
- AiProvider
#[async_trait]is required: this trait is consumed exclusively asDynAiProvider(Arc<dyn AiProvider>), and adyn-compatible trait cannot use nativeasync fn.