Skip to content

Commit ddd073f

Browse files
committed
fix(anthropic): carry catalog compat onto hand-built forward-compat model rows
1 parent 9fd5bde commit ddd073f

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎extensions/anthropic/forward-compat-generation.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ describe("unreleased Claude generations", () => {
4747
expect(supportsClaudeAdaptiveThinking({ id: "claude-haiku-4-5-20251001" })).toBe(false);
4848
});
4949

50+
it("carries manifest catalog compat onto hand-built modern rows", () => {
51+
// The hand-built forward-compat row replaces the catalog row when the
52+
// runtime prefers plugin-resolved modern models. Dropping compat here
53+
// silently disables catalog-driven behavior such as codeMode "auto",
54+
// including on env-key-only runs whose model registry is empty.
55+
expect(resolveModel("claude-opus-5")?.compat).toEqual({ codeMode: "preferred" });
56+
expect(resolveModel("claude-sonnet-5")?.compat).toEqual({ codeMode: "preferred" });
57+
// The Claude CLI provider rows are intentionally unflagged: those runs use
58+
// the CLI harness where OpenClaw code mode does not apply.
59+
expect(resolveModel("claude-opus-5", "claude-cli")?.compat).toBeUndefined();
60+
});
61+
62+
it("prefers registry compat over the manifest index", () => {
63+
const model = buildAnthropicProvider().resolveDynamicModel?.({
64+
provider: "anthropic",
65+
modelId: "claude-opus-5",
66+
config: {},
67+
modelRegistry: {
68+
find: () => ({ compat: { codeMode: "capable" } }),
69+
},
70+
} as unknown as Parameters<
71+
NonNullable<ReturnType<typeof buildAnthropicProvider>["resolveDynamicModel"]>
72+
>[0]);
73+
expect(model?.compat).toEqual({ codeMode: "capable" });
74+
});
75+
5076
it("does not claim non-Claude ids", () => {
5177
// Third-party models reach the Anthropic-compatible transport too.
5278
expect(resolveModel("mimo-v2-flash")).toBeUndefined();

‎extensions/anthropic/register.runtime.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import {
3434
buildProviderReplayFamilyHooks,
3535
cloneFirstTemplateModel,
36+
type ModelCompatConfig,
3637
modelCostsEqual,
3738
type ProviderPlugin,
3839
resolveClaudeFable5ModelIdentity,
@@ -442,6 +443,30 @@ function resolveAnthropicUnreleasedCanonicalModelId(modelId: string): string {
442443
return /(?:^|-)claude-sonnet-/.test(modelId) ? "claude-sonnet-5" : "claude-opus-5";
443444
}
444445

446+
// Lazily indexed manifest compat per provider so hand-built dynamic rows keep
447+
// catalog capability metadata even when the run's model registry is empty
448+
// (for example env-key-only runs without a generated models.json).
449+
let anthropicManifestCompatIndex: Map<string, ModelCompatConfig> | undefined;
450+
451+
function resolveAnthropicManifestCompat(
452+
provider: string,
453+
modelId: string,
454+
): ModelCompatConfig | undefined {
455+
if (!anthropicManifestCompatIndex) {
456+
anthropicManifestCompatIndex = new Map();
457+
const providers = manifest.modelCatalog?.providers ?? {};
458+
for (const [providerId, catalog] of Object.entries(providers)) {
459+
for (const model of catalog.models ?? []) {
460+
const compat = (model as { compat?: ModelCompatConfig }).compat;
461+
if (compat) {
462+
anthropicManifestCompatIndex.set(`${providerId}/${model.id}`, compat);
463+
}
464+
}
465+
}
466+
}
467+
return anthropicManifestCompatIndex.get(`${provider}/${modelId}`);
468+
}
469+
445470
function buildAnthropicForwardCompatModel(
446471
ctx: ProviderResolveDynamicModelContext,
447472
): ProviderRuntimeModel | undefined {
@@ -457,10 +482,21 @@ function buildAnthropicForwardCompatModel(
457482
}
458483
const provider =
459484
normalizedProvider === CLAUDE_CLI_BACKEND_ID ? CLAUDE_CLI_BACKEND_ID : PROVIDER_ID;
485+
// This hand-built row replaces the catalog row when the runtime prefers
486+
// plugin-resolved modern models, so it must carry the catalog's compat
487+
// capability metadata (for example compat.codeMode) instead of dropping it.
488+
// Registry compat wins when present (it may carry config overrides); the
489+
// manifest index covers empty-registry runs such as env-key-only sessions.
490+
const catalogModel = ctx.modelRegistry.find(provider, trimmedModelId) as
491+
| Pick<ProviderRuntimeModel, "compat">
492+
| null
493+
| undefined;
494+
const compat = catalogModel?.compat ?? resolveAnthropicManifestCompat(provider, trimmedModelId);
460495
return {
461496
id: trimmedModelId,
462497
name: trimmedModelId,
463498
provider,
499+
...(compat ? { compat } : {}),
464500
api: "anthropic-messages",
465501
baseUrl: "https://api.anthropic.com",
466502
reasoning: true,

0 commit comments

Comments
 (0)