Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(agents): send mobile Ask AI to the agent session when chat v3 is on (#6764)

Wolf Mermelstein19b30706d8b5
diff --git a/apps/web/src/features/command/mobile/MobileSearchInput.tsx b/apps/web/src/features/command/mobile/MobileSearchInput.tsx
index e7d67a061d..20373186de 100644
--- a/apps/web/src/features/command/mobile/MobileSearchInput.tsx
+++ b/apps/web/src/features/command/mobile/MobileSearchInput.tsx
@@ -1,4 +1,3 @@
-import { openChatWithMessage } from '@app/features/chat/ChatWithAgentButton';
import {
useForegroundMobileView,
useMobileNavNavigate,
@@ -9,6 +8,7 @@ import XIcon from '@phosphor/x.svg';
import { cn } from '@ui';
import { createEffect, on } from 'solid-js';
import { SearchState } from './mobileSearchState';
+import { openMobileAskAi } from './open-mobile-ask-ai';
// This component only writes the global session state. The active split's
// bridge effect (see soup-view-context) mirrors the session into its own
@@ -18,13 +18,12 @@ import { SearchState } from './mobileSearchState';
// session itself (see MobileDockRow's search layout).
/**
- * Sends the current query to a new AI chat and ends the search session.
- * Same wiring as the desktop command menu's "Ask AI about" row.
+ * Sends the current query to a new AI conversation and ends the search session.
*/
function submitAskAi() {
const query = SearchState.query().trim();
if (!query) return;
- openChatWithMessage(query);
+ openMobileAskAi(query);
SearchState.close();
}
diff --git a/apps/web/src/features/command/mobile/open-mobile-ask-ai.test.ts b/apps/web/src/features/command/mobile/open-mobile-ask-ai.test.ts
new file mode 100644
index 0000000000..43d9a5d8c7
--- /dev/null
+++ b/apps/web/src/features/command/mobile/open-mobile-ask-ai.test.ts
@@ -0,0 +1,73 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({
+ agentsEnabled: false,
+ openChatWithMessage: vi.fn(),
+ startPendingSession: vi.fn(() => 'pending-session'),
+ openWithSplit: vi.fn(),
+ manager: true,
+ failure: vi.fn(),
+}));
+
+vi.mock('@app/features/block-agent/context/pending-session', () => ({
+ startPendingSession: mocks.startPendingSession,
+}));
+vi.mock('@app/features/chat/ChatWithAgentButton', () => ({
+ openChatWithMessage: mocks.openChatWithMessage,
+}));
+vi.mock('@app/signal/splitLayout', () => ({
+ globalSplitManager: () =>
+ mocks.manager ? { openWithSplit: mocks.openWithSplit } : undefined,
+}));
+vi.mock('@core/component/Toast/Toast', () => ({
+ toast: { failure: mocks.failure },
+}));
+vi.mock('@core/constant/featureFlags', () => ({
+ enableChatV3Agents: { key: 'enable-chat-v3-agents' },
+ isFeatureEnabled: () => mocks.agentsEnabled,
+}));
+
+import { openMobileAskAi } from './open-mobile-ask-ai';
+
+describe('openMobileAskAi', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.agentsEnabled = false;
+ mocks.manager = true;
+ mocks.startPendingSession.mockReturnValue('pending-session');
+ });
+
+ it('opens the cognition chat when chat v3 agents are off', () => {
+ openMobileAskAi('reply to Margot');
+
+ expect(mocks.openChatWithMessage).toHaveBeenCalledWith('reply to Margot');
+ expect(mocks.startPendingSession).not.toHaveBeenCalled();
+ expect(mocks.openWithSplit).not.toHaveBeenCalled();
+ });
+
+ it('starts an agent session with the query when chat v3 agents are on', () => {
+ mocks.agentsEnabled = true;
+
+ openMobileAskAi('reply to Margot');
+
+ expect(mocks.startPendingSession).toHaveBeenCalledWith({
+ prompt: 'reply to Margot',
+ });
+ expect(mocks.openWithSplit).toHaveBeenCalledWith(
+ { type: 'agent', id: 'pending-session' },
+ { activate: true, preferNewSplit: true }
+ );
+ expect(mocks.openChatWithMessage).not.toHaveBeenCalled();
+ });
+
+ it('reports a failure and skips session creation when no split can open', () => {
+ mocks.agentsEnabled = true;
+ mocks.manager = false;
+
+ openMobileAskAi('reply to Margot');
+
+ expect(mocks.failure).toHaveBeenCalledWith('Unable to open chat');
+ expect(mocks.startPendingSession).not.toHaveBeenCalled();
+ expect(mocks.openChatWithMessage).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/features/command/mobile/open-mobile-ask-ai.ts b/apps/web/src/features/command/mobile/open-mobile-ask-ai.ts
new file mode 100644
index 0000000000..6de2b492ea
--- /dev/null
+++ b/apps/web/src/features/command/mobile/open-mobile-ask-ai.ts
@@ -0,0 +1,31 @@
+import { startPendingSession } from '@app/features/block-agent/context/pending-session';
+import { openChatWithMessage } from '@app/features/chat/ChatWithAgentButton';
+import { globalSplitManager } from '@app/signal/splitLayout';
+import { toast } from '@core/component/Toast/Toast';
+import {
+ enableChatV3Agents,
+ isFeatureEnabled,
+} from '@core/constant/featureFlags';
+
+/**
+ * Opens a conversation for a mobile search query and sends it immediately.
+ * With chat v3 agents, that is a managed agent session whose first prompt is
+ * the query. Otherwise it is the cognition chat.
+ */
+export function openMobileAskAi(query: string) {
+ if (!isFeatureEnabled(enableChatV3Agents)) {
+ void openChatWithMessage(query);
+ return;
+ }
+
+ const manager = globalSplitManager();
+ if (!manager) {
+ toast.failure('Unable to open chat');
+ return;
+ }
+
+ manager.openWithSplit(
+ { type: 'agent', id: startPendingSession({ prompt: query }) },
+ { activate: true, preferNewSplit: true }
+ );
+}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index 23c7e67358..058eb54579 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -201,6 +201,11 @@ The area behind the composer is transparent, without a bottom gradient overlay.
The composer has one editable field. Its placeholder appears only while empty;
placeholder updates and disabled-state changes preserve the editor and draft.
+The **Ask AI** button beside the mobile search field sends the typed query.
+With `enable-chat-v3-agents` on, it opens an agent session (`/app/agent/<id>`)
+and delivers the query as the first prompt. With the flag off, it opens a
+cognition chat (`/app/chat/<uuid>`) and sends the query.
+
Almost every list surface (Home, Agents, Files, Tasks, Customers, Email) has a bottom
composer with placeholder **`Ask AI, @mention anything`**. Click it, `type_text` the message,
press Enter — the app creates a chat and navigates to `/app/chat/<uuid>`. Alternatively,