feat: answer calls in the voice channel through the response policy

- conversation.rs: the loop between the core's events and the rest.
  Finals go through call detection and the response policy; answers are
  asked of the brain and spoken from the app's queue, an interruption
  cancels only that answer, a voice stop silences everything, and missed
  requests are kept without text (last 100). Tested with a fake voice side.
- Core: answer(user, text) adopts a playback request the worker speaks
  under the same id, cancel(id) stops one request, ask_addressed and
  ask_rank pass the conversation's questions; new SpeakingStopped,
  Addressed and Ranked events.
- Worker client: reply, addressed and rank messages and their results; a
  reply with no answer, refused or not sent ends its speech as failed.
- Voice worker: addressed and rank messages on their own threads, beside
  a running reply; a spoken reply cancelled while the brain is answering
  is not spoken. judges.py holds the two short LLM judgements with the
  heard text fenced as data; eval evals/test_voice_judges.py.
- Specs (conversation, discord core, voice worker), docs/llm_contexts.md
  and the roadmap updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 22:26:47 +09:00
parent e885630e91
commit f892a1dce9
20 changed files with 1174 additions and 14 deletions

View File

@@ -57,11 +57,17 @@ pub enum CoreEvent {
Joined { guild_id: u64, channel_id: u64 },
Left { guild_id: u64, channel_id: u64, reason: String },
SpeechStart(Heard),
/// The speaker stopped sending audio (their final is still to come).
SpeakingStopped(u64),
Partial(Heard, String),
Final(HeardFinal),
SpeakStart(String),
SpeakEnd(PlaybackEnd),
Chat(ChatMessage),
/// The brain's answer to `addressed()`.
Addressed { id: String, addressed: bool },
/// The brain's answer to `rank()`: candidate ids, most important first (empty: failed).
Ranked { id: String, order: Vec<String> },
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -390,6 +396,31 @@ impl DiscordCore {
Some(id)
}
/// Have the brain answer `user` and speak it as one request in the queue. The request id (its
/// `SpeakStart` and `SpeakEnd` follow as for `say`), or None when not in a voice channel. It ends as
/// failed when the brain gives no answer.
pub fn answer(&self, user: u64, text: &str) -> Option<String> {
self.voice_channel_id()?;
let id = with_playback(&self.inner, |p| p.adopt());
self.inner.worker.reply(&id, user, text, true);
Some(id)
}
/// Stop one request (an answer or a `say`); the rest of the queue goes on.
pub fn cancel(&self, id: &str) {
with_playback(&self.inner, |p| p.cancel(id));
}
/// Ask the brain whether `text` was said to Jarvis; the answer comes as `CoreEvent::Addressed`.
pub fn ask_addressed(&self, id: &str, user: u64, text: &str) -> bool {
self.inner.worker.addressed(id, user, text)
}
/// Ask the brain to rank candidates `(id, user, text)`; the answer comes as `CoreEvent::Ranked`.
pub fn ask_rank(&self, id: &str, candidates: &[(String, u64, String)]) -> bool {
self.inner.worker.rank(id, candidates)
}
/// More text for a request started with `say(.., true)`.
pub fn continue_text(&self, id: &str, text: &str, more: bool) {
with_playback(&self.inner, |p| p.continue_text(id, text, more));
@@ -622,6 +653,15 @@ async fn worker_task(core: std::sync::Weak<Inner>, mut rx: mpsc::UnboundedReceiv
WorkerEvent::Final(m) => on_final(&inner, m),
WorkerEvent::TtsAudio { id, seq, pcm } => with_playback(&inner, |p| p.audio(&id, seq, pcm)),
WorkerEvent::TtsDone(d) => with_playback(&inner, |p| p.done(&d)),
WorkerEvent::ReplyText { id, text, failed } => {
debug_log!("voice", "reply {id} chars={} failed={failed}", text.chars().count());
}
WorkerEvent::Addressed { id, addressed } => {
let _ = inner.events.send(CoreEvent::Addressed { id, addressed });
}
WorkerEvent::Ranked { id, order } => {
let _ = inner.events.send(CoreEvent::Ranked { id, order });
}
WorkerEvent::Ready(_) => {
report_chat_channels(&inner);
report_voice_state(&inner);
@@ -803,6 +843,7 @@ async fn speaking_end_timer(core: std::sync::Weak<Inner>, rx: Arc<Mutex<RxState>
}
if gate.end(user) {
inner.worker.speaking_end(&id);
let _ = inner.events.send(CoreEvent::SpeakingStopped(user));
}
}
}