mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
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:
@@ -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");
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user