UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

47 lines (46 loc) • 2.65 kB
export const REOPEN_REASONS = Object.freeze(["env_failed", "tool_unavailable", "constraint_rejected", "config_refused"]); export const RESUME_STARTUP_CAUSES = Object.freeze(["environment", "session_gone", "transcript_corrupt", "tool_unavailable", "configuration", "decision_rejected"]); const CAUSE_OF_CODE = new Map([ ["resume.env_failed", "environment"], ["checkpoint.resume_aborted", "environment"], ["resume.session_not_found", "session_gone"], ["corrupt_session", "transcript_corrupt"], ["invalid_session", "transcript_corrupt"], ["resume.tool_unavailable", "tool_unavailable"], ["resume.tool_contract_mismatch", "tool_unavailable"], ["checkpoint.config_refused", "configuration"], ["resume.parent_constraint_missing", "configuration"], ["resume.parent_constraint_mismatch", "configuration"], ["checkpoint.gate_mismatch", "decision_rejected"], ["checkpoint.invalid_outcome", "decision_rejected"], ["resume.constraint_rejected", "decision_rejected"], ["resume.constraint_unprojectable", "decision_rejected"], ]); export function resumeStartupCauseOf(code) { if (code === undefined) return undefined; return CAUSE_OF_CODE.get(code) ?? (code.startsWith("config.") ? "configuration" : undefined); } const REOPEN_REASON_OF_CAUSE = { environment: "env_failed", session_gone: "env_failed", transcript_corrupt: "env_failed", tool_unavailable: "tool_unavailable", configuration: "config_refused", decision_rejected: "constraint_rejected", }; export function reopenReasonOf(cause) { return cause === undefined ? "env_failed" : REOPEN_REASON_OF_CAUSE[cause]; } export function reopenedUnstartedSentence(reason) { switch (reason) { case "env_failed": return "the approved action never started, so the checkpoint was REOPENED (pending): the same approval can be resumed again, do not ask for a fresh one"; case "config_refused": return "the approved action never started, so the checkpoint was REOPENED (pending): the deployment's configuration refused the resumed leg, so resuming under the same configuration fails the same way — correct the configuration, then resume, or decide afresh"; case "tool_unavailable": return "the approved action never started, so the checkpoint was REOPENED (pending): the approved tool is not available to the resumed leg, so this approval cannot run — decide afresh"; case "constraint_rejected": return "the approved action never started, so the checkpoint was REOPENED (pending): the decided input was refused, so decide afresh"; } }