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