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 services_reconcile;
33mod startup_validation;
34pub mod trace;
35mod validation;
36mod wellknown;
37
38pub use builder::{AppContextBuilder, discover_models};
39pub use context::{AppContext, ConfigPlane, DataPlane, Plugins, ShutdownRequest, Subsystems};
40pub use database_context::DatabaseContext;
41pub use error::{RuntimeError, RuntimeResult};
42pub use registry::{ModuleApiRegistration, ModuleApiRegistry, ModuleType, WellKnownRoute};
43pub use startup_validation::{
44    ExtensionConfigOutcome, FilesConfigValidator, StartupValidator, collect_manifest_errors,
45    display_validation_report, display_validation_warnings, merge_mcp_errors,
46    validate_extension_configs,
47};
48pub use systemprompt_database::MigrationConfig;
49pub use trace::{
50    AiRequestClientEvidence, AiRequestDetail, AiRequestFilter, AiRequestInfo, AiRequestListItem,
51    AiRequestStats, AiRequestSummary, AiTraceService, AuditLookupResult, AuditPage,
52    AuditToolCallRow, ConversationMessage, ExecutionStep, ExecutionStepSummary, LevelCount,
53    LinkedMcpCall, LogSearchFilter, LogSearchItem, LogTimeRange, McpExecutionSummary,
54    McpToolExecution, ModelStatsRow, ModuleCount, ProviderStatsRow, RequestCursor,
55    RequestCursorError, TaskArtifact, TaskInfo, ToolExecutionFilter, ToolExecutionItem,
56    ToolLogEntry, TraceError, TraceEvent, TraceListFilter, TraceListItem, TraceQueryService,
57};
58pub use validation::{validate_database_path, validate_system};
59pub use wellknown::{WellKnownMetadata, get_wellknown_metadata};
60
61pub use systemprompt_models::modules::ServiceCategory;
62
63#[macro_export]
64macro_rules! register_module_api {
65    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr, $module_type:expr) => {
66        inventory::submit! {
67            $crate::ModuleApiRegistration {
68                module_name: $module_name,
69                category: $category,
70                module_type: $module_type,
71                router_fn: $router_fn,
72                auth_required: $auth_required,
73            }
74        }
75    };
76    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr) => {
77        inventory::submit! {
78            $crate::ModuleApiRegistration {
79                module_name: $module_name,
80                category: $category,
81                module_type: $crate::ModuleType::Regular,
82                router_fn: $router_fn,
83                auth_required: $auth_required,
84            }
85        }
86    };
87}
88
89#[macro_export]
90macro_rules! register_wellknown_route {
91    ($path:literal, $handler:expr, $methods:expr, name: $name:literal, description: $desc:literal) => {
92        inventory::submit! {
93            $crate::WellKnownRoute {
94                path: $path,
95                handler_fn: $handler,
96                methods: $methods,
97            }
98        }
99
100        inventory::submit! {
101            $crate::WellKnownMetadata::new($path, $name, $desc)
102        }
103    };
104
105    ($path:literal, $handler:expr, $methods:expr) => {
106        inventory::submit! {
107            $crate::WellKnownRoute {
108                path: $path,
109                handler_fn: $handler,
110                methods: $methods,
111            }
112        }
113    };
114}