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