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:
@@ -286,3 +286,76 @@ async fn chat_channels_go_out_and_chat_actions_come_back_with_their_results() {
|
||||
]);
|
||||
c.close();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_spoken_reply_takes_its_audio_and_a_failed_one_ends_its_speech() {
|
||||
let w = FakeWorker::start(0).await;
|
||||
let (c, mut rx) = client(&w.url(), json!({}));
|
||||
c.start();
|
||||
c.wait_ready(Duration::from_secs(2)).await.expect("ready");
|
||||
assert!(c.reply("r1", 42, "자비스 날씨 어때", true));
|
||||
assert!(c.reply("r2", 43, "자비스 안녕", true));
|
||||
until(|| w.got().len() >= 3).await;
|
||||
assert_eq!(w.got()[1], Got::Json(json!({"type": "reply", "id": "r1", "user": "42", "text": "자비스 날씨 어때",
|
||||
"via": "voice", "speak": true})));
|
||||
// The brain's answer is spoken under the reply id, so its audio reaches the app.
|
||||
w.send(Message::text(json!({"type": "reply_text", "id": "r1", "text": "맑아요.", "failed": false}).to_string()));
|
||||
w.send(tts_frame("r1", 0));
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::ReplyText { .. })).await;
|
||||
assert_eq!(e, WorkerEvent::ReplyText { id: "r1".into(), text: "맑아요.".into(), failed: false });
|
||||
next_matching(&mut rx, |e| matches!(e, WorkerEvent::TtsAudio { id, .. } if id == "r1")).await;
|
||||
// No answer: nothing will be spoken, so its speech ends as failed.
|
||||
w.send(Message::text(json!({"type": "reply_text", "id": "r2", "text": "", "failed": true}).to_string()));
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::TtsDone(_))).await;
|
||||
assert_eq!(e, WorkerEvent::TtsDone(TtsDone { id: "r2".into(), chunks: 0, cancelled: false, failed: true }));
|
||||
c.close();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_reply_the_worker_cannot_answer_or_send_ends_as_failed() {
|
||||
let w = FakeWorker::start(0).await;
|
||||
let (c, mut rx) = client(&w.url(), json!({}));
|
||||
c.start();
|
||||
c.wait_ready(Duration::from_secs(2)).await.expect("ready");
|
||||
c.reply("r3", 42, "x", true);
|
||||
w.send(Message::text(json!({"type": "error", "code": "brain_unavailable", "message": "no", "id": "r3"}).to_string()));
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::TtsDone(_))).await;
|
||||
assert_eq!(e, WorkerEvent::TtsDone(TtsDone { id: "r3".into(), chunks: 0, cancelled: false, failed: true }));
|
||||
c.close();
|
||||
|
||||
let (c, mut rx) = client("ws://127.0.0.1:1", json!({}));
|
||||
assert!(!c.reply("r4", 42, "x", true));
|
||||
let e = next_matching(&mut rx, |_| true).await;
|
||||
assert_eq!(e, WorkerEvent::TtsDone(TtsDone { id: "r4".into(), chunks: 0, cancelled: false, failed: true }));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn addressed_and_rank_questions_go_out_and_their_answers_come_back() {
|
||||
let w = FakeWorker::start(0).await;
|
||||
let (c, mut rx) = client(&w.url(), json!({}));
|
||||
c.start();
|
||||
c.wait_ready(Duration::from_secs(2)).await.expect("ready");
|
||||
assert!(c.addressed("q1", 42, "불 좀 꺼 줄래"));
|
||||
assert!(c.rank("k2", &[("7".into(), 42, "날씨".into()), ("8".into(), 43, "불 꺼".into())]));
|
||||
until(|| w.got().len() >= 3).await;
|
||||
let got: Vec<Value> = w.got()[1..].iter().map(|g| match g { Got::Json(v) => v.clone(), Got::Bin(_) => json!(null) }).collect();
|
||||
assert_eq!(got, vec![
|
||||
json!({"type": "addressed", "id": "q1", "user": "42", "text": "불 좀 꺼 줄래"}),
|
||||
json!({"type": "rank", "id": "k2", "candidates": [{"id": "7", "user": "42", "text": "날씨"},
|
||||
{"id": "8", "user": "43", "text": "불 꺼"}]}),
|
||||
]);
|
||||
w.send(Message::text(json!({"type": "addressed_result", "id": "q1", "addressed": true, "failed": false}).to_string()));
|
||||
w.send(Message::text(json!({"type": "rank_result", "id": "k2", "order": ["8", "7"], "failed": false}).to_string()));
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::Addressed { .. })).await;
|
||||
assert_eq!(e, WorkerEvent::Addressed { id: "q1".into(), addressed: true });
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::Ranked { .. })).await;
|
||||
assert_eq!(e, WorkerEvent::Ranked { id: "k2".into(), order: vec!["8".into(), "7".into()] });
|
||||
// A failed judgement is a "no", and a failed ranking has no order.
|
||||
w.send(Message::text(json!({"type": "addressed_result", "id": "q3", "addressed": true, "failed": true}).to_string()));
|
||||
w.send(Message::text(json!({"type": "rank_result", "id": "k4", "order": ["8"], "failed": true}).to_string()));
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::Addressed { .. })).await;
|
||||
assert_eq!(e, WorkerEvent::Addressed { id: "q3".into(), addressed: false });
|
||||
let e = next_matching(&mut rx, |e| matches!(e, WorkerEvent::Ranked { .. })).await;
|
||||
assert_eq!(e, WorkerEvent::Ranked { id: "k4".into(), order: vec![] });
|
||||
c.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user