mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(antigravity): offer each model its own thinking levels (#10524)
agy lists `thought_level` choices only for the selected model, and drops the option entirely for Orchestrator and GPT-OSS. ACP catalog discovery read one session/new and copied the startup model's levels onto every model, so the composer offered and defaulted to a thinking level for Orchestrator. Opening the draft session then set the model, found no `thought_level`, and failed with "ACP session does not expose thinking configuration". The new `acpOptions.perModelThinkingOptions` makes discovery select each model in the throwaway catalog session and record the levels the agent lists for it, or none; Antigravity turns it on. It is opt-in because selecting a model can reset other options in some agents. The server also stops giving a model the catalog's default when the model brings its own options, since that default came from another model's list. Closes #10468
This commit is contained in:
@@ -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<ProviderModel[]> {
|
||||
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<void> {
|
||||
if (selectedValue(modelOption(this.configOptions)) === model) return;
|
||||
await this.applyNativeConfigChange({ target: "model", value: model });
|
||||
}
|
||||
|
||||
async prompt(input: Extract<ProviderInput, { type: "session.prompt" }>): Promise<void> {
|
||||
if (this.closing || this.processFailed || this.deferredRetirement) {
|
||||
throw new Error("ACP session is closed");
|
||||
|
||||
@@ -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<AcpStreamMessage, { id: string | number | null; method: string }>;
|
||||
|
||||
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 });
|
||||
|
||||
@@ -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;
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,24 @@ interface ProviderHarnessOptions {
|
||||
handleInput?: (input: ProviderInput, emit: (event: ProviderEvent) => void) => Promise<boolean>;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -2092,14 +2092,21 @@ function mapModel(
|
||||
catalogThinkingOptions: Extract<ProviderEvent, { type: "catalog" }>["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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -573,6 +573,8 @@ export const vendorEdits: AcpTransformer = {
|
||||
};
|
||||
```
|
||||
|
||||
如果 Agent 只为当前选中的模型列出 `thought_level` 选项,请设置 `acpOptions.perModelThinkingOptions`。目录发现会依次选中每个模型,并为它记录 Agent 列出的思考选项。没有 `thought_level` 选项的模型不会显示思考选择器。
|
||||
|
||||
## 测试与发布 {#test-and-publish}
|
||||
|
||||
用真实的 Agent 测试 Provider,而不只是模拟的数据帧:
|
||||
|
||||
Reference in New Issue
Block a user