feat(voice_worker): record history from the app and answer reply requests with the brain
Worker (voice_worker.spec.md "History and brain"): - --history <file> keeps the conversation history store; --brain hosts the jarvis reply engine (JarvisBrain, settings point ollama_base_url at /v1). - voice_join / voice_leave / member_join / member_leave keep presence; the session end closes it. Non-empty finals are stored under the speaker's name in the current voice channel. - chat_message / chat_edit / chat_delete keep registered chat channels. - reply builds the asker's scoped history context, runs the brain on a thread (one at a time), answers reply_text, stores a voice answer, and with speak=true says it under the same id. memory settings in hello and memory_config. brain_unavailable without --brain. App (discord_core.spec.md "History reporting"): - WorkerClient sends the new messages; the core reports the voice channel and its heard members after a join, a move and every worker reconnect, member joins and leaves, voice_leave when a session ends, and every message of a readable registered channel (its own too, with `to` on replies), edits and deletes. - live_discord runs the worker with --history and checks the store at the end: 8 finals under the speaker's name, the edited chat message only, Jarvis's own messages, 5 presence intervals, none left open (passed, 107.8 s). Eval: history recall gains a chat-record case and fails a reply that reads a record stamp out (field run with qwen2.5:7b did once in four). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -221,6 +221,48 @@ impl WorkerClient {
|
||||
self.send_json(json!({"type": "speaker_leave", "speaker": speaker}));
|
||||
}
|
||||
|
||||
// --- history (voice_worker.spec.md "History and brain"). Dropped while disconnected; the
|
||||
// discord core sends the voice state again when the worker is ready. ----------------------
|
||||
|
||||
/// Jarvis is in (or moved to) this voice channel.
|
||||
pub fn voice_join(&self, channel: u64) {
|
||||
self.send_json(json!({"type": "voice_join", "channel": channel.to_string()}));
|
||||
}
|
||||
|
||||
pub fn voice_leave(&self) {
|
||||
self.send_json(json!({"type": "voice_leave"}));
|
||||
}
|
||||
|
||||
pub fn member_join(&self, user: u64, name: &str) {
|
||||
self.send_json(json!({"type": "member_join", "user": user.to_string(), "name": name}));
|
||||
}
|
||||
|
||||
pub fn member_leave(&self, user: u64) {
|
||||
self.send_json(json!({"type": "member_leave", "user": user.to_string()}));
|
||||
}
|
||||
|
||||
/// A message of a registered chat channel. `to`: the user Jarvis answered, on its own messages.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn chat_message(&self, channel: u64, message: u64, author: u64, name: &str, text: &str, ts: f64,
|
||||
to: Option<u64>) {
|
||||
let mut v = json!({"type": "chat_message", "channel": channel.to_string(), "message_id": message.to_string(),
|
||||
"author": author.to_string(), "name": name, "text": text, "ts": ts});
|
||||
if let Some(to) = to {
|
||||
v["to"] = Value::String(to.to_string());
|
||||
}
|
||||
self.send_json(v);
|
||||
}
|
||||
|
||||
pub fn chat_edit(&self, channel: u64, message: u64, text: &str) {
|
||||
self.send_json(json!({"type": "chat_edit", "channel": channel.to_string(), "message_id": message.to_string(),
|
||||
"text": text}));
|
||||
}
|
||||
|
||||
pub fn chat_delete(&self, channel: u64, message: u64) {
|
||||
self.send_json(json!({"type": "chat_delete", "channel": channel.to_string(),
|
||||
"message_id": message.to_string()}));
|
||||
}
|
||||
|
||||
/// Change STT settings now and for every later connection.
|
||||
pub fn configure(&self, changes: Map<String, Value>) {
|
||||
self.inner.state.lock().unwrap().stt.extend(changes.clone());
|
||||
|
||||
Reference in New Issue
Block a user