From 391d8388d8ad653ab32af54dac8443a337617b67 Mon Sep 17 00:00:00 2001 From: ryan-di Date: Thu, 15 Oct 2026 11:29:55 +0800 Subject: [PATCH] fix(agent): judge dragged asset cards by their stored file name On cloud an asset card's attachment ref is its content hash, which has no extension, so the agent panel fell back to the card's display label. A PNG labelled "Flux.dev", "render.v2" or "Upscale 1.5x" became an invalid file and blocked Send, while a stored .usdz behind an extensionless label was attached and sent. The drag payload already carries the stored file name. The panel now judges a card by its ref, then by its stored file name, and uses the label only when the payload has no stored name. A card that has to be downloaded first is named after its stored file name, so the uploaded file is judged by the same name. The canvas drop path is unchanged. --- src/utils/__tests__/eventUtils.test.ts | 2 + src/utils/eventUtils.ts | 5 +- .../extensions/agent/AgentPanelRoot.test.ts | 72 +++++++++++++++++++ .../extensions/agent/AgentPanelRoot.vue | 4 +- 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/eventUtils.test.ts b/src/utils/__tests__/eventUtils.test.ts index fd8725a2667..677b2fba600 100644 --- a/src/utils/__tests__/eventUtils.test.ts +++ b/src/utils/__tests__/eventUtils.test.ts @@ -214,6 +214,7 @@ describe('eventUtils', () => { expect(getDroppedAsset(dataTransfer)).toEqual({ name: 'My asset', + filename: 'asset.png', uri: 'http://localhost/api/view?x=1', ref: 'stored-asset.png', kind: 'image', @@ -234,6 +235,7 @@ describe('eventUtils', () => { expect(getDroppedAsset(dataTransfer)).toEqual({ name: 'asset.mp4', + filename: 'asset.mp4', uri: undefined, ref: 'stored-asset.mp4', kind: 'video', diff --git a/src/utils/eventUtils.ts b/src/utils/eventUtils.ts index c1b9a287924..4447b270830 100644 --- a/src/utils/eventUtils.ts +++ b/src/utils/eventUtils.ts @@ -4,6 +4,7 @@ import { isHdrImageFilename } from '@/utils/hdrFormatUtil' export interface DroppedAsset { name: string + filename?: string uri?: string ref?: string kind?: MediaKind @@ -26,6 +27,7 @@ export function getDroppedAsset( return uri || ref ? { name: name ?? ref ?? uri!, + filename: asset?.filename, uri, ref, kind: asset?.media_kind, @@ -45,13 +47,14 @@ function decodedBasename(pathname: string): string { } function sourceFileName( - { name, ref }: DroppedAsset, + { name, filename, ref }: DroppedAsset, uri: string, responseUrl: string ): string { const resolvedUrl = new URL(responseUrl || uri, 'http://localhost') const named = [ resolvedUrl.searchParams.get('filename'), + filename, ref, decodedBasename(resolvedUrl.pathname), name diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 4a817177bb7..959ce788964 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -4312,6 +4312,78 @@ describe('AgentPanelRoot attach flow', () => { expect(useToast().toasts).toEqual([]) }) + it.for(['Flux.dev', 'render.v2', 'Upscale 1.5x'])( + 'attaches a hashed image card labelled %s by its stored file name', + async (label) => { + const uploaded = stubUploadFetch() + renderWithSelectedTarget() + await nextTick() + const data = assetPanelDrag(label, { + name: 'abcdef0123456789.png', + hash: 'blake3:abcdef0123456789' + }) + + dispatchDrag(screen.getByRole('textbox'), 'drop', data) + + await screen.findByRole('group', { name: label }) + expect(useAgentComposerStore().attachments).toEqual([ + expect.objectContaining({ + name: label, + ref: 'blake3:abcdef0123456789' + }) + ]) + expect(screen.queryByRole('status')).not.toBeInTheDocument() + await userEvent.type(screen.getByRole('textbox'), 'Describe this') + expect(screen.getByRole('button', { name: 'Send' })).not.toHaveAttribute( + 'aria-disabled' + ) + expect(uploaded).toEqual([]) + } + ) + + it('refuses a hashed card whose stored file is a refused type behind an extensionless label', async () => { + const uploaded = stubUploadFetch() + renderWithSelectedTarget() + await nextTick() + const data = assetPanelDrag('My scene', { + name: 'abcdef0123456789.usdz', + hash: 'blake3:abcdef0123456789' + }) + + dispatchDrag(screen.getByRole('textbox'), 'drop', data) + + expect( + await screen.findByRole('status', { + name: unsupportedTypeMessage('My scene') + }) + ).toBeVisible() + expect(useAgentComposerStore().attachments).toEqual([ + expect.objectContaining({ + name: 'My scene', + ref: '', + validationError: 'unsupported-type' + }) + ]) + expect(fetchRequests(data.getData('text/uri-list'))).toEqual([]) + expect(uploaded).toEqual([]) + }) + + it('uploads a hashed card it has to fetch under its stored file name', async () => { + const uploaded = stubUploadFetch() + renderWithSelectedTarget() + await nextTick() + const data = assetPanelDrag('Holiday.v2', { + name: 'abcdef0123456789.heic', + hash: 'blake3:abcdef0123456789' + }) + + dispatchDrag(screen.getByRole('textbox'), 'drop', data) + + await vi.waitFor(() => expect(uploaded).toEqual(['abcdef0123456789.heic'])) + expect(fetchRequests(data.getData('text/uri-list'))).toHaveLength(1) + expect(screen.queryByRole('status')).not.toBeInTheDocument() + }) + it('attaches a dropped workflow json to the chat instead of the graph loader', async () => { stubUploadFetch() renderWithSelectedTarget() diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index ed387952f1b..5a2218d8162 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1843,7 +1843,9 @@ function warnAttachment(message: string): void { function droppedAssetVerdict(asset: DroppedAsset): AgentAttachVerdict { const fromRef = asset.ref ? agentAttachRefVerdict(asset.ref) : 'unknown' - return fromRef === 'unknown' ? agentAttachVerdict(asset.name) : fromRef + return fromRef === 'unknown' + ? agentAttachVerdict(asset.filename ?? asset.name) + : fromRef } function stageAcceptedAssetCard(