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(copilot): workspace file listing fix (#12190)

Zamil Majdy6e61cb103c89
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/GenericTool/GenericTool.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/GenericTool/GenericTool.tsx
index 542ec75d0c..35147af037 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/tools/GenericTool/GenericTool.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/tools/GenericTool/GenericTool.tsx
@@ -501,27 +501,79 @@ function getFileAccordionData(
"path",
"pattern",
) ?? "File";
- const content = getStringField(output, "content", "text", "_raw");
+ const content = getStringField(
+ output,
+ "content",
+ "text",
+ "preview",
+ "content_preview",
+ "_raw",
+ );
const message = getStringField(output, "message");
+
+ // Handle base64 content from workspace files
+ let displayContent = content;
+ if (output.content_base64 && typeof output.content_base64 === "string") {
+ try {
+ const bytes = Uint8Array.from(atob(output.content_base64), (c) =>
+ c.charCodeAt(0),
+ );
+ displayContent = new TextDecoder().decode(bytes);
+ } catch {
+ displayContent = "[Binary content]";
+ }
+ }
+
+ // Handle MCP-style content blocks from SDK tools (Read, Glob, Grep, Edit)
+ if (!displayContent) {
+ displayContent = extractMcpText(output);
+ }
+
// For Glob/list results, try to show file list
- const files = Array.isArray(output.files)
- ? output.files.filter((f: unknown): f is string => typeof f === "string")
- : null;
+ // Files can be either strings (from Glob) or objects (from list_workspace_files)
+ const files = Array.isArray(output.files) ? output.files : null;
+
+ // Format file list for display
+ let fileListText: string | null = null;
+ if (files && files.length > 0) {
+ const fileLines = files.map((f: unknown) => {
+ if (typeof f === "string") {
+ return f;
+ }
+ if (typeof f === "object" && f !== null) {
+ const fileObj = f as Record<string, unknown>;
+ // Workspace file format: path (size, mime_type)
+ 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, ${mimeType})`
+ : "";
+ return `${filePath}${size}`;
+ }
+ return String(f);
+ });
+ fileListText = fileLines.join("\n");
+ }
return {
title: message ?? "File output",
description: truncate(filePath, 80),
content: (
<div className="space-y-2">
- {content && (
- <ContentCodeBlock>{truncate(content, 2000)}</ContentCodeBlock>
+ {displayContent && (
+ <ContentCodeBlock>{truncate(displayContent, 2000)}</ContentCodeBlock>
)}
- {files && files.length > 0 && (
- <ContentCodeBlock>
- {truncate(files.join("\n"), 2000)}
- </ContentCodeBlock>
+ {fileListText && (
+ <ContentCodeBlock>{truncate(fileListText, 2000)}</ContentCodeBlock>
)}
- {!content && !files && message && (
+ {!displayContent && !fileListText && message && (
<ContentMessage>{message}</ContentMessage>
)}
</div>