refactor(sse): extract shared Claude effort-model predicate

This commit is contained in:
Will Gordon
2026-07-30 14:46:45 -04:00
parent 0e66f7e566
commit a8fb526e9c
2 changed files with 33 additions and 4 deletions

View File

@@ -64,6 +64,17 @@ export function formatClaudeEffortLabel(level: string): string {
return level.charAt(0).toUpperCase() + level.slice(1);
}
/**
* Whether `bareModelId` (no provider prefix, no effort suffix) is a real,
* effort-capable Claude-family model — the single source of truth used both to
* decide whether the catalog should advertise an effort variant AND whether
* dispatch-time stripping should unwind one back to this model.
*/
export function isKnownClaudeEffortBaseModel(bareModelId: string): boolean {
const spec = getModelSpec(bareModelId);
return spec?.supportsThinking === true && CLAUDE_NAME_RE.test(bareModelId);
}
/**
* Whether the catalog should advertise reasoning-effort variants for this entry.
*
@@ -84,10 +95,7 @@ export function shouldExposeClaudeEffortVariants(
if (CLAUDE_EFFORT_SUFFIX_RE.test(id)) return false;
const name = bareModelName(id);
const spec = getModelSpec(name);
if (!spec) return false;
return spec.supportsThinking === true && CLAUDE_NAME_RE.test(name);
return isKnownClaudeEffortBaseModel(name);
}
/**

View File

@@ -6,6 +6,7 @@ import {
CLAUDE_XHIGH_EFFORT_LEVEL,
formatClaudeEffortLabel,
shouldExposeClaudeEffortVariants,
isKnownClaudeEffortBaseModel,
claudeEffortLevelsFor,
appendClaudeEffortVariants,
} from "../../open-sse/utils/claudeEffortVariants.ts";
@@ -63,6 +64,26 @@ test("non-string / empty / non-object ids never match", () => {
assert.equal(shouldExposeClaudeEffortVariants({ id: 42 as never }), false);
});
// ── isKnownClaudeEffortBaseModel ─────────────────────────────────────────────
test("isKnownClaudeEffortBaseModel returns true for a real effort-capable Claude model", () => {
assert.equal(isKnownClaudeEffortBaseModel("claude-fable-5"), true);
});
test("isKnownClaudeEffortBaseModel returns false for a non-Claude model", () => {
assert.equal(isKnownClaudeEffortBaseModel("gpt-4o"), false);
});
test("isKnownClaudeEffortBaseModel returns false for an unregistered model id", () => {
assert.equal(isKnownClaudeEffortBaseModel("totally-unregistered-model-xyz"), false);
});
test("isKnownClaudeEffortBaseModel returns false for a non-Claude model that also supports thinking (SC-1)", () => {
// gpt-5.5 has supportsThinking:true in MODEL_SPECS (like 36+ other non-Claude models) —
// the /claude/i name check is the only thing excluding it, not the thinking flag alone.
assert.equal(isKnownClaudeEffortBaseModel("gpt-5.5"), false);
});
// ── claudeEffortLevelsFor ────────────────────────────────────────────────────
test("xHigh is added only for models that support it", () => {