UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 1.62 kB
import { PAUSE_REGISTRY } from "../core/pause-registry.js"; export const UNEXPECTED_SUSPENDED = "unexpected.suspended"; export const UNEXPECTED_NEEDS_REVIEW = "unexpected.needs_review"; export function isDurablePause(terminal) { return terminal.kind === "paused"; } export function resumeNeverStarted(result) { const t = result.terminal; return t.kind === "failed" && t.unstartedRow !== undefined; } export function pauseFamily(t) { return PAUSE_REGISTRY[t.gate.kind].taskStatus; } const LEG_CLAUSE = { card: ", and the leg its parked card records (CheckpointState.compositionLeg)", caller: ", and the parked leg — this run's card records none because the task spec named no session, so you supply it yourself", }; export function mapNestedSuspend(result, resume) { const t = result.terminal; if (!isDurablePause(t)) { return result; } const word = pauseFamily(t); const code = word === "needs_review" ? UNEXPECTED_NEEDS_REVIEW : UNEXPECTED_SUSPENDED; const legClause = resume.legFrom === undefined ? "" : LEG_CLAUSE[resume.legFrom]; const message = `a nested task durably paused ("${word}") on a HITL gate and the orchestrator stopped there, keeping the parked leg's session: ` + `once the pause is decided, continue it with ${resume.door}, handing it this pause's token (nestedPause.token) and the decision${legClause}; ` + "or run the orchestrated task under a non-durable policy so it auto-adjudicates instead of pausing."; return { ...result, terminal: { kind: "failed", code, message, nestedPause: t }, }; }