feat(app): M5 step 2, service control and the dashboard data
- control: one Controller starts, stops and restarts the services (stopped, starting, running, stopping, failed); a failed start leaves nothing running and keeps its error with secrets masked. The app binary uses it. - dashboard: built from the core's events alone: the bot's tag, the voice channel, live captions (screen only, cleared on leaving or stopping), the last 20 voice answers split into stages with medians (matched by the new AnswerAsked event), and missed requests without text. - system: memory in use and per NVIDIA GPU its use and VRAM (nvidia-smi). - DiscordCore::voice_members, WorkerClient::hello, the conversation's missed requests shared with the dashboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -117,6 +117,9 @@ impl ChatCalls {
|
||||
/// Chat answers waited for longer than this are forgotten (the brain or the worker went away).
|
||||
const CHAT_ANSWER_KEPT: Duration = Duration::from_secs(300);
|
||||
|
||||
/// The missed requests, shared between the conversation loop and the dashboard.
|
||||
pub type MissedLog = std::sync::Arc<std::sync::Mutex<VecDeque<Missed>>>;
|
||||
|
||||
/// A request that was not answered, or an answer that was stopped. No text: only who, why and when.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Missed {
|
||||
@@ -136,7 +139,8 @@ pub struct Conversation<V: Voice> {
|
||||
by_speech: HashMap<String, u64>,
|
||||
/// Ask id -> the request it becomes on a yes, and when it was asked.
|
||||
asks: HashMap<String, (Request, Instant)>,
|
||||
missed: VecDeque<Missed>,
|
||||
/// Shared with the dashboard (`missed_handle`).
|
||||
missed: MissedLog,
|
||||
chat: ChatCalls,
|
||||
/// Chat answer id -> the message it answers (channel, message) and when it was asked.
|
||||
chat_answers: HashMap<String, (u64, u64, Instant)>,
|
||||
@@ -152,7 +156,7 @@ pub struct Conversation<V: Voice> {
|
||||
impl<V: Voice> Conversation<V> {
|
||||
pub fn new(voice: V, calls: CallSettings, policy: PolicySettings) -> Self {
|
||||
Self { voice, calls, policy: Policy::new(policy), next_id: 0, answers: HashMap::new(),
|
||||
by_speech: HashMap::new(), asks: HashMap::new(), missed: VecDeque::new(), chat: ChatCalls::default(),
|
||||
by_speech: HashMap::new(), asks: HashMap::new(), missed: MissedLog::default(), chat: ChatCalls::default(),
|
||||
chat_answers: HashMap::new(), started: HashMap::new(), wakes: HashMap::new(),
|
||||
chimed: HashSet::new() }
|
||||
}
|
||||
@@ -206,8 +210,14 @@ impl<V: Voice> Conversation<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn missed(&self) -> impl Iterator<Item = &Missed> {
|
||||
self.missed.iter()
|
||||
/// The missed requests kept, oldest first.
|
||||
pub fn missed(&self) -> std::vec::IntoIter<Missed> {
|
||||
self.missed.lock().unwrap().iter().cloned().collect::<Vec<_>>().into_iter()
|
||||
}
|
||||
|
||||
/// The same records for the dashboard, readable while the loop runs.
|
||||
pub fn missed_handle(&self) -> MissedLog {
|
||||
self.missed.clone()
|
||||
}
|
||||
|
||||
pub fn on_event(&mut self, ev: &CoreEvent, now: Instant) {
|
||||
@@ -413,10 +423,11 @@ impl<V: Voice> Conversation<V> {
|
||||
Action::Missed(r, reason) => {
|
||||
self.chimed.remove(&r.id);
|
||||
debug_log!("conversation", "missed req={} speaker={} reason={reason:?}", r.id, r.speaker);
|
||||
if self.missed.len() == MISSED_KEPT {
|
||||
self.missed.pop_front();
|
||||
let mut missed = self.missed.lock().unwrap();
|
||||
if missed.len() == MISSED_KEPT {
|
||||
missed.pop_front();
|
||||
}
|
||||
self.missed.push_back(Missed { speaker: r.speaker, reason, at: now, chars: r.text.chars().count() });
|
||||
missed.push_back(Missed { speaker: r.speaker, reason, at: now, chars: r.text.chars().count() });
|
||||
}
|
||||
Action::Rank { id, candidates } => {
|
||||
let c: Vec<(String, u64, String)> =
|
||||
@@ -724,7 +735,7 @@ mod tests {
|
||||
c.on_event(&fin(A, "자비스 날씨", 100), ms(t, 0));
|
||||
c.on_event(&fin(B, "자비스 안녕", 100), ms(t, 100));
|
||||
assert_eq!(f.take().len(), 1);
|
||||
let m: Vec<_> = c.missed().cloned().collect();
|
||||
let m: Vec<_> = c.missed().collect();
|
||||
assert_eq!(m, vec![Missed { speaker: B, reason: MissReason::Busy, at: ms(t, 100), chars: "자비스 안녕".chars().count() }]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user