UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.92 kB
import{l as normalizeOptionalString}from"./string-coerce-CpTFcSwY.mjs";import{d as readErrorName}from"./error-coercion-DlKnt6w-.mjs";import{i as asOptionalObjectRecord,p as readStringField}from"./record-coerce-BTbqdJ3-.mjs";import{d as isProviderRequestSizeCeilingError,h as isTimeoutErrorMessage}from"./message-patterns-CUldVmpX.mjs"; //!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`;const MODEL_CHAT_UNSUPPORTED_TEXT=`This model doesn't support chat; pick another model.`;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.`;const AUTH_PROFILE_COOLDOWN_ERROR_CODE=`auth_profile_cooldown`;const AUTH_ROUTE_ACCOUNT_MISMATCH_CODE=`auth_route_account_mismatch`;const CLI_LIVE_SESSION_HOST_MEMORY_ERROR_CODE=`cli_live_session_host_memory`;const CLI_LIVE_SESSION_LIMIT_ERROR_CODE=`cli_live_session_limit`;const CLI_LIVE_SESSION_REFUSAL_TEXT=/* @__PURE__ */ new Map([[CLI_LIVE_SESSION_HOST_MEMORY_ERROR_CODE,`⚠️ This host is low on memory, so it could not start another session. Try again after active conversations finish.`],[CLI_LIVE_SESSION_LIMIT_ERROR_CODE,`⚠️ This host is already running as many sessions as it allows, so it could not start another one. Try again after active conversations finish.`]]);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;this.rateLimitResetAt=t.rateLimitResetAt}};function assertModelSupportsChat(e,t){if(e===false)throw new FailoverError(MODEL_CHAT_UNSUPPORTED_TEXT,{reason:`format`,code:`model_chat_unsupported`,...t})}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)}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)}function isSignalTimeoutReason(e){try{return readErrorName(e)===`TimeoutError`}catch{return false}}export{isTimeoutError as _,CLI_LIVE_SESSION_REFUSAL_TEXT as a,MODEL_CHAT_REJECTED_CODE as c,assertModelSupportsChat as d,findErrorProperty as f,isSignalTimeoutReason as g,isFailoverError as h,CLI_LIVE_SESSION_LIMIT_ERROR_CODE as i,MODEL_CHAT_REJECTED_TEXT as l,isCliPartialOutputRejected as m,AUTH_ROUTE_ACCOUNT_MISMATCH_CODE as n,CLI_PARTIAL_OUTPUT_REJECTED_ERROR_CODE as o,getFailoverErrorCode as p,CLI_LIVE_SESSION_HOST_MEMORY_ERROR_CODE as r,FailoverError as s,AUTH_PROFILE_COOLDOWN_ERROR_CODE as t,MODEL_CHAT_UNSUPPORTED_TEXT as u,readDirectErrorCode as v,readDirectErrorMessage as y};