From 1f4105e8f9554d7bff016ce8216041bf4c378bf3 Mon Sep 17 00:00:00 2001 From: Bently Date: Mon, 9 Feb 2026 10:25:08 +0000 Subject: [PATCH] fix(frontend): Handle object values in FileInput component (#11948) Fixes [#11800](https://github.com/Significant-Gravitas/AutoGPT/issues/11800) ## Problem 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. ## Example Input Object When using the external API (`/external-api/v1/graphs/{id}/execute/{version}`), file inputs can be passed as objects: ```json { "node_input": { "input_image": { "name": "image.jpeg", "type": "image/jpeg", "size": 131147, "data": "/9j/4QAW..." } } } ``` ## 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 | 26 ++++++++++++++++++- 1 file changed, 25 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..2677a7483b 100644 --- a/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx +++ b/autogpt_platform/frontend/src/components/atoms/FileInput/FileInput.tsx @@ -104,7 +104,31 @@ 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, + typeof obj.type === "string" ? obj.type : "", + ); + } + 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]) {