Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(doctor): use controller entries instead of registered controllers

Steven Enamakelb627cc50cad7
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index caea1dc0d1..4a93cc53db 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -370,10 +370,10 @@ fn build_registered_controllers() -> Vec<GroupedController> {
crate::core::subsystem::all_subsystems_registered_controllers(),
);
// Diagnostic tools
- push(
+ push_entries(
&mut controllers,
DomainGroup::Platform,
- crate::platform::doctor::all_doctor_registered_controllers(),
+ crate::platform::doctor::all_doctor_controller_entries(),
);
// User-authored hooks — inspect, reload, and test-fire `hooks.json` entries.
push(
diff --git a/crates/openhuman-core/src/platform/doctor/mod.rs b/crates/openhuman-core/src/platform/doctor/mod.rs
index 7c6fbc8f18..a7ba45534a 100644
--- a/crates/openhuman-core/src/platform/doctor/mod.rs
+++ b/crates/openhuman-core/src/platform/doctor/mod.rs
@@ -12,6 +12,7 @@ pub use schemas::{
all_controller_schemas as all_doctor_controller_schemas,
all_registered_controllers as all_doctor_registered_controllers,
};
+pub(crate) use schemas::all_controller_entries as all_doctor_controller_entries;
#[cfg(test)]
pub(crate) use schemas::doctor_parameter_contracts;
diff --git a/crates/openhuman-core/src/platform/doctor/schemas.rs b/crates/openhuman-core/src/platform/doctor/schemas.rs
index c6bc6e65c0..884abf4cc7 100644
--- a/crates/openhuman-core/src/platform/doctor/schemas.rs
+++ b/crates/openhuman-core/src/platform/doctor/schemas.rs
@@ -2,7 +2,11 @@ use crate::core::runtime::DispatchCtx;
use serde::de::DeserializeOwned;
use serde_json::{Map, Value};
-use crate::core::all::{ControllerFuture, RegisteredController};
+use crate::config::Config;
+use crate::core::all::{
+ BoundRegisteredController, ControllerEntry, ControllerFuture, ControllerTask,
+ RegisteredController,
+};
use crate::core::Outcome;
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
@@ -23,6 +27,13 @@ pub fn all_registered_controllers() -> Vec<RegisteredController> {
]
}
+pub(crate) fn all_controller_entries() -> Vec<ControllerEntry> {
+ vec![
+ ControllerEntry::bound(report_controller()),
+ ControllerEntry::bound(models_controller()),
+ ]
+}
+
#[cfg(test)]
pub(crate) fn doctor_parameter_contracts() -> Vec<crate::core::all::ControllerParamContract> {
tests::doctor_parameter_contracts()
@@ -75,16 +86,51 @@ pub fn schemas(function: &str) -> ControllerSchema {
}
fn handle_report(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+ report_controller().invoke(ctx, _params)
+}
+
+fn handle_models(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ models_controller().invoke(ctx, params)
+}
+
+fn report_controller() -> BoundRegisteredController {
+ BoundRegisteredController::after_gate(
+ schemas("report"),
+ load_config,
+ parse_report,
+ run_report,
+ )
+}
+
+fn models_controller() -> BoundRegisteredController {
+ BoundRegisteredController::after_gate(
+ schemas("models"),
+ load_config,
+ parse_models,
+ run_models,
+ )
+}
+
+fn load_config(ctx: DispatchCtx) -> ControllerTask<Config> {
+ Box::pin(async move { ctx.load_config().await })
+}
+
+fn parse_report(_params: Map<String, Value>) -> Result<(), String> {
+ Ok(())
+}
+
+fn parse_models(params: Map<String, Value>) -> Result<bool, String> {
+ Ok(read_optional::<bool>(&params, "use_cache")?.unwrap_or(true))
+}
+
+fn run_report(_ctx: DispatchCtx, config: Config, (): ()) -> ControllerFuture {
Box::pin(async move {
- let config = ctx.load_config().await?;
to_json(crate::platform::doctor::rpc::doctor_report(&config).await?)
})
}
-fn handle_models(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn run_models(_ctx: DispatchCtx, config: Config, use_cache: bool) -> ControllerFuture {
Box::pin(async move {
- let config = ctx.load_config().await?;
- let use_cache = read_optional::<bool>(&params, "use_cache")?.unwrap_or(true);
to_json(crate::platform::doctor::rpc::doctor_models(&config, use_cache).await?)
})
}