From 638e150a128deaa9071903de2bd6e2a4d00b9dff Mon Sep 17 00:00:00 2001 From: Bentlybro Date: Tue, 3 Feb 2026 11:19:10 +0000 Subject: [PATCH] fix(frontend): Handle object values in FileInput component Fixes #11800 The FileInput component crashed with 'TypeError: e.startsWith is not a function' when the value was an object (from external API) instead of a string. Changes: - Updated getFileLabelFromValue() to handle object format: { name, type, size, data } - Added type guards for string vs object values - Graceful fallback for edge cases (null, undefined, empty object) Test cases verified: - Object with name: returns filename - Object with type only: extracts and formats MIME type - String data URI: parses correctly - String file path: extracts extension - Edge cases: returns 'File' fallback --- .../components/atoms/FileInput/FileInput.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx b/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx index d43063b411..26370ce8ab 100644 --- a/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx +++ b/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx @@ -104,7 +104,28 @@ export function FileInput(props: Props) { return false; } - const getFileLabelFromValue = (val: string) => { + const getFileLabelFromValue = (val: unknown): string => { + // Handle object format from external API: { name, type, size, data } + if (val && typeof val === "object") { + const obj = val as Record; + if (typeof obj.name === "string") { + return getFileLabel(obj.name, (obj.type as string) || ""); + } + if (typeof obj.type === "string") { + const mimeParts = obj.type.split("/"); + if (mimeParts.length > 1) { + return `${mimeParts[1].toUpperCase()} file`; + } + return `${obj.type} file`; + } + return "File"; + } + + // Handle string values (data URIs or file paths) + if (typeof val !== "string") { + return "File"; + } + if (val.startsWith("data:")) { const matches = val.match(/^data:([^;]+);/); if (matches?.[1]) {