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