edaa95fec0
Move three pure helpers from src/shared/ into @oh-my-opencode/model-core so the package can stand alone without depending on plugin internals:
- buildModelCapabilitiesSnapshotFromModelsDev + fetchModelCapabilitiesSnapshot (models.dev normalization)
- parseModelSuggestion (cross-provider ProviderModelNotFoundError suggestion extraction)
- resolveActualContextLimit (Anthropic GA 1M context override)
Split provider-model-id-transform into two variants exposed by model-core:
- transformModelForProvider keeps the runtime dash to dot Anthropic rewrite used by the SDK
- transformModelForProviderDisplay preserves hyphenated Anthropic IDs so the installer writes registry-compatible model strings, fixing the ProviderModelNotFoundError fresh installs hit when the dotted form leaks into the config
src/shared/* and src/cli/provider-model-id-transform.ts collapse to re-export shims that point at the new core modules. Stale src/shared/{known-variants,model-capability-aliases,model-capability-guardrails,model-capability-heuristics}.ts re-export files plus the duplicated context-limit-resolver test are removed in favor of the canonical model-core copies.
Tests: bun test packages/model-core src/shared/model-capabilities-cache.test.ts src/cli/provider-model-id-transform.test.ts
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import process from "node:process"
|
|
|
|
const DEFAULT_ANTHROPIC_ACTUAL_LIMIT = 200_000
|
|
const ANTHROPIC_GA_1M_LIMIT = 1_000_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"
|
|
? ANTHROPIC_GA_1M_LIMIT
|
|
: DEFAULT_ANTHROPIC_ACTUAL_LIMIT
|
|
}
|
|
|
|
function hasGA1MContext(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 === ANTHROPIC_GA_1M_LIMIT) return explicit1M
|
|
|
|
const cachedLimit = modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`)
|
|
if (cachedLimit && hasGA1MContext(modelID)) return cachedLimit
|
|
|
|
if (hasGA1MContext(modelID)) return ANTHROPIC_GA_1M_LIMIT
|
|
|
|
return DEFAULT_ANTHROPIC_ACTUAL_LIMIT
|
|
}
|
|
|
|
return modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`) ?? null
|
|
}
|