Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): stop a tool result rendering its own discriminator (#14178)

Nicholas Tindle072c06434361
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/resultHelpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/resultHelpers.test.ts
index 43d0ffbe31..550c3de046 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/resultHelpers.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/resultHelpers.test.ts
@@ -67,6 +67,33 @@ describe("stripBaseFields", () => {
}),
).toEqual({ result: 5 });
});
+
+ it("drops a name that only echoes the discriminator", () => {
+ // no_results repeats its own type in `name`. Left in, it renders as a
+ // "Name no_results" row and makes the object two-keyed, so the card that
+ // handles a lone string array never runs and the suggestions come out raw.
+ expect(
+ stripBaseFields({
+ type: "no_results",
+ message: "Nothing found",
+ suggestions: ["Try broader keywords"],
+ name: "no_results",
+ }),
+ ).toEqual({ suggestions: ["Try broader keywords"] });
+ });
+
+ it("keeps a name that is real payload", () => {
+ // A folder, file, or block is named, and that name is the answer. It is
+ // only envelope when it repeats the type.
+ expect(
+ stripBaseFields({
+ type: "folder_created",
+ message: "Created",
+ name: "Testing",
+ id: "f1",
+ }),
+ ).toEqual({ name: "Testing", id: "f1" });
+ });
});
describe("resultItemKey", () => {
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/resultHelpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/resultHelpers.ts
index 775c2d205e..9c34015710 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/resultHelpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/resultHelpers.ts
@@ -31,8 +31,19 @@ const BASE_RESPONSE_KEYS = new Set(["type", "message", "session_id"]);
export function stripBaseFields(
obj: Record<string, unknown>,
): Record<string, unknown> {
+ // A couple of responses repeat their own discriminator in `name`
+ // ("no_results", "agents_found"). It is envelope, not payload, and left in
+ // it both renders as a field of its own and pushes the object past the
+ // single-key check that picks a real card -- so a no-results answer came out
+ // as a raw suggestions array labelled "Suggestions", with "Name no_results"
+ // under it. Only drop `name` when it is that echo: a payload whose name
+ // means something (a folder, a file, a block) never equals the type.
+ const type = obj.type;
return Object.fromEntries(
- Object.entries(obj).filter(([key]) => !BASE_RESPONSE_KEYS.has(key)),
+ Object.entries(obj).filter(
+ ([key, value]) =>
+ !BASE_RESPONSE_KEYS.has(key) && !(key === "name" && value === type),
+ ),
);
}