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(agents): open ask agent actions in the new-conversation composer (#9166)
Jacob Beckerman1dcdfc27ce8b
diff --git a/apps/web/src/features/agents-view/primitives/open-composer.test.ts b/apps/web/src/features/agents-view/primitives/open-composer.test.tsindex e13cafdcf4..8f665b7bb9 100644--- a/apps/web/src/features/agents-view/primitives/open-composer.test.ts+++ b/apps/web/src/features/agents-view/primitives/open-composer.test.ts@@ -96,6 +96,38 @@ describe('openAgentComposer', () => {expect(home.textContent).toBe('Keep this draft');});+ it('seeds the composer draft in a new split', () => {+ const manager = layout();+ openAgentComposer(manager, true, { draft: '@Plan ' });+ expect(manager.openWithSplit).toHaveBeenCalledWith(+ expect.objectContaining({+ params: expect.objectContaining({ draft: '@Plan ' }),+ }),+ { referredFrom: 'launcher', preferNewSplit: true }+ );+ });++ it('replaces the draft when an existing Agents split is reused', () => {+ const manager = layout(true);+ openAgentComposer(manager, true, { draft: 'first' });+ openAgentComposer(manager, true, { draft: 'second' });+ expect(manager.content().params).toEqual(+ expect.objectContaining({ draft: 'second' })+ );+ });++ it('opens in the given split instead of placing a new one', () => {+ const manager = layout();+ const handle = { id: 'search-split' } as unknown as SplitHandle;+ openAgentComposer(manager, false, { draft: '', handle });+ expect(manager.openWithSplit).toHaveBeenCalledWith(expect.anything(), {+ referredFrom: 'launcher',+ preferNewSplit: false,+ handle,+ allowDuplicate: true,+ });+ });+it('does not steal focus when navigation is unavailable', () => {openAgentComposer({ openWithSplit: () => ({ status: 'unavailable' }) });expect(focus.target).toBeUndefined();diff --git a/apps/web/src/features/agents-view/primitives/open-composer.ts b/apps/web/src/features/agents-view/primitives/open-composer.tsindex b1d61b1e0e..bf5c073755 100644--- a/apps/web/src/features/agents-view/primitives/open-composer.ts+++ b/apps/web/src/features/agents-view/primitives/open-composer.ts@@ -1,20 +1,35 @@-import type { SplitManager } from '@components/app/split-layout/layoutManager';+import type {+ SplitHandle,+ SplitManager,+} from '@components/app/split-layout/layoutManager';import { triggerFocusInput } from '@core/directive/focusInput';/** Open the new-conversation page, including when its split is already mounted. */export function openAgentComposer(layout: Pick<SplitManager, 'openWithSplit'>,- preferNewSplit = false+ preferNewSplit = false,+ seed?: {+ /** Unsent composer text, such as an @mention of the entity being asked about. */+ draft?: string;+ /** Open in this split instead of placing a new one. */+ handle?: SplitHandle;+ }) {const content = {type: 'component' as const,id: 'agents',preserveParams: true,- params: { focusComposer: crypto.randomUUID() },+ params: {+ focusComposer: crypto.randomUUID(),+ ...(seed?.draft !== undefined ? { draft: seed.draft } : {}),+ },};const split = layout.openWithSplit(content, {referredFrom: 'launcher',preferNewSplit,+ // Replace the given split even when another Agents split is open, so that+ // split keeps its own draft.+ ...(seed?.handle ? { handle: seed.handle, allowDuplicate: true } : {}),}).split;if (!split) return;// Opening an existing split activates it without updating its params.diff --git a/apps/web/src/features/chat/ChatWithAgentButton.test.ts b/apps/web/src/features/chat/ChatWithAgentButton.test.tsindex 22f6382008..f70c4de885 100644--- a/apps/web/src/features/chat/ChatWithAgentButton.test.ts+++ b/apps/web/src/features/chat/ChatWithAgentButton.test.ts@@ -14,6 +14,16 @@ const mocks = vi.hoisted(() => ({manager: true,failure: vi.fn(),openWithSplit: vi.fn(),+ openAgentComposer: vi.fn(),+ agents: false,+}));++vi.mock('@app/features/agents-view/primitives/open-composer', () => ({+ openAgentComposer: mocks.openAgentComposer,+}));+vi.mock('@core/constant/featureFlags', () => ({+ enableChatV3Agents: {},+ isFeatureEnabled: () => mocks.agents,}));vi.mock('@app/signal/splitLayout', () => ({@@ -45,11 +55,12 @@ import {openChatWithMessageReplacingSplit,} from './ChatWithAgentButton';-describe('openChatWithAgent', () => {+describe('Ask Agent without the agent composer', () => {beforeEach(() => {vi.clearAllMocks();mocks.startPendingSession.mockReturnValue('session-id');mocks.manager = true;+ mocks.agents = false;});it('opens a bare agent session, without the Agents sidebar, with an unsent visible mention', async () => {@@ -189,3 +200,67 @@ describe('openChatWithAgent', () => {});});++describe('Ask Agent with the agent composer', () => {+ const mention =+ '<m-document-mention>{"documentId":"document-id","documentName":"Project plan","blockName":"md","blockParams":{}}</m-document-mention> ';++ beforeEach(() => {+ vi.clearAllMocks();+ mocks.startPendingSession.mockReturnValue('session-id');+ mocks.manager = true;+ mocks.agents = true;+ });++ it('opens the new-conversation composer in a new split with the mention as its draft', async () => {+ expect(+ await openChatWithAgent({+ type: 'document',+ id: 'document-id',+ name: 'Project plan',+ fileType: 'md',+ })+ ).toBe(true);+ expect(mocks.openAgentComposer).toHaveBeenCalledWith(+ { openWithSplit: mocks.openWithSplit },+ true,+ { draft: mention, handle: undefined }+ );+ expect(mocks.startPendingSession).not.toHaveBeenCalled();+ expect(mocks.openWithSplit).not.toHaveBeenCalled();+ });++ it('opens the composer for a channel-message draft', async () => {+ await openChatWithInput('A message reference\n\n');+ expect(mocks.openAgentComposer).toHaveBeenCalledWith(+ expect.anything(),+ true,+ { draft: 'A message reference\n\n', handle: undefined }+ );+ expect(mocks.startPendingSession).not.toHaveBeenCalled();+ });++ it('opens the composer in place of the search split', async () => {+ const split = { replace: vi.fn() } as unknown as SplitHandle;+ await openChatWithInputReplacingSplit('', split);+ expect(mocks.openAgentComposer).toHaveBeenCalledWith(+ expect.anything(),+ false,+ { draft: '', handle: split }+ );+ expect(mocks.startPendingSession).not.toHaveBeenCalled();+ });++ it('still starts a session for handoffs with hidden instructions or a model', async () => {+ await openChatWithInput('Draft', { instructions: 'Private context' });+ await openChatWithInput('Draft', { model: 'database-model' });+ expect(mocks.openAgentComposer).not.toHaveBeenCalled();+ expect(mocks.startPendingSession).toHaveBeenCalledTimes(2);+ });++ it('still sends a submitted query straight to a session', async () => {+ await openChatWithMessage('Find my latest invoices');+ expect(mocks.openAgentComposer).not.toHaveBeenCalled();+ expect(mocks.startPendingSession).toHaveBeenCalled();+ });+});diff --git a/apps/web/src/features/chat/ChatWithAgentButton.tsx b/apps/web/src/features/chat/ChatWithAgentButton.tsxindex ea71c38737..d95525cb54 100644--- a/apps/web/src/features/chat/ChatWithAgentButton.tsx+++ b/apps/web/src/features/chat/ChatWithAgentButton.tsx@@ -1,4 +1,5 @@import { agentsRouteId } from '@app/features/agents-view/core/route';+import { openAgentComposer } from '@app/features/agents-view/primitives/open-composer';import { startPendingSession } from '@app/features/block-agent/context/pending-session';import { globalSplitManager } from '@app/signal/splitLayout';import { HeaderActionButton } from '@components/app/HeaderActionButton';@@ -9,6 +10,10 @@ import {} from '@core/component/AI/util/chatAttachmentMention';import { toast } from '@core/component/Toast/Toast';import { fileTypeToBlockName } from '@core/constant/allBlocks';+import {+ enableChatV3Agents,+ isFeatureEnabled,+} from '@core/constant/featureFlags';import { fireAndForget } from '@core/util/fireAndForget';import AgentIcon from '@icon/system/regular/sparkle.svg';import type { ChannelType } from '@service-cognition/generated/schemas/channelType';@@ -64,6 +69,22 @@ async function createAndOpenAgent(seed: {toast.failure('Unable to open chat');return false;}+ // Unsent text with no session settings is a draft for the new-conversation+ // composer, where the user picks Auto, Chat, or Code and the agent first.+ if (+ manager &&+ seed.input !== undefined &&+ !seed.message &&+ !seed.model &&+ !seed.instructions &&+ isFeatureEnabled(enableChatV3Agents)+ ) {+ openAgentComposer(manager, !seed.replaceSplit, {+ draft: seed.input,+ handle: seed.replaceSplit,+ });+ return true;+ }const id = startPendingSession({prompt: seed.message,diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex 9b0710310d..2a80f1be78 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -289,18 +289,23 @@ or stop.**Ask AI** in desktop search (including Tab) and the command menu opensan agent session. A nonempty search query is sent as the first prompt once the-session is ready; an empty search opens an empty composer. Desktop search replaces-its current split into the Agents workspace, while command-menu actions open a new split.+session is ready. With the Agents workspace enabled, an empty search replaces its+split with the Agents workspace's new-conversation composer; otherwise it opens an+empty session there. Command-menu actions open a new split.**Ask Macro** and **Chat with Agent** on documents, tasks, PDFs, DOCX files,-code files, images, canvases, spreadsheets, email, channels, calls, and projects-also open agent sessions. Like command-menu Ask AI, they open the bare session in-a new split, without the Agents workspace's conversation sidebar. Their entity mention stays-in the composer as an unsent draft. Spreadsheet mentions retain the current sheet-and selected range; channel-message actions retain the referenced message. On+code files, images, canvases, spreadsheets, email, channels, calls, and projects,+and the channel message hover menu, open the Agents workspace's new-conversation+composer in a new split, the same centered composer as Home and **Create → Agent**,+with its Auto/Chat/Code switch and agent, model, and effort pickers. Their entity+mention fills the composer as an unsent draft; an Agents split that is already open+returns to its composer with that draft. Spreadsheet mentions retain the current+sheet and selected range; channel-message actions retain the referenced message. Onphones, the channel message long-press drawer offers the same action as **Ask Macro**.-Add a question and press Send to submit that context. These actions do not create-legacy cognition chats, regardless of the Agents workspace feature flag.+Add a question and press Send to start the conversation. Handoffs that carry hidden+instructions or a fixed model (database chat, booking-link setup, connector import)+still open a bare session directly, as does every action while the Agents workspace+flag is off. These actions do not create legacy cognition chats.## Dispatching coding agents from chatdiff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex 190cbe6bb1..16067bd43e 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -876,7 +876,7 @@ must be saved before persistent comments are available.## Ask Macro about a spreadsheet**Ask Macro** sits immediately left of **Share**. Select the relevant cells, then-click it to open a new agent session in a split beside the workbook. The composer starts+click it to open the agent composer in a split beside the workbook. The composer startswith the workbook mention followed by one space; nothing sends automatically.The mention captures the active sheet ID/name and normalized selected range atclick time. Changing the selection later does not change that draft attachment.@@ -1470,8 +1470,8 @@ and as colored dots on the thumbnails of slides they are on. A viewer who opensa deck nobody has shared yet, or anyone when the sync service is unreachable,gets the stored file read-only.-**Ask Macro**, in the header beside **Share**, opens a new agent session in a-split with the deck mentioned in the composer (nothing sends automatically).+**Ask Macro**, in the header beside **Share**, opens the agent composer in a+split with the deck mentioned (nothing sends automatically).Macro AI reads decks with `ReadPresentation` (slides, layouts, theme colors,sections, transitions, header and footer, and every shape with its id, kind,placeholder role, position in points, text, table cells with merges and style,@@ -2985,9 +2985,8 @@ updates live and shows each collaborator's caret with their name`addComment` ones) are.- The stored upload is not rewritten yet. Search, the PDF export and AI`ReadContent` still see the original file.-- **Ask Macro**, in the header beside **Share**, opens a new agent session in- a split with the document mentioned in the composer (nothing sends- automatically).+- **Ask Macro**, in the header beside **Share**, opens the agent composer in+ a split with the document mentioned (nothing sends automatically).- AI `ReadWordDocument` and `EditWordDocument` read and edit the live copy, soopen editors patch agent edits in as they land. `ReadWordDocument` listsevery paragraph, table cell and content control with its id. `EditWordDocument`