@sema-agent/core
Version:
Stateless, task-oriented AI agent core
26 lines (25 loc) • 1.38 kB
JavaScript
import { readRowExpectation, sessionRowMatches } from "./repo-utils.js";
import { receiptRefusal } from "../../core/own-property-receipt.js";
import { describeRejectedValue } from "../../core/tool-search-setting.js";
export function readSessionRepoRowCells(where, raw) {
if (raw === undefined || raw === "engine")
return "engine";
if (raw === "host")
return "host";
throw receiptRefusal(`${where}.rowCells must be "engine" (the repo holds a row's occupant cells) or "host" (the host holds them) when given (got ${describeRejectedValue(raw)})`);
}
export function heldRowCells(mode, row) {
if (mode === "engine")
return row;
const { incarnation: _incarnation, forkedFromIncarnation: _forkedFromIncarnation, ...rest } = row;
return rest;
}
export function heldRowMatches(mode, expect, row, logNow) {
if (mode === "host" && expect !== undefined) {
const want = readRowExpectation(expect);
if (want.row !== null && want.row.incarnation !== undefined) {
throw new TypeError(`a session row expectation names an occupant (row.incarnation) to a repo whose occupant cells the host holds (rowCells "host") — this repo judges a conditional write on the row's owner and log; leave the occupant out and judge it in the host's own store`);
}
}
return sessionRowMatches(expect, row, logNow);
}