2026-02-03 11:28:22 +09:00
|
|
|
/**
|
|
|
|
|
* 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<RuntimeFallbackConfig> = {
|
2026-02-22 01:54:34 +09:00
|
|
|
enabled: false,
|
2026-03-23 10:34:22 +09:00
|
|
|
retry_on_errors: [402, 429, 500, 502, 503, 504],
|
2026-02-03 11:28:22 +09:00
|
|
|
max_fallback_attempts: 3,
|
|
|
|
|
cooldown_seconds: 60,
|
2026-02-12 13:10:55 -05:00
|
|
|
timeout_seconds: 30,
|
2026-02-03 11:28:22 +09:00
|
|
|
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.?exceeded/i,
|
2026-03-04 18:35:09 +01:00
|
|
|
/quota\s+will\s+reset\s+after/i,
|
|
|
|
|
/all\s+credentials\s+for\s+model/i,
|
|
|
|
|
/cool(?:ing)?\s+down/i,
|
|
|
|
|
/exhausted\s+your\s+capacity/i,
|
2026-02-12 17:13:34 -05:00
|
|
|
/usage\s+limit\s+has\s+been\s+reached/i,
|
2026-03-28 00:42:52 +09:00
|
|
|
/model.{0,20}?not.{0,10}?supported/i,
|
|
|
|
|
/model_not_supported/i,
|
2026-02-03 11:28:22 +09:00
|
|
|
/service.?unavailable/i,
|
|
|
|
|
/overloaded/i,
|
|
|
|
|
/temporarily.?unavailable/i,
|
|
|
|
|
/try.?again/i,
|
2026-02-11 16:59:26 -05:00
|
|
|
/credit.*balance.*too.*low/i,
|
|
|
|
|
/insufficient.?(?:credits?|funds?|balance)/i,
|
2026-03-23 10:34:22 +09:00
|
|
|
/subscription.*quota/i,
|
|
|
|
|
/billing.?(?:hard.?)?limit/i,
|
|
|
|
|
/payment.?required/i,
|
|
|
|
|
/out\s+of\s+credits?/i,
|
|
|
|
|
/(?:^|\s)402(?:\s|$)/,
|
2026-02-05 23:15:05 +09:00
|
|
|
/(?:^|\s)429(?:\s|$)/,
|
|
|
|
|
/(?:^|\s)503(?:\s|$)/,
|
|
|
|
|
/(?:^|\s)529(?:\s|$)/,
|
2026-02-03 11:28:22 +09:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hook name for identification and logging
|
|
|
|
|
*/
|
|
|
|
|
export const HOOK_NAME = "runtime-fallback"
|