/** * Runtime Fallback Hook - Constants * * Default values and configuration constants for the runtime fallback feature. */ import type { RuntimeFallbackConfig } from "../../config" /** * Default configuration values for runtime fallback */ export const DEFAULT_CONFIG: Required = { enabled: false, retry_on_errors: [429, 500, 502, 503, 504], max_fallback_attempts: 3, cooldown_seconds: 60, timeout_seconds: 30, notify_on_fallback: true, } /** * Error patterns that indicate rate limiting or temporary failures * These are checked in addition to HTTP status codes */ export const RETRYABLE_ERROR_PATTERNS = [ /rate.?limit/i, /too.?many.?requests/i, /quota\s+will\s+reset\s+after/i, /quota.?exceeded/i, /exceeded.*quota/i, /usage\s*quota/i, /exhausted\s+your\s+capacity/i, /limit\s+exhausted/i, /all\s+credentials\s+for\s+model/i, /cool(?:ing)?\s+down/i, /model.{0,20}?not.{0,10}?supported/i, /model_not_supported/i, /service.?unavailable/i, /overloaded/i, /temporarily.?unavailable/i, /try.?again/i, /(?:^|\s)429(?:\s|$)/, /(?:^|\s)503(?:\s|$)/, /(?:^|\s)529(?:\s|$)/, /使用上限/, /频率限制/, /请求过于频繁/, /暂时不可用/, /服务不可用/, /请稍后重试/, ] /** * Hook name for identification and logging */ export const HOOK_NAME = "runtime-fallback" /** * First-prompt watchdog: how long to wait for the first sign of progress * (assistant text/reasoning/finish) from a subagent session before assuming * the provider is silently stuck and dispatching the configured fallback. * * Tuned to be longer than typical first-token latency (well under 30s in * practice) yet much shorter than the 30-minute outer poll timeout that * would otherwise be the only safety net. */ export const DEFAULT_FIRST_PROMPT_WATCHDOG_MS = 90_000