@ai2070/l0
Version:
L0: The Missing Reliability Substrate for AI
99 lines • 4.24 kB
TypeScript
import { ErrorCategory } from "../types/retry";
export { ErrorCategory };
export declare const L0ErrorCodes: {
readonly STREAM_ABORTED: "STREAM_ABORTED";
readonly INITIAL_TOKEN_TIMEOUT: "INITIAL_TOKEN_TIMEOUT";
readonly INTER_TOKEN_TIMEOUT: "INTER_TOKEN_TIMEOUT";
readonly ZERO_OUTPUT: "ZERO_OUTPUT";
readonly GUARDRAIL_VIOLATION: "GUARDRAIL_VIOLATION";
readonly FATAL_GUARDRAIL_VIOLATION: "FATAL_GUARDRAIL_VIOLATION";
readonly INVALID_STREAM: "INVALID_STREAM";
readonly ALL_STREAMS_EXHAUSTED: "ALL_STREAMS_EXHAUSTED";
readonly NETWORK_ERROR: "NETWORK_ERROR";
readonly DRIFT_DETECTED: "DRIFT_DETECTED";
readonly ADAPTER_NOT_FOUND: "ADAPTER_NOT_FOUND";
readonly FEATURE_NOT_ENABLED: "FEATURE_NOT_ENABLED";
};
export type L0ErrorCode = (typeof L0ErrorCodes)[keyof typeof L0ErrorCodes];
export declare function getErrorCategory(code: L0ErrorCode): ErrorCategory;
export interface L0ErrorContext {
code: L0ErrorCode;
checkpoint?: string;
tokenCount?: number;
contentLength?: number;
modelRetryCount?: number;
networkRetryCount?: number;
fallbackIndex?: number;
metadata?: Record<string, unknown>;
context?: Record<string, unknown>;
}
export declare class L0Error extends Error {
readonly code: L0ErrorCode;
readonly context: L0ErrorContext;
readonly timestamp: number;
constructor(message: string, context: L0ErrorContext);
get category(): ErrorCategory;
get hasCheckpoint(): boolean;
get isRecoverable(): boolean;
getCheckpoint(): string | undefined;
toDetailedString(): string;
toJSON(): {
name: string;
code: L0ErrorCode;
category: ErrorCategory;
message: string;
timestamp: number;
hasCheckpoint: boolean;
checkpoint: string | undefined;
tokenCount: number | undefined;
modelRetryCount: number | undefined;
networkRetryCount: number | undefined;
fallbackIndex: number | undefined;
metadata: Record<string, unknown> | undefined;
context: Record<string, unknown> | undefined;
};
}
export declare function isL0Error(error: unknown): error is L0Error;
export declare enum NetworkErrorType {
CONNECTION_DROPPED = "connection_dropped",
FETCH_ERROR = "fetch_error",
ECONNRESET = "econnreset",
ECONNREFUSED = "econnrefused",
SSE_ABORTED = "sse_aborted",
NO_BYTES = "no_bytes",
PARTIAL_CHUNKS = "partial_chunks",
RUNTIME_KILLED = "runtime_killed",
BACKGROUND_THROTTLE = "background_throttle",
DNS_ERROR = "dns_error",
SSL_ERROR = "ssl_error",
TIMEOUT = "timeout",
UNKNOWN = "unknown"
}
export interface NetworkErrorAnalysis {
type: NetworkErrorType;
retryable: boolean;
countsTowardLimit: boolean;
suggestion: string;
context?: Record<string, any>;
}
export declare function isConnectionDropped(error: Error): boolean;
export declare function isFetchTypeError(error: Error): boolean;
export declare function isECONNRESET(error: Error): boolean;
export declare function isECONNREFUSED(error: Error): boolean;
export declare function isSSEAborted(error: Error): boolean;
export declare function isNoBytes(error: Error): boolean;
export declare function isPartialChunks(error: Error): boolean;
export declare function isRuntimeKilled(error: Error): boolean;
export declare function isBackgroundThrottle(error: Error): boolean;
export declare function isDNSError(error: Error): boolean;
export declare function isSSLError(error: Error): boolean;
export declare function isTimeoutError(error: Error): boolean;
export declare function analyzeNetworkError(error: Error): NetworkErrorAnalysis;
export declare function isNetworkError(error: Error): boolean;
export declare function describeNetworkError(error: Error): string;
export declare function createNetworkError(originalError: Error, analysis: NetworkErrorAnalysis): Error & {
analysis: NetworkErrorAnalysis;
};
export declare function isStreamInterrupted(error: Error, tokenCount: number): boolean;
export declare function suggestRetryDelay(error: Error, attempt: number, customDelays?: Partial<Record<NetworkErrorType, number>>, maxDelay?: number): number;
//# sourceMappingURL=errors.d.ts.map