import type { OpenClawConfig } from "../config/types.openclaw.js"; import { type ModelFallbackStepFields } from "./model-fallback-observation.js"; import type { FallbackAttempt } from "./model-fallback.types.js"; import type { FailoverReason } from "./pi-embedded-helpers/types.js"; type FailoverAttribution = { sessionId?: string; lane?: string; }; /** * Structured error thrown when all model fallback candidates have been * exhausted. Carries per-attempt details so callers can build informative * user-facing messages (e.g. "rate-limited, retry in 30 s"). */ export declare class FallbackSummaryError extends Error { readonly attempts: FallbackAttempt[]; readonly soonestCooldownExpiry: number | null; readonly sessionId?: string; readonly lane?: string; constructor(message: string, attempts: FallbackAttempt[], soonestCooldownExpiry: number | null, cause?: Error, attribution?: FailoverAttribution); } export declare function isFallbackSummaryError(err: unknown): err is FallbackSummaryError; export type ModelFallbackRunOptions = { allowTransientCooldownProbe?: boolean; }; type ModelFallbackRunFn = (provider: string, model: string, options?: ModelFallbackRunOptions) => Promise; type ModelFallbackErrorHandler = (attempt: { provider: string; model: string; error: unknown; attempt: number; total: number; }) => void | Promise; type ModelFallbackStepHandler = (step: ModelFallbackStepFields) => void | Promise; export type ModelFallbackResultClassification = { message: string; reason?: FailoverReason; status?: number; code?: string; rawError?: string; } | { error: unknown; } | null | undefined; type ModelFallbackResultClassifier = (attempt: { result: T; provider: string; model: string; attempt: number; total: number; }) => ModelFallbackResultClassification | Promise; type ModelFallbackRunResult = { result: T; provider: string; model: string; attempts: FallbackAttempt[]; }; declare function resolveProbeThrottleKey(provider: string, agentDir?: string): string; declare function pruneProbeState(now: number): void; declare function isProbeThrottleOpen(now: number, throttleKey: string): boolean; declare function markProbeAttempt(now: number, throttleKey: string): void; /** @internal – exposed for unit tests only */ export declare const _probeThrottleInternals: { readonly lastProbeAttempt: Map; readonly MIN_PROBE_INTERVAL_MS: 30000; readonly PROBE_MARGIN_MS: number; readonly PROBE_STATE_TTL_MS: number; readonly MAX_PROBE_KEYS: 256; readonly resolveProbeThrottleKey: typeof resolveProbeThrottleKey; readonly isProbeThrottleOpen: typeof isProbeThrottleOpen; readonly pruneProbeState: typeof pruneProbeState; readonly markProbeAttempt: typeof markProbeAttempt; }; export declare function runWithModelFallback(params: { cfg: OpenClawConfig | undefined; provider: string; model: string; runId?: string; sessionId?: string; lane?: string; agentDir?: string; /** Optional explicit fallbacks list; when provided (even empty), replaces agents.defaults.model.fallbacks. */ fallbacksOverride?: string[]; run: ModelFallbackRunFn; onError?: ModelFallbackErrorHandler; onFallbackStep?: ModelFallbackStepHandler; classifyResult?: ModelFallbackResultClassifier; }): Promise>; export declare function runWithImageModelFallback(params: { cfg: OpenClawConfig | undefined; modelOverride?: string; run: (provider: string, model: string) => Promise; onError?: ModelFallbackErrorHandler; }): Promise>; export {};