Skip to content

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

feat(voice): re-export gemini voice constants and hosted provider ids

Steven Enamakel20c379f4e5c7
diff --git a/crates/openhuman-core/src/voice/live/mod.rs b/crates/openhuman-core/src/voice/live/mod.rs
index a2c76dc4f8..88257b6bde 100644
--- a/crates/openhuman-core/src/voice/live/mod.rs
+++ b/crates/openhuman-core/src/voice/live/mod.rs
@@ -28,5 +28,5 @@ pub mod types;
pub mod ws;
pub use error::LiveVoiceError;
-pub use providers::PreparedProvider;
+pub use providers::{PreparedProvider, GEMINI_LANGUAGES, GEMINI_VOICES};
pub use schemas::{live_controller_schemas, live_registered_controllers, live_schemas};
diff --git a/crates/openhuman-embed/src/host_internals.rs b/crates/openhuman-embed/src/host_internals.rs
index 3853f5599c..5f178bb2ea 100644
--- a/crates/openhuman-embed/src/host_internals.rs
+++ b/crates/openhuman-embed/src/host_internals.rs
@@ -370,8 +370,13 @@ pub mod voice_registry {
register_live_provider, register_live_provider_in, unregister_live_provider, ConfigureFn,
ConfiguredFn, LiveFuture, LiveProviderEntry, PrepareFn,
};
+ pub use openhuman_core::config::schema::voice_live::{
+ LIVE_PROVIDER_ELEVENLABS_HOSTED, LIVE_PROVIDER_GEMINI_HOSTED,
+ };
pub use openhuman_core::voice::live::types::{LiveProviderInfo, LiveProviderKind};
- pub use openhuman_core::voice::live::{LiveVoiceError, PreparedProvider};
+ pub use openhuman_core::voice::live::{
+ LiveVoiceError, PreparedProvider, GEMINI_LANGUAGES, GEMINI_VOICES,
+ };
}
// The rest is the rpc server alone.
diff --git a/crates/openhuman-tinyhumans/src/voice/live.rs b/crates/openhuman-tinyhumans/src/voice/live.rs
new file mode 100644
index 0000000000..6887c3fb4d
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/voice/live.rs
@@ -0,0 +1,182 @@
+//! The hosted live voice providers: `gemini-hosted` and `elevenlabs-hosted`.
+//!
+//! Both are reached through the TinyHumans backend. Minting the Gemini Live
+//! relay ticket and the ElevenLabs signed URL happens here, against the
+//! backend, because `tinyliveagents` deliberately holds no backend or
+//! credential code. They register with the core's live-provider registry
+//! ([`register`]); the core carries no hosted entry of its own.
+
+use openhuman_embed::__host::config::Config;
+use openhuman_embed::__host::security::credentials::session_support::resolve_backend_credential;
+use openhuman_embed::__host::voice_registry::{
+ register_live_provider, LiveProviderEntry, LiveProviderKind, LiveVoiceError, PreparedProvider,
+ GEMINI_LANGUAGES, GEMINI_VOICES, LIVE_PROVIDER_ELEVENLABS_HOSTED, LIVE_PROVIDER_GEMINI_HOSTED,
+};
+use reqwest::Method;
+use serde_json::{json, Value};
+use std::sync::Arc;
+use tinyagents_live::tinyliveagents::elevenlabs::ElevenLabsConvai;
+use tinyagents_live::tinyliveagents::gemini::{self, GeminiRelay};
+use tinyagents_live::tinyliveagents::LiveConfig;
+
+use super::realtime::{ensure_secure_backend_url, mint_voice_agent_signed_url};
+use crate::client::{flatten_authed_error, BackendClient};
+
+const LOG_PREFIX: &str = "[voice-live]";
+
+/// The backend route that mints a Gemini Live relay ticket.
+pub(crate) const GEMINI_LIVE_SESSIONS_PATH: &str = "/agent-integrations/gemini/live/sessions";
+
+fn strings(items: &[&str]) -> Vec<String> {
+ items.iter().map(|s| (*s).to_string()).collect()
+}
+
+fn non_empty(value: Option<String>) -> Option<String> {
+ value.filter(|v| !v.trim().is_empty())
+}
+
+/// Whether a backend credential is available for the hosted providers.
+fn backend_ready(config: &Config) -> bool {
+ resolve_backend_credential(config).is_ok()
+}
+
+/// Shapes the session configuration for `gemini-hosted` from the user's settings.
+pub(crate) fn configure_gemini(config: &Config, system_instruction: &str, live: &mut LiveConfig) {
+ let settings = &config.voice_live;
+ live.system_instruction = Some(system_instruction.to_string());
+ live.model = settings.gemini.model.clone();
+ live.voice = settings.gemini.voice.clone();
+ live.language = settings.gemini.language.clone();
+ // Keep long conversations inside the context window.
+ live.provider_options = json!({ "context_window_compression": { "slidingWindow": {} } });
+}
+
+/// Shapes the session configuration for `elevenlabs-hosted`.
+pub(crate) fn configure_elevenlabs(config: &Config, _system_instruction: &str, live: &mut LiveConfig) {
+ // The hosted agent owns its prompt and its brain (OpenHuman over the
+ // Custom-LLM relay); only the voice may be overridden.
+ live.voice = non_empty(config.voice_live.elevenlabs.voice_id.clone());
+}
+
+/// A minted relay ticket.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub(crate) struct GeminiTicket {
+ pub(crate) ws_url: String,
+ pub(crate) session_id: String,
+ pub(crate) model: String,
+}
+
+/// Parses the backend's ticket response (`data`-wrapped or bare).
+pub(crate) fn parse_ticket(raw: &Value) -> Result<GeminiTicket, LiveVoiceError> {
+ let data = raw.get("data").unwrap_or(raw);
+ let field = |name: &str| {
+ data.get(name)
+ .and_then(Value::as_str)
+ .filter(|v| !v.is_empty())
+ .map(str::to_string)
+ };
+ let ws_url = field("wsUrl").ok_or_else(|| {
+ LiveVoiceError::backend("backend returned no wsUrl for the live session".to_string())
+ })?;
+ Ok(GeminiTicket {
+ ws_url,
+ session_id: field("sessionId").unwrap_or_default(),
+ model: field("model").unwrap_or_default(),
+ })
+}
+
+async fn mint_gemini_ticket(
+ config: &Config,
+ live: &LiveConfig,
+) -> Result<GeminiTicket, LiveVoiceError> {
+ let credential = resolve_backend_credential(config).map_err(LiveVoiceError::not_configured)?;
+ let client =
+ BackendClient::from_config(config).map_err(|e| LiveVoiceError::backend(e.to_string()))?;
+ ensure_secure_backend_url(client.base_url()).map_err(LiveVoiceError::backend)?;
+ let body = gemini::ticket_request(live);
+ let raw = client
+ .authed_json(
+ &credential,
+ Method::POST,
+ GEMINI_LIVE_SESSIONS_PATH,
+ Some(body),
+ )
+ .await
+ .map_err(|error| LiveVoiceError::backend(flatten_authed_error(error)))?;
+ parse_ticket(&raw)
+}
+
+/// Connects `gemini-hosted`: mints a relay ticket and points a relay at it.
+pub(crate) async fn prepare_gemini(
+ config: Config,
+ live: LiveConfig,
+) -> Result<PreparedProvider, LiveVoiceError> {
+ let ticket = mint_gemini_ticket(&config, &live).await?;
+ log::debug!(
+ "{LOG_PREFIX} minted gemini live ticket session={} model={}",
+ ticket.session_id,
+ ticket.model
+ );
+ let relay =
+ GeminiRelay::connect_url(ticket.ws_url).with_session(ticket.session_id, ticket.model);
+ Ok(PreparedProvider {
+ provider: Box::new(relay),
+ config: live,
+ })
+}
+
+/// Connects `elevenlabs-hosted`: mints a signed agent URL.
+pub(crate) async fn prepare_elevenlabs(
+ config: Config,
+ mut live: LiveConfig,
+) -> Result<PreparedProvider, LiveVoiceError> {
+ let signed = mint_voice_agent_signed_url(&config)
+ .await
+ .map_err(LiveVoiceError::backend)?
+ .value;
+ // `user_token` is the identity the backend's Custom-LLM relay verifies on
+ // every relayed turn (#5399).
+ live.provider_options = json!({
+ "user_id": signed.user_token,
+ "custom_llm_extra_body": { "user": signed.user_token },
+ });
+ Ok(PreparedProvider {
+ provider: Box::new(ElevenLabsConvai::connect_url(signed.signed_url)),
+ config: live,
+ })
+}
+
+/// Registers both hosted live providers under their configured ids.
+pub(super) fn register() {
+ register_live_provider(
+ LIVE_PROVIDER_GEMINI_HOSTED,
+ LiveProviderEntry {
+ label: "Gemini Live (TinyHumans)".to_string(),
+ kind: LiveProviderKind::Hosted,
+ voices: strings(GEMINI_VOICES),
+ languages: strings(GEMINI_LANGUAGES),
+ key_slug: None,
+ configured: Arc::new(backend_ready),
+ configure: Some(Arc::new(configure_gemini)),
+ prepare: Arc::new(|config, live| Box::pin(prepare_gemini(config, live))),
+ },
+ );
+ register_live_provider(
+ LIVE_PROVIDER_ELEVENLABS_HOSTED,
+ LiveProviderEntry {
+ label: "ElevenLabs Agent (TinyHumans)".to_string(),
+ kind: LiveProviderKind::Hosted,
+ voices: Vec::new(),
+ languages: Vec::new(),
+ key_slug: None,
+ configured: Arc::new(backend_ready),
+ configure: Some(Arc::new(configure_elevenlabs)),
+ prepare: Arc::new(|config, live| Box::pin(prepare_elevenlabs(config, live))),
+ },
+ );
+ log::debug!("{LOG_PREFIX} registered hosted live providers");
+}
+
+#[cfg(test)]
+#[path = "live_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-tinyhumans/src/voice/live_tests.rs b/crates/openhuman-tinyhumans/src/voice/live_tests.rs
new file mode 100644
index 0000000000..7355b01570
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/voice/live_tests.rs
@@ -0,0 +1,69 @@
+use super::*;
+use openhuman_embed::__host::voice_registry::unregister_live_provider;
+
+#[test]
+fn parses_wrapped_and_bare_tickets() {
+ let wrapped = json!({"data": {"wsUrl": "wss://x/ws?ticket=t", "sessionId": "s", "model": "m"}});
+ assert_eq!(
+ parse_ticket(&wrapped).unwrap(),
+ GeminiTicket {
+ ws_url: "wss://x/ws?ticket=t".into(),
+ session_id: "s".into(),
+ model: "m".into()
+ }
+ );
+ let bare = json!({"wsUrl": "wss://y"});
+ assert_eq!(parse_ticket(&bare).unwrap().session_id, "");
+ assert_eq!(
+ parse_ticket(&json!({"data": {}})).unwrap_err().code,
+ "backend"
+ );
+}
+
+#[test]
+fn gemini_hosted_config_follows_the_settings() {
+ let mut config = Config::default();
+ config.voice_live.gemini.voice = Some("Kore".into());
+ config.voice_live.gemini.model = Some("gemini-x".into());
+ let mut live = LiveConfig::new();
+ configure_gemini(&config, "prompt", &mut live);
+ assert_eq!(live.system_instruction.as_deref(), Some("prompt"));
+ assert_eq!(live.voice.as_deref(), Some("Kore"));
+ assert_eq!(live.model.as_deref(), Some("gemini-x"));
+ assert!(live
+ .provider_options
+ .get("context_window_compression")
+ .is_some());
+}
+
+#[test]
+fn elevenlabs_hosted_config_owns_its_prompt_and_ignores_blank_voices() {
+ let mut config = Config::default();
+ config.voice_live.elevenlabs.voice_id = Some(" ".into());
+ let mut live = LiveConfig::new();
+ configure_elevenlabs(&config, "prompt", &mut live);
+ assert_eq!(live.system_instruction, None, "the hosted agent owns its prompt");
+ assert_eq!(live.voice, None, "blank voice ids are ignored");
+ config.voice_live.elevenlabs.voice_id = Some("v1".into());
+ configure_elevenlabs(&config, "prompt", &mut live);
+ assert_eq!(live.voice.as_deref(), Some("v1"));
+}
+
+#[test]
+fn registration_lists_both_hosted_providers_as_hosted() {
+ register();
+ let config = Config::default();
+ let infos = openhuman_embed::__host::voice_registry::provider_infos(&config);
+ for id in [LIVE_PROVIDER_GEMINI_HOSTED, LIVE_PROVIDER_ELEVENLABS_HOSTED] {
+ let info = infos.iter().find(|i| i.id == id).expect(id);
+ assert_eq!(info.kind, LiveProviderKind::Hosted, "{id}");
+ assert_eq!(info.key_slug, None, "{id}");
+ }
+ let gemini = infos
+ .iter()
+ .find(|i| i.id == LIVE_PROVIDER_GEMINI_HOSTED)
+ .unwrap();
+ assert!(gemini.voices.contains(&"Puck".to_string()));
+ unregister_live_provider(LIVE_PROVIDER_GEMINI_HOSTED);
+ unregister_live_provider(LIVE_PROVIDER_ELEVENLABS_HOSTED);
+}