Skip to content

The agent that grows with you

fix(webapp): name the file when a drop into a message being edited cannot be staged

unsupportedpastels988cc79005d6
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
index 0404c80ccf5..7a4c9d3fff5 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
@@ -51,6 +51,7 @@ import { detectTrigger, openDirectiveScope, textBeforeCaret, type TriggerState }
import { ComposerTriggerPopover } from '@/app/chat/composer/trigger-popover'
import { isRedoShortcut, isUndoShortcut } from '@/app/chat/composer/undo-history'
import { chipTypedUrlOnSpace, linkifyUrls } from '@/app/chat/composer/url-refs'
+import { type DropFailure, dropWarning } from '@/app/chat/hooks/drop-warning'
import {
extractDroppedFiles,
HERMES_PATHS_MIME,
@@ -78,7 +79,7 @@ import { Loader2Icon } from '@/lib/icons'
import { isMacPlatform } from '@/lib/platform'
import { cn } from '@/lib/utils'
import type { ComposerAttachment } from '@/store/composer'
-import { notifyError } from '@/store/notifications'
+import { notify, notifyError, readableError } from '@/store/notifications'
import { $terminalBackend } from '@/store/session'
import { ambientRequestFor } from '@/store/session-gone-latch'
import { isSessionRemote, requestForOwnedSession } from '@/store/session-states'
@@ -474,16 +475,30 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
requestForOwnedSession<T>(sessionId, ambient, method, params)
const refs: InlineRefInput[] = []
+ // The staging reason leaves out the name (the main composer's drop warning adds it): name
+ // each rejected file here too, in the same bounded warning, so several aren't told apart.
+ const failures: DropFailure[] = []
for (const candidate of osDrops) {
+ let path: string
+
try {
// A rejected stage carries the server's or a proxy's reason (an nginx 413).
- const path = await stageDroppedFilePath(candidate)
+ path = await stageDroppedFilePath(candidate)
+ } catch (err) {
+ const name = candidate.file?.name || candidate.path || 'file'
+ const reason = readableError(err, '').message
- if (!path) {
- continue
- }
+ failures.push(reason ? { name, reason } : { name })
+
+ continue
+ }
+ if (!path) {
+ continue
+ }
+
+ try {
const kind: ComposerAttachment['kind'] =
candidate.file?.type.startsWith('image/') || isImagePath(candidate.file?.name || path) ? 'image' : 'file'
@@ -502,9 +517,13 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
}
}
+ if (failures.length) {
+ notify({ kind: 'error', title: t.desktop.dropFiles, ...dropWarning(failures, t.desktop.dropFilesMore) })
+ }
+
return refs
},
- [cwd, gateway, sessionId, t.desktop.dropFiles]
+ [cwd, gateway, sessionId, t.desktop.dropFiles, t.desktop.dropFilesMore]
)
const resetDragState = useCallback(() => {
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-message-edit-drop-staging.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-message-edit-drop-staging.test.tsx
index 1281ced3207..3f3578c1266 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-message-edit-drop-staging.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-message-edit-drop-staging.test.tsx
@@ -50,16 +50,23 @@ function Harness({ gateway }: { gateway: HermesGateway }) {
)
}
-// A browser drop: a File with no native path (the Webapp shell has no getPathForFile).
-function fileDrop(file: File) {
+// A browser drop: Files with no native path (the Webapp shell has no getPathForFile).
+function fileDrop(...files: File[]) {
return {
- files: { item: (index: number) => (index === 0 ? file : null), length: 1 },
+ files: { item: (index: number) => files[index] ?? null, length: files.length },
getData: () => '',
- items: [{ getAsFile: () => file, kind: 'file', webkitGetAsEntry: () => null }],
+ items: files.map(file => ({ getAsFile: () => file, kind: 'file', webkitGetAsEntry: () => null })),
types: ['Files']
}
}
+async function openEditor(gateway: HermesGateway) {
+ render(<Harness gateway={gateway} />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+
+ return screen.findByRole('textbox', { name: 'Edit message' })
+}
+
describe('edit composer drop staging failures', () => {
it('reports why a dropped file could not be staged', async () => {
const stageFileForAttach = vi.fn(async () => {
@@ -68,10 +75,7 @@ describe('edit composer drop staging failures', () => {
Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { stageFileForAttach } })
const request = vi.fn(async () => ({}))
- render(<Harness gateway={{ request } as unknown as HermesGateway} />)
-
- fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
- const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ const editor = await openEditor({ request } as unknown as HermesGateway)
await act(async () => {
fireEvent.drop(editor, { dataTransfer: fileDrop(new File(['payload'], 'notes.txt', { type: 'text/plain' })) })
@@ -79,8 +83,54 @@ describe('edit composer drop staging failures', () => {
await waitFor(() => expect(stageFileForAttach).toHaveBeenCalledOnce())
await waitFor(() =>
- expect($notifications.get()).toEqual([expect.objectContaining({ kind: 'error', message: UPLOAD_413 })])
+ expect($notifications.get()).toEqual([
+ expect.objectContaining({ kind: 'error', message: `Could not attach notes.txt: ${UPLOAD_413}` })
+ ])
)
expect(request).not.toHaveBeenCalledWith('file.attach', expect.anything())
})
+
+ // The oversize reason leaves out the name, so the edit composer must add it, or several
+ // oversized files in one drop give the same error. A long name is shortened; the limit stays.
+ it('names each oversized file of a mixed drop, bounded, and keeps the limit', async () => {
+ const limit = 'The file is larger than 16 MiB, the largest file the browser can attach.'
+ const longName = `${'a'.repeat(150)}.zip`
+
+ const stageFileForAttach = vi.fn(async (file: File) => {
+ if (file.name === 'notes.txt') {
+ return '/srv/uploads/web-notes.txt'
+ }
+
+ throw new Error(limit)
+ })
+
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { stageFileForAttach } })
+ const editor = await openEditor({ request: vi.fn(async () => ({})) } as unknown as HermesGateway)
+
+ await act(async () => {
+ fireEvent.drop(editor, {
+ dataTransfer: fileDrop(
+ new File(['payload'], 'notes.txt', { type: 'text/plain' }),
+ new File(['x'], longName, { type: 'application/zip' }),
+ new File(['x'], 'big.zip', { type: 'application/zip' })
+ )
+ })
+ })
+
+ await waitFor(() => expect(stageFileForAttach).toHaveBeenCalledTimes(3))
+
+ const warning = await waitFor(() => {
+ const found = $notifications.get().find(notice => notice.message.includes('big.zip'))
+ expect(found).toBeDefined()
+
+ return found!
+ })
+
+ expect(warning.kind).toBe('error')
+ expect(warning.message).toContain(`Could not attach ${'a'.repeat(24)}…${'a'.repeat(19)}.zip: ${limit}`)
+ expect(warning.message).toContain(`Could not attach big.zip: ${limit}`)
+ expect(warning.message).not.toContain(longName)
+ expect(warning.message).not.toContain('notes.txt')
+ expect(warning.detail).toContain(`Could not attach ${longName}: ${limit}`)
+ })
})