import type { KlawConfig } from "../config/types.klaw.js"; import type { AuthProfileStore } from "./auth-profiles/types.js"; import { type ModelFallbackStepFields } from "./model-fallback-observation.js"; import type { FallbackAttempt, ModelCandidate } from "./model-fallback.types.js"; import { type ModelManifestNormalizationContext } from "./model-selection-normalize.js"; import type { FailoverReason } from "./pi-embedded-helpers/types.js"; import { resolveSessionSuspensionReason } from "./session-suspension.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[]; }; type ModelFallbackAuthRuntime = typeof import("./model-fallback-auth.runtime.js"); declare function resolveImageFallbackCandidates(params: { cfg: KlawConfig | undefined; defaultProvider: string; modelOverride?: string; } & ModelManifestNormalizationContext): ModelCandidate[]; export declare const testing: { readonly resolveFallbackCandidates: typeof resolveFallbackCandidates; readonly resolveImageFallbackCandidates: typeof resolveImageFallbackCandidates; readonly resolveCooldownDecision: typeof resolveCooldownDecision; readonly resolveSessionSuspensionReason: typeof resolveSessionSuspensionReason; }; declare function resolveFallbackCandidates(params: { cfg: KlawConfig | undefined; provider: string; model: string; /** Optional explicit fallbacks list; when provided (even empty), replaces agents.defaults.model.fallbacks. */ fallbacksOverride?: string[]; } & ModelManifestNormalizationContext): ModelCandidate[]; 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; }; type CooldownDecision = { type: "skip"; reason: FailoverReason; error: string; } | { type: "attempt"; reason: FailoverReason; markProbe: boolean; } | { type: "suspend_lanes"; reason: FailoverReason; leaderCandidate?: ModelCandidate; }; declare function resolveCooldownDecision(params: { candidate: ModelCandidate; isPrimary: boolean; requestedModel: boolean; hasFallbackCandidates: boolean; now: number; probeThrottleKey: string; authRuntime: ModelFallbackAuthRuntime; authStore: AuthProfileStore; profileIds: string[]; }): CooldownDecision; export declare function runWithModelFallback(params: { cfg: KlawConfig | undefined; provider: string; model: string; runId?: string; sessionId?: string; agentId?: string; sessionKey?: string; resolveAgentHarnessRuntimeOverride?: (provider: string, model: string) => string | undefined; prepareAgentHarnessRuntime?: (params: { provider: string; model: string; agentHarnessRuntimeOverride?: string; }) => Promise | void; 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; skipAuthProfileRuntime?: boolean; } & ModelManifestNormalizationContext): Promise>; export declare function runWithImageModelFallback(params: { cfg: KlawConfig | undefined; modelOverride?: string; run: (provider: string, model: string) => Promise; onError?: ModelFallbackErrorHandler; }): Promise>; export { testing as __testing };