Skip to content

The agent that grows with you

fix(desktop): MEDIA: non-media files get the preview file card, not a degraded 'Open' anchor (#97812)

Tekniumfae063fc74d2
diff --git a/agent/prompt_builder.py b/agent/prompt_builder.py
index 050cef06d54..44757c95c25 100644
--- a/agent/prompt_builder.py
+++ b/agent/prompt_builder.py
@@ -878,10 +878,11 @@ PLATFORM_HINTS = {
"GitHub flavor (tables, code blocks with syntax highlighting, math "
"via $...$, task lists, blockquote callouts). "
"You can deliver files natively — include MEDIA:/absolute/path/to/file "
- "in your response. Images (.png, .jpg, .webp) appear inline, audio and "
- "video play inline, and other files arrive as download links. You can "
- "also include image URLs in markdown format ![alt](url) and they "
- "render inline as photos. "
+ "in your response, any file type. Images appear inline, audio and "
+ "video play inline, and every other file becomes a card that opens in "
+ "the preview pane. Image URLs also render inline via markdown "
+ "![alt](url) — but for local files use MEDIA:, never markdown image "
+ "syntax (local ![](C:/...) is blocked by the renderer). "
"To show an HTML file you wrote as a LIVE inline page right in your "
"message, put ::preview{file=\"path/to/file.html\"} alone on its own "
"line — desktop plugins can register more ::name{...} directives like "
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.media-md.test.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.media-md.test.tsx
index 9ade3e89793..f124fd23379 100644
--- a/apps/desktop/src/components/assistant-ui/markdown-text.media-md.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/markdown-text.media-md.test.tsx
@@ -34,12 +34,27 @@ describe('markdown documents delivered via MEDIA', () => {
expect(screen.getByText('report.md')).toBeTruthy()
})
- it('still renders a non-markdown MEDIA file through the media fallback', async () => {
+ it('renders a non-markdown MEDIA file as a preview attachment too', async () => {
+ // Extends #84951 to every non-media extension: PDFs, archives, data
+ // files. MediaAttachment's kind==='file' branch was a degraded dead-end
+ // (bare "Open ..." anchor, verified live with .pdf and .qzx7 — the
+ // markdown-LINK path already gave these a proper file card). MEDIA:
+ // must never render worse than a plain markdown link to the same file.
const href = mediaMarkdownHref('/home/user/out/archive.zip')
render(<MarkdownTextContent isRunning={false} text={`[archive.zip](${href})`} />)
- expect(await screen.findByText(/archive\.zip/)).toBeTruthy()
- expect(screen.queryByRole('button')).toBeNull()
+ expect(await screen.findByRole('button')).toBeTruthy()
+ expect(screen.getByText('archive.zip')).toBeTruthy()
+ expect(screen.queryByText(/^Open archive/)).toBeNull()
+ })
+
+ it('renders a MEDIA pdf as a preview attachment', async () => {
+ const href = mediaMarkdownHref('C:/Users/a/report.pdf')
+
+ render(<MarkdownTextContent isRunning={false} text={`[report.pdf](${href})`} />)
+
+ expect(await screen.findByRole('button')).toBeTruthy()
+ expect(screen.getByText('report.pdf')).toBeTruthy()
})
})
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
index 5f3e2892d25..f0671fb1a84 100644
--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
@@ -266,6 +266,16 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'a
return <PreviewAttachment source="tool-result" target={mediaPath} />
}
+ // Non-media files (PDFs, data files, anything outside MEDIA_BY_EXT):
+ // MediaAttachment's kind==='file' branch is a degraded dead-end (bare
+ // "Open <name>" anchor). Route through the preview pipeline instead —
+ // the same file card + "Open preview" the bare-path markdown-link
+ // branch below produces — so MEDIA: uniformly delivers the richest
+ // rendering for every file type.
+ if (mediaKind(mediaPath) === 'file') {
+ return <PreviewAttachment source="tool-result" target={mediaPath} />
+ }
+
return <MediaAttachment path={mediaPath} />
}