@mastra/core
Version:
41 lines • 2.16 kB
TypeScript
import type { Processor, ProcessAPIErrorArgs, ProcessAPIErrorResult } from './index.js';
export type StreamErrorRetryMatcher = (error: unknown) => boolean;
export type StreamErrorRetryDelayMs = number | ((args: ProcessAPIErrorArgs) => number | Promise<number>);
/**
* A matcher with its own retry policy. When this matcher is the first to match
* an error, its `maxRetries` and `delayMs` override the processor-level defaults.
* Omitted fields fall back to the processor-level values.
*/
export type StreamErrorRetryMatcherConfig = {
match: StreamErrorRetryMatcher;
maxRetries?: number;
delayMs?: StreamErrorRetryDelayMs;
};
/** A matcher entry: either a plain predicate or a config object with per-matcher policy. */
export type StreamErrorRetryMatcherEntry = StreamErrorRetryMatcher | StreamErrorRetryMatcherConfig;
export type StreamErrorRetryProcessorOptions = {
maxRetries?: number;
matchers?: StreamErrorRetryMatcherEntry[];
/**
* Optional delay (ms) to wait before signaling a retry. Accepts a number or an
* async function evaluated with the current error args. Negative/non-finite
* values are clamped to 0. Defaults to 0 (retry immediately), preserving the
* existing behavior for consumers that do not configure a delay.
*/
delayMs?: StreamErrorRetryDelayMs;
};
export declare function isRetryableOpenAIResponsesStreamError(error: unknown): boolean;
/**
* Matcher for transient HTTP 400 (Bad Request) failures. Providers like OpenAI
* occasionally return 400 during service degradation that succeeds on retry.
* Recommended with `maxRetries: 1` since a 400 could also be genuinely invalid.
*/
export declare function isBadRequestError(error: unknown): boolean;
export declare class StreamErrorRetryProcessor implements Processor<'stream-error-retry-processor'> {
#private;
readonly id: "stream-error-retry-processor";
readonly name = "Stream Error Retry Processor";
constructor(options?: StreamErrorRetryProcessorOptions);
processAPIError(args: ProcessAPIErrorArgs): Promise<ProcessAPIErrorResult | void>;
}
//# sourceMappingURL=stream-error-retry-processor.d.ts.map