openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 1.58 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
//#region src/infra/approval-errors.ts
const INVALID_REQUEST = "INVALID_REQUEST";
const APPROVAL_NOT_FOUND = "APPROVAL_NOT_FOUND";
const APPROVAL_ALREADY_RESOLVED = "APPROVAL_ALREADY_RESOLVED";
const LEGACY_APPROVAL_NOT_FOUND_RE = /\b(?:unknown or expired approval id|approval expired or not found)\b/i;
function readApprovalErrorDetailsReason(e) {
if (!e || typeof e !== "object" || Array.isArray(e)) return null;
const t = e.reason;
return normalizeOptionalString(t) ?? null;
}
/**
* Detects approval-not-found failures across gateway error shapes.
* Kept broad enough for legacy message-only errors emitted before structured codes.
*/
function isApprovalNotFoundError(e) {
if (!(e instanceof Error)) return false;
const t = normalizeOptionalString(e.gatewayCode);
if (t === APPROVAL_NOT_FOUND) return true;
const n = readApprovalErrorDetailsReason(e.details);
if (t === INVALID_REQUEST && n === APPROVAL_NOT_FOUND) return true;
return LEGACY_APPROVAL_NOT_FOUND_RE.test(e.message);
}
/** Detects approval failures that mean a pending prompt is no longer actionable. */
function isApprovalStaleError(e) {
if (isApprovalNotFoundError(e)) return true;
if (!(e instanceof Error)) return false;
const t = normalizeOptionalString(e.gatewayCode);
const n = readApprovalErrorDetailsReason(e.details);
return t === INVALID_REQUEST && n === APPROVAL_ALREADY_RESOLVED || /approval already resolved/i.test(e.message);
}
//#endregion
export { isApprovalStaleError as n, isApprovalNotFoundError as t };