feat(app): chat channel name/topic sync, TTS speed, safe window close
Review follow-ups to M5. - Chat channel names and topics (app/src/channel_sync.rs): a channel with syncDiscord (default on) gets its name and description as its Discord name and topic when saved; registering fills them from Discord; Discord's form of the name is written back; a topic over 1,024 characters is refused before saving; a rate-limited edit is pending and retried once by itself with the latest text; a missing permission fails with the reason and the app keeps the text. Commands discord_channel_info and channel_sync_status. Checked on real Discord with a temporary channel (fill, edit, rate limit, automatic retry). - voice.tts.speed (0.5-2.0) on the model screen, passed to the worker as --melo-speed. MeloTTS's Korean model has one voice, so no voice choice. - Closing the window runs AdminApi::shutdown first: an install in progress is cancelled and waited for, the services stop, a failed run's leftovers (Strata) are cleared (Controller::shutdown). If that fails the window stays open with the reason; closing again quits. - WebView2 data goes in the data folder (cache/webview), or a temp scratch folder before one is chosen, removed at the next start: %APPDATA%\JarvisBot holds only the location file. - Command output that is not UTF-8 (CP949 on a PC without the UTF-8 option) is decoded in the OEM code page instead of ending the reading. Verified on the win-ci VM: closing during the install leaves no process, no --location keeps only location.json under %APPDATA%, the unit tests on Windows 168/168. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,9 @@ pub struct ChatChannelSettings {
|
||||
/// Answer every message here (`answer: "everything"`), not only those calling a wake word (`"wakeWord"`,
|
||||
/// the default; conversation.spec.md).
|
||||
pub answer_all: bool,
|
||||
/// Keep the Discord channel's name and topic in step with `name` and `description`
|
||||
/// (`syncDiscord`, on by default; admin.spec.md, "Chat channel names and topics").
|
||||
pub sync_discord: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -58,6 +61,8 @@ pub struct VoiceSettings {
|
||||
pub wake_words: Vec<String>,
|
||||
/// Voice worker STT settings (voice_worker.spec.md); the worker validates them.
|
||||
pub stt: Map<String, Value>,
|
||||
/// How fast the voice speaks (MeloTTS `speed`, 0.5-2.0); the worker gets it at start.
|
||||
pub tts_speed: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -125,6 +130,7 @@ impl Default for Settings {
|
||||
join_notice: DEFAULT_JOIN_NOTICE.into(),
|
||||
wake_words: vec!["자비스".into()],
|
||||
stt: Map::new(),
|
||||
tts_speed: 1.5,
|
||||
},
|
||||
chat_channels: vec![],
|
||||
voice_worker: WorkerSettings {
|
||||
@@ -153,6 +159,18 @@ pub fn worker_cwd_for(exe: Option<&Path>) -> PathBuf {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src")
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
/// The voice worker's arguments: `voiceWorker.args`, plus the voice speed when it speaks
|
||||
/// (`--melo-python`) and the arguments do not set one themselves.
|
||||
pub fn worker_args(&self) -> Vec<String> {
|
||||
let mut a = self.voice_worker.args.clone();
|
||||
if a.iter().any(|x| x == "--melo-python") && !a.iter().any(|x| x == "--melo-speed") {
|
||||
a.extend(["--melo-speed".to_string(), self.voice.tts_speed.to_string()]);
|
||||
}
|
||||
a
|
||||
}
|
||||
}
|
||||
|
||||
fn err<T>(msg: impl Into<String>) -> Result<T, SettingsError> {
|
||||
Err(SettingsError(msg.into()))
|
||||
}
|
||||
@@ -352,6 +370,17 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
if join_notice.encode_utf16().count() > 2000 {
|
||||
return err("voice.joinNotice must be at most 2000 characters");
|
||||
}
|
||||
let tts_speed = match voice.and_then(|m| m.get("tts")) {
|
||||
None => d.voice.tts_speed,
|
||||
Some(Value::Object(t)) => match t.get("speed") {
|
||||
None => d.voice.tts_speed,
|
||||
Some(v) => match v.as_f64() {
|
||||
Some(x) if (0.5..=2.0).contains(&x) => x,
|
||||
_ => return err("voice.tts.speed must be a number 0.5-2.0"),
|
||||
},
|
||||
},
|
||||
Some(_) => return err("voice.tts must be an object"),
|
||||
};
|
||||
let stt = match voice.and_then(|m| m.get("stt")) {
|
||||
None => d.voice.stt.clone(),
|
||||
Some(Value::Object(m)) => m.clone(),
|
||||
@@ -386,6 +415,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
"everything" => true,
|
||||
_ => return err(format!("{path}.answer must be wakeWord or everything")),
|
||||
},
|
||||
sync_discord: get_bool(Some(m), "syncDiscord", &path, true)?,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -403,6 +433,7 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
join_notice,
|
||||
wake_words,
|
||||
stt,
|
||||
tts_speed,
|
||||
},
|
||||
chat_channels,
|
||||
voice_worker: WorkerSettings {
|
||||
@@ -467,6 +498,21 @@ mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn the_tts_speed_reaches_the_worker_when_it_speaks() {
|
||||
let melo = json!({"voiceWorker": {"args": ["--melo-python", "/m/python", "--brain"]}});
|
||||
let s = parse_settings(&melo).unwrap();
|
||||
let speed = |a: &[String]| a.iter().position(|x| x == "--melo-speed").map(|i| a[i + 1].clone());
|
||||
assert_eq!(speed(&s.worker_args()), Some(s.voice.tts_speed.to_string()), "the default speed");
|
||||
let mut fast = melo.clone();
|
||||
fast["voice"] = json!({"tts": {"speed": 1.8}});
|
||||
assert_eq!(speed(&parse_settings(&fast).unwrap().worker_args()).as_deref(), Some("1.8"));
|
||||
assert!(speed(&Settings::default().worker_args()).is_none(), "no TTS, no speed");
|
||||
for bad in [json!(0.2), json!(3), json!("fast")] {
|
||||
assert!(parse_settings(&json!({"voice": {"tts": {"speed": bad}}})).unwrap_err().0.contains("voice.tts.speed"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_python_sources_shipped_next_to_the_app_win_over_the_repository() {
|
||||
let dir = crate::datadir::temp_dir("pysrc");
|
||||
@@ -512,7 +558,7 @@ mod tests {
|
||||
assert_eq!(s.voice.stt.get("end_silence_ms"), Some(&json!(250)));
|
||||
assert_eq!(s.chat_channels, vec![ChatChannelSettings { id: IDN, name: "일정".into(),
|
||||
description: "일정 올리는 곳".into(), read: true, send: false, edit: true, react: true, delete: false,
|
||||
pin: false, answer_all: false }]);
|
||||
pin: false, answer_all: false, sync_discord: true }]);
|
||||
assert_eq!(s.voice_worker.args, vec!["--melo-python", "/m/python"]);
|
||||
assert_eq!(s.voice_worker.cwd, PathBuf::from("/repo/src"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user