@sema-agent/core
Version:
Stateless, task-oriented AI agent core
25 lines (24 loc) • 1.08 kB
JavaScript
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 pauseFamily(t) {
return PAUSE_REGISTRY[t.gate.kind].taskStatus;
}
export function mapNestedSuspend(result) {
const t = result.terminal;
if (!isDurablePause(t)) {
return result;
}
const word = pauseFamily(t);
const code = word === "needs_review" ? UNEXPECTED_NEEDS_REVIEW : UNEXPECTED_SUSPENDED;
const message = `a nested task durably paused ("${word}") on a HITL gate; durable suspend/resume and plan/` +
"dry-run review are only supported at the top-level runTask (design/45 v1 / design/80). Resume it via " +
"the pause's token, 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 },
};
}