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.
This commit is contained in:
majdyz
2026-04-09 16:49:18 +07:00
parent a3c97c14c1
commit 0b06e948b9
2 changed files with 39 additions and 5 deletions

View File

@@ -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");

View File

@@ -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<typeof useBuilderChatPanel>["messages"],
}),
);
render(<BuilderChatPanel />);
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(