- {files.map((file, index) => (
-
- @
- {attachmentLabel(file)}
-
- ))}
+ {files.map((file, index) =>
+ file.mime.startsWith('image/') ? (
+
+ ) : (
+
+ @
+ {attachmentLabel(file)}
+
+ ),
+ )}
{agents.map((agent, index) => (
void
+ directory?: string
}
interface MermaidBlockProps {
@@ -181,11 +184,16 @@ function isMermaidBlockComplete(text: string): boolean {
return false
}
-export function TextPart({ text, onFileClick }: TextPartProps) {
+export function TextPart({ text, onFileClick, directory }: TextPartProps) {
const mermaidComplete = React.useMemo(() => {
return text ? isMermaidBlockComplete(text) : false
}, [text])
+ const resolveLocalPath = useMemo(
+ () => (directory ? (path: string) => getWorkspaceFilePath(path, { directory }) : undefined),
+ [directory],
+ )
+
if (!text || text.trim() === '') {
return null
}
@@ -195,6 +203,7 @@ export function TextPart({ text, onFileClick }: TextPartProps) {
},
+ img(props) {
+ return
+ },
}}
>
{text}
diff --git a/frontend/src/components/ui/inline-image.test.tsx b/frontend/src/components/ui/inline-image.test.tsx
new file mode 100644
index 00000000..fab0ef5f
--- /dev/null
+++ b/frontend/src/components/ui/inline-image.test.tsx
@@ -0,0 +1,25 @@
+import { describe, it, expect } from 'vitest'
+import { render, screen, fireEvent } from '@testing-library/react'
+import { InlineImage } from './inline-image'
+
+describe('InlineImage', () => {
+ it('opens a full-size dialog when the thumbnail is clicked', () => {
+ render()
+
+ const thumbnail = screen.getByAltText('shot.png')
+ expect(thumbnail).toHaveAttribute('src', 'data:image/png;base64,aGVsbG8=')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Expand image: shot.png' }))
+
+ expect(screen.getAllByAltText('shot.png')).toHaveLength(2)
+ })
+
+ it('falls back to the alt text when the image fails to load', () => {
+ render()
+
+ fireEvent.error(screen.getByAltText('shot.png'))
+
+ expect(screen.queryByRole('button')).not.toBeInTheDocument()
+ expect(screen.getByText('shot.png')).toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/components/ui/inline-image.tsx b/frontend/src/components/ui/inline-image.tsx
new file mode 100644
index 00000000..7fd5f185
--- /dev/null
+++ b/frontend/src/components/ui/inline-image.tsx
@@ -0,0 +1,44 @@
+import { useState } from 'react'
+import { cn } from '@/lib/utils'
+import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
+
+/**
+ * Renders an image as a bounded thumbnail button that opens a full-size preview dialog.
+ * Falls back to a muted alt-text span (or nothing) when the image fails to load.
+ */
+export function InlineImage({ src, alt, className }: { src: string; alt?: string; className?: string }) {
+ const [open, setOpen] = useState(false)
+ const [failed, setFailed] = useState(false)
+
+ if (failed) {
+ return alt ? {alt} : null
+ }
+
+ return (
+ <>
+
+
+ >
+ )
+}
diff --git a/frontend/src/components/ui/markdown-image.tsx b/frontend/src/components/ui/markdown-image.tsx
new file mode 100644
index 00000000..614cfcb7
--- /dev/null
+++ b/frontend/src/components/ui/markdown-image.tsx
@@ -0,0 +1,34 @@
+import type { ComponentPropsWithoutRef } from 'react'
+import type { ExtraProps } from 'react-markdown'
+import { InlineImage } from '@/components/ui/inline-image'
+import { getFileApiUrl } from '@/api/files'
+import { getLocalLinkPath } from '@/lib/markdownLinks'
+
+type MarkdownImageProps = ComponentPropsWithoutRef<'img'> & ExtraProps & {
+ resolveLocalPath?: (path: string) => string | null
+}
+
+/**
+ * Renders a markdown image through the inline image viewer. Local file sources, resolved by
+ * `resolveLocalPath` or absolute, load through the raw file API; everything else, including
+ * `data:image/*` URIs, is rendered unchanged.
+ */
+export function MarkdownImage({ src, alt, resolveLocalPath }: MarkdownImageProps) {
+ if (typeof src !== 'string' || src === '') {
+ return null
+ }
+
+ const localPath = getLocalLinkPath(src)
+ let imageSrc = src
+
+ if (localPath) {
+ const resolvedPath = resolveLocalPath?.(localPath) ?? null
+ if (resolvedPath) {
+ imageSrc = getFileApiUrl(resolvedPath, { params: { raw: true } })
+ } else if (localPath.startsWith('/')) {
+ imageSrc = getFileApiUrl(localPath, { params: { raw: true } })
+ }
+ }
+
+ return
+}
diff --git a/frontend/src/lib/markdownRehypePlugins.ts b/frontend/src/lib/markdownRehypePlugins.ts
index 2e81a113..764e0ee0 100644
--- a/frontend/src/lib/markdownRehypePlugins.ts
+++ b/frontend/src/lib/markdownRehypePlugins.ts
@@ -1,11 +1,37 @@
import rehypeHighlight from 'rehype-highlight'
import rehypeRaw from 'rehype-raw'
-import rehypeSanitize from 'rehype-sanitize'
-import type { Options } from 'react-markdown'
+import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'
+import { defaultUrlTransform } from 'react-markdown'
+import type { Options, UrlTransform } from 'react-markdown'
+
+const markdownSanitizeSchema = {
+ ...defaultSchema,
+ protocols: {
+ ...defaultSchema.protocols,
+ src: [...(defaultSchema.protocols?.src ?? []), 'data'],
+ },
+}
/**
* Rehype pipeline shared by every Markdown renderer. Raw HTML is parsed, then sanitized to
* GitHub's allow-list so scripts, frames and event handlers are stripped from model output and
- * repository files, and highlighting runs last so its classes survive sanitization.
+ * repository files, and highlighting runs last so its classes survive sanitization. The schema
+ * additionally allows the `data` protocol on `src` so inline image data URIs survive sanitization.
*/
-export const markdownRehypePlugins: NonNullable = [rehypeRaw, rehypeSanitize, rehypeHighlight]
+export const markdownRehypePlugins: NonNullable = [
+ rehypeRaw,
+ [rehypeSanitize, markdownSanitizeSchema],
+ rehypeHighlight,
+]
+
+/**
+ * URL transform for Markdown renderers. Keeps `data:image/*` sources intact, which react-markdown's
+ * default transform strips, and defers every other URL to that default.
+ */
+export const markdownUrlTransform: UrlTransform = (url, key) => {
+ if (key === 'src' && /^data:image\//i.test(url)) {
+ return url
+ }
+
+ return defaultUrlTransform(url)
+}
diff --git a/shared/src/config/defaults.ts b/shared/src/config/defaults.ts
index 641765f4..c9063722 100644
--- a/shared/src/config/defaults.ts
+++ b/shared/src/config/defaults.ts
@@ -90,6 +90,7 @@ export const ALLOWED_MIME_TYPES = [
'image/png',
'image/jpeg',
'image/gif',
+ 'image/webp',
'image/svg+xml',
'application/pdf',
'application/zip',