fix: centralize provider thinking profiles

This commit is contained in:
Peter Steinberger
2026-04-21 09:04:37 +01:00
parent 1cc2fc82ca
commit f1805ab54d
57 changed files with 718 additions and 572 deletions

View File

@@ -225,53 +225,31 @@ describe("anthropic provider replay hooks", () => {
reasoning: true,
});
expect(
provider.resolveDefaultThinkingLevel?.({
provider.resolveThinkingProfile?.({
provider: "anthropic",
modelId: "claude-opus-4-7",
} as never),
).toBe("off");
).toMatchObject({
levels: expect.arrayContaining([{ id: "xhigh" }, { id: "adaptive" }, { id: "max" }]),
defaultLevel: "off",
});
expect(
provider.resolveDefaultThinkingLevel?.({
provider.resolveThinkingProfile?.({
provider: "anthropic",
modelId: "claude-opus-4-6",
} as never),
).toBe("adaptive");
).toMatchObject({
levels: expect.arrayContaining([{ id: "adaptive" }]),
defaultLevel: "adaptive",
});
expect(
provider.supportsXHighThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-7",
} as never),
).toBe(true);
expect(
provider.supportsXHighThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-6",
} as never),
provider
.resolveThinkingProfile?.({
provider: "anthropic",
modelId: "claude-opus-4-6",
} as never)
?.levels.some((level) => level.id === "xhigh" || level.id === "max"),
).toBe(false);
expect(
provider.supportsMaxThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-7",
} as never),
).toBe(true);
expect(
provider.supportsMaxThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-6",
} as never),
).toBe(false);
expect(
provider.supportsAdaptiveThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-7",
} as never),
).toBe(true);
expect(
provider.supportsAdaptiveThinking?.({
provider: "anthropic",
modelId: "claude-opus-4-6",
} as never),
).toBe(true);
});
it("resolves claude-cli synthetic oauth auth", async () => {

View File

@@ -494,16 +494,26 @@ export function buildAnthropicProvider(): ProviderPlugin {
buildReplayPolicy: buildAnthropicReplayPolicy,
isModernModelRef: ({ modelId }) => matchesAnthropicModernModel(modelId),
resolveReasoningOutputMode: () => "native",
supportsXHighThinking: ({ modelId }) => isAnthropicOpus47Model(modelId),
supportsAdaptiveThinking: ({ modelId }) => supportsAnthropicAdaptiveThinking(modelId),
supportsMaxThinking: ({ modelId }) => isAnthropicOpus47Model(modelId),
resolveThinkingProfile: ({ modelId }) => {
const levels: Array<{
id: "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive" | "max";
}> = [{ id: "off" }, { id: "minimal" }, { id: "low" }, { id: "medium" }, { id: "high" }];
if (isAnthropicOpus47Model(modelId)) {
levels.push({ id: "xhigh" }, { id: "adaptive" }, { id: "max" });
} else if (supportsAnthropicAdaptiveThinking(modelId)) {
levels.push({ id: "adaptive" });
}
return {
levels,
defaultLevel: isAnthropicOpus47Model(modelId)
? "off"
: matchesAnthropicModernModel(modelId) &&
shouldUseAnthropicAdaptiveThinkingDefault(modelId)
? "adaptive"
: undefined,
};
},
wrapStreamFn: wrapAnthropicProviderStream,
resolveDefaultThinkingLevel: ({ modelId }) =>
isAnthropicOpus47Model(modelId)
? "off"
: matchesAnthropicModernModel(modelId) && shouldUseAnthropicAdaptiveThinkingDefault(modelId)
? "adaptive"
: undefined,
resolveUsageAuth: async (ctx) => await ctx.resolveOAuthToken(),
fetchUsageSnapshot: async (ctx) =>
await fetchClaudeUsage(ctx.token, ctx.timeoutMs, ctx.fetchFn),