diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index 8de1053eed..36375e4955 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -46,6 +46,7 @@ import { type ProviderEvent, type ProviderInput, type ProviderLaunch, + type ProviderModel, type ProviderPermissionResponse, type ProviderPersistence, type ProviderSessionConfig, @@ -694,7 +695,10 @@ class AcpRuntime { this.nativeSessionId = response.sessionId; this.modes = response.modes ?? null; this.configOptions = response.configOptions ?? []; - const catalog = toProviderCatalog(this.modes, this.configOptions); + let catalog = toProviderCatalog(this.modes, this.configOptions); + if (this.options.options.acpOptions?.perModelThinkingOptions) { + catalog = { ...catalog, models: await this.modelsWithOwnThinkingOptions(catalog) }; + } const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; if (!autoAcceptMode) return catalog; return { @@ -704,6 +708,33 @@ class AcpRuntime { }; } + /** + * Selects each model in the discovery session to read the thinking options the agent lists for + * it, then selects the opening model again for the transformers that run after discovery. + */ + private async modelsWithOwnThinkingOptions(catalog: ProviderCatalog): Promise { + const models: ProviderModel[] = []; + for (const model of catalog.models) { + await this.selectModel(model.id); + const { thinkingOptions, thinkingOption } = toProviderConfigState( + this.modes, + this.configOptions, + ); + models.push({ + ...model, + thinkingOptions: [...thinkingOptions], + defaultThinkingOptionId: thinkingOption, + }); + } + if (catalog.defaultModel) await this.selectModel(catalog.defaultModel); + return models; + } + + private async selectModel(model: string): Promise { + if (selectedValue(modelOption(this.configOptions)) === model) return; + await this.applyNativeConfigChange({ target: "model", value: model }); + } + async prompt(input: Extract): Promise { if (this.closing || this.processFailed || this.deferredRetirement) { throw new Error("ACP session is closed"); diff --git a/packages/plugin/src/server/acp.test.ts b/packages/plugin/src/server/acp.test.ts index a7e33e2d32..f2d61c2627 100644 --- a/packages/plugin/src/server/acp.test.ts +++ b/packages/plugin/src/server/acp.test.ts @@ -65,6 +65,24 @@ async function waitForEvent( return events.find(predicate)!; } +interface ModelThinking { + id: string; + thinkingOptions?: readonly { id: string }[]; + defaultThinkingOptionId?: string; +} + +function modelThinking(model: ModelThinking) { + return { + id: model.id, + thinkingOptions: model.thinkingOptions?.map(optionId), + defaultThinkingOptionId: model.defaultThinkingOptionId, + }; +} + +function optionId(option: { id: string }): string { + return option.id; +} + type AcpRequestMessage = Extract; interface ConnectorInstance { @@ -1997,6 +2015,70 @@ lines.on("line", (line) => { }, ); + it("discovers each model's own thinking options when the agent describes only the selected model", async () => { + const executable = await fakeAcp(`const readline = require("node:readline"); +const lines = readline.createInterface({ input: process.stdin }); +const send = (message) => process.stdout.write(JSON.stringify(message) + "\\n"); +const levels = (values) => values.map((value) => ({ name: value[0].toUpperCase() + value.slice(1), value })); +const thinking = { + neon: { currentValue: "high", options: levels(["low", "high", "xhigh"]) }, + carbon: { currentValue: "medium", options: levels(["low", "medium", "high"]) }, +}; +let model = "neon"; +const options = () => [ + { id: "model", name: "Model", category: "model", type: "select", currentValue: model, options: [{ name: "Neon", value: "neon" }, { name: "Carbon", value: "carbon" }, { name: "Orchestrator", value: "orchestrator" }] }, + ...(thinking[model] ? [{ id: "thought_level", name: "Thinking", category: "thought_level", type: "select", ...thinking[model] }] : []), +]; +lines.on("line", (line) => { + const message = JSON.parse(line); + if (message.method === "initialize") send({ jsonrpc: "2.0", id: message.id, result: { protocolVersion: message.params.protocolVersion, agentCapabilities: {} } }); + else if (message.method === "session/new") send({ jsonrpc: "2.0", id: message.id, result: { sessionId: "native-1", modes: null, configOptions: options() } }); + else if (message.method === "session/set_config_option") { + if (message.params.configId === "model") model = message.params.value; + send({ jsonrpc: "2.0", id: message.id, result: { configOptions: options() } }); + } +});`); + let modelSeenByTransformer: unknown; + const registration = runAcpProvider({ + id: "test-acp", + label: "Test ACP", + command: [process.execPath, executable], + acpOptions: { perModelThinkingOptions: true }, + transformers: [ + { + async discover(catalog, { config }) { + modelSeenByTransformer = (await config.read()).model; + return catalog; + }, + }, + ], + }); + const connection = await registration.connect({ versions: [1], capabilities: [] }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send({ type: "catalog", requestId: "catalog-1", cwd: process.cwd() }); + const event = await waitForEvent( + events, + (candidate) => candidate.type === "catalog" || candidate.type === "request.failed", + ); + if (event.type !== "catalog") throw new Error(`Expected catalog, got ${event.type}`); + expect(event.catalog.defaultModel).toBe("neon"); + expect(event.catalog.models.map(modelThinking)).toEqual([ + { id: "neon", thinkingOptions: ["low", "high", "xhigh"], defaultThinkingOptionId: "high" }, + { + id: "carbon", + thinkingOptions: ["low", "medium", "high"], + defaultThinkingOptionId: "medium", + }, + { id: "orchestrator", thinkingOptions: [], defaultThinkingOptionId: undefined }, + ]); + expect(modelSeenByTransformer).toBe("neon"); + } finally { + await connection.close(); + } + }); + it("selects the model control when an agent files several controls under the model category", async () => { const executable = await fakeAcp(`const readline = require("node:readline"); const lines = readline.createInterface({ input: process.stdin }); diff --git a/packages/plugin/src/server/acp.ts b/packages/plugin/src/server/acp.ts index 68404471ce..43b17202e2 100644 --- a/packages/plugin/src/server/acp.ts +++ b/packages/plugin/src/server/acp.ts @@ -49,6 +49,11 @@ export interface AcpOptions { startupTimeoutMs?: number; /** Global discovery initializes ACP but returns an empty catalog without opening a session. */ workspaceOnlyCatalog?: boolean; + /** + * For an agent that lists thinking options only for the selected model: discovery selects each + * model in turn and records the thinking options the agent lists for it, or none. + */ + perModelThinkingOptions?: boolean; waitForInitialCommands?: boolean; initialCommandsTimeoutMs?: number; /** diff --git a/packages/server/src/server/agent/plugin-provider.test.ts b/packages/server/src/server/agent/plugin-provider.test.ts index e1eed274d9..8835f8cb1b 100644 --- a/packages/server/src/server/agent/plugin-provider.test.ts +++ b/packages/server/src/server/agent/plugin-provider.test.ts @@ -60,6 +60,24 @@ interface ProviderHarnessOptions { handleInput?: (input: ProviderInput, emit: (event: ProviderEvent) => void) => Promise; } +interface ModelThinking { + id: string; + thinkingOptions?: readonly { id: string }[]; + defaultThinkingOptionId?: string; +} + +function modelThinking(model: ModelThinking) { + return { + id: model.id, + thinkingOptions: model.thinkingOptions?.map(optionId), + defaultThinkingOptionId: model.defaultThinkingOptionId, + }; +} + +function optionId(option: { id: string }): string { + return option.id; +} + function controlKey(control: { key: string }): string { return control.key; } @@ -2131,6 +2149,48 @@ describe("PluginAgentClientRegistry", () => { } }); + test("keeps a model's own thinking options and default instead of the catalog's", async () => { + const harness = createProviderHarness({ + async handleInput(input, emit) { + if (input.type !== "catalog") return false; + emit({ + type: "catalog", + requestId: input.requestId, + catalog: { + models: [ + { id: "shared", label: "Shared" }, + { + id: "fast", + label: "Fast", + thinkingOptions: [{ id: "light", label: "Light" }], + defaultThinkingOptionId: "light", + }, + { id: "planner", label: "Planner", thinkingOptions: [] }, + ], + modes: [], + thinkingOptions: [{ id: "deep", label: "Deep" }], + defaultModel: "shared", + defaultThinkingOption: "deep", + }, + }); + return true; + }, + }); + const registry = new PluginAgentClientRegistry(createTestLogger()); + registry.replace([harness.registration]); + try { + const client = registry.clients()[harness.registration.id]!; + const catalog = await client.fetchCatalog({ scope: "global", force: false }); + expect(catalog.models.map(modelThinking)).toEqual([ + { id: "shared", thinkingOptions: ["deep"], defaultThinkingOptionId: "deep" }, + { id: "fast", thinkingOptions: ["light"], defaultThinkingOptionId: "light" }, + { id: "planner", thinkingOptions: [], defaultThinkingOptionId: undefined }, + ]); + } finally { + await registry.shutdown(); + } + }); + test("adapts callback providers into the existing AgentClient and AgentSession path", async () => { const harness = createProviderHarness(); const registry = new PluginAgentClientRegistry(createTestLogger()); diff --git a/packages/server/src/server/agent/plugin-provider.ts b/packages/server/src/server/agent/plugin-provider.ts index 2cfb6136f9..00a674eccf 100644 --- a/packages/server/src/server/agent/plugin-provider.ts +++ b/packages/server/src/server/agent/plugin-provider.ts @@ -2092,14 +2092,21 @@ function mapModel( catalogThinkingOptions: Extract["catalog"]["thinkingOptions"], catalogDefaultThinkingOption: string | undefined, ): AgentModelDefinition { - const thinkingOptions = model.thinkingOptions ?? catalogThinkingOptions; + // A default belongs to the options it was chosen from, so a model with its own options never + // takes the catalog's default. + const thinking = model.thinkingOptions + ? { options: model.thinkingOptions, defaultId: model.defaultThinkingOptionId } + : { + options: catalogThinkingOptions, + defaultId: model.defaultThinkingOptionId ?? catalogDefaultThinkingOption, + }; return { ...model, provider, isDefault: model.isDefault ?? model.id === defaultModel, metadata: model.metadata ? { ...model.metadata } : undefined, - thinkingOptions: thinkingOptions?.map((option) => Object.assign({}, option)), - defaultThinkingOptionId: model.defaultThinkingOptionId ?? catalogDefaultThinkingOption, + thinkingOptions: thinking.options?.map((option) => Object.assign({}, option)), + defaultThinkingOptionId: thinking.defaultId, }; } diff --git a/plugins/antigravity-provider/server/provider.test.ts b/plugins/antigravity-provider/server/provider.test.ts index 6e3a5e967b..6e8bbd1ba9 100644 --- a/plugins/antigravity-provider/server/provider.test.ts +++ b/plugins/antigravity-provider/server/provider.test.ts @@ -517,6 +517,112 @@ it.each(["live", "replay"] as const)( }, ); +// agy 1.5.14 lists `thought_level` only for the selected model and omits it for Orchestrator. +it("offers each model its own thinking options and opens Orchestrator with its default", async () => { + const { directory, launch } = await launchAgent(` + const { createInterface } = require("node:readline"); + const levels = (...values) => values.map((value) => ({ value, name: value })); + const thinking = { + "gemini-4-neon": { currentValue: "high", options: levels("low", "medium", "high", "xhigh") }, + "gemini-4-carbon": { currentValue: "high", options: levels("low", "medium", "high") }, + "claude-opus-5-5": { currentValue: "medium", options: levels("low", "medium", "high") }, + }; + let model = "gemini-4-neon"; + const configOptions = () => [ + { id: "model", name: "Model", category: "model", type: "select", currentValue: model, options: [ + { value: "gemini-4-neon", name: "Gemini 4 Neon" }, + { value: "gemini-4-carbon", name: "Gemini 4 Carbon" }, + { value: "gemini-pro-orchestrator-neon", name: "Orchestrator (Neon)" }, + { value: "claude-opus-5-5", name: "Claude Opus 5.5" }, + ] }, + ...(thinking[model] ? [{ id: "thought_level", name: "Thinking", category: "thought_level", type: "select", ...thinking[model] }] : []), + { id: "mode", name: "Mode", category: "mode", type: "select", currentValue: "default", + options: [{ value: "default", name: "Default" }, { value: "plan", name: "Plan" }] }, + ]; + const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); + createInterface({ input: process.stdin }).on("line", (line) => { + const { id, method, params } = JSON.parse(line); + if (method === "initialize") send({ id, result: { protocolVersion: 1, agentCapabilities: {} } }); + if (method === "session/new") { + model = "gemini-4-neon"; + send({ id, result: { sessionId: "native", configOptions: configOptions() } }); + } + if (method === "session/set_config_option") { + if (params.configId === "thought_level" && !thinking[model]) { + send({ id, error: { code: -32602, message: "unknown config option" } }); + return; + } + if (params.configId === "model") model = params.value; + else if (params.configId === "thought_level") thinking[model].currentValue = params.value; + send({ id, result: { configOptions: configOptions() } }); + } + if (method === "session/close") send({ id, result: {} }); + }); + `); + const connection = await createAntigravityProvider().connect({ + launch, + versions: [1], + capabilities: ["session.configure"], + }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + try { + await connection.send({ type: "catalog", requestId: "catalog", cwd: directory }); + await expect + .poll(() => + events.find((event) => event.type === "catalog" || event.type === "request.failed"), + ) + .toMatchObject({ type: "catalog" }); + const catalog = events.find((event) => event.type === "catalog"); + if (catalog?.type !== "catalog") throw new Error("Expected a catalog"); + const thinkingByModel = Object.fromEntries( + catalog.catalog.models.map((model) => [ + model.id, + { + options: model.thinkingOptions?.map((option) => option.id), + default: model.defaultThinkingOptionId, + }, + ]), + ); + expect(thinkingByModel).toEqual({ + "gemini-4-neon": { options: ["low", "medium", "high", "xhigh"], default: "high" }, + "gemini-4-carbon": { options: ["low", "medium", "high"], default: "high" }, + "gemini-pro-orchestrator-neon": { options: [], default: undefined }, + "claude-opus-5-5": { options: ["low", "medium", "high"], default: "medium" }, + }); + + await connection.send({ + type: "session.open", + requestId: "open", + sessionId: "orchestrator", + history: "skip", + config: { + cwd: directory, + model: "gemini-pro-orchestrator-neon", + mode: "full-access", + thinkingOption: thinkingByModel["gemini-pro-orchestrator-neon"]!.default, + env: {}, + mcpServers: {}, + settings: {}, + persist: true, + }, + }); + await expect + .poll( + () => + events.find( + (event) => + (event.type === "session.ready" && event.sessionId === "orchestrator") || + (event.type === "request.failed" && event.requestId === "open"), + ), + { timeout: 3_000 }, + ) + .toMatchObject({ type: "session.ready" }); + } finally { + await connection.close(); + } +}); + describe("installation", () => { const signal = new AbortController().signal; diff --git a/plugins/antigravity-provider/server/provider.ts b/plugins/antigravity-provider/server/provider.ts index b32fdd0e40..ae4016fa8f 100644 --- a/plugins/antigravity-provider/server/provider.ts +++ b/plugins/antigravity-provider/server/provider.ts @@ -109,6 +109,8 @@ export function createAntigravityProvider(): ProviderRegistration { icon: "icon.svg", command: ["agy", "acp", "--disable-telemetry"], acpOptions: { + // agy 1.5.14 lists thinking options for the selected model only, and none for Orchestrator. + perModelThinkingOptions: true, waitForInitialCommands: true, loadReplayQuietPeriodMs: 200, // COMPAT(antigravityAcpV1DeferredTurn): added in v0.18.0, remove once Antigravity CLI supports ACP v2 state_update. diff --git a/public-docs/plugins/providers.md b/public-docs/plugins/providers.md index 9e50ae8b53..e78b222df3 100644 --- a/public-docs/plugins/providers.md +++ b/public-docs/plugins/providers.md @@ -711,6 +711,10 @@ The adapter selects an unambiguous ACP `allow_once` action without opening a Pas Set `default: true` to make this the default for new sessions. The adapter requires an idle session without pending approvals before it switches to or from this mode. +Set `acpOptions.perModelThinkingOptions` for an agent that lists `thought_level` choices only for +the selected model. Catalog discovery selects each model in turn and gives it the thinking options +the agent lists for it. A model without a `thought_level` option gets no thinking picker. + ## Test and publish Test the provider against the real agent, not only mocked frames: diff --git a/public-docs/plugins/providers.zh-CN.md b/public-docs/plugins/providers.zh-CN.md index 95cc19b5fe..fd8c60b140 100644 --- a/public-docs/plugins/providers.zh-CN.md +++ b/public-docs/plugins/providers.zh-CN.md @@ -573,6 +573,8 @@ export const vendorEdits: AcpTransformer = { }; ``` +如果 Agent 只为当前选中的模型列出 `thought_level` 选项,请设置 `acpOptions.perModelThinkingOptions`。目录发现会依次选中每个模型,并为它记录 Agent 列出的思考选项。没有 `thought_level` 选项的模型不会显示思考选择器。 + ## 测试与发布 {#test-and-publish} 用真实的 Agent 测试 Provider,而不只是模拟的数据帧: