diff --git a/desktop/src/store/chat/streamStore.ts b/desktop/src/store/chat/streamStore.ts index a5b4bcd..0cad221 100644 --- a/desktop/src/store/chat/streamStore.ts +++ b/desktop/src/store/chat/streamStore.ts @@ -34,6 +34,7 @@ import { resolveGatewayAgentId, } from './conversationStore'; import { useMessageStore } from './messageStore'; +import { useArtifactStore } from './artifactStore'; const log = createLogger('StreamStore'); @@ -297,6 +298,39 @@ export const useStreamStore = create()( return { ...m, toolSteps: steps }; }) ); + + // Auto-create artifact when file_write tool produces output + if (tool === 'file_write' && output) { + try { + const parsed = JSON.parse(output); + const filePath = parsed?.path || parsed?.file_path || ''; + const content = parsed?.content || ''; + if (filePath && content) { + const fileName = filePath.split('/').pop() || filePath; + const ext = fileName.split('.').pop()?.toLowerCase() || ''; + const typeMap: Record = { + ts: 'code', tsx: 'code', js: 'code', jsx: 'code', + py: 'code', rs: 'code', go: 'code', java: 'code', + md: 'markdown', txt: 'text', json: 'code', + html: 'code', css: 'code', sql: 'code', sh: 'code', + }; + const langMap: Record = { + ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript', + py: 'python', rs: 'rust', go: 'go', java: 'java', + html: 'html', css: 'css', sql: 'sql', sh: 'bash', json: 'json', + }; + useArtifactStore.getState().addArtifact({ + id: `artifact_${Date.now()}`, + name: fileName, + content: typeof content === 'string' ? content : JSON.stringify(content, null, 2), + type: typeMap[ext] || 'text', + language: langMap[ext], + createdAt: new Date(), + sourceStepId: assistantId, + }); + } + } catch { /* non-critical: artifact creation from tool output */ } + } } else { // toolStart: create new running step const step: ToolCallStep = {