Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(agent): file attachments on agent prompts as ACP resource links (#6269)
Eric Hayes3dedbf5ca8d7
diff --git a/Cargo.lock b/Cargo.lockindex d286a92bb5..99a1fa2500 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -397,6 +397,7 @@ dependencies = ["ai_usage","anyhow","async-trait",+ "attachment","axum","bot_id","bytes",@@ -411,6 +412,8 @@ dependencies = ["mcp_select","mcp_toolset","memory",+ "model-entity",+ "non_empty","opentelemetry","opentelemetry_sdk","prompt",diff --git a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx b/apps/web/src/features/agents-view/components/ChatComposer.test.tsxindex b98b0f5478..3a6dac7a6f 100644--- a/apps/web/src/features/agents-view/components/ChatComposer.test.tsx+++ b/apps/web/src/features/agents-view/components/ChatComposer.test.tsx@@ -1,3 +1,4 @@+import type { InputAttachmentData } from '@channel/Input/types';import { $createQuoteNode, QuoteNode } from '@lexical/rich-text';import { fireEvent, render, screen } from '@solidjs/testing-library';import {@@ -19,6 +20,9 @@ const editor = vi.hoisted(() => ({| ((event: unknown, markdown: string) => boolean)| undefined,change: undefined as ((markdown: string) => void) | undefined,+ paste: undefined as+ | ((files: File[], directories: FileSystemDirectoryEntry[]) => void)+ | undefined,text: '',}));@@ -38,6 +42,12 @@ vi.mock(withRestoreFocus: () => builder,withSkills: () => builder,withAgentCommands: () => builder,+ withFilePaste: (options: {+ onPasteFilesAndDirs: typeof editor.paste;+ }) => {+ editor.paste = options.onPasteFilesAndDirs;+ return builder;+ },onEnter: (callback: typeof editor.enter) => {editor.enter = callback;return builder;@@ -66,6 +76,24 @@ vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({),}));+vi.mock('@channel/Input/Input', () => ({+ Input: {+ DropZone: (props: { children: unknown }) => props.children,+ DropOverlay: () => null,+ Attachments: () => null,+ AttachFilesAction: (props: { disabled?: boolean }) => (+ <button aria-label="Attach files" disabled={props.disabled} />+ ),+ },+}));+vi.mock('@core/util/upload', () => ({+ handleFileFolderDrop: async (+ files: File[],+ _dirs: unknown[],+ callback: (entries: { file: File }[]) => void+ ) => callback(files.map((file) => ({ file }))),+}));+beforeEach(() => {vi.stubGlobal('ResizeObserver',@@ -97,7 +125,7 @@ describe('Chat session input', () => {).toBe('Model');type(' Follow up ');fireEvent.click(screen.getByRole('button', { name: 'Send' }));- expect(send).toHaveBeenCalledWith('Follow up');+ expect(send).toHaveBeenCalledWith('Follow up', []);expect(editor.clear).toHaveBeenCalledOnce();expect(screen.getByRole('button', { name: 'Send' }).hasAttribute('disabled')@@ -121,7 +149,7 @@ describe('Chat session input', () => {expect(stop).toHaveBeenCalledOnce();type('Next request');fireEvent.click(screen.getByRole('button', { name: 'Send' }));- expect(send).toHaveBeenCalledWith('Next request');+ expect(send).toHaveBeenCalledWith('Next request', []);});it('advances a queued prompt with Enter only when the draft is empty', () => {@@ -134,7 +162,7 @@ describe('Chat session input', () => {expect(stop).toHaveBeenCalledOnce();type('Another request');editor.enter?.(undefined, editor.text);- expect(send).toHaveBeenCalledWith('Another request');+ expect(send).toHaveBeenCalledWith('Another request', []);expect(stop).toHaveBeenCalledOnce();});@@ -233,3 +261,74 @@ it('expands for a short quote and collapses when replaced with a paragraph', ());expect(layout?.getAttribute('data-composer-compact')).toBe('true');});++describe('attachments in the shared composer', () => {+ const image: InputAttachmentData = {+ id: 'image-id',+ name: 'pasted.png',+ kind: 'image',+ mimeType: 'image/png',+ };++ it('routes pasted files to the session uploader', () => {+ const attach = vi.fn();+ render(() => <ChatSessionInput onSend={vi.fn()} onAttachFiles={attach} />);+ const file = new File(['image'], 'pasted.png', { type: 'image/png' });+ editor.paste?.([file], []);+ expect(attach).toHaveBeenCalledWith([file]);+ expect(screen.getByRole('button', { name: 'Attach files' })).toBeTruthy();+ });++ it('holds an image-only prompt while uploading, then sends the image instead of stopping', () => {+ const send = vi.fn();+ const stop = vi.fn();+ const [attachments, setAttachments] = createSignal([+ { ...image, pending: true },+ ]);+ render(() => (+ <ChatSessionInput+ busy+ hasQueuedMessages+ onSend={send}+ onStop={stop}+ attachments={attachments()}+ />+ ));+ expect(+ screen.getByRole('button', { name: 'Send' }).hasAttribute('disabled')+ ).toBe(true);+ editor.enter?.(undefined, '');+ expect(send).not.toHaveBeenCalled();+ expect(stop).not.toHaveBeenCalled();+ setAttachments([{ ...image, pending: false }]);+ editor.enter?.(undefined, '');+ expect(send).toHaveBeenCalledWith('', [{ ...image, pending: false }]);+ expect(stop).not.toHaveBeenCalled();+ });++ it('sends attachments and text from a new conversation', () => {+ const send = vi.fn();+ render(() => (+ <ChatComposer+ draft="Describe this"+ onDraftChange={vi.fn()}+ selector={null}+ attachments={[image]}+ onSend={send}+ />+ ));+ editor.enter?.(undefined, 'Describe this');+ expect(send).toHaveBeenCalledWith('Describe this', [image]);+ });+});++it('keeps the paperclip visible while the session is unavailable', () => {+ render(() => (+ <ChatSessionInput disabled onSend={vi.fn()} onAttachFiles={vi.fn()} />+ ));+ expect(+ screen+ .getByRole('button', { name: 'Attach files' })+ .hasAttribute('disabled')+ ).toBe(true);+});diff --git a/apps/web/src/features/agents-view/components/ChatComposer.tsx b/apps/web/src/features/agents-view/components/ChatComposer.tsxindex 9cf95c68b9..07000cfa9e 100644--- a/apps/web/src/features/agents-view/components/ChatComposer.tsx+++ b/apps/web/src/features/agents-view/components/ChatComposer.tsx@@ -1,9 +1,13 @@import type { AgentInputProps } from '@app/features/block-agent/ui';+import { InputProvider } from '@channel/Input/context';+import { Input } from '@channel/Input/Input';+import type { InputAttachmentData, InputCommands } from '@channel/Input/types';import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { useTouchOutsideToDismissKeyboard } from '@core/mobile/useTouchOutsideToDismissKeyboard';+import { handleFileFolderDrop } from '@core/util/upload';import { $insertReferencedPaste } from '@macro-inc/lexical-core';import { createResizeObserver } from '@solid-primitives/resize-observer';import { Button, ComposerSurface, SendButton } from '@ui';@@ -25,8 +29,11 @@ export function ChatComposer(props: {onDraftChange: (draft: string) => void;blockedReason?: string;selector: JSX.Element;- onSend: (prompt: string) => void;+ onSend: (prompt: string, attachments: InputAttachmentData[]) => void;session?: AgentInputProps;+ attachments?: InputAttachmentData[];+ onAttachFiles?: (files: File[]) => void;+ onRemoveAttachment?: (attachment: InputAttachmentData) => void;drawer?: JSX.Element;drawerOpen?: boolean;placeholder?: string;@@ -35,18 +42,35 @@ export function ChatComposer(props: {() => props.draft.trim().length === 0,!props.session);+ const attachments = () => props.attachments ?? [];+ const hasContent = () => !!props.draft.trim() || attachments().length > 0;+ const hasPendingAttachments = () =>+ attachments().some((file) => file.pending);+ const canAttach = () => !!props.onAttachFiles && !disabled();+ const attachFiles = (files: File[]) => {+ if (canAttach() && files.length > 0) props.onAttachFiles?.(files);+ };+ const [isDraggedOver, setIsDraggedOver] = createSignal(false);+ const inputCommands: InputCommands = {+ send: async () => false,+ attachFiles: async (files) => attachFiles(files),+ removeAttachment: (attachment) => props.onRemoveAttachment?.(attachment),+ toggleFormatRibbon: () => {},+ close: () => {},+ };+ const [content, setContent] = createSignal<HTMLDivElement>();const [layout, setLayout] = createSignal<HTMLDivElement>();const [height, setHeight] = createSignal<number>();- createResizeObserver(layout, (_, element) => {+ createResizeObserver(content, (_, element) => {setHeight(element.getBoundingClientRect().height);});let container: HTMLDivElement | undefined;useTouchOutsideToDismissKeyboard(() => container);const disabled = () => !!props.blockedReason || props.session?.disabled;const canSendNext = () =>- !props.draft.trim() &&- props.session?.busy &&- props.session.hasQueuedMessages &&+ !hasContent() &&+ !props.session?.stopPending &&+ props.session?.hasQueuedMessages &&props.session.onStop &&!disabled();const editor = buildConfig('chat')@@ -57,9 +81,16 @@ export function ChatComposer(props: {.withHistory({ timeGap: 400 }).withCode().withRestoreFocus()+ .withFilePaste({+ onPasteFilesAndDirs: (files, directories) => {+ void handleFileFolderDrop(files, directories, (entries) =>+ attachFiles(entries.map((entry) => entry.file))+ );+ },+ }).onEnter((_event, markdown) => {- if (markdown.trim()) send(markdown);- else if (canSendNext()) props.session?.onStop?.();+ if (markdown.trim() || attachments().length > 0) send(markdown);+ else if (canSendNext()) sendNext();return true;}).onFocusLeave({@@ -107,10 +138,20 @@ export function ChatComposer(props: {const send = (markdown = editor.controls.getMarkdown()) => {const prompt = markdown.trim();- if (!prompt || disabled()) return;+ if (+ (!prompt && attachments().length === 0) ||+ hasPendingAttachments() ||+ disabled()+ )+ return;+ const attached = attachments();editor.controls.clear();props.onDraftChange('');- props.onSend(prompt);+ props.onSend(prompt, attached);+ };++ const sendNext = () => {+ if (canSendNext()) (props.session?.onSendNext ?? props.session?.onStop)?.();};const focusEditor = (event: Event) => {@@ -126,105 +167,144 @@ export function ChatComposer(props: {};return (- <div ref={container} data-keep-keyboard class="min-w-0">- <ComposerSurface- as="div"- data-agent-composer="chat"- class="relative z-10 min-w-0 rounded-[32px] transition-[height] duration-150 ease-out motion-reduce:transition-none"- style={{ height: height() === undefined ? undefined : `${height()}px` }}- onPointerDown={focusEditor}- onMouseDown={focusEditor}- >- <div- ref={setLayout}- data-composer-compact={isCompact()}- class="group/composer flex min-w-0 data-[composer-compact=false]:flex-col data-[composer-compact=false]:items-stretch items-end gap-2 p-[7.5px]"+ <InputProvider+ value={{+ view: () => ({+ mode: 'channel',+ attachments: attachments(),+ isDraggedOver: isDraggedOver(),+ hasPendingAttachments: hasPendingAttachments(),+ }),+ commands: inputCommands,+ }}+ >+ <div ref={container} data-keep-keyboard class="min-w-0">+ <ComposerSurface+ as="div"+ data-agent-composer="chat"+ class="relative z-10 min-w-0 rounded-[32px] transition-[height] duration-150 ease-out motion-reduce:transition-none"+ style={{+ height: height() === undefined ? undefined : `${height()}px`,+ }}+ onPointerDown={focusEditor}+ onMouseDown={focusEditor}>- <div class="max-h-60 min-w-0 flex-1 self-center group-data-[composer-compact=false]/composer:flex-none group-data-[composer-compact=false]/composer:self-stretch overflow-y-auto px-[9.375px]">- <MarkdownShell- class="h-auto min-h-6 text-base leading-6 [&_[data-markdown-editable]]:min-h-6 [&_[data-markdown-editable]]:outline-none [&_[data-markdown-editable]>.md-p]:my-0 [&_[data-markdown-placeholder]]:max-w-full [&_[data-markdown-placeholder]>p]:m-0 [&_[data-markdown-placeholder]>p]:truncate"- config={editor}- initialValue={props.draft}- placeholder={props.placeholder ?? tip()}- refFn={(element) =>- element.setAttribute('aria-label', 'Message the agent')- }- autofocus={- !isTouchDevice() &&- (props.autoFocus ?? props.session?.autofocus ?? true)- }- />- </div>- <div- data-composer-controls- class="flex min-w-0 max-w-[55%] group-data-[composer-compact=false]/composer:max-w-none shrink-0 items-center"- role="group"- aria-label="Composer settings"+ <Input.DropZone+ onDragStart={(valid) => canAttach() && setIsDraggedOver(valid)}+ onDragEnd={() => setIsDraggedOver(false)}>- <div class="ml-auto flex min-w-0 max-w-full items-center gap-2 [&_.menu]:right-0 [&_.menu]:left-auto [&_.menu-anchor]:min-w-0 [&_.pill]:max-w-full">- {props.selector}- <Show- when={- props.session?.busy &&- props.session.onStop &&- !props.draft.trim()- }- fallback={- <SendButton- appearance="composer"- aria-label="Send"- title={props.blockedReason}- disabled={!props.draft.trim() || disabled()}- onClick={() => send()}- />- }+ <Show when={canAttach()}>+ <Input.DropOverlay+ class="rounded-[32px]"+ hint="Drop files here to send them to the agent"+ />+ </Show>+ <div ref={setContent} data-composer-content>+ <Input.Attachments kind="media" class="pb-0" />+ <Input.Attachments kind="document" class="pb-0" />+ <div+ ref={setLayout}+ data-composer-compact={isCompact()}+ class="group/composer flex min-w-0 data-[composer-compact=false]:flex-col data-[composer-compact=false]:items-stretch items-end gap-2 p-[7.5px]">- <Show- when={canSendNext()}- fallback={- <Button- variant="strong"- size="icon-composer"- label="Stop"- disabled={disabled()}- onClick={() => props.session?.onStop?.()}- >- <div class="size-3.5 rounded-sm bg-current" />- </Button>- }- >- <SendButton- appearance="composer"- aria-label="Send next queued message"- tooltip="Send next queued message"- shortcut="Enter"- onClick={() => props.session?.onStop?.()}+ <div class="max-h-60 min-w-0 flex-1 self-center group-data-[composer-compact=false]/composer:flex-none group-data-[composer-compact=false]/composer:self-stretch overflow-y-auto px-[9.375px]">+ <MarkdownShell+ class="h-auto min-h-6 text-base leading-6 [&_[data-markdown-editable]]:min-h-6 [&_[data-markdown-editable]]:outline-none [&_[data-markdown-editable]>.md-p]:my-0 [&_[data-markdown-placeholder]]:max-w-full [&_[data-markdown-placeholder]>p]:m-0 [&_[data-markdown-placeholder]>p]:truncate"+ config={editor}+ initialValue={props.draft}+ placeholder={props.placeholder ?? tip()}+ refFn={(element) =>+ element.setAttribute('aria-label', 'Message the agent')+ }+ autofocus={+ !isTouchDevice() &&+ (props.autoFocus ?? props.session?.autofocus ?? true)+ }/>- </Show>- </Show>+ </div>+ <div+ data-composer-controls+ class="flex min-w-0 max-w-[55%] group-data-[composer-compact=false]/composer:max-w-none shrink-0 items-center"+ role="group"+ aria-label="Composer settings"+ >+ <div class="ml-auto flex min-w-0 max-w-full items-center gap-2 [&_.menu]:right-0 [&_.menu]:left-auto [&_.menu-anchor]:min-w-0 [&_.pill]:max-w-full">+ <Show when={props.onAttachFiles}>+ <Input.AttachFilesAction+ accept={null}+ disabled={disabled()}+ />+ </Show>+ {props.selector}+ <Show+ when={+ (props.session?.busy || canSendNext()) &&+ props.session?.onStop &&+ !hasContent()+ }+ fallback={+ <SendButton+ appearance="composer"+ aria-label="Send"+ title={props.blockedReason}+ disabled={+ !hasContent() ||+ hasPendingAttachments() ||+ disabled()+ }+ onClick={() => send()}+ />+ }+ >+ <Show+ when={canSendNext()}+ fallback={+ <Button+ variant="strong"+ size="icon-composer"+ label="Stop"+ disabled={disabled()}+ onClick={() => props.session?.onStop?.()}+ >+ <div class="size-3.5 rounded-sm bg-current" />+ </Button>+ }+ >+ <SendButton+ appearance="composer"+ aria-label="Send next queued message"+ tooltip="Send next queued message"+ shortcut="Enter"+ onClick={sendNext}+ />+ </Show>+ </Show>+ </div>+ </div>+ </div></div>- </div>- </div>- </ComposerSurface>- <Show when={props.drawer}>- <div- class="composer-drawer"- data-open={props.drawerOpen ? '' : undefined}- aria-hidden={!props.drawerOpen}- inert={!props.drawerOpen}- >- <div class="composer-drawer-inner">- <div- class="composer-drawer-content"- role="group"- aria-label="Repository settings"- >- {props.drawer}+ </Input.DropZone>+ </ComposerSurface>+ <Show when={props.drawer}>+ <div+ class="composer-drawer"+ data-open={props.drawerOpen ? '' : undefined}+ aria-hidden={!props.drawerOpen}+ inert={!props.drawerOpen}+ >+ <div class="composer-drawer-inner">+ <div+ class="composer-drawer-content"+ role="group"+ aria-label="Repository settings"+ >+ {props.drawer}+ </div></div></div>- </div>- </Show>- </div>+ </Show>+ </div>+ </InputProvider>);}@@ -238,6 +318,9 @@ export function ChatSessionInput(props: AgentInputProps) {selector={props.modelControl}onSend={props.onSend}session={props}+ attachments={props.attachments}+ onAttachFiles={props.onAttachFiles}+ onRemoveAttachment={props.onRemoveAttachment}/>);}diff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsxindex 5da13c8820..a5e42810e5 100644--- a/apps/web/src/features/agents-view/views/AgentsView.tsx+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx@@ -206,6 +206,7 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {const id = startPendingSession({botId: start.botId,prompt: start.prompt,+ attachments: start.attachments,modelOverride: start.modelOverride,repoUrl: start.repoUrl,repoBranch: start.repoBranch,diff --git a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx b/apps/web/src/features/agents-view/views/NewChatPage.test.tsxindex a6af6d41fb..e7f848230f 100644--- a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx+++ b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx@@ -1,3 +1,4 @@+import type { InputAttachmentData } from '@channel/Input/types';import { CURSOR_BOT_ID } from '@core/constant/cursorAgent';import { MACRO_CODER_BOT_ID } from '@core/constant/macroCoder';import {@@ -15,9 +16,15 @@ import { NewChatPage } from './NewChatPage';const mocks = vi.hoisted(() => ({openSettings: vi.fn(),+ attachments: [] as InputAttachmentData[],recentIds: [] as string[],repositories: [] as { url: string; defaultBranch?: string }[],}));+vi.mock('@core/util/upload', () => ({ uploadFile: vi.fn() }));+vi.mock('@channel/Input', async () => ({+ ...(await import('../../channel/Input/attachment-tracker')),+ uploadInputAttachments: vi.fn(),+}));vi.mock('@core/context/user', () => ({ useUserId: () => () => 'user' }));vi.mock('@core/constant/SettingsState', () => ({useSettingsState: () => ({ openSettings: mocks.openSettings }),@@ -80,7 +87,7 @@ type ComposerProps = {drawerOpen: boolean;draft: string;onDraftChange: (draft: string) => void;- onSend: (prompt: string) => void;+ onSend: (prompt: string, attachments: InputAttachmentData[]) => void;};vi.mock('../components/ChatComposer', () => ({ChatComposer: (props: ComposerProps) => (@@ -94,7 +101,14 @@ vi.mock('../components/ChatComposer', () => ({value={props.draft}onInput={(event) => props.onDraftChange(event.currentTarget.value)}/>- <button onClick={() => props.onSend(props.draft || 'Prompt')}>+ <button+ onClick={() =>+ props.onSend(+ props.draft || (mocks.attachments.length ? '' : 'Prompt'),+ mocks.attachments+ )+ }+ >Send</button></>@@ -148,6 +162,7 @@ async function hoverAgent(name: string) {describe('agent-led new conversation', () => {let motionStyles: HTMLStyleElement;beforeEach(() => {+ mocks.attachments = [];mocks.recentIds = [MACRO_CODER_BOT_ID];mocks.repositories = [{ url: 'https://github.com/macro-inc/macro', defaultBranch: 'develop' },@@ -458,3 +473,30 @@ describe('agent-led new conversation', () => {expect(screen.getByTestId('drawer').hasAttribute('hidden')).toBe(true);});});++it('starts a conversation with an uploaded image and no text', () => {+ mocks.attachments = [+ {+ id: 'sfs-image',+ name: 'pasted.png',+ kind: 'image',+ mimeType: 'image/png',+ size: 123,+ },+ ];+ const start = page();+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));+ expect(start).toHaveBeenCalledWith(+ expect.objectContaining({+ prompt: '',+ attachments: [+ {+ uri: expect.stringContaining('sfs-image'),+ name: 'pasted.png',+ mimeType: 'image/png',+ size: 123,+ },+ ],+ })+ );+});diff --git a/apps/web/src/features/agents-view/views/NewChatPage.tsx b/apps/web/src/features/agents-view/views/NewChatPage.tsxindex fcdccbff31..3536b69199 100644--- a/apps/web/src/features/agents-view/views/NewChatPage.tsx+++ b/apps/web/src/features/agents-view/views/NewChatPage.tsx@@ -1,6 +1,14 @@+import { promptActionOf } from '@app/features/block-agent/component/prompt-action';import { createRecentAgentSelections } from '@app/features/block-agent/context/recent-agent-selections';+import {+ createInputAttachmentTracker,+ type InputAttachmentData,+ uploadInputAttachments,+} from '@channel/Input';import { useSettingsState } from '@core/constant/SettingsState';import { useUserId } from '@core/context/user';+import { uploadFile } from '@core/util/upload';+import type { PromptAttachment } from '@service-agent-harness/generated/schemas';import { createMemo, createSignal } from 'solid-js';import { ChatComposer } from '../components/ChatComposer';import type { AgentKind } from '../core/agent-kind';@@ -14,6 +22,7 @@ import { RepositoryPicker } from './RepositoryPicker';/** What the composer hands the workspace to start a session with. */export type StartConversation = {prompt: string;+ attachments?: PromptAttachment[];/** Persisted or first-party bot to run; omitted for Macro's default. */botId?: string;repoUrl?: string;@@ -83,19 +92,38 @@ export function NewChatPage(props: {if (agent.harness === 'cursor') openSettings('Harness');};- const send = (prompt: string) => {+ const attachmentTracker = createInputAttachmentTracker();+ const attachFiles = (files: File[]) =>+ void uploadInputAttachments({+ files,+ tracker: attachmentTracker,+ uploadFile: (file) =>+ uploadFile(file, 'static', { hideProgressIndicator: true }),+ });++ const send = (prompt: string, attachments: InputAttachmentData[]) => {const persona = selected();- if (!prompt.trim() || !persona || blocked()) return;+ if (+ (!prompt.trim() && attachments.length === 0) ||+ !persona ||+ blocked() ||+ attachmentTracker.hasPending()+ )+ return;recentAgents.remember(persona.id);const repo = canSelectRepository() ? repoUrl() : undefined;if (repo) repositories.remember(repo);props.onStart({prompt,+ ...(attachments.length > 0+ ? { attachments: promptActionOf(prompt, attachments).attachments }+ : {}),botId: persona.botId,repoUrl: repo,...(repo ? { repoBranch: repoBranch() } : {}),...(modelOverride() ? { modelOverride: modelOverride() } : {}),});+ attachmentTracker.clearAttachments();setModelOverride(undefined);};@@ -146,6 +174,11 @@ export function NewChatPage(props: {drawerOpen={coding()}placeholder={coding() ? 'Describe what you want to build' : undefined}onSend={send}+ attachments={attachmentTracker.attachments()}+ onAttachFiles={attachFiles}+ onRemoveAttachment={(attachment) =>+ attachmentTracker.removeAttachment(attachment.id)+ }/></div></section>diff --git a/apps/web/src/features/block-agent/component/AgentComposer.tsx b/apps/web/src/features/block-agent/component/AgentComposer.tsxindex 95f2c6ae85..142ddda793 100644--- a/apps/web/src/features/block-agent/component/AgentComposer.tsx+++ b/apps/web/src/features/block-agent/component/AgentComposer.tsx@@ -5,9 +5,15 @@* marks — so the composer keeps no state of its own.*/+import {+ createInputAttachmentTracker,+ type InputAttachmentData,+ uploadInputAttachments,+} from '@channel/Input';import { toast } from '@core/component/Toast/Toast';import { useUserId } from '@core/context/user';import { idToDisplayName } from '@core/user/util';+import { uploadFile } from '@core/util/upload';import type { AgentAction } from '@service-agent-harness/generated/schemas';import { type Component, Show } from 'solid-js';import { useAgentSession } from '../context/AgentSessionContext';@@ -21,6 +27,7 @@ import {QueuedPrompts,} from '../ui';import type { AgentModelSelectorProps } from '../ui/AgentModelSelector';+import { promptActionOf } from './prompt-action';export function AgentComposer(props: {/**@@ -77,6 +84,26 @@ export function AgentComposer(props: {messages().some((message) => message.pending) &&!hasPendingStop(messages());+ // Files dropped, pasted, or picked into the composer. Every one goes to+ // the static file service - documents too, not only media - because the+ // agent can only reach a file by a URL it can fetch. The chips and the+ // upload flow are the channel composer's.+ const attachmentTracker = createInputAttachmentTracker();+ const attachFiles = (files: File[]) =>+ void uploadInputAttachments({+ files,+ tracker: attachmentTracker,+ uploadFile: (file) =>+ uploadFile(file, 'static', { hideProgressIndicator: true }),+ });+ // Attachments ride the prompt action itself, so they take the same path as+ // the text: issued once, speculated by the fold, and queued server-side+ // behind a running turn with the files still on them.+ const send = (markdown: string, attachments: InputAttachmentData[]) => {+ act(promptActionOf(markdown, attachments), 'The message could not be sent');+ attachmentTracker.clearAttachments();+ };+// Focus plumbing between the input and the queue list above it: Up at the// start of the input lands on the bottom (next-to-dispatch) queue row, and// Down past that row comes back. Plain variables, read only at call time.@@ -93,6 +120,7 @@ export function AgentComposer(props: {actionId: entry.actionId,kind: entry.kind,prompt: entry.prompt ?? undefined,+ attachments: entry.attachments,queuedBy:actor && actor !== userId() ? idToDisplayName(actor) : undefined,};@@ -141,11 +169,14 @@ export function AgentComposer(props: {// into, but not sent from, until the id lands.disabled={loadFailed() || pending()}commands={() => metadata()?.availableCommands ?? []}- onSend={(prompt) =>- act({ type: 'prompt', prompt }, 'The message could not be sent')- }+ onSend={send}onStop={() => act({ type: 'stop' }, 'The agent could not be stopped')}onSendNext={sendNext}+ attachments={attachmentTracker.attachments()}+ onAttachFiles={attachFiles}+ onRemoveAttachment={(attachment) =>+ attachmentTracker.removeAttachment(attachment.id)+ }// Installed only while a queue row exists to land on: an installed// handler claims the keys (Up, and the shared plugin's other// leave-at-start keys), which must keep their defaults when there isdiff --git a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx b/apps/web/src/features/block-agent/component/AgentMessage.test.tsxindex a07bc98bfa..29367ade8c 100644--- a/apps/web/src/features/block-agent/component/AgentMessage.test.tsx+++ b/apps/web/src/features/block-agent/component/AgentMessage.test.tsx@@ -40,6 +40,11 @@ vi.mock('./parts/PermissionPart', () => ({PermissionPart: () => <div data-testid="permission" />,}));vi.mock('./parts/PlanPart', () => ({ PlanPart: () => null }));+vi.mock('./parts/AttachmentPart', () => ({+ AttachmentPart: (props: { part: { name: string } }) => (+ <div data-testid="attachment">{props.part.name}</div>+ ),+}));vi.mock('./parts/ControlPart', () => ({ ControlPart: () => null }));vi.mock('./parts/ElicitationPart', () => ({ ElicitationPart: () => null }));vi.mock('../ui', () => ({diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsxindex 526494b3e5..4c9eb532e2 100644--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx@@ -27,6 +27,7 @@ import {ToolGroup,WorkingLine,} from '../ui';+import { AttachmentPart } from './parts/AttachmentPart';import { ControlPart } from './parts/ControlPart';import { ElicitationPart } from './parts/ElicitationPart';import { PermissionPart } from './parts/PermissionPart';@@ -47,6 +48,7 @@ function AgentMessagePart(props: {.with({ kind: 'text' }, (part) => (<TextPart text={part.text} inFlight={props.inFlight} />))+ .with({ kind: 'attachment' }, (part) => <AttachmentPart part={part} />).with({ kind: 'thought' }, (part) => (<Thoughttext={part.text}diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsxnew file mode 100644index 0000000000..a9fcec1399--- /dev/null+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.test.tsx@@ -0,0 +1,124 @@+/**+ * @vitest-environment jsdom+ *+ * What an attached file renders as is decided by its media type: images and+ * videos as media, everything else as a chip that opens the file.+ */++import type { MessagePart } from '@service-agent-fold/generated/types';+import { render } from '@solidjs/testing-library';+import { describe, expect, it, vi } from 'vitest';+import { AttachmentPart, attachmentMedium } from './AttachmentPart';++vi.mock('@channel/Media/MediaImage', () => ({+ MediaImage: {+ Root: (props: { children: unknown }) => (+ <div>{props.children as never}</div>+ ),+ Image: (props: { src: string }) => (+ <img data-testid="media-image" src={props.src} alt="" />+ ),+ Fallback: () => null,+ },+}));+vi.mock('@channel/Media/MediaVideo', () => ({+ MediaVideo: {+ Root: (props: { children: unknown }) => (+ <div>{props.children as never}</div>+ ),+ Preview: (props: { src: string }) => (+ <video data-testid="media-video" src={props.src} />+ ),+ PlayOverlay: () => null,+ },+}));+// The block registry eagerly imports every block's definition, which drags+// the chat input's storage module into jsdom; the extension-to-icon mapping+// is all this component needs from it.+vi.mock('@core/constant/allBlocks', () => ({+ fileTypeToBlockName: (fileType?: string) => fileType ?? 'unknown',+}));+vi.mock('@core/component/EntityIcon', () => ({+ EntityIcon: (props: { targetType: string }) => (+ <i data-testid="entity-icon" data-type={props.targetType} />+ ),+}));++type Attachment = Extract<MessagePart, { kind: 'attachment' }>;++const attachment = (over: Partial<Attachment>): Attachment => ({+ kind: 'attachment',+ uri: 'https://static.example/file/1',+ name: 'file.bin',+ mimeType: null,+ size: null,+ ...over,+});++describe('attachmentMedium', () => {+ it('reads the medium off the media type', () => {+ expect(attachmentMedium({ mimeType: 'image/png', name: 'a' })).toBe(+ 'image'+ );+ // A wildcard range is what channel attachments carry.+ expect(attachmentMedium({ mimeType: 'video/*', name: 'a' })).toBe('video');+ expect(attachmentMedium({ mimeType: 'application/pdf', name: 'a' })).toBe(+ 'file'+ );+ expect(attachmentMedium({ mimeType: null, name: 'notes.txt' })).toBe(+ 'file'+ );+ });++ it('falls back to the file name when the sender knew no media type', () => {+ // A browser that reports an empty `type` must not turn the thumbnail the+ // composer showed into a chip once the prompt is sent.+ expect(attachmentMedium({ mimeType: null, name: 'shot.png' })).toBe(+ 'image'+ );+ expect(attachmentMedium({ mimeType: null, name: 'clip.mov' })).toBe(+ 'video'+ );+ expect(attachmentMedium({ mimeType: null, name: 'README' })).toBe('file');+ });+});++describe('AttachmentPart', () => {+ it('renders an image as a sized thumbnail linking to the original', () => {+ const { getByTestId, container } = render(() => (+ <AttachmentPart+ part={attachment({ name: 'shot.png', mimeType: 'image/png' })}+ />+ ));+ expect(getByTestId('media-image').getAttribute('src')).toBe(+ 'https://static.example/file/1?size=1080'+ );+ expect(container.querySelector('a')?.getAttribute('href')).toBe(+ 'https://static.example/file/1'+ );+ });++ it('renders a video as a preview', () => {+ const { getByTestId } = render(() => (+ <AttachmentPart+ part={attachment({ name: 'clip.mp4', mimeType: 'video/mp4' })}+ />+ ));+ expect(getByTestId('media-video').getAttribute('src')).toBe(+ 'https://static.example/file/1'+ );+ });++ it('renders anything else as a named chip that opens the file', () => {+ const { getByTestId, container } = render(() => (+ <AttachmentPart+ part={attachment({ name: 'notes.pdf', mimeType: 'application/pdf' })}+ />+ ));+ expect(container.textContent).toContain('notes.pdf');+ expect(getByTestId('entity-icon').getAttribute('data-type')).toBe('pdf');+ const link = container.querySelector('a');+ expect(link?.getAttribute('href')).toBe('https://static.example/file/1');+ expect(link?.getAttribute('target')).toBe('_blank');+ });+});diff --git a/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsxnew file mode 100644index 0000000000..1710ebba8f--- /dev/null+++ b/apps/web/src/features/block-agent/component/parts/AttachmentPart.tsx@@ -0,0 +1,93 @@+/**+ * A file the user attached to their prompt. Images and videos render as the+ * channel composer's media thumbnails; anything else is a chip that opens+ * the file. The fold hands over a URL, never bytes, so this is a plain+ * fetch from the static file service.+ */++import { getAttachmentKindFromFile } from '@channel/Input/utils/file-helpers';+import { MediaImage } from '@channel/Media/MediaImage';+import { MediaVideo } from '@channel/Media/MediaVideo';+import { EntityIcon } from '@core/component/EntityIcon';+import { fileTypeToBlockName } from '@core/constant/allBlocks';+import { staticFileSizedUrl } from '@core/constant/servers';+import type { MessagePart } from '@service-agent-fold/generated/types';+import { Match, Switch } from 'solid-js';++type AttachmentPartData = Extract<MessagePart, { kind: 'attachment' }>;++/**+ * `image`, `video`, or `file`, from the media type and then the name.+ *+ * The same classifier the composer's chips use, so a file renders the same+ * way before and after it is sent - a browser that reported no media type+ * for `shot.png` must not turn a thumbnail into a chip.+ */+export function attachmentMedium(part: {+ mimeType: string | null;+ name: string;+}): 'image' | 'video' | 'file' {+ const kind = getAttachmentKindFromFile({+ name: part.name,+ mimeType: part.mimeType ?? undefined,+ });+ return kind === 'document' ? 'file' : kind;+}++function fileExtension(name: string): string | undefined {+ const extension = name.split('.').pop()?.toLowerCase();+ if (!extension || extension === name.toLowerCase()) return undefined;+ return extension;+}++export function AttachmentPart(props: { part: AttachmentPartData }) {+ const medium = () => attachmentMedium(props.part);++ return (+ <div class="ph-no-capture my-1 first:mt-0 last:mb-0" data-attachment-part>+ <Switch>+ <Match when={medium() === 'image'}>+ <a href={props.part.uri} target="_blank" rel="noreferrer">+ <MediaImage.Root>+ <MediaImage.Image+ src={staticFileSizedUrl(props.part.uri, 'medium')}+ class="max-h-64 max-w-full select-none rounded-lg border border-edge object-contain"+ loading="lazy"+ fallback={<MediaImage.Fallback square />}+ />+ </MediaImage.Root>+ </a>+ </Match>+ <Match when={medium() === 'video'}>+ <a href={props.part.uri} target="_blank" rel="noreferrer">+ <MediaVideo.Root class="group max-h-64 overflow-hidden border border-edge bg-surface">+ <MediaVideo.Preview+ src={props.part.uri}+ class="max-h-64 max-w-full object-contain"+ />+ <MediaVideo.PlayOverlay />+ </MediaVideo.Root>+ </a>+ </Match>+ <Match when={medium() === 'file'}>+ <a+ href={props.part.uri}+ target="_blank"+ rel="noreferrer"+ class="inline-flex max-w-full items-center gap-1.5 rounded-xs border border-edge-muted px-2 py-1 text-sm hover:bg-hover hover-transition-bg"+ title={props.part.name}+ >+ <EntityIcon+ targetType={fileTypeToBlockName(+ fileExtension(props.part.name),+ true+ )}+ size="xs"+ />+ <span class="truncate">{props.part.name}</span>+ </a>+ </Match>+ </Switch>+ </div>+ );+}diff --git a/apps/web/src/features/block-agent/component/prompt-action.test.ts b/apps/web/src/features/block-agent/component/prompt-action.test.tsnew file mode 100644index 0000000000..c8b15e6478--- /dev/null+++ b/apps/web/src/features/block-agent/component/prompt-action.test.ts@@ -0,0 +1,55 @@+/**+ * The composer's prompt action: what the draft and its chips become on the+ * wire. This is the contract `create-composer-controller.test.ts` covered+ * before #6518 moved sending onto the session's `issue`.+ */++import { describe, expect, it } from 'vitest';+import { promptActionOf } from './prompt-action';++const uploaded = {+ id: 'file-1',+ name: 'screenshot.png',+ kind: 'image' as const,+ mimeType: 'image/png',+ size: 2048,+};++describe('the prompt action', () => {+ it('carries the attached files alongside the text', () => {+ expect(promptActionOf('look', [uploaded])).toEqual({+ type: 'prompt',+ prompt: 'look',+ attachments: [+ {+ uri: expect.stringContaining('file-1'),+ name: 'screenshot.png',+ mimeType: 'image/png',+ size: 2048,+ },+ ],+ });+ });++ it('omits the field entirely when nothing is attached', () => {+ expect(promptActionOf('look', [])).toEqual({+ type: 'prompt',+ prompt: 'look',+ });+ });++ it('leaves out a file that is still uploading', () => {+ expect(promptActionOf('look', [{ ...uploaded, pending: true }])).toEqual({+ type: 'prompt',+ prompt: 'look',+ });+ });++ it('sends attachments with no text at all', () => {+ const action = promptActionOf('', [uploaded]);+ expect(action).toMatchObject({ type: 'prompt', prompt: '' });+ expect(+ 'attachments' in action ? action.attachments : undefined+ ).toHaveLength(1);+ });+});diff --git a/apps/web/src/features/block-agent/component/prompt-action.ts b/apps/web/src/features/block-agent/component/prompt-action.tsnew file mode 100644index 0000000000..79f46b85c5--- /dev/null+++ b/apps/web/src/features/block-agent/component/prompt-action.ts@@ -0,0 +1,48 @@+/**+ * The composer's prompt action: what a draft and its attachment chips become+ * on the wire.+ *+ * Kept apart from the composer component so the shape can be tested without+ * standing up the session context the component reads.+ */++import type { InputAttachmentData } from '@channel/Input';+import { staticFileIdEndpoint } from '@core/constant/servers';+import type {+ AgentPromptAction,+ PromptAttachment,+} from '@service-agent-harness/generated/schemas';++/**+ * The prompt attachment for an uploaded file: the static file service URL+ * the agent fetches it from, plus what the chip knew about it.+ */+function promptAttachmentOf(attachment: InputAttachmentData): PromptAttachment {+ return {+ uri: staticFileIdEndpoint(attachment.id),+ name: attachment.name,+ ...(attachment.mimeType ? { mimeType: attachment.mimeType } : {}),+ ...(attachment.size !== undefined ? { size: attachment.size } : {}),+ };+}++/**+ * The prompt action for a draft and its attachments.+ *+ * A file still uploading is left out rather than sent half-there, and with+ * nothing to send the field is omitted entirely, so a plain prompt stays the+ * shape it has always been on the wire.+ */+export function promptActionOf(+ markdown: string,+ attachments: InputAttachmentData[]+): AgentPromptAction & { type: 'prompt' } {+ const ready = attachments+ .filter((attachment) => !attachment.pending)+ .map(promptAttachmentOf);+ return {+ type: 'prompt',+ prompt: markdown,+ ...(ready.length > 0 ? { attachments: ready } : {}),+ };+}diff --git a/apps/web/src/features/block-agent/context/pending-session.ts b/apps/web/src/features/block-agent/context/pending-session.tsindex 9fe4dc846d..897e2366ec 100644--- a/apps/web/src/features/block-agent/context/pending-session.ts+++ b/apps/web/src/features/block-agent/context/pending-session.ts@@ -18,7 +18,10 @@import { markMessageSent } from '@core/util/message-send-motion';import { agentHarnessServiceClient } from '@service-agent-harness/client';-import type { CreateAgentSessionRequest } from '@service-agent-harness/generated/schemas';+import type {+ CreateAgentSessionRequest,+ PromptAttachment,+} from '@service-agent-harness/generated/schemas';import { type Accessor, createSignal } from 'solid-js';/**@@ -51,6 +54,8 @@ export type StartPendingSessionOptions = {botId?: string;/** First prompt, delivered after any model override. */prompt?: string;+ /** Uploaded SFS files delivered with the first prompt. */+ attachments?: PromptAttachment[];/** Optional model switch applied before the first prompt. */modelOverride?: string;/**@@ -106,11 +111,14 @@ export function startPendingSession(return;}}- const prompt = options.prompt?.trim();- if (prompt) {+ const prompt = options.prompt?.trim() ?? '';+ if (prompt || options.attachments?.length) {const delivered = await agentHarnessServiceClient.control(id, {type: 'prompt',prompt,+ ...(options.attachments?.length+ ? { attachments: options.attachments }+ : {}),});if (delivered.isErr()) {setError(diff --git a/apps/web/src/features/block-agent/context/resolve-session-id.test.ts b/apps/web/src/features/block-agent/context/resolve-session-id.test.tsindex de85ec6f08..6cd51efb2c 100644--- a/apps/web/src/features/block-agent/context/resolve-session-id.test.ts+++ b/apps/web/src/features/block-agent/context/resolve-session-id.test.ts@@ -172,3 +172,28 @@ describe('a placeholder', () => {});});});++it.each(['Describe this', ''])(+ 'delivers first-prompt attachments with text %j',+ async (prompt) => {+ create.control.mockResolvedValue({+ isErr: () => false,+ value: { actionId: 'image-action', status: 'accepted' },+ });+ const attachments = [+ {+ uri: 'https://static.macro.com/file/image-id',+ name: 'pasted.png',+ mimeType: 'image/png',+ },+ ];+ startPendingSession({ prompt, attachments });+ create.resolve?.('session-image');+ await flush();+ expect(create.control).toHaveBeenCalledWith('session-image', {+ type: 'prompt',+ prompt,+ attachments,+ });+ }+);diff --git a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx b/apps/web/src/features/block-agent/ui/AgentInput.test.tsxindex a74a31a54a..3b609da0e8 100644--- a/apps/web/src/features/block-agent/ui/AgentInput.test.tsx+++ b/apps/web/src/features/block-agent/ui/AgentInput.test.tsx@@ -10,9 +10,9 @@ import {* @vitest-environment jsdom*/-import { fireEvent, render, screen } from '@solidjs/testing-library';+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';import { beforeEach, describe, expect, it, vi } from 'vitest';-import { AgentInput } from './AgentInput';+import { AGENT_INPUT_TEXT_AREA_ID, AgentInput } from './AgentInput';const editor = vi.hoisted(() => ({lexical: undefined as LexicalEditor | undefined,@@ -36,6 +36,7 @@ vi.mock(withCode: () => builder,withRestoreFocus: () => builder,withAgentCommands: () => builder,+ withFilePaste: () => builder,onEnter: (callback: () => boolean) => {editor.enter = callback;return builder;@@ -60,6 +61,27 @@ vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({MarkdownShell: () => <div data-testid="agent-input-editor" />,}));+// The channel composer's chips and drop zone reach the block registry (and+// through it the chat input's storage module) on import; the composer's own+// send/attach logic is what is under test, so they are stubs that surface+// what this component hands them.+vi.mock('@channel/Input/context', () => ({+ InputProvider: (props: { children: unknown }) => props.children,+}));+vi.mock('@channel/Input/Input', () => ({+ Input: {+ DropZone: (props: { children: unknown }) => props.children,+ DropOverlay: () => null,+ Attachments: () => null,+ AttachFilesAction: () => (+ <button type="button" aria-label="Attach files">+ attach+ </button>+ ),+ },+}));+vi.mock('@core/util/upload', () => ({ handleFileFolderDrop: vi.fn() }));+vi.mock('@phosphor/arrow-up.svg', () => ({default: () => <span data-testid="send-icon" />,}));@@ -120,11 +142,46 @@ describe('queued message advancement', () => {editor.change?.(' another request ');editor.enter?.();- expect(onSend).toHaveBeenCalledWith('another request');+ expect(onSend).toHaveBeenCalledWith('another request', []);expect(onStop).not.toHaveBeenCalled();expect(editor.clear).toHaveBeenCalledOnce();});+ it('sends attached files instead of advancing past them', () => {+ const onSend = vi.fn();+ const onStop = vi.fn();+ const uploaded = {+ id: 'file-1',+ name: 'screenshot.png',+ kind: 'image' as const,+ mimeType: 'image/png',+ size: 2048,+ };++ render(() => (+ <AgentInput+ busy+ hasQueuedMessages+ onSend={onSend}+ onStop={onStop}+ attachments={[uploaded]}+ onAttachFiles={vi.fn()}+ />+ ));++ // Attached files are a draft, so this is the typed-text case: Enter sends+ // them, and the control is Stop rather than the send-next Enter action,+ // which would have stopped the agent and left the files behind.+ expect(+ screen.queryByRole('button', { name: 'Send next queued message' })+ ).toBeNull();+ expect(screen.getByRole('button', { name: 'Stop' })).toBeTruthy();++ editor.enter?.();+ expect(onSend).toHaveBeenCalledWith('', [uploaded]);+ expect(onStop).not.toHaveBeenCalled();+ });+it('keeps Enter inert when there is no queued message or draft', () => {const onStop = vi.fn();@@ -136,6 +193,85 @@ describe('queued message advancement', () => {});});+describe('attachments', () => {+ const uploaded = {+ id: 'file-1',+ name: 'screenshot.png',+ kind: 'image' as const,+ mimeType: 'image/png',+ size: 2048,+ };++ it('sends attached files with no text at all', () => {+ const onSend = vi.fn();++ render(() => (+ <AgentInput+ onSend={onSend}+ attachments={[uploaded]}+ onAttachFiles={vi.fn()}+ />+ ));++ editor.enter?.();+ expect(onSend).toHaveBeenCalledWith('', [uploaded]);+ });++ it('holds the send while a file is still uploading', () => {+ const onSend = vi.fn();++ render(() => (+ <AgentInput+ onSend={onSend}+ attachments={[{ ...uploaded, pending: true }]}+ onAttachFiles={vi.fn()}+ />+ ));++ editor.change?.('look at this');+ editor.enter?.();+ expect(onSend).not.toHaveBeenCalled();+ expect(screen.getByRole('button', { name: 'Send' })).toHaveProperty(+ 'disabled',+ true+ );+ });++ it('measures the composer height above the editor row, so chips are inside it', () => {+ // The surface is pinned to the measured element's height. The attachment+ // chips render alongside the editor row, so the measured element has to be+ // their shared parent — measuring the row alone clips them. The chips come+ // from the mocked `@channel/Input` here, so this pins the measurement+ // boundary rather than the chip markup.+ const { container } = render(() => (+ <AgentInput+ onSend={vi.fn()}+ attachments={[uploaded]}+ onAttachFiles={vi.fn()}+ />+ ));++ const measured = container.querySelector('[data-composer-content]');+ const editorRow = container.querySelector('[data-composer-compact]');+ expect(measured).toBeTruthy();+ expect(editorRow).toBeTruthy();+ expect(measured).not.toBe(editorRow);+ expect(editorRow?.parentElement).toBe(measured);+ expect(+ measured?.querySelector(`#${AGENT_INPUT_TEXT_AREA_ID}`)+ ).toBeTruthy();+ });++ it('offers the paperclip only when files can be attached', () => {+ render(() => <AgentInput onSend={vi.fn()} />);+ expect(screen.queryByRole('button', { name: 'Attach files' })).toBeNull();++ cleanup();+ render(() => <AgentInput onSend={vi.fn()} onAttachFiles={vi.fn()} />);+ expect(screen.getByRole('button', { name: 'Attach files' })).toBeTruthy();+ });+});+it('expands for a short quote and collapses when replaced with a paragraph', () => {const { container } = render(() => <AgentInput onSend={vi.fn()} />);const layout = container.querySelector('[data-composer-compact]');diff --git a/apps/web/src/features/block-agent/ui/AgentInput.tsx b/apps/web/src/features/block-agent/ui/AgentInput.tsxindex b8077f5360..1c3f3c2887 100644--- a/apps/web/src/features/block-agent/ui/AgentInput.tsx+++ b/apps/web/src/features/block-agent/ui/AgentInput.tsx@@ -2,12 +2,17 @@ import { createResizeObserver } from '@solid-primitives/resize-observer';/*** The agent block's composer: the chat input's look and its markdown editing* surface (`MarkdownShell` over a lean `EditorConfigBuilder`), including `@`- * mentions so users can attach Macro items the same way they do in chat.- * Attachments, upload queue, and chat contexts stay out; model plumbing- * arrives through the `modelControl` slot. Visual chrome mirrors+ * mentions so users can attach Macro items the same way they do in chat, and+ * file attachments - drop, paste, or the paperclip - shown as the channel+ * composer's chips. Uploading itself stays out: the parent owns the+ * attachment list and hands files back through `onAttachFiles`. Model+ * plumbing arrives through the `modelControl` slot. Visual chrome mirrors* `@core/component/AI/component/input/ChatInput.tsx`.*/+import { InputProvider } from '@channel/Input/context';+import { Input } from '@channel/Input/Input';+import type { InputAttachmentData, InputCommands } from '@channel/Input/types';import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';import type { AgentCommandItem } from '@core/component/LexicalMarkdown/plugins';@@ -15,6 +20,7 @@ import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/creaimport { isMobile } from '@core/mobile/isMobile';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { useTouchOutsideToDismissKeyboard } from '@core/mobile/useTouchOutsideToDismissKeyboard';+import { handleFileFolderDrop } from '@core/util/upload';import { $insertReferencedPaste } from '@macro-inc/lexical-core';import EnterIcon from '@phosphor-icons/core/regular/arrow-bend-down-left.svg?component-solid';import { Button, ComposerSurface, SendButton } from '@ui';@@ -56,9 +62,22 @@ export interface AgentInputProps {* typing `/` opens a typeahead over them. `/` stays plain text while empty.*/commands?: () => AgentCommandItem[];- /** Receives the composed markdown, including any `<m-document-mention>` tags. */- onSend: (markdown: string) => void;+ /**+ * Receives the composed markdown, including any `<m-document-mention>`+ * tags, and the attachments as they stood when Send was pressed. Either+ * may be empty, never both.+ */+ onSend: (markdown: string, attachments: InputAttachmentData[]) => void;onStop?: () => void;+ /**+ * Files attached so far, uploaded or still uploading. Owned by the parent+ * (an `InputAttachmentTracker`), which is what lets the composer clear+ * them after a send.+ */+ attachments?: InputAttachmentData[];+ /** Files the user dropped, pasted, or picked. Absent means no attaching. */+ onAttachFiles?: (files: File[]) => void;+ onRemoveAttachment?: (attachment: InputAttachmentData) => void;/** Model control: a pill above the box on desktop, footer-left on touch. */modelControl?: JSX.Element;/**@@ -81,32 +100,65 @@ export interface AgentInputProps {export function AgentInput(props: AgentInputProps) {const [markdown, setMarkdown] = createSignal('');+ const [isDraggedOver, setIsDraggedOver] = createSignal(false);let containerRef: HTMLDivElement | undefined;const [layout, setLayout] = createSignal<HTMLDivElement>();+ const [content, setContent] = createSignal<HTMLDivElement>();const [height, setHeight] = createSignal<number>();- createResizeObserver(layout, (_, element) => {+ // The surface is pinned to its content's height, so the measured element has+ // to enclose the attachment chips as well as the editor row — they sit inside+ // the surface, and a row-only measurement clips them.+ createResizeObserver(content, (_, element) => {setHeight(element.getBoundingClientRect().height);});useTouchOutsideToDismissKeyboard(() => containerRef);+ const attachments = () => props.attachments ?? [];+ const canAttach = () => props.onAttachFiles !== undefined && !props.disabled;+ const hasPendingAttachments = () =>+ attachments().some((attachment) => attachment.pending);+ const attachFiles = (files: File[]) => {+ if (!canAttach() || files.length === 0) return;+ props.onAttachFiles?.(files);+ };+// Sending while busy is allowed — the service queues prompts behind the- // running turn.- const canSend = () => markdown().trim().length > 0 && !props.disabled;+ // running turn. A file still uploading holds the send: its URL is not+ // known yet, and the agent gets exactly what the chips show.+ const canSend = () =>+ (markdown().trim().length > 0 || attachments().length > 0) &&+ !hasPendingAttachments() &&+ !props.disabled;++ // The channel composer's chips, drop zone, and overlay read their state+ // from `Input.Root`'s context; this is that context, over this composer's+ // props. Only attaching and removing do anything - there is no channel+ // send or format ribbon behind these slots.+ const inputCommands: InputCommands = {+ send: async () => false,+ attachFiles: async (files) => attachFiles(files),+ toggleFormatRibbon: () => {},+ close: () => {},+ removeAttachment: (attachment) => props.onRemoveAttachment?.(attachment),+ };const send = () => {if (!canSend()) return;const content = markdown().trim();+ const attached = attachments();editor.controls.clear();- props.onSend(content);+ props.onSend(content, attached);};// Deliberately not gated on `busy`. A speculated stop reads as done// everywhere else, so `busy` is already false while the runtime is still// winding the turn down - and that is exactly when a waiting message is// most worth advancing. What does gate it is a stop already in flight:- // repeating it just posts another cancel for the same turn.+ // repeating it just posts another cancel for the same turn. Attached files+ // are something to send in their own right, so they hold it back too.const canSendNext = () =>markdown().trim().length === 0 &&+ attachments().length === 0 &&props.hasQueuedMessages === true &&!props.stopPending &&!props.disabled &&@@ -134,6 +186,15 @@ export function AgentInput(props: AgentInputProps) {.withCode().withRestoreFocus().withAgentCommands({ commands: () => props.commands?.() ?? [] })+ // Pasted files (and, on iOS, recovered clipboard images) become+ // attachments through the same door as a drop.+ .withFilePaste({+ onPasteFilesAndDirs: (files, directories) => {+ void handleFileFolderDrop(files, directories, (entries) =>+ attachFiles(entries.map((entry) => entry.file))+ );+ },+ }).onEnter(() => {if (canSend()) send();else sendNext();@@ -193,99 +254,144 @@ export function AgentInput(props: AgentInputProps) {};return (- <div ref={containerRef} data-keep-keyboard class="flex flex-col gap-1.5">- {/* Desktop: the model pill sits above the box, as it always has. */}- <Show when={!isTouchDevice() && props.modelControl}>- <div class="flex items-center px-0.5">{props.modelControl}</div>- </Show>- {/* h-auto beats Surface's size-full so the in-flow controls are not- clipped over the editor (that was Auto sitting on the placeholder). */}- <ComposerSurface- class="h-auto transition-[height] duration-150 ease-out motion-reduce:transition-none"- style={{ height: height() === undefined ? undefined : `${height()}px` }}- >- {/* Desktop: one row, send right of the text. Touch: the text gets- the whole width and the controls drop to a footer row (model- left, send right) — the chat-tall / channel footer shape. */}- <div- ref={setLayout}- data-composer-compact={isCompact()}- class="group/composer flex items-end data-[composer-compact=false]:flex-col data-[composer-compact=false]:items-stretch gap-[3.75px] p-[7.5px] min-h-[48.75px] touch:min-h-0 touch:flex-col touch:items-stretch touch:gap-0 touch:p-0"- onPointerDown={focusEditor}- onMouseDown={focusEditor}+ <InputProvider+ value={{+ view: () => ({+ mode: 'channel',+ attachments: attachments(),+ isDraggedOver: isDraggedOver(),+ hasPendingAttachments: hasPendingAttachments(),+ }),+ commands: inputCommands,+ }}+ >+ <div ref={containerRef} data-keep-keyboard class="flex flex-col gap-1.5">+ {/* Desktop: the model pill sits above the box, as it always has. */}+ <Show when={!isTouchDevice() && props.modelControl}>+ <div class="flex items-center px-0.5">{props.modelControl}</div>+ </Show>+ {/* h-auto beats Surface's size-full so the in-flow controls are not+ clipped over the editor (that was Auto sitting on the placeholder). */}+ <ComposerSurface+ class="h-auto transition-[height] duration-150 ease-out motion-reduce:transition-none"+ style={{+ height: height() === undefined ? undefined : `${height()}px`,+ }}>- <div- id={AGENT_INPUT_TEXT_AREA_ID}- class="min-w-0 flex-1 group-data-[composer-compact=false]/composer:flex-none text-base text-ink not-touch:px-[9.375px] not-touch:py-[4.6875px] not-touch:leading-[24.375px] not-touch:min-h-[24.375px] not-touch:text-composer-ink touch:px-3 touch:py-2"- classList={{- // While empty only the placeholder renders; keep it to one clipped- // line so it doesn't wrap into the single-line height.- 'overflow-hidden whitespace-nowrap':- markdown().trim().length === 0,- // Long drafts must not eat the mobile viewport above the dock.- 'max-h-[calc(32*var(--dvh,1dvh))] overflow-y-auto':- hasMultilineContent() && isMobile(),- }}+ <Input.DropZone+ onDragStart={(valid) => canAttach() && setIsDraggedOver(valid)}+ onDragEnd={() => setIsDraggedOver(false)}>- <ComposerEditor- config={editor}- placeholder={- props.placeholder ?? 'Message the agent, @mention anything'- }- autofocus={!isMobile() && !isTouchDevice() && props.autofocus}- />- </div>-- {/* In-flow — never absolute over the text. */}- <div class="flex shrink-0 items-center gap-[3.75px] touch:h-8 touch:gap-2 touch:p-2 touch:mb-2">- <Show when={isTouchDevice() && props.modelControl}>- <div class="min-w-0">{props.modelControl}</div>+ <Show when={canAttach()}>+ {/* Matches ComposerSurface's own radius so the overlay's rim+ sits on the composer's edge, not inside it. */}+ <Input.DropOverlay+ class="rounded-[26.25px] touch:rounded-3xl"+ hint="Drop files here to send them to the agent"+ /></Show>- <div class="ml-auto shrink-0">- <Show- when={canSendNext()}- fallback={- <Show- when={props.busy && props.onStop}- fallback={- <SendButton- appearance="composer"- tooltip="Send"- disabled={!canSend()}- onClick={send}- />+ <div ref={setContent} data-composer-content>+ {/* Chips above the text, media and documents in their own rows,+ exactly as the channel composer lays them out. */}+ <Input.Attachments kind="media" class="pb-0" />+ <Input.Attachments kind="document" class="pb-0" />+ {/* Desktop: one row, send right of the text. Touch: the text gets+ the whole width and the controls drop to a footer row (model+ left, send right) — the chat-tall / channel footer shape. */}+ <div+ ref={setLayout}+ data-composer-compact={isCompact()}+ class="group/composer flex items-end data-[composer-compact=false]:flex-col data-[composer-compact=false]:items-stretch gap-[3.75px] p-[7.5px] min-h-[48.75px] touch:min-h-0 touch:flex-col touch:items-stretch touch:gap-0 touch:p-0"+ onPointerDown={focusEditor}+ onMouseDown={focusEditor}+ >+ <div+ id={AGENT_INPUT_TEXT_AREA_ID}+ class="min-w-0 flex-1 group-data-[composer-compact=false]/composer:flex-none text-base text-ink not-touch:px-[9.375px] not-touch:py-[4.6875px] not-touch:leading-[24.375px] not-touch:min-h-[24.375px] not-touch:text-composer-ink touch:px-3 touch:py-2"+ classList={{+ // While empty only the placeholder renders; keep it to one clipped+ // line so it doesn't wrap into the single-line height.+ 'overflow-hidden whitespace-nowrap':+ markdown().trim().length === 0,+ // Long drafts must not eat the mobile viewport above the dock.+ 'max-h-[calc(32*var(--dvh,1dvh))] overflow-y-auto':+ hasMultilineContent() && isMobile(),+ }}+ >+ <ComposerEditor+ config={editor}+ placeholder={+ props.placeholder ??+ 'Message the agent, @mention anything'}- >- <Button- variant={isTouchDevice() ? 'ghost' : 'strong'}- size="icon-composer"- label="Stop"- onClick={() => props.onStop?.()}- class={- isTouchDevice()- ? 'rounded-full size-7.5 text-ink-extra-muted not-disabled:bg-ink/5 not-disabled:hover:bg-ink/10'- : undefined+ autofocus={+ !isMobile() && !isTouchDevice() && props.autofocus+ }+ />+ </div>++ {/* In-flow — never absolute over the text. */}+ <div class="flex shrink-0 items-center gap-[3.75px] touch:h-8 touch:gap-2 touch:p-2 touch:mb-2">+ <Show when={isTouchDevice() && props.modelControl}>+ <div class="min-w-0">{props.modelControl}</div>+ </Show>+ <Show when={props.onAttachFiles}>+ {/* The picker accepts whatever the drop zone does: an+ agent's reason to attach a file is usually a source+ file, and the static upload stores any type. */}+ <Input.AttachFilesAction+ accept={null}+ disabled={props.disabled}+ />+ </Show>+ <div class="ml-auto shrink-0">+ <Show+ when={canSendNext()}+ fallback={+ <Show+ when={props.busy && props.onStop}+ fallback={+ <SendButton+ appearance="composer"+ tooltip="Send"+ disabled={!canSend()}+ onClick={send}+ />+ }+ >+ <Button+ variant={isTouchDevice() ? 'ghost' : 'strong'}+ size="icon-composer"+ label="Stop"+ onClick={() => props.onStop?.()}+ class={+ isTouchDevice()+ ? 'rounded-full size-7.5 text-ink-extra-muted not-disabled:bg-ink/5 not-disabled:hover:bg-ink/10'+ : undefined+ }+ >+ <div class="size-3.5 not-touch:size-[13.125px] rounded-sm bg-current" />+ </Button>+ </Show>}>- <div class="size-3.5 not-touch:size-[13.125px] rounded-sm bg-current" />- </Button>- </Show>- }- >- <SendButton- appearance="composer"- aria-label="Send next queued message"- tooltip="Send next queued message"- shortcut="Enter"- onClick={sendNext}- >- <EnterIcon />- </SendButton>- </Show>+ <SendButton+ appearance="composer"+ aria-label="Send next queued message"+ tooltip="Send next queued message"+ shortcut="Enter"+ onClick={sendNext}+ >+ <EnterIcon />+ </SendButton>+ </Show>+ </div>+ </div>+ </div></div>- </div>- </div>- </ComposerSurface>- </div>+ </Input.DropZone>+ </ComposerSurface>+ </div>+ </InputProvider>);}diff --git a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsxindex 8dc7cae991..22bdfa3065 100644--- a/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx+++ b/apps/web/src/features/block-agent/ui/QueuedPrompts.tsx@@ -32,6 +32,8 @@ export type QueuedPromptItem = {kind: string;/** The prompt's raw text, absent for a compact. */prompt?: string;+ /** Files the prompt refers to; an edit keeps them, only the text changes. */+ attachments?: { name: string; mimeType?: string | null }[];/** Who queued it, when it was somebody other than the current user. */queuedBy?: string;};@@ -234,6 +236,22 @@ function PromptBody(props: QueuedRowProps) {return (<div class="text-sm text-ink" onFocusOut={flush}><MarkdownShell config={editor} initialValue={props.item.prompt} />+ {/* Attached files ride the prompt as-is: an edit rewrites the text and+ keeps them, so they are shown but not editable here. */}+ <Show when={props.item.attachments?.length}>+ <div+ class="flex flex-wrap gap-1 pt-1 text-xs text-ink-muted"+ data-testid="agent-queued-attachments"+ >+ <For each={props.item.attachments}>+ {(attachment) => (+ <span class="rounded-xs border border-edge-muted px-1.5 py-0.5">+ {attachment.name}+ </span>+ )}+ </For>+ </div>+ </Show></div>);}diff --git a/apps/web/src/features/channel/Input/ActionButton.tsx b/apps/web/src/features/channel/Input/ActionButton.tsxindex f344f72a39..ad765e9faa 100644--- a/apps/web/src/features/channel/Input/ActionButton.tsx+++ b/apps/web/src/features/channel/Input/ActionButton.tsx@@ -5,6 +5,7 @@ export function InputActionButton(props: {label: string;onClick?: (event: MouseEvent) => void;active?: boolean;+ disabled?: boolean;class?: string;children: JSX.Element;}) {@@ -12,6 +13,7 @@ export function InputActionButton(props: {<Buttonaria-label={props.label}label={props.label}+ disabled={props.disabled}variant={props.active ? 'accent' : 'ghost'}size="icon-composer"class={cn('rounded-full touch:size-6', props.class)}diff --git a/apps/web/src/features/channel/Input/InputActions.tsx b/apps/web/src/features/channel/Input/InputActions.tsxindex 03c6247cba..045c1d4352 100644--- a/apps/web/src/features/channel/Input/InputActions.tsx+++ b/apps/web/src/features/channel/Input/InputActions.tsx@@ -7,7 +7,17 @@ import { InputActionButton } from './ActionButton';import { CHANNEL_FILE_PICKER_ACCEPT } from './accepted-file-types';import { useInput, useInputCommands } from './context';-export function AttachFilesAction() {+/**+ * The paperclip.+ *+ * `accept` narrows the picker, defaulting to the channel's own media and+ * document types. A surface whose upload path takes more than that — the+ * agent composer, where a source file is usually the point — passes `null`+ * to accept whatever it would accept on a drop.+ */+export function AttachFilesAction(+ props: { accept?: string | null; disabled?: boolean } = {}+) {const commands = useInputCommands();let fileInputRef: HTMLInputElement | undefined;@@ -29,12 +39,18 @@ export function AttachFilesAction() {type="file"class="hidden"multiple- accept={CHANNEL_FILE_PICKER_ACCEPT}+ accept={+ props.accept === null+ ? undefined+ : (props.accept ?? CHANNEL_FILE_PICKER_ACCEPT)+ }onChange={onAttachFiles}+ disabled={props.disabled}data-input-attach-file-picker/><InputActionButtonlabel="Attach files"+ disabled={props.disabled}onClick={() => fileInputRef?.click()}><PaperclipIcon />diff --git a/apps/web/src/features/channel/Input/tests/upload-attachments.test.ts b/apps/web/src/features/channel/Input/tests/upload-attachments.test.tsindex ece43aa816..c8340ab100 100644--- a/apps/web/src/features/channel/Input/tests/upload-attachments.test.ts+++ b/apps/web/src/features/channel/Input/tests/upload-attachments.test.ts@@ -102,6 +102,8 @@ describe('uploadInputAttachments', () => {id: 'uploaded-image-1',name: 'image.png',kind: 'image',+ mimeType: 'image/png',+ size: 3,previewSrc: 'blob:attachment-preview',},]);@@ -163,6 +165,8 @@ describe('uploadInputAttachments', () => {id: media.uploadedId,name: media.name,kind: media.kind,+ mimeType: media.mimeType,+ size: 3,width: 1920,height: 1080,previewSrc: 'blob:attachment-preview',@@ -210,6 +214,8 @@ describe('uploadInputAttachments', () => {name: 'manual',kind: 'document',iconType: 'pdf',+ mimeType: 'application/pdf',+ size: 3,},]);});diff --git a/apps/web/src/features/channel/Input/types.ts b/apps/web/src/features/channel/Input/types.tsindex 30d64fcd79..48f4257e1d 100644--- a/apps/web/src/features/channel/Input/types.ts+++ b/apps/web/src/features/channel/Input/types.ts@@ -20,6 +20,10 @@ export type InputAttachmentData = {width?: number;/** Image/video height in pixels (set after upload). */height?: number;+ /** The uploaded file's media type, as the browser reported it. */+ mimeType?: string;+ /** The uploaded file's size in bytes. */+ size?: number;};export type InputPersistenceKey = PersistenceKey;diff --git a/apps/web/src/features/channel/Input/upload-attachments.ts b/apps/web/src/features/channel/Input/upload-attachments.tsindex bf563e12b9..0e9f8d1fac 100644--- a/apps/web/src/features/channel/Input/upload-attachments.ts+++ b/apps/web/src/features/channel/Input/upload-attachments.ts@@ -118,6 +118,8 @@ export async function uploadInputAttachments(options: {if (previewSrc && uploaded.kind !== 'document') {uploaded.previewSrc = previewSrc;}+ if (file.type) uploaded.mimeType = file.type;+ uploaded.size = file.size;if (dimensions) {uploaded.width = dimensions.width;uploaded.height = dimensions.height;diff --git a/apps/web/src/features/channel/Input/utils/file-helpers.ts b/apps/web/src/features/channel/Input/utils/file-helpers.tsindex 53ffcdf6b1..6178139689 100644--- a/apps/web/src/features/channel/Input/utils/file-helpers.ts+++ b/apps/web/src/features/channel/Input/utils/file-helpers.ts@@ -76,10 +76,17 @@ export function buildUploadedAttachment(result: UploadSuccess): InputAttachmentData | undefined {if (result.destination === 'static') {+ // A static upload keeps the kind the file was classified as: channels+ // only send media here, but the agent composer sends every file, and a+ // PDF stored as a static file is still a document chip.return {id: result.id,name: file.name,- kind: pendingKind === 'video' ? 'video' : 'image',+ kind: pendingKind,+ iconType:+ pendingKind === 'document'+ ? iconTypeFromFilename(file.name)+ : undefined,};}diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.tsindex c6164891de..67bf8298f8 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.ts+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MagicChip/presentation.ts@@ -149,87 +149,98 @@ function toolActivity(}function partActivity(part: MessagePart): MagicChipActivity {- return match(part)- .with({ kind: 'text' }, () => ({ label: 'Writing response', busy: false }))- .with({ kind: 'thought' }, ({ text }) => ({- label: 'Thinking',- detail: text.trim() || undefined,- busy: true,- }))- .with({ kind: 'tool_use' }, toolActivity)- .with({ kind: 'permission', outcome: { kind: 'cancelled' } }, () => ({- label: 'Permission cancelled',- busy: false,- }))- .with({ kind: 'permission', outcome: { kind: 'selected' } }, () => ({- label: 'Resuming work',- busy: true,- }))- .with({ kind: 'permission', outcome: { kind: 'pending' } }, () => ({- label: 'Permission needed',- busy: false,- }))- .with({ kind: 'permission', outcome: { kind: 'errored' } }, () => ({- label: 'Permission failed',- busy: false,- }))- .with({ kind: 'permission', outcome: { kind: 'unrecognized' } }, () => ({- label: 'Permission unavailable',- busy: false,- }))- .with({ kind: 'control', control: { kind: 'set_model' } }, (part) => ({- label: 'Model changed',- detail: part.control.model,- busy: false,- }))- .with({ kind: 'control', control: { kind: 'compact' } }, () => ({- label: 'Context compacted',- busy: false,- }))- .with({ kind: 'control', control: { kind: 'stop' } }, () => ({- label: 'Stop requested',- busy: false,- }))- .with({ kind: 'elicitation', outcome: { kind: 'pending' } }, () => ({- label: 'Waiting for your input',- busy: false,- }))- .with({ kind: 'elicitation', outcome: { kind: 'accepted' } }, () => ({- label: 'Resuming work',- busy: true,- }))- .with({ kind: 'elicitation', outcome: { kind: 'completed' } }, () => ({- label: 'Resuming work',- busy: true,- }))- .with({ kind: 'elicitation', outcome: { kind: 'declined' } }, () => ({- label: 'Question declined',- busy: true,- }))- .with({ kind: 'elicitation', outcome: { kind: 'cancelled' } }, () => ({- label: 'Question cancelled',- busy: false,- }))- .with({ kind: 'elicitation', outcome: { kind: 'errored' } }, () => ({- label: 'Question refused',- busy: false,- }))- .with({ kind: 'elicitation', outcome: { kind: 'unrecognized' } }, () => ({- label: 'Question answered',- busy: true,- }))- .with({ kind: 'plan' }, ({ entries }) => {- const completed = entries.filter(- (entry) => entry.status === 'completed'- ).length;- const current = entries.find((entry) => entry.status === 'in_progress');- return {- label: `Todos ${completed}/${entries.length}`,- detail: current?.content,- busy: completed < entries.length,- };- })- .exhaustive();+ return (+ match(part)+ .with({ kind: 'text' }, () => ({+ label: 'Writing response',+ busy: false,+ }))+ // A user's part, never an agent's; here only so the match stays total.+ .with({ kind: 'attachment' }, ({ name }) => ({+ label: 'File attached',+ detail: name,+ busy: false,+ }))+ .with({ kind: 'thought' }, ({ text }) => ({+ label: 'Thinking',+ detail: text.trim() || undefined,+ busy: true,+ }))+ .with({ kind: 'tool_use' }, toolActivity)+ .with({ kind: 'permission', outcome: { kind: 'cancelled' } }, () => ({+ label: 'Permission cancelled',+ busy: false,+ }))+ .with({ kind: 'permission', outcome: { kind: 'selected' } }, () => ({+ label: 'Resuming work',+ busy: true,+ }))+ .with({ kind: 'permission', outcome: { kind: 'pending' } }, () => ({+ label: 'Permission needed',+ busy: false,+ }))+ .with({ kind: 'permission', outcome: { kind: 'errored' } }, () => ({+ label: 'Permission failed',+ busy: false,+ }))+ .with({ kind: 'permission', outcome: { kind: 'unrecognized' } }, () => ({+ label: 'Permission unavailable',+ busy: false,+ }))+ .with({ kind: 'control', control: { kind: 'set_model' } }, (part) => ({+ label: 'Model changed',+ detail: part.control.model,+ busy: false,+ }))+ .with({ kind: 'control', control: { kind: 'compact' } }, () => ({+ label: 'Context compacted',+ busy: false,+ }))+ .with({ kind: 'control', control: { kind: 'stop' } }, () => ({+ label: 'Stop requested',+ busy: false,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'pending' } }, () => ({+ label: 'Waiting for your input',+ busy: false,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'accepted' } }, () => ({+ label: 'Resuming work',+ busy: true,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'completed' } }, () => ({+ label: 'Resuming work',+ busy: true,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'declined' } }, () => ({+ label: 'Question declined',+ busy: true,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'cancelled' } }, () => ({+ label: 'Question cancelled',+ busy: false,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'errored' } }, () => ({+ label: 'Question refused',+ busy: false,+ }))+ .with({ kind: 'elicitation', outcome: { kind: 'unrecognized' } }, () => ({+ label: 'Question answered',+ busy: true,+ }))+ .with({ kind: 'plan' }, ({ entries }) => {+ const completed = entries.filter(+ (entry) => entry.status === 'completed'+ ).length;+ const current = entries.find((entry) => entry.status === 'in_progress');+ return {+ label: `Todos ${completed}/${entries.length}`,+ detail: current?.content,+ busy: completed < entries.length,+ };+ })+ .exhaustive()+ );}/** How the turn ended, when it has — every ending but a clean answer. */diff --git a/apps/web/src/lib/queries/agent-session/control.ts b/apps/web/src/lib/queries/agent-session/control.tsnew file mode 100644index 0000000000..0cd92b5a7c--- /dev/null+++ b/apps/web/src/lib/queries/agent-session/control.ts@@ -0,0 +1,57 @@+/**+ * Control actions on a live agent session: prompt, stop, model change.+ *+ * One mutation for the one endpoint. The service owns ordering (a prompt+ * posted mid-turn waits in the session's server-side queue), so there is no+ * optimistic cache to maintain here; what the caller gets back is the+ * accepted action's id, which the fold stamps as `requestId` on the folded+ * message the action derives.+ */++import { throwOnErr } from '@core/util/result';+import { type MutationCallbacks, withCallbacks } from '@queries/utils';+import { agentHarnessServiceClient } from '@service-agent-harness/client';+import type {+ ControlRequest,+ ControlResponse,+} from '@service-agent-harness/generated/schemas';+import { useMutation } from '@tanstack/solid-query';++/** One control POST: the session it targets and the action it carries. */+export type AgentSessionControlVars = {+ sessionId: string;+ action: ControlRequest;+};++/** The shape a caller uses to issue control actions, mutation or fake. */+export type AgentSessionControl = (+ vars: AgentSessionControlVars+) => Promise<ControlResponse>;++/**+ * Post a control action to an agent session.+ *+ * `gcTime: 0`: nothing reads a finished control back out of the cache, so+ * there is no reason to hold it. Failures reject (`throwOnErr`), which is how+ * `mutateAsync` reports them to the composer.+ */+export function useAgentSessionControlMutation(+ callbacks?: MutationCallbacks<+ ControlResponse,+ Error,+ AgentSessionControlVars,+ unknown+ >+) {+ return useMutation(() => ({+ gcTime: 0,+ mutationFn: async ({ sessionId, action }: AgentSessionControlVars) =>+ await throwOnErr(() =>+ agentHarnessServiceClient.control(sessionId, action)+ ),+ ...withCallbacks<ControlResponse, Error, AgentSessionControlVars, unknown>(+ {},+ callbacks+ ),+ }));+}diff --git a/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts b/apps/web/src/lib/service-clients/service-agent-fold/generated/types.tsindex a5db47fb5c..a617d2cf84 100644--- a/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts+++ b/apps/web/src/lib/service-clients/service-agent-fold/generated/types.ts@@ -508,6 +508,28 @@ export type MessagePart =/** The prose. */text: string;}+ /**+ * A file the user attached to their prompt, by where it can be fetched.+ *+ * Read off the prompt's `resource_link` blocks - the only shape this+ * side sends files in, since bytes never ride the log. Rendering decides+ * from `mime_type` whether that is a thumbnail or a chip.+ */+ | {+ kind: 'attachment';+ /** Where the file can be fetched - a static file service URL. */+ uri: string;+ /** Display name, typically the original file name. */+ name: string;+ /** The file's media type, when the sender knew it. */+ mimeType: string | null;+ /**+ * Size in bytes, when the sender knew it. A double on the wire:+ * specta refuses 64-bit integers, and no file this renders is+ * anywhere near the precision limit.+ */+ size: number | null;+ }/** The agent's reasoning, which a reader may want to hide by default. */| {kind: 'thought';diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/agentPromptAction.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/agentPromptAction.tsindex 4f71abbf0f..e34a6ce8b3 100644--- a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/agentPromptAction.ts+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/agentPromptAction.ts@@ -4,11 +4,15 @@* agent_harness_service* OpenAPI spec version: 0.1.0*/+import type { PromptAttachment } from './promptAttachment';/*** Ask the agent to work on something.*/export interface AgentPromptAction {+ /** Files the prompt refers to, in the order the user attached them.+Delivered after the text as one `resource_link` block each. */+ attachments?: PromptAttachment[];/** What to tell the agent. */prompt: string;}diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/index.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/index.tsindex 729a5ab766..3f6f4dcb81 100644--- a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/index.ts+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/index.ts@@ -111,6 +111,9 @@ export * from './messageParentOneOfType';export * from './modelHarnessDto';export * from './previewAgentSessionsRequest';export * from './previewAgentSessionsResponse';+export * from './promptAttachment';+export * from './promptAttachmentMimeType';+export * from './promptAttachmentSize';export * from './queuedActionDto';export * from './queuedActionDtoActorUserId';export * from './queuedActionDtoPrompt';diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachment.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachment.tsnew file mode 100644index 0000000000..818952a46c--- /dev/null+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachment.ts@@ -0,0 +1,29 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * agent_harness_service+ * OpenAPI spec version: 0.1.0+ */+import type { PromptAttachmentMimeType } from './promptAttachmentMimeType';+import type { PromptAttachmentSize } from './promptAttachmentSize';++/**+ * A file the prompt refers to, by where the agent can fetch it.++Mirrors ACP's `resource_link` content block, which every agent must+accept: bytes never ride the prompt, only a URI (a static file service URL+in practice) with enough metadata for a client to render a chip and for+the agent to decide whether to fetch it. Keeping the wire shape ACP-native+means the harness translates without resolving anything, and the fold+reads the same fields back off the logged frame.+ */+export interface PromptAttachment {+ /** The file's media type, when known. */+ mimeType?: PromptAttachmentMimeType;+ /** Display name, typically the original file name. */+ name: string;+ /** Size in bytes, when known. */+ size?: PromptAttachmentSize;+ /** Where the agent can fetch the file. */+ uri: string;+}diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentMimeType.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentMimeType.tsnew file mode 100644index 0000000000..5eb25c253e--- /dev/null+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentMimeType.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * agent_harness_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * The file's media type, when known.+ */+export type PromptAttachmentMimeType = string | null;diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentSize.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentSize.tsnew file mode 100644index 0000000000..d1b2b1198b--- /dev/null+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/promptAttachmentSize.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * agent_harness_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Size in bytes, when known.+ */+export type PromptAttachmentSize = number | null;diff --git a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/queuedActionDto.ts b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/queuedActionDto.tsindex 17e2552273..165a2e5f33 100644--- a/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/queuedActionDto.ts+++ b/apps/web/src/lib/service-clients/service-agent-harness/generated/schemas/queuedActionDto.ts@@ -5,6 +5,7 @@* OpenAPI spec version: 0.1.0*/import type { AgentActionId } from './agentActionId';+import type { PromptAttachment } from './promptAttachment';import type { QueuedActionDtoActorUserId } from './queuedActionDtoActorUserId';import type { QueuedActionDtoPrompt } from './queuedActionDtoPrompt';@@ -18,6 +19,9 @@ export interface QueuedActionDto {actionId: AgentActionId;/** The user who queued it, absent when a bot acted on nobody's behalf. */actorUserId?: QueuedActionDtoActorUserId;+ /** Files the prompt refers to, for prompts only. Kept through an edit,+which replaces the text alone. */+ attachments?: PromptAttachment[];/** When it was accepted. */createdAt: string;/** What kind of action waits - `prompt` or `compact`; onlydiff --git a/apps/web/src/lib/service-clients/service-agent-harness/openapi.json b/apps/web/src/lib/service-clients/service-agent-harness/openapi.jsonindex 0e62286fae..2b5ff0358f 100644--- a/apps/web/src/lib/service-clients/service-agent-harness/openapi.json+++ b/apps/web/src/lib/service-clients/service-agent-harness/openapi.json@@ -1203,6 +1203,13 @@"description": "Ask the agent to work on something.","required": ["prompt"],"properties": {+ "attachments": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/PromptAttachment"+ },+ "description": "Files the prompt refers to, in the order the user attached them.\nDelivered after the text as one `resource_link` block each."+ },"prompt": {"type": "string","description": "What to tell the agent."@@ -1992,6 +1999,30 @@}}},+ "PromptAttachment": {+ "type": "object",+ "description": "A file the prompt refers to, by where the agent can fetch it.\n\nMirrors ACP's `resource_link` content block, which every agent must\naccept: bytes never ride the prompt, only a URI (a static file service URL\nin practice) with enough metadata for a client to render a chip and for\nthe agent to decide whether to fetch it. Keeping the wire shape ACP-native\nmeans the harness translates without resolving anything, and the fold\nreads the same fields back off the logged frame.",+ "required": ["uri", "name"],+ "properties": {+ "mimeType": {+ "type": ["string", "null"],+ "description": "The file's media type, when known."+ },+ "name": {+ "type": "string",+ "description": "Display name, typically the original file name."+ },+ "size": {+ "type": ["integer", "null"],+ "format": "int64",+ "description": "Size in bytes, when known."+ },+ "uri": {+ "type": "string",+ "description": "Where the agent can fetch the file."+ }+ }+ },"QueuedActionDto": {"type": "object","description": "One action waiting in a session's queue.\n\nClients deserialize this, so both derives are used.",@@ -2005,6 +2036,13 @@"type": ["string", "null"],"description": "The user who queued it, absent when a bot acted on nobody's behalf."},+ "attachments": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/PromptAttachment"+ },+ "description": "Files the prompt refers to, for prompts only. Kept through an edit,\nwhich replaces the text alone."+ },"createdAt": {"type": "string","format": "date-time",diff --git a/crates/agent_fold/src/bin/fold_jsonl.rs b/crates/agent_fold/src/bin/fold_jsonl.rsindex 69a74d270d..d5da41fcd3 100644--- a/crates/agent_fold/src/bin/fold_jsonl.rs+++ b/crates/agent_fold/src/bin/fold_jsonl.rs@@ -236,6 +236,18 @@ fn render_part(part: &MessagePart) -> String {MessagePart::Text { text } => {let _ = writeln!(out, "{}", text.trim_end());}+ MessagePart::Attachment {+ uri,+ name,+ mime_type,+ ..+ } => {+ let _ = writeln!(+ out,+ "[attachment] {name} ({}) {uri}",+ mime_type.as_deref().unwrap_or("unknown type")+ );+ }MessagePart::Thought { text } => {let _ = writeln!(out, "[thought]\n{}", indent(text.trim_end()));}diff --git a/crates/agent_fold/src/domain/fold/convert.rs b/crates/agent_fold/src/domain/fold/convert.rsindex 224e92a3a2..f2962eb7c1 100644--- a/crates/agent_fold/src/domain/fold/convert.rs+++ b/crates/agent_fold/src/domain/fold/convert.rs@@ -2,17 +2,36 @@use agent_client_protocol::RawJsonRpcParams;use agent_client_protocol::schema::v1::{ContentBlock, ToolKind};+use agent_runtime_protocol::domain::action::PromptAttachment;++use crate::domain::model::MessagePart;/// The text carried by a content block, if it carries any.pub(super) fn content_block_text(block: ContentBlock) -> Option<String> {match block {ContentBlock::Text(text) => Some(text.text),// Images, audio, resource links and embedded resources have no text- // to fold. Rendering them is a separate problem from this one.+ // to fold. Resource links fold to attachment parts instead - see+ // [`user_content_part`]; the rest are not rendered yet._ => None,}}+/// What a user's content block folds to: prose, or an attachment for the+/// `resource_link` blocks a prompt's files travel as. `None` for the block+/// kinds this side never sends in a prompt.+pub(super) fn user_content_part(block: ContentBlock) -> Option<MessagePart> {+ if let Some(attachment) = PromptAttachment::from_content_block(&block) {+ return Some(MessagePart::Attachment {+ uri: attachment.uri,+ name: attachment.name,+ mime_type: attachment.mime_type,+ size: attachment.size,+ });+ }+ content_block_text(block).map(|text| MessagePart::Text { text })+}+pub(super) fn tool_kind_name(kind: ToolKind) -> &'static str {match kind {ToolKind::Read => "read",diff --git a/crates/agent_fold/src/domain/fold/state.rs b/crates/agent_fold/src/domain/fold/state.rsindex ea3fc5eb26..1d48c6cf94 100644--- a/crates/agent_fold/src/domain/fold/state.rs+++ b/crates/agent_fold/src/domain/fold/state.rs@@ -17,7 +17,7 @@ use agent_runtime_protocol::domain::action::AgentAction;use agent_runtime_protocol::domain::schema::v0::{SystemEvent, ToRuntimeMessage, ToServerMessage};use serde::Deserialize;-use super::convert::{content_block_text, param};+use super::convert::{content_block_text, param, user_content_part};/// How one push changed [`State::messages`].#[derive(Debug, Clone, Copy)]@@ -466,7 +466,7 @@ impl FoldState {.is_none_or(|turn| turn.prompt_id.is_none()) =>{StepChange::message(- content_block_text(chunk.content).and_then(|text| self.replay_user_text(text)),+ user_content_part(chunk.content).and_then(|part| self.replay_user_part(part)),)}SessionUpdate::UserMessageChunk(_) => Vec::new(),diff --git a/crates/agent_fold/src/domain/fold/turn.rs b/crates/agent_fold/src/domain/fold/turn.rsindex bf4da2c953..b034ef6c68 100644--- a/crates/agent_fold/src/domain/fold/turn.rs+++ b/crates/agent_fold/src/domain/fold/turn.rs@@ -10,21 +10,31 @@ use agent_runtime_protocol::domain::action::AgentActionId;use macro_user_id::user_id::MacroUserIdStr;use non_empty::NonEmpty;-use super::convert::{content_block_text, deserialize_params};+use super::convert::{deserialize_params, user_content_part};use super::state::{Changed, FoldState, Turn};impl FoldState {/// Adjacent user chunks form one replayed prompt; agent activity separates turns.- pub(super) fn replay_user_text(&mut self, text: String) -> Option<Changed> {- if text.is_empty() {+ ///+ /// Text chunks extend the prompt's text part; an attachment chunk becomes+ /// its own part after it, the same shape [`Self::begin_turn`] derives+ /// from an original prompt, so a replayed session renders like a live one.+ pub(super) fn replay_user_part(&mut self, part: MessagePart) -> Option<Changed> {+ if matches!(&part, MessagePart::Text { text } if text.is_empty()) {return None;}if self.turn.as_ref().is_some_and(|turn| turn.agent.is_none())&& let Some(message) = self.messages.last_mut()&& matches!(message.author, Author::User { .. })- && let Some(MessagePart::Text { text: held }) = message.parts.get_mut(0){- held.push_str(&text);+ match part {+ MessagePart::Text { text } => match message.parts.get_mut(0) {+ Some(MessagePart::Text { text: held }) => held.push_str(&text),+ // The prompt so far was attachments only; its text leads.+ _ => message.parts.insert(0, MessagePart::Text { text }),+ },+ part => message.parts.push(part),+ }return Some(Changed::updated(self.messages.len() - 1));}self.close_turn(Some(StopReason::EndTurn));@@ -35,7 +45,7 @@ impl FoldState {id,author: Author::User { user_id: None },request_id: None,- parts: NonEmpty::one(MessagePart::Text { text }),+ parts: NonEmpty::one(part),stop: None,pending: self.speculative,});@@ -79,32 +89,41 @@ impl FoldState {// id, an optional `_meta`) carry nothing this fold renders, so there// is nothing to warn *about* beyond "no text," which showing no user// message already says.- let text = deserialize_params::<PromptRequest>(params)- .map(|request| {- // A confirmed prompt names the session the runtime answers- // to; a speculative one only echoes what this fold already- // knew, so it must not become the source of that fact.- if !self.speculative {- self.acp_session = Some(request.session_id.clone());+ //+ // Text blocks join into one part, since a harness may split prose+ // across blocks; each attached file is its own part, in prompt order+ // after the text, which is the order this side sends them in.+ let mut text = String::new();+ let mut attachments = Vec::new();+ if let Some(request) = deserialize_params::<PromptRequest>(params) {+ // A confirmed prompt names the session the runtime answers+ // to; a speculative one only echoes what this fold already+ // knew, so it must not become the source of that fact.+ if !self.speculative {+ self.acp_session = Some(request.session_id.clone());+ }+ for block in request.prompt {+ match user_content_part(block) {+ Some(MessagePart::Text { text: chunk }) => text.push_str(&chunk),+ Some(part) => attachments.push(part),+ None => {}}- request- .prompt- .into_iter()- .filter_map(content_block_text)- .collect::<Vec<_>>()- .join("")- })- .unwrap_or_default();+ }+ }+ let mut parts = attachments;+ if !text.is_empty() {+ parts.insert(0, MessagePart::Text { text });+ }- // A prompt carrying no text derives no user message, but still opens- // the turn the agent will answer into.- let changed = (!text.is_empty()).then(|| {+ // A prompt carrying nothing renderable derives no user message, but+ // still opens the turn the agent will answer into.+ let changed = NonEmpty::new(parts).ok().map(|parts| {let message = self.messages.len();self.messages.push(FoldedMessage {id,author: Author::User { user_id },request_id: AgentActionId::from_request_id(prompt_id),- parts: NonEmpty::one(MessagePart::Text { text }),+ parts,stop: None,pending: self.speculative,});diff --git a/crates/agent_fold/src/domain/model/part.rs b/crates/agent_fold/src/domain/model/part.rsindex 71f946337b..4cf95da500 100644--- a/crates/agent_fold/src/domain/model/part.rs+++ b/crates/agent_fold/src/domain/model/part.rs@@ -23,6 +23,25 @@ pub enum MessagePart {/// The prose.text: String,},+ /// A file the user attached to their prompt, by where it can be fetched.+ ///+ /// Read off the prompt's `resource_link` blocks - the only shape this+ /// side sends files in, since bytes never ride the log. Rendering decides+ /// from `mime_type` whether that is a thumbnail or a chip.+ Attachment {+ /// Where the file can be fetched - a static file service URL.+ uri: String,+ /// Display name, typically the original file name.+ name: String,+ /// The file's media type, when the sender knew it.+ #[serde(rename = "mimeType")]+ mime_type: Option<String>,+ /// Size in bytes, when the sender knew it. A double on the wire:+ /// specta refuses 64-bit integers, and no file this renders is+ /// anywhere near the precision limit.+ #[specta(type = Option<f64>)]+ size: Option<i64>,+ },/// The agent's reasoning, which a reader may want to hide by default.Thought {/// The reasoning.diff --git a/crates/agent_fold/src/domain/model/search.rs b/crates/agent_fold/src/domain/model/search.rsindex 0a0e6e3054..642e60aca4 100644--- a/crates/agent_fold/src/domain/model/search.rs+++ b/crates/agent_fold/src/domain/model/search.rs@@ -65,6 +65,9 @@ impl SearchText {fn part(&mut self, part: &MessagePart) {match part {MessagePart::Text { text } | MessagePart::Thought { text } => self.push(text),+ // The file's name is what a person would recognize and search+ // for; its static file URL is opaque and would only add noise.+ MessagePart::Attachment { name, .. } => self.push(name),MessagePart::ToolUse { name, detail, .. } => {self.push(name.display());self.tool(detail);diff --git a/crates/agent_fold/src/domain/test/fold.rs b/crates/agent_fold/src/domain/test/fold.rsindex 55d358a8f4..57b12b8634 100644--- a/crates/agent_fold/src/domain/test/fold.rs+++ b/crates/agent_fold/src/domain/test/fold.rs@@ -704,3 +704,110 @@ fn a_turn_that_had_started_talking_fails_in_place() {"what the agent managed to say is kept");}++const LINKED_PROMPT: &str = concat!(+ r#"{"direction":"to_runtime","user_id":"macro|[email protected]","content":{"type":"acp","jsonrpc":"2.0","id":"p","method":"session/prompt","params":{"sessionId":"s","prompt":["#,+ r#"{"type":"text","text":"what is wrong "},"#,+ r#"{"type":"text","text":"in this screenshot?"},"#,+ r#"{"type":"resource_link","uri":"https://static.example/file/11111111-1111-4111-8111-111111111111","name":"screenshot.png","mimeType":"image/png","size":2048},"#,+ r#"{"type":"resource_link","uri":"https://static.example/file/22222222-2222-4222-8222-222222222222","name":"notes.txt"}"#,+ r#"]}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","id":"p","result":{"stopReason":"end_turn"}}}"#,+);++/// A prompt's attached files fold to attachment parts after its text, so+/// the transcript shows what the user sent alongside what they said.+#[test]+fn a_prompt_with_attached_files_folds_them_as_parts() {+ let (messages, warnings) = fold_capturing_warnings(parse_log(LINKED_PROMPT));+ assert_eq!(warnings, vec![]);++ let user = &messages[0];+ assert!(matches!(user.author, Author::User { .. }));+ assert_eq!(+ user.parts.as_slice(),+ &[+ MessagePart::Text {+ text: "what is wrong in this screenshot?".to_owned()+ },+ MessagePart::Attachment {+ uri: "https://static.example/file/11111111-1111-4111-8111-111111111111".to_owned(),+ name: "screenshot.png".to_owned(),+ mime_type: Some("image/png".to_owned()),+ size: Some(2048),+ },+ MessagePart::Attachment {+ uri: "https://static.example/file/22222222-2222-4222-8222-222222222222".to_owned(),+ name: "notes.txt".to_owned(),+ mime_type: None,+ size: None,+ },+ ]+ );+}++/// Files alone are a message too - "look at this" needs no words.+#[test]+fn a_prompt_of_only_attached_files_still_derives_a_user_message() {+ let log = parse_log(+ r#"{"direction":"to_runtime","user_id":"macro|[email protected]","content":{"type":"acp","jsonrpc":"2.0","id":"p","method":"session/prompt","params":{"sessionId":"s","prompt":[{"type":"resource_link","uri":"https://static.example/file/1","name":"a.png","mimeType":"image/png"}]}}}"#,+ );+ let messages = fold(log);+ assert_eq!(messages.len(), 1);+ assert_eq!(+ messages[0].parts.as_slice(),+ &[MessagePart::Attachment {+ uri: "https://static.example/file/1".to_owned(),+ name: "a.png".to_owned(),+ mime_type: Some("image/png".to_owned()),+ size: None,+ }]+ );+}++/// A replayed session's user chunks carry the same links, and fold to the+/// same shape as a live prompt: text first, files after.+#[test]+fn replayed_user_chunks_keep_attached_files() {+ let log = parse_log(concat!(+ r#"{"direction":"to_runtime","content":{"type":"acp","jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":1}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","id":0,"result":{}}}"#,+ "\n",+ r#"{"direction":"to_runtime","content":{"type":"acp","jsonrpc":"2.0","id":1,"method":"session/load","params":{"sessionId":"s","cwd":"/","mcpServers":[]}}}"#,+ "\n",+ // The file arrives before the words: the text still leads.+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"resource_link","uri":"https://static.example/file/1","name":"a.png","mimeType":"image/png"}}}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"text","text":"what is "}}}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"user_message_chunk","content":{"type":"text","text":"this?"}}}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"a cat"}}}}}"#,+ "\n",+ r#"{"direction":"to_server","content":{"type":"acp","jsonrpc":"2.0","id":1,"result":{}}}"#,+ ));+ let messages = fold(log);+ assert_eq!(messages.len(), 2, "the replayed prompt and its answer");+ assert_eq!(+ messages[0].parts.as_slice(),+ &[+ MessagePart::Text {+ text: "what is this?".to_owned()+ },+ MessagePart::Attachment {+ uri: "https://static.example/file/1".to_owned(),+ name: "a.png".to_owned(),+ mime_type: Some("image/png".to_owned()),+ size: None,+ },+ ]+ );+ assert_eq!(+ messages[1].parts.as_slice(),+ &[MessagePart::Text {+ text: "a cat".to_owned()+ }]+ );+}diff --git a/crates/agent_harness/src/domain/model.rs b/crates/agent_harness/src/domain/model.rsindex 41d57df40f..8f6b6262a7 100644--- a/crates/agent_harness/src/domain/model.rs+++ b/crates/agent_harness/src/domain/model.rs@@ -3,12 +3,13 @@use agent_client_protocol::schema::v1::{HttpHeader, McpServer as AcpMcpServer, McpServerHttp};use agent_egress::domain::model::{McpServerSlug, RepoSlug};use agent_fold::domain::model::TurnSignal;-use agent_runtime_protocol::domain::action::{AgentAction, AgentActionId};+use agent_runtime_protocol::domain::action::{AgentAction, AgentActionId, PromptAttachment};use agent_session::domain::model::{AgentMcpServers, AgentSessionId, MessageId, SandboxSize};use agent_session::domain::ports::ControlEvent;use bot_id::BotId;use macro_user_id::user_id::MacroUserIdStr;use macro_uuid::Uuid;+use messages::domain::events::MessageEventAttachment;/// Where a mention happened.#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]pub struct MentionOrigin {@@ -22,6 +23,68 @@ pub struct MentionOrigin {pub sender: MacroUserIdStr<'static>,/// The message text, verbatim; becomes the session's first prompt.pub content: String,+ /// Files attached to the message, as the prompt will refer to them.+ #[serde(default)]+ pub attachments: Vec<PromptAttachment>,+}++/// How a channel message's attached files are named to an agent.+///+/// Channel attachments are stored by static file id; the agent needs a URL it+/// can fetch. The base URL is deployment configuration handed in by the+/// composition root, so this stays a pure translation.+#[derive(Debug, Clone)]+pub struct StaticFileLinks {+ base_url: String,+}++impl StaticFileLinks {+ /// Channel attachment entity type for an image stored as a static file.+ const STATIC_IMAGE: &str = "static/image";+ /// Channel attachment entity type for a video stored as a static file.+ const STATIC_VIDEO: &str = "static/video";++ /// Links under the static file service at `base_url`.+ #[must_use]+ pub fn new(base_url: impl Into<String>) -> Self {+ let mut base_url = base_url.into();+ while base_url.ends_with('/') {+ base_url.pop();+ }+ Self { base_url }+ }++ /// The prompt attachment for a channel attachment, or `None` for one that+ /// is not a static file - documents reach the agent through mentions,+ /// and have no URL an agent could fetch unauthenticated.+ ///+ /// Channel rows record only that a file is an image or a video, not its+ /// exact type, so the media type is the matching wildcard range.+ #[must_use]+ pub fn prompt_attachment(+ &self,+ attachment: &MessageEventAttachment,+ ) -> Option<PromptAttachment> {+ let (kind, mime_type) = match attachment.entity_type.as_str() {+ Self::STATIC_IMAGE => ("image", "image/*"),+ Self::STATIC_VIDEO => ("video", "video/*"),+ _ => return None,+ };+ let uri = format!("{}/file/{}", self.base_url, attachment.entity_id);+ Some(PromptAttachment::new(uri, kind).mime_type(mime_type))+ }++ /// The prompt attachments for a message's attached files, in order.+ #[must_use]+ pub fn prompt_attachments(+ &self,+ attachments: &[MessageEventAttachment],+ ) -> Vec<PromptAttachment> {+ attachments+ .iter()+ .filter_map(|attachment| self.prompt_attachment(attachment))+ .collect()+ }}/// Open a new session for a mention.@@ -253,14 +316,17 @@ pub enum CommandOutcome {impl DeliverAction {/// A prompt from a user, arriving from a channel that may need answering.+ ///+ /// Takes the action rather than its text so a prompt's attached files+ /// ride along; `AgentAction::prompt(text)` is the plain-text form.pub fn prompt(- content: impl Into<String>,+ action: AgentAction,actor: Option<MacroUserIdStr<'static>>,announce: Option<AnnounceOrigin>,) -> Self {Self {id: AgentActionId::mint(),- action: AgentAction::prompt(content),+ action,actor,announce,}diff --git a/crates/agent_harness/src/domain/service/open.rs b/crates/agent_harness/src/domain/service/open.rsindex ccef47c661..8397e6b7cd 100644--- a/crates/agent_harness/src/domain/service/open.rs+++ b/crates/agent_harness/src/domain/service/open.rs@@ -536,7 +536,7 @@ wheresession_id,DeliverAction {id: AgentActionId::mint(),- action: AgentAction::prompt(origin.content),+ action: AgentAction::prompt_with_attachments(origin.content, origin.attachments),actor: Some(origin.sender),announce: Some(AnnounceOrigin {parent: origin.parent,diff --git a/crates/agent_harness/src/domain/service/test.rs b/crates/agent_harness/src/domain/service/test.rsindex 8a5fbd8d00..2280800a50 100644--- a/crates/agent_harness/src/domain/service/test.rs+++ b/crates/agent_harness/src/domain/service/test.rs@@ -95,6 +95,7 @@ fn open_command() -> OpenSession {message_id: thread_id,sender: sender(),content: "@claude fix the failing test".to_owned(),+ attachments: vec![],},}}@@ -105,7 +106,7 @@ fn forward_message(content: &str) -> DeliverAction {// Staff: `disconnected_session` is a Daytona coder bot, and the// execute() gate admits only macro.com actors onto those.DeliverAction::prompt(- content,+ AgentAction::prompt(content),Some(staff_sender()),Some(AnnounceOrigin {parent: MessageParent::Channel(macro_uuid::Uuid::from_u128(0xf0)),@@ -2164,7 +2165,11 @@ async fn prompt(service.execute(id,- HarnessCommand::Deliver(DeliverAction::prompt(content, Some(sender()), None)),+ HarnessCommand::Deliver(DeliverAction::prompt(+ AgentAction::prompt(content),+ Some(sender()),+ None,+ )),).await}diff --git a/crates/agent_harness/src/domain/trigger_router.rs b/crates/agent_harness/src/domain/trigger_router.rsindex 4b791ba8a2..1211cd9c4f 100644--- a/crates/agent_harness/src/domain/trigger_router.rs+++ b/crates/agent_harness/src/domain/trigger_router.rs@@ -6,9 +6,11 @@ use agent_trigger::domain::broker_events::{};use bot_id::BotId;+use agent_runtime_protocol::domain::action::AgentAction;+use super::model::{AgentKind, AgentRuntimeConfig, AnnounceOrigin, AnnouncePrompt, DeliverAction, HarnessCommand,- MentionOrigin, OpenSession,+ MentionOrigin, OpenSession, StaticFileLinks,};/// What one trigger event asks this deployment to do.@@ -52,6 +54,7 @@ pub fn agent_trigger_bot_id(event: &AgentTriggerTopicEvent) -> Option<BotId> {pub fn route_agent_trigger(event: AgentTriggerTopicEvent,runtime: Option<AgentRuntimeConfig>,+ links: &StaticFileLinks,) -> Result<RoutedTrigger, Skipped> {match event {AgentTriggerTopicEvent::New(event) => {@@ -79,6 +82,7 @@ pub fn route_agent_trigger(message_id: message.message_id,sender,content: message.content,+ attachments: links.prompt_attachments(&message.attachments),},}),))@@ -105,7 +109,10 @@ pub fn route_agent_trigger(return Ok(RoutedTrigger::Command(session_id,HarnessCommand::Deliver(DeliverAction::prompt(- message.content,+ AgentAction::prompt_with_attachments(+ message.content,+ links.prompt_attachments(&message.attachments),+ ),message.sender.as_user().cloned(),Some(origin),)),diff --git a/crates/agent_harness/src/inbound/kafka/test.rs b/crates/agent_harness/src/inbound/kafka/test.rsindex e32a2bed06..8a6f4b4660 100644--- a/crates/agent_harness/src/inbound/kafka/test.rs+++ b/crates/agent_harness/src/inbound/kafka/test.rs@@ -15,7 +15,9 @@ use messages::domain::events::MessagePostedMetadata;use messages::domain::models::MessageParent;use super::*;-use crate::domain::model::{AgentKind, AgentRuntimeConfig, HarnessCommand};+use crate::domain::model::{AgentKind, AgentRuntimeConfig, HarnessCommand, StaticFileLinks};+use agent_runtime_protocol::domain::action::PromptAttachment;+use channels::domain::broker_events::ChannelEventAttachment;fn runtime(kind: AgentKind) -> Option<AgentRuntimeConfig> {Some(AgentRuntimeConfig {@@ -35,6 +37,10 @@ fn runtime(kind: AgentKind) -> Option<AgentRuntimeConfig> {})}+fn links() -> StaticFileLinks {+ StaticFileLinks::new("https://static.example/")+}+fn user() -> MacroUserIdStr<'static> {MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id")}@@ -98,6 +104,7 @@ fn a_mention_for_our_bot_opens_a_session() {let routed = route_agent_trigger(mentioned(BotId::TEST_A, ChannelSender::new_from_user(user())),runtime(AgentKind::InMemory),+ &links(),).expect("a mention for our bot should yield work");@@ -128,7 +135,7 @@ fn a_threaded_mention_answers_into_its_thread() {));let RoutedTrigger::Command(_, HarnessCommand::Open(open)) =- route_agent_trigger(event, runtime(AgentKind::InMemory))+ route_agent_trigger(event, runtime(AgentKind::InMemory), &links()).expect("the mention should yield work")else {panic!("a new-session event should open");@@ -142,6 +149,7 @@ fn a_foreign_bots_open_is_skipped() {route_agent_trigger(mentioned(BotId::TEST_A, ChannelSender::new_from_user(user())),None,+ &links(),).unwrap_err(),Skipped::ForeignBot@@ -151,7 +159,7 @@ fn a_foreign_bots_open_is_skipped() {#[test]fn an_unresolved_existing_session_is_treated_as_external() {assert!(matches!(- route_agent_trigger(channel_message(MACRO_CODER_BOT_ID), None),+ route_agent_trigger(channel_message(MACRO_CODER_BOT_ID), None, &links()),Ok(RoutedTrigger::Announce(_, _))));}@@ -162,6 +170,7 @@ fn a_bot_authored_mention_is_skipped() {route_agent_trigger(mentioned(BotId::TEST_A, ChannelSender::new_from_bot(BotId::TEST_B)),runtime(AgentKind::InMemory),+ &links(),).unwrap_err(),Skipped::NotFromUser@@ -176,6 +185,7 @@ fn any_user_mention_can_open_a_managed_agent() {route_agent_trigger(mentioned(BotId::TEST_A, ChannelSender::new_from_user(user)),runtime(AgentKind::InMemory),+ &links(),),Ok(RoutedTrigger::Command(_, HarnessCommand::Open(_)))));@@ -186,6 +196,7 @@ fn a_managed_channel_message_forwards_to_its_session() {let routed = route_agent_trigger(channel_message(MACRO_CODER_BOT_ID),runtime(AgentKind::SandboxedCoder),+ &links(),).expect("a channel event for our bot should yield work");@@ -214,8 +225,12 @@ fn a_managed_channel_message_forwards_to_its_session() {fn an_external_channel_message_announces_only() {// The external bot's own runtime delivers the prompt; this deployment// only posts the chip, whichever bot it manages itself.- let routed = route_agent_trigger(channel_message(BotId::TEST_A), runtime(AgentKind::External))- .expect("an external existing-session event should yield work");+ let routed = route_agent_trigger(+ channel_message(BotId::TEST_A),+ runtime(AgentKind::External),+ &links(),+ )+ .expect("an external existing-session event should yield work");let RoutedTrigger::Announce(session_id, prompt) = routed else {panic!("an external existing-session event should announce");@@ -242,7 +257,7 @@ fn a_bot_authored_external_channel_message_is_skipped() {},));assert_eq!(- route_agent_trigger(event, runtime(AgentKind::External)).unwrap_err(),+ route_agent_trigger(event, runtime(AgentKind::External), &links()).unwrap_err(),Skipped::NotFromUser);}@@ -266,7 +281,7 @@ fn a_document_mention_opens_and_follows_up_on_its_document() {message: document_message(ChannelSender::new_from_user(user())),}));let RoutedTrigger::Command(_, HarnessCommand::Open(open)) =- route_agent_trigger(opened, runtime(AgentKind::InMemory))+ route_agent_trigger(opened, runtime(AgentKind::InMemory), &links()).expect("a document mention for our bot should open")else {panic!("a new-session event should open");@@ -282,7 +297,7 @@ fn a_document_mention_opens_and_follows_up_on_its_document() {message: document_message(ChannelSender::new_from_user(user())),}));let RoutedTrigger::Announce(session_id, prompt) =- route_agent_trigger(followed, None).expect("an external follow-up announces")+ route_agent_trigger(followed, None, &links()).expect("an external follow-up announces")else {panic!("an external existing-session event should announce");};@@ -297,6 +312,7 @@ fn any_user_can_follow_up_to_their_cursor_session() {route_agent_trigger(channel_message_from(bot_id::CURSOR_BOT_ID, ChannelSender::new_from_user(user)),runtime(AgentKind::Cursor),+ &links(),),Ok(RoutedTrigger::Command(_, HarnessCommand::Deliver(_)))));@@ -309,6 +325,7 @@ fn any_user_can_follow_up_to_a_coder_session() {let routed = route_agent_trigger(channel_message_from(MACRO_CODER_BOT_ID, ChannelSender::new_from_user(user)),runtime(AgentKind::SandboxedCoder),+ &links(),).expect("channel users may follow up");assert!(matches!(@@ -325,6 +342,7 @@ fn a_bot_authored_follow_up_to_a_managed_session_still_delivers() {ChannelSender::new_from_bot(BotId::TEST_B),),runtime(AgentKind::SandboxedCoder),+ &links(),).expect("explicit bot mentions continue to reach managed sessions");@@ -333,3 +351,82 @@ fn a_bot_authored_follow_up_to_a_managed_session_still_delivers() {};assert_eq!(deliver.actor, None);}++fn attached(entity_type: &str, id: u128) -> ChannelEventAttachment {+ ChannelEventAttachment {+ attachment_id: Uuid::from_u128(id),+ entity_type: entity_type.to_owned(),+ entity_id: Uuid::from_u128(id).to_string(),+ created_at: Utc::now(),+ }+}++fn message_with_files(sender: ChannelSender<'static>) -> ChannelMessagePostedMetadata {+ ChannelMessagePostedMetadata {+ attachments: vec![+ attached("static/image", 0x10),+ // Documents reach the agent as mentions, never as file links.+ attached("document", 0x11),+ attached("static/video", 0x12),+ ],+ ..message(sender)+ }+}++/// The files a message carries reach the agent with its words - as links+/// it can fetch, since the static file service is where the bytes live.+#[test]+fn a_mention_with_attached_files_opens_with_them_as_prompt_attachments() {+ let event = AgentTriggerTopicEvent::New(NewAgentSessionEvent::TopLevelMentioned(+ AgentBotMentionedEvent {+ bot_id: BotId::TEST_A,+ message: message_with_files(ChannelSender::new_from_user(user())),+ },+ ));+ let routed = route_agent_trigger(event, runtime(AgentKind::InMemory), &links()).unwrap();+ let RoutedTrigger::Command(_, HarnessCommand::Open(open)) = routed else {+ panic!("a new-session event should open");+ };+ assert_eq!(+ open.origin.attachments,+ vec![+ PromptAttachment::new(+ format!("https://static.example/file/{}", Uuid::from_u128(0x10)),+ "image",+ )+ .mime_type("image/*"),+ PromptAttachment::new(+ format!("https://static.example/file/{}", Uuid::from_u128(0x12)),+ "video",+ )+ .mime_type("video/*"),+ ]+ );+}++#[test]+fn a_managed_channel_message_with_files_delivers_them_as_prompt_attachments() {+ let event = AgentTriggerTopicEvent::Existing(ExistingAgentSessionEvent::Channel(+ ChannelEventMetadata {+ bot_id: MACRO_CODER_BOT_ID,+ session_id: AgentSessionId::TEST_A,+ kind: ThreadMessageKind::MentionThread,+ message: message_with_files(ChannelSender::new_from_user(user())),+ },+ ));+ let routed = route_agent_trigger(event, runtime(AgentKind::SandboxedCoder), &links()).unwrap();+ let RoutedTrigger::Command(_, HarnessCommand::Deliver(deliver)) = routed else {+ panic!("a managed existing-session event should deliver");+ };+ let AgentAction::Prompt(prompt) = deliver.action else {+ panic!("a channel message becomes a prompt");+ };+ assert_eq!(prompt.prompt, "@claude fix the tests");+ assert_eq!(+ prompt.attachments.len(),+ 2,+ "the document is not a file link"+ );+ assert_eq!(prompt.attachments[0].mime_type.as_deref(), Some("image/*"));+ assert_eq!(prompt.attachments[1].mime_type.as_deref(), Some("video/*"));+}diff --git a/crates/agent_inmem/Cargo.toml b/crates/agent_inmem/Cargo.tomlindex df4c13052d..8582cd90df 100644--- a/crates/agent_inmem/Cargo.toml+++ b/crates/agent_inmem/Cargo.toml@@ -14,6 +14,7 @@ agent_runtime_protocol = { path = "../agent_runtime_protocol" }agent_session = { path = "../agent_session" }anyhow = { workspace = true }ai_tools = { path = "../ai_tools" }+attachment = { path = "../attachment" }ai_toolset = { path = "../ai_toolset" }ai_usage = { path = "../ai_usage" }bytes = { workspace = true }@@ -30,6 +31,8 @@ macro_uuid = { path = "../macro_uuid" }mcp_select = { path = "../mcp_select" }mcp_toolset = { path = "../mcp_toolset" }memory = { path = "../memory" }+model-entity = { path = "../model-entity" }+non_empty = { path = "../non_empty" }prompt = { path = "../prompt" }rmcp = { workspace = true, features = ["client", "transport-streamable-http-client"] }schemars = { workspace = true }diff --git a/crates/agent_inmem/src/domain/agent.rs b/crates/agent_inmem/src/domain/agent.rsindex 10dfb225e4..9486c806bf 100644--- a/crates/agent_inmem/src/domain/agent.rs+++ b/crates/agent_inmem/src/domain/agent.rs@@ -43,7 +43,7 @@ use tracing::Instrument as _;use crate::domain::engine::{AgentIdentity, TurnEngine, TurnRequest};use crate::domain::mcp::{DynMcpToolConnector, dialable_servers};-use crate::domain::session::{HistoryEntry, SessionStore, messages_for_turn};+use crate::domain::session::{HistoryEntry, SessionStore, UserPrompt, messages_for_turn};use crate::domain::user_input::{SharedUserInputRequester, UserInputError, UserInputOutcome, UserInputRequest,UserInputRequester,@@ -197,7 +197,7 @@ impl AgentState {/// Everything from the session's state that a turn answering `prompt`/// runs from.- fn turn_input(&self, prompt: &str) -> TurnInput {+ fn turn_input(&self, prompt: &UserPrompt) -> TurnInput {self.store.get(&self.session_id).map_or_else(|| TurnInput {messages: messages_for_turn(&[], prompt),@@ -214,7 +214,7 @@ impl AgentState {)}- fn push_turn(&self, prompt: String, parts: Vec<AssistantMessagePart>) {+ fn push_turn(&self, prompt: UserPrompt, parts: Vec<AssistantMessagePart>) {if let Some(mut state) = self.store.get_mut(&self.session_id) {state.history.push(HistoryEntry::User(prompt));if !parts.is_empty() {@@ -567,8 +567,8 @@ pub async fn serve(state: Arc<AgentState>, acp: AcpChannel) -> Result<(), AcpErrgen_ai.conversation.id = %state.session_id,);genai_telemetry::propagation::set_parent(&span, request.meta.as_ref());- let prompt = prompt_text(&request);- if prompt.trim() == COMPACT_COMMAND {+ let prompt = UserPrompt::from_request(&request);+ if prompt.is_compact_command() {state.clear_history();let _ = connection.send_notification(SessionNotification::new(request.session_id,@@ -581,7 +581,7 @@ pub async fn serve(state: Arc<AgentState>, acp: AcpChannel) -> Result<(), AcpErrreturn responder.respond(PromptResponse::new(StopReason::EndTurn));}if state.enable_dev_commands- && let Some(question) = prompt.trim().strip_prefix(ASK_COMMAND)+ && let Some(question) = prompt.text.trim().strip_prefix(ASK_COMMAND){let question = question.trim().to_owned();let cancel = state.begin_turn();@@ -674,7 +674,7 @@ async fn run_turn(state: &AgentState,connection: &ConnectionTo<Client>,acp_session_id: SessionId,- prompt: String,+ prompt: UserPrompt,cancel: CancellationToken,) -> StopReason {let _turn = state.turn_lock.lock().await;@@ -778,7 +778,7 @@ async fn run_ask(state: &AgentState,connection: &ConnectionTo<Client>,acp_session_id: SessionId,- prompt: String,+ prompt: UserPrompt,question: String,cancel: CancellationToken,) -> StopReason {@@ -963,18 +963,6 @@ fn tool_kind(name: &str) -> ToolKind {}}-/// The prompt's text content, other block types ignored.-fn prompt_text(request: &PromptRequest) -> String {- request- .prompt- .iter()- .filter_map(|block| match block {- ContentBlock::Text(text) => Some(text.text.as_str()),- _ => None,- })- .collect()-}-/// Close tool calls that never got a response - a cancelled or failed turn/// leaves them dangling, and an unmatched call would poison the next turn's/// provider payload. Returns what was synthesized as `(id, name)`.diff --git a/crates/agent_inmem/src/domain/agent/test.rs b/crates/agent_inmem/src/domain/agent/test.rsindex 13ac828949..24ea5cd90c 100644--- a/crates/agent_inmem/src/domain/agent/test.rs+++ b/crates/agent_inmem/src/domain/agent/test.rs@@ -3,8 +3,8 @@ use std::sync::Arc;use agent::StreamPart;use agent_client_protocol::schema::ProtocolVersion;use agent_client_protocol::schema::v1::{- ContentBlock, InitializeRequest, NewSessionRequest, PromptRequest, SessionNotification,- TextContent,+ ContentBlock, InitializeRequest, NewSessionRequest, PromptRequest, ResourceLink,+ SessionNotification, TextContent,};use agent_client_protocol::{Client, ConnectionTo};use rig_agent::agent::StreamingError;@@ -336,6 +336,58 @@ async fn turns_accumulate_history_and_send_the_model() {);}+#[tokio::test]+async fn attached_files_reach_the_model_and_stay_in_history() {+ let engine = Arc::new(ScriptedEngine::new(vec![StreamPart::Content(+ "blue".into(),+ )]));+ let image = "https://static.example/file/11111111-1111-4111-8111-111111111111";+ let notes = "https://static.example/file/22222222-2222-4222-8222-222222222222";++ with_agent(Arc::clone(&engine), async |connection, session| {+ let prompt = PromptRequest::new(+ session.clone(),+ vec![+ ContentBlock::Text(TextContent::new("what color is this?")),+ ContentBlock::ResourceLink(+ ResourceLink::new("screenshot.png", image).mime_type("image/png".to_owned()),+ ),+ ContentBlock::ResourceLink(+ ResourceLink::new("notes.txt", notes).mime_type("text/plain".to_owned()),+ ),+ ],+ );+ connection+ .send_request(prompt)+ .block_task()+ .await+ .expect("the prompt should complete");+ connection+ .send_request(text_prompt(&session, "and now?"))+ .block_task()+ .await+ .expect("the prompt should complete");+ })+ .await;++ let requests = engine.requests();+ assert_eq!(requests.len(), 2);+ // The image rides the user message as an image URL the provider fetches;+ // the text file has no image form, so it is named to the model instead.+ assert_eq!(requests[0].messages, vec!["what color is this?".to_owned()]);+ assert_eq!(requests[0].images, vec![image.to_owned()]);+ // History keeps the files: a follow-up still shows the model the image.+ assert_eq!(requests[1].images, vec![image.to_owned()]);+ assert_eq!(+ requests[1].messages,+ vec![+ "what color is this?".to_owned(),+ "blue".to_owned(),+ "and now?".to_owned()+ ]+ );+}+#[tokio::test]async fn compact_clears_history_without_running_a_turn() {let engine = Arc::new(ScriptedEngine::new(vec![StreamPart::Content("ok".into())]));@@ -369,6 +421,48 @@ async fn compact_clears_history_without_running_a_turn() {);}+#[tokio::test]+async fn compact_with_a_file_attached_is_a_prompt_about_the_file() {+ // The command word alone is the control. With a file alongside, the user+ // is asking about that file, and compacting would drop it unseen.+ let engine = Arc::new(ScriptedEngine::new(vec![StreamPart::Content("ok".into())]));+ let notes = "https://static.example/file/33333333-3333-4333-8333-333333333333";++ with_agent(Arc::clone(&engine), async |connection, session| {+ connection+ .send_request(text_prompt(&session, "remember this"))+ .block_task()+ .await+ .expect("the prompt should complete");+ connection+ .send_request(PromptRequest::new(+ session.clone(),+ vec![+ ContentBlock::Text(TextContent::new("/compact")),+ ContentBlock::ResourceLink(+ ResourceLink::new("notes.txt", notes).mime_type("text/plain".to_owned()),+ ),+ ],+ ))+ .block_task()+ .await+ .expect("the prompt should complete");+ })+ .await;++ let requests = engine.requests();+ assert_eq!(requests.len(), 2, "the attached prompt runs a turn");+ assert_eq!(+ requests[1].messages,+ vec![+ "remember this".to_owned(),+ "ok".to_owned(),+ "/compact".to_owned()+ ],+ "the conversation is kept, not compacted"+ );+}+#[tokio::test]async fn cancel_stops_the_turn_with_the_cancelled_stop_reason() {let engine = Arc::new(HangingEngine);diff --git a/crates/agent_inmem/src/domain/replay.rs b/crates/agent_inmem/src/domain/replay.rsindex 5b58e2bb7c..59b50768aa 100644--- a/crates/agent_inmem/src/domain/replay.rs+++ b/crates/agent_inmem/src/domain/replay.rs@@ -20,13 +20,12 @@ use agent_client_protocol::schema::v1::{ContentBlock, PromptRequest, SessionNotification, SessionUpdate, ToolCallStatus,};use agent_client_protocol::{JsonRpcMessage, RawJsonRpcMessage, RawJsonRpcParams};-use agent_runtime_protocol::domain::action::COMPACT_COMMAND;use agent_runtime_protocol::domain::schema::v0::{ToRuntimeMessage, ToServerMessage};use agent_session::domain::model::Message;use futures::future::BoxFuture;use crate::domain::agent::close_dangling_tool_calls;-use crate::domain::session::HistoryEntry;+use crate::domain::session::{HistoryEntry, UserPrompt};#[cfg(test)]mod test;@@ -50,11 +49,12 @@ pub trait FrameSource: Send + Sync + 'static {/// User prompts open turns and `session/update` notifications fill them in,/// mirroring what the live agent pushed into its history as the turn ran. A/// `/compact` prompt drops everything recorded before it, exactly as the live-/// agent's compact handling cleared its history.+/// agent's compact handling cleared its history - and, by the same rule, a+/// `/compact` that carried files is a turn like any other.#[must_use]pub fn replay_history(frames: impl IntoIterator<Item = Message>) -> Vec<HistoryEntry> {let mut history = Vec::new();- let mut open: Option<(String, Vec<AssistantMessagePart>)> = None;+ let mut open: Option<(UserPrompt, Vec<AssistantMessagePart>)> = None;for frame in frames {match frame {@@ -69,21 +69,14 @@ pub fn replay_history(frames: impl IntoIterator<Item = Message>) -> Vec<HistoryEelse {continue;};- let text: String = prompt- .prompt- .iter()- .filter_map(|block| match block {- ContentBlock::Text(text) => Some(text.text.as_str()),- _ => None,- })- .collect();+ let prompt = UserPrompt::from_blocks(&prompt.prompt);close_turn(&mut history, &mut open);- if text.trim() == COMPACT_COMMAND {+ if prompt.is_compact_command() {// Compaction dropped everything before it from the// model's context; replaying it back would undo that.history.clear();} else {- open = Some((text, Vec::new()));+ open = Some((prompt, Vec::new()));}}Message::ToServer(ToServerMessage::Acp(acp)) => {@@ -200,7 +193,7 @@ fn unanswered_call_name(parts: &[AssistantMessagePart], id: &str) -> Option<Stri/// Push the open turn into the history, closing whatever it left dangling.fn close_turn(history: &mut Vec<HistoryEntry>,- open: &mut Option<(String, Vec<AssistantMessagePart>)>,+ open: &mut Option<(UserPrompt, Vec<AssistantMessagePart>)>,) {let Some((prompt, mut parts)) = open.take() else {return;diff --git a/crates/agent_inmem/src/domain/replay/test.rs b/crates/agent_inmem/src/domain/replay/test.rsindex 5a8f36921d..07a5e9cc25 100644--- a/crates/agent_inmem/src/domain/replay/test.rs+++ b/crates/agent_inmem/src/domain/replay/test.rs@@ -1,6 +1,6 @@use agent_client_protocol::schema::v1::{- ContentChunk, SessionId, TextContent, ToolCall as AcpToolCall, ToolCallStatus, ToolCallUpdate,- ToolCallUpdateFields,+ ContentChunk, ResourceLink, SessionId, TextContent, ToolCall as AcpToolCall, ToolCallStatus,+ ToolCallUpdate, ToolCallUpdateFields,};use agent_runtime_protocol::domain::schema::v0::AcpMessage;@@ -39,6 +39,25 @@ fn update_frame(update: SessionUpdate) -> Message {Message::ToServer(ToServerMessage::Acp(AcpMessage(raw)))}+/// A logged `session/prompt` whose text is followed by one file link.+fn prompt_frame_with_file(text: &str, name: &str, uri: &str) -> Message {+ let request = PromptRequest::new(+ acp_session(),+ vec![+ ContentBlock::Text(TextContent::new(text)),+ ContentBlock::ResourceLink(ResourceLink::new(name, uri)),+ ],+ );+ let raw: RawJsonRpcMessage = serde_json::from_value(serde_json::json!({+ "jsonrpc": "2.0",+ "id": 1,+ "method": "session/prompt",+ "params": serde_json::to_value(request).expect("a prompt should serialize"),+ }))+ .expect("a request frame should deserialize");+ Message::ToRuntime(ToRuntimeMessage::Acp(AcpMessage(raw)))+}+fn message_chunk(text: &str) -> SessionUpdate {SessionUpdate::AgentMessageChunk(ContentChunk::new(ContentBlock::Text(TextContent::new(text,@@ -79,8 +98,8 @@ fn a_logged_turn_replays_as_the_history_the_live_agent_recorded() {else {panic!("two full turns should replay, got {history:#?}");};- assert_eq!(first, "find the roadmap");- assert_eq!(second, "thanks");+ assert_eq!(first.text, "find the roadmap");+ assert_eq!(second.text, "thanks");assert_eq!(second_parts.as_slice(),[AssistantMessagePart::Text {@@ -128,7 +147,7 @@ fn a_compact_prompt_drops_everything_recorded_before_it() {let [HistoryEntry::User(prompt), HistoryEntry::Assistant(parts)] = history.as_slice() else {panic!("only the post-compact turn should replay, got {history:#?}");};- assert_eq!(prompt, "after");+ assert_eq!(prompt.text, "after");assert_eq!(parts.as_slice(),[AssistantMessagePart::Text {@@ -137,6 +156,32 @@ fn a_compact_prompt_drops_everything_recorded_before_it() {);}+#[test]+fn a_compact_prompt_carrying_a_file_replays_as_an_ordinary_turn() {+ // Serving the turn kept the conversation (the files make it a real+ // prompt), so a cold attach must rebuild it the same way - replaying it+ // as compaction would drop context the live session still had.+ let history = replay_history(vec![+ prompt_frame("remember this"),+ update_frame(message_chunk("noted")),+ prompt_frame_with_file("/compact", "notes.txt", "https://static.example/file/9"),+ update_frame(message_chunk("read it")),+ ]);++ let [+ HistoryEntry::User(first),+ HistoryEntry::Assistant(_),+ HistoryEntry::User(second),+ HistoryEntry::Assistant(_),+ ] = history.as_slice()+ else {+ panic!("both turns should replay, got {history:#?}");+ };+ assert_eq!(first.text, "remember this");+ assert_eq!(second.text, "/compact");+ assert_eq!(second.attachments.len(), 1);+}+#[test]fn a_call_the_log_never_answered_is_closed_rather_than_left_dangling() {let history = replay_history(vec![diff --git a/crates/agent_inmem/src/domain/session.rs b/crates/agent_inmem/src/domain/session.rsindex 8e0bbe9c2e..e991df54b2 100644--- a/crates/agent_inmem/src/domain/session.rs+++ b/crates/agent_inmem/src/domain/session.rs@@ -6,9 +6,165 @@//! rebuilds it from the frame log (see [`crate::domain::replay`]).use agent::types::{AssistantMessagePart, ChatMessage, ChatMessageContent, Role};-use agent_client_protocol::schema::v1::SessionId;+use agent_client_protocol::schema::v1::{ContentBlock, PromptRequest, SessionId};+use agent_runtime_protocol::domain::action::{COMPACT_COMMAND, PromptAttachment};use agent_session::domain::model::AgentSessionId;+use attachment::image::ImageData;+use attachment::{AttachmentContent, AttachmentPart, Attachments};use dashmap::DashMap;+use model_entity::EntityType;+use non_empty::NonEmpty;++#[cfg(test)]+mod test;++/// What a user said in one turn: the prompt's text, and the files it named.+///+/// Files arrive as ACP `resource_link` blocks - URLs, never bytes. HTTPS+/// images go to the model as image URLs, which the provider fetches itself;+/// anything else is described to the model by name and URL, since there is+/// no way to show it the bytes and the URL is still something its tools can+/// fetch.+#[derive(Debug, Clone, PartialEq, Eq)]+pub struct UserPrompt {+ /// The prompt's text blocks, joined.+ pub text: String,+ /// The prompt's `resource_link` blocks, in order.+ pub attachments: Vec<PromptAttachment>,+}++impl UserPrompt {+ /// A prompt of text alone.+ #[must_use]+ pub fn text(text: impl Into<String>) -> Self {+ Self {+ text: text.into(),+ attachments: Vec::new(),+ }+ }++ /// Read a prompt off the content blocks of a `session/prompt`. Block kinds+ /// this agent has no use for (inline images, audio, embedded resources -+ /// none of which it advertises) are skipped.+ #[must_use]+ pub fn from_blocks(blocks: &[ContentBlock]) -> Self {+ let mut prompt = Self::text(String::new());+ for block in blocks {+ match block {+ ContentBlock::Text(text) => prompt.text.push_str(&text.text),+ block => {+ if let Some(attachment) = PromptAttachment::from_content_block(block) {+ prompt.attachments.push(attachment);+ }+ }+ }+ }+ prompt+ }++ /// Read a prompt off a `session/prompt` request.+ #[must_use]+ pub fn from_request(request: &PromptRequest) -> Self {+ Self::from_blocks(&request.prompt)+ }++ /// Whether this is the compaction control rather than a message.+ ///+ /// The command word and nothing else. A `/compact` that also carries+ /// files is a real prompt about those files, and compacting would throw+ /// them away unseen - so serving a turn and replaying one must agree on+ /// this, or a cold attach would drop a conversation the live session+ /// kept. The harness applies the same rule where it reads a control off+ /// the wire (`AgentAction::control_from_runtime`).+ #[must_use]+ pub fn is_compact_command(&self) -> bool {+ self.text.trim() == COMPACT_COMMAND && self.attachments.is_empty()+ }++ /// The model-facing form of the attached files, `None` without any.+ #[must_use]+ pub fn to_attachments(&self) -> Option<Attachments<'static>> {+ let resolved: Vec<_> = self+ .attachments+ .iter()+ .map(|attachment| Ok(attachment_content(attachment)))+ .collect();+ NonEmpty::new(resolved).ok().map(Attachments::new)+ }++ /// The message this prompt is to the model.+ #[must_use]+ pub fn to_chat_message(&self) -> ChatMessage {+ ChatMessage {+ content: ChatMessageContent::Text(self.text.clone()),+ role: Role::User,+ attachments: self.to_attachments(),+ }+ }+}++/// The image file extensions the composer's chips classify as images, so a+/// file the user sees as a thumbnail is one the model sees as an image. Keep+/// in step with `CHANNEL_IMAGE_FILE_EXTENSIONS` on the web side.+const IMAGE_EXTENSIONS: &[&str] = &[+ "apng", "avif", "bmp", "gif", "heic", "heif", "jpeg", "jpg", "png", "svg", "tif", "tiff",+ "webp",+];++/// Whether this file is an image, by media type and then by name.+///+/// A browser can report no media type at all for a `.png`, and the composer+/// still shows it as a thumbnail, so the name decides when the type cannot.+fn is_image(attachment: &PromptAttachment) -> bool {+ let mime = attachment.mime_type.as_deref().unwrap_or_default();+ if mime.starts_with("image/") {+ return true;+ }+ // Mirrors the composer's own order: a media type naming another medium+ // wins, and otherwise the name decides.+ if mime.starts_with("video/") {+ return false;+ }+ attachment+ .name+ .rsplit_once('.')+ .map(|(_, extension)| extension.to_ascii_lowercase())+ .is_some_and(|extension| IMAGE_EXTENSIONS.contains(&extension.as_str()))+}++/// One attached file as resolved attachment content.+///+/// Only an HTTPS image is handed over as an image URL: providers refuse plain+/// HTTP, and history keeps every attachment for the rest of the session, so+/// one such link would fail every later turn. Anything else is named in text.+fn attachment_content(attachment: &PromptAttachment) -> AttachmentContent<'static> {+ let is_image = is_image(attachment);+ let fetchable = attachment.uri.starts_with("https://");+ let part = if is_image && fetchable {+ AttachmentPart::Image(ImageData::StaticUrl(attachment.uri.clone()))+ } else {+ let kind = attachment.mime_type.as_deref().unwrap_or("unknown type");+ AttachmentPart::Content(format!(+ "Attached file \"{}\" ({kind}): {}",+ attachment.name, attachment.uri+ ))+ };+ AttachmentContent {+ // The static file id is the URL's last path segment; a URL shaped+ // some other way is identified by the whole URL.+ reference: EntityType::StaticFile.with_entity_string(+ attachment+ .uri+ .rsplit('/')+ .next()+ .filter(|id| !id.is_empty())+ .unwrap_or(&attachment.uri)+ .to_owned(),+ ),+ name: Some(attachment.name.clone()),+ content: NonEmpty::one(part),+ }+}use super::engine::AgentIdentity;@@ -17,7 +173,7 @@ use super::engine::AgentIdentity;#[derive(Debug, Clone)]pub enum HistoryEntry {/// A prompt from a user.- User(String),+ User(UserPrompt),/// One assistant turn: text, tool calls, and tool results, flattened.Assistant(Vec<AssistantMessagePart>),}@@ -63,25 +219,17 @@ pub type SessionStore = DashMap<AgentSessionId, SessionState>;/// Materialize the conversation for one turn: the recorded history followed/// by the prompt being answered.#[must_use]-pub fn messages_for_turn(history: &[HistoryEntry], prompt: &str) -> Vec<ChatMessage> {+pub fn messages_for_turn(history: &[HistoryEntry], prompt: &UserPrompt) -> Vec<ChatMessage> {history.iter().map(|entry| match entry {- HistoryEntry::User(text) => ChatMessage {- content: ChatMessageContent::Text(text.clone()),- role: Role::User,- attachments: None,- },+ HistoryEntry::User(prompt) => prompt.to_chat_message(),HistoryEntry::Assistant(parts) => ChatMessage {content: ChatMessageContent::AssistantMessageParts(parts.clone()),role: Role::Assistant,attachments: None,},})- .chain(std::iter::once(ChatMessage {- content: ChatMessageContent::Text(prompt.to_owned()),- role: Role::User,- attachments: None,- }))+ .chain(std::iter::once(prompt.to_chat_message())).collect()}diff --git a/crates/agent_inmem/src/domain/session/test.rs b/crates/agent_inmem/src/domain/session/test.rsnew file mode 100644index 0000000000..a7021390d5--- /dev/null+++ b/crates/agent_inmem/src/domain/session/test.rs@@ -0,0 +1,136 @@+use agent_client_protocol::schema::v1::{ContentBlock, ResourceLink, TextContent};+use attachment::AttachmentPart;+use attachment::image::ImageData;++use super::*;++fn link(name: &str, uri: &str, mime: Option<&str>) -> ContentBlock {+ ContentBlock::ResourceLink(ResourceLink::new(name, uri).mime_type(mime.map(str::to_owned)))+}++#[test]+fn a_prompt_reads_its_text_and_its_file_links_off_the_blocks() {+ let prompt = UserPrompt::from_blocks(&[+ ContentBlock::Text(TextContent::new("what is ")),+ link("a.png", "https://x/file/1", Some("image/png")),+ ContentBlock::Text(TextContent::new("this?")),+ link("b.txt", "https://x/file/2", None),+ ]);+ assert_eq!(prompt.text, "what is this?");+ assert_eq!(prompt.attachments.len(), 2);+ assert_eq!(prompt.attachments[0].name, "a.png");+ assert_eq!(prompt.attachments[1].uri, "https://x/file/2");+}++#[test]+fn images_become_image_urls_and_other_files_are_named_to_the_model() {+ let prompt = UserPrompt::from_blocks(&[+ ContentBlock::Text(TextContent::new("look")),+ link("a.png", "https://x/file/1", Some("image/png")),+ link("spec.pdf", "https://x/file/2", Some("application/pdf")),+ ]);+ let message = prompt.to_chat_message();+ assert_eq!(message.content.message_text(), "look");+ let attachments = message.attachments.expect("files attach to the message");+ let contents: Vec<_> = attachments+ .parts()+ .iter()+ .map(|resolved| resolved.as_ref().expect("links always resolve"))+ .collect();+ assert_eq!(contents.len(), 2);++ // The static file id is what the reference names.+ assert_eq!(contents[0].reference.entity_id, "1");+ assert_eq!(contents[0].name.as_deref(), Some("a.png"));+ assert!(matches!(+ &contents[0].content[0],+ AttachmentPart::Image(ImageData::StaticUrl(url)) if url == "https://x/file/1"+ ));++ let AttachmentPart::Content(text) = &contents[1].content[0] else {+ panic!(+ "a non-image file is described in text: {:?}",+ contents[1].content[0]+ );+ };+ assert!(text.contains("spec.pdf") && text.contains("application/pdf"));+ assert!(text.contains("https://x/file/2"));+}++#[test]+fn an_image_the_browser_left_untyped_is_still_handed_over_as_an_image() {+ // A browser can report no media type for a `.png`, and the composer shows+ // it as a thumbnail either way - so the model must see the image, not a+ // line of text describing it.+ let prompt = UserPrompt::from_blocks(&[+ link("shot.PNG", "https://x/file/1", None),+ link("clip.mp4", "https://x/file/2", None),+ link("notes", "https://x/file/3", None),+ ]);+ let attachments = prompt+ .to_chat_message()+ .attachments+ .expect("files attach to the message");+ let contents: Vec<_> = attachments+ .parts()+ .iter()+ .map(|resolved| resolved.as_ref().expect("links always resolve"))+ .collect();++ // The name decides, and its case does not matter.+ assert!(matches!(+ &contents[0].content[0],+ AttachmentPart::Image(ImageData::StaticUrl(url)) if url == "https://x/file/1"+ ));+ // A video and an extensionless file are still named in text.+ assert!(matches!(+ &contents[1].content[0],+ AttachmentPart::Content(_)+ ));+ assert!(matches!(+ &contents[2].content[0],+ AttachmentPart::Content(_)+ ));+}++#[test]+fn a_media_type_naming_another_medium_wins_over_the_name() {+ // The composer classifies by media type first, so a file typed as video+ // is a video however it is named - the model input must agree.+ let prompt =+ UserPrompt::from_blocks(&[link("thumb.png", "https://x/file/1", Some("video/mp4"))]);+ let attachments = prompt+ .to_chat_message()+ .attachments+ .expect("the file attaches");+ let content = attachments.parts()[0].as_ref().expect("links resolve");+ assert!(matches!(&content.content[0], AttachmentPart::Content(_)));+}++#[test]+fn a_text_only_prompt_attaches_nothing() {+ let message = UserPrompt::text("hi").to_chat_message();+ assert_eq!(message.content.message_text(), "hi");+ assert!(message.attachments.is_none());+}++#[test]+fn a_plain_http_image_is_named_rather_than_handed_over_as_an_image_url() {+ // Providers refuse http image URLs, and the attachment stays in history+ // for the rest of the session - so it must never reach them as an image.+ let prompt = UserPrompt::from_blocks(&[link(+ "a.png",+ "http://localhost:8100/file/1",+ Some("image/png"),+ )]);+ let message = prompt.to_chat_message();+ let attachments = message.attachments.expect("the file still attaches");+ let content = attachments.parts()[0].as_ref().expect("links resolve");+ let AttachmentPart::Content(text) = &content.content[0] else {+ panic!(+ "an http image is described, not embedded: {:?}",+ content.content[0]+ );+ };+ assert!(text.contains("a.png") && text.contains("http://localhost:8100/file/1"));+}diff --git a/crates/agent_inmem/src/testing.rs b/crates/agent_inmem/src/testing.rsindex 9be5142e55..6422c2ac65 100644--- a/crates/agent_inmem/src/testing.rs+++ b/crates/agent_inmem/src/testing.rs@@ -22,6 +22,8 @@ pub(crate) struct RecordedTurn {pub(crate) model: String,/// The conversation, flattened to text per message.pub(crate) messages: Vec<String>,+ /// Every image URL attached across the conversation, in order.+ pub(crate) images: Vec<String>,/// The session's instructions, as handed to the engine.pub(crate) instructions: Option<String>,/// Who the agent is, as handed to the engine.@@ -57,6 +59,20 @@ impl TurnEngine for ScriptedEngine {.iter().map(|message| message.content.message_text_with_tools()).collect(),+ images: request+ .messages+ .iter()+ .filter_map(|message| message.attachments.as_ref())+ .flat_map(|attachments| attachments.parts().iter())+ .filter_map(|resolved| resolved.as_ref().ok())+ .flat_map(|content| content.content.iter())+ .filter_map(|part| match part {+ attachment::AttachmentPart::Image(+ attachment::image::ImageData::StaticUrl(url),+ ) => Some(url.clone()),+ _ => None,+ })+ .collect(),instructions: request.instructions.clone(),identity: request.identity.clone(),});diff --git a/crates/agent_runtime_protocol/src/domain/action.rs b/crates/agent_runtime_protocol/src/domain/action.rsindex 5c36c1dc78..46bc4dc7f4 100644--- a/crates/agent_runtime_protocol/src/domain/action.rs+++ b/crates/agent_runtime_protocol/src/domain/action.rs@@ -6,9 +6,9 @@use std::collections::BTreeMap;use agent_client_protocol::schema::v1::{- CancelNotification, ClientRequest, CreateElicitationResponse, ElicitationAcceptAction,- ElicitationAction, ElicitationContentValue as AcpContentValue, PromptRequest, RequestId,- SessionId, SetSessionConfigOptionRequest,+ CancelNotification, ClientRequest, ContentBlock, CreateElicitationResponse,+ ElicitationAcceptAction, ElicitationAction, ElicitationContentValue as AcpContentValue,+ PromptRequest, RequestId, ResourceLink, SessionId, SetSessionConfigOptionRequest,};use agent_client_protocol::{JsonRpcMessage, RawJsonRpcMessage};use macro_uuid::Uuid;@@ -93,6 +93,81 @@ pub enum ActionError {Acp(String),}+/// A file the prompt refers to, by where the agent can fetch it.+///+/// Mirrors ACP's `resource_link` content block, which every agent must+/// accept: bytes never ride the prompt, only a URI (a static file service URL+/// in practice) with enough metadata for a client to render a chip and for+/// the agent to decide whether to fetch it. Keeping the wire shape ACP-native+/// means the harness translates without resolving anything, and the fold+/// reads the same fields back off the logged frame.+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]+#[serde(rename_all = "camelCase")]+pub struct PromptAttachment {+ /// Where the agent can fetch the file.+ pub uri: String,+ /// Display name, typically the original file name.+ pub name: String,+ /// The file's media type, when known.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub mime_type: Option<String>,+ /// Size in bytes, when known.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub size: Option<i64>,+}++impl PromptAttachment {+ /// An attachment at `uri` shown as `name`.+ pub fn new(uri: impl Into<String>, name: impl Into<String>) -> Self {+ Self {+ uri: uri.into(),+ name: name.into(),+ mime_type: None,+ size: None,+ }+ }++ /// Record the file's media type.+ #[must_use]+ pub fn mime_type(mut self, mime_type: impl Into<String>) -> Self {+ self.mime_type = Some(mime_type.into());+ self+ }++ /// Record the file's size in bytes.+ #[must_use]+ pub fn size(mut self, size: i64) -> Self {+ self.size = Some(size);+ self+ }++ /// The ACP content block this attachment travels as.+ #[must_use]+ pub fn to_content_block(&self) -> ContentBlock {+ ContentBlock::ResourceLink(+ ResourceLink::new(self.name.clone(), self.uri.clone())+ .mime_type(self.mime_type.clone())+ .size(self.size),+ )+ }++ /// Read an attachment back off a prompt's content block. `None` for the+ /// text and any block this side never sends.+ #[must_use]+ pub fn from_content_block(block: &ContentBlock) -> Option<Self> {+ let ContentBlock::ResourceLink(link) = block else {+ return None;+ };+ Some(Self {+ uri: link.uri.clone(),+ name: link.name.clone(),+ mime_type: link.mime_type.clone(),+ size: link.size,+ })+ }+}+/// Ask the agent to work on something.#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]@@ -100,6 +175,10 @@ pub enum ActionError {pub struct AgentPromptAction {/// What to tell the agent.pub prompt: String,+ /// Files the prompt refers to, in the order the user attached them.+ /// Delivered after the text as one `resource_link` block each.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub attachments: Vec<PromptAttachment>,/// Raw user text used for a visible session name when `prompt` is enriched.#[serde(skip)]name_source: Option<String>,@@ -290,8 +369,17 @@ pub enum AgentAction {impl AgentAction {/// Ask the agent to work on a text prompt.pub fn prompt(prompt: impl Into<String>) -> Self {+ Self::prompt_with_attachments(prompt, Vec::new())+ }++ /// Ask the agent to work on a text prompt that refers to `attachments`.+ pub fn prompt_with_attachments(+ prompt: impl Into<String>,+ attachments: Vec<PromptAttachment>,+ ) -> Self {Self::Prompt(AgentPromptAction {prompt: prompt.into(),+ attachments,name_source: None,})}@@ -330,17 +418,14 @@ impl AgentAction {{let params = request.params.clone()?.into_value();let request: PromptRequest = serde_json::from_value(params).ok()?;- let text = request- .prompt- .into_iter()- .filter_map(|content| match content {- agent_client_protocol::schema::v1::ContentBlock::Text(text) => {- Some(text.text)- }- _ => None,- })- .collect::<String>();- (text.trim() == COMPACT_COMMAND).then_some(Self::Compact)+ // The compaction control travels as text and nothing else.+ // A prompt that also carries a resource link is a real prompt+ // with a file attached, and reading it as the control would+ // drop that file on the way to the agent.+ let [ContentBlock::Text(text)] = request.prompt.as_slice() else {+ return None;+ };+ (text.text.trim() == COMPACT_COMMAND).then_some(Self::Compact)}RawJsonRpcMessage::Notification(notification)if CancelNotification::matches_method(¬ification.method) =>@@ -374,8 +459,24 @@ impl AgentAction {) -> Result<ToRuntimeMessage, ActionError> {match self {Self::Prompt(action) => {- let payload =- PromptRequest::new(session_id.clone(), vec![action.prompt.clone().into()]);+ // Text first, then one link per attachment: agents read the+ // prompt in order, and the text is what the links are about.+ // A file-only send carries no text block at all: an empty one+ // reads as an empty prompt to some runtimes, and the fold+ // drops it, so sending one would make the wire and the+ // transcript disagree.+ let text =+ (!action.prompt.is_empty()).then(|| ContentBlock::from(action.prompt.clone()));+ let blocks = text+ .into_iter()+ .chain(+ action+ .attachments+ .iter()+ .map(PromptAttachment::to_content_block),+ )+ .collect();+ let payload = PromptRequest::new(session_id.clone(), blocks);let params = serde_json::to_value(&payload).map_err(|error| ActionError::Acp(error.to_string()))?;let frame =diff --git a/crates/agent_runtime_protocol/src/domain/action/test.rs b/crates/agent_runtime_protocol/src/domain/action/test.rsindex b1f54cfb12..f19ebdb6b9 100644--- a/crates/agent_runtime_protocol/src/domain/action/test.rs+++ b/crates/agent_runtime_protocol/src/domain/action/test.rs@@ -324,3 +324,137 @@ fn elicitation_ids_round_trip_and_null_is_unanswerable() {None);}++#[test]+fn a_prompt_with_attachments_sends_text_then_one_resource_link_each() {+ let session_id = SessionId::new("acp-abc");+ let screenshot = PromptAttachment::new(+ "https://static.example/file/11111111-1111-4111-8111-111111111111",+ "screenshot.png",+ )+ .mime_type("image/png")+ .size(2048);+ let clip = PromptAttachment::new(+ "https://static.example/file/22222222-2222-4222-8222-222222222222",+ "clip.mp4",+ );+ let translated = AgentAction::prompt_with_attachments(+ "what is wrong in this screenshot?",+ vec![screenshot.clone(), clip.clone()],+ )+ .to_runtime(&session_id, RequestId::Str("harness:prompt:1".to_owned()))+ .unwrap();++ let ToRuntimeMessage::Acp(AcpMessage(RawJsonRpcMessage::Request(request))) = translated else {+ panic!("a prompt translates to an ACP request");+ };+ let ClientRequest::PromptRequest(parsed) =+ ClientRequest::parse_message(&request.method, &request.params).unwrap()+ else {+ panic!("a prompt translates to PromptRequest");+ };++ // Text first, so the links read as belonging to it.+ assert_eq!(parsed.prompt.len(), 3);+ let ContentBlock::Text(text) = &parsed.prompt[0] else {+ panic!("the first block is the prompt text");+ };+ assert_eq!(text.text, "what is wrong in this screenshot?");++ // Every agent must accept resource links, so no capability is checked.+ let ContentBlock::ResourceLink(link) = &parsed.prompt[1] else {+ panic!("an attachment travels as a resource link");+ };+ assert_eq!(link.uri, screenshot.uri);+ assert_eq!(link.name, "screenshot.png");+ assert_eq!(link.mime_type.as_deref(), Some("image/png"));+ assert_eq!(link.size, Some(2048));++ // The logged frame reads back to the same attachments, which is how the+ // fold renders them without a second source of truth.+ let read_back: Vec<PromptAttachment> = parsed+ .prompt+ .iter()+ .filter_map(PromptAttachment::from_content_block)+ .collect();+ assert_eq!(read_back, vec![screenshot, clip]);+}++#[test]+fn a_file_only_prompt_carries_no_text_block_at_all() {+ // The composer allows a send with files and no words. An empty text+ // block would read as an empty prompt to some runtimes, and the fold+ // drops it, so the wire must not carry one either.+ let session_id = SessionId::new("acp-abc");+ let screenshot = PromptAttachment::new(+ "https://static.example/file/11111111-1111-4111-8111-111111111111",+ "screenshot.png",+ )+ .mime_type("image/png");+ let translated = AgentAction::prompt_with_attachments("", vec![screenshot])+ .to_runtime(&session_id, RequestId::Str("harness:prompt:2".to_owned()))+ .unwrap();++ let ToRuntimeMessage::Acp(AcpMessage(RawJsonRpcMessage::Request(request))) = translated else {+ panic!("a prompt translates to an ACP request");+ };+ let ClientRequest::PromptRequest(parsed) =+ ClientRequest::parse_message(&request.method, &request.params).unwrap()+ else {+ panic!("a prompt translates to PromptRequest");+ };++ // Just the link: no leading empty text.+ assert_eq!(parsed.prompt.len(), 1);+ assert!(+ matches!(&parsed.prompt[0], ContentBlock::ResourceLink(_)),+ "a file-only prompt is links alone, got {:?}",+ parsed.prompt[0]+ );+}++#[test]+fn attachments_are_optional_on_the_wire() {+ // Clients that predate attachments post `{type, prompt}` and must keep+ // working; and a prompt without attachments must not grow a field every+ // old reader has to learn to ignore.+ let parsed: AgentAction =+ serde_json::from_value(serde_json::json!({ "type": "prompt", "prompt": "hi" })).unwrap();+ assert_eq!(parsed, AgentAction::prompt("hi"));+ let serialized = serde_json::to_value(AgentAction::prompt("hi")).unwrap();+ assert_eq!(+ serialized,+ serde_json::json!({ "type": "prompt", "prompt": "hi" })+ );++ let with = AgentAction::prompt_with_attachments(+ "look",+ vec![PromptAttachment::new("https://x/file/1", "a.png").mime_type("image/png")],+ );+ let json = serde_json::to_value(&with).unwrap();+ assert_eq!(+ json,+ serde_json::json!({+ "type": "prompt",+ "prompt": "look",+ "attachments": [{ "uri": "https://x/file/1", "name": "a.png", "mimeType": "image/png" }]+ })+ );+ assert_eq!(serde_json::from_value::<AgentAction>(json).unwrap(), with);+}++#[test]+fn a_compact_command_with_attachments_is_still_a_plain_prompt() {+ // Only the text decides whether a prompt is the compaction control; an+ // attached file rides a real prompt, never a control.+ let session_id = SessionId::new("acp-abc");+ let message = AgentAction::prompt_with_attachments(+ COMPACT_COMMAND,+ vec![PromptAttachment::new("https://x/file/1", "a.png")],+ )+ .to_runtime(&session_id, RequestId::Str("p".to_owned()))+ .unwrap();+ // A resource link alongside the text is what makes it a real prompt: the+ // control carries text and nothing else.+ assert_eq!(AgentAction::control_from_runtime(&message), None);+}diff --git a/crates/agent_session/src/domain/model.rs b/crates/agent_session/src/domain/model.rsindex ea800afa69..4bfe5da605 100644--- a/crates/agent_session/src/domain/model.rs+++ b/crates/agent_session/src/domain/model.rs@@ -336,6 +336,10 @@ pub struct QueuedActionDto {/// replaces.#[serde(default, skip_serializing_if = "Option::is_none")]pub prompt: Option<String>,+ /// Files the prompt refers to, for prompts only. Kept through an edit,+ /// which replaces the text alone.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub attachments: Vec<agent_runtime_protocol::domain::action::PromptAttachment>,/// The user who queued it, absent when a bot acted on nobody's behalf.#[serde(default, skip_serializing_if = "Option::is_none")]pub actor_user_id: Option<String>,@@ -346,14 +350,17 @@ pub struct QueuedActionDto {impl From<super::ports::QueuedControl> for QueuedActionDto {fn from(queued: super::ports::QueuedControl) -> Self {use agent_runtime_protocol::domain::action::AgentAction;- let prompt = match &queued.action {- AgentAction::Prompt(action) => Some(action.prompt.clone()),- _ => None,+ let (prompt, attachments) = match &queued.action {+ AgentAction::Prompt(action) => {+ (Some(action.prompt.clone()), action.attachments.clone())+ }+ _ => (None, Vec::new()),};Self {action_id: queued.action_id,kind: queued.action.as_ref().to_owned(),prompt,+ attachments,actor_user_id: queued.actor.map(|actor| actor.to_string()),created_at: queued.created_at,}diff --git a/crates/macro_aws_config/src/lib.rs b/crates/macro_aws_config/src/lib.rsindex 57e12ebb9d..081a7e04ce 100644--- a/crates/macro_aws_config/src/lib.rs+++ b/crates/macro_aws_config/src/lib.rs@@ -10,6 +10,12 @@ maybe_env_var! {pub struct LocalAwsUrl;}+maybe_env_var! {+ /// Browser-facing LocalStack origin for a local stack with mapped ports.+ #[derive(Clone)]+ pub struct LocalAwsPublicUrl;+}+/// Creates an S3 client#[cfg(feature = "s3")]pub async fn s3_client() -> aws_sdk_s3::Client {@@ -56,7 +62,7 @@ pub fn is_local_aws() -> bool {}/// internal method to transform the local aws url-fn transform_local_url(url: &str) -> String {+fn transform_local_url(url: &str, public_url: Option<&str>) -> String {// NOTE: it is ok to use expect as this is only run locallylet parsed = url::Url::parse(url).expect("valid url");let host = parsed.host_str().unwrap();@@ -64,11 +70,15 @@ fn transform_local_url(url: &str) -> String {let path = parsed.path();let query = parsed.query().map(|q| format!("?{q}")).unwrap_or_default();+ let origin = public_url+ .map(|url| url.trim_end_matches('/').to_owned())+ .unwrap_or_else(|| format!("http://localhost:{port}"));+// Path-style LocalStack URLs generated inside Docker use `localstack` as// the host, which the browser on the host machine cannot resolve. Keep the- // existing path (`/{bucket}/{key}`) and only swap the host to localhost.+ // existing path (`/{bucket}/{key}`) and use the browser-facing origin.if host == "localstack" || host == "localhost" {- return format!("http://localhost:{port}{path}{query}");+ return format!("{origin}{path}{query}");}// hostname should be in the form {asset}.localstack or {asset}.localhost@@ -77,35 +87,37 @@ fn transform_local_url(url: &str) -> String {.or_else(|| host.strip_suffix(".localhost")).unwrap();- format!("http://localhost:{port}/{asset}{path}{query}")+ format!("{origin}/{asset}{path}{query}")}/// Transforms a localstack url into one that will work within the app/// For example, presigned urls for localstack come out as `http://{BUCKET_NAME}.localstack:{PORT}`/// but we need them to be formulated as `http://localhost:{PORT}/bucket-name`.+/// `LOCAL_AWS_PUBLIC_URL`, when set by the local stack, supplies the browser-facing+/// origin so named instances use their published port instead of Docker's port.pub fn transform_aws_url(url: &str) -> String {if is_local_aws() {- return transform_local_url(url);+ let public_url = LocalAwsPublicUrl::new();+ return transform_local_url(url, public_url.as_ref().map(|url| url.as_ref()));}url.to_string()}/// internal method to transform a browser-facing local url into one reachable/// from inside the docker network-fn transform_internal_url(url: &str) -> String {+fn transform_internal_url(url: &str, local_aws_url: &str) -> String {// NOTE: it is ok to use expect as this is only run locallylet parsed = url::Url::parse(url).expect("valid url");let host = parsed.host_str().unwrap();- let port = parsed.port().unwrap_or(4566);let path = parsed.path();let query = parsed.query().map(|q| format!("?{q}")).unwrap_or_default();// Browser-facing local URLs use `localhost`, which inside a container- // resolves to the container itself. Swap it for the `localstack` service- // hostname so service-to-service fetches reach LocalStack. Leave any other+ // resolves to the container itself. Use the SDK endpoint, including its+ // internal port, so service-to-service fetches reach LocalStack. Leave any other// host untouched.if host == "localhost" || host == "localstack" {- return format!("http://localstack:{port}{path}{query}");+ return format!("{}{path}{query}", local_aws_url.trim_end_matches('/'));}url.to_string()@@ -120,8 +132,8 @@ fn transform_internal_url(url: &str) -> String {/// Docker network must use the `localstack` service hostname instead. No-op/// outside local AWS.pub fn transform_aws_url_for_internal_fetch(url: &str) -> String {- if is_local_aws() {- return transform_internal_url(url);+ if let Some(local_aws_url) = LocalAwsUrl::new() {+ return transform_internal_url(url, local_aws_url.as_ref());}url.to_string()}diff --git a/crates/macro_aws_config/src/test.rs b/crates/macro_aws_config/src/test.rsindex b5d18fa200..b935ab79ba 100644--- a/crates/macro_aws_config/src/test.rs+++ b/crates/macro_aws_config/src/test.rs@@ -5,7 +5,7 @@ fn test_transform_path_style_localstack() {let input = "http://localstack:4566/doc-storage/macro%7Cteo%40macro.com/doc/1?x-id=PutObject";let expected = "http://localhost:4566/doc-storage/macro%7Cteo%40macro.com/doc/1?x-id=PutObject";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -14,7 +14,7 @@ fn test_transform_path_style_localhost() {let input = "http://localhost:4566/doc-storage/macro%7Cteo%40macro.com/doc/1?x-id=PutObject";let expected = "http://localhost:4566/doc-storage/macro%7Cteo%40macro.com/doc/1?x-id=PutObject";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -24,7 +24,7 @@ fn test_transform_presigned_url_with_query_params_localstack() {let expected = "http://localhost:4566/static-file-storage/file/a31e9af3-dd26-4531-b367-bfbbbac706cc?x-id=PutObject&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ANOTREAL%2F20260203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260203T184319Z&X-Amz-Expires=120&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=deed6b123a18335b61567eaf8ddb7ea6e00bf264cfd80cb0f4031860235dc077";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -34,7 +34,7 @@ fn test_transform_presigned_url_with_query_params_localhost() {let expected = "http://localhost:4566/static-file-storage/file/a31e9af3-dd26-4531-b367-bfbbbac706cc?x-id=PutObject&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ANOTREAL%2F20260203%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20260203T184319Z&X-Amz-Expires=120&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Signature=deed6b123a18335b61567eaf8ddb7ea6e00bf264cfd80cb0f4031860235dc077";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -43,7 +43,7 @@ fn test_transform_simple_url_localstack() {let input = "http://my-bucket.localstack:4566/some/path/to/file.txt";let expected = "http://localhost:4566/my-bucket/some/path/to/file.txt";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -52,7 +52,7 @@ fn test_transform_simple_url_localhost() {let input = "http://my-bucket.localhost:4566/some/path/to/file.txt";let expected = "http://localhost:4566/my-bucket/some/path/to/file.txt";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -61,7 +61,7 @@ fn test_transform_url_root_path() {let input = "http://bucket.localstack:4566/";let expected = "http://localhost:4566/bucket/";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -70,7 +70,7 @@ fn test_transform_url_no_path() {let input = "http://bucket.localhost:4566";let expected = "http://localhost:4566/bucket/";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -79,7 +79,7 @@ fn test_transform_url_with_simple_query() {let input = "http://test-bucket.localstack:4566/key?versionId=123";let expected = "http://localhost:4566/test-bucket/key?versionId=123";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -88,7 +88,7 @@ fn test_transform_url_with_simple_query_localhost() {let input = "http://test-bucket.localhost:4566/key?versionId=123";let expected = "http://localhost:4566/test-bucket/key?versionId=123";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -97,7 +97,7 @@ fn test_transform_url_default_port_localstack() {let input = "http://bucket.localstack/path/file.txt";let expected = "http://localhost:4566/bucket/path/file.txt";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -106,7 +106,7 @@ fn test_transform_url_default_port_localhost() {let input = "http://bucket.localhost/path/file.txt";let expected = "http://localhost:4566/bucket/path/file.txt";- let result = transform_local_url(input);+ let result = transform_local_url(input, None);assert_eq!(result, expected);}@@ -115,7 +115,7 @@ fn test_internal_fetch_rewrites_localhost_to_localstack() {let input = "http://localhost:4566/doc-storage/macro%7Cteo%40macro.com/doc/1";let expected = "http://localstack:4566/doc-storage/macro%7Cteo%40macro.com/doc/1";- let result = transform_internal_url(input);+ let result = transform_internal_url(input, "http://localstack:4566");assert_eq!(result, expected);}@@ -124,7 +124,7 @@ fn test_internal_fetch_preserves_query_params() {let input = "http://localhost:4566/doc-storage/key?versionId=123";let expected = "http://localstack:4566/doc-storage/key?versionId=123";- let result = transform_internal_url(input);+ let result = transform_internal_url(input, "http://localstack:4566");assert_eq!(result, expected);}@@ -133,7 +133,7 @@ fn test_internal_fetch_localstack_is_idempotent() {let input = "http://localstack:4566/doc-storage/key";let expected = "http://localstack:4566/doc-storage/key";- let result = transform_internal_url(input);+ let result = transform_internal_url(input, "http://localstack:4566");assert_eq!(result, expected);}@@ -142,6 +142,33 @@ fn test_internal_fetch_leaves_remote_url_untouched() {let input = "https://d123.cloudfront.net/doc-storage/key?Signature=abc";let expected = "https://d123.cloudfront.net/doc-storage/key?Signature=abc";- let result = transform_internal_url(input);+ let result = transform_internal_url(input, "http://localstack:4566");assert_eq!(result, expected);}++#[test]+fn named_instance_uses_public_port_and_preserves_signature_and_encoded_key() {+ for input in [+ "http://localstack:4566/static-file-storage/file/pasted%20image.png?X-Amz-Signature=test&x-id=PutObject",+ "http://static-file-storage.localstack:4566/file/pasted%20image.png?X-Amz-Signature=test&x-id=PutObject",+ ] {+ let public = transform_local_url(input, Some("http://localhost:29806"));+ assert_eq!(+ public,+ "http://localhost:29806/static-file-storage/file/pasted%20image.png?X-Amz-Signature=test&x-id=PutObject"+ );+ assert_eq!(+ transform_internal_url(&public, "http://localstack:4566"),+ "http://localstack:4566/static-file-storage/file/pasted%20image.png?X-Amz-Signature=test&x-id=PutObject"+ );+ }+}++#[test]+fn host_process_keeps_its_configured_localstack_endpoint_for_internal_fetch() {+ let input = "http://localhost:29806/doc-storage/key";+ assert_eq!(+ transform_internal_url(input, "http://localhost:29806"),+ input+ );+}diff --git a/crates/non_empty/src/lib.rs b/crates/non_empty/src/lib.rsindex 769f6f3318..b7df9ea03c 100644--- a/crates/non_empty/src/lib.rs+++ b/crates/non_empty/src/lib.rs@@ -82,6 +82,18 @@ impl<T> NonEmpty<Vec<T>> {self.inner.push(value);}+ /// Insert an element at `index`, shifting everything after it.+ ///+ /// Cannot break the invariant for the same reason as [`Self::push`]: the+ /// vector only grows.+ ///+ /// # Panics+ ///+ /// Panics if `index > len`, as [`Vec::insert`] does.+ pub fn insert(&mut self, index: usize, value: T) {+ self.inner.insert(index, value);+ }+/// A mutable reference to the element at `index`, or `None` when the/// index is out of bounds.///diff --git a/crates/non_empty/src/test.rs b/crates/non_empty/src/test.rsindex ad54263f0a..f53949383b 100644--- a/crates/non_empty/src/test.rs+++ b/crates/non_empty/src/test.rs@@ -129,3 +129,11 @@ fn test_last_mut_needs_no_option() {*vec.last_mut() = 20;assert_eq!(vec.inner(), &vec![10, 20]);}++#[test]+fn insert_grows_in_place() {+ let mut list = NonEmpty::one("b");+ list.insert(0, "a");+ list.push("c");+ assert_eq!(list.inner(), &vec!["a", "b", "c"]);+}diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 9a419f9673..f3ebd303a8 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -315,6 +315,20 @@ latest turn.access and get an `agent_session_mentioned` notification that opens the session; a viewer'smention only notifies people who could already open it.+In Home, a new Agents conversation, and an existing agent session, files can be+attached to a prompt three ways: drop them anywhere on the composer (a+"Drop files here to send them to the agent" overlay appears), paste them from the+clipboard, or use the paperclip **`Attach files`** button. Every file uploads to the+static file service and shows as a chip above the text (media thumbnails, document+pills with a remove `×`); **Send** is disabled while an upload is pending. The agent+receives each file as an ACP `resource_link` (a URL it can fetch) after the prompt text,+and the sent prompt renders its files in the transcript (image thumbnails, video+previews, file chips that open the file). A prompt may be files only, including the+first message in a new conversation. Uploading attachments survive switching the+agent or opening repository settings; sending clears the attachment previews.+Queued prompts+list their attached file names under the text; editing a queued prompt keeps them.+On mobile the composer (and any queued prompts above it) floats in the bottomaccessory region above the dock — same placement as channel and AI chat — so itstays tappable and clear of the home indicator. The box is full width; the textdiff --git a/docs/RUNNING_LOCALLY.md b/docs/RUNNING_LOCALLY.mdindex 1abbab2864..d635606036 100644--- a/docs/RUNNING_LOCALLY.md+++ b/docs/RUNNING_LOCALLY.md@@ -115,6 +115,13 @@ When startup finishes, the command prints the frontend URL and the important serOpen the frontend URL in your browser.+The local environment supplies both `LOCAL_AWS_URL` (the container endpoint)+and `LOCAL_AWS_PUBLIC_URL` (the instance's published LocalStack port). SFS and+other presigned uploads use the public endpoint in browser-facing URLs. If an+upload attempts `localhost:4566` on a named instance, rebuild the service and+reload its generated environment; named instances publish storage on their own+port.+The stack does not create accounts in advance. Passwordless login creates a useron demand. Register with any email address. FusionAuth sends you a one-time codeby email. That email lands in **Mailpit** at http://localhost:8025, not in a realdiff --git a/packages/sdk/generated/agent-harness/index.ts b/packages/sdk/generated/agent-harness/index.tsindex 06c4807a04..5cfa1deab5 100644--- a/packages/sdk/generated/agent-harness/index.ts+++ b/packages/sdk/generated/agent-harness/index.ts@@ -1,4 +1,4 @@// This file is auto-generated by @hey-api/openapi-tsexport { type Options, Sdk } from './sdk.gen';-export type { AgentAction, AgentActionId, AgentModelDto, AgentModelsStatusDto, AgentPromptAction, AgentRepositoriesResponse, AgentRepositoryDto, AgentRespondElicitationAction, AgentSessionLogEntryDto, AgentSessionLogResponse, AgentSessionPreviewData, AgentSessionPreviewDto, AgentSessionQueueResponse, AgentSessionResponse, AgentSetModelAction, BotId, ClientOptions, CompleteData, CompleteErrors, CompleteRequest, CompleteResponse, CompleteResponses, ControlAgentSessionData, ControlAgentSessionError, ControlAgentSessionErrors, ControlAgentSessionResponse, ControlAgentSessionResponses, ControlRequest, ControlResponse, ControlStatusDto, CreateAgentSessionData, CreateAgentSessionError, CreateAgentSessionErrors, CreateAgentSessionRequest, CreateAgentSessionResponse, CreateAgentSessionResponse2, CreateAgentSessionResponses, CreateSessionThread, DeleteAgentSessionData, DeleteAgentSessionError, DeleteAgentSessionErrors, DeleteAgentSessionResponses, DisconnectData, DisconnectErrors, DisconnectResponse, DisconnectResponses, DocumentId, EditQueuedActionData, EditQueuedActionError, EditQueuedActionErrors, EditQueuedActionRequest, EditQueuedActionResponse, EditQueuedActionResponses, ElicitationAnswer, ElicitationContentValue, ElicitationRequestId, EmptyRequest, ExternalSessionResponse, GetAgentSandboxSizeData, GetAgentSandboxSizeError, GetAgentSandboxSizeErrors, GetAgentSandboxSizeResponse, GetAgentSandboxSizeResponses, GetAgentSessionData, GetAgentSessionError, GetAgentSessionErrors, GetAgentSessionLogData, GetAgentSessionLogError, GetAgentSessionLogErrors, GetAgentSessionLogResponse, GetAgentSessionLogResponses, GetAgentSessionQueueData, GetAgentSessionQueueError, GetAgentSessionQueueErrors, GetAgentSessionQueueResponse, GetAgentSessionQueueResponses, GetAgentSessionResponse, GetAgentSessionResponses, ListAgentRepositoriesData, ListAgentRepositoriesErrors, ListAgentRepositoriesResponse, ListAgentRepositoriesResponses, LoadAgentModelsHandlerData, LoadAgentModelsHandlerErrors, LoadAgentModelsHandlerResponse, LoadAgentModelsHandlerResponses, LoadAgentModelsRequest, LoadAgentModelsResponse, LogDirectionDto, LogFrameDto, MessageParent, ModelHarnessDto, PreviewAgentSessionsData, PreviewAgentSessionsError, PreviewAgentSessionsErrors, PreviewAgentSessionsRequest, PreviewAgentSessionsResponse, PreviewAgentSessionsResponse2, PreviewAgentSessionsResponses, PutAgentSandboxSizeData, PutAgentSandboxSizeError, PutAgentSandboxSizeErrors, PutAgentSandboxSizeResponse, PutAgentSandboxSizeResponses, PutAgentSessionSandboxSizeData, PutAgentSessionSandboxSizeError, PutAgentSessionSandboxSizeErrors, PutAgentSessionSandboxSizeResponse, PutAgentSessionSandboxSizeResponses, QueuedActionDto, RemoveQueuedActionData, RemoveQueuedActionError, RemoveQueuedActionErrors, RemoveQueuedActionResponse, RemoveQueuedActionResponses, RenameAgentSessionData, RenameAgentSessionError, RenameAgentSessionErrors, RenameAgentSessionRequest, RenameAgentSessionResponse, RenameAgentSessionResponses, SandboxSize, SandboxSizeBody, SessionBot, SessionStatusDto, StartData, StartErrors, StartResponse, StartResponse2, StartResponses, StatusData, StatusErrors, StatusResponse, StatusResponse2, StatusResponses, WithAgentSessionId } from './types.gen';+export type { AgentAction, AgentActionId, AgentModelDto, AgentModelsStatusDto, AgentPromptAction, AgentRepositoriesResponse, AgentRepositoryDto, AgentRespondElicitationAction, AgentSessionLogEntryDto, AgentSessionLogResponse, AgentSessionPreviewData, AgentSessionPreviewDto, AgentSessionQueueResponse, AgentSessionResponse, AgentSetModelAction, BotId, ClientOptions, CompleteData, CompleteErrors, CompleteRequest, CompleteResponse, CompleteResponses, ControlAgentSessionData, ControlAgentSessionError, ControlAgentSessionErrors, ControlAgentSessionResponse, ControlAgentSessionResponses, ControlRequest, ControlResponse, ControlStatusDto, CreateAgentSessionData, CreateAgentSessionError, CreateAgentSessionErrors, CreateAgentSessionRequest, CreateAgentSessionResponse, CreateAgentSessionResponse2, CreateAgentSessionResponses, CreateSessionThread, DeleteAgentSessionData, DeleteAgentSessionError, DeleteAgentSessionErrors, DeleteAgentSessionResponses, DisconnectData, DisconnectErrors, DisconnectResponse, DisconnectResponses, DocumentId, EditQueuedActionData, EditQueuedActionError, EditQueuedActionErrors, EditQueuedActionRequest, EditQueuedActionResponse, EditQueuedActionResponses, ElicitationAnswer, ElicitationContentValue, ElicitationRequestId, EmptyRequest, ExternalSessionResponse, GetAgentSandboxSizeData, GetAgentSandboxSizeError, GetAgentSandboxSizeErrors, GetAgentSandboxSizeResponse, GetAgentSandboxSizeResponses, GetAgentSessionData, GetAgentSessionError, GetAgentSessionErrors, GetAgentSessionLogData, GetAgentSessionLogError, GetAgentSessionLogErrors, GetAgentSessionLogResponse, GetAgentSessionLogResponses, GetAgentSessionQueueData, GetAgentSessionQueueError, GetAgentSessionQueueErrors, GetAgentSessionQueueResponse, GetAgentSessionQueueResponses, GetAgentSessionResponse, GetAgentSessionResponses, ListAgentRepositoriesData, ListAgentRepositoriesErrors, ListAgentRepositoriesResponse, ListAgentRepositoriesResponses, LoadAgentModelsHandlerData, LoadAgentModelsHandlerErrors, LoadAgentModelsHandlerResponse, LoadAgentModelsHandlerResponses, LoadAgentModelsRequest, LoadAgentModelsResponse, LogDirectionDto, LogFrameDto, MessageParent, ModelHarnessDto, PreviewAgentSessionsData, PreviewAgentSessionsError, PreviewAgentSessionsErrors, PreviewAgentSessionsRequest, PreviewAgentSessionsResponse, PreviewAgentSessionsResponse2, PreviewAgentSessionsResponses, PromptAttachment, PutAgentSandboxSizeData, PutAgentSandboxSizeError, PutAgentSandboxSizeErrors, PutAgentSandboxSizeResponse, PutAgentSandboxSizeResponses, PutAgentSessionSandboxSizeData, PutAgentSessionSandboxSizeError, PutAgentSessionSandboxSizeErrors, PutAgentSessionSandboxSizeResponse, PutAgentSessionSandboxSizeResponses, QueuedActionDto, RemoveQueuedActionData, RemoveQueuedActionError, RemoveQueuedActionErrors, RemoveQueuedActionResponse, RemoveQueuedActionResponses, RenameAgentSessionData, RenameAgentSessionError, RenameAgentSessionErrors, RenameAgentSessionRequest, RenameAgentSessionResponse, RenameAgentSessionResponses, SandboxSize, SandboxSizeBody, SessionBot, SessionStatusDto, StartData, StartErrors, StartResponse, StartResponse2, StartResponses, StatusData, StatusErrors, StatusResponse, StatusResponse2, StatusResponses, WithAgentSessionId } from './types.gen';diff --git a/packages/sdk/generated/agent-harness/types.gen.ts b/packages/sdk/generated/agent-harness/types.gen.tsindex ffc44ee603..559151e2de 100644--- a/packages/sdk/generated/agent-harness/types.gen.ts+++ b/packages/sdk/generated/agent-harness/types.gen.ts@@ -65,6 +65,11 @@ export type AgentModelsStatusDto = 'available' | 'unsupported';* Ask the agent to work on something.*/export type AgentPromptAction = {+ /**+ * Files the prompt refers to, in the order the user attached them.+ * Delivered after the text as one `resource_link` block each.+ */+ attachments?: Array<PromptAttachment>;/*** What to tell the agent.*/@@ -695,6 +700,35 @@ export type PreviewAgentSessionsResponse = {previews: Array<AgentSessionPreviewDto>;};+/**+ * A file the prompt refers to, by where the agent can fetch it.+ *+ * Mirrors ACP's `resource_link` content block, which every agent must+ * accept: bytes never ride the prompt, only a URI (a static file service URL+ * in practice) with enough metadata for a client to render a chip and for+ * the agent to decide whether to fetch it. Keeping the wire shape ACP-native+ * means the harness translates without resolving anything, and the fold+ * reads the same fields back off the logged frame.+ */+export type PromptAttachment = {+ /**+ * The file's media type, when known.+ */+ mimeType?: string | null;+ /**+ * Display name, typically the original file name.+ */+ name: string;+ /**+ * Size in bytes, when known.+ */+ size?: number | null;+ /**+ * Where the agent can fetch the file.+ */+ uri: string;+};+/*** One action waiting in a session's queue.*@@ -709,6 +743,11 @@ export type QueuedActionDto = {* The user who queued it, absent when a bot acted on nobody's behalf.*/actorUserId?: string | null;+ /**+ * Files the prompt refers to, for prompts only. Kept through an edit,+ * which replaces the text alone.+ */+ attachments?: Array<PromptAttachment>;/*** When it was accepted.*/diff --git a/packages/sdk/specs/agent-harness.json b/packages/sdk/specs/agent-harness.jsonindex 0e62286fae..2b5ff0358f 100644--- a/packages/sdk/specs/agent-harness.json+++ b/packages/sdk/specs/agent-harness.json@@ -1203,6 +1203,13 @@"description": "Ask the agent to work on something.","required": ["prompt"],"properties": {+ "attachments": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/PromptAttachment"+ },+ "description": "Files the prompt refers to, in the order the user attached them.\nDelivered after the text as one `resource_link` block each."+ },"prompt": {"type": "string","description": "What to tell the agent."@@ -1992,6 +1999,30 @@}}},+ "PromptAttachment": {+ "type": "object",+ "description": "A file the prompt refers to, by where the agent can fetch it.\n\nMirrors ACP's `resource_link` content block, which every agent must\naccept: bytes never ride the prompt, only a URI (a static file service URL\nin practice) with enough metadata for a client to render a chip and for\nthe agent to decide whether to fetch it. Keeping the wire shape ACP-native\nmeans the harness translates without resolving anything, and the fold\nreads the same fields back off the logged frame.",+ "required": ["uri", "name"],+ "properties": {+ "mimeType": {+ "type": ["string", "null"],+ "description": "The file's media type, when known."+ },+ "name": {+ "type": "string",+ "description": "Display name, typically the original file name."+ },+ "size": {+ "type": ["integer", "null"],+ "format": "int64",+ "description": "Size in bytes, when known."+ },+ "uri": {+ "type": "string",+ "description": "Where the agent can fetch the file."+ }+ }+ },"QueuedActionDto": {"type": "object","description": "One action waiting in a session's queue.\n\nClients deserialize this, so both derives are used.",@@ -2005,6 +2036,13 @@"type": ["string", "null"],"description": "The user who queued it, absent when a bot acted on nobody's behalf."},+ "attachments": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/PromptAttachment"+ },+ "description": "Files the prompt refers to, for prompts only. Kept through an edit,\nwhich replaces the text alone."+ },"createdAt": {"type": "string","format": "date-time",diff --git a/packages/sdk/src/entities/agent-sessions/agent-session.ts b/packages/sdk/src/entities/agent-sessions/agent-session.tsindex ddf7ac348b..ab924dbed0 100644--- a/packages/sdk/src/entities/agent-sessions/agent-session.ts+++ b/packages/sdk/src/entities/agent-sessions/agent-session.ts@@ -3,6 +3,7 @@ import type {AgentSessionLogResponse,AgentSessionResponse,ControlResponse,+ PromptAttachment,SandboxSize,} from '../../../generated/agent-harness/types.gen';import { unwrap } from '../../utils';@@ -179,9 +180,22 @@ export class AgentSession extends MacroEntity<AgentSessionResponse> {);}- /** Send a prompt to the session — sugar over {@link control}. */- prompt(text: string): Promise<ControlResponse> {- return this.control({ type: 'prompt', prompt: text });+ /**+ * Send a prompt to the session — sugar over {@link control}.+ *+ * `attachments` are files the prompt refers to, each by a URL the agent+ * can fetch (a static file service URL in practice); they reach the agent+ * as ACP `resource_link` blocks after the text.+ */+ prompt(+ text: string,+ attachments?: PromptAttachment[],+ ): Promise<ControlResponse> {+ return this.control({+ type: 'prompt',+ prompt: text,+ ...(attachments && attachments.length > 0 ? { attachments } : {}),+ });}/**diff --git a/packages/sdk/src/entities/agent-sessions/queued-action.ts b/packages/sdk/src/entities/agent-sessions/queued-action.tsindex a622f62b8d..991d641eec 100644--- a/packages/sdk/src/entities/agent-sessions/queued-action.ts+++ b/packages/sdk/src/entities/agent-sessions/queued-action.ts@@ -1,4 +1,7 @@-import type { QueuedActionDto } from '../../../generated/agent-harness/types.gen';+import type {+ PromptAttachment,+ QueuedActionDto,+} from '../../../generated/agent-harness/types.gen';import { unwrap } from '../../utils';import type { MacroClient } from '../../utils/client';@@ -47,6 +50,11 @@ export class QueuedAction {return this.dto.prompt ?? undefined;}+ /** Files the prompt refers to; empty for a compact. Kept through an edit. */+ get attachments(): PromptAttachment[] {+ return this.dto.attachments ?? [];+ }+/** The user who queued it, absent when a bot acted on nobody's behalf. */get actorUserId(): string | undefined {return this.dto.actorUserId ?? undefined;diff --git a/services/agent_harness_service/src/api/swagger.rs b/services/agent_harness_service/src/api/swagger.rsindex df21d7609f..e1d1641071 100644--- a/services/agent_harness_service/src/api/swagger.rs+++ b/services/agent_harness_service/src/api/swagger.rs@@ -5,7 +5,7 @@ use agent_harness::inbound::model_load::{ModelHarnessDto,};use agent_harness::inbound::repositories::{self, AgentRepositoriesResponse, AgentRepositoryDto};-use agent_runtime_protocol::domain::action::{AgentAction, AgentActionId};+use agent_runtime_protocol::domain::action::{AgentAction, AgentActionId, PromptAttachment};use agent_session::domain::model::{SandboxSize, SessionBot};use agent_session::inbound::axum_router::{self, AgentSessionLogEntryDto, AgentSessionLogResponse, AgentSessionPreviewData,@@ -75,6 +75,7 @@ impl Modify for SecurityAddon {EditQueuedActionRequest,AgentAction,AgentActionId,+ PromptAttachment,AgentSessionResponse,PreviewAgentSessionsRequest,PreviewAgentSessionsResponse,diff --git a/services/agent_harness_service/src/main.rs b/services/agent_harness_service/src/main.rsindex a6c31fd2e2..728b0005b5 100644--- a/services/agent_harness_service/src/main.rs+++ b/services/agent_harness_service/src/main.rs@@ -32,7 +32,7 @@ use agent_egress::outbound::session_authority::StoredTokenSessionAuthority;use agent_fold::domain::service::FoldedMessageService;use agent_harness::domain::model::{AgentKind, AgentRuntimeConfig, HarnessCommand, HarnessDefaults, SessionDefaults,- SessionRepository,+ SessionRepository, StaticFileLinks,};use agent_harness::domain::model_load::AgentModelsServiceImpl;use agent_harness::domain::ports::AgentRuntimeDirectory as _;@@ -116,6 +116,7 @@ use macro_event_broker::{};use macro_service_urls::{AgentHarnessEgressUrl, ConnectionGatewayUrl, LexicalServiceUrl, McpServiceUrl,+ StaticFileServiceUrl,};use model_providers::{CursorModels, InMemoryModels, MacrodModels, VisibleHarnessAccess};use pipedream_mcp::outbound::api::{PipedreamClient, PipedreamConfig};@@ -340,6 +341,10 @@ async fn run() -> anyhow::Result<()> {};let container_shutdown = sandbox.clone();+ // Channel attachments reach a prompt as links the agent can fetch, so+ // the trigger router needs to know where static files are served from.+ let static_file_links = StaticFileLinks::new(StaticFileServiceUrl::new()?.to_string());+// Tracks event publishes the in-memory agent's tool context starts;// closed and drained on shutdown so nothing is dropped mid-publish.let event_broker_tracker = tokio_util::task::TaskTracker::new();@@ -1077,7 +1082,7 @@ async fn run() -> anyhow::Result<()> {Some(bot_id) => runtime_directory.runtime_for(bot_id).await?,None => None,};- let routed = match route_agent_trigger(trigger_event, runtime) {+ let routed = match route_agent_trigger(trigger_event, runtime, &static_file_links) {Ok(routed) => routed,Err(skipped) => {// Info, not debug: a skip is the last visible tracediff --git a/tooling/xtask/crates/xtask_local/src/local/local_env.rs b/tooling/xtask/crates/xtask_local/src/local/local_env.rsindex 25ea7ac5fe..706e25d714 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env.rs@@ -77,7 +77,7 @@ impl LocalEnv {"http://localhost:{}/static-file",instance.port(Port::Proxy)),- infra: InfraEnv::local(),+ infra: InfraEnv::local(instance),storage: StorageEnv::local(),queues: QueueEnv::local(),mail: MailEnv::local(),@@ -143,16 +143,18 @@ struct InfraEnv {redis_uri: String,opensearch_url: String,local_aws_url: String,+ local_aws_public_url: String,kafka_brokers: String,}impl InfraEnv {- fn local() -> Self {+ fn local(instance: &Instance) -> Self {InfraEnv {database_url: "postgres://user:password@postgres:5432/macrodb".into(),redis_uri: "redis://redis:6379".into(),opensearch_url: "http://search:9200".into(),local_aws_url: "http://localstack:4566".into(),+ local_aws_public_url: format!("http://localhost:{}", instance.port(Port::LocalStack)),// The broker's in-network listener (see docker/docker-compose-databases.yml);// host processes use localhost:9092 instead.kafka_brokers: "kafka:29092".into(),@@ -170,6 +172,10 @@ impl InfraEnv {env.insert("LAST_ONLINE_REDIS_URI".into(), self.redis_uri.clone());env.insert("OPENSEARCH_URL".into(), self.opensearch_url.clone());env.insert("LOCAL_AWS_URL".into(), self.local_aws_url.clone());+ env.insert(+ "LOCAL_AWS_PUBLIC_URL".into(),+ self.local_aws_public_url.clone(),+ );env.insert("KAFKA_BROKERS".into(), self.kafka_brokers.clone());// In-network services resolve the gateway through the OVERRIDE_ var;// without it the resolver's Environment::Local defaultdiff --git a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rsindex 91ecb57f88..a6dfe890b5 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs@@ -26,6 +26,7 @@ fn emits_required_keys() {"REDIS_URI","OPENSEARCH_URL","LOCAL_AWS_URL",+ "LOCAL_AWS_PUBLIC_URL","AWS_ACCESS_KEY_ID","STATIC_STORAGE_BUCKET","CONNECTION_GATEWAY_TABLE",@@ -418,3 +419,14 @@ fn the_public_tunnel_overrides_the_egress_service_url() {);assert!(!env.contains_key("EGRESS_BASE_URL"));}++#[test]+fn named_instance_separates_browser_and_container_aws_endpoints() {+ let instance = Instance::derive(Some("image"), None).expect("named instance derives");+ let env = LocalEnv::for_instance(Mode::Local, &instance, false, None).to_env();+ assert_eq!(env["LOCAL_AWS_URL"], "http://localstack:4566");+ assert_eq!(+ env["LOCAL_AWS_PUBLIC_URL"],+ format!("http://localhost:{}", instance.port(Port::LocalStack))+ );+}