fix: tighten type safety on file object fields

Use explicit typeof checks for path, name, and mime_type instead of
relying on truthiness, which could produce unexpected output for
non-string values.
This commit is contained in:
Otto-AGPT
2026-02-23 18:16:57 +00:00
parent 04dc25f110
commit 1bed2a2916

View File

@@ -543,10 +543,19 @@ function getFileAccordionData(
if (typeof f === "object" && f !== null) {
const fileObj = f as Record<string, unknown>;
// Workspace file format: path (size, mime_type)
const filePath = fileObj.path || fileObj.name || "unknown";
const filePath =
typeof fileObj.path === "string"
? fileObj.path
: typeof fileObj.name === "string"
? fileObj.name
: "unknown";
const mimeType =
typeof fileObj.mime_type === "string"
? fileObj.mime_type
: "unknown";
const size =
typeof fileObj.size_bytes === "number"
? ` (${(fileObj.size_bytes / 1024).toFixed(1)} KB, ${fileObj.mime_type || "unknown"})`
? ` (${(fileObj.size_bytes / 1024).toFixed(1)} KB, ${mimeType})`
: "";
return `${filePath}${size}`;
}