feat: compaction

This commit is contained in:
Gab 2026-03-26 17:26:17 +11:00
parent e581d80c7a
commit 191f907b2d
3 changed files with 8 additions and 4 deletions

View File

@ -381,7 +381,7 @@
},
"packages/tfcode": {
"name": "tfcode",
"version": "1.0.7",
"version": "1.0.8",
"bin": {
"tfcode": "./bin/tfcode",
},

View File

@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/package.json",
"version": "1.0.7",
"version": "1.0.8",
"name": "tfcode",
"type": "module",
"license": "MIT",

View File

@ -29,6 +29,7 @@ export namespace SessionCompaction {
}
const COMPACTION_BUFFER = 20_000
const COMPACTION_BUFFER_TOOTHFAIRYAI = 100_000
export async function isOverflow(input: { tokens: MessageV2.Assistant["tokens"]; model: Provider.Model }) {
const config = await Config.get()
@ -40,8 +41,11 @@ export namespace SessionCompaction {
input.tokens.total ||
input.tokens.input + input.tokens.output + input.tokens.cache.read + input.tokens.cache.write
const reserved =
config.compaction?.reserved ?? Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
const defaultBuffer =
input.model.providerID === "toothfairyai"
? COMPACTION_BUFFER_TOOTHFAIRYAI
: Math.min(COMPACTION_BUFFER, ProviderTransform.maxOutputTokens(input.model))
const reserved = config.compaction?.reserved ?? defaultBuffer
const usable = input.model.limit.input
? input.model.limit.input - reserved
: context - ProviderTransform.maxOutputTokens(input.model)