@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
41 lines • 2.04 kB
JavaScript
const DEFAULT_COMPACTION_TOKEN_SETTINGS = {
reserveTokens: 16384,
keepRecentTokens: 20000,
};
function isPlainObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
function isNonNegativeSafeInteger(value) {
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
}
export function compactionEnabled(settings) {
return settings?.enabled ?? true;
}
/**
* Resolve one token budget through the model override, then the ordinary setting,
* then the built-in default. A configured-but-invalid value is an error rather than
* a silent fallback, so a typo cannot quietly change the compaction budget.
*/
export function compactionTokenSetting(settings, field, forModel) {
const ordinary = settings?.[field];
if (ordinary !== undefined && !isNonNegativeSafeInteger(ordinary)) {
throw new Error(`Invalid compaction.${field} setting: ${String(ordinary)}. Expected a non-negative safe integer.`);
}
const modelKey = forModel ? `${forModel.provider}/${forModel.id}` : undefined;
const entry = modelKey !== undefined ? settings?.modelOverrides?.[modelKey] : undefined;
if (entry !== undefined && !isPlainObject(entry)) {
throw new Error(`Invalid compaction.modelOverrides["${modelKey}"] setting: ${String(entry)}. Expected an object.`);
}
const override = entry?.[field];
if (override !== undefined && !isNonNegativeSafeInteger(override)) {
throw new Error(`Invalid compaction.modelOverrides["${modelKey}"].${field} setting: ${String(override)}. Expected a non-negative safe integer.`);
}
return override ?? ordinary ?? DEFAULT_COMPACTION_TOKEN_SETTINGS[field];
}
export function compactionReserveTokens(settings, forModel) {
return compactionTokenSetting(settings, "reserveTokens", forModel);
}
export function compactionKeepRecentTokens(settings, forModel) {
return compactionTokenSetting(settings, "keepRecentTokens", forModel);
}
//# sourceMappingURL=compaction-settings-access.js.map