@sema-agent/core
Version:
Stateless, task-oriented AI agent core
25 lines (24 loc) • 732 B
JavaScript
const humanInputOrdinals = new WeakMap();
export function nextHumanInputSeq(key) {
let box = humanInputOrdinals.get(key);
if (box === undefined) {
box = { n: 0 };
humanInputOrdinals.set(key, box);
}
return ++box.n;
}
const acceptanceSeats = new WeakMap();
export function armAcceptance(record, publish) {
let published;
acceptanceSeats.set(record, () => (published ??= publish()));
}
export function announceAcceptance(record) {
return acceptanceSeats.get(record)?.();
}
export function steeringError(msg, code = "steering.not_running", detail) {
const e = new Error(`cannot steer: ${msg}`);
e.code = code;
if (detail !== undefined)
e.detail = detail;
return e;
}