Files
oh-my-opencode/src/shared/context-limit-resolver.ts
T
YeonGyu-Kim f1b5b1023f fix: tighten Anthropic provider matching and fix look-at test isolation
- Replace overly broad .includes('anthropic') with exact provider ID
  matching against known Anthropic providers (anthropic, google-vertex-
  anthropic, aws-bedrock-anthropic) in context-limit-resolver
- Add afterEach cleanup for vision-capable-models cache in look-at
  tool tests to prevent cross-test state leakage
2026-03-12 00:31:02 +09:00

34 lines
1.1 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
}
export function resolveActualContextLimit(
providerID: string,
modelID: string,
modelCacheState?: ContextLimitModelCacheState,
): number | null {
if (isAnthropicProvider(providerID)) {
return getAnthropicActualLimit(modelCacheState)
}
return modelCacheState?.modelContextLimitsCache?.get(`${providerID}/${modelID}`) ?? null
}