π OpenHands: AI-Driven Development
fix(frontend): terminal output not appearing in v1 (#11769)
Hiep Lef5611c2188e5
diff --git a/frontend/__tests__/stores/use-event-store.test.ts b/frontend/__tests__/stores/use-event-store.test.tsindex 79ea9e1509..82377d8179 100644--- a/frontend/__tests__/stores/use-event-store.test.ts+++ b/frontend/__tests__/stores/use-event-store.test.ts@@ -55,7 +55,7 @@ const mockObservationEvent: ObservationEvent = {tool_call_id: "call_123",observation: {kind: "ExecuteBashObservation",- output: "hello\n",+ content: [{ type: "text", text: "hello\n" }],command: "echo hello",exit_code: 0,error: false,diff --git a/frontend/__tests__/utils/handle-event-for-ui.test.ts b/frontend/__tests__/utils/handle-event-for-ui.test.tsindex 01f8009c27..dde84629c2 100644--- a/frontend/__tests__/utils/handle-event-for-ui.test.ts+++ b/frontend/__tests__/utils/handle-event-for-ui.test.ts@@ -17,7 +17,7 @@ describe("handleEventForUI", () => {tool_call_id: "call_123",observation: {kind: "ExecuteBashObservation",- output: "hello\n",+ content: [{ type: "text", text: "hello\n" }],command: "echo hello",exit_code: 0,error: false,diff --git a/frontend/src/components/v1/chat/event-content-helpers/get-observation-content.ts b/frontend/src/components/v1/chat/event-content-helpers/get-observation-content.tsindex ef4ffa253f..6bfc3734e5 100644--- a/frontend/src/components/v1/chat/event-content-helpers/get-observation-content.ts+++ b/frontend/src/components/v1/chat/event-content-helpers/get-observation-content.ts@@ -47,17 +47,19 @@ const getExecuteBashObservationContent = (): string => {const { observation } = event;- let { output } = observation;+ // Extract text content from the observation+ const textContent = observation.content+ .filter((c) => c.type === "text")+ .map((c) => c.text)+ .join("\n");- if (!output) {- output = "";- }+ let content = textContent || "";- if (output.length > MAX_CONTENT_LENGTH) {- output = `${output.slice(0, MAX_CONTENT_LENGTH)}...`;+ if (content.length > MAX_CONTENT_LENGTH) {+ content = `${content.slice(0, MAX_CONTENT_LENGTH)}...`;}- return `Output:\n\`\`\`sh\n${output.trim() || i18n.t("OBSERVATION$COMMAND_NO_OUTPUT")}\n\`\`\``;+ return `Output:\n\`\`\`sh\n${content.trim() || i18n.t("OBSERVATION$COMMAND_NO_OUTPUT")}\n\`\`\``;};// Tool Observationsdiff --git a/frontend/src/contexts/conversation-websocket-context.tsx b/frontend/src/contexts/conversation-websocket-context.tsxindex bb56e1497e..a58dd92c87 100644--- a/frontend/src/contexts/conversation-websocket-context.tsx+++ b/frontend/src/contexts/conversation-websocket-context.tsx@@ -178,7 +178,12 @@ export function ConversationWebSocketProvider({// Handle ExecuteBashObservation events - add output to terminalif (isExecuteBashObservationEvent(event)) {- appendOutput(event.observation.output);+ // Extract text content from the observation content array+ const textContent = event.observation.content+ .filter((c) => c.type === "text")+ .map((c) => c.text)+ .join("\n");+ appendOutput(textContent);}}} catch (error) {diff --git a/frontend/src/mocks/mock-ws-helpers.ts b/frontend/src/mocks/mock-ws-helpers.tsindex c3205b7731..512045766f 100644--- a/frontend/src/mocks/mock-ws-helpers.ts+++ b/frontend/src/mocks/mock-ws-helpers.ts@@ -165,7 +165,7 @@ export const createMockExecuteBashActionEvent = (* Creates a mock ExecuteBashObservation event for testing terminal output handling*/export const createMockExecuteBashObservationEvent = (- output: string = "total 24\ndrwxr-xr-x 5 user staff 160 Jan 10 12:00 .",+ content: string = "total 24\ndrwxr-xr-x 5 user staff 160 Jan 10 12:00 .",command: string = "ls -la",) => ({id: "bash-obs-123",@@ -175,7 +175,7 @@ export const createMockExecuteBashObservationEvent = (tool_call_id: "bash-call-456",observation: {kind: "ExecuteBashObservation",- output,+ content: [{ type: "text", text: content }],command,exit_code: 0,error: false,diff --git a/frontend/src/types/v1/core/base/observation.ts b/frontend/src/types/v1/core/base/observation.tsindex 5433087548..e406e30593 100644--- a/frontend/src/types/v1/core/base/observation.ts+++ b/frontend/src/types/v1/core/base/observation.ts@@ -56,9 +56,9 @@ export interface BrowserObservationexport interface ExecuteBashObservationextends ObservationBase<"ExecuteBashObservation"> {/**- * The raw output from the tool.+ * Content returned from the tool as a list of TextContent/ImageContent objects.*/- output: string;+ content: Array<TextContent | ImageContent>;/*** The bash command that was executed. Can be empty string if the observation is from a previous command that hit soft timeout and is not yet finished.*/