Show each ACP model's own thinking levels when the provider reports them (#9717)
* 修复 ACP 模型档位按精确型号读取 Co-authored-by: Alfred <alfred@mkiio.com> Alfred-Model: auto/gpt-6.1-sol Alfred-Thinking-Effort: high * fix(acp): keep shared thinking options for models without their own A model that reports its own reasoning levels in its ACP metadata uses them. A model that reports none keeps the session's thinking options, as before, instead of losing its thinking picker. Co-authored-by: sj <doskoi.panda@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: sj <doskoi.panda@gmail.com> Co-authored-by: Alfred <alfred@mkiio.com> Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+386
-21
No files matched your search
@@ -19,6 +19,7 @@ import {
|
||||
RequestPermissionRequest,
|
||||
SessionConfigOption,
|
||||
SessionUpdate,
|
||||
type NewSessionResponse,
|
||||
} from "@agentclientprotocol/sdk";
|
||||
|
||||
import {
|
||||
@@ -2114,6 +2115,117 @@ describe("deriveModelDefinitionsFromACP", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("gives a model that reports its own reasoning levels those levels and default", () => {
|
||||
const models = deriveModelDefinitionsFromACP(
|
||||
"acp",
|
||||
{
|
||||
currentModelId: "startup",
|
||||
availableModels: [
|
||||
{ modelId: "startup", name: "Startup" },
|
||||
{
|
||||
modelId: "other",
|
||||
name: "Other",
|
||||
_meta: {
|
||||
reasoningEffort: "xhigh",
|
||||
reasoningEfforts: [
|
||||
{ id: "high", label: "High" },
|
||||
{ id: "xhigh", label: "Extra high" },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
[selectConfigOption("thought_level", ["none", "low"], "low")],
|
||||
);
|
||||
|
||||
expect(models[0]).toMatchObject({
|
||||
thinkingOptions: [{ id: "none" }, { id: "low" }],
|
||||
defaultThinkingOptionId: "low",
|
||||
});
|
||||
expect(models[1]).toMatchObject({
|
||||
thinkingOptions: [
|
||||
{ id: "high", label: "High", isDefault: false },
|
||||
{ id: "xhigh", label: "Extra high", isDefault: true },
|
||||
],
|
||||
defaultThinkingOptionId: "xhigh",
|
||||
});
|
||||
});
|
||||
|
||||
test("uses the wire value and a model's marked default when no reasoningEffort is provided", () => {
|
||||
const models = deriveModelDefinitionsFromACP("acp", {
|
||||
currentModelId: "current",
|
||||
availableModels: [
|
||||
{
|
||||
modelId: "current",
|
||||
name: "Current",
|
||||
_meta: {
|
||||
reasoningEfforts: [
|
||||
{
|
||||
id: "display-id",
|
||||
value: "wire/id@large",
|
||||
label: "Custom",
|
||||
default: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(models[0]).toMatchObject({
|
||||
thinkingOptions: [{ id: "wire/id@large", label: "Custom", isDefault: true }],
|
||||
defaultThinkingOptionId: "wire/id@large",
|
||||
});
|
||||
});
|
||||
|
||||
test.each([{ supportsReasoningEffort: false }, { reasoningEfforts: [] }])(
|
||||
"shows no thinking options for a model that reports none: %j",
|
||||
(metadata) => {
|
||||
const models = deriveModelDefinitionsFromACP(
|
||||
"acp",
|
||||
{
|
||||
currentModelId: "current",
|
||||
availableModels: [{ modelId: "current", name: "Current", _meta: metadata }],
|
||||
},
|
||||
[selectConfigOption("thought_level", ["low", "high"], "high")],
|
||||
);
|
||||
|
||||
expect(models[0].thinkingOptions).toBeUndefined();
|
||||
expect(models[0].defaultThinkingOptionId).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
test.each([
|
||||
{ supportsReasoningEffort: true },
|
||||
{ reasoningEfforts: [{ id: "high", label: "High", description: 42 }] },
|
||||
{
|
||||
reasoningEfforts: [
|
||||
{ id: "high", label: "High" },
|
||||
{ id: "high", label: "Duplicate" },
|
||||
],
|
||||
},
|
||||
])(
|
||||
"keeps session thinking options when a model's reasoning table is unusable: %j",
|
||||
(metadata) => {
|
||||
const models = deriveModelDefinitionsFromACP(
|
||||
"acp",
|
||||
{
|
||||
currentModelId: "default",
|
||||
availableModels: [
|
||||
{ modelId: "default", name: "Default" },
|
||||
{ modelId: "other", name: "Other", _meta: metadata },
|
||||
],
|
||||
},
|
||||
[selectConfigOption("thought_level", ["off", "on"], "on")],
|
||||
);
|
||||
|
||||
expect(models[1]).toMatchObject({
|
||||
thinkingOptions: [{ id: "off" }, { id: "on" }],
|
||||
defaultThinkingOptionId: "on",
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("ACPAgentClient modelTransformer", () => {
|
||||
@@ -2171,6 +2283,164 @@ describe("ACPAgentClient modelTransformer", () => {
|
||||
});
|
||||
|
||||
describe("ACPAgentClient catalog discovery without a model resolver", () => {
|
||||
test.each(["magpie/workbuddy/deepseek-v4.1-flash", "grok-4.7"])(
|
||||
"reads each exact model's reasoning metadata through the ACP response schema with default %s without switching models",
|
||||
async (currentModelId) => {
|
||||
const requests: string[] = [];
|
||||
const response: NewSessionResponse = {
|
||||
sessionId: "catalog-session",
|
||||
models: {
|
||||
currentModelId,
|
||||
availableModels: [
|
||||
{
|
||||
modelId: "grok-4.7",
|
||||
name: "Grok 4.7",
|
||||
_meta: {
|
||||
supportsReasoningEffort: true,
|
||||
reasoningEffort: "high",
|
||||
reasoningEfforts: [
|
||||
{ id: "xhigh", value: "xhigh", label: "Extra High", default: false },
|
||||
{ id: "high", value: "high", label: "High", default: true },
|
||||
{ id: "medium", value: "medium", label: "Medium", default: false },
|
||||
{ id: "low", value: "low", label: "Low", default: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
modelId: "magpie/codex/gpt-6.1-sol",
|
||||
name: "Sol",
|
||||
_meta: {
|
||||
supportsReasoningEffort: true,
|
||||
reasoningEffort: "low",
|
||||
reasoningEfforts: [
|
||||
{ id: "low", value: "low", label: "Low", description: null, default: false },
|
||||
{ id: "medium", value: "medium", label: "Medium", default: false },
|
||||
{ id: "high", value: "high", label: "High", default: false },
|
||||
{ id: "xhigh", value: "xhigh", label: "X-High", default: false },
|
||||
{ id: "max", value: "max", label: "Max", default: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
modelId: "magpie/workbuddy/deepseek-v4.1-flash",
|
||||
name: "DeepSeek",
|
||||
_meta: {
|
||||
supportsReasoningEffort: true,
|
||||
reasoningEffort: "high",
|
||||
reasoningEfforts: [
|
||||
{ id: "none", value: "none", label: "None", default: false },
|
||||
{ id: "low", value: "low", label: "Low", default: false },
|
||||
{ id: "high", value: "high", label: "High", default: false },
|
||||
{ id: "max", value: "max", label: "Max", default: false },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
configOptions: [
|
||||
selectConfigOption(
|
||||
"thought_level",
|
||||
currentModelId === "grok-4.7"
|
||||
? ["xhigh", "high", "medium", "low"]
|
||||
: ["none", "low", "high", "max"],
|
||||
currentModelId === "grok-4.7" ? "medium" : "high",
|
||||
),
|
||||
selectConfigOption("mode", ["https://example.com/modes#agent"]),
|
||||
],
|
||||
};
|
||||
const clientToAgent = new TransformStream<Uint8Array, Uint8Array>();
|
||||
const agentToClient = new TransformStream<Uint8Array, Uint8Array>();
|
||||
const agent: Agent = {
|
||||
async initialize() {
|
||||
return { protocolVersion: PROTOCOL_VERSION, agentCapabilities: {} };
|
||||
},
|
||||
async newSession({ cwd }) {
|
||||
requests.push(`session/new:${cwd}`);
|
||||
return response;
|
||||
},
|
||||
async setSessionConfigOption() {
|
||||
throw new Error("Catalog discovery must not change the selected model");
|
||||
},
|
||||
async prompt() {
|
||||
throw new Error("Catalog discovery must not send a prompt");
|
||||
},
|
||||
async authenticate() {},
|
||||
async cancel() {},
|
||||
};
|
||||
const agentConnection = new AgentSideConnection(
|
||||
() => agent,
|
||||
ndJsonStream(agentToClient.writable, clientToAgent.readable),
|
||||
);
|
||||
const connection = new ClientSideConnection(
|
||||
() => ({
|
||||
async requestPermission() {
|
||||
return { outcome: { outcome: "cancelled" } };
|
||||
},
|
||||
async sessionUpdate() {},
|
||||
}),
|
||||
ndJsonStream(clientToAgent.writable, agentToClient.readable),
|
||||
);
|
||||
const initialize = await connection.initialize({ protocolVersion: PROTOCOL_VERSION });
|
||||
class CatalogClient extends GenericACPAgentClient {
|
||||
protected override async spawnProcess(): Promise<SpawnedACPProcess> {
|
||||
return { child: createProbeChildStub(), connection, initialize };
|
||||
}
|
||||
protected override async closeProbe(): Promise<void> {
|
||||
requests.push("close");
|
||||
}
|
||||
}
|
||||
const client = new CatalogClient({
|
||||
logger: createTestLogger(),
|
||||
command: ["test-acp"],
|
||||
providerId: "grok",
|
||||
});
|
||||
|
||||
const catalog = await client.fetchCatalog({
|
||||
scope: "workspace",
|
||||
cwd: "/tmp/sc/.worktrees/model-options",
|
||||
});
|
||||
|
||||
const modelOptions = [];
|
||||
for (const model of catalog.models) {
|
||||
modelOptions.push({
|
||||
id: model.id,
|
||||
isDefault: model.isDefault,
|
||||
thinking: model.thinkingOptions?.map((option) => option.id),
|
||||
defaultThinkingOptionId: model.defaultThinkingOptionId,
|
||||
});
|
||||
}
|
||||
expect(modelOptions).toEqual([
|
||||
{
|
||||
id: "grok-4.7",
|
||||
isDefault: currentModelId === "grok-4.7",
|
||||
thinking: ["xhigh", "high", "medium", "low"],
|
||||
defaultThinkingOptionId: currentModelId === "grok-4.7" ? "medium" : "high",
|
||||
},
|
||||
{
|
||||
id: "magpie/codex/gpt-6.1-sol",
|
||||
isDefault: false,
|
||||
thinking: ["low", "medium", "high", "xhigh", "max"],
|
||||
defaultThinkingOptionId: "low",
|
||||
},
|
||||
{
|
||||
id: "magpie/workbuddy/deepseek-v4.1-flash",
|
||||
isDefault: currentModelId === "magpie/workbuddy/deepseek-v4.1-flash",
|
||||
thinking: ["none", "low", "high", "max"],
|
||||
defaultThinkingOptionId: "high",
|
||||
},
|
||||
]);
|
||||
expect(catalog.models[1].thinkingOptions?.[0]).toMatchObject({
|
||||
id: "low",
|
||||
label: "Low",
|
||||
isDefault: true,
|
||||
description: undefined,
|
||||
});
|
||||
expect(catalog.modes.map(({ id }) => id)).toEqual(["https://example.com/modes#agent"]);
|
||||
expect(requests).toEqual(["session/new:/tmp/sc/.worktrees/model-options", "close"]);
|
||||
expect(agentConnection.signal.aborted).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
test("never switches models during catalog discovery even with multiple models and a thinking picker", async () => {
|
||||
// Model discovery extensions live on providers that opt in. The base
|
||||
// client ships no catalog model resolver, so a slow or nonconforming ACP can't
|
||||
|
||||
@@ -64,6 +64,7 @@ import {
|
||||
type Stream as ACPStream,
|
||||
} from "@agentclientprotocol/sdk";
|
||||
import type { Logger } from "pino";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
getAgentStreamEventTurnId,
|
||||
@@ -838,32 +839,126 @@ export function deriveModelDefinitionsFromACP(
|
||||
models: SessionModelState | null | undefined,
|
||||
configOptions?: SessionConfigOption[] | null,
|
||||
): AgentModelDefinition[] {
|
||||
const thinkingOptions = deriveSelectorOptions(configOptions, "thought_level");
|
||||
const defaultThinkingOptionId = thinkingOptions.find((option) => option.isDefault)?.id ?? null;
|
||||
const sessionThinking = deriveSessionThinking(configOptions);
|
||||
|
||||
if (models?.availableModels?.length) {
|
||||
return models.availableModels.map((model) => ({
|
||||
provider,
|
||||
id: model.modelId,
|
||||
label: model.name,
|
||||
description: model.description ?? undefined,
|
||||
isDefault: model.modelId === models.currentModelId,
|
||||
thinkingOptions: thinkingOptions.length > 0 ? thinkingOptions : undefined,
|
||||
defaultThinkingOptionId: defaultThinkingOptionId ?? undefined,
|
||||
}));
|
||||
return models.availableModels.map((model) => {
|
||||
const isDefault = model.modelId === models.currentModelId;
|
||||
const thinking = deriveACPModelThinking({
|
||||
metadata: model._meta,
|
||||
isDefault,
|
||||
sessionThinking,
|
||||
});
|
||||
return {
|
||||
provider,
|
||||
id: model.modelId,
|
||||
label: model.name,
|
||||
description: model.description ?? undefined,
|
||||
isDefault,
|
||||
thinkingOptions: thinking.thinkingOptions,
|
||||
defaultThinkingOptionId: thinking.defaultThinkingOptionId,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const modelOptions = deriveSelectorOptions(configOptions, "model");
|
||||
return modelOptions.map((option) => ({
|
||||
provider,
|
||||
id: option.id,
|
||||
label: option.label,
|
||||
description: option.description,
|
||||
isDefault: option.isDefault,
|
||||
thinkingOptions: thinkingOptions.length > 0 ? thinkingOptions : undefined,
|
||||
defaultThinkingOptionId: defaultThinkingOptionId ?? undefined,
|
||||
metadata: option.metadata,
|
||||
}));
|
||||
return modelOptions.map((option) => {
|
||||
const thinking = deriveACPModelThinking({
|
||||
metadata: option.metadata,
|
||||
isDefault: option.isDefault === true,
|
||||
sessionThinking,
|
||||
});
|
||||
return {
|
||||
provider,
|
||||
id: option.id,
|
||||
label: option.label,
|
||||
description: option.description,
|
||||
isDefault: option.isDefault,
|
||||
thinkingOptions: thinking.thinkingOptions,
|
||||
defaultThinkingOptionId: thinking.defaultThinkingOptionId,
|
||||
metadata: option.metadata,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
type ACPModelThinking = Pick<AgentModelDefinition, "thinkingOptions" | "defaultThinkingOptionId">;
|
||||
|
||||
const NO_THINKING: ACPModelThinking = {
|
||||
thinkingOptions: undefined,
|
||||
defaultThinkingOptionId: undefined,
|
||||
};
|
||||
|
||||
// Some ACP agents describe each model's reasoning levels in the model's `_meta`.
|
||||
const ACPModelReasoningSchema = z.object({
|
||||
supportsReasoningEffort: z.boolean().optional(),
|
||||
reasoningEffort: z.string().min(1).nullish(),
|
||||
reasoningEfforts: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
value: z.string().min(1).optional(),
|
||||
label: z.string(),
|
||||
description: z.string().nullish(),
|
||||
default: z.boolean().optional(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
function deriveSessionThinking(
|
||||
configOptions: SessionConfigOption[] | null | undefined,
|
||||
): ACPModelThinking {
|
||||
const thinkingOptions = deriveSelectorOptions(configOptions, "thought_level");
|
||||
if (thinkingOptions.length === 0) {
|
||||
return NO_THINKING;
|
||||
}
|
||||
return {
|
||||
thinkingOptions,
|
||||
defaultThinkingOptionId: thinkingOptions.find((option) => option.isDefault)?.id,
|
||||
};
|
||||
}
|
||||
|
||||
// A model's own reasoning metadata describes that model. A model that reports none
|
||||
// keeps the session's thought_level options, which describe the startup model.
|
||||
function deriveACPModelThinking(input: {
|
||||
metadata: Record<string, unknown> | null | undefined;
|
||||
isDefault: boolean;
|
||||
sessionThinking: ACPModelThinking;
|
||||
}): ACPModelThinking {
|
||||
const { metadata, isDefault, sessionThinking } = input;
|
||||
const parsed = ACPModelReasoningSchema.safeParse(metadata ?? {});
|
||||
if (!parsed.success) {
|
||||
return sessionThinking;
|
||||
}
|
||||
const { supportsReasoningEffort, reasoningEffort, reasoningEfforts } = parsed.data;
|
||||
if (supportsReasoningEffort === false || reasoningEfforts?.length === 0) {
|
||||
return NO_THINKING;
|
||||
}
|
||||
if (!reasoningEfforts) {
|
||||
return sessionThinking;
|
||||
}
|
||||
|
||||
const ids = reasoningEfforts.map((effort) => effort.value ?? effort.id);
|
||||
if (new Set(ids).size !== ids.length) {
|
||||
return sessionThinking;
|
||||
}
|
||||
const markedDefault = reasoningEfforts.find((effort) => effort.default);
|
||||
const defaultCandidates = [
|
||||
isDefault ? sessionThinking.defaultThinkingOptionId : undefined,
|
||||
reasoningEffort,
|
||||
markedDefault ? (markedDefault.value ?? markedDefault.id) : undefined,
|
||||
];
|
||||
const defaultThinkingOptionId =
|
||||
defaultCandidates.find((id) => id && ids.includes(id)) ?? undefined;
|
||||
return {
|
||||
thinkingOptions: reasoningEfforts.map((effort, index) => ({
|
||||
id: ids[index],
|
||||
label: effort.label,
|
||||
description: effort.description ?? undefined,
|
||||
isDefault: ids[index] === defaultThinkingOptionId,
|
||||
})),
|
||||
defaultThinkingOptionId,
|
||||
};
|
||||
}
|
||||
|
||||
export function deriveControlsFromACP(
|
||||
|
||||
Reference in new issue
Block a user