The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): MEDIA-delivered .md opens in the preview rail, not as a download link
Tekniumcb7dd6d2b867
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.tsxnew file mode 100644index 00000000000..9ade3e89793--- /dev/null+++ b/apps/desktop/src/components/assistant-ui/markdown-text.media-md.test.tsx@@ -0,0 +1,45 @@+import { cleanup, render, screen } from '@testing-library/react'+import { afterEach, describe, expect, it } from 'vitest'++import { isMarkdownDocumentPath, mediaMarkdownHref } from '@/lib/media'++import { MarkdownTextContent } from './markdown-text'++// Regression for #84951: a `.md` delivered via MEDIA has no entry in+// MEDIA_BY_EXT, so it classified as a generic 'file' and rendered as a+// download-style link. Markdown is renderable content — it must route to the+// preview rail (which renders .md with a rendered/source toggle) instead.+describe('markdown documents delivered via MEDIA', () => {+ afterEach(cleanup)++ it('classifies markdown extensions as markdown documents', () => {+ expect(isMarkdownDocumentPath('/tmp/report.md')).toBe(true)+ expect(isMarkdownDocumentPath('/tmp/notes.markdown')).toBe(true)+ expect(isMarkdownDocumentPath('C:\\Users\\a\\report.MD')).toBe(true)+ expect(isMarkdownDocumentPath('/tmp/report.md?x=1')).toBe(true)+ expect(isMarkdownDocumentPath('/tmp/archive.zip')).toBe(false)+ expect(isMarkdownDocumentPath('/tmp/clip.mp4')).toBe(false)+ expect(isMarkdownDocumentPath('/tmp/README')).toBe(false)+ })++ it('renders a MEDIA .md as a preview attachment, not a download link', async () => {+ const href = mediaMarkdownHref('/home/user/out/report.md')++ render(<MarkdownTextContent isRunning={false} text={`[report.md](${href})`} />)++ // PreviewAttachment renders an "open preview" toggle button; the old+ // MediaAttachment 'file' fallback rendered a bare "Open ..." anchor.+ expect(await screen.findByRole('button')).toBeTruthy()+ expect(screen.queryByText(/^Loading /)).toBeNull()+ expect(screen.getByText('report.md')).toBeTruthy()+ })++ it('still renders a non-markdown MEDIA file through the media fallback', async () => {+ 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()+ })+})diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsxindex b2e6ba0c2b7..f9eb78084af 100644--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx@@ -23,6 +23,7 @@ import { preprocessMarkdown } from '@/lib/markdown-preprocess'import {downloadGatewayMediaFile,isInlineMediaSrc,+ isMarkdownDocumentPath,isRemoteGateway,mediaExternalUrl,mediaKind,@@ -255,6 +256,14 @@ function MarkdownLink({ children, className, href, ...props }: ComponentProps<'aconst mediaPath = mediaPathFromMarkdownHref(href)if (mediaPath) {+ // A delivered markdown document is renderable content, not an opaque+ // download: route it to the preview rail (which renders .md with a+ // rendered/source toggle) instead of the download-link fallback that+ // `mediaKind() === 'file'` would produce. (#84951)+ if (isMarkdownDocumentPath(mediaPath)) {+ return <PreviewAttachment source="tool-result" target={mediaPath} />+ }+return <MediaAttachment path={mediaPath} />}diff --git a/apps/desktop/src/lib/media.ts b/apps/desktop/src/lib/media.tsindex 97404eb1895..3bc9808aa50 100644--- a/apps/desktop/src/lib/media.ts+++ b/apps/desktop/src/lib/media.ts@@ -40,6 +40,17 @@ export function mediaKind(path: string): MediaKind {return mediaInfo(path)?.kind ?? 'file'}+// Markdown is renderable content, not an opaque download: the preview rail+// already knows how to render a `.md` file (rendered/source toggle), so the+// MEDIA delivery path routes these to a preview instead of a download link.+const MARKDOWN_EXTENSIONS = new Set(['md', 'markdown', 'mdown', 'mkd'])++export function isMarkdownDocumentPath(path: string): boolean {+ const ext = path.split(/[?#]/, 1)[0]?.split('.').pop()?.toLowerCase()++ return ext ? MARKDOWN_EXTENSIONS.has(ext) : false+}+export function mediaMime(path: string): string {return mediaInfo(path)?.mime ?? 'application/octet-stream'}