UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

22 lines (21 loc) • 1.31 kB
import { receiptRefusal } from "../../core/own-property-receipt.js"; export const LEDGER_COMPACT_EVERY_DEFAULTS = Object.freeze({ FileCheckpointStore: 1000, FileMailboxStore: 500, FileBackgroundAgentStore: 1000, FileWorkflowRunStore: 1000, }); function shown(value) { return typeof value === "number" ? String(value) : value === null ? "null" : Array.isArray(value) ? "an array" : typeof value; } export function readLedgerTuning(given, store, subject) { const fsync = given.fsync; if (fsync !== undefined && typeof fsync !== "boolean") { throw receiptRefusal(`${subject}.fsync must be a boolean when given (got ${shown(fsync)}) — refused rather than read as on`); } const compactEvery = given.compactEvery; if (compactEvery !== undefined && !(typeof compactEvery === "number" && Number.isSafeInteger(compactEvery) && compactEvery >= 1)) { throw receiptRefusal(`${subject}.compactEvery must be a whole number of events of at least 1 when given (got ${shown(compactEvery)}) — refused rather than kept: such a threshold is never reached (the ledger grows without compacting) or reached at every event (a rewrite per write)`); } return Object.freeze({ fsync: fsync !== false, compactEvery: compactEvery ?? LEDGER_COMPACT_EVERY_DEFAULTS[store] }); }