Skip to content

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

fix: preserve partial live voice settings

Steven Enamakel4d21525b3df5
diff --git a/app/src/lib/i18n/zh-CN.ts b/app/src/lib/i18n/zh-CN.ts
index db9a22833e..3817b8940d 100644
--- a/app/src/lib/i18n/zh-CN.ts
+++ b/app/src/lib/i18n/zh-CN.ts
@@ -4965,7 +4965,7 @@ const messages: TranslationMap = {
'connections.voiceAgents.keySaved': '密钥已保存。',
'connections.voiceAgents.keyCleared': '密钥已移除。',
'connections.voiceAgents.voice': '音色',
- 'connections.voiceAgents.speaker': '播音员',
+ 'connections.voiceAgents.speaker': '发音人',
'connections.voiceAgents.language': '语言',
'connections.voiceAgents.providerDefault': '提供方默认',
'connections.voiceAgents.loadFailed': '无法加载语音助手设置',
diff --git a/crates/openhuman-core/src/voice/live/ops.rs b/crates/openhuman-core/src/voice/live/ops.rs
index 5a1c75b4de..11e6156864 100644
--- a/crates/openhuman-core/src/voice/live/ops.rs
+++ b/crates/openhuman-core/src/voice/live/ops.rs
@@ -7,7 +7,10 @@ use tinyagents_live::tinyliveagents::LiveEvent;
use super::error::LiveVoiceError;
use super::providers;
use super::session;
-use super::types::{LiveProvidersResponse, LiveSettingsPatch, LiveTestResult, LiveVoiceConfig};
+use super::types::{
+ ElevenLabsLiveSettingsPatch, GeminiLiveSettingsPatch, LiveProvidersResponse, LiveSettingsPatch,
+ LiveTestResult, LiveVoiceConfig, SarvamLiveSettingsPatch,
+};
use crate::config::schema::voice_live::is_live_provider;
use crate::config::Config;
use crate::core::Outcome;
@@ -40,17 +43,49 @@ pub(crate) fn apply_patch(config: &mut Config, patch: LiveSettingsPatch) -> Resu
config.voice_live.default_provider = provider;
}
if let Some(gemini) = patch.gemini {
- config.voice_live.gemini = gemini;
+ merge_gemini(&mut config.voice_live.gemini, gemini);
}
if let Some(sarvam) = patch.sarvam {
- config.voice_live.sarvam = sarvam;
+ merge_sarvam(&mut config.voice_live.sarvam, sarvam);
}
if let Some(elevenlabs) = patch.elevenlabs {
- config.voice_live.elevenlabs = elevenlabs;
+ if let Some(value) = elevenlabs.voice_id {
+ config.voice_live.elevenlabs.voice_id = value;
+ }
}
Ok(())
}
+fn merge_gemini(
+ settings: &mut crate::config::schema::voice_live::GeminiLiveSettings,
+ patch: GeminiLiveSettingsPatch,
+) {
+ if let Some(value) = patch.model {
+ settings.model = value;
+ }
+ if let Some(value) = patch.voice {
+ settings.voice = value;
+ }
+ if let Some(value) = patch.language {
+ settings.language = value;
+ }
+}
+
+fn merge_sarvam(
+ settings: &mut crate::config::schema::voice_live::SarvamLiveSettings,
+ patch: SarvamLiveSettingsPatch,
+) {
+ if let Some(value) = patch.language {
+ settings.language = value;
+ }
+ if let Some(value) = patch.speaker {
+ settings.speaker = value;
+ }
+ if let Some(value) = patch.model {
+ settings.model = value;
+ }
+}
+
/// Updates and saves the live voice settings.
pub async fn live_settings_set(
config: &mut Config,
diff --git a/crates/openhuman-core/src/voice/live/ops_tests.rs b/crates/openhuman-core/src/voice/live/ops_tests.rs
index 723639d44b..7d86aba60f 100644
--- a/crates/openhuman-core/src/voice/live/ops_tests.rs
+++ b/crates/openhuman-core/src/voice/live/ops_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::config::schema::voice_live::{SarvamLiveSettings, LIVE_PROVIDER_SARVAM};
+use crate::config::schema::voice_live::LIVE_PROVIDER_SARVAM;
#[test]
fn providers_and_settings_reflect_the_config() {
@@ -21,10 +21,9 @@ fn patches_apply_only_the_given_fields_and_validate_ids() {
&mut config,
LiveSettingsPatch {
default_provider: Some(LIVE_PROVIDER_SARVAM.into()),
- sarvam: Some(SarvamLiveSettings {
- language: Some("hi-IN".into()),
- speaker: None,
- model: None,
+ sarvam: Some(SarvamLiveSettingsPatch {
+ language: Some(Some("hi-IN".into())),
+ ..SarvamLiveSettingsPatch::default()
}),
..LiveSettingsPatch::default()
},
@@ -36,7 +35,7 @@ fn patches_apply_only_the_given_fields_and_validate_ids() {
apply_patch(
&mut config,
LiveSettingsPatch {
- gemini: Some(Default::default()),
+ gemini: Some(GeminiLiveSettingsPatch::default()),
elevenlabs: Some(Default::default()),
..LiveSettingsPatch::default()
},
@@ -53,6 +52,49 @@ fn patches_apply_only_the_given_fields_and_validate_ids() {
assert!(err.contains("nope"));
}
+#[test]
+fn provider_patches_preserve_omitted_fields_and_clear_explicit_nulls() {
+ let mut config = Config::default();
+ apply_patch(
+ &mut config,
+ LiveSettingsPatch {
+ gemini: Some(GeminiLiveSettingsPatch {
+ voice: Some(Some("Puck".into())),
+ ..Default::default()
+ }),
+ ..Default::default()
+ },
+ )
+ .unwrap();
+ apply_patch(
+ &mut config,
+ LiveSettingsPatch {
+ gemini: Some(GeminiLiveSettingsPatch {
+ language: Some(Some("en-US".into())),
+ ..Default::default()
+ }),
+ ..Default::default()
+ },
+ )
+ .unwrap();
+ assert_eq!(config.voice_live.gemini.voice.as_deref(), Some("Puck"));
+ assert_eq!(config.voice_live.gemini.language.as_deref(), Some("en-US"));
+
+ apply_patch(
+ &mut config,
+ LiveSettingsPatch {
+ gemini: Some(GeminiLiveSettingsPatch {
+ voice: Some(None),
+ ..Default::default()
+ }),
+ ..Default::default()
+ },
+ )
+ .unwrap();
+ assert_eq!(config.voice_live.gemini.voice, None);
+ assert_eq!(config.voice_live.gemini.language.as_deref(), Some("en-US"));
+}
+
#[tokio::test]
async fn settings_set_saves_to_disk() {
let dir = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/voice/live/session.rs b/crates/openhuman-core/src/voice/live/session.rs
index 467d6244ba..2a65d6a838 100644
--- a/crates/openhuman-core/src/voice/live/session.rs
+++ b/crates/openhuman-core/src/voice/live/session.rs
@@ -142,7 +142,13 @@ pub(crate) async fn start(
thread_id.clone(),
)
.await
- .unwrap_or_default();
+ .unwrap_or_else(|error| {
+ tracing::warn!(
+ session_id,
+ "[voice-live] could not load thread context: {error}"
+ );
+ Vec::new()
+ });
let mut live = providers::live_config(
&config,
&provider,
diff --git a/crates/openhuman-core/src/voice/live/types.rs b/crates/openhuman-core/src/voice/live/types.rs
index b747362903..a5ccce77ce 100644
--- a/crates/openhuman-core/src/voice/live/types.rs
+++ b/crates/openhuman-core/src/voice/live/types.rs
@@ -1,6 +1,6 @@
//! Wire types for live voice sessions: RPC payloads and WebSocket frames.
-use serde::{Deserialize, Serialize};
+use serde::{Deserialize, Deserializer, Serialize};
pub use crate::config::schema::voice_live::{
ElevenLabsLiveSettings, GeminiLiveSettings, LiveVoiceConfig, SarvamLiveSettings,
@@ -49,11 +49,48 @@ pub struct LiveSettingsPatch {
#[serde(default)]
pub default_provider: Option<String>,
#[serde(default)]
- pub gemini: Option<GeminiLiveSettings>,
+ pub gemini: Option<GeminiLiveSettingsPatch>,
#[serde(default)]
- pub sarvam: Option<SarvamLiveSettings>,
+ pub sarvam: Option<SarvamLiveSettingsPatch>,
#[serde(default)]
- pub elevenlabs: Option<ElevenLabsLiveSettings>,
+ pub elevenlabs: Option<ElevenLabsLiveSettingsPatch>,
+}
+
+/// A provider patch distinguishes an omitted field from an explicit `null`.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct GeminiLiveSettingsPatch {
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub model: Option<Option<String>>,
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub voice: Option<Option<String>>,
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub language: Option<Option<String>>,
+}
+
+/// A provider patch distinguishes an omitted field from an explicit `null`.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct SarvamLiveSettingsPatch {
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub language: Option<Option<String>>,
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub speaker: Option<Option<String>>,
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub model: Option<Option<String>>,
+}
+
+/// A provider patch distinguishes an omitted field from an explicit `null`.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct ElevenLabsLiveSettingsPatch {
+ #[serde(default, deserialize_with = "deserialize_double_option")]
+ pub voice_id: Option<Option<String>>,
+}
+
+fn deserialize_double_option<'de, D, T>(deserializer: D) -> Result<Option<Option<T>>, D::Error>
+where
+ D: Deserializer<'de>,
+ T: Deserialize<'de>,
+{
+ Ok(Some(Option::<T>::deserialize(deserializer)?))
}
/// `voice.live_test_provider` result.