The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(voice): add live voice provider registry and error types
Steven Enamakel64656a406e41
diff --git a/crates/openhuman-core/src/voice/live/error.rs b/crates/openhuman-core/src/voice/live/error.rsindex b09da4c456..fb0a7b9938 100644--- a/crates/openhuman-core/src/voice/live/error.rs+++ b/crates/openhuman-core/src/voice/live/error.rs@@ -4,13 +4,13 @@ use tinyagents_live::tinyliveagents::Error as LiveError;/// A failure with a stable, content-free `code` the UI can switch on.#[derive(Debug, Clone, PartialEq, Eq)]-pub(crate) struct LiveVoiceError {- pub(crate) code: &'static str,- pub(crate) message: String,+pub struct LiveVoiceError {+ pub code: &'static str,+ pub message: String,}impl LiveVoiceError {- pub(crate) fn new(code: &'static str, message: impl Into<String>) -> Self {+ pub fn new(code: &'static str, message: impl Into<String>) -> Self {Self {code,message: message.into(),@@ -18,22 +18,22 @@ impl LiveVoiceError {}/// The provider needs a key or sign-in it does not have.- pub(crate) fn not_configured(message: impl Into<String>) -> Self {+ pub fn not_configured(message: impl Into<String>) -> Self {Self::new("not_configured", message)}/// The request named something that does not exist.- pub(crate) fn invalid(message: impl Into<String>) -> Self {+ pub fn invalid(message: impl Into<String>) -> Self {Self::new("invalid_request", message)}/// The TinyHumans backend refused or failed.- pub(crate) fn backend(message: impl Into<String>) -> Self {+ pub fn backend(message: impl Into<String>) -> Self {Self::new("backend", message)}/// Something inside the core failed (agent build, config).- pub(crate) fn internal(message: impl Into<String>) -> Self {+ pub fn internal(message: impl Into<String>) -> Self {Self::new("internal", message)}}diff --git a/crates/openhuman-core/src/voice/live/mod.rs b/crates/openhuman-core/src/voice/live/mod.rsindex a72107a12f..a2c76dc4f8 100644--- a/crates/openhuman-core/src/voice/live/mod.rs+++ b/crates/openhuman-core/src/voice/live/mod.rs@@ -20,10 +20,13 @@ mod error;pub mod ops;mod persist;mod providers;+pub mod registry;pub mod schemas;mod session;pub mod types;#[cfg(feature = "http-server")]pub mod ws;+pub use error::LiveVoiceError;+pub use providers::PreparedProvider;pub use schemas::{live_controller_schemas, live_registered_controllers, live_schemas};diff --git a/crates/openhuman-core/src/voice/live/providers.rs b/crates/openhuman-core/src/voice/live/providers.rsindex 978094366f..0020c39e60 100644--- a/crates/openhuman-core/src/voice/live/providers.rs+++ b/crates/openhuman-core/src/voice/live/providers.rs@@ -81,6 +81,12 @@ fn strings(items: &[&str]) -> Vec<String> {/// The provider catalogue with each provider's readiness.pub(crate) fn provider_infos(config: &Config) -> Vec<LiveProviderInfo> {let hosted = backend_ready(config);+ let mut infos = built_in_provider_infos(config, hosted);+ super::registry::merge_provider_infos(&mut infos, config);+ infos+}++fn built_in_provider_infos(config: &Config, hosted: bool) -> Vec<LiveProviderInfo> {LIVE_PROVIDERS.iter().map(|id| {@@ -164,6 +170,7 @@ pub(crate) fn live_config(}_ => {}}+ super::registry::configure(config, provider, system_instruction, &mut live);live}@@ -172,9 +179,9 @@ fn non_empty(value: Option<String>) -> Option<String> {}/// A provider ready to connect, with the configuration it must connect with.-pub(crate) struct PreparedProvider {- pub(crate) provider: Box<dyn LiveProvider>,- pub(crate) config: LiveConfig,+pub struct PreparedProvider {+ pub provider: Box<dyn LiveProvider>,+ pub config: LiveConfig,}/// Resolves `provider` to something `tinyagents-live` can connect, minting a@@ -184,6 +191,9 @@ pub(crate) async fn prepare(provider: &str,mut live: LiveConfig,) -> Result<PreparedProvider, LiveVoiceError> {+ if let Some(prepared) = super::registry::prepare(config, provider, live.clone()).await {+ return prepared;+ }match provider {LIVE_PROVIDER_GEMINI_HOSTED => {let ticket = mint_gemini_ticket(config, &live).await?;diff --git a/crates/openhuman-core/src/voice/live/registry.rs b/crates/openhuman-core/src/voice/live/registry.rsnew file mode 100644index 0000000000..65790dcd73--- /dev/null+++ b/crates/openhuman-core/src/voice/live/registry.rs@@ -0,0 +1,130 @@+//! Registered live voice providers, keyed by provider slug.+//!+//! The built-in catalogue in [`super::providers`] covers the providers the+//! core can reach itself. An outside crate registers further ones here: each+//! entry says how the provider is listed, whether it is usable right now, how+//! a session's [`LiveConfig`] is shaped for it, and how to connect it.+//! [`prepare`](super::providers::prepare) asks this registry first, so a+//! registered slug wins over a built-in one; with nothing registered the+//! built-in behaviour is unchanged.++use std::future::Future;+use std::pin::Pin;+use std::sync::Arc;++use tinyagents_live::tinyliveagents::LiveConfig;++use super::error::LiveVoiceError;+use super::providers::PreparedProvider;+use super::types::{LiveProviderInfo, LiveProviderKind};+use crate::config::Config;+use crate::core::slots::HookSlot;++/// A boxed `Send` future, the shape a registered `prepare` returns.+pub type LiveFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;++/// Whether a registered provider is usable right now for `config`.+pub type ConfiguredFn = Arc<dyn Fn(&Config) -> bool + Send + Sync>;+/// Shapes a session's [`LiveConfig`] for a registered provider+/// (`config`, the system instruction, the live config to adjust).+pub type ConfigureFn = Arc<dyn Fn(&Config, &str, &mut LiveConfig) + Send + Sync>;+/// Connects a registered provider.+pub type PrepareFn = Arc<+ dyn Fn(Config, LiveConfig) -> LiveFuture<Result<PreparedProvider, LiveVoiceError>>+ + Send+ + Sync,+>;++/// One registered live provider.+#[derive(Clone)]+pub struct LiveProviderEntry {+ /// Display label.+ pub label: String,+ /// Hosted or bring-your-own-key.+ pub kind: LiveProviderKind,+ /// Voices the provider offers.+ pub voices: Vec<String>,+ /// Languages the provider speaks.+ pub languages: Vec<String>,+ /// The `provider:<slug>` key the provider reads, if any.+ pub key_slug: Option<String>,+ /// Whether the provider can be used right now.+ pub configured: ConfiguredFn,+ /// Optional per-session [`LiveConfig`] shaping.+ pub configure: Option<ConfigureFn>,+ /// Connects the provider.+ pub prepare: PrepareFn,+}++static LIVE_PROVIDERS: HookSlot<LiveProviderEntry> = HookSlot::new("voice::live::providers");++/// Registers the live provider `slug` for the whole process.+pub fn register_live_provider(slug: impl Into<String>, entry: LiveProviderEntry) {+ LIVE_PROVIDERS.register(slug, entry);+}++/// Registers the live provider `slug` for the context built from `extensions`.+pub fn register_live_provider_in(+ extensions: &crate::core::slots::Extensions,+ slug: impl Into<String>,+ entry: LiveProviderEntry,+) {+ LIVE_PROVIDERS.register_in(extensions, slug, entry);+}++/// Removes the process-wide live provider `slug`.+pub fn unregister_live_provider(slug: &str) -> bool {+ LIVE_PROVIDERS.unregister(slug)+}++/// Lists registered providers after the built-in ones; a registered slug that+/// is also built in replaces the built-in row in place.+pub(super) fn merge_provider_infos(infos: &mut Vec<LiveProviderInfo>, config: &Config) {+ for (slug, entry) in LIVE_PROVIDERS.entries() {+ let info = LiveProviderInfo {+ id: slug.clone(),+ label: entry.label.clone(),+ kind: entry.kind,+ configured: (entry.configured)(config),+ key_slug: entry.key_slug.clone(),+ voices: entry.voices.clone(),+ languages: entry.languages.clone(),+ };+ match infos.iter_mut().find(|existing| existing.id == slug) {+ Some(existing) => *existing = info,+ None => infos.push(info),+ }+ }+}++/// Applies a registered provider's [`LiveConfig`] shaping, if it has any.+pub(super) fn configure(+ config: &Config,+ provider: &str,+ system_instruction: &str,+ live: &mut LiveConfig,+) {+ if let Some(configure) = LIVE_PROVIDERS+ .get(provider)+ .and_then(|entry| entry.configure.clone())+ {+ tracing::debug!(provider, "[voice-live] shaping config via registered provider");+ configure(config, system_instruction, live);+ }+}++/// Connects the registered provider `provider`, or `None` when none is+/// registered under that slug.+pub(super) async fn prepare(+ config: &Config,+ provider: &str,+ live: LiveConfig,+) -> Option<Result<PreparedProvider, LiveVoiceError>> {+ let entry = LIVE_PROVIDERS.get(provider)?;+ tracing::debug!(provider, "[voice-live] preparing via registered provider");+ Some((entry.prepare)(config.clone(), live).await)+}++#[cfg(test)]+#[path = "registry_tests.rs"]+mod tests;