From fe0c45a30b2e8f5380600baa39e6d9cc9efb72ec Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 30 Sep 2026 04:53:18 +0000 Subject: [PATCH 01/37] fix(agent): one accepted file-type list for every composer upload path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The paperclip, a panel drop and a paste each decided for themselves what could be attached, and only two of them decided at all. - The paperclip ran no check. `accept` on a file input is a picker hint, and "All Files" defeats it, so .hdr, .exr, .wmv, .flv, .aac and .wma reached the composer through the wildcards the accept list used to carry (PM-1854). - Text and 3D could not be attached beyond .glb/.md/.txt, so .json, .csv, .yaml, .xml, .log and every other mesh format were refused (PM-1855). - A refused file did nothing: no message, no chip, no clue (PM-1856). The accept list now comes from the server contract. attachableFiles derives it from the generated AgentAttachmentPolicy enums, so it cannot drift from what the agent service enforces, and the validation moved into useAttachment.addFiles — the one function all three paths already call, which is what stops them disagreeing again. The accept attribute names extensions only, since the MIME wildcards are what widened the picker in the first place. A .json dropped ON THE PANEL now attaches to the chat. The canvas still opens one as a workflow through its own drop handler, which a panel drop never reaches. The chip also says what the agent can do with each file: it reads an image, measures a clip, and cannot open a mesh or a text file at all. That difference was invisible, so an attached .md looked exactly like an attached .png. PM-1854, PM-1855, PM-1856 --- .../tests/agent/agentAttachJsonFile.spec.ts | 103 +++++++---- packages/ingest-types/src/index.ts | 5 + packages/ingest-types/src/types.gen.ts | 127 +++++++++++++- packages/ingest-types/src/zod.gen.ts | 108 +++++++++++- src/locales/en/main.json | 4 + .../extensions/agent/AgentPanelRoot.test.ts | 34 ++-- .../extensions/agent/AgentPanelRoot.vue | 12 +- .../agent/Composer.pasteAttachment.test.ts | 19 ++- .../agent/composer/AttachmentChip.stories.ts | 15 ++ .../agent/composer/AttachmentChip.test.ts | 20 +++ .../agent/composer/AttachmentChip.vue | 23 +++ .../agent/composer/InlinePromptEditor.vue | 9 +- .../composables/agent/useAttachment.test.ts | 68 ++++++-- .../agent/composables/agent/useAttachment.ts | 13 +- .../agent/utils/attachableFiles.test.ts | 161 +++++++++++------- .../extensions/agent/utils/attachableFiles.ts | 117 ++++++++----- 16 files changed, 657 insertions(+), 181 deletions(-) diff --git a/browser_tests/tests/agent/agentAttachJsonFile.spec.ts b/browser_tests/tests/agent/agentAttachJsonFile.spec.ts index a9e5605627e..fd80c63aa20 100644 --- a/browser_tests/tests/agent/agentAttachJsonFile.spec.ts +++ b/browser_tests/tests/agent/agentAttachJsonFile.spec.ts @@ -9,50 +9,85 @@ import { agentTest as test } from '@e2e/tests/agent/agentPanelMocks' import { assetPath } from '@e2e/fixtures/utils/paths' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' +/** + * Only formats that already have a fixture in browser_tests/assets are covered + * here: .json, .glb and .obj on the accepted side and .exr on the rejected one. + * The rest of the agreed list (PM-1855) has no asset to drive a real upload + * with, and is pinned by the unit suite over attachableFiles instead. + */ +const ACCEPTED_FIXTURES = [ + { file: 'default.json', capability: 'reference' }, + { file: 'animated_triangle.glb', capability: 'reference' }, + { file: 'cube.obj', capability: 'reference' } +] as const + test.describe( - 'Agent panel .json attachment', + 'Agent panel attachment file types', { tag: ['@cloud', '@ui'] }, () => { test.beforeEach(async ({ comfyPage }) => { - const response: UploadImageResponse = { - name: 'default.json', - subfolder: '', - type: 'input' - } - await comfyPage.page.route('**/api/upload/image', (route) => - route.fulfill(jsonRoute(response)) - ) + await comfyPage.page.route('**/api/upload/image', (route) => { + const response: UploadImageResponse = { + name: 'uploaded', + subfolder: '', + type: 'input' + } + return route.fulfill(jsonRoute(response)) + }) await comfyPage.nodeOps.clearGraph() await expect.poll(() => comfyPage.nodeOps.getGraphNodesCount()).toBe(0) }) - test('advertises .json in the attach accept list and accepts a .json file through the file browser', async ({ + test('advertises extensions only, so the OS picker cannot offer a rejected type', async ({ agentPanel }) => { await agentPanel.open() - const { fileInput, composerAssetSection: assetSection } = agentPanel - // The OS picker filters on this attribute; a missing `.json`/ - // `application/json` entry is exactly what hid JSON files from it. - await expect(fileInput).toHaveAttribute('accept', AGENT_ATTACH_ACCEPT) + // image/*, video/* and audio/* wildcards are exactly what let .exr, .hdr, + // .wmv and .wma reach a paperclip that did no checking of its own. + await expect(agentPanel.fileInput).toHaveAttribute( + 'accept', + AGENT_ATTACH_ACCEPT + ) + expect(AGENT_ATTACH_ACCEPT).not.toContain('/*') + expect(AGENT_ATTACH_ACCEPT).toContain('.json') + }) - // Browse flow: picking a .json file through the input lands it in the - // composer instead of being silently ignored. This is the actual bug - // that was reported (the OS picker hid .json files) and the actual fix - // (AGENT_ATTACH_ACCEPT now lists .json/application/json). - await fileInput.setInputFiles(assetPath('default.json')) - await expect(assetSection).toContainText('default.json') - await expect( - assetSection.locator(`[aria-label="${enMessages.agent.uploading}"]`) - ).toHaveCount(0) + for (const { file } of ACCEPTED_FIXTURES) { + test(`attaches ${file} picked through the file browser`, async ({ + agentPanel + }) => { + await agentPanel.open() + const { fileInput, composerAssetSection: assetSection } = agentPanel - await assetSection - .getByRole('button', { name: enMessages.agent.remove, exact: true }) - .click() - await expect(assetSection).toHaveCount(0) + await fileInput.setInputFiles(assetPath(file)) + await expect(assetSection).toContainText(file) + await expect( + assetSection.locator(`[aria-label="${enMessages.agent.uploading}"]`) + ).toHaveCount(0) + }) + } + + test('refuses a rejected type picked through the file browser and says why', async ({ + agentPanel, + comfyPage + }) => { + await agentPanel.open() + + // "All Files" in the OS picker defeats the accept attribute, so the + // paperclip has to run the same check drag and paste do (PM-1854), and + // has to say something when it refuses (PM-1856). + await agentPanel.fileInput.setInputFiles( + assetPath('test_upload_image.exr') + ) + + await expect( + comfyPage.page.getByText('test_upload_image.exr', { exact: false }) + ).toBeVisible() + await expect(agentPanel.composerAssetSection).toHaveCount(0) }) - test('leaves a drag-and-dropped .json file unclaimed for the graph loader', async ({ + test('attaches a .json dropped on the panel instead of opening it as a workflow', async ({ agentPanel, comfyPage }) => { @@ -70,14 +105,10 @@ test.describe( } }) - await expect.poll(() => comfyPage.nodeOps.getGraphNodesCount()).toBe(7) - expect( - await comfyPage.nodeOps.getNodeRefsByType('KSampler') - ).toHaveLength(1) - expect( - await comfyPage.nodeOps.getNodeRefsByType('CLIPTextEncode') - ).toHaveLength(2) - await expect(assetSection).toHaveCount(0) + // Dropping onto the composer means "attach this to the chat" (PM-1855). + // The canvas still opens a workflow, through its own drop handler. + await expect(assetSection).toContainText('default.json') + expect(await comfyPage.nodeOps.getGraphNodesCount()).toBe(0) }) } ) diff --git a/packages/ingest-types/src/index.ts b/packages/ingest-types/src/index.ts index 0c7f39a9fc7..56361322265 100644 --- a/packages/ingest-types/src/index.ts +++ b/packages/ingest-types/src/index.ts @@ -20,6 +20,8 @@ export type { AgentAnswerAskResponse, AgentAnswerAskResponses, AgentAnswerRequest, + AgentAttachmentPolicy, + AgentAttachmentRejected, AgentCancelAccepted, AgentCancelMessageData, AgentCancelMessageError, @@ -82,6 +84,7 @@ export type { AgentPostMessageRequest, AgentPostMessageResponse, AgentPostMessageResponses, + AgentProbeableAttachmentExtension, AgentPublishSkillData, AgentPublishSkillError, AgentPublishSkillErrors, @@ -92,6 +95,7 @@ export type { AgentPutRunModeErrors, AgentPutRunModeResponse, AgentPutRunModeResponses, + AgentReferenceAttachmentExtension, AgentRunMode, AgentRunModePutRequest, AgentSkill, @@ -102,6 +106,7 @@ export type { AgentThreadListResponse, AgentThreadSummary, AgentTurnAccepted, + AgentViewableAttachmentExtension, Asset, AssetCreated, AssetCreatedWritable, diff --git a/packages/ingest-types/src/types.gen.ts b/packages/ingest-types/src/types.gen.ts index 3f953b7126c..7dc6b0a32d5 100644 --- a/packages/ingest-types/src/types.gen.ts +++ b/packages/ingest-types/src/types.gen.ts @@ -1204,7 +1204,7 @@ export type ResubscribeRequest = { } /** - * The newest open renewal invoice of the workspace's Stripe subscription (active, or canceled but not yet ended). Returned only to workspace owners on the stripe billing rail while billing_status is payment_failed, and not while a payment for it is processing. hosted_invoice_url is a bearer payment link. + * The newest open renewal invoice of the workspace's Stripe subscription (active, or canceled but not yet ended). Returned only to workspace owners on the stripe billing rail while billing_status is payment_failed or paused, and not while a payment for it is processing. hosted_invoice_url is a bearer payment link. */ export type RenewalInvoice = { /** @@ -4475,6 +4475,22 @@ export type AssetCreated = Asset & { created_new: boolean } +/** + * Attachment extensions whose content the model can see. Exactly the raster formats Go's + * image package decodes — view_asset always re-encodes to PNG or JPEG, so the provider's own + * four-type image allowlist is satisfied by construction rather than by matching this list. + * + */ +export type AgentViewableAttachmentExtension = + | '.png' + | '.jpg' + | '.jpeg' + | '.gif' + | '.webp' + | '.bmp' + | '.tif' + | '.tiff' + /** * Acknowledgement that a turn was accepted. The agent runs asynchronously; output streams over the WebSocket (agent_message_delta, agent_tool_call, draft_patch, agent_message_done). */ @@ -4641,12 +4657,75 @@ export type AgentRunMode = { mode: 'ask_approval' | 'auto' | 'auto_limited' } +/** + * Attachment extensions the agent can name and wire into a graph but cannot read. + * + * 3D covers every format Load3D opens EXCEPT .usdz, which the accepted list rejects. Text + * formats are accepted so a user can attach and keep them beside a workflow; the agent is told + * the kind and the id, and the composer must not imply the model has read them. + * + */ +export type AgentReferenceAttachmentExtension = + | '.glb' + | '.obj' + | '.fbx' + | '.gltf' + | '.stl' + | '.ply' + | '.spz' + | '.splat' + | '.ksplat' + | '.md' + | '.markdown' + | '.txt' + | '.json' + | '.csv' + | '.yaml' + | '.yml' + | '.xml' + | '.log' + | '.svg' + | '.avif' + +/** + * Attachment extensions the agent can only describe from metadata. Matches the containers + * ingest sorts into a load node's video/audio lists, so anything accepted here is also + * wirable into a graph. + * + */ +export type AgentProbeableAttachmentExtension = + | '.mp4' + | '.webm' + | '.mov' + | '.m4v' + | '.avi' + | '.mkv' + | '.mp3' + | '.wav' + | '.ogg' + | '.opus' + | '.flac' + | '.m4a' + /** * A user turn posted to the agent. */ export type AgentPostMessageRequest = { /** - * Optional input filenames the client already uploaded to the ComfyUI input namespace (via /api/upload/image, which returns the {name, subfolder, type} reference). Images, video and audio are all accepted. The agent wires them into the workflow by filename — it never receives file bytes here, and reads an attachment's contents through its own asset tools when a request depends on them. + * Optional input filenames the client already uploaded to the ComfyUI input namespace (via + * /api/upload/image, which returns the {name, subfolder, type} reference). The agent wires + * them into the workflow by filename — it never receives file bytes here, and reads an + * attachment's contents through its own asset tools when a request depends on them. + * + * Each entry's extension must appear in AgentAttachmentPolicy; a reference outside it is + * rejected with 422 (AgentAttachmentRejected). Which tier of that policy an extension lands + * in says what the agent can do with it, and the tiers differ sharply — a client that + * presents them as one flat list misleads the user. + * + * The constraint is expressed as three enums rather than on this array because the array + * carries FILENAMES, not content types: an extension is what both ends can actually agree + * on, and the upload route this list references stores no MIME type for what it accepts. + * */ attachments?: Array /** @@ -4797,6 +4876,46 @@ export type AgentCancelAccepted = { status: 'cancelling' } +/** + * 422 body when a posted attachment's extension is outside the accepted list. It carries the + * policy rather than only an error string so a client never has to hardcode the list to + * explain the refusal — the same reason the list is expressed as enums the frontend generates + * its types from. + * + */ +export type AgentAttachmentRejected = { + accepted: AgentAttachmentPolicy + error: string + /** + * The offending references, in the order they were posted. + */ + rejected: Array + type: 'ATTACHMENT_TYPE_NOT_ACCEPTED' +} + +/** + * Every extension the agent accepts as an attachment, grouped by what it can actually DO with + * one. The grouping is the point: the tiers differ sharply, and a client that renders them as + * one flat "supported files" list tells the user something false (PM-1855). + * + * - `view`: the model sees the content. view_asset decodes the still and re-encodes it as + * PNG/JPEG into the turn, so the model reasons about actual pixels. + * - `probe`: metadata only. probe_media reports duration, resolution, frame rate and codecs; + * nothing in the model's input can carry a clip, so the CONTENT stays unreadable. Seeing a + * video means cutting a frame out with process_media and viewing that. + * - `reference`: the agent knows the file exists, its kind and its id, and can wire it into a + * graph node by filename — but cannot read it at all. The cloud turn registers neither a + * shell nor a file-read tool, by design: it is a shared multi-tenant pod. + * + * The union of the three arrays is the accepted list. Anything absent is rejected. + * + */ +export type AgentAttachmentPolicy = { + probe: Array + reference: Array + view: Array +} + /** * The user's answer to a pending ask_user prompt. `selected` holds the chosen option ids; a permission gate answers with one id (e.g. the Approve/Deny option). `other_text` carries a free-text answer when the ask set allow_other. */ @@ -5869,6 +5988,10 @@ export type AgentPostMessageErrors = { * Forbidden (workflow or thread not owned by the caller). An ingest refusal, such as the web session's, is ErrorResponse; the agent service's is AgentError. */ 403: ErrorResponse | AgentError + /** + * One or more attachments name a file type the agent does not accept. The body names the offending references and carries the full accepted policy, so the client can explain the refusal without hardcoding the list. + */ + 422: AgentAttachmentRejected /** * Internal server error (ingest-raised failures use the standard ErrorResponse shape instead) */ diff --git a/packages/ingest-types/src/zod.gen.ts b/packages/ingest-types/src/zod.gen.ts index 8520f88cf3f..e44c49c8170 100644 --- a/packages/ingest-types/src/zod.gen.ts +++ b/packages/ingest-types/src/zod.gen.ts @@ -767,7 +767,7 @@ export const zResubscribeRequest = z.object({ }) /** - * The newest open renewal invoice of the workspace's Stripe subscription (active, or canceled but not yet ended). Returned only to workspace owners on the stripe billing rail while billing_status is payment_failed, and not while a payment for it is processing. hosted_invoice_url is a bearer payment link. + * The newest open renewal invoice of the workspace's Stripe subscription (active, or canceled but not yet ended). Returned only to workspace owners on the stripe billing rail while billing_status is payment_failed or paused, and not while a payment for it is processing. hosted_invoice_url is a bearer payment link. */ export const zRenewalInvoice = z.object({ amount_due: z.coerce @@ -2683,6 +2683,23 @@ export const zAssetCreated = zAsset.and( }) ) +/** + * Attachment extensions whose content the model can see. Exactly the raster formats Go's + * image package decodes — view_asset always re-encodes to PNG or JPEG, so the provider's own + * four-type image allowlist is satisfied by construction rather than by matching this list. + * + */ +export const zAgentViewableAttachmentExtension = z.enum([ + '.png', + '.jpg', + '.jpeg', + '.gif', + '.webp', + '.bmp', + '.tif', + '.tiff' +]) + /** * Acknowledgement that a turn was accepted. The agent runs asynchronously; output streams over the WebSocket (agent_message_delta, agent_tool_call, draft_patch, agent_message_done). */ @@ -2777,6 +2794,58 @@ export const zAgentRunMode = z.object({ mode: z.enum(['ask_approval', 'auto', 'auto_limited']) }) +/** + * Attachment extensions the agent can name and wire into a graph but cannot read. + * + * 3D covers every format Load3D opens EXCEPT .usdz, which the accepted list rejects. Text + * formats are accepted so a user can attach and keep them beside a workflow; the agent is told + * the kind and the id, and the composer must not imply the model has read them. + * + */ +export const zAgentReferenceAttachmentExtension = z.enum([ + '.glb', + '.obj', + '.fbx', + '.gltf', + '.stl', + '.ply', + '.spz', + '.splat', + '.ksplat', + '.md', + '.markdown', + '.txt', + '.json', + '.csv', + '.yaml', + '.yml', + '.xml', + '.log', + '.svg', + '.avif' +]) + +/** + * Attachment extensions the agent can only describe from metadata. Matches the containers + * ingest sorts into a load node's video/audio lists, so anything accepted here is also + * wirable into a graph. + * + */ +export const zAgentProbeableAttachmentExtension = z.enum([ + '.mp4', + '.webm', + '.mov', + '.m4v', + '.avi', + '.mkv', + '.mp3', + '.wav', + '.ogg', + '.opus', + '.flac', + '.m4a' +]) + /** * A user turn posted to the agent. */ @@ -2862,6 +2931,43 @@ export const zAgentCancelAccepted = z.object({ status: z.enum(['cancelling']) }) +/** + * Every extension the agent accepts as an attachment, grouped by what it can actually DO with + * one. The grouping is the point: the tiers differ sharply, and a client that renders them as + * one flat "supported files" list tells the user something false (PM-1855). + * + * - `view`: the model sees the content. view_asset decodes the still and re-encodes it as + * PNG/JPEG into the turn, so the model reasons about actual pixels. + * - `probe`: metadata only. probe_media reports duration, resolution, frame rate and codecs; + * nothing in the model's input can carry a clip, so the CONTENT stays unreadable. Seeing a + * video means cutting a frame out with process_media and viewing that. + * - `reference`: the agent knows the file exists, its kind and its id, and can wire it into a + * graph node by filename — but cannot read it at all. The cloud turn registers neither a + * shell nor a file-read tool, by design: it is a shared multi-tenant pod. + * + * The union of the three arrays is the accepted list. Anything absent is rejected. + * + */ +export const zAgentAttachmentPolicy = z.object({ + probe: z.array(zAgentProbeableAttachmentExtension), + reference: z.array(zAgentReferenceAttachmentExtension), + view: z.array(zAgentViewableAttachmentExtension) +}) + +/** + * 422 body when a posted attachment's extension is outside the accepted list. It carries the + * policy rather than only an error string so a client never has to hardcode the list to + * explain the refusal — the same reason the list is expressed as enums the frontend generates + * its types from. + * + */ +export const zAgentAttachmentRejected = z.object({ + accepted: zAgentAttachmentPolicy, + error: z.string(), + rejected: z.array(z.string()), + type: z.enum(['ATTACHMENT_TYPE_NOT_ACCEPTED']) +}) + /** * The user's answer to a pending ask_user prompt. `selected` holds the chosen option ids; a permission gate answers with one id (e.g. the Approve/Deny option). `other_text` carries a free-text answer when the ask set allow_other. */ diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 646bd6dc5b1..263a58d3fa3 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -5331,7 +5331,11 @@ }, "addFromAssets": "Drag in asset from asset panel", "assetNotAttachable": "Images, video, audio, 3D models, and text files can be attached", + "attachmentCapabilityProbe": "The agent can read this file's format and length, but not what it contains", + "attachmentCapabilityReference": "The agent can use this file in the graph, but can't read what it contains", + "attachmentCapabilityView": "The agent can see this image", "attachmentTooLarge": "{name} is larger than {limit}", + "attachmentTypeNotAccepted": "{name} is not a file type the agent accepts", "attachmentUploadFailed": "{name} could not be uploaded", "mention": "Mention a node", "changeWorkflowForChat": "Change the workflow that the agent can edit", diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index cfe86875e21..d27538c7604 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -3146,9 +3146,11 @@ describe('AgentPanelRoot attach flow', () => { } }) - it('attaches dropped assets and leaves other files to the graph loader', async () => { - // The graph loader only opens a dropped workflow while the drop is - // unclaimed, so the panel must not claim files it cannot attach. + it('attaches a dropped workflow json to the chat instead of the graph loader', async () => { + // Dropping ONTO THE COMPOSER means "attach this", so the panel claims a + // .json rather than leaving it for the loader (PM-1855). The canvas keeps + // the open-as-workflow behaviour through its own handler, which a drop on + // this target never reaches. stubUploadFetch() renderWithSelectedTarget() await nextTick() @@ -3157,29 +3159,24 @@ describe('AgentPanelRoot attach flow', () => { const workflow = new File(['{}'], 'flow.json', { type: 'application/json' }) - expect(dispatchDrag(target, 'drop', { files: [workflow] })).toBe(false) - expect(screen.queryByText('flow.json')).not.toBeInTheDocument() - - const asset = new File(['x'], 'cat.png', { type: 'image/png' }) - expect(dispatchDrag(target, 'drop', { files: [asset] })).toBe(true) + expect(dispatchDrag(target, 'drop', { files: [workflow] })).toBe(true) expect( within(await screen.findByTestId('composer-asset-section')).getByText( - 'cat.png' + 'flow.json' ) ).toBeInTheDocument() }) - it('attaches only the assets out of a mixed drop', async () => { + it('attaches the accepted files out of a mixed drop and reports the rest', async () => { const uploaded = stubUploadFetch() renderWithSelectedTarget() await nextTick() - // The non-attachable file comes first: addFiles uploads sequentially, so a - // regression that forwards the whole drop would upload flow.json before - // cat.png and the settled assertion below could never latch a lucky - // intermediate state. + // The rejected file comes first so a regression that forwards the whole + // drop would upload doc.pdf before cat.png, rather than the assertion + // latching a lucky intermediate state. const files = [ - new File(['{}'], 'flow.json', { type: 'application/json' }), + new File(['x'], 'doc.pdf', { type: 'application/pdf' }), new File(['x'], 'cat.png', { type: 'image/png' }) ] dispatchDrag(screen.getByRole('textbox'), 'drop', { files }) @@ -3190,6 +3187,13 @@ describe('AgentPanelRoot attach flow', () => { ) ).toBeInTheDocument() await vi.waitFor(() => expect(uploaded).toEqual(['cat.png'])) + expect(screen.queryByText('doc.pdf')).not.toBeInTheDocument() + // PM-1856: the refusal is surfaced, not swallowed. + expect( + useToastStore().messagesToAdd.some(({ detail }) => + String(detail).includes('doc.pdf') + ) + ).toBe(true) }) // Falsifiers for the committed-drop gates: an implementation that emits diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index a409a52db92..78f133d509c 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1682,11 +1682,13 @@ async function onPanelDrop(event: DragEvent): Promise { }) return } - // Anything the composer cannot attach still belongs to the graph loader, which - // only runs while the drop is unclaimed, so claim the attachable files alone. - const files = Array.from(event.dataTransfer?.files ?? []).filter( - isAgentAttachable - ) + // A drop ON THE PANEL is claimed whole, including a .json the graph loader + // would otherwise open as a workflow: dropping onto the composer says "attach + // this to the chat", and the canvas keeps the workflow behaviour because it + // has its own handler (useCanvasDrop) this never reaches (PM-1855). Claiming + // everything is also what lets an unsupported file be REPORTED instead of + // silently falling through to a loader that ignores it (PM-1856). + const files = Array.from(event.dataTransfer?.files ?? []) if (files.length === 0) return event.preventDefault() if (await attachment.addFiles(files)) diff --git a/src/workbench/extensions/agent/components/agent/Composer.pasteAttachment.test.ts b/src/workbench/extensions/agent/components/agent/Composer.pasteAttachment.test.ts index c20b1c53de7..e28002ab900 100644 --- a/src/workbench/extensions/agent/components/agent/Composer.pasteAttachment.test.ts +++ b/src/workbench/extensions/agent/components/agent/Composer.pasteAttachment.test.ts @@ -33,7 +33,10 @@ describe('pasting files into the composer', () => { expect(view.emitted().attachFiles).toEqual([[[screenshot]]]) }) - it('attaches every attachable file in one paste', async () => { + it('forwards every pasted file, leaving the accept decision to the composer', async () => { + // The editor deliberately does not filter: the composer's addFiles is the + // single gate, and it is what reports a type it will not take. Filtering + // here made a rejected paste look like pasting nothing (PM-1856). const user = userEvent.setup() const view = mount() @@ -47,7 +50,11 @@ describe('pasting files into the composer', () => { ) const [[attached]] = view.emitted<[File[]]>().attachFiles - expect(attached.map((file) => file.name)).toEqual(['first.png', 'notes.md']) + expect(attached.map((file) => file.name)).toEqual([ + 'first.png', + 'notes.md', + 'archive.zip' + ]) }) it('attaches the file and still pastes the text a mixed clipboard carries', async () => { @@ -94,7 +101,9 @@ describe('pasting files into the composer', () => { clipboardOf(new File(['x'], 'archive.zip', { type: 'application/zip' })) ) - expect(view.emitted().attachFiles).toBeUndefined() + // Forwarded so the composer can refuse it out loud; the draft the paste + // would have replaced is still untouched. + expect(view.emitted().attachFiles).toHaveLength(1) expect(editor).toHaveTextContent('keep me') }) @@ -113,7 +122,7 @@ describe('pasting files into the composer', () => { } ) - it('leaves the paste to the editor when no clipboard file is attachable', async () => { + it('still pastes the text a mixed clipboard carries when its file is unattachable', async () => { const user = userEvent.setup() const view = mount() const clipboard = clipboardOf( @@ -124,7 +133,7 @@ describe('pasting files into the composer', () => { await user.click(screen.getByRole('textbox')) await user.paste(clipboard) - expect(view.emitted().attachFiles).toBeUndefined() + expect(view.emitted().attachFiles).toHaveLength(1) expect(screen.getByRole('textbox')).toHaveTextContent('fallback text') }) }) diff --git a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.stories.ts b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.stories.ts index a34f91195cf..c983be4ebf3 100644 --- a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.stories.ts +++ b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.stories.ts @@ -43,3 +43,18 @@ export const Uploading: Story = { uploading: true } } + +/** + * One chip per capability tier. Hovering each shows what the agent can actually + * do with it: read the image, measure the clip, or only wire the mesh and the + * notes into a graph. The same text is exposed as aria-description. + */ +export const CapabilityTiers: Story = { + render: () => ({ + components: { AttachmentChip }, + setup: () => ({ + names: ['photo.png', 'clip.mp4', 'mesh.glb', 'notes.md'] + }), + template: `` + }) +} diff --git a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts index 6180dc23192..f70dfc31dfc 100644 --- a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts +++ b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.test.ts @@ -59,4 +59,24 @@ describe('AttachmentChip', () => { ).toBeInTheDocument() expect(screen.queryByRole('img')).not.toBeInTheDocument() }) + + // What the agent can do with a file is otherwise invisible: an image it reads, + // a clip it only measures, and a mesh or a text file it cannot open at all. + // Without this the chips look identical and the user assumes it was read. + describe('capability affordance', () => { + it.for([ + ['cat.png', 'can see this image'], + ['clip.mp4', 'format and length, but not what it contains'], + ['mesh.glb', "use this file in the graph, but can't read"], + ['notes.md', "use this file in the graph, but can't read"] + ])('tells the user what the agent can do with %s', ([name, phrase]) => { + renderChip({ name }) + const chip = screen.getByTestId('agent-attachment-chip') + expect(chip).toHaveAttribute('title', expect.stringContaining(phrase)) + expect(chip).toHaveAttribute( + 'aria-description', + expect.stringContaining(phrase) + ) + }) + }) }) diff --git a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.vue b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.vue index 08a88c5469f..217954093ae 100644 --- a/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.vue +++ b/src/workbench/extensions/agent/components/agent/composer/AttachmentChip.vue @@ -1,10 +1,12 @@