From 0b06e948b973bb08652b09ef43821fe8deadbf3d Mon Sep 17 00:00:00 2001 From: majdyz Date: Thu, 9 Apr 2026 16:49:18 +0700 Subject: [PATCH] fix(frontend/builder): hide seed message from visible chat messages Import SEED_PROMPT_PREFIX in BuilderChatPanel and extend the visibleMessages filter to exclude any user message whose text starts with the prefix. Adds a regression test for the new filter. --- .../BuilderChatPanel/BuilderChatPanel.tsx | 15 ++++++---- .../__tests__/BuilderChatPanel.test.tsx | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx index b03d26894d..7515c8328a 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/BuilderChatPanel.tsx @@ -16,6 +16,7 @@ import { MessagePartRenderer } from "@/app/(platform)/copilot/components/ChatMes import type { CustomNode } from "../FlowEditor/nodes/CustomNode/CustomNode"; import { GraphAction, + SEED_PROMPT_PREFIX, extractTextFromParts, getActionKey, getNodeDisplayName, @@ -199,12 +200,16 @@ function MessageList({ messagesEndRef, isStreaming, }: MessageListProps) { - const visibleMessages = messages.filter( - (msg) => - Boolean(extractTextFromParts(msg.parts)) || + const visibleMessages = messages.filter((msg) => { + const text = extractTextFromParts(msg.parts); + if (msg.role === "user" && text.startsWith(SEED_PROMPT_PREFIX)) + return false; + return ( + Boolean(text) || (msg.role === "assistant" && - msg.parts?.some((p) => p.type === "dynamic-tool")), - ); + msg.parts?.some((p) => p.type === "dynamic-tool")) + ); + }); const lastVisibleRole = visibleMessages.at(-1)?.role; const showTypingIndicator = isStreaming && (!lastVisibleRole || lastVisibleRole === "user"); diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx index 5730a9ef2f..ccd0590806 100644 --- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/__tests__/BuilderChatPanel.test.tsx @@ -13,6 +13,7 @@ import { getNodeDisplayName, buildSeedPrompt, extractTextFromParts, + SEED_PROMPT_PREFIX, } from "../helpers"; import type { CustomNode } from "../../FlowEditor/nodes/CustomNode/CustomNode"; import type { CustomEdge } from "../../FlowEditor/edges/CustomEdge"; @@ -341,6 +342,34 @@ describe("BuilderChatPanel", () => { expect(screen.queryByLabelText("Undo last applied change")).toBeNull(); }); + it("hides the seed message from the chat UI", () => { + mockUseBuilderChatPanel.mockReturnValue( + makeMockHook({ + isOpen: true, + messages: [ + { + id: "seed", + role: "user", + parts: [ + { + type: "text", + text: `${SEED_PROMPT_PREFIX} Here is the current graph...`, + }, + ], + }, + { + id: "reply", + role: "assistant", + parts: [{ type: "text", text: "I see you have an empty graph." }], + }, + ] as ReturnType["messages"], + }), + ); + render(); + expect(screen.queryByText(SEED_PROMPT_PREFIX, { exact: false })).toBeNull(); + expect(screen.getByText("I see you have an empty graph.")).toBeDefined(); + }); + it("passes onGraphEdited and isGraphLoaded to useBuilderChatPanel", () => { const onGraphEdited = vi.fn(); render(