d2c576c510
- postinstall.mjs: fix alias package detection - migrate-legacy-plugin-entry: dedupe + regression tests - task_system: default consistency across runtime paths - task() contract: consistent tool behavior - runtime model selection, tool cap, stale-task cancellation - recovery sanitization, context-limit gating - Ralph semantic DONE hardening, Atlas fallback persistence - native-skill description/content, skill path traversal guard - publish workflow: platform awaited via reusable workflow job - release: version edits reapplied before commit/tag - JSONC plugin migration: top-level plugin key safety - cold-cache: user fallback models skip disconnected providers - docs/version/release framing updates Verified: bun test (4599 pass), tsc --noEmit clean, bun run build clean
43 lines
1.5 KiB
TypeScript
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(?:-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
|
|
}
|