Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-ui): tell the user about a duplicate document and title both attachment kinds
Alfredo Lopez7a3d090523ee
diff --git a/desktop-app/test/e2e-playwright/qa-recorder-document-upload.spec.ts b/desktop-app/test/e2e-playwright/qa-recorder-document-upload.spec.tsindex b22e5e49e..afada39b2 100644--- a/desktop-app/test/e2e-playwright/qa-recorder-document-upload.spec.ts+++ b/desktop-app/test/e2e-playwright/qa-recorder-document-upload.spec.ts@@ -375,7 +375,6 @@ test('document-upload fixture: an attached text file reaches the model through tfs.mkdirSync(testInfo.outputPath(), { recursive: true })fs.writeFileSync(testInfo.outputPath(document.fileName), document.buffer)- fs.writeFileSync(testInfo.outputPath(largeDocument.fileName), largeDocument.buffer)let app: ElectronApplication | undefinedlet recordedPage: Page | undefineddiff --git a/desktop-app/ui/src/components/agents/ComposerPanel.tsx b/desktop-app/ui/src/components/agents/ComposerPanel.tsxindex 81e9c8bad..964ab76e0 100644--- a/desktop-app/ui/src/components/agents/ComposerPanel.tsx+++ b/desktop-app/ui/src/components/agents/ComposerPanel.tsx@@ -400,9 +400,9 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrcomposerImageAttachments.length > 0 && hostModelSelection.visualSendBlocked// Per-instance id: the main panel and the chat drawer can both be mounted.const imageNoticeId = useId()- // #678 — a document that is still being read, or that failed, is not part of- // the message. Sending now would leave it out without saying so, so send- // stays disabled until each chip is ready or removed.+ // #678 — a document that is still being read is not part of the message yet.+ // Sending now would leave it out without saying so, so send stays disabled+ // until each chip is ready or removed.const filesBlockedForSend = composerFileAttachments.some(file => file.status !== 'ready')const handleSend = useCallback(() => {if (imagesBlockedForSend || filesBlockedForSend) return@@ -1111,7 +1111,7 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrdata-file-status={attachment.status}><span- className="composer-reference-icon composer-reference-icon--uploaded-image"+ className="composer-reference-icon composer-reference-icon--uploaded-file"aria-hidden="true"><IconAttachFile />diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsxindex 8339e0404..3a1be9be6 100644--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx@@ -12,6 +12,7 @@ import {COMPOSER_MAX_TOTAL_IMAGE_BASE64_BYTES,} from '@constants/attachments'import type { HostModelsResult } from '@hooks/useChatStore'+import { readComposerFile } from '@lib/composerFileAdmission'import {type ImageInputDecision,imageInputBlockMessage,@@ -1047,39 +1048,33 @@ describe('ComposerPanel failed-send recovery actions', () => {})describe('ComposerPanel document attachments (#678)', () => {- const readyClassification = {- class: 'text' as const,- detectedMediaType: 'text/plain',- detection: 'text_utf8' as const,- textReadable: true,- reader: 'text' as const,- modelImageInput: 'unsupported' as const,- mismatch: false,+ /** A chip built by the same read the composer runs, never by hand. */+ async function readyFile(+ id: string,+ name: string,+ bytes: Uint8Array<ArrayBuffer>,+ type: string+ ): Promise<ComposerFileAttachment> {+ const result = await readComposerFile(new File([bytes], name, { type }), id)+ if (result.status !== 'ready') throw new Error(`fixture ${name} did not read: ${result.error}`)+ return result}- function readyFile(- overrides: Partial<Extract<ComposerFileAttachment, { status: 'ready' }>> = {}- ) {- return {- id: 'file-1',- type: 'file' as const,- filename: 'notes.txt',- sizeBytes: 2048,- declaredMediaType: 'text/plain',- status: 'ready' as const,- classification: readyClassification,- dataBase64: 'aGVsbG8=',- digestHex: 'a'.repeat(64),- ...overrides,- }+ const notesBytes = new TextEncoder().encode('n'.repeat(2048))+ // A ZIP local-file header: bytes the agent has no reader for.+ const zipBytes = new Uint8Array([0x50, 0x4b, 0x03, 0x04, ...new Array(60).fill(0)])+ const pdfBytes = new TextEncoder().encode('%PDF-1.4\n1 0 obj\n<<>>\nendobj\n%%EOF\n')++ function notesFile() {+ return readyFile('file-1', 'notes.txt', notesBytes, 'text/plain')}function sendButton(): HTMLButtonElement {return screen.getByRole('button', { name: 'Send message' }) as HTMLButtonElement}- it('shows a ready document chip and lets a message with only that document be sent', () => {- composerState.composerFileAttachments = [readyFile()]+ it('shows a ready document chip and lets a message with only that document be sent', async () => {+ composerState.composerFileAttachments = [await notesFile()]render(<ComposerPanel inline />)const chip = screen.getByTestId('composer-file-chip')@@ -1089,15 +1084,27 @@ describe('ComposerPanel document attachments (#678)', () => {expect(sendButton().disabled).toBe(false)})- it('removes a document through its chip button', () => {- composerState.composerFileAttachments = [readyFile()]+ it('gives a document chip its own icon class, not the image one', async () => {+ composerState.composerFileAttachments = [await notesFile()]+ render(<ComposerPanel inline />)++ const chip = screen.getByTestId('composer-file-chip')+ // Witness: the chip renders its icon at all.+ expect(chip.querySelector('.composer-reference-icon')).not.toBeNull()+ expect(chip.querySelector('.composer-reference-icon--uploaded-file')).not.toBeNull()+ expect(chip.querySelector('.composer-reference-icon--uploaded-image')).toBeNull()+ })++ it('removes a document through its chip button', async () => {+ composerState.composerFileAttachments = [await notesFile()]render(<ComposerPanel inline />)fireEvent.click(screen.getByRole('button', { name: 'Remove notes.txt' }))expect(actionsMock.handleRemoveComposerFileAttachment).toHaveBeenCalledWith('file-1')})- it.each(['selected', 'reading'] as const)('blocks the send while a document is %s', status => {+ it('blocks the send while a document is reading', () => {+ // A reading chip has no read result yet, so it is the one built by hand.composerState.composerFileAttachments = [{id: 'file-2',@@ -1105,7 +1112,7 @@ describe('ComposerPanel document attachments (#678)', () => {filename: 'big.pdf',sizeBytes: 1024,declaredMediaType: 'application/pdf',- status,+ status: 'reading',},]draftState.value = 'read this'@@ -1131,14 +1138,10 @@ describe('ComposerPanel document attachments (#678)', () => {expect(sendButton().disabled).toBe(false)})- it('lists refusals before the notices of ready documents', () => {+ it('lists refusals before the notices of ready documents', async () => {composerState.composerFileRefusals = [{ id: 'refusal-2', text: 'huge.bin is too large.' }]composerState.composerFileAttachments = [- readyFile({- id: 'file-5',- filename: 'archive.zip',- classification: { ...readyClassification, class: 'binary_unsupported', reader: 'none' },- }),+ await readyFile('file-5', 'archive.zip', zipBytes, 'application/zip'),]render(<ComposerPanel inline />)@@ -1148,14 +1151,11 @@ describe('ComposerPanel document attachments (#678)', () => {expect(screen.getByTestId('composer-file-chip').getAttribute('data-file-status')).toBe('ready')})- it('says when the agent has no reader for an attached document', () => {- composerState.composerFileAttachments = [- readyFile({- id: 'file-4',- filename: 'archive.zip',- classification: { ...readyClassification, class: 'binary_unsupported', reader: 'none' },- }),- ]+ it('says when the agent has no reader for an attached document', async () => {+ const archive = await readyFile('file-4', 'archive.zip', zipBytes, 'application/zip')+ // Precondition: the real read classifies these bytes as unreadable.+ expect(archive.status === 'ready' && archive.classification.reader).toBe('none')+ composerState.composerFileAttachments = [archive]render(<ComposerPanel inline />)expect(screen.getByTestId('composer-file-chip').textContent).toContain('No reader available')@@ -1165,14 +1165,11 @@ describe('ComposerPanel document attachments (#678)', () => {expect(sendButton().disabled).toBe(false)})- it('warns when the bytes do not match the name or type', () => {- composerState.composerFileAttachments = [- readyFile({- id: 'file-5',- filename: 'report.txt',- classification: { ...readyClassification, class: 'pdf', mismatch: true },- }),- ]+ it('warns when the bytes do not match the name or type', async () => {+ const report = await readyFile('file-5', 'report.txt', pdfBytes, 'text/plain')+ // Precondition: the real read sees PDF bytes behind a text name.+ expect(report.status === 'ready' && report.classification.mismatch).toBe(true)+ composerState.composerFileAttachments = [report]render(<ComposerPanel inline />)expect(screen.getByRole('status').textContent).toBe(diff --git a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.tsindex 8f4f2bbd9..936c9fc35 100644--- a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts+++ b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts@@ -1,10 +1,6 @@import type { ReactNode, RefObject } from 'react'import type { ChatDeleteFence } from '../../../../src/types'-import type {- ComposerFileAttachment,- ComposerImageAttachment,- ComposerReferenceAttachment,-} from '../../uiTypes'+import type { ComposerImageAttachment, ComposerReferenceAttachment } from '../../uiTypes'export interface QueuedChatDelete {agentRef: string@@ -37,7 +33,6 @@ export interface AgentChatActionsContextValue {handleRemoveComposerImageAttachment: (attachmentId: string) => voidhandleAddComposerFiles: (files: File[], draft: string) => voidhandleRemoveComposerFileAttachment: (attachmentId: string) => void- handleRestoreComposerFiles: (files: ComposerFileAttachment[]) => voidhandleAddComposerReferenceAttachments: (attachments: ComposerReferenceAttachment[]) => voidhandleRemoveComposerReferenceAttachment: (attachmentId: string) => voidhandleSendAgentMessage: (text: string) => Promise<void>diff --git a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsxindex f786b01b2..e267b4756 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx@@ -7,10 +7,21 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { act, waitFor } from '@testing-library/react'import { createHash } from 'node:crypto'+import { loadHostModels, resetHostModelSelectionStore } from '@lib/hostModelSelectionStore'+import type { HostModelsResult } from '../../../../../src/types'import { renderController } from './__fixtures__/controllerHarness'import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'let clerum: MockClerum++const imageCatalog: HostModelsResult = {+ provider: 'zai',+ hostDefault: 'glm-5.3-flash',+ sessionModel: null,+ degraded: false,+ modelSelectionRevision: 0,+ models: [{ name: 'glm-5.3-flash', imageInput: { state: 'supported', reason: 'supported' } }],+}let uuidCounter = 0;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true@@ -32,6 +43,7 @@ beforeEach(() => {afterEach(() => {vi.restoreAllMocks()+ resetHostModelSelectionStore()uninstallMockClerum()})@@ -319,6 +331,51 @@ describe('sendAgentMessage — a Host without file attachments (#678 D13)', () =expect(rendered.result.current.failedAgentSend?.files.map(item => item.id)).toEqual([file.id])})+ it('titles a new chat from both the images and the documents of a send without text', async () => {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ response: 'done' })+ const modelTransport = {+ getHostModels: vi.fn(async () => imageCatalog),+ setHostModel: vi.fn(),+ }+ Object.assign(clerum.rpc, modelTransport)+ const rendered = renderController()+ await settleMount()+ // An image send needs a model with verified image input.+ await act(async () => {+ await loadHostModels(modelTransport, 'agent-x', null)+ })+ expect(rendered.result.current.activeChatId).toBeNull()+ act(() => {+ rendered.result.current.handleAddComposerImageAttachments([+ {+ id: 'image-1',+ name: 'shot.png',+ mimeType: 'image/png',+ dataBase64: 'YWJj',+ sizeBytes: 3,+ previewDataUrl: 'data:image/png;base64,YWJj',+ },+ ])+ })+ await addReadyFile(rendered)++ await act(async () => {+ await rendered.result.current.handleSendAgentMessage('')+ })++ // Witness: the send auto-created the chat that gets the title.+ const createdChatId = rendered.result.current.activeChatId+ expect(createdChatId).not.toBeNull()+ await waitFor(() =>+ expect(clerum.chat.rename).toHaveBeenCalledWith(+ 'agent-x',+ createdChatId,+ 'Images: shot.png; Files: notes.txt',+ 1+ )+ )+ })+it('does not read an empty ack (an unreadable Host answer) as a dropped file', async () => {const rendered = renderController()await settleMount()diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsxindex ffd907dae..bc6ce656b 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx@@ -100,7 +100,7 @@ describe('useComposerAttachments — documents (#678)', () => {expect(orders[0]).toBeLessThan(orders[1]!)})- it('drops a second copy of the same file instead of attaching it twice', async () => {+ it('drops a second copy of the same file and says it is already attached', async () => {const { result } = render()act(() => {@@ -113,6 +113,7 @@ describe('useComposerAttachments — documents (#678)', () => {// Liveness witness: the second copy was admitted (reading) before it was dropped.expect(statuses(result)).toEqual(['ready', 'reading'])await waitFor(() => expect(statuses(result)).toEqual(['ready']))+ expect(refusalTexts(result)).toEqual(['"same.txt" is already attached.'])})it('attaches a file whose name the OS reports decomposed under its NFC name', async () => {diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex 5bbc306d0..a29c2eb34 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -3025,15 +3025,23 @@ export function useAgentChatController({chatList.find(c => c.id === sendChatId) ??(autoCreatedMeta && autoCreatedMeta.id === sendChatId ? autoCreatedMeta : undefined)if (chat && chat.title === 'New Chat') {+ // Without text, the title names every kind of attachment the send+ // carried: images and documents together, else the context references.+ const attachmentTitleParts = [+ effectiveAttachments.length > 0+ ? `Images: ${effectiveAttachments.map(att => att.name).join(', ')}`+ : '',+ effectiveFiles.length > 0+ ? `Files: ${effectiveFiles.map(file => file.filename).join(', ')}`+ : '',+ ].filter(Boolean)const autoTitleSeed =trimmedContent ||- (effectiveAttachments.length > 0- ? `Images: ${effectiveAttachments.map(att => att.name).join(', ')}`- : effectiveFiles.length > 0- ? `Files: ${effectiveFiles.map(file => file.filename).join(', ')}`- : effectiveReferences.length > 0- ? `Context: ${effectiveReferences.map(ref => ref.label).join(', ')}`- : '')+ (attachmentTitleParts.length > 0+ ? attachmentTitleParts.join('; ')+ : effectiveReferences.length > 0+ ? `Context: ${effectiveReferences.map(ref => ref.label).join(', ')}`+ : '')const autoTitle = truncateTitle(autoTitleSeed)if (autoTitle) {// spec 15 §2.5/B19: the client-derived auto-title stays LOCAL only —@@ -3529,8 +3537,8 @@ export function useAgentChatController({const handleSendAgentMessage = useCallback(async (text: string) => {- // A document still being read, or one that failed, is not part of the- // message: sending now would silently leave it out.+ // A document still being read is not part of the message yet: sending+ // now would silently leave it out.if (composerFilesBlockSend) returnawait sendAgentMessage(text,diff --git a/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts b/desktop-app/ui/src/hooks/domain/useComposerAttachments.tsindex 5bdb491d0..7888ee03e 100644--- a/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts+++ b/desktop-app/ui/src/hooks/domain/useComposerAttachments.ts@@ -286,22 +286,28 @@ export function useComposerAttachments({setComposerFileRefusals(previous => [...previous, { id, text: result.error }])return}- commitComposerFiles(previous => {- if (- previous.some(- item =>- item.id !== id &&- item.status === 'ready' &&- item.filename === result.filename &&- item.digestHex === result.digestHex- )- ) {- return previous.filter(item => item.id !== id)- }- return previous.map(item =>+ // The same bytes under the same name are one document: the second copy+ // leaves no chip, and the user is told why it did not appear.+ const duplicate = composerFilesRef.current.some(+ item =>+ item.id !== id &&+ item.status === 'ready' &&+ item.filename === result.filename &&+ item.digestHex === result.digestHex+ )+ if (duplicate) {+ commitComposerFiles(previous => previous.filter(item => item.id !== id))+ setComposerFileRefusals(previous => [+ ...previous,+ { id, text: `"${result.filename}" is already attached.` },+ ])+ return+ }+ commitComposerFiles(previous =>+ previous.map(item =>item.id === id ? { ...result, addedOrder: item.addedOrder } : item)- })+ )})}setComposerFileRefusals(refusals)diff --git a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts b/desktop-app/ui/src/hooks/useAgentChatActionsValue.tsindex fc50e45ff..97de28c15 100644--- a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts+++ b/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts@@ -34,7 +34,6 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuconst handleRemoveComposerFileAttachment = useStableCallback(vm.handleRemoveComposerFileAttachment)- const handleRestoreComposerFiles = useStableCallback(vm.handleRestoreComposerFiles)const handleAddComposerReferenceAttachments = useStableCallback(vm.handleAddComposerReferenceAttachments)@@ -63,7 +62,6 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuhandleRemoveComposerImageAttachment,handleAddComposerFiles,handleRemoveComposerFileAttachment,- handleRestoreComposerFiles,handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment,handleSendAgentMessage,@@ -87,7 +85,6 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuhandleRemoveComposerImageAttachment,handleAddComposerFiles,handleRemoveComposerFileAttachment,- handleRestoreComposerFiles,handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment,handleSendAgentMessage,diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.tsindex 417a170b3..f84164de3 100644--- a/desktop-app/ui/src/hooks/useAppController.ts+++ b/desktop-app/ui/src/hooks/useAppController.ts@@ -1567,7 +1567,6 @@ export function useAppController() {handleRemoveComposerImageAttachment: chat.handleRemoveComposerImageAttachment,handleAddComposerFiles: chat.handleAddComposerFiles,handleRemoveComposerFileAttachment: chat.handleRemoveComposerFileAttachment,- handleRestoreComposerFiles: chat.handleRestoreComposerFiles,handleAddComposerReferenceAttachments: chat.handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment: chat.handleRemoveComposerReferenceAttachment,cancelTask: chat.cancelTask,diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex cd4df2eb5..59f0d8e17 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -14058,6 +14058,17 @@ pre {border-color: rgba(var(--accent-rgb), 0.34);}+.composer-reference-icon--uploaded-file {+ background: rgba(var(--info-rgb), 0.14);+ border-color: rgba(var(--info-rgb), 0.34);+}++.composer-reference-icon--uploaded-file svg {+ width: 13px;+ height: 13px;+ stroke-width: 1.8;+}+/* Support the JS attachment type and the CSS-friendly alias used by modal rows. */.composer-reference-icon--agent_file,.composer-reference-icon--agent-file {diff --git a/desktop-app/ui/src/uiTypes.ts b/desktop-app/ui/src/uiTypes.tsindex 9820aefa6..7193cc185 100644--- a/desktop-app/ui/src/uiTypes.ts+++ b/desktop-app/ui/src/uiTypes.ts@@ -281,7 +281,7 @@ type ComposerFileAttachmentBase = {*/export type ComposerFileAttachment = ComposerFileAttachmentBase &(- | { status: 'selected' | 'reading' }+ | { status: 'reading' }| {status: 'ready'classification: FileClassification