Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): Don't show terminal commands in chat interface that are from the user (#8729)

sp.wackcdb9aeb9baeb
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<MessagesProps> = React.memo(
return (
<>
- {messages.filter(shouldRenderEvent).map((message, index) => (
+ {messages.map((message, index) => (
<EventMessage
key={index}
event={message}
diff --git a/frontend/src/types/core/actions.ts b/frontend/src/types/core/actions.ts
index 0d535b0540..abbadd708f 100644
--- a/frontend/src/types/core/actions.ts
+++ b/frontend/src/types/core/actions.ts
@@ -20,7 +20,7 @@ export interface SystemMessageAction extends OpenHandsActionEvent<"system"> {
}
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;