UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

107 lines (106 loc) • 5.01 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { i as asOptionalObjectRecord, p as readStringField } from "./record-coerce-CVPuDqcc.mjs"; import { d as readErrorName } from "./error-coercion-hDrHOSGy.mjs"; import { d as isProviderRequestSizeCeilingError, h as isTimeoutErrorMessage } from "./message-patterns-xrpp7Aip.mjs"; //#region src/agents/failover/error.ts const ABORT_TIMEOUT_RE = /request was aborted|request aborted/i; const CLI_PARTIAL_OUTPUT_REJECTED_ERROR_CODE = "cli_partial_output_rejected"; /** A listed model failed its chat request; see isListedModelChatRejection. */ const MODEL_CHAT_REJECTED_CODE = "model_chat_rejected"; const MODEL_CHAT_REJECTED_TEXT = "The provider lists this model but rejected a chat request. It may not be a chat model, or it isn't enabled for this account. Choose another model."; /** Host-authored planner diagnostic that names a saved login; never provider reply copy. */ const AUTH_PROFILE_COOLDOWN_ERROR_CODE = "auth_profile_cooldown"; /** The host refused another warm CLI process because its free memory is low. */ const CLI_LIVE_SESSION_HOST_MEMORY_ERROR_CODE = "cli_live_session_host_memory"; /** Structured error used to carry model fallback/failover metadata across layers. */ var FailoverError = class extends Error { constructor(e, t) { super(e, { cause: t.cause }); this.name = "FailoverError"; this.reason = t.reason; this.provider = t.provider; this.model = t.model; this.profileId = t.profileId; this.authMode = t.authMode; this.status = t.status; this.code = t.code; this.rawError = t.rawError; this.rateLimitRetriesExhausted = t.rateLimitRetriesExhausted; this.requestSizeCeiling = isProviderRequestSizeCeilingError(t.rawError ?? e); this.authProfileFailure = t.authProfileFailure; this.sessionId = t.sessionId; this.lane = t.lane; this.suspend = t.suspend; this.cliTimeout = t.cliTimeout; this.timeout = t.timeout; this.attempts = t.attempts; this.soonestCooldownExpiry = t.soonestCooldownExpiry; } }; /** Return true for native or serialized failover errors. */ function isFailoverError(e) { if (e instanceof FailoverError) return true; const t = asOptionalObjectRecord(e); return t?.name === "FailoverError" && typeof t.reason === "string"; } function findErrorProperty(e, t, n = /* @__PURE__ */ new Set()) { const r = t(e); if (r !== void 0) return r; const i = asOptionalObjectRecord(e); if (!i || n.has(i)) return; n.add(i); return findErrorProperty(i.error, t, n) ?? findErrorProperty(i.cause, t, n); } /** Preserve the producer's output decision through cancellation and cleanup wrappers. */ function isCliPartialOutputRejected(e) { return findErrorProperty(e, (e) => isFailoverError(e) && e.code === "cli_partial_output_rejected" ? true : void 0) === true; } function readDirectErrorCode(e) { const t = asOptionalObjectRecord(e); if (!t) return; const n = t.code; if (typeof n === "string") return normalizeOptionalString(n); const r = t.detail?.code; if (typeof r === "string") return normalizeOptionalString(r); const i = t.status; if (typeof i !== "string" || /^\d+$/.test(i)) return; return normalizeOptionalString(i); } function getFailoverErrorCode(e) { return isFailoverError(e) ? e.code : findErrorProperty(e, readDirectErrorCode); } function readDirectErrorMessage(e) { if (e instanceof Error) return e.message || void 0; if (typeof e === "string") return e || void 0; if (typeof e === "number" || typeof e === "boolean" || typeof e === "bigint") return String(e); if (typeof e === "symbol") return e.description; return readStringField(asOptionalObjectRecord(e), "message") || void 0; } function getErrorMessage(e) { return findErrorProperty(e, readDirectErrorMessage) ?? ""; } function hasTimeoutHint(e) { if (!e) return false; if (readErrorName(e) === "TimeoutError") return true; const t = getErrorMessage(e); return Boolean(t && isTimeoutErrorMessage(t)); } function isTimeoutError(e) { if (hasTimeoutHint(e)) return true; if (!e || typeof e !== "object" || readErrorName(e) !== "AbortError") return false; const t = getErrorMessage(e); if (t && ABORT_TIMEOUT_RE.test(t)) return true; const n = "cause" in e ? e.cause : void 0; const r = "reason" in e ? e.reason : void 0; return hasTimeoutHint(n) || hasTimeoutHint(r); } /** Return true when an abort-signal reason is an intentional timeout; plain AbortError is a cancellation, not a timeout. */ function isSignalTimeoutReason(e) { try { return readErrorName(e) === "TimeoutError"; } catch { return false; } } //#endregion export { MODEL_CHAT_REJECTED_CODE as a, getFailoverErrorCode as c, isSignalTimeoutReason as d, isTimeoutError as f, FailoverError as i, isCliPartialOutputRejected as l, readDirectErrorMessage as m, CLI_LIVE_SESSION_HOST_MEMORY_ERROR_CODE as n, MODEL_CHAT_REJECTED_TEXT as o, readDirectErrorCode as p, CLI_PARTIAL_OUTPUT_REJECTED_ERROR_CODE as r, findErrorProperty as s, AUTH_PROFILE_COOLDOWN_ERROR_CODE as t, isFailoverError as u };