Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: keep created files outside the collapsed tool card (#10446)

Chaitanya Laxman2d9671da7c85
diff --git a/studio/frontend/src/components/assistant-ui/sandbox-files-view.tsx b/studio/frontend/src/components/assistant-ui/sandbox-files-view.tsx
index 287e8270ca5..6028416981b 100644
--- a/studio/frontend/src/components/assistant-ui/sandbox-files-view.tsx
+++ b/studio/frontend/src/components/assistant-ui/sandbox-files-view.tsx
@@ -13,6 +13,7 @@ import { toast } from "sonner";
import { authFetch, getAuthToken } from "@/features/auth";
import { apiUrl, isTauri } from "@/lib/api-base";
import { downloadUrlStreaming, isDownloadCancelled } from "@/lib/native-files";
+import { cn } from "@/lib/utils";
import { sandboxFilePath, type SandboxFile } from "./sandbox-files";
import { revealSandbox } from "./sandbox-reveal";
@@ -128,13 +129,15 @@ function SandboxFolderLabel({
export function SandboxFiles({
sessionId,
files,
+ className,
}: {
sessionId: string;
files: SandboxFile[];
+ className?: string;
}) {
if (!sessionId || files.length === 0) return null;
return (
- <div className="mt-2 border-t border-dashed pt-2">
+ <div className={cn("mt-2 border-t border-dashed pt-2", className)}>
<SandboxFolderLabel
sessionId={sessionId}
label={files.length === 1 ? "file created" : "files created"}
diff --git a/studio/frontend/src/components/assistant-ui/sandbox-files.ts b/studio/frontend/src/components/assistant-ui/sandbox-files.ts
index 54f877c3110..095b5b8ac20 100644
--- a/studio/frontend/src/components/assistant-ui/sandbox-files.ts
+++ b/studio/frontend/src/components/assistant-ui/sandbox-files.ts
@@ -97,6 +97,14 @@ export function isSandboxToolResult(
);
}
+/** Whether a python/terminal call's card shows a created-files row. */
+export function hasCreatedFiles(toolName: unknown, result: unknown): boolean {
+ if (typeof toolName !== "string" || !SANDBOX_FILE_TOOLS.has(toolName)) return false;
+ if (!isSandboxToolResult(result)) return false;
+ const { files } = result as { files?: unknown[] | null };
+ return Array.isArray(files) && files.length > 0;
+}
+
/** Ids a path segment can carry: ASGI decodes %2F before it matches a route. */
const PATH_SAFE_SESSION = /^[A-Za-z0-9_-]{1,64}$/;
diff --git a/studio/frontend/src/components/assistant-ui/tool-group.tsx b/studio/frontend/src/components/assistant-ui/tool-group.tsx
index ad37967852b..ba67f744bcc 100644
--- a/studio/frontend/src/components/assistant-ui/tool-group.tsx
+++ b/studio/frontend/src/components/assistant-ui/tool-group.tsx
@@ -28,6 +28,7 @@ import {
import { useCollapseScrollLock } from "@/hooks/use-collapse-scroll-lock";
import { cn } from "@/lib/utils";
import { Spinner } from "@/components/ui/spinner";
+import { hasCreatedFiles } from "./sandbox-files";
import { syncToolActivityPreference } from "./tool-activity-open-state";
const ANIMATION_DURATION = 200;
@@ -240,7 +241,9 @@ const ToolGroupImpl: FC<
.some(
(part) =>
part.type === "tool-call" &&
- (part.toolName === "render_html" || part.toolName === "python"),
+ (part.toolName === "render_html" ||
+ part.toolName === "python" ||
+ hasCreatedFiles(part.toolName, part.result)),
),
);
// A blocking allow/deny prompt must never be hidden inside a collapsed
@@ -300,8 +303,8 @@ const ToolGroupImpl: FC<
((hasLiveOutput && messageRunning) ||
(forcedOpenRef.current && messageRunning)));
- // Render single calls, canvases, and Python scripts directly so their
- // persistent content never hides in a collapsed group.
+ // Render single calls, canvases, Python scripts, and calls that created files
+ // directly so their persistent content never hides in a collapsed group.
if (toolCount <= 1 || containsUngroupedTool) {
return <>{children}</>;
}
diff --git a/studio/frontend/src/components/assistant-ui/tool-ui-python.tsx b/studio/frontend/src/components/assistant-ui/tool-ui-python.tsx
index 35361dfc0df..1daa553b93b 100644
--- a/studio/frontend/src/components/assistant-ui/tool-ui-python.tsx
+++ b/studio/frontend/src/components/assistant-ui/tool-ui-python.tsx
@@ -139,7 +139,8 @@ const PythonToolUIImpl: ToolCallMessagePartComponent = ({
// ToolFallbackContent so it stays visible on reopen (#7165) -- a script is an artifact, a
// one-line command is not. That holds only while collapseToolActivity is off; with it on the
// script moves inside the collapsible, behind one click. awaitingApproval is the exception: a
- // decision about a script needs the script on screen.
+ // decision about a script needs the script on screen. Created files stay outside even when the
+ // card is collapsed (#10425).
<ToolFallbackRoot
defaultOpen={isRunning}
awaitingApproval={awaitingApproval}
@@ -181,9 +182,6 @@ const PythonToolUIImpl: ToolCallMessagePartComponent = ({
</div>
) : null}
- {/* Anything the script wrote, as a real download */}
- <SandboxFiles sessionId={sessionId} files={files} />
-
{/* Images from Python tool execution */}
{images.length > 0 && sessionId && (
<div className="mt-2 flex flex-col gap-2">
@@ -198,6 +196,7 @@ const PythonToolUIImpl: ToolCallMessagePartComponent = ({
)}
</div>
</ToolFallbackContent>
+ <SandboxFiles className="ml-5" sessionId={sessionId} files={files} />
</ToolFallbackRoot>
);
};
diff --git a/studio/frontend/src/components/assistant-ui/tool-ui-terminal.tsx b/studio/frontend/src/components/assistant-ui/tool-ui-terminal.tsx
index 653f7acb751..d25728f5446 100644
--- a/studio/frontend/src/components/assistant-ui/tool-ui-terminal.tsx
+++ b/studio/frontend/src/components/assistant-ui/tool-ui-terminal.tsx
@@ -120,10 +120,10 @@ const TerminalToolUIImpl: ToolCallMessagePartComponent = ({
<ToolResultOutput text={displayOutput} />
</div>
) : null}
- {/* Files the command wrote; this card used to show nothing for them */}
- <SandboxFiles sessionId={sessionId} files={files} />
</div>
</ToolFallbackContent>
+ {/* Files stay outside even when the card is collapsed (#10425) */}
+ <SandboxFiles className="ml-5" sessionId={sessionId} files={files} />
</ToolFallbackRoot>
);
};
diff --git a/studio/frontend/tests/tool-activity-preference.test.ts b/studio/frontend/tests/tool-activity-preference.test.ts
index 101b65b2aa0..291bec123f5 100644
--- a/studio/frontend/tests/tool-activity-preference.test.ts
+++ b/studio/frontend/tests/tool-activity-preference.test.ts
@@ -633,3 +633,80 @@ test("the Python script cell moves inside the collapsible when collapsing is on"
"the always-visible script cell is no longer guarded by the preference",
);
});
+
+test("created files stay outside the collapsible on Python and Terminal cards", async () => {
+ for (const file of [
+ "../src/components/assistant-ui/tool-ui-python.tsx",
+ "../src/components/assistant-ui/tool-ui-terminal.tsx",
+ ]) {
+ const source = await sourceOf(file);
+ const root = jsxElement(source, "ToolFallbackRoot");
+ const content = jsxElement(root, "ToolFallbackContent");
+ const files = find(
+ root,
+ (node) =>
+ (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) &&
+ ts.isIdentifier(node.tagName) &&
+ node.tagName.text === "SandboxFiles",
+ );
+ assert.equal(
+ files.length,
+ 1,
+ `${file} must render SandboxFiles once under ToolFallbackRoot`,
+ );
+ const insideContent = find(content, (node) => node === files[0]);
+ assert.equal(
+ insideContent.length,
+ 0,
+ `${file} hid SandboxFiles inside ToolFallbackContent`,
+ );
+ // No wrapper element: an empty one would sit in the DOM of every card that created nothing.
+ assert.equal(files[0].parent, root, `${file} wraps SandboxFiles`);
+ const cls = (files[0] as ts.JsxSelfClosingElement).attributes.properties.find(
+ (property): property is ts.JsxAttribute =>
+ ts.isJsxAttribute(property) && property.name.getText() === "className",
+ );
+ assert.match(
+ cls?.initializer?.getText() ?? "",
+ /ml-5/,
+ `${file} is missing ml-5, so the file row sits flush with the trigger`,
+ );
+ }
+});
+
+test("a call that created files keeps its group from collapsing", async () => {
+ const { hasCreatedFiles } = await import(
+ "../src/components/assistant-ui/sandbox-files.ts"
+ );
+ const wrapped = (files: unknown) => ({
+ text: "",
+ images: [],
+ sessionId: "s",
+ files,
+ });
+ assert.equal(hasCreatedFiles("terminal", wrapped([{ name: "a.txt", size: 3 }])), true);
+ assert.equal(hasCreatedFiles("python", wrapped([{ name: "a.txt", size: null }])), true);
+ assert.equal(hasCreatedFiles("terminal", wrapped([])), false);
+ assert.equal(hasCreatedFiles("terminal", wrapped(undefined)), false);
+ assert.equal(hasCreatedFiles("terminal", "plain output"), false);
+ assert.equal(
+ hasCreatedFiles("mcp__fs__write", wrapped([{ name: "a.txt", size: 3 }])),
+ false,
+ );
+
+ const source = await sourceOf(
+ "../src/components/assistant-ui/tool-group.tsx",
+ );
+ const call = find(
+ initializerOf(source, "containsUngroupedTool"),
+ (node) =>
+ ts.isCallExpression(node) &&
+ ts.isIdentifier(node.expression) &&
+ node.expression.text === "hasCreatedFiles",
+ )[0] as ts.CallExpression | undefined;
+ assert.ok(call, "a grouped terminal call hides its created files again");
+ assert.deepEqual(
+ call.arguments.map((argument) => argument.getText()),
+ ["part.toolName", "part.result"],
+ );
+});