fix: read anthropic 1m flag from live model cache state

This commit is contained in:
YeonGyu-Kim
2026-02-17 10:45:48 +09:00
parent d979bd945a
commit 21144ed1e3
12 changed files with 64 additions and 38 deletions
+8 -4
View File
@@ -2,8 +2,12 @@ import { log } from "../shared/logger"
const DEFAULT_ACTUAL_LIMIT = 200_000
function getAnthropicActualLimit(anthropicContext1MEnabled: boolean): number {
return anthropicContext1MEnabled ||
type ModelCacheStateLike = {
anthropicContext1MEnabled: boolean
}
function getAnthropicActualLimit(modelCacheState?: ModelCacheStateLike): number {
return (modelCacheState?.anthropicContext1MEnabled ?? false) ||
process.env.ANTHROPIC_1M_CONTEXT === "true" ||
process.env.VERTEX_ANTHROPIC_1M_CONTEXT === "true"
? 1_000_000
@@ -47,7 +51,7 @@ type PluginInput = {
export function createPreemptiveCompactionHook(
ctx: PluginInput,
anthropicContext1MEnabled = false,
modelCacheState?: ModelCacheStateLike,
) {
const compactionInProgress = new Set<string>()
const compactedSessions = new Set<string>()
@@ -65,7 +69,7 @@ export function createPreemptiveCompactionHook(
const actualLimit =
isAnthropicProvider(cached.providerID)
? getAnthropicActualLimit(anthropicContext1MEnabled)
? getAnthropicActualLimit(modelCacheState)
: DEFAULT_ACTUAL_LIMIT
const lastTokens = cached.tokens