@sema-agent/core
Version:
Stateless, task-oriented AI agent core
21 lines (20 loc) • 1.48 kB
JavaScript
import { resolveDataRoot } from "./fs-atomic.js";
import { holdSingleProcessTableRoot } from "./lock-reading.js";
import { optionKeys, receiptRefusal, receiveMembers } from "../../core/own-property-receipt.js";
import { describeRejectedValue } from "../../core/tool-search-setting.js";
const DATA_ROOT_DECLARATION_KEYS = optionKeys()({ singleProcessTable: 0 });
export function declareDataRoot(root, declaration, anchor) {
if (typeof root !== "string" || root === "") {
throw receiptRefusal(`declareDataRoot: the data root must be a non-empty path (got ${describeRejectedValue(root)})`);
}
if (typeof declaration !== "object" || declaration === null) {
throw receiptRefusal(`declareDataRoot: the declaration must be a record, { singleProcessTable: true } (got ${describeRejectedValue(declaration)})`);
}
const read = receiveMembers(declaration, { subject: "declareDataRoot declaration", unit: "member", moment: "at declareDataRoot" }, DATA_ROOT_DECLARATION_KEYS);
const value = Object.hasOwn(read, "singleProcessTable") ? read.singleProcessTable : undefined;
if (value !== true) {
throw receiptRefusal(`declareDataRoot: singleProcessTable must be the literal true (got ${describeRejectedValue(value)}) — it states that every process ` +
`opening this data root runs in this one process table; where that does not hold, declare nothing`);
}
holdSingleProcessTableRoot(resolveDataRoot(root, anchor));
}