Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

feat: enhance ChatFileDownload component and add test for artifact download behavior (#740)

Govinda Vashishtha079f832ac65d
diff --git a/.changeset/readonly-download-tooltip.md b/.changeset/readonly-download-tooltip.md
new file mode 100644
index 000000000..cf82e56ab
--- /dev/null
+++ b/.changeset/readonly-download-tooltip.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge-ui': patch
+---
+
+Show an optional tooltip when sandbox artifact downloads are read-only.
diff --git a/packages/trueforge-ui/src/atoms/ChatFileDownload.tsx b/packages/trueforge-ui/src/atoms/ChatFileDownload.tsx
index 19c0a1eb1..6596c061c 100644
--- a/packages/trueforge-ui/src/atoms/ChatFileDownload.tsx
+++ b/packages/trueforge-ui/src/atoms/ChatFileDownload.tsx
@@ -5,6 +5,7 @@ import { useState, type MouseEvent } from 'react';
import { Icon } from '../icons/Icon.js';
import { cn } from './lib/cn.js';
import { Spinner } from './primitives/Spinner.js';
+import { Tooltip } from './primitives/Tooltip.js';
export type ChatFileDownloadFile = {
name: string;
@@ -16,9 +17,17 @@ export type ChatFileDownloadProps = {
fileDownloadBaseUrl?: string;
onDownloadArtifact?: (path: string, filename: string) => Promise<void>;
readOnly?: boolean;
+ /** Shown on hover when `readOnly` is true. */
+ readOnlyTooltip?: string;
};
-export function ChatFileDownload({ files, fileDownloadBaseUrl, onDownloadArtifact, readOnly }: ChatFileDownloadProps) {
+export function ChatFileDownload({
+ files,
+ fileDownloadBaseUrl,
+ onDownloadArtifact,
+ readOnly,
+ readOnlyTooltip,
+}: ChatFileDownloadProps) {
const [downloadingPath, setDownloadingPath] = useState<string | null>(null);
return (
@@ -27,24 +36,37 @@ export function ChatFileDownload({ files, fileDownloadBaseUrl, onDownloadArtifac
className="aui-sandbox-artifacts group my-2 overflow-hidden rounded-lg border border-primary-button-bg/20 bg-card-bg"
data-testid="aui-sandbox-artifacts"
>
- <summary className="flex min-h-9 cursor-pointer list-none items-center gap-2 bg-primary-button-bg/5 px-3 py-2 text-xs font-medium leading-none text-primary-button-bg [&::-webkit-details-marker]:hidden">
- <Icon name="chevron-down" size={13} className="shrink-0 transition-transform group-open:rotate-180" />
- <Icon name="file" size={16} className="shrink-0" />
- <span className="leading-none">
- {files.length} {files.length === 1 ? 'file' : 'files'} generated
+ <summary className="min-h-9 cursor-pointer list-none bg-primary-button-bg/5 px-3 py-2 text-xs font-medium leading-none text-primary-button-bg [&::-webkit-details-marker]:hidden">
+ <span className="inline-flex items-center gap-1">
+ <Icon name="chevron-down" size={13} className="shrink-0 transition-transform group-open:rotate-180" />
+ <Icon name="file" size={16} className="shrink-0" />
+ <span className="leading-none">
+ {files.length} {files.length === 1 ? 'file' : 'files'} generated
+ </span>
</span>
</summary>
<div className="flex flex-wrap items-center gap-y-1 px-3 py-2">
{files.map(({ name, path }) => {
if (readOnly) {
- return (
- <span
- key={path}
- className="mr-3 inline-flex min-h-7 items-center gap-1.5 border-r border-border pr-3 text-xs text-text-secondary last:mr-0 last:border-r-0 last:pr-0"
- >
+ const itemClassName =
+ 'mr-3 inline-flex min-h-7 items-center gap-1.5 border-r border-border pr-3 text-xs text-text-secondary last:mr-0 last:border-r-0 last:pr-0';
+ const label = (
+ <>
<Icon name="file" size={14} className="shrink-0" />
<span className="leading-none">{name}</span>
+ </>
+ );
+ if (readOnlyTooltip) {
+ return (
+ <Tooltip key={path} content={readOnlyTooltip} triggerClassName={itemClassName}>
+ <span className="inline-flex items-center gap-1.5">{label}</span>
+ </Tooltip>
+ );
+ }
+ return (
+ <span key={path} className={itemClassName}>
+ {label}
</span>
);
}
diff --git a/packages/trueforge-ui/src/atoms/Markdown.tsx b/packages/trueforge-ui/src/atoms/Markdown.tsx
index 10d0225cb..d4b2df915 100644
--- a/packages/trueforge-ui/src/atoms/Markdown.tsx
+++ b/packages/trueforge-ui/src/atoms/Markdown.tsx
@@ -33,6 +33,8 @@ export type MarkdownProps = {
onDownloadArtifact?: (path: string, filename: string) => Promise<void>;
/** When true, download actions in sandbox artifact blocks are hidden/disabled. */
readOnly?: boolean;
+ /** Shown on hover over sandbox artifact filenames when `readOnly` is true. */
+ sandboxDownloadReadOnlyTooltip?: string;
className?: string;
};
@@ -61,6 +63,7 @@ function makeComponents(opts: {
fileDownloadBaseUrl?: string;
onDownloadArtifact?: (path: string, filename: string) => Promise<void>;
readOnly?: boolean;
+ sandboxDownloadReadOnlyTooltip?: string;
OpenUiFenceBlock: ComponentType<OpenUiFenceBlockProps>;
SandboxArtifactDownload: ComponentType<SandboxArtifactDownloadProps>;
SyntaxHighlighter: ComponentType<SyntaxHighlighterProps>;
@@ -73,6 +76,7 @@ function makeComponents(opts: {
fileDownloadBaseUrl,
onDownloadArtifact,
readOnly,
+ sandboxDownloadReadOnlyTooltip,
OpenUiFenceBlock,
SandboxArtifactDownload,
SyntaxHighlighter,
@@ -118,6 +122,7 @@ function makeComponents(opts: {
fileDownloadBaseUrl={fileDownloadBaseUrl}
onDownloadArtifact={onDownloadArtifact}
readOnly={readOnly}
+ sandboxDownloadReadOnlyTooltip={sandboxDownloadReadOnlyTooltip}
/>
);
}
@@ -156,6 +161,7 @@ export function Markdown({
fileDownloadBaseUrl,
onDownloadArtifact,
readOnly,
+ sandboxDownloadReadOnlyTooltip,
className,
}: MarkdownProps) {
const mode = useThemeMode();
@@ -178,6 +184,7 @@ export function Markdown({
fileDownloadBaseUrl,
onDownloadArtifact,
readOnly,
+ sandboxDownloadReadOnlyTooltip,
OpenUiFenceBlock,
SandboxArtifactDownload,
SyntaxHighlighter,
@@ -189,6 +196,7 @@ export function Markdown({
fileDownloadBaseUrl,
onDownloadArtifact,
readOnly,
+ sandboxDownloadReadOnlyTooltip,
OpenUiFenceBlock,
SandboxArtifactDownload,
SyntaxHighlighter,
diff --git a/packages/trueforge-ui/src/atoms/SandboxArtifactDownload.tsx b/packages/trueforge-ui/src/atoms/SandboxArtifactDownload.tsx
index 4eda1db33..d4f6af21f 100644
--- a/packages/trueforge-ui/src/atoms/SandboxArtifactDownload.tsx
+++ b/packages/trueforge-ui/src/atoms/SandboxArtifactDownload.tsx
@@ -10,6 +10,8 @@ export type SandboxArtifactDownloadProps = {
fileDownloadBaseUrl?: string;
onDownloadArtifact?: (path: string, filename: string) => Promise<void>;
readOnly?: boolean;
+ /** Shown on hover when `readOnly` is true. */
+ sandboxDownloadReadOnlyTooltip?: string;
};
export type SandboxArtifact = ChatFileDownloadFile;
@@ -56,6 +58,7 @@ export function SandboxArtifactDownload({
fileDownloadBaseUrl,
onDownloadArtifact,
readOnly,
+ sandboxDownloadReadOnlyTooltip,
}: SandboxArtifactDownloadProps) {
const ChatFileDownload = useSlot('ChatFileDownload');
const artifacts = useMemo(() => parseSandboxArtifacts(code), [code]);
@@ -67,6 +70,7 @@ export function SandboxArtifactDownload({
fileDownloadBaseUrl={fileDownloadBaseUrl}
onDownloadArtifact={onDownloadArtifact}
readOnly={readOnly}
+ readOnlyTooltip={sandboxDownloadReadOnlyTooltip}
/>
);
}
diff --git a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
index c95e407f2..bb8d08cad 100644
--- a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
+++ b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
@@ -4,6 +4,7 @@ import { ThreadPrimitive, type ThreadMessageLike } from '@assistant-ui/react';
import { convertTurnsToThreadMessages } from '@truefoundry/assistant-ui-runtime';
import { Suspense, useCallback, useEffect, useMemo, useRef, useState, type ComponentType } from 'react';
+import { Markdown, type MarkdownProps } from '../atoms/Markdown.js';
import { useServer } from '../server/ServerContext.js';
import type { AgentChatServer, SessionEventItem } from '../server/types.js';
import type { SlotOverrides } from '../theme/SlotsProvider.js';
@@ -17,9 +18,21 @@ import { AssistantMessageContainer } from './AssistantMessageContainer.js';
import { ReadOnlySessionTurnRuntime } from './ReadOnlySessionTurnRuntime.js';
import { UserMessageContainer } from './UserMessageContainer.js';
+function ReadOnlyMarkdown(props: MarkdownProps) {
+ return (
+ <Markdown
+ {...props}
+ readOnly
+ onDownloadArtifact={undefined}
+ sandboxDownloadReadOnlyTooltip="Download File is not available in read-only mode"
+ />
+ );
+}
+
const READ_ONLY_SLOT_OVERRIDES: SlotOverrides = {
UserMessageActionBar: () => <></>,
MessageActionBar: () => <></>,
+ Markdown: ReadOnlyMarkdown,
};
type TurnCreatedEvent = Extract<SessionEventItem['event'], { type: 'turn.created' }>;
diff --git a/packages/trueforge-ui/test/atoms/ChatFileDownload.test.tsx b/packages/trueforge-ui/test/atoms/ChatFileDownload.test.tsx
index e0aa91908..3ac3a6b72 100644
--- a/packages/trueforge-ui/test/atoms/ChatFileDownload.test.tsx
+++ b/packages/trueforge-ui/test/atoms/ChatFileDownload.test.tsx
@@ -84,6 +84,19 @@ describe('ChatFileDownload', () => {
expect(screen.queryByLabelText(/Download /)).not.toBeInTheDocument();
});
+ it('shows a read-only tooltip on hover when configured', () => {
+ render(
+ <ChatFileDownload
+ readOnly
+ readOnlyTooltip="Download File is not available in read-only mode"
+ files={[{ name: 'report.txt', path: '/report.txt' }]}
+ />,
+ );
+
+ fireEvent.mouseEnter(screen.getByText('report.txt').parentElement ?? screen.getByText('report.txt'));
+ expect(screen.getByRole('tooltip')).toHaveTextContent('Download File is not available in read-only mode');
+ });
+
it('marks files as unavailable when no download mechanism is configured', () => {
render(<ChatFileDownload files={[{ name: 'offline.txt', path: '/offline.txt' }]} />);
diff --git a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
index 080564737..ad3724969 100644
--- a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
+++ b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
@@ -216,4 +216,57 @@ describe('AgentSessionTimelineContainer', () => {
expect(within(turn3).getByText('Cancelled: client-cancelled')).toBeInTheDocument();
expect(within(turn4).getByText('model failed')).toBeInTheDocument();
});
+
+ it('disables sandbox artifact downloads in session turns', async () => {
+ const artifactEvents: SessionEventItem[] = [
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.created',
+ id: 'c1',
+ turnId: 'turn-1',
+ previousTurnId: null,
+ input: [{ type: 'user.message', content: 'generate a file' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'model.message',
+ id: 'm1',
+ threadId: 'main',
+ content: ['Files ready:', '', '```sandbox_artifacts', '[report.txt](/tmp/report.txt)', '```'].join('\n'),
+ createdAt: '2026-01-01T00:00:01.000Z',
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.done',
+ id: 'd1',
+ state: doneState,
+ createdAt: doneState.completedAt,
+ },
+ },
+ ];
+
+ render(
+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>
+ <ServerProvider server={createMockAgentUIServer()}>
+ <AgentSessionTimelineContainer sessionId="sess-1" events={artifactEvents} />
+ </ServerProvider>
+ </SlotsProvider>,
+ );
+
+ expect(await screen.findByTestId('aui-sandbox-artifacts')).toBeInTheDocument();
+ expect(screen.getByText('report.txt')).toBeInTheDocument();
+ expect(screen.queryByLabelText(/Download /)).not.toBeInTheDocument();
+ expect(screen.queryAllByRole('link')).toHaveLength(0);
+
+ fireEvent.mouseEnter(screen.getByText('report.txt').parentElement ?? screen.getByText('report.txt'));
+ expect(screen.getByRole('tooltip')).toHaveTextContent('Download File is not available in read-only mode');
+ });
});