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;
30mod registry;
31pub mod services_reconcile;
32mod startup_validation;
33mod validation;
34mod wellknown;
35
36pub use builder::{AppContextBuilder, discover_models};
37pub use context::{AppContext, ConfigPlane, DataPlane, Plugins, ShutdownRequest, Subsystems};
38pub use database_context::DatabaseContext;
39pub use error::{RuntimeError, RuntimeResult};
40pub use registry::{ModuleApiRegistration, ModuleApiRegistry, ModuleType, WellKnownRoute};
41pub use startup_validation::{
42    ExtensionConfigOutcome, FilesConfigValidator, StartupValidator, collect_manifest_errors,
43    display_validation_report, display_validation_warnings, merge_mcp_errors,
44    validate_extension_configs,
45};
46pub use systemprompt_database::MigrationConfig;
47pub use validation::{validate_database_path, validate_system};
48pub use wellknown::{WellKnownMetadata, get_wellknown_metadata};
49
50pub use systemprompt_models::modules::ServiceCategory;
51
52#[macro_export]
53macro_rules! register_module_api {
54    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr, $module_type:expr) => {
55        inventory::submit! {
56            $crate::ModuleApiRegistration {
57                module_name: $module_name,
58                category: $category,
59                module_type: $module_type,
60                router_fn: $router_fn,
61                auth_required: $auth_required,
62            }
63        }
64    };
65    ($module_name:literal, $category:expr, $router_fn:expr, $auth_required:expr) => {
66        inventory::submit! {
67            $crate::ModuleApiRegistration {
68                module_name: $module_name,
69                category: $category,
70                module_type: $crate::ModuleType::Regular,
71                router_fn: $router_fn,
72                auth_required: $auth_required,
73            }
74        }
75    };
76}
77
78#[macro_export]
79macro_rules! register_wellknown_route {
80    ($path:literal, $handler:expr, $methods:expr, name: $name:literal, description: $desc:literal) => {
81        inventory::submit! {
82            $crate::WellKnownRoute {
83                path: $path,
84                handler_fn: $handler,
85                methods: $methods,
86            }
87        }
88
89        inventory::submit! {
90            $crate::WellKnownMetadata::new($path, $name, $desc)
91        }
92    };
93
94    ($path:literal, $handler:expr, $methods:expr) => {
95        inventory::submit! {
96            $crate::WellKnownRoute {
97                path: $path,
98                handler_fn: $handler,
99                methods: $methods,
100            }
101        }
102    };
103}