Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

refactor(agentic): one drop-and-paste pipeline for every prompt surface

rubenluetke10-beep8cf6c43c0ae4
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
index d0931ae4a7..149ac284c8 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx
@@ -17,11 +17,9 @@ import {
Brain,
Check,
ChevronUp,
- FileText,
Files,
FolderGit2,
GripVertical,
- Image as ImageIcon,
ListChecks,
Loader2,
Minus,
@@ -73,23 +71,17 @@ import { ContinueInterrupted } from "./ContinueInterrupted";
import { PaneNotifications } from "./PaneNotifications";
import { isVoiceActive } from "./useVoiceCall";
import { PromptEditor } from "./PromptEditor";
+// One strip of chips, one drop handler and one paste handler for every
+// surface that writes to an agent (see ./PromptAttachments).
+import { AttachmentStrip, usePromptAttachments } from "./PromptAttachments";
import { WorkspaceSettings } from "./WorkspaceSettings";
import { WorkspaceExplorer } from "./WorkspaceExplorer";
import { WorkspaceFileViewer } from "./WorkspaceFileViewer";
-import { usePaneFileDrag } from "./paneFileDrag";
import { sameRows } from "./paneRows";
import type { WorkspaceView } from "./workspaceView";
-import {
- extractPaneDrop,
- extractPasteFiles,
- isEmptyPayload,
- nameClipboardFile,
- type PaneDropPayload,
-} from "./paneDrop";
import { usePaneArrange, type DropZone } from "./paneArrange";
import {
addTerminal,
- attachToTerminal,
closeTerminal,
closeTerminals,
moveTerminal,
@@ -103,7 +95,6 @@ import {
syncAgenticIdeSurface,
setTerminalRecap,
promptTerminal,
- type DropAttachment,
type IdeAccountState,
type IdeState,
type PaneNotification,
@@ -1954,54 +1945,23 @@ export function AgenticGrid({
* is still saved and still referenced; the description is the floor under it,
* not a replacement for it.
*/
- const [attachments, setAttachments] = useState<DropAttachment[]>([]);
- const [analyzing, setAnalyzing] = useState(0);
-
- const attach = useCallback(
- async (payload: PaneDropPayload) => {
- if (isEmptyPayload(payload)) return;
- if (!target) {
- pushToast("warning", "Pick a terminal first — a dropped file belongs to one.");
- return;
- }
- setAnalyzing((n) => n + 1);
- try {
- const result = await attachToTerminal(target, {
- ...payload,
- analyze: true,
- // Held, not typed: the user is still writing the sentence that says
- // what to do with it, and it goes in with that sentence.
- deliver: false,
- });
- const found = result.analysis ?? [];
- if (found.length === 0) {
- pushToast("warning", "That drop carried nothing this prompt could use.");
- return;
- }
- setAttachments((prev) => [...prev, ...found]);
- } catch (e) {
- pushToast("error", (e as Error).message);
- } finally {
- setAnalyzing((n) => Math.max(0, n - 1));
- }
- },
- [target],
- );
-
- const { dragging, handlers: dragHandlers } = usePaneFileDrag(
+ const {
+ attachments,
+ analyzing,
+ dragging,
+ dragHandlers,
+ attachFiles,
+ onPaste: onComposerPaste,
+ remove: dropAttachment,
+ clear: clearAttachments,
+ } = usePromptAttachments(
+ target,
useCallback(
- (dt: DataTransfer) => {
- // Read BEFORE any await — a DataTransfer empties the moment this
- // handler returns (see ./paneDrop).
- void attach(extractPaneDrop(dt));
- },
- [attach],
+ (message: string, severity: "warning" | "error") => pushToast(severity, message),
+ [pushToast],
),
);
- const dropAttachment = useCallback((name: string) => {
- setAttachments((prev) => prev.filter((a) => a.name !== name));
- }, []);
/**
* Compose and deliver in one request — the same thing "prompt Mika …" does
@@ -2028,7 +1988,7 @@ export function AgenticGrid({
try {
const result = await promptTerminal(target, text, { compose: true, attachments });
replacePrompt("");
- setAttachments([]);
+ clearAttachments();
// The pane's badge flips to "working" NOW, not when the poll catches the
// screen moving: the user just watched this send succeed, and a badge
// still saying "done" for the next several seconds reads as a send that
@@ -2796,16 +2756,7 @@ export function AgenticGrid({
hidden={composerCollapsed}
style={{ height: composerHeight }}
{...dragHandlers}
- onPaste={(event) => {
- // Clipboard IMAGES only. Pasted text belongs to the textarea, and
- // intercepting it would break ordinary paste into the prompt.
- const images = extractPasteFiles(event.clipboardData).map((f) =>
- nameClipboardFile(f, target || "prompt"),
- );
- if (images.length === 0) return;
- event.preventDefault();
- void attach({ paths: [], files: images });
- }}
+ onPaste={onComposerPaste}
className={cn(
/*
* The height the seam dragged belongs to THIS element; the padding
@@ -2923,7 +2874,7 @@ export function AgenticGrid({
sending={sending}
seed={promptSeed}
onSend={send}
- onAttach={(files) => void attach({ paths: [], files })}
+ onAttach={attachFiles}
/>
</div>
</div>
@@ -3206,86 +3157,6 @@ function TerminalFontSizeControl({
);
}
-/**
- * The files waiting to go in with the next prompt.
- *
- * Each chip says what was actually LEARNED from the file, not just that one was
- * attached. That distinction is the whole feature: "screenshot.png" tells the
- * user nothing about whether the agent will be able to see it, while "described"
- * and "not described" are the two outcomes they need to be able to tell apart
- * before they press Send — and the second one happens for real, on any install
- * whose providers cannot see images.
- */
-function AttachmentStrip({
- attachments,
- analyzing,
- onRemove,
-}: {
- attachments: DropAttachment[];
- analyzing: number;
- onRemove: (name: string) => void;
-}) {
- return (
- <div
- data-testid="agentic-attachments"
- className="mb-2 flex max-h-20 shrink-0 flex-wrap items-center gap-1.5 overflow-y-auto scrollbar-jarvis"
- >
- {attachments.map((item) => {
- const read = item.described_by !== "none" && item.detail.length > 0;
- return (
- <span
- key={item.name}
- data-testid={`agentic-attachment-${item.name}`}
- title={
- read
- ? `${item.detail.slice(0, 400)}${item.detail.length > 400 ? "…" : ""}`
- : item.note || "Attached as a file."
- }
- className={cn(
- "flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px]",
- read
- ? "border-primary/40 bg-primary/10 text-foreground"
- : "border-border text-muted-foreground",
- )}
- >
- {item.kind === "image" ? (
- <ImageIcon className="h-3 w-3 shrink-0" />
- ) : (
- <FileText className="h-3 w-3 shrink-0" />
- )}
- <span className="max-w-[12rem] truncate font-mono">{item.name}</span>
- <span className="shrink-0 text-[10px] text-muted-foreground">
- {read
- ? item.described_by === "vision"
- ? "described"
- : "text read"
- : "not described"}
- </span>
- <button
- type="button"
- aria-label={`Remove ${item.name}`}
- data-testid={`agentic-attachment-remove-${item.name}`}
- onClick={() => onRemove(item.name)}
- className="shrink-0 rounded text-muted-foreground hover:text-destructive"
- >
- <X className="h-3 w-3" />
- </button>
- </span>
- );
- })}
- {analyzing > 0 && (
- <span
- data-testid="agentic-attachment-working"
- className="flex items-center gap-1.5 rounded-md border border-dashed border-border px-2 py-1 text-[11px] text-muted-foreground"
- >
- <Loader2 className="h-3 w-3 animate-spin" />
- Reading {analyzing === 1 ? "the dropped file" : `${analyzing} dropped files`}…
- </span>
- )}
- </div>
- );
-}
-
function ConfirmSelectionClose({
names,
busy,
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.test.ts b/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.test.ts
new file mode 100644
index 0000000000..4eac17b8a1
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.test.ts
@@ -0,0 +1,194 @@
+import { act, renderHook, waitFor } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import { usePromptAttachments } from "@/components/agentic/PromptAttachments";
+import * as api from "@/lib/agenticIdeApi";
+import { NATIVE_DROP_EVENT } from "@/lib/nativeDrop";
+
+/**
+ * Holding a file for an agent's next instruction.
+ *
+ * The case worth a test of its own is the desktop shell's: a file dragged out
+ * of Explorer reaches the page as BYTES with no path, and the host reports the
+ * real location a moment later. Attaching the bytes anyway would hand the agent
+ * a copy in `.jarvis/drops` — it would answer about a file the user cannot see
+ * and cannot have edited, which looks exactly like the agent ignoring them.
+ */
+
+vi.mock("@/lib/agenticIdeApi", () => ({ attachToTerminal: vi.fn() }));
+
+const analysed = (name: string) => ({
+ name,
+ reference: `@${name}`,
+ kind: "image" as const,
+ detail: "a screenshot",
+ described_by: "vision" as const,
+ note: "",
+});
+
+function reply(names: string[]) {
+ return {
+ terminal: "T1",
+ references: [],
+ files: [],
+ copied: 0,
+ submitted: false,
+ delivered: false,
+ analysis: names.map(analysed),
+ };
+}
+
+/** A drag out of Explorer as the desktop shell delivers it: bytes, no path. */
+function bytesOnly(file: File): DataTransfer {
+ return {
+ types: ["Files"],
+ files: [file],
+ items: [],
+ getData: () => "",
+ dropEffect: "none",
+ } as unknown as DataTransfer;
+}
+
+/** Pretend to be the pywebview shell, which answers a drop it has resolved. */
+function shellAnswers(detail: { paths: string[]; names: string[] } | null) {
+ (window as unknown as { pywebview?: unknown }).pywebview = {};
+ if (detail === null) return;
+ queueMicrotask(() =>
+ window.dispatchEvent(new CustomEvent(NATIVE_DROP_EVENT, { detail })),
+ );
+}
+
+describe("usePromptAttachments", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.mocked(api.attachToTerminal).mockResolvedValue(reply(["shot.png"]));
+ });
+
+ afterEach(() => {
+ delete (window as unknown as { pywebview?: unknown }).pywebview;
+ });
+
+ it("attaches a browser drop as bytes — outside the shell there is no path", async () => {
+ const problem = vi.fn();
+ const { result } = renderHook(() => usePromptAttachments("T1", problem));
+
+ act(() => {
+ result.current.dragHandlers.onDrop({
+ preventDefault: () => {},
+ dataTransfer: bytesOnly(new File(["x"], "shot.png", { type: "image/png" })),
+ } as never);
+ });
+
+ await waitFor(() => expect(api.attachToTerminal).toHaveBeenCalled());
+ const [, payload] = vi.mocked(api.attachToTerminal).mock.calls[0];
+ expect(payload.files?.map((f) => f.name)).toEqual(["shot.png"]);
+ expect(payload.paths ?? []).toEqual([]);
+ // Held for the message being written, and read so a text-only CLI can
+ // still be told what is in the picture.
+ expect(payload).toMatchObject({ analyze: true, deliver: false });
+ expect(problem).not.toHaveBeenCalled();
+ });
+
+ it("prefers the path the desktop shell reports over uploading the same bytes", async () => {
+ shellAnswers({ paths: ["C:\\work\\app\\src\\main.ts"], names: ["main.ts"] });
+ const { result } = renderHook(() => usePromptAttachments("T1", vi.fn()));
+
+ act(() => {
+ result.current.dragHandlers.onDrop({
+ preventDefault: () => {},
+ dataTransfer: bytesOnly(new File(["x"], "main.ts", { type: "text/plain" })),
+ } as never);
+ });
+
+ await waitFor(() => expect(api.attachToTerminal).toHaveBeenCalled());
+ const [, payload] = vi.mocked(api.attachToTerminal).mock.calls[0];
+ expect(payload.paths).toEqual(["C:\\work\\app\\src\\main.ts"]);
+ // The byte copy of the very same file is dropped, or the agent would be
+ // handed the file twice — once where it lives and once as a copy.
+ expect(payload.files ?? []).toEqual([]);
+ });
+
+ it("still attaches the bytes when the shell resolves nothing", async () => {
+ shellAnswers(null); // in the shell, but no answer for this drop
+ const { result } = renderHook(() => usePromptAttachments("T1", vi.fn()));
+
+ act(() => {
+ result.current.dragHandlers.onDrop({
+ preventDefault: () => {},
+ dataTransfer: bytesOnly(new File(["x"], "shot.png", { type: "image/png" })),
+ } as never);
+ });
+
+ await waitFor(() => expect(api.attachToTerminal).toHaveBeenCalled(), { timeout: 4000 });
+ const [, payload] = vi.mocked(api.attachToTerminal).mock.calls[0];
+ expect(payload.files?.map((f) => f.name)).toEqual(["shot.png"]);
+ });
+
+ it("renames a pasted screenshot and leaves pasted text alone", async () => {
+ const { result } = renderHook(() => usePromptAttachments("T1", vi.fn()));
+
+ act(() => {
+ result.current.onPaste({
+ preventDefault: () => {},
+ clipboardData: { items: [], types: ["text/plain"], files: [] },
+ } as never);
+ });
+ expect(api.attachToTerminal).not.toHaveBeenCalled();
+
+ const image = new File(["png"], "image.png", { type: "image/png" });
+ act(() => {
+ result.current.onPaste({
+ preventDefault: () => {},
+ clipboardData: { items: [{ kind: "file", getAsFile: () => image }] },
+ } as never);
+ });
+
+ await waitFor(() => expect(api.attachToTerminal).toHaveBeenCalled());
+ const [, payload] = vi.mocked(api.attachToTerminal).mock.calls[0];
+ // Every clipboard calls its image `image.png`; two screenshots must not
+ // arrive under one name.
+ expect(payload.files?.[0].name).not.toBe("image.png");
+ expect(payload.files?.[0].name).toContain("t1-paste-");
+ });
+
+ it("holds the same file once, however often it is dropped", async () => {
+ const { result } = renderHook(() => usePromptAttachments("T1", vi.fn()));
+
+ for (let i = 0; i < 2; i += 1) {
+ act(() => {
+ result.current.attachFiles([new File(["x"], "shot.png", { type: "image/png" })]);
+ });
+ await waitFor(() => expect(result.current.attachments).toHaveLength(1));
+ }
+ expect(api.attachToTerminal).toHaveBeenCalledTimes(2);
+ // Two attempts, one chip: a repeated reference has the agent read the same
+ // file twice for nothing.
+ expect(result.current.attachments.map((a) => a.name)).toEqual(["shot.png"]);
+ });
+
+ it("tells a failure apart from a drop that carried nothing", async () => {
+ const problem = vi.fn();
+ const { result } = renderHook(() => usePromptAttachments("T1", problem));
+
+ vi.mocked(api.attachToTerminal).mockResolvedValueOnce(reply([]));
+ act(() => result.current.attachFiles([new File(["x"], "empty.bin")]));
+ await waitFor(() => expect(problem).toHaveBeenCalled());
+ expect(problem.mock.calls[0][1]).toBe("warning");
+
+ vi.mocked(api.attachToTerminal).mockRejectedValueOnce(new Error("pane is gone"));
+ act(() => result.current.attachFiles([new File(["x"], "again.bin")]));
+ await waitFor(() => expect(problem).toHaveBeenCalledTimes(2));
+ expect(problem.mock.calls[1]).toEqual(["pane is gone", "error"]);
+ });
+
+ it("refuses a drop with no session picked instead of swallowing it", async () => {
+ const problem = vi.fn();
+ const { result } = renderHook(() => usePromptAttachments("", problem));
+
+ act(() => result.current.attachFiles([new File(["x"], "shot.png")]));
+
+ await waitFor(() => expect(problem).toHaveBeenCalled());
+ expect(problem.mock.calls[0][1]).toBe("warning");
+ expect(api.attachToTerminal).not.toHaveBeenCalled();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.tsx b/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.tsx
new file mode 100644
index 0000000000..5165e1b913
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentic/PromptAttachments.tsx
@@ -0,0 +1,254 @@
+/**
+ * Files going in with the next instruction — the drop, the paste, and the strip
+ * of chips that shows what is waiting.
+ *
+ * Extracted from the grid's composer so every surface that writes to an agent
+ * behaves the same. A drop that works in one place and does nothing one click
+ * away is read as the app being broken, not as two surfaces with different
+ * features (maintainer, 2026-08-24) — and this repo has had two such surfaces
+ * more than once.
+ *
+ * The desktop shell is why the drop handler is not three lines. Inside it a
+ * dragged file usually arrives with NO path — the page is handed bytes and a
+ * name, by design — while the host process can see where the file really lies
+ * and reports it a moment later (jarvis/ui/native_drop.py). Waiting for that
+ * answer is the difference between the agent opening the user's own file and
+ * the agent opening a copy of it that nothing else knows about.
+ *
+ * What a drop DOES here is deliberately not what a drop on a terminal pane
+ * does. The pane types a path, which is right for "read this file". A prompt
+ * bar holds the file instead, has it READ — an image described, a document
+ * extracted — and sends that along with the sentence being typed. Several
+ * coding CLIs cannot open an image at all, so without the description the user
+ * drops a picture of a broken layout, types "fix this", and the agent receives
+ * a path and a pronoun.
+ */
+import { useCallback, useState } from "react";
+import { FileText, ImageIcon, Loader2, X } from "lucide-react";
+
+import { usePaneFileDrag } from "@/components/agentic/paneFileDrag";
+import {
+ extractPaneDrop,
+ extractPasteFiles,
+ isEmptyPayload,
+ nameClipboardFile,
+ type PaneDropPayload,
+} from "@/components/agentic/paneDrop";
+import { waitForNativeDrop } from "@/lib/nativeDrop";
+import { attachToTerminal, type DropAttachment } from "@/lib/agenticIdeApi";
+import { cn } from "@/lib/utils";
+
+export interface PromptAttachments {
+ /** What will travel with the next instruction. */
+ attachments: DropAttachment[];
+ /** How many files are being read right now — 0 when nothing is in flight. */
+ analyzing: number;
+ /** True while a file drag hovers the surface; drives the drop styling. */
+ dragging: boolean;
+ /** Spread onto the element that should accept drops. */
+ dragHandlers: ReturnType<typeof usePaneFileDrag>["handlers"];
+ /** Attach files chosen by hand (the paperclip) or read off the clipboard. */
+ attachFiles: (files: File[]) => void;
+ /** Put on the element that should take pasted images; text paste is left alone. */
+ onPaste: (event: React.ClipboardEvent) => void;
+ remove: (name: string) => void;
+ clear: () => void;
+}
+
+/**
+ * Hold files for one agent's next instruction.
+ *
+ * `target` is the pane's call-sign; with none, a drop is refused through
+ * `onProblem` rather than silently swallowed. `onProblem` is where the caller
+ * puts its own toast or inline error — this hook does not decide how a surface
+ * reports things. It DOES decide how bad the news is, and the two are not the
+ * same: a drop that carried nothing usable is a warning about what was
+ * dragged, while an attach that threw is an error about the app. Collapsing
+ * them into one level buries the second.
+ */
+export function usePromptAttachments(
+ target: string,
+ onProblem: (message: string, severity: "warning" | "error") => void,
+): PromptAttachments {
+ const [attachments, setAttachments] = useState<DropAttachment[]>([]);
+ const [analyzing, setAnalyzing] = useState(0);
+
+ const attach = useCallback(
+ async (payload: PaneDropPayload) => {
+ if (isEmptyPayload(payload)) return;
+ if (!target) {
+ onProblem("Pick a session first — a dropped file belongs to one.", "warning");
+ return;
+ }
+ setAnalyzing((n) => n + 1);
+ try {
+ const result = await attachToTerminal(target, {
+ ...payload,
+ analyze: true,
+ // Held, not typed: the user is still writing the sentence that says
+ // what to do with the file, and it goes in with that sentence.
+ deliver: false,
+ });
+ const found = result.analysis ?? [];
+ if (found.length === 0) {
+ onProblem("That drop carried nothing this prompt could use.", "warning");
+ return;
+ }
+ // Keyed by name so the same file dropped twice is held once — a
+ // repeated reference has the agent read it again for nothing.
+ setAttachments((prev) => [
+ ...prev,
+ ...found.filter((item) => !prev.some((held) => held.name === item.name)),
+ ]);
+ } catch (e) {
+ onProblem((e as Error).message, "error");
+ } finally {
+ setAnalyzing((n) => Math.max(0, n - 1));
+ }
+ },
+ [target, onProblem],
+ );
+
+ const { dragging, handlers: dragHandlers } = usePaneFileDrag(
+ useCallback(
+ (dt: DataTransfer) => {
+ // Both reads happen BEFORE any await, and they have to: a DataTransfer
+ // empties the moment this handler returns, and the desktop shell only
+ // answers a listener that was already in place when the drop happened.
+ const payload = extractPaneDrop(dt);
+ void waitForNativeDrop().then((detail) => {
+ if (!detail?.paths.length) return void attach(payload);
+ // Inside the desktop shell the host knows where the file really
+ // lies. Prefer that over uploading its bytes — same file, no copy —
+ // and drop the byte copies the shell just accounted for so nothing
+ // is attached twice.
+ const named = new Set(detail.names.map((n) => n.toLowerCase()));
+ return void attach({
+ paths: Array.from(new Set([...payload.paths, ...detail.paths])),
+ files: payload.files.filter((f) => !named.has(f.name.toLowerCase())),
+ });
+ });
+ },
+ [attach],
+ ),
+ );
+
+ const attachFiles = useCallback(
+ (files: File[]) => {
+ if (files.length > 0) void attach({ paths: [], files });
+ },
+ [attach],
+ );
+
+ const onPaste = useCallback(
+ (event: React.ClipboardEvent) => {
+ // Text paste belongs to the browser and must keep working — this only
+ // claims what a text box would otherwise discard: an IMAGE on the
+ // clipboard, which is what PrintScreen and Ctrl+V produce.
+ const files = extractPasteFiles(event.clipboardData).map((f) =>
+ nameClipboardFile(f, target || "chat"),
+ );
+ if (files.length === 0) return;
+ event.preventDefault();
+ void attach({ paths: [], files });
+ },
+ [attach, target],
+ );
+
+ const remove = useCallback((name: string) => {
+ setAttachments((prev) => prev.filter((a) => a.name !== name));
+ }, []);
+
+ const clear = useCallback(() => setAttachments([]), []);
+
+ return {
+ attachments,
+ analyzing,
+ dragging,
+ dragHandlers,
+ attachFiles,
+ onPaste,
+ remove,
+ clear,
+ };
+}
+
+/**
+ * The files waiting to go in with the next prompt.
+ *
+ * Each chip says what was actually LEARNED from the file, not just that one was
+ * attached. That distinction is the whole feature: "screenshot.png" tells the
+ * user nothing about whether the agent will be able to see it, while "described"
+ * and "not described" are the two outcomes they need to be able to tell apart
+ * before they press Send — and the second one happens for real, on any install
+ * whose providers cannot see images.
+ */
+export function AttachmentStrip({
+ attachments,
+ analyzing,
+ onRemove,
+}: {
+ attachments: DropAttachment[];
+ analyzing: number;
+ onRemove: (name: string) => void;
+}) {
+ return (
+ <div
+ data-testid="agentic-attachments"
+ className="mb-2 flex max-h-20 shrink-0 flex-wrap items-center gap-1.5 overflow-y-auto scrollbar-jarvis"
+ >
+ {attachments.map((item) => {
+ const read = item.described_by !== "none" && item.detail.length > 0;
+ return (
+ <span
+ key={item.name}
+ data-testid={`agentic-attachment-${item.name}`}
+ title={
+ read
+ ? `${item.detail.slice(0, 400)}${item.detail.length > 400 ? "…" : ""}`
+ : item.note || "Attached as a file."
+ }
+ className={cn(
+ "flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px]",
+ read
+ ? "border-primary/40 bg-primary/10 text-foreground"
+ : "border-border text-muted-foreground",
+ )}
+ >
+ {item.kind === "image" ? (
+ <ImageIcon className="h-3 w-3 shrink-0" />
+ ) : (
+ <FileText className="h-3 w-3 shrink-0" />
+ )}
+ <span className="max-w-[12rem] truncate font-mono">{item.name}</span>
+ <span className="shrink-0 text-[10px] text-muted-foreground">
+ {read
+ ? item.described_by === "vision"
+ ? "described"
+ : "text read"
+ : "not described"}
+ </span>
+ <button
+ type="button"
+ aria-label={`Remove ${item.name}`}
+ data-testid={`agentic-attachment-remove-${item.name}`}
+ onClick={() => onRemove(item.name)}
+ className="shrink-0 rounded text-muted-foreground hover:text-destructive"
+ >
+ <X className="h-3 w-3" />
+ </button>
+ </span>
+ );
+ })}
+ {analyzing > 0 && (
+ <span
+ data-testid="agentic-attachment-working"
+ className="flex items-center gap-1.5 rounded-md border border-dashed border-border px-2 py-1 text-[11px] text-muted-foreground"
+ >
+ <Loader2 className="h-3 w-3 animate-spin" />
+ Reading {analyzing === 1 ? "the dropped file" : `${analyzing} dropped files`}…
+ </span>
+ )}
+ </div>
+ );
+}