UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

43 lines (42 loc) • 2.57 kB
export const ASK_UNRESOLVABLE_CAUSES = Object.freeze(["approver_unavailable", "no_approver_wired", "mandate_unreconstructible"]); Object.freeze(ASK_UNRESOLVABLE_CAUSES); const ASK_UNRESOLVABLE_CAUSE_SET = new Set(ASK_UNRESOLVABLE_CAUSES); export function isAskUnresolvableCause(v) { return ASK_UNRESOLVABLE_CAUSE_SET.has(v); } const CAUSE_CLAUSE = { approver_unavailable: "the approver reported that nobody is reachable for this ask", no_approver_wired: "nobody in this run can be asked to answer it — the headless posture", mandate_unreconstructible: "an inherited durable-approval mandate binds this ask and this leg has no park facility to honor it", }; const CAUSE_REMEDY_SEAT = { approver_unavailable: "unavailable", no_approver_wired: "absent", mandate_unreconstructible: undefined, }; export function askUnresolvableRemedySeat(cause) { return CAUSE_REMEDY_SEAT[cause]; } export function askUnresolvableNotice(facts) { const { sessionId, toolName, toolCallId, cause, parkLaneExisted, remedy } = facts; if (typeof sessionId !== "string" || sessionId.length === 0) { throw new TypeError("delegation.ask_unresolvable: sessionId is required — a user-audience notice with no session routes nowhere"); } if (typeof toolName !== "string" || toolName.length === 0) { throw new TypeError("delegation.ask_unresolvable: toolName is required"); } if (typeof toolCallId !== "string" || toolCallId.length === 0) { throw new TypeError("delegation.ask_unresolvable: toolCallId is required"); } if (!isAskUnresolvableCause(cause)) { throw new TypeError(`delegation.ask_unresolvable: cause ${JSON.stringify(cause)} is not one of ${ASK_UNRESOLVABLE_CAUSES.join("/")}`); } const park = parkLaneExisted ? "the durable approval park did not take it" : "no durable approval park is armed for this run"; return { code: "delegation.ask_unresolvable", message: `approval for "${toolName}" could not be resolved: ${CAUSE_CLAUSE[cause]} and ${park} — ` + `the call was denied fail-closed and did not run. ${typeof remedy === "string" && remedy.length > 0 ? `To let it run: ${remedy}. ` : ""}To let such approvals wait for a person, run with a checkpoint store and a ` + `durable approval opt-in (or a live approver reachable for delegated children).`, detail: { sessionId, toolName, toolCallId, cause, parkLaneExisted: parkLaneExisted === true, ...(typeof remedy === "string" && remedy.length > 0 ? { remedy } : {}) }, }; }