UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

7 lines • 2.76 kB
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{d as isProviderRequestSizeCeilingError,f as isRateLimitErrorMessage,o as isBillingErrorMessage}from"./message-patterns-CUldVmpX.mjs";import{t as FAILOVER_REASONS}from"./signal-2DrNzDky.mjs";import{i as looksLikeProviderContextOverflowCandidate,n as isContextOverflowErrorFromTables,r as isReasoningConstraintErrorMessage,t as hasRateLimitTpmHint}from"./context-overflow-tables-B_UZ9JrK.mjs";import{a as resolveLoadedProviderRuntimePlugin,i as resolveLoadedProviderPluginsForHooks}from"./provider-hook-runtime-CkdKr0V8.mjs";import{matchesContextOverflowMessage}from"@openclaw/ai/internal/shared"; //!src/plugins/provider-failover.ts function isFailoverReason(e){return typeof e===`string`&&FAILOVER_REASONS.some(t=>t===e)}function classifyProviderFailoverSignalWithPlugin(e){const t=resolveProviderPluginsForScopedHook(e);for(const n of t){if(n.matchesContextOverflowError?.(e.context))return`context_overflow`;const t=n.classifyFailoverReason?.(e.context);if(t)return isFailoverReason(t)?t:void 0}}function resolveProviderPluginsForScopedHook(e){if(!e.provider)return resolveLoadedProviderPluginsForHooks(e)??[];const t=resolveLoadedProviderRuntimePlugin({...e,provider:e.provider});if(t)return[t];if(hasStructuredFailoverDescriptor(e.context))return[];return resolveLoadedProviderPluginsForHooks(e)??[]}function hasStructuredFailoverDescriptor(e){return e.status!==void 0||e.code!==void 0||e.errorType!==void 0} //!src/agents/failover/provider-patterns.ts function classifyProviderPluginError(e){const{providerPlugin:t,...n}=e;if(t===null)return null;if(t){const e={...n,provider:t.id};if(t.matchesContextOverflowError?.(e))return`context_overflow`;return t.classifyFailoverReason?.(e)??null}return classifyProviderFailoverSignalWithPlugin({provider:e.provider,context:n})??null} //!src/agents/failover/context-overflow.ts function isContextOverflowError(e){if(!e)return false;return isContextOverflowErrorFromTables(e)||looksLikeProviderContextOverflowCandidate(e)&&classifyProviderPluginError({errorMessage:e})===`context_overflow`}function isLikelyContextOverflowError(e){if(!e)return false;if(isProviderRequestSizeCeilingError(e))return isContextOverflowErrorFromTables(e);if(hasRateLimitTpmHint(e)||isReasoningConstraintErrorMessage(e)||isBillingErrorMessage(e)||matchesContextOverflowMessage(e,`context-window-too-small`)||isRateLimitErrorMessage(e))return false;return isContextOverflowError(e)||!normalizeLowercaseStringOrEmpty(e).includes(`prompt template`)&&!matchesContextOverflowMessage(e,`rate-limit-hint`)&&matchesContextOverflowMessage(e,`failover-hint`)}export{isLikelyContextOverflowError as n,classifyProviderPluginError as r,isContextOverflowError as t};