Skip to content

Commit eb2d403

Browse files
Lellansinclaude
andcommitted
feat: parse context size threshold from model name suffix
Model names ending with [1m], [70k], [128k], etc. now set the compaction threshold to that context window size automatically, avoiding hardcoded per-model special-cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9dca459 commit eb2d403

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/session.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,24 @@ type ChatCompletionDebugOptions = {
7474
params?: Record<string, unknown>;
7575
};
7676

77+
const CONTEXT_SIZE_SUFFIX_RE = /\[(\d+(?:\.\d+)?)(k|m)\]$/i;
78+
79+
function parseContextSizeSuffix(model: string): number | undefined {
80+
const match = CONTEXT_SIZE_SUFFIX_RE.exec(model);
81+
if (!match) {
82+
return undefined;
83+
}
84+
const value = parseFloat(match[1]);
85+
const unit = match[2].toLowerCase();
86+
const tokens = unit === "m" ? value * 1024 * 1024 : value * 1024;
87+
return Math.floor(tokens);
88+
}
89+
7790
export function getCompactPromptTokenThreshold(model: string): number {
91+
const fromSuffix = parseContextSizeSuffix(model);
92+
if (fromSuffix !== undefined) {
93+
return fromSuffix;
94+
}
7895
return DEEPSEEK_V4_MODELS.has(model)
7996
? DEEPSEEK_V4_COMPACT_PROMPT_TOKEN_THRESHOLD
8097
: DEFAULT_COMPACT_PROMPT_TOKEN_THRESHOLD;

0 commit comments

Comments
 (0)