Skip to content

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

refactor(profiles): split profile controllers into typed parse and run functions

Steven Enamakel2e56be1d343a
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index 8ec4f87927..2637eeb2ce 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -661,10 +661,10 @@ fn build_registered_controllers() -> Vec<GroupedController> {
crate::agent_runs::all_orchestration_registered_controllers(),
);
// SaaS operator plane: provision and inspect user profiles.
- push(
+ push_entries(
&mut controllers,
DomainGroup::Operator,
- crate::profiles::all_profiles_registered_controllers(),
+ crate::profiles::schemas::all_profiles_controller_entries(),
);
controllers
}
diff --git a/crates/openhuman-core/src/profiles/schemas.rs b/crates/openhuman-core/src/profiles/schemas.rs
index 43b14e2880..f0801f5610 100644
--- a/crates/openhuman-core/src/profiles/schemas.rs
+++ b/crates/openhuman-core/src/profiles/schemas.rs
@@ -9,7 +9,9 @@ use serde::de::DeserializeOwned;
use serde::Deserialize;
use serde_json::{Map, Value};
-use crate::core::all::{ControllerFuture, RegisteredController};
+use crate::core::all::{
+ BoundRegisteredController, ControllerEntry, ControllerFuture, RegisteredController,
+};
use crate::core::Outcome;
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
@@ -79,6 +81,18 @@ pub fn all_profiles_registered_controllers() -> Vec<RegisteredController> {
]
}
+pub(crate) fn all_profiles_controller_entries() -> Vec<ControllerEntry> {
+ vec![
+ ControllerEntry::bound(provision_controller()),
+ ControllerEntry::bound(deprovision_controller()),
+ ControllerEntry::bound(list_controller()),
+ ControllerEntry::bound(status_controller()),
+ ControllerEntry::bound(set_credential_controller()),
+ ControllerEntry::bound(clear_credential_controller()),
+ ControllerEntry::bound(release_controller()),
+ ]
+}
+
pub fn profiles_schemas(function: &str) -> ControllerSchema {
match function {
"provision" => ControllerSchema {
@@ -189,34 +203,108 @@ pub fn profiles_schemas(function: &str) -> ControllerSchema {
}
}
-fn handle_provision(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let payload = deserialize_params::<UserParams>(params)?;
- to_json(super::ops::provision(&payload.user_id).await?)
- })
+fn provision_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(profiles_schemas("provision"), parse_user, run_provision)
}
-fn handle_deprovision(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let payload = deserialize_params::<ProfileParams>(params)?;
- to_json(super::ops::deprovision(&payload.profile_id).await?)
- })
+fn deprovision_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(
+ profiles_schemas("deprovision"),
+ parse_profile,
+ run_deprovision,
+ )
+}
+
+fn list_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(profiles_schemas("list"), parse_list, run_list)
+}
+
+fn status_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(profiles_schemas("status"), parse_profile, run_status)
+}
+
+fn set_credential_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(
+ profiles_schemas("set_credential"),
+ parse_credential,
+ run_set_credential,
+ )
+}
+
+fn clear_credential_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(
+ profiles_schemas("clear_credential"),
+ parse_profile,
+ run_clear_credential,
+ )
+}
+
+fn release_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(profiles_schemas("release"), parse_profile, run_release)
+}
+
+fn handle_provision(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ provision_controller().invoke(ctx, params)
+}
+
+fn handle_deprovision(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ deprovision_controller().invoke(ctx, params)
+}
+
+fn handle_list(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ list_controller().invoke(ctx, params)
+}
+
+fn handle_status(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ status_controller().invoke(ctx, params)
+}
+
+fn handle_set_credential(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ set_credential_controller().invoke(ctx, params)
+}
+
+fn handle_clear_credential(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ clear_credential_controller().invoke(ctx, params)
+}
+
+fn handle_release(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ release_controller().invoke(ctx, params)
+}
+
+fn parse_user(params: Map<String, Value>) -> Result<UserParams, String> {
+ deserialize_params(params)
+}
+
+fn parse_profile(params: Map<String, Value>) -> Result<ProfileParams, String> {
+ deserialize_params(params)
+}
+
+fn parse_list(_params: Map<String, Value>) -> Result<(), String> {
+ Ok(())
}
-fn handle_list(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+fn parse_credential(params: Map<String, Value>) -> Result<CredentialParams, String> {
+ deserialize_params(params)
+}
+
+fn run_provision(_ctx: DispatchCtx, payload: UserParams) -> ControllerFuture {
+ Box::pin(async move { to_json(super::ops::provision(&payload.user_id).await?) })
+}
+
+fn run_deprovision(_ctx: DispatchCtx, payload: ProfileParams) -> ControllerFuture {
+ Box::pin(async move { to_json(super::ops::deprovision(&payload.profile_id).await?) })
+}
+
+fn run_list(_ctx: DispatchCtx, (): ()) -> ControllerFuture {
Box::pin(async move { to_json(super::ops::list().await?) })
}
-fn handle_status(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let payload = deserialize_params::<ProfileParams>(params)?;
- to_json(super::ops::status(&payload.profile_id).await?)
- })
+fn run_status(_ctx: DispatchCtx, payload: ProfileParams) -> ControllerFuture {
+ Box::pin(async move { to_json(super::ops::status(&payload.profile_id).await?) })
}
-fn handle_set_credential(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn run_set_credential(_ctx: DispatchCtx, payload: CredentialParams) -> ControllerFuture {
Box::pin(async move {
- let payload = deserialize_params::<CredentialParams>(params)?;
to_json(
super::ops::set_credential(
&payload.profile_id,
@@ -229,18 +317,12 @@ fn handle_set_credential(_ctx: DispatchCtx, params: Map<String, Value>) -> Contr
})
}
-fn handle_clear_credential(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let payload = deserialize_params::<ProfileParams>(params)?;
- to_json(super::ops::clear_credential(&payload.profile_id).await?)
- })
+fn run_clear_credential(_ctx: DispatchCtx, payload: ProfileParams) -> ControllerFuture {
+ Box::pin(async move { to_json(super::ops::clear_credential(&payload.profile_id).await?) })
}
-fn handle_release(_ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let payload = deserialize_params::<ProfileParams>(params)?;
- to_json(super::ops::release(&payload.profile_id).await?)
- })
+fn run_release(_ctx: DispatchCtx, payload: ProfileParams) -> ControllerFuture {
+ Box::pin(async move { to_json(super::ops::release(&payload.profile_id).await?) })
}
fn deserialize_params<T: DeserializeOwned>(params: Map<String, Value>) -> Result<T, String> {