/** * fetchWithRetry — 带自动重试的 fetch 封装 * * 遇到 50x 上游错误或请求超时(Abort/Timeout/ECONNRESET 等)时, * 自动每隔 intervalMs 重试,最多 maxRetries 次。 * 4xx 等客户端错误不会重试。 * * 支持通过数据库配置的上游代理 PROXY_URL 转发请求。 */ /** 判断错误是否可重试(50x 上游错误、请求超时、上游网关故障、空响应) */ export declare function isRetryableError(err: unknown): boolean; export interface FetchWithRetryOptions extends RequestInit { /** 请求超时毫秒数(每个 attempt 独立计时) */ timeoutMs?: number; /** 最大重试次数(默认 3) */ maxRetries?: number; /** 重试间隔毫秒数(默认 500) */ retryIntervalMs?: number; /** 日志标签 */ providerLabel?: string; /** 请求 ID (Tracing ID) */ requestId?: string; /** 会话种子(用于 opencode.ai 的 x-opencode-session 稳定会话 ID) */ sessionId?: string; /** * 响应校验函数 — 在响应成功返回后被调用,可检查响应内容。 * 如果校验失败,抛出的错误会被 isRetryableError 判断, * 符合条件时自动重试。 */ validateResponse?: (response: globalThis.Response) => Promise | void; } /** * 带自动重试的 fetch,支持响应内容校验 * * 每个 attempt 独立创建 AbortController 并设置超时。 * 遇到可重试错误时等待 retryIntervalMs 后重试。 * 如果提供了 validateResponse,在响应成功后调用,可校验响应内容并触发重试。 */ export declare function fetchWithRetry(endpoint: string, options: FetchWithRetryOptions): Promise; //# sourceMappingURL=fetch-with-retry.d.ts.map