Skip to main content

systemprompt_runtime/
lib.rs

1//! `systemprompt-runtime` — application runtime services.
2//!
3//! This crate hosts [`AppContext`], the lifecycle [`AppContextBuilder`],
4//! the inventory-driven module API and well-known route registries,
5//! per-module installation helpers, startup validation, and the typed
6//! [`RuntimeError`] / [`RuntimeResult`] error boundary used by all of
7//! the above.
8//!
9//! Public APIs return [`RuntimeResult<T>`]. [`RuntimeError`] composes
10//! upstream typed errors (`ConfigError`, `RepositoryError`,
11//! `FilesError`, `UserError`, `LoaderError`, `AnalyticsError`,
12//! `ProfileBootstrapError`, `PathError`) via `#[from]` and absorbs
13//! untyped third-party errors into [`RuntimeError::Internal`] as strings.
14//!
15//! # Feature flags
16//!
17//! | Feature       | Effect                                                          |
18//! |---------------|------------------------------------------------------------------|
19//! | (default)     | Core context, builder, registries, validation                   |
20//! | `geolocation` | Enables `MaxMind` `GeoIP2` loading via `maxminddb` and pulls in `systemprompt-analytics/geolocation` |
21//!
22//! Copyright (c) systemprompt.io — Business Source License 1.1.
23//! See <https://systemprompt.io> for licensing details.
24
25mod builder;
26mod context;
27mod context_traits;
28mod database_context;
29mod error;
30pub mod managed;
31mod registry;
32pub mod reporting;
33pub mod services_reconcile;
34mod startup_validation;
35pub mod trace;
36mod validation;
37mod wellknown;
38
39pub use builder::{AppContextBuilder, discover_models};
40pub use context::{AppContext, ConfigPlane, DataPlane, Plugins, ShutdownRequest, Subsystems};
41pub use database_context::DatabaseContext;
42pub use error::{RuntimeError, RuntimeResult};
43pub use registry::{ModuleApiRegistration, ModuleApiRegistry, ModuleType, WellKnownRoute};
44pub use startup_validation::{
45    ExtensionConfigOutcome, FilesConfigValidator, StartupValidator, collect_manifest_errors,
46    display_validation_report, display_validation_warnings, merge_mcp_errors,
47    validate_extension_configs,
48};
49pub use systemprompt_database::MigrationConfig;
50pub use trace::{
51    AiRequestClientEvidence, AiRequestDetail, AiRequestFilter, AiRequestInfo, AiRequestListItem,
52    AiRequestStats, AiRequestSummary, AiTraceService, AuditLookupResult, AuditPage,
53    AuditToolCallRow, ConversationMessage, ExecutionStep, ExecutionStepSummary, LevelCount,
54    LinkedMcpCall, LogSearchFilter, LogSearchItem, LogTimeRange, McpExecutionSummary,
55    McpToolExecution, ModelStatsRow, ModuleCount, ProviderStatsRow, RequestCursor,
56    RequestCursorError, TaskArtifact, TaskInfo, ToolExecutionFilter, ToolExecutionItem,
57    ToolLogEntry, TraceError, TraceEvent, TraceListFilter, TraceListItem, TraceQueryService,
58};
59pub use validation::{validate_database_path, validate_system};
60pub use wellknown::{WellKnownMetadata, get_wellknown_metadata};
61
62pub use systemprompt_models::modules::ServiceCategory;
63
64#[macro_export]
65macro_rules! register_module_api {
66    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr, $module_type:expr) => {
67        inventory::submit! {
68            $crate::ModuleApiRegistration {
69                module_name: $module_name,
70                category: $category,
71                module_type: $module_type,
72                router_fn: $router_fn,
73                auth_required: $auth_required,
74            }
75        }
76    };
77    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr) => {
78        inventory::submit! {
79            $crate::ModuleApiRegistration {
80                module_name: $module_name,
81                category: $category,
82                module_type: $crate::ModuleType::Regular,
83                router_fn: $router_fn,
84                auth_required: $auth_required,
85            }
86        }
87    };
88}
89
90#[macro_export]
91macro_rules! register_wellknown_route {
92    ($path:literal, $handler:expr, $methods:expr, name: $name:literal, description: $desc:literal) => {
93        inventory::submit! {
94            $crate::WellKnownRoute {
95                path: $path,
96                handler_fn: $handler,
97                methods: $methods,
98            }
99        }
100
101        inventory::submit! {
102            $crate::WellKnownMetadata::new($path, $name, $desc)
103        }
104    };
105
106    ($path:literal, $handler:expr, $methods:expr) => {
107        inventory::submit! {
108            $crate::WellKnownRoute {
109                path: $path,
110                handler_fn: $handler,
111                methods: $methods,
112            }
113        }
114    };
115}