mono/packages/kbot/ref/services/compact/timeBasedMCConfig.ts
2026-04-01 01:05:48 +02:00

44 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getFeatureValue_CACHED_MAY_BE_STALE } from '../analytics/growthbook.js'
/**
* GrowthBook config for time-based microcompact.
*
* Triggers content-clearing microcompact when the gap since the last main-loop
* assistant message exceeds a threshold — the server-side prompt cache has
* almost certainly expired, so the full prefix will be rewritten anyway.
* Clearing old tool results before the request shrinks what gets rewritten.
*
* Runs BEFORE the API call (in microcompactMessages, upstream of callModel)
* so the shrunk prompt is what actually gets sent. Running after the first
* miss would only help subsequent turns.
*
* Main thread only — subagents have short lifetimes where gap-based eviction
* doesn't apply.
*/
export type TimeBasedMCConfig = {
/** Master switch. When false, time-based microcompact is a no-op. */
enabled: boolean
/** Trigger when (now last assistant timestamp) exceeds this many minutes.
* 60 is the safe choice: the server's 1h cache TTL is guaranteed expired
* for all users, so we never force a miss that wouldn't have happened. */
gapThresholdMinutes: number
/** Keep this many most-recent compactable tool results.
* When set, takes priority over any default; older results are cleared. */
keepRecent: number
}
const TIME_BASED_MC_CONFIG_DEFAULTS: TimeBasedMCConfig = {
enabled: false,
gapThresholdMinutes: 60,
keepRecent: 5,
}
export function getTimeBasedMCConfig(): TimeBasedMCConfig {
// Hoist the GB read so exposure fires on every eval path, not just when
// the caller's other conditions (querySource, messages.length) pass.
return getFeatureValue_CACHED_MAY_BE_STALE<TimeBasedMCConfig>(
'tengu_slate_heron',
TIME_BASED_MC_CONFIG_DEFAULTS,
)
}