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/builder): guard extractTextFromParts against undefined parts
Zamil Majdyd31ff0586e34
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.tsxindex ca66bf827d..24be65656b 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@@ -796,4 +796,12 @@ describe("extractTextFromParts", () => {const parts = [{ type: "text" }, { type: "text", text: "hello" }];expect(extractTextFromParts(parts)).toBe("hello");});++ it("returns empty string for null parts", () => {+ expect(extractTextFromParts(null)).toBe("");+ });++ it("returns empty string for undefined parts", () => {+ expect(extractTextFromParts(undefined)).toBe("");+ });});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.tsindex d4f31e1a0b..526fc6b52b 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderChatPanel/helpers.ts@@ -165,9 +165,9 @@ export function getNodeDisplayName(* Reused in both the hook (action parsing) and the component (rendering).*/export function extractTextFromParts(- parts: ReadonlyArray<{ type: string; text?: string }>,+ parts: ReadonlyArray<{ type: string; text?: string }> | null | undefined,): string {- return parts+ return (parts ?? []).filter((p): p is { type: "text"; text: string } => p.type === "text").map((p) => p.text).join("");