Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(TUI): Fix null value issues in TUI frontend

kdgmpw679920df41c3
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index 1d26035208..60d99cf780 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -1996,7 +1996,9 @@ export class AppScreen implements Component, Focusable {
maxPrimaryColumnWidth: 42,
});
list.onSelect = (item) => {
- void this.handleResumeSessionSelection(item.value);
+ if (item && item.value) {
+ void this.handleResumeSessionSelection(item.value);
+ }
};
list.onCancel = () => {
this.resumeSessionList = null;
@@ -2012,6 +2014,9 @@ export class AppScreen implements Component, Focusable {
}
private async handleResumeSessionSelection(sessionId: string): Promise<void> {
+ if (!sessionId || typeof sessionId !== "string") {
+ return;
+ }
const nextSessionId = sessionId.trim();
if (!nextSessionId) {
return;
@@ -2096,7 +2101,11 @@ export class AppScreen implements Component, Focusable {
minPrimaryColumnWidth: 24,
maxPrimaryColumnWidth: 42,
});
- list.onSelect = (item) => void this.handleResumeSessionSelection(item.value);
+ list.onSelect = (item) => {
+ if (item && item.value) {
+ void this.handleResumeSessionSelection(item.value);
+ }
+ };
list.onCancel = () => {
this.resumeSessionList = null;
this.tui.requestRender();
diff --git a/tests/unit/agentserver/test_interface_chat_error.py b/tests/unit/agentserver/test_interface_chat_error.py
index 315c0ce414..4ac88a9af2 100644
--- a/tests/unit/agentserver/test_interface_chat_error.py
+++ b/tests/unit/agentserver/test_interface_chat_error.py
@@ -175,16 +175,23 @@ async def test_chat_error_history_record_persists_error_type_at_top_level(
history_file = sessions_root / sid / "history.json"
chat_errors: list[dict[str, Any]] = []
- for _ in range(50):
+ for _ in range(100):
if history_file.exists():
- persisted = json.loads(history_file.read_text(encoding="utf-8"))
- chat_errors = [r for r in persisted if r.get("event_type") == "chat.error"]
- if chat_errors:
- break
- await asyncio.sleep(0.02)
+ raw = history_file.read_text(encoding="utf-8")
+ if raw.strip():
+ try:
+ persisted = json.loads(raw)
+ except json.JSONDecodeError:
+ # 文件正在写入中,下一轮重试
+ pass
+ else:
+ chat_errors = [r for r in persisted if r.get("event_type") == "chat.error"]
+ if chat_errors:
+ break
+ await asyncio.sleep(0.05)
assert history_file.exists(), f"history.json not written at {history_file}"
- assert len(chat_errors) == 1
+ assert len(chat_errors) == 1, f"expected 1 chat.error record, got {len(chat_errors)}"
# The doc claims this field is at the top level (not nested under
# event_payload or extra). Pin it.
assert chat_errors[0].get("error_type") == "LookupError"