Skip to content

The agent that grows with you

fix(desktop): show local vision images in activity

KoNit-K46cd0458c14e
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
index 26297ae2d41..1505450a68f 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model.test.ts
@@ -27,12 +27,9 @@ afterEach(() => {
})
describe('buildToolView image handling', () => {
- // vision_analyze reports the input image as a local path; an <img> pointed at
- // a bare path resolves against the renderer origin and 404s, so we render the
- // tool codicon instead of a broken image.
- it('drops bare filesystem paths', () => {
- expect(buildToolView(part({ args: { path: '/Users/me/shot.png' } }), '').imageUrl).toBe('')
- expect(buildToolView(part({ result: { image_path: '/tmp/out.jpg' } }), '').imageUrl).toBe('')
+ it('keeps local image paths for the activity renderer to resolve', () => {
+ expect(buildToolView(part({ args: { path: '/Users/me/shot.png' } }), '').imageUrl).toBe('/Users/me/shot.png')
+ expect(buildToolView(part({ result: { image_path: '/tmp/out.jpg' } }), '').imageUrl).toBe('/tmp/out.jpg')
})
it('keeps fetchable data URLs', () => {
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
index 3b7bf7d5e1c..a0aaed80ca1 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback-model/index.ts
@@ -2,6 +2,7 @@ import { stripAnsi } from '@hermes/shared/ansi'
import { type ToolTitleKey, translateNow } from '@/i18n'
import { normalizeExternalUrl } from '@/lib/external-link'
+import { isFileMediaPath, mediaKind } from '@/lib/media'
import { summarizeShellCommand } from '@/lib/summarize-command'
import { capitalize, firstStringField, normalize } from '@/lib/text'
import { CONNECTION_CARD_KEY, isCardTool, isFileEditTool, isSilentTool } from '@/lib/tool-render-class'
@@ -781,14 +782,14 @@ function toolImageUrl(args: Record<string, unknown>, result: Record<string, unkn
return ''
}
- // Only inline-render images the renderer can actually fetch: data URLs or
- // remote http(s). A bare filesystem path (e.g. vision_analyze's input image)
- // resolves against the dev-server origin and 404s — fall back to the tool's
- // codicon instead of a broken <img>.
+ // Filesystem images are resolved by the activity renderer through the
+ // authenticated media pipeline before they reach an <img>. This matters for
+ // vision_analyze, whose input commonly lives on the local or remote gateway.
const isDataImage = candidate.toLowerCase().startsWith('data:image/')
const isRemoteImage = /^https?:\/\//i.test(candidate) && /\.(png|jpe?g|gif|webp|bmp|svg)(\?|#|$)/i.test(candidate)
+ const isLocalImage = isFileMediaPath(candidate) && mediaKind(candidate) === 'image'
- return isDataImage || isRemoteImage ? candidate : ''
+ return isDataImage || isRemoteImage || isLocalImage ? candidate : ''
}
export function stripInlineDiffChrome(value: string): string {
diff --git a/apps/desktop/src/components/assistant-ui/tool/fallback.tsx b/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
index 3cc8c8c41ae..0a49c542279 100644
--- a/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
+++ b/apps/desktop/src/components/assistant-ui/tool/fallback.tsx
@@ -44,6 +44,7 @@ import { useI18n } from '@/i18n'
import { connectorCalls, mcpTargets } from '@/lib/connector-tools'
import { PrettyLink, LinkifiedText as SharedLinkifiedText, urlSlugTitleLabel } from '@/lib/external-link'
import { AlertCircle, CheckCircle2 } from '@/lib/icons'
+import { resolveMediaDisplaySrc } from '@/lib/media'
import { isOnboardingEnabled } from '@/lib/onboarding-enabled'
import { toolResultRecord } from '@/lib/tool-result-metadata'
import { useEnterAnimation } from '@/lib/use-enter-animation'
@@ -112,6 +113,41 @@ const TOOL_SECTION_PRE_CLASS = cn(TOOL_SECTION_SURFACE_CLASS, 'font-mono text-[0
// Raw args/result dump — reference material, so a notch smaller than a body.
const TOOL_PAYLOAD_PRE_CLASS = cn(TOOL_SECTION_SURFACE_CLASS, 'font-mono text-[0.65rem] leading-relaxed')
+function ToolActivityImage({ alt, src }: { alt: string; src: string }) {
+ const [resolvedSrc, setResolvedSrc] = useState('')
+
+ useEffect(() => {
+ let cancelled = false
+
+ setResolvedSrc('')
+ void resolveMediaDisplaySrc(src)
+ .then(value => {
+ if (!cancelled) {
+ setResolvedSrc(value)
+ }
+ })
+ .catch(() => {
+ if (!cancelled) {
+ setResolvedSrc('')
+ }
+ })
+
+ return () => {
+ cancelled = true
+ }
+ }, [src])
+
+ if (!resolvedSrc) {
+ return null
+ }
+
+ return (
+ <div className="max-w-72 overflow-hidden rounded-[0.25rem] border border-(--ui-stroke-tertiary)">
+ <ZoomableImage alt={alt} className="h-auto w-full object-cover" src={resolvedSrc} />
+ </div>
+ )
+}
+
/**
* Technical-mode raw payload, behind a chevron disclosure.
*
@@ -624,11 +660,7 @@ function ToolEntry({ part }: ToolEntryProps) {
{part.toolName === 'terminal' && toolViewMode !== 'technical' && (
<TerminalTranscript command={view.terminalCommand} exitCode={view.terminalExitCode} />
)}
- {view.imageUrl && (
- <div className="max-w-72 overflow-hidden rounded-[0.25rem] border border-(--ui-stroke-tertiary)">
- <ZoomableImage alt={copy.outputAlt} className="h-auto w-full object-cover" src={view.imageUrl} />
- </div>
- )}
+ {view.imageUrl && <ToolActivityImage alt={copy.outputAlt} src={view.imageUrl} />}
{hasSearchHits && view.searchHits && (
<div className="max-w-full text-xs leading-relaxed text-(--ui-text-secondary)">
{view.searchQuery && (