|
@@ -8,6 +8,7 @@ from dataclasses import dataclass, field
|
|
|
|
|
|
|
|
MAX_TRANSCRIPTS = 200
|
|
MAX_TRANSCRIPTS = 200
|
|
|
MAX_CHAT = 200
|
|
MAX_CHAT = 200
|
|
|
|
|
+MAX_LOWER = 500
|
|
|
|
|
|
|
|
MODE_STYLES = {
|
|
MODE_STYLES = {
|
|
|
"idle": "green",
|
|
"idle": "green",
|
|
@@ -24,6 +25,7 @@ class ViewState:
|
|
|
mode: str = "idle"
|
|
mode: str = "idle"
|
|
|
stt_ok: bool = True
|
|
stt_ok: bool = True
|
|
|
device_ok: bool = True
|
|
device_ok: bool = True
|
|
|
|
|
+ speech_open: bool = False
|
|
|
worker_stall_s: float = 0.0
|
|
worker_stall_s: float = 0.0
|
|
|
queue_depth: int = 0
|
|
queue_depth: int = 0
|
|
|
ready: bool = False
|
|
ready: bool = False
|
|
@@ -33,6 +35,7 @@ class ViewState:
|
|
|
in_flight: bool = False
|
|
in_flight: bool = False
|
|
|
transcripts: list[dict] = field(default_factory=list)
|
|
transcripts: list[dict] = field(default_factory=list)
|
|
|
chat: list[dict] = field(default_factory=list)
|
|
chat: list[dict] = field(default_factory=list)
|
|
|
|
|
+ lower: list[str] = field(default_factory=list)
|
|
|
tool: dict | None = None
|
|
tool: dict | None = None
|
|
|
tool_result: dict | None = None
|
|
tool_result: dict | None = None
|
|
|
last_error: dict | None = None
|
|
last_error: dict | None = None
|
|
@@ -49,6 +52,12 @@ class ViewState:
|
|
|
self.phase = event.get("phase", self.phase)
|
|
self.phase = event.get("phase", self.phase)
|
|
|
self.command_text = event.get("command_text", self.command_text)
|
|
self.command_text = event.get("command_text", self.command_text)
|
|
|
self.stt_ok = bool(event.get("stt_ok", self.stt_ok))
|
|
self.stt_ok = bool(event.get("stt_ok", self.stt_ok))
|
|
|
|
|
+ if "speech_open" in event:
|
|
|
|
|
+ self.speech_open = bool(event["speech_open"])
|
|
|
|
|
+ elif etype == "speech_start":
|
|
|
|
|
+ self.speech_open = True
|
|
|
|
|
+ elif etype == "speech_stop":
|
|
|
|
|
+ self.speech_open = False
|
|
|
elif etype == "heartbeat":
|
|
elif etype == "heartbeat":
|
|
|
# The heartbeat re-states the mode: a missed `mode` event self-corrects.
|
|
# The heartbeat re-states the mode: a missed `mode` event self-corrects.
|
|
|
self.mode = event.get("mode", self.mode)
|
|
self.mode = event.get("mode", self.mode)
|
|
@@ -69,12 +78,27 @@ class ViewState:
|
|
|
elif etype == "chat_message":
|
|
elif etype == "chat_message":
|
|
|
self.chat.append(event)
|
|
self.chat.append(event)
|
|
|
del self.chat[:-MAX_CHAT]
|
|
del self.chat[:-MAX_CHAT]
|
|
|
|
|
+ self.append_lower(f"{event.get('role', '?')}: {event.get('text', '')}")
|
|
|
elif etype == "tool_call":
|
|
elif etype == "tool_call":
|
|
|
self.tool = event
|
|
self.tool = event
|
|
|
|
|
+ args = event.get("args") or {}
|
|
|
|
|
+ suffix = f" {args}" if args else ""
|
|
|
|
|
+ self.append_lower(f"-> tool {event.get('tool')}{suffix}")
|
|
|
elif etype == "tool_result":
|
|
elif etype == "tool_result":
|
|
|
self.tool_result = event
|
|
self.tool_result = event
|
|
|
|
|
+ verdict = "ok" if event.get("ok") else "failed"
|
|
|
|
|
+ self.append_lower(f"<- {verdict}: {event.get('result', '')}")
|
|
|
elif etype == "error":
|
|
elif etype == "error":
|
|
|
self.last_error = event
|
|
self.last_error = event
|
|
|
|
|
+ self.append_lower(f"! {event.get('code')}: {event.get('message')}")
|
|
|
|
|
+
|
|
|
|
|
+ def append_lower(self, line: str) -> None:
|
|
|
|
|
+ """Append one line to the lower pane log (chat turns, tool calls, results, errors)."""
|
|
|
|
|
+ self.lower.append(line)
|
|
|
|
|
+ del self.lower[:-MAX_LOWER]
|
|
|
|
|
+
|
|
|
|
|
+ def lower_lines(self) -> list[str]:
|
|
|
|
|
+ return list(self.lower)
|
|
|
|
|
|
|
|
def health_ok(self) -> bool:
|
|
def health_ok(self) -> bool:
|
|
|
"""False when the header should go red."""
|
|
"""False when the header should go red."""
|