Skip to content

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

refactor(voice): update voice controller entry registration

Steven Enamakel049f1d7c9088
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index e0ced0cfcc..94e5be8b95 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -594,10 +594,10 @@ fn build_registered_controllers() -> Vec<GroupedController> {
);
// Voice transcription and synthesis (gated behind the `voice` feature).
#[cfg(feature = "voice")]
- push(
+ push_entries(
&mut controllers,
DomainGroup::Voice,
- crate::voice::all_voice_registered_controllers(),
+ crate::voice::all_voice_controller_entries(),
);
// Webhook tunnel management
push(
diff --git a/crates/openhuman-core/src/voice/live/schemas.rs b/crates/openhuman-core/src/voice/live/schemas.rs
index 2688c32660..98d8570a1c 100644
--- a/crates/openhuman-core/src/voice/live/schemas.rs
+++ b/crates/openhuman-core/src/voice/live/schemas.rs
@@ -9,7 +9,10 @@ use serde_json::{Map, Value};
use super::ops;
use super::types::LiveSettingsPatch;
-use crate::core::all::{ControllerFuture, RegisteredController};
+use crate::config::Config;
+use crate::core::all::{
+ BoundRegisteredController, ControllerEntry, ControllerFuture, ControllerTask, RegisteredController,
+};
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
fn json_output(name: &'static str, comment: &'static str) -> FieldSchema {
@@ -117,31 +120,77 @@ struct TestParams {
provider: String,
}
-fn handle_live_providers(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+fn load_config(ctx: DispatchCtx) -> ControllerTask<Config> {
+ Box::pin(async move { ctx.load_config().await })
+}
+
+fn ignored_params(_params: Map<String, Value>) -> Result<(), String> {
+ Ok(())
+}
+
+fn live_providers_controller() -> BoundRegisteredController {
+ BoundRegisteredController::after_gate(
+ live_schemas("voice_live_providers"),
+ load_config,
+ ignored_params,
+ run_live_providers,
+ )
+}
+
+fn live_settings_get_controller() -> BoundRegisteredController {
+ BoundRegisteredController::after_gate(
+ live_schemas("voice_live_settings_get"),
+ load_config,
+ ignored_params,
+ run_live_settings_get,
+ )
+}
+
+fn live_settings_set_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(
+ live_schemas("voice_live_settings_set"),
+ parse_params::<LiveSettingsPatch>,
+ run_live_settings_set,
+ )
+}
+
+fn live_test_provider_controller() -> BoundRegisteredController {
+ BoundRegisteredController::typed(
+ live_schemas("voice_live_test_provider"),
+ parse_params::<TestParams>,
+ run_live_test_provider,
+ )
+}
+
+fn run_live_providers(
+ _ctx: DispatchCtx,
+ config: Config,
+ (): (),
+) -> ControllerFuture {
Box::pin(async move {
- let config = ctx.load_config().await?;
to_value(ops::live_providers(&config).value)
})
}
-fn handle_live_settings_get(ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+fn run_live_settings_get(
+ _ctx: DispatchCtx,
+ config: Config,
+ (): (),
+) -> ControllerFuture {
Box::pin(async move {
- let config = ctx.load_config().await?;
to_value(ops::live_settings_get(&config).value)
})
}
-fn handle_live_settings_set(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn run_live_settings_set(ctx: DispatchCtx, patch: LiveSettingsPatch) -> ControllerFuture {
Box::pin(async move {
- let patch = parse_params::<LiveSettingsPatch>(params)?;
let mut config = ctx.load_config().await?;
to_value(ops::live_settings_set(&mut config, patch).await?.value)
})
}
-fn handle_live_test_provider(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+fn run_live_test_provider(ctx: DispatchCtx, params: TestParams) -> ControllerFuture {
Box::pin(async move {
- let params = parse_params::<TestParams>(params)?;
let config = ctx.load_config().await?;
to_value(
ops::live_test_provider(&config, &params.provider)
@@ -151,6 +200,34 @@ fn handle_live_test_provider(ctx: DispatchCtx, params: Map<String, Value>) -> Co
})
}
+pub(crate) fn bound_live_controller_entries() -> Vec<ControllerEntry> {
+ vec![
+ live_providers_controller(),
+ live_settings_get_controller(),
+ live_settings_set_controller(),
+ live_test_provider_controller(),
+ ]
+ .into_iter()
+ .map(ControllerEntry::bound)
+ .collect()
+}
+
+fn handle_live_providers(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ live_providers_controller().invoke(ctx, params)
+}
+
+fn handle_live_settings_get(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ live_settings_get_controller().invoke(ctx, params)
+}
+
+fn handle_live_settings_set(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ live_settings_set_controller().invoke(ctx, params)
+}
+
+fn handle_live_test_provider(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {
+ live_test_provider_controller().invoke(ctx, params)
+}
+
/// Every live voice controller.
pub fn live_registered_controllers() -> Vec<RegisteredController> {
vec![
diff --git a/crates/openhuman-core/src/voice/schemas/registry.rs b/crates/openhuman-core/src/voice/schemas/registry.rs
index d659d0947e..2327a0eea5 100644
--- a/crates/openhuman-core/src/voice/schemas/registry.rs
+++ b/crates/openhuman-core/src/voice/schemas/registry.rs
@@ -103,7 +103,7 @@ pub(crate) fn all_voice_controller_entries() -> Vec<ControllerEntry> {
]
.into_iter()
.map(ControllerEntry::bound)
- .chain(crate::voice::live::bound_live_controller_entries())
+ .chain(crate::voice::live::schemas::bound_live_controller_entries())
.collect()
}