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 the TUI frontend's null value issue when handling workflow data

kdgmpw2de7d57c524d
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
index daf18eb195..6470e12733 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/event-handlers.ts
@@ -1055,6 +1055,18 @@ function handleWorkflowUpdated(
if (typeof (workflow as Record<string, unknown>).id !== "string") {
return false;
}
+
+ // Normalize phases and agents to ensure they are arrays
+ const wf = workflow as Record<string, unknown>;
+ if (!Array.isArray(wf.phases)) {
+ wf.phases = [];
+ }
+ for (const phase of wf.phases as Record<string, unknown>[]) {
+ if (!Array.isArray(phase.agents)) {
+ phase.agents = [];
+ }
+ }
+
delegate.applyWorkflowUpdate(workflow as unknown as WorkflowRun);
return true;
}
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts b/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts
index c410ed7011..01ea159fd2 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/workflows.ts
@@ -190,7 +190,17 @@ export function applyWorkflowUpdate(
): WorkflowRun[] {
const index = workflows.findIndex((workflow) => workflow.id === incoming.id);
if (index === -1) {
- return [incoming, ...workflows];
+ // Normalize incoming workflow to ensure phases and agents are arrays
+ const normalized: WorkflowRun = {
+ ...incoming,
+ phases: Array.isArray(incoming.phases)
+ ? incoming.phases.map((phase) => ({
+ ...phase,
+ agents: Array.isArray(phase.agents) ? phase.agents : [],
+ }))
+ : [],
+ };
+ return [normalized, ...workflows];
}
return workflows.map((workflow, itemIndex) =>
itemIndex === index ? mergeWorkflowRun(workflow, incoming) : workflow,
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index 8a6abd341e..1d26035208 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -3212,7 +3212,7 @@ export class AppScreen implements Component, Focusable {
} else if (selectedPhase) {
lines.push(
...this.renderSwarmWorkflowAgentRows(
- selectedPhase.agents,
+ selectedPhase.agents ?? [],
width,
SWARM_WORKFLOW_AGENT_PREVIEW_LIMIT,
),