mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
fix(models): cycle-safe short names; keep user-alias display
Extra High MERGE AFTER FIX on d3f86f5. mimo-v2.5 aliased to
xiaomi/mimo-v2.5 then last-segment recursed forever. Looking up
SHORT_NAMES before resolveAlias also froze user remaps of known
ids (gpt-4o still displayed as GPT-4o).
Follow user aliases first. Break strip→alias→leaf cycles.
Do not invent a Kimi rate. Do not paper over this with a
mimo-v2.5 SHORT_NAMES row.
This commit is contained in:
parent
d3f86f5d16
commit
d5ced78595
2 changed files with 56 additions and 20 deletions
|
|
@ -985,32 +985,52 @@ function deriveClaudeShortName(canonical: string): string | undefined {
|
|||
return `${CLAUDE_FAMILY[family]} ${major}${minor ? `.${minor}` : ''}`
|
||||
}
|
||||
|
||||
export function getShortModelName(model: string): string {
|
||||
if (autoModelNames[model]) return autoModelNames[model]
|
||||
const stripped = getCanonicalName(model)
|
||||
// Pricing aliases may re-namespace a leaf (mimo-v2.5-pro → xiaomi/…).
|
||||
// Display names live on the leaf. Look that up before following the alias
|
||||
// or we recurse forever: strip → alias → last-segment → strip.
|
||||
for (const [key, name] of SORTED_SHORT_NAMES) {
|
||||
if (stripped === key || stripped.startsWith(key + '-')) return name
|
||||
}
|
||||
const canonical = resolveAlias(stripped)
|
||||
const claude = deriveClaudeShortName(canonical)
|
||||
function lookupShortName(id: string): string | undefined {
|
||||
const claude = deriveClaudeShortName(id)
|
||||
if (claude) return claude
|
||||
for (const [key, name] of SORTED_SHORT_NAMES) {
|
||||
if (canonical === key || canonical.startsWith(key + '-')) return name
|
||||
if (id === key || id.startsWith(key + '-')) return name
|
||||
}
|
||||
// getCanonicalName only strips the leading provider prefix, so a raw
|
||||
// path-style id (e.g. accounts/fireworks/models/glm-5p2) still has slashes
|
||||
// here. Take the last path segment and re-resolve it: the segment may itself
|
||||
// be a known model slug (Fireworks fleet ids), earning a friendly name; a
|
||||
// genuinely unmapped slug resolves to itself, preserving the raw-segment
|
||||
// fallback for everything else.
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function getShortModelName(model: string, seen: Set<string> = new Set()): string {
|
||||
if (autoModelNames[model]) return autoModelNames[model]
|
||||
if (seen.has(model)) {
|
||||
const leaf = model.includes('/') ? model.slice(model.lastIndexOf('/') + 1) : model
|
||||
return lookupShortName(leaf) ?? leaf
|
||||
}
|
||||
seen.add(model)
|
||||
|
||||
// User aliases win over built-in display names. A remap of gpt-4o must
|
||||
// show the target, not "GPT-4o".
|
||||
if (Object.hasOwn(userAliases, model)) {
|
||||
return getShortModelName(userAliases[model]!, seen)
|
||||
}
|
||||
|
||||
const stripped = getCanonicalName(model)
|
||||
if (stripped !== model) {
|
||||
if (Object.hasOwn(userAliases, stripped)) {
|
||||
return getShortModelName(userAliases[stripped]!, seen)
|
||||
}
|
||||
const knownStripped = lookupShortName(stripped)
|
||||
if (knownStripped && !Object.hasOwn(BUILTIN_ALIASES, stripped) && !Object.hasOwn(BUILTIN_ALIASES, stripped.toLowerCase())) {
|
||||
return knownStripped
|
||||
}
|
||||
}
|
||||
|
||||
const canonical = resolveAlias(stripped)
|
||||
const known = lookupShortName(canonical)
|
||||
if (known) return known
|
||||
|
||||
if (canonical.includes('/')) {
|
||||
const segment = canonical.slice(canonical.lastIndexOf('/') + 1)
|
||||
return segment ? getShortModelName(segment) : canonical
|
||||
if (!segment || seen.has(segment) || segment === stripped) {
|
||||
return lookupShortName(segment) ?? segment
|
||||
}
|
||||
return getShortModelName(segment, seen)
|
||||
}
|
||||
return canonical
|
||||
return lookupShortName(canonical) ?? canonical
|
||||
}
|
||||
|
||||
// Pricing is process-global state assembled at CLI startup from the cached
|
||||
|
|
|
|||
|
|
@ -310,6 +310,13 @@ describe('user aliases via setModelAliases', () => {
|
|||
expect(getModelCosts('anthropic--claude-4.6-opus')).toEqual(getModelCosts('claude-sonnet-4-5'))
|
||||
})
|
||||
|
||||
it('user alias whose source already has a short name displays the target', () => {
|
||||
setModelAliases({ 'gpt-4o': 'claude-opus-4-6' })
|
||||
expect(getModelCosts('gpt-4o')).toEqual(getModelCosts('claude-opus-4-6'))
|
||||
expect(getShortModelName('gpt-4o')).toBe('Opus 4.6')
|
||||
setModelAliases({})
|
||||
})
|
||||
|
||||
it('resetting aliases restores builtins', () => {
|
||||
setModelAliases({ 'anthropic--claude-4.6-opus': 'claude-sonnet-4-5' })
|
||||
setModelAliases({})
|
||||
|
|
@ -739,6 +746,8 @@ describe('observed provider model aliases', () => {
|
|||
['MiMo-V2-Flash', 'xiaomi/mimo-v2-flash'],
|
||||
['mimo-v2.5-pro', 'xiaomi/mimo-v2.5-pro'],
|
||||
['MiMo-v2.5-Pro', 'xiaomi/mimo-v2.5-pro'],
|
||||
['mimo-v2.5', 'xiaomi/mimo-v2.5'],
|
||||
['MiMo-v2.5', 'xiaomi/mimo-v2.5'],
|
||||
['KAT-Coder-Pro-V1', 'kwaipilot/kat-coder-pro'],
|
||||
// Kimi Code wires report bare `k3` in llm.request.model; it must price
|
||||
// through the kimi-k3 table entry, not fall through to $0.
|
||||
|
|
@ -760,6 +769,13 @@ describe('observed provider model aliases', () => {
|
|||
expect(getShortModelName('k3')).toBe('Kimi K3')
|
||||
})
|
||||
|
||||
it('does not recurse on vendor-requalified MiMo aliases', () => {
|
||||
expect(getShortModelName('mimo-v2.5')).toBe('mimo-v2.5')
|
||||
expect(getShortModelName('MiMo-v2.5')).toBe('mimo-v2.5')
|
||||
expect(getShortModelName('cline-pass/mimo-v2.5')).toBe('mimo-v2.5')
|
||||
expect(getShortModelName('cline-pass/mimo-v2.5-pro')).toBe('MiMo v2.5 Pro')
|
||||
})
|
||||
|
||||
it('does not map dated Qwen3 Max to a reseller price without provider context', () => {
|
||||
expect(getModelCosts('qwen3-max-2026-01-23')).toBeNull()
|
||||
expect(calculateCost('qwen3-max-2026-01-23', 1_000_000, 1_000_000, 0, 0, 0)).toBe(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue