@sema-agent/core
Version:
Stateless, task-oriented AI agent core
42 lines (41 loc) • 2.92 kB
JavaScript
import { unansweredAskRefusal } from "./ask-origin.js";
export function engineLaneLegOf(internals) {
return internals?.isDelegatedChild === true || internals?.observerLeg === true;
}
export function writeHolderOf(internals) {
return engineLaneLegOf(internals) ? internals?.treeHolder : (internals?.holder ?? internals?.treeHolder);
}
export function claimHolderOf(internals) {
return internals?.holder ?? internals?.treeHolder;
}
export function approvalParkNotResumableOf(leg) {
if (leg.engineLaneLeg && !leg.parkLaneHeld)
return "lane";
return leg.hostDeclaredNotResumable ? "host" : undefined;
}
export function notResumableSaysOf(fact, hostDeclared) {
return fact === undefined ? undefined : hostDeclared ? "host" : fact;
}
export function notResumableWayOut(source, mandated, asks = "approval") {
const verb = asks === "answer" ? "answer" : "approve";
const later = source === "lane"
? `ask from the parent leg itself, or delegate the work as a background agent that can pause — its ${asks === "answer" ? "questions" : "approvals"} wait for a person to ${verb} later, and its result comes back`
: `run it where its host can resume a parked ${asks === "answer" ? "question" : "approval"} (this host declared it cannot)`;
return mandated ? later : `have a person who is present ${verb} it live, or ${later}`;
}
export function reviewRefusalSentence(source) {
return `This plan was not presented to anyone, and no one will review it: ${notResumableClause(source)}. To go on: give the plan in your final report — whoever reads this leg's result can present it to a person for approval; or ${notResumableWayOut(source, true)}.`;
}
export function notResumableClause(source) {
return source === "lane"
? "this leg runs on a lane that holds no park of it (a synchronous or fork child, a background child whose lane cannot park, an observer, or a woken retained agent)"
: "its host declared that a parked approval of this run cannot be resumed";
}
export function notResumableRefusal(subject, source) {
return `${subject}, and this leg cannot be resumed — ${notResumableClause(source)} — so it was refused without asking anyone (fail-closed): the call did not run (do not report it as done); do not retry it on this leg, where nothing can wait for a person`;
}
export const NOT_RESUMABLE_CARRY_ON = "Meanwhile, tell the user what was blocked and why you needed it, and continue with the parts of the task that need no approval.";
export function questionNotShownOnLeg(leg, faceWired) {
const how = faceWired && !leg.mandated ? "nothing could keep it waiting past the live face" : "it was refused without asking anyone; trying again on this leg cannot help";
return unansweredAskRefusal({ cause: "question", noAttempt: true, leg: `this leg cannot be resumed — ${notResumableClause(leg.source)} — so ${how}` });
}