@sema-agent/core
Version:
Stateless, task-oriented AI agent core
25 lines (24 loc) • 1.11 kB
JavaScript
export function refuseRetentionPolicy(label, knob, value, requirement) {
const e = new Error(`${label}: ${knob} must be ${requirement} (got ${typeof value === "string" ? JSON.stringify(value) : String(value)}) — a retention bound that cannot be evaluated silently decides what to delete instead of bounding it`);
e.code = "config.retention_policy_invalid";
throw e;
}
function invalidPolicy(label, knob, value, requirement) {
refuseRetentionPolicy(label, knob, value, requirement);
}
export function assertRetentionPolicy(label, opts) {
if (opts === undefined)
return;
for (const knob of ["maxAgeMs", "staleRunningMaxAgeMs"]) {
const v = opts[knob];
if (v !== undefined && (!Number.isFinite(v) || v < 0)) {
invalidPolicy(label, knob, v, "a finite, non-negative number of milliseconds");
}
}
for (const knob of ["keep", "maxEntries"]) {
const v = opts[knob];
if (v !== undefined && (!Number.isInteger(v) || v < 0)) {
invalidPolicy(label, knob, v, "a whole number of rows, 0 or more");
}
}
}