Files
oh-my-opencode/src/shared/context-limit-resolver.ts
T
YeonGyu-Kim def44338ff refactor(models): bump claude-opus-4-6 to claude-opus-4-7 across fallback chains, categories, and hooks
Updates the canonical Anthropic Opus model in every fallback chain
(sisyphus, oracle, prometheus, metis, momus, visual-engineering,
ultrabrain, deep, artistry, unspecified-high), the unspecified-high
category default, the think-mode HIGH_VARIANT_MAP, the Claude Code
alias map, the claude-thinking legacy alias, the context-limit GA
regex, and event.ts fallback strings.

Widens supportsCachedAnthropicLimit to accept both claude-*-4-6 and
claude-*-4-7 so the 1M context cache still applies across the bump.

Regenerates the bundled model-capabilities snapshot from models.dev
and the model-fallback snapshot to match the new source output.
2026-04-17 14:51:52 +09:00

43 lines
1.5 KiB
TypeScript

import process from "node:process"
const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000
export type ContextLimitModelCacheState = {
anthropicContext1MEnabled: boolean
modelContextLimitsCache?: Map<string, number>
}
function isAnthropicProvider(providerID: string): boolean {
const normalized = providerID.toLowerCase()
return normalized === "anthropic" || normalized === "google-vertex-anthropic" || normalized === "aws-bedrock-anthropic"
}
function getAnthropicActualLimit(modelCacheState?: ContextLimitModelCacheState): number {
return (modelCacheState?.anthropicContext1MEnabled ?? false) ||
process.env.ANTHROPIC_1M_CONTEXT === "true" ||
process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true"
? 1_000_000
: DEFAULT_ANTHROPIC_ACTUAL_LIMIT
}
function supportsCachedAnthropicLimit(modelID: string): boolean {
return /^claude-(opus|sonnet)-4(?:-|\.)(?:6|7)(?:-high)?$/.test(modelID)
}
export function resolveActualContextLimit(
providerID: string,
modelID: string,
modelCacheState?: ContextLimitModelCacheState,
): number | null {
if (isAnthropicProvider(providerID)) {
const explicit1M = getAnthropicActualLimit(modelCacheState)
if (explicit1M === 1_000_000) return explicit1M
const cachedLimit = modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`)
if (cachedLimit && supportsCachedAnthropicLimit(modelID)) return cachedLimit
return DEFAULT_ANTHROPIC_ACTUAL_LIMIT
}
return modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`) ?? null
}