Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): read a drop's files from dataTransfer.items when files is empty

Shanu5253d9390033
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
index 82362eda9a..34613ab8c2 100644
--- a/app/src/components/assistant-ui/thread.tsx
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -209,6 +209,25 @@ const lexicalDrivesTheStore = (): boolean =>
// Counts only — never a filename, a MIME type or clipboard content.
const debug = debugFactory('openhuman:assistant-composer');
+/**
+ * The files a drop is actually carrying.
+ *
+ * `dataTransfer.files` is the obvious source and is empty more often than it
+ * looks: several macOS drag sources — the floating screenshot thumbnail among
+ * them — hand the webview promise-backed items instead, leaving `files` at
+ * length 0 while `items` holds the same content. Reading `files` alone made
+ * those drops do nothing at all, with no error, because there was nothing to
+ * reject.
+ */
+function filesFromDrop(dataTransfer: DataTransfer | null): File[] {
+ const direct = Array.from(dataTransfer?.files ?? []);
+ if (direct.length > 0) return direct;
+ return Array.from(dataTransfer?.items ?? [])
+ .filter(item => item.kind === 'file')
+ .map(item => item.getAsFile())
+ .filter((file): file is File => file !== null);
+}
+
const EMPTY_COMPONENTS: ThreadComponents = {};
const ThreadComponentsContext = createContext<ThreadComponents>(EMPTY_COMPONENTS);
@@ -531,9 +550,9 @@ const Composer: FC<{
debug('[assistant-composer] drop: refused, ingest not accepting');
return;
}
- const files = event.dataTransfer?.files;
- if (!files || files.length === 0) {
- debug('[assistant-composer] drop: file drag carried no files');
+ const files = filesFromDrop(event.dataTransfer);
+ if (files.length === 0) {
+ debug('[assistant-composer] drop: file drag carried no readable files');
return;
}
debug('[assistant-composer] drop: ingesting %d file(s)', files.length);
diff --git a/app/src/pages/__tests__/Conversations.attachments.test.tsx b/app/src/pages/__tests__/Conversations.attachments.test.tsx
index 69494d0601..f3cbc374ce 100644
--- a/app/src/pages/__tests__/Conversations.attachments.test.tsx
+++ b/app/src/pages/__tests__/Conversations.attachments.test.tsx
@@ -398,6 +398,30 @@ describe('Conversations — attachment feature', () => {
});
});
+ // Several macOS drag sources — the floating screenshot thumbnail among them —
+ // leave `dataTransfer.files` empty and carry the payload on `items` instead.
+ // Reading `files` alone made those drops do nothing, silently.
+ it('attaches a dropped file carried only on dataTransfer.items', async () => {
+ await renderWithSelectedThread();
+
+ const shell = document.querySelector('[data-slot="aui_composer-shell"]') as HTMLElement;
+ const file = makeFile('from-items.png', 'image/png', 512);
+
+ await act(async () => {
+ fireEvent.drop(shell, {
+ dataTransfer: {
+ files: [],
+ types: ['Files'],
+ items: [{ kind: 'file', type: 'image/png', getAsFile: () => file }],
+ },
+ });
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText('from-items.png')).toBeInTheDocument();
+ });
+ });
+
it('marks the composer while files are dragged over it, and clears on leave', async () => {
await renderWithSelectedThread();
@@ -463,16 +487,21 @@ describe('Conversations — attachment feature', () => {
});
});
- // Count only once both ingests have settled. Asserting earlier measures how
- // far the reads happen to have got, not the budget: mid-flight this reads 2
- // whether or not the queue is serialised.
+ // Two-stage on purpose, and neither stage is redundant.
+ //
+ // Waiting for the cap catches the opposite failure — a queued run starved of
+ // its slot would stall below four and time out here. But `waitFor` alone
+ // cannot pin the count: unserialised, the total climbs 0 -> 6 and passes
+ // *through* four, so a bare `toHaveLength(4)` latches the transient and
+ // passes against the very bug this guards. The settle window after it is
+ // what lets the fifth and sixth land, so the final count is the real one.
+ await waitFor(() => {
+ expect(screen.queryAllByText(/^ovl-/).length).toBeGreaterThanOrEqual(ATTACHMENT_MAX_IMAGES);
+ });
await act(async () => {
- await new Promise(resolve => setTimeout(resolve, 400));
+ await new Promise(resolve => setTimeout(resolve, 300));
});
-
- // Unserialised, both runs seed from the same empty snapshot and admit three
- // each — six against a cap of four.
- expect(screen.queryAllByText(/^ovl-/).length).toBeLessThanOrEqual(ATTACHMENT_MAX_IMAGES);
+ expect(screen.queryAllByText(/^ovl-/)).toHaveLength(ATTACHMENT_MAX_IMAGES);
});
it('shows too-many error when selecting more than 4 images', async () => {