The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): index explicitly delivered Office documents in Artifacts
Konstantin Khlopkovf9c632a193d0
diff --git a/apps/desktop/src/app/artifacts/artifact-utils.ts b/apps/desktop/src/app/artifacts/artifact-utils.tsindex 2a8649d08ff..0d39c0f2baf 100644--- a/apps/desktop/src/app/artifacts/artifact-utils.ts+++ b/apps/desktop/src/app/artifacts/artifact-utils.ts@@ -36,7 +36,7 @@ const WINDOWS_PATH_RE = /(^|[\s("'`])([A-Za-z]:[\\/][^\s"'`<>]+(?:\.[a-z0-9]{1,8const IMAGE_EXT_RE = /\.(?:png|jpe?g|gif|webp|svg|bmp)(?:\?.*)?$/iconst FILE_EXT_RE =- /\.(?:png|jpe?g|gif|webp|svg|bmp|pdf|txt|json|md|csv|zip|tar|gz|avi|flac|m4a|mkv|mp3|ogg|opus|wav|webm|mp4|mov)(?:\?.*)?$/i+ /\.(?:png|jpe?g|gif|webp|svg|bmp|pdf|txt|json|md|csv|xlsx?|docx?|pptx?|html|zip|tar|gz|avi|flac|m4a|mkv|mp3|ogg|opus|wav|webm|mp4|mov)(?:\?.*)?$/iconst MAX_UNIX_SECONDS = 10_000_000_000@@ -51,6 +51,31 @@ const PRODUCER_TOOL_ARTIFACT_KEY_RE =const SCREENSHOT_PATH_RE = /Screenshot path:\s*([^\r\n<>]+)/gi+// A pushValue callback plus whether the value is an explicit delivery the+// author asserted as an artifact (a raw `MEDIA:` tag), as opposed to a path+// scraped heuristically out of prose or a tool payload.+type PushValue = (value: string, explicit?: boolean) => void++function looksLikeArtifact(value: string, explicit = false): boolean {+ if (/^(?:https?:\/\/|data:image\/)/.test(value)) {+ return true+ }++ if (!looksLikePathOrUrl(value)) {+ return false+ }++ // An explicitly delivered file is an artifact by definition even when its+ // extension is unknown — it should be listed as an opaque `file` entry+ // rather than silently vanish. Extensionless bare paths scraped from prose+ // stay excluded.+ if (explicit) {+ return true+ }++ return IMAGE_EXT_RE.test(value) || FILE_EXT_RE.test(value)+}+function artifactSessionTitle(session: SessionInfo): string {return session.title?.trim() || session.preview?.trim() || 'Untitled session'}@@ -72,9 +97,9 @@ function unquoteMediaValue(value: string): string {return trimmed}-function collectMediaValues(text: string, pushValue: (value: string) => void): void {+function collectMediaValues(text: string, pushValue: PushValue): void {for (const value of mediaTagValues(text)) {- pushValue(unquoteMediaValue(value))+ pushValue(unquoteMediaValue(value), true)}}@@ -141,14 +166,6 @@ function looksLikePathOrUrl(value: string): boolean {)}-function looksLikeArtifact(value: string): boolean {- if (/^(?:https?:\/\/|data:image\/)/.test(value)) {- return true- }-- return looksLikePathOrUrl(value) && (IMAGE_EXT_RE.test(value) || FILE_EXT_RE.test(value))-}-function artifactKind(value: string): ArtifactKind {if (value.startsWith('data:image/') || IMAGE_EXT_RE.test(value)) {return 'image'@@ -257,7 +274,7 @@ function collectStringValues(}}-function collectArtifactsFromText(text: string, pushValue: (value: string) => void): void {+function collectArtifactsFromText(text: string, pushValue: PushValue): void {collectMediaValues(text, pushValue)for (const match of text.matchAll(MARKDOWN_IMAGE_RE)) {@@ -330,7 +347,7 @@ function structuredToolPayload(message: SessionMessage): null | unknown {return content}-function collectArtifactsFromMessage(message: SessionMessage, pushValue: (value: string) => void): void {+function collectArtifactsFromMessage(message: SessionMessage, pushValue: PushValue): void {const text = messageText(message)if (message.role === 'assistant' && text) {@@ -389,10 +406,10 @@ export function collectArtifactsForSession(session: SessionInfo, messages: Sessicontinue}- collectArtifactsFromMessage(message, candidate => {+ collectArtifactsFromMessage(message, (candidate, explicit = false) => {const value = normalizeValue(candidate)- if (!value || !looksLikeArtifact(value)) {+ if (!value || !looksLikeArtifact(value, explicit)) {return}diff --git a/apps/desktop/src/app/artifacts/index.test.ts b/apps/desktop/src/app/artifacts/index.test.tsindex e39c36ac741..bf1d25643ee 100644--- a/apps/desktop/src/app/artifacts/index.test.ts+++ b/apps/desktop/src/app/artifacts/index.test.ts@@ -251,6 +251,58 @@ ${payload}])})+ it('indexes explicitly delivered Office documents as files', () => {+ const artifacts = collectArtifactsForSession(makeSession({ id: 'office-session' }), [+ {+ content: 'Workbook ready. MEDIA:C:\\Users\\Example\\Documents\\report.xlsx',+ role: 'assistant',+ timestamp: 1_781_774_001+ },+ {+ content: 'Deck exported. **MEDIA: /tmp/generated/summary.pptx**',+ role: 'assistant',+ timestamp: 1_781_774_002+ },+ {+ content: 'Notes compiled. MEDIA:"/tmp/generated/contract draft.docx"',+ role: 'assistant',+ timestamp: 1_781_774_003+ }+ ])++ expect(artifacts.map(artifact => artifact.kind)).toEqual(['file', 'file', 'file'])+ expect(artifacts.map(artifact => artifact.value)).toEqual([+ 'C:\\Users\\Example\\Documents\\report.xlsx',+ '/tmp/generated/summary.pptx',+ '/tmp/generated/contract draft.docx'+ ])+ })++ it('keeps unknown-extension explicit deliveries as opaque files', () => {+ const artifacts = collectArtifactsForSession(makeSession({ id: 'odd-ext-session' }), [+ {+ content: 'Palette saved. MEDIA:/tmp/generated/palette.icc',+ role: 'assistant',+ timestamp: 1_781_774_001+ }+ ])++ expect(artifacts).toHaveLength(1)+ expect(artifacts[0]).toMatchObject({ kind: 'file', value: '/tmp/generated/palette.icc' })+ })++ it('does not index extensionless or unknown-extension bare paths from prose', () => {+ const artifacts = collectArtifactsForSession(makeSession(), [+ {+ content: 'State lives in /tmp/plumbing/state-dir and /tmp/notes.bin',+ role: 'assistant',+ timestamp: 1_781_774_001+ }+ ])++ expect(artifacts).toHaveLength(0)+ })+it('normalizes epoch-second message timestamps', () => {const artifacts = collectArtifactsForSession(makeSession(), [{