feat: 添加 compact 缓存与上下文压缩增强

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
unraid
2026-04-22 22:38:09 +08:00
parent be97a0b010
commit 6c5df395c3
4 changed files with 240 additions and 41 deletions

View File

@@ -86,27 +86,24 @@ export function getAPIContextManagement(options?: {
})
}
// Tool clearing strategies are ant-only
if (process.env.USER_TYPE !== 'ant') {
return strategies.length > 0 ? { edits: strategies } : undefined
}
const useClearToolResults = isEnvTruthy(
process.env.USE_API_CLEAR_TOOL_RESULTS,
)
// Tool clearing: default enabled for all users (upstream gates on USER_TYPE=ant).
// Opt out via USE_API_CLEAR_TOOL_RESULTS=0 / USE_API_CLEAR_TOOL_USES=0.
const useClearToolResults =
process.env.USE_API_CLEAR_TOOL_RESULTS !== undefined
? isEnvTruthy(process.env.USE_API_CLEAR_TOOL_RESULTS)
: true
const useClearToolUses = isEnvTruthy(process.env.USE_API_CLEAR_TOOL_USES)
// If no tool clearing strategy is enabled, return early
if (!useClearToolResults && !useClearToolUses) {
return strategies.length > 0 ? { edits: strategies } : undefined
}
if (useClearToolResults) {
const triggerThreshold = process.env.API_MAX_INPUT_TOKENS
? parseInt(process.env.API_MAX_INPUT_TOKENS)
? parseInt(process.env.API_MAX_INPUT_TOKENS, 10)
: DEFAULT_MAX_INPUT_TOKENS
const keepTarget = process.env.API_TARGET_INPUT_TOKENS
? parseInt(process.env.API_TARGET_INPUT_TOKENS)
? parseInt(process.env.API_TARGET_INPUT_TOKENS, 10)
: DEFAULT_TARGET_INPUT_TOKENS
const strategy: ContextEditStrategy = {
@@ -127,10 +124,10 @@ export function getAPIContextManagement(options?: {
if (useClearToolUses) {
const triggerThreshold = process.env.API_MAX_INPUT_TOKENS
? parseInt(process.env.API_MAX_INPUT_TOKENS)
? parseInt(process.env.API_MAX_INPUT_TOKENS, 10)
: DEFAULT_MAX_INPUT_TOKENS
const keepTarget = process.env.API_TARGET_INPUT_TOKENS
? parseInt(process.env.API_TARGET_INPUT_TOKENS)
? parseInt(process.env.API_TARGET_INPUT_TOKENS, 10)
: DEFAULT_TARGET_INPUT_TOKENS
const strategy: ContextEditStrategy = {