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.

fix(web): keep the agent mention menu open while models load (#7330)

Wolf Mermelsteindc3924209ebe
diff --git a/apps/web/src/features/agents-view/queries/composer-models.test.ts b/apps/web/src/features/agents-view/queries/composer-models.test.ts
index 441cc0c332..2db0cd390c 100644
--- a/apps/web/src/features/agents-view/queries/composer-models.test.ts
+++ b/apps/web/src/features/agents-view/queries/composer-models.test.ts
@@ -4,14 +4,16 @@ import type { RosterAgent } from '../core/roster';
import { composerModelTarget, createComposerModels } from './composer-models';
const discovery = vi.hoisted(() => ({
- targets: undefined as (() => unknown) | undefined,
- queries: [] as object[],
+ target: undefined as (() => unknown) | undefined,
+ enabled: undefined as (() => boolean) | undefined,
+ query: {} as object,
}));
vi.mock('@queries/agents/models', () => ({
- useAgentModelsQueries: (targets: () => unknown) => {
- discovery.targets = targets;
- return discovery.queries;
+ useAgentModelsQuery: (target: () => unknown, enabled: () => boolean) => {
+ discovery.target = target;
+ discovery.enabled = enabled;
+ return discovery.query;
},
}));
@@ -34,7 +36,6 @@ describe('composer model discovery', () => {
});
it('switches discovery targets with the selected agent and skips disconnected runtimes', () => {
- discovery.queries = [];
createRoot((dispose) => {
const [agent, setAgent] = createSignal<RosterAgent>({
id: 'bot-one',
@@ -46,15 +47,21 @@ describe('composer model discovery', () => {
runtime: { label: 'Cursor', connected: true },
});
createComposerModels(agent);
- expect(discovery.targets?.()).toEqual([{ harness: 'cursor' }]);
+ expect(discovery.enabled?.()).toBe(true);
+ expect(discovery.target?.()).toEqual({ harness: 'cursor' });
setAgent({ ...agent(), harness: 'claude-cloud' });
- expect(discovery.targets?.()).toEqual([{ harness: 'claude-cloud' }]);
+ expect(discovery.target?.()).toEqual({ harness: 'claude-cloud' });
setAgent({ ...agent(), harness: 'macrod', harnessId: 'paired-runtime' });
- expect(discovery.targets?.()).toEqual([
- { harness: 'macrod', harnessId: 'paired-runtime' },
- ]);
+ expect(discovery.target?.()).toEqual({
+ harness: 'macrod',
+ harnessId: 'paired-runtime',
+ });
setAgent({ ...agent(), runtime: { label: 'Offline', connected: false } });
- expect(discovery.targets?.()).toEqual([]);
+ expect(discovery.enabled?.()).toBe(false);
+ expect(discovery.target?.()).toEqual({
+ harness: 'in-memory',
+ harnessId: 'composer-idle',
+ });
dispose();
});
});
@@ -66,24 +73,25 @@ describe('composer model discovery', () => {
{ id: 'runtime-model', name: 'Runtime model' },
{ id: 'anthropic/claude-fable-5-1', name: 'Fable 5.1' },
];
- discovery.queries = [
- {
- get isSuccess() {
- return ready();
- },
- get isPending() {
- return !ready();
- },
- get data() {
- if (!ready()) throw new Error('Pending resource must not be read');
- return {
- models,
- currentModel: 'runtime-model',
- status: 'available',
- };
- },
+ discovery.query = {
+ get isSuccess() {
+ return ready();
},
- ];
+ get isPending() {
+ return !ready();
+ },
+ get isError() {
+ return false;
+ },
+ get data() {
+ if (!ready()) throw new Error('Pending resource must not be read');
+ return {
+ models,
+ currentModel: 'runtime-model',
+ status: 'available',
+ };
+ },
+ };
const source = createComposerModels(() => ({
id: 'bot',
name: 'Agent',
diff --git a/apps/web/src/features/agents-view/queries/composer-models.ts b/apps/web/src/features/agents-view/queries/composer-models.ts
index 4ef0e08cfd..c748919e5b 100644
--- a/apps/web/src/features/agents-view/queries/composer-models.ts
+++ b/apps/web/src/features/agents-view/queries/composer-models.ts
@@ -1,12 +1,21 @@
import { isModelPickerOption } from '@core/component/AI/constant/model';
import {
type AgentModelTarget,
- useAgentModelsQueries,
+ useAgentModelsQuery,
} from '@queries/agents/models';
import { ModelHarnessDto } from '@service-agent-harness/generated/schemas/modelHarnessDto';
import type { Accessor } from 'solid-js';
import type { RosterAgent } from '../core/roster';
+/**
+ * Disabled-query placeholder. `useQuery` still wants a target for its key;
+ * this one is never fetched and does not collide with a live catalog.
+ */
+const IDLE_MODEL_TARGET: AgentModelTarget = {
+ harness: 'in-memory',
+ harnessId: 'composer-idle',
+};
+
/** Map a roster entry to the same discovery target used by agent settings. */
export function composerModelTarget(
agent: Pick<RosterAgent, 'harness' | 'harnessId'> | undefined
@@ -28,13 +37,21 @@ export function composerModelTarget(
/** Keep discovery scoped to the selected, connected runtime. */
export function createComposerModels(agent: Accessor<RosterAgent | undefined>) {
- const queries = useAgentModelsQueries(() => {
+ const target = (): AgentModelTarget | undefined => {
const selected = agent();
- const target = composerModelTarget(selected);
- return target && selected?.runtime.connected ? [target] : [];
- });
- // Status-gated reads keep a pending catalog from suspending the composer.
- const data = () => (queries[0]?.isSuccess ? queries[0].data : undefined);
+ const next = composerModelTarget(selected);
+ return next && selected?.runtime.connected ? next : undefined;
+ };
+ // `useQueries` exposes `data` as a Solid resource, so reading it suspends
+ // on every update — including after success. The composer lives under
+ // <Suspense>; that suspend detaches the editor and closes an open mention
+ // menu. `useQuery` only suspends while `data` is still undefined, and the
+ // isSuccess gate below skips that read.
+ const query = useAgentModelsQuery(
+ () => target() ?? IDLE_MODEL_TARGET,
+ () => target() !== undefined
+ );
+ const data = () => (target() && query.isSuccess ? query.data : undefined);
return {
models: () =>
data()?.models.filter((model) => isModelPickerOption(model.id)) ?? [],
@@ -42,10 +59,10 @@ export function createComposerModels(agent: Accessor<RosterAgent | undefined>) {
message: () => {
if (!agent()?.runtime.connected)
return 'Connect the runtime to load models.';
- if (queries[0]?.isError)
- return 'Could not load models from this runtime.';
- if (queries[0]?.isPending) return 'Loading models…';
- if (data()?.status === 'unsupported' || !composerModelTarget(agent())) {
+ if (!target()) return 'This runtime does not provide model discovery.';
+ if (query.isError) return 'Could not load models from this runtime.';
+ if (query.isPending) return 'Loading models…';
+ if (data()?.status === 'unsupported') {
return 'This runtime does not provide model discovery.';
}
return 'This runtime returned no models.';
diff --git a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
index 931cfb7582..9ee364aee5 100644
--- a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
+++ b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
@@ -102,51 +102,58 @@ vi.mock('@queries/agents/capabilities', () => ({
}));
vi.mock('@queries/agents/models', () => ({
- useAgentModelsQueries: (targets: () => { harness: string }[]) => [
- {
- get isSuccess() {
- return targets().length > 0;
- },
- get data() {
- const harness = targets()[0]?.harness;
- return {
- status: 'available',
- currentModel:
- harness === 'cursor' ? 'cursor-default' : 'chat-default',
- models:
- harness === 'cursor'
- ? [
- { id: 'cursor-default', name: 'Cursor default' },
- { id: 'gpt-5', name: 'GPT-5' },
- ]
- : [
- { id: 'chat-default', name: 'Chat default' },
- { id: 'claude-sonnet-4', name: 'Sonnet 4' },
- {
- id: 'anthropic/claude-fable-5-1',
- name: 'Fable 5.1',
- },
- {
- id: 'anthropic/claude-sonnet-5',
- name: 'anthropic/claude-sonnet-5',
- },
- { id: 'anthropic/claude-opus-5', name: 'Claude Opus 5' },
- { id: 'openai/gpt-5.6', name: 'GPT-5.6' },
- { id: 'google/gemini-3.8-flash', name: 'Gemini 3.8 Flash' },
- { id: 'fireworks/kimi-k3', name: 'Kimi K3' },
- { id: 'fireworks/glm-5p3', name: 'GLM 5.3' },
- {
- id: 'fireworks/glm-5p3-flash',
- name: 'GLM 5.3 Flash',
- },
- { id: 'fireworks/qwen3p8-max', name: 'Qwen 3.8 Max' },
- { id: 'fireworks/minimax-m3', name: 'MiniMax M3' },
- { id: 'cerebras/gpt-oss-120b', name: 'GPT OSS 120B' },
- ],
- };
- },
+ useAgentModelsQuery: (
+ target: () => { harness: string },
+ enabled: () => boolean
+ ) => ({
+ get isSuccess() {
+ return enabled();
+ },
+ get isPending() {
+ return false;
},
- ],
+ get isError() {
+ return false;
+ },
+ get data() {
+ if (!enabled()) throw new Error('Pending resource must not be read');
+ const harness = target().harness;
+ return {
+ status: 'available',
+ currentModel: harness === 'cursor' ? 'cursor-default' : 'chat-default',
+ models:
+ harness === 'cursor'
+ ? [
+ { id: 'cursor-default', name: 'Cursor default' },
+ { id: 'gpt-5', name: 'GPT-5' },
+ ]
+ : [
+ { id: 'chat-default', name: 'Chat default' },
+ { id: 'claude-sonnet-4', name: 'Sonnet 4' },
+ {
+ id: 'anthropic/claude-fable-5-1',
+ name: 'Fable 5.1',
+ },
+ {
+ id: 'anthropic/claude-sonnet-5',
+ name: 'anthropic/claude-sonnet-5',
+ },
+ { id: 'anthropic/claude-opus-5', name: 'Claude Opus 5' },
+ { id: 'openai/gpt-5.6', name: 'GPT-5.6' },
+ { id: 'google/gemini-3.8-flash', name: 'Gemini 3.8 Flash' },
+ { id: 'fireworks/kimi-k3', name: 'Kimi K3' },
+ { id: 'fireworks/glm-5p3', name: 'GLM 5.3' },
+ {
+ id: 'fireworks/glm-5p3-flash',
+ name: 'GLM 5.3 Flash',
+ },
+ { id: 'fireworks/qwen3p8-max', name: 'Qwen 3.8 Max' },
+ { id: 'fireworks/minimax-m3', name: 'MiniMax M3' },
+ { id: 'cerebras/gpt-oss-120b', name: 'GPT OSS 120B' },
+ ],
+ };
+ },
+ }),
}));
// Keep the real picker and send wiring; substitute only the Lexical editor.
diff --git a/apps/web/src/features/block-automation/component/AutomationComposer.test.tsx b/apps/web/src/features/block-automation/component/AutomationComposer.test.tsx
index bff60b81d5..9a82f505f4 100644
--- a/apps/web/src/features/block-automation/component/AutomationComposer.test.tsx
+++ b/apps/web/src/features/block-automation/component/AutomationComposer.test.tsx
@@ -114,30 +114,27 @@ vi.mock('../../agents-view/queries/agent-roster-source', () => ({
}),
}));
vi.mock('@queries/agents/models', () => ({
- useAgentModelsQueries: () => [
- {
- get isSuccess() {
- return catalogState() === 'success';
- },
- get isPending() {
- return catalogState() === 'pending';
- },
- get isError() {
- return catalogState() === 'error';
- },
- get data() {
- if (catalogState() !== 'success')
- throw new Error('Unsafe catalog read');
- return {
- status: 'available',
- models: [
- { id: 'claude-sonnet-4-6', name: 'Sonnet' },
- { id: 'vendor/custom-model', name: 'Custom model' },
- ],
- };
- },
+ useAgentModelsQuery: () => ({
+ get isSuccess() {
+ return catalogState() === 'success';
},
- ],
+ get isPending() {
+ return catalogState() === 'pending';
+ },
+ get isError() {
+ return catalogState() === 'error';
+ },
+ get data() {
+ if (catalogState() !== 'success') throw new Error('Unsafe catalog read');
+ return {
+ status: 'available',
+ models: [
+ { id: 'claude-sonnet-4-6', name: 'Sonnet' },
+ { id: 'vendor/custom-model', name: 'Custom model' },
+ ],
+ };
+ },
+ }),
}));
let styles: HTMLStyleElement;
diff --git a/apps/web/src/features/block-automation/views/routine-execution-picker.test.tsx b/apps/web/src/features/block-automation/views/routine-execution-picker.test.tsx
index 13a3ac536b..aeb8d6f28d 100644
--- a/apps/web/src/features/block-automation/views/routine-execution-picker.test.tsx
+++ b/apps/web/src/features/block-automation/views/routine-execution-picker.test.tsx
@@ -51,33 +51,31 @@ type Catalog = {
};
const [catalogs, setCatalogs] = createSignal<Record<string, Catalog>>({});
vi.mock('@queries/agents/models', () => ({
- useAgentModelsQueries: (
- targets: () => { harness: string; harnessId?: string }[]
+ useAgentModelsQuery: (
+ target: () => { harness: string; harnessId?: string },
+ enabled: () => boolean
) => {
const current = () => {
- const target = targets()[0];
- return target
- ? catalogs()[target.harnessId ?? target.harness]
- : undefined;
+ if (!enabled()) return undefined;
+ const next = target();
+ return catalogs()[next.harnessId ?? next.harness];
};
- return [
- {
- get isSuccess() {
- return current()?.status === 'success';
- },
- get isPending() {
- return current()?.status === 'pending';
- },
- get isError() {
- return current()?.status === 'error';
- },
- get data() {
- if (current()?.status !== 'success')
- throw new Error('Read a pending catalog');
- return { status: 'available', models: current()?.models ?? [] };
- },
+ return {
+ get isSuccess() {
+ return current()?.status === 'success';
},
- ];
+ get isPending() {
+ return current()?.status === 'pending';
+ },
+ get isError() {
+ return current()?.status === 'error';
+ },
+ get data() {
+ if (current()?.status !== 'success')
+ throw new Error('Read a pending catalog');
+ return { status: 'available', models: current()?.models ?? [] };
+ },
+ };
},
}));