From cdb9aeb9baeb9622cd59b7ed155a8a49018cd06a Mon Sep 17 00:00:00 2001 From: "sp.wack" <83104063+amanape@users.noreply.github.com> Date: Tue, 27 May 2025 22:59:32 +0400 Subject: [PATCH] fix(frontend): Don't show terminal commands in chat interface that are from the user (#8729) --- .../should-render-event.ts | 17 ++++++++++++- .../src/components/features/chat/messages.tsx | 24 +------------------ frontend/src/types/core/actions.ts | 2 +- frontend/src/types/core/guards.ts | 5 ++++ frontend/src/types/core/observations.ts | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/features/chat/event-content-helpers/should-render-event.ts b/frontend/src/components/features/chat/event-content-helpers/should-render-event.ts index 581b76e5ec..e6838a2ab3 100644 --- a/frontend/src/components/features/chat/event-content-helpers/should-render-event.ts +++ b/frontend/src/components/features/chat/event-content-helpers/should-render-event.ts @@ -1,6 +1,11 @@ import { OpenHandsAction } from "#/types/core/actions"; import { OpenHandsEventType } from "#/types/core/base"; -import { isOpenHandsAction, isOpenHandsObservation } from "#/types/core/guards"; +import { + isCommandAction, + isCommandObservation, + isOpenHandsAction, + isOpenHandsObservation, +} from "#/types/core/guards"; import { OpenHandsObservation } from "#/types/core/observations"; const COMMON_NO_RENDER_LIST: OpenHandsEventType[] = [ @@ -15,11 +20,21 @@ export const shouldRenderEvent = ( event: OpenHandsAction | OpenHandsObservation, ) => { if (isOpenHandsAction(event)) { + if (isCommandAction(event) && event.source === "user") { + // For user commands, we always hide them from the chat interface + return false; + } + const noRenderList = COMMON_NO_RENDER_LIST.concat(ACTION_NO_RENDER_LIST); return !noRenderList.includes(event.action); } if (isOpenHandsObservation(event)) { + if (isCommandObservation(event) && event.source === "user") { + // For user commands, we always hide them from the chat interface + return false; + } + return !COMMON_NO_RENDER_LIST.includes(event.observation); } diff --git a/frontend/src/components/features/chat/messages.tsx b/frontend/src/components/features/chat/messages.tsx index 73de59204e..c300627789 100644 --- a/frontend/src/components/features/chat/messages.tsx +++ b/frontend/src/components/features/chat/messages.tsx @@ -2,32 +2,10 @@ import React from "react"; import { OpenHandsAction } from "#/types/core/actions"; import { OpenHandsObservation } from "#/types/core/observations"; import { isOpenHandsAction, isOpenHandsObservation } from "#/types/core/guards"; -import { OpenHandsEventType } from "#/types/core/base"; import { EventMessage } from "./event-message"; import { ChatMessage } from "./chat-message"; import { useOptimisticUserMessage } from "#/hooks/use-optimistic-user-message"; -const COMMON_NO_RENDER_LIST: OpenHandsEventType[] = [ - "system", - "agent_state_changed", - "change_agent_state", -]; - -const ACTION_NO_RENDER_LIST: OpenHandsEventType[] = ["recall"]; - -const shouldRenderEvent = (event: OpenHandsAction | OpenHandsObservation) => { - if (isOpenHandsAction(event)) { - const noRenderList = COMMON_NO_RENDER_LIST.concat(ACTION_NO_RENDER_LIST); - return !noRenderList.includes(event.action); - } - - if (isOpenHandsObservation(event)) { - return !COMMON_NO_RENDER_LIST.includes(event.observation); - } - - return true; -}; - interface MessagesProps { messages: (OpenHandsAction | OpenHandsObservation)[]; isAwaitingUserConfirmation: boolean; @@ -54,7 +32,7 @@ export const Messages: React.FC = React.memo( return ( <> - {messages.filter(shouldRenderEvent).map((message, index) => ( + {messages.map((message, index) => ( { } export interface CommandAction extends OpenHandsActionEvent<"run"> { - source: "agent"; + source: "agent" | "user"; args: { command: string; security_risk: ActionSecurityRisk; diff --git a/frontend/src/types/core/guards.ts b/frontend/src/types/core/guards.ts index a98bfc0722..dfdb86d277 100644 --- a/frontend/src/types/core/guards.ts +++ b/frontend/src/types/core/guards.ts @@ -4,6 +4,7 @@ import { AssistantMessageAction, OpenHandsAction, SystemMessageAction, + CommandAction, } from "./actions"; import { AgentStateChangeObservation, @@ -41,6 +42,10 @@ export const isErrorObservation = ( ): event is ErrorObservation => isOpenHandsObservation(event) && event.observation === "error"; +export const isCommandAction = ( + event: OpenHandsParsedEvent, +): event is CommandAction => isOpenHandsAction(event) && event.action === "run"; + export const isAgentStateChangeObservation = ( event: OpenHandsParsedEvent, ): event is AgentStateChangeObservation => diff --git a/frontend/src/types/core/observations.ts b/frontend/src/types/core/observations.ts index 1b0061304c..caf467065b 100644 --- a/frontend/src/types/core/observations.ts +++ b/frontend/src/types/core/observations.ts @@ -11,7 +11,7 @@ export interface AgentStateChangeObservation } export interface CommandObservation extends OpenHandsObservationEvent<"run"> { - source: "agent"; + source: "agent" | "user"; extras: { command: string; hidden?: boolean;