UNPKG

@ai2070/l0

Version:

L0: The Missing Reliability Substrate for AI

634 lines 23.5 kB
import type { GuardrailViolation } from "./guardrails"; import type { L0State } from "./l0"; export type FailureType = "network" | "model" | "tool" | "timeout" | "abort" | "zero_output" | "unknown"; export type RecoveryStrategy = "retry" | "fallback" | "continue" | "halt"; export interface RecoveryPolicy { retryEnabled: boolean; fallbackEnabled: boolean; maxRetries: number; maxFallbacks: number; attempt: number; fallbackIndex: number; } export declare const EventCategory: { readonly SESSION: "SESSION"; readonly STREAM: "STREAM"; readonly ADAPTER: "ADAPTER"; readonly TIMEOUT: "TIMEOUT"; readonly NETWORK: "NETWORK"; readonly ABORT: "ABORT"; readonly GUARDRAIL: "GUARDRAIL"; readonly DRIFT: "DRIFT"; readonly CHECKPOINT: "CHECKPOINT"; readonly RESUME: "RESUME"; readonly RETRY: "RETRY"; readonly FALLBACK: "FALLBACK"; readonly STRUCTURED: "STRUCTURED"; readonly CONTINUATION: "CONTINUATION"; readonly TOOL: "TOOL"; readonly COMPLETION: "COMPLETION"; }; export type EventCategory = (typeof EventCategory)[keyof typeof EventCategory]; export declare const SessionEvents: { readonly SESSION_START: "SESSION_START"; readonly SESSION_END: "SESSION_END"; readonly SESSION_SUMMARY: "SESSION_SUMMARY"; readonly ATTEMPT_START: "ATTEMPT_START"; }; export declare const StreamEvents: { readonly STREAM_INIT: "STREAM_INIT"; readonly STREAM_READY: "STREAM_READY"; readonly TOKEN: "TOKEN"; }; export declare const AdapterEvents: { readonly ADAPTER_DETECTED: "ADAPTER_DETECTED"; readonly ADAPTER_WRAP_START: "ADAPTER_WRAP_START"; readonly ADAPTER_WRAP_END: "ADAPTER_WRAP_END"; }; export declare const TimeoutEvents: { readonly TIMEOUT_START: "TIMEOUT_START"; readonly TIMEOUT_RESET: "TIMEOUT_RESET"; readonly TIMEOUT_TRIGGERED: "TIMEOUT_TRIGGERED"; }; export declare const NetworkEvents: { readonly NETWORK_ERROR: "NETWORK_ERROR"; readonly NETWORK_RECOVERY: "NETWORK_RECOVERY"; readonly CONNECTION_DROPPED: "CONNECTION_DROPPED"; readonly CONNECTION_RESTORED: "CONNECTION_RESTORED"; }; export declare const AbortEvents: { readonly ABORT_REQUESTED: "ABORT_REQUESTED"; readonly ABORT_COMPLETED: "ABORT_COMPLETED"; }; export declare const GuardrailEvents: { readonly GUARDRAIL_PHASE_START: "GUARDRAIL_PHASE_START"; readonly GUARDRAIL_RULE_START: "GUARDRAIL_RULE_START"; readonly GUARDRAIL_RULE_RESULT: "GUARDRAIL_RULE_RESULT"; readonly GUARDRAIL_RULE_END: "GUARDRAIL_RULE_END"; readonly GUARDRAIL_PHASE_END: "GUARDRAIL_PHASE_END"; readonly GUARDRAIL_CALLBACK_START: "GUARDRAIL_CALLBACK_START"; readonly GUARDRAIL_CALLBACK_END: "GUARDRAIL_CALLBACK_END"; }; export declare const DriftEvents: { readonly DRIFT_CHECK_START: "DRIFT_CHECK_START"; readonly DRIFT_CHECK_RESULT: "DRIFT_CHECK_RESULT"; readonly DRIFT_CHECK_END: "DRIFT_CHECK_END"; readonly DRIFT_CHECK_SKIPPED: "DRIFT_CHECK_SKIPPED"; }; export declare const CheckpointEvents: { readonly CHECKPOINT_SAVED: "CHECKPOINT_SAVED"; }; export declare const ResumeEvents: { readonly RESUME_START: "RESUME_START"; }; export declare const RetryEvents: { readonly RETRY_START: "RETRY_START"; readonly RETRY_ATTEMPT: "RETRY_ATTEMPT"; readonly RETRY_END: "RETRY_END"; readonly RETRY_GIVE_UP: "RETRY_GIVE_UP"; readonly RETRY_FN_START: "RETRY_FN_START"; readonly RETRY_FN_RESULT: "RETRY_FN_RESULT"; readonly RETRY_FN_ERROR: "RETRY_FN_ERROR"; }; export declare const FallbackEvents: { readonly FALLBACK_START: "FALLBACK_START"; readonly FALLBACK_MODEL_SELECTED: "FALLBACK_MODEL_SELECTED"; readonly FALLBACK_END: "FALLBACK_END"; }; export declare const StructuredEvents: { readonly STRUCTURED_PARSE_START: "STRUCTURED_PARSE_START"; readonly STRUCTURED_PARSE_END: "STRUCTURED_PARSE_END"; readonly STRUCTURED_PARSE_ERROR: "STRUCTURED_PARSE_ERROR"; readonly STRUCTURED_VALIDATION_START: "STRUCTURED_VALIDATION_START"; readonly STRUCTURED_VALIDATION_END: "STRUCTURED_VALIDATION_END"; readonly STRUCTURED_VALIDATION_ERROR: "STRUCTURED_VALIDATION_ERROR"; readonly STRUCTURED_AUTO_CORRECT_START: "STRUCTURED_AUTO_CORRECT_START"; readonly STRUCTURED_AUTO_CORRECT_END: "STRUCTURED_AUTO_CORRECT_END"; }; export declare const ContinuationEvents: { readonly CONTINUATION_START: "CONTINUATION_START"; }; export declare const ToolEvents: { readonly TOOL_REQUESTED: "TOOL_REQUESTED"; readonly TOOL_START: "TOOL_START"; readonly TOOL_RESULT: "TOOL_RESULT"; readonly TOOL_ERROR: "TOOL_ERROR"; readonly TOOL_COMPLETED: "TOOL_COMPLETED"; }; export declare const CompletionEvents: { readonly COMPLETE: "COMPLETE"; readonly ERROR: "ERROR"; }; export declare const EventType: { readonly COMPLETE: "COMPLETE"; readonly ERROR: "ERROR"; readonly TOOL_REQUESTED: "TOOL_REQUESTED"; readonly TOOL_START: "TOOL_START"; readonly TOOL_RESULT: "TOOL_RESULT"; readonly TOOL_ERROR: "TOOL_ERROR"; readonly TOOL_COMPLETED: "TOOL_COMPLETED"; readonly CONTINUATION_START: "CONTINUATION_START"; readonly STRUCTURED_PARSE_START: "STRUCTURED_PARSE_START"; readonly STRUCTURED_PARSE_END: "STRUCTURED_PARSE_END"; readonly STRUCTURED_PARSE_ERROR: "STRUCTURED_PARSE_ERROR"; readonly STRUCTURED_VALIDATION_START: "STRUCTURED_VALIDATION_START"; readonly STRUCTURED_VALIDATION_END: "STRUCTURED_VALIDATION_END"; readonly STRUCTURED_VALIDATION_ERROR: "STRUCTURED_VALIDATION_ERROR"; readonly STRUCTURED_AUTO_CORRECT_START: "STRUCTURED_AUTO_CORRECT_START"; readonly STRUCTURED_AUTO_CORRECT_END: "STRUCTURED_AUTO_CORRECT_END"; readonly FALLBACK_START: "FALLBACK_START"; readonly FALLBACK_MODEL_SELECTED: "FALLBACK_MODEL_SELECTED"; readonly FALLBACK_END: "FALLBACK_END"; readonly RETRY_START: "RETRY_START"; readonly RETRY_ATTEMPT: "RETRY_ATTEMPT"; readonly RETRY_END: "RETRY_END"; readonly RETRY_GIVE_UP: "RETRY_GIVE_UP"; readonly RETRY_FN_START: "RETRY_FN_START"; readonly RETRY_FN_RESULT: "RETRY_FN_RESULT"; readonly RETRY_FN_ERROR: "RETRY_FN_ERROR"; readonly RESUME_START: "RESUME_START"; readonly CHECKPOINT_SAVED: "CHECKPOINT_SAVED"; readonly DRIFT_CHECK_START: "DRIFT_CHECK_START"; readonly DRIFT_CHECK_RESULT: "DRIFT_CHECK_RESULT"; readonly DRIFT_CHECK_END: "DRIFT_CHECK_END"; readonly DRIFT_CHECK_SKIPPED: "DRIFT_CHECK_SKIPPED"; readonly GUARDRAIL_PHASE_START: "GUARDRAIL_PHASE_START"; readonly GUARDRAIL_RULE_START: "GUARDRAIL_RULE_START"; readonly GUARDRAIL_RULE_RESULT: "GUARDRAIL_RULE_RESULT"; readonly GUARDRAIL_RULE_END: "GUARDRAIL_RULE_END"; readonly GUARDRAIL_PHASE_END: "GUARDRAIL_PHASE_END"; readonly GUARDRAIL_CALLBACK_START: "GUARDRAIL_CALLBACK_START"; readonly GUARDRAIL_CALLBACK_END: "GUARDRAIL_CALLBACK_END"; readonly ABORT_REQUESTED: "ABORT_REQUESTED"; readonly ABORT_COMPLETED: "ABORT_COMPLETED"; readonly NETWORK_ERROR: "NETWORK_ERROR"; readonly NETWORK_RECOVERY: "NETWORK_RECOVERY"; readonly CONNECTION_DROPPED: "CONNECTION_DROPPED"; readonly CONNECTION_RESTORED: "CONNECTION_RESTORED"; readonly TIMEOUT_START: "TIMEOUT_START"; readonly TIMEOUT_RESET: "TIMEOUT_RESET"; readonly TIMEOUT_TRIGGERED: "TIMEOUT_TRIGGERED"; readonly ADAPTER_DETECTED: "ADAPTER_DETECTED"; readonly ADAPTER_WRAP_START: "ADAPTER_WRAP_START"; readonly ADAPTER_WRAP_END: "ADAPTER_WRAP_END"; readonly STREAM_INIT: "STREAM_INIT"; readonly STREAM_READY: "STREAM_READY"; readonly TOKEN: "TOKEN"; readonly SESSION_START: "SESSION_START"; readonly SESSION_END: "SESSION_END"; readonly SESSION_SUMMARY: "SESSION_SUMMARY"; readonly ATTEMPT_START: "ATTEMPT_START"; }; export type EventType = (typeof EventType)[keyof typeof EventType]; export declare const EventTypesByCategory: { readonly SESSION: { readonly SESSION_START: "SESSION_START"; readonly SESSION_END: "SESSION_END"; readonly SESSION_SUMMARY: "SESSION_SUMMARY"; readonly ATTEMPT_START: "ATTEMPT_START"; }; readonly STREAM: { readonly STREAM_INIT: "STREAM_INIT"; readonly STREAM_READY: "STREAM_READY"; readonly TOKEN: "TOKEN"; }; readonly ADAPTER: { readonly ADAPTER_DETECTED: "ADAPTER_DETECTED"; readonly ADAPTER_WRAP_START: "ADAPTER_WRAP_START"; readonly ADAPTER_WRAP_END: "ADAPTER_WRAP_END"; }; readonly TIMEOUT: { readonly TIMEOUT_START: "TIMEOUT_START"; readonly TIMEOUT_RESET: "TIMEOUT_RESET"; readonly TIMEOUT_TRIGGERED: "TIMEOUT_TRIGGERED"; }; readonly NETWORK: { readonly NETWORK_ERROR: "NETWORK_ERROR"; readonly NETWORK_RECOVERY: "NETWORK_RECOVERY"; readonly CONNECTION_DROPPED: "CONNECTION_DROPPED"; readonly CONNECTION_RESTORED: "CONNECTION_RESTORED"; }; readonly ABORT: { readonly ABORT_REQUESTED: "ABORT_REQUESTED"; readonly ABORT_COMPLETED: "ABORT_COMPLETED"; }; readonly GUARDRAIL: { readonly GUARDRAIL_PHASE_START: "GUARDRAIL_PHASE_START"; readonly GUARDRAIL_RULE_START: "GUARDRAIL_RULE_START"; readonly GUARDRAIL_RULE_RESULT: "GUARDRAIL_RULE_RESULT"; readonly GUARDRAIL_RULE_END: "GUARDRAIL_RULE_END"; readonly GUARDRAIL_PHASE_END: "GUARDRAIL_PHASE_END"; readonly GUARDRAIL_CALLBACK_START: "GUARDRAIL_CALLBACK_START"; readonly GUARDRAIL_CALLBACK_END: "GUARDRAIL_CALLBACK_END"; }; readonly DRIFT: { readonly DRIFT_CHECK_START: "DRIFT_CHECK_START"; readonly DRIFT_CHECK_RESULT: "DRIFT_CHECK_RESULT"; readonly DRIFT_CHECK_END: "DRIFT_CHECK_END"; readonly DRIFT_CHECK_SKIPPED: "DRIFT_CHECK_SKIPPED"; }; readonly CHECKPOINT: { readonly CHECKPOINT_SAVED: "CHECKPOINT_SAVED"; }; readonly RESUME: { readonly RESUME_START: "RESUME_START"; }; readonly RETRY: { readonly RETRY_START: "RETRY_START"; readonly RETRY_ATTEMPT: "RETRY_ATTEMPT"; readonly RETRY_END: "RETRY_END"; readonly RETRY_GIVE_UP: "RETRY_GIVE_UP"; readonly RETRY_FN_START: "RETRY_FN_START"; readonly RETRY_FN_RESULT: "RETRY_FN_RESULT"; readonly RETRY_FN_ERROR: "RETRY_FN_ERROR"; }; readonly FALLBACK: { readonly FALLBACK_START: "FALLBACK_START"; readonly FALLBACK_MODEL_SELECTED: "FALLBACK_MODEL_SELECTED"; readonly FALLBACK_END: "FALLBACK_END"; }; readonly STRUCTURED: { readonly STRUCTURED_PARSE_START: "STRUCTURED_PARSE_START"; readonly STRUCTURED_PARSE_END: "STRUCTURED_PARSE_END"; readonly STRUCTURED_PARSE_ERROR: "STRUCTURED_PARSE_ERROR"; readonly STRUCTURED_VALIDATION_START: "STRUCTURED_VALIDATION_START"; readonly STRUCTURED_VALIDATION_END: "STRUCTURED_VALIDATION_END"; readonly STRUCTURED_VALIDATION_ERROR: "STRUCTURED_VALIDATION_ERROR"; readonly STRUCTURED_AUTO_CORRECT_START: "STRUCTURED_AUTO_CORRECT_START"; readonly STRUCTURED_AUTO_CORRECT_END: "STRUCTURED_AUTO_CORRECT_END"; }; readonly CONTINUATION: { readonly CONTINUATION_START: "CONTINUATION_START"; }; readonly TOOL: { readonly TOOL_REQUESTED: "TOOL_REQUESTED"; readonly TOOL_START: "TOOL_START"; readonly TOOL_RESULT: "TOOL_RESULT"; readonly TOOL_ERROR: "TOOL_ERROR"; readonly TOOL_COMPLETED: "TOOL_COMPLETED"; }; readonly COMPLETION: { readonly COMPLETE: "COMPLETE"; readonly ERROR: "ERROR"; }; }; export interface L0ObservabilityEvent { type: EventType; ts: number; streamId: string; context: Record<string, unknown>; } export type L0EventHandler = (event: L0Event) => void; export interface SessionStartEvent extends L0ObservabilityEvent { type: "SESSION_START"; attempt: number; isRetry: boolean; isFallback: boolean; } export interface SessionEndEvent extends L0ObservabilityEvent { type: "SESSION_END"; durationMs: number; success: boolean; tokenCount: number; } export interface SessionSummaryEvent extends L0ObservabilityEvent { type: "SESSION_SUMMARY"; tokenCount: number; startTs: number; endTs: number; totalTokens: number; totalRetries: number; totalFallbacks: number; violations: number; driftDetected: boolean; guardrailViolations: number; fallbackDepth: number; retryCount: number; checkpointsCreated: number; } export interface AttemptStartEvent extends L0ObservabilityEvent { type: "ATTEMPT_START"; attempt: number; isRetry: boolean; isFallback: boolean; } export interface StreamInitEvent extends L0ObservabilityEvent { type: "STREAM_INIT"; } export interface StreamReadyEvent extends L0ObservabilityEvent { type: "STREAM_READY"; adapterName?: string; } export interface AdapterDetectedEvent extends L0ObservabilityEvent { type: "ADAPTER_DETECTED"; adapterName: string; adapter: string; } export interface AdapterWrapStartEvent extends L0ObservabilityEvent { type: "ADAPTER_WRAP_START"; adapterName: string; } export interface AdapterWrapEndEvent extends L0ObservabilityEvent { type: "ADAPTER_WRAP_END"; adapterName: string; durationMs: number; } export interface TimeoutStartEvent extends L0ObservabilityEvent { type: "TIMEOUT_START"; timeoutType: "initial" | "inter"; timeoutMs: number; } export interface TimeoutResetEvent extends L0ObservabilityEvent { type: "TIMEOUT_RESET"; timeoutType: "initial" | "inter"; tokenIndex?: number; } export interface TimeoutTriggeredEvent extends L0ObservabilityEvent { type: "TIMEOUT_TRIGGERED"; timeoutType: "initial" | "inter"; elapsedMs: number; } export interface NetworkErrorEvent extends L0ObservabilityEvent { type: "NETWORK_ERROR"; error: string; errorCode?: string; code?: string; category: string; retryable: boolean; } export interface NetworkRecoveryEvent extends L0ObservabilityEvent { type: "NETWORK_RECOVERY"; attempt: number; attemptCount: number; delayMs: number; durationMs: number; } export interface ConnectionDroppedEvent extends L0ObservabilityEvent { type: "CONNECTION_DROPPED"; reason?: string; } export interface ConnectionRestoredEvent extends L0ObservabilityEvent { type: "CONNECTION_RESTORED"; downtimeMs: number; } export interface AbortRequestedEvent extends L0ObservabilityEvent { type: "ABORT_REQUESTED"; source?: "user" | "timeout" | "error"; } export interface AbortCompletedEvent extends L0ObservabilityEvent { type: "ABORT_COMPLETED"; tokenCount: number; contentLength: number; resourcesFreed?: boolean; } export interface GuardrailPhaseStartEvent extends L0ObservabilityEvent { type: "GUARDRAIL_PHASE_START"; callbackId?: string; ruleCount: number; tokenCount: number; contextSize?: number; } export interface GuardrailRuleStartEvent extends L0ObservabilityEvent { type: "GUARDRAIL_RULE_START"; index: number; ruleId: string; callbackId?: string; } export interface GuardrailRuleResultEvent extends L0ObservabilityEvent { type: "GUARDRAIL_RULE_RESULT"; index: number; ruleId: string; callbackId?: string; passed: boolean; result?: unknown; violation?: GuardrailViolation; rule?: unknown; } export interface GuardrailRuleEndEvent extends L0ObservabilityEvent { type: "GUARDRAIL_RULE_END"; index: number; ruleId: string; callbackId?: string; durationMs: number; } export interface GuardrailPhaseEndEvent extends L0ObservabilityEvent { type: "GUARDRAIL_PHASE_END"; callbackId?: string; totalDurationMs: number; durationMs: number; ruleCount: number; violations: GuardrailViolation[]; shouldRetry: boolean; shouldHalt: boolean; } export interface GuardrailCallbackStartEvent extends L0ObservabilityEvent { type: "GUARDRAIL_CALLBACK_START"; callbackId?: string; callbackType: "onViolation"; index?: number; ruleId?: string; } export interface GuardrailCallbackEndEvent extends L0ObservabilityEvent { type: "GUARDRAIL_CALLBACK_END"; callbackId?: string; callbackType: "onViolation"; index?: number; ruleId?: string; durationMs: number; success?: boolean; error?: string; } export interface DriftCheckStartEvent extends L0ObservabilityEvent { type: "DRIFT_CHECK_START"; checkpoint?: string; tokenCount: number; contentLength: number; strategy?: string; } export interface DriftCheckResultEvent extends L0ObservabilityEvent { type: "DRIFT_CHECK_RESULT"; detected: boolean; types: string[]; confidence?: number; metrics?: Record<string, unknown>; threshold?: number; } export interface DriftCheckEndEvent extends L0ObservabilityEvent { type: "DRIFT_CHECK_END"; durationMs: number; detected: boolean; } export interface DriftCheckSkippedEvent extends L0ObservabilityEvent { type: "DRIFT_CHECK_SKIPPED"; reason: string; } export interface CheckpointSavedEvent extends L0ObservabilityEvent { type: "CHECKPOINT_SAVED"; checkpoint: string; tokenCount: number; } export interface ResumeStartEvent extends L0ObservabilityEvent { type: "RESUME_START"; checkpoint: string; stateHash?: string; tokenCount: number; } export interface RetryStartEvent extends L0ObservabilityEvent { type: "RETRY_START"; attempt: number; maxAttempts: number; reason: string; } export interface RetryAttemptEvent extends L0ObservabilityEvent { type: "RETRY_ATTEMPT"; index?: number; attempt: number; maxAttempts: number; reason: string; delayMs: number; countsTowardLimit?: boolean; isNetwork?: boolean; isModelIssue?: boolean; } export interface RetryEndEvent extends L0ObservabilityEvent { type: "RETRY_END"; attempt: number; totalAttempts: number; success: boolean; durationMs?: number; finalReason?: string; } export interface RetryGiveUpEvent extends L0ObservabilityEvent { type: "RETRY_GIVE_UP"; totalAttempts: number; reason: string; lastError?: string; } export interface RetryFnStartEvent extends L0ObservabilityEvent { type: "RETRY_FN_START"; attempt: number; category: string; defaultShouldRetry: boolean; } export interface RetryFnResultEvent extends L0ObservabilityEvent { type: "RETRY_FN_RESULT"; attempt: number; category: string; userResult: boolean; finalShouldRetry: boolean; durationMs: number; } export interface RetryFnErrorEvent extends L0ObservabilityEvent { type: "RETRY_FN_ERROR"; attempt: number; category: string; error: string; finalShouldRetry: boolean; durationMs: number; } export interface FallbackStartEvent extends L0ObservabilityEvent { type: "FALLBACK_START"; fromIndex: number; toIndex: number; reason: string; } export interface FallbackModelSelectedEvent extends L0ObservabilityEvent { type: "FALLBACK_MODEL_SELECTED"; index: number; } export interface FallbackEndEvent extends L0ObservabilityEvent { type: "FALLBACK_END"; finalIndex: number; success: boolean; } export interface StructuredParseStartEvent extends L0ObservabilityEvent { type: "STRUCTURED_PARSE_START"; contentLength: number; } export interface StructuredParseEndEvent extends L0ObservabilityEvent { type: "STRUCTURED_PARSE_END"; durationMs: number; success: boolean; } export interface StructuredParseErrorEvent extends L0ObservabilityEvent { type: "STRUCTURED_PARSE_ERROR"; error: string; contentPreview?: string; } export interface StructuredValidationStartEvent extends L0ObservabilityEvent { type: "STRUCTURED_VALIDATION_START"; schemaName?: string; } export interface StructuredValidationEndEvent extends L0ObservabilityEvent { type: "STRUCTURED_VALIDATION_END"; durationMs: number; valid: boolean; } export interface StructuredValidationErrorEvent extends L0ObservabilityEvent { type: "STRUCTURED_VALIDATION_ERROR"; errors: string[]; } export interface StructuredAutoCorrectStartEvent extends L0ObservabilityEvent { type: "STRUCTURED_AUTO_CORRECT_START"; errorCount: number; } export interface StructuredAutoCorrectEndEvent extends L0ObservabilityEvent { type: "STRUCTURED_AUTO_CORRECT_END"; durationMs: number; success: boolean; correctionsMade: number; } export interface ContinuationStartEvent extends L0ObservabilityEvent { type: "CONTINUATION_START"; checkpoint: string; tokenCount: number; } export interface ToolRequestedEvent extends L0ObservabilityEvent { type: "TOOL_REQUESTED"; toolName: string; toolCallId: string; arguments: Record<string, unknown>; } export interface ToolStartEvent extends L0ObservabilityEvent { type: "TOOL_START"; toolCallId: string; toolName: string; } export interface ToolResultEvent extends L0ObservabilityEvent { type: "TOOL_RESULT"; toolCallId: string; result: unknown; durationMs: number; } export type ToolErrorType = "NOT_FOUND" | "TIMEOUT" | "EXECUTION_ERROR" | "VALIDATION_ERROR"; export interface ToolErrorEvent extends L0ObservabilityEvent { type: "TOOL_ERROR"; toolCallId: string; error: string; errorType: ToolErrorType; durationMs: number; } export interface ToolCompletedEvent extends L0ObservabilityEvent { type: "TOOL_COMPLETED"; toolCallId: string; status: "success" | "error"; } export interface CompleteEvent extends L0ObservabilityEvent { type: "COMPLETE"; tokenCount: number; contentLength: number; durationMs: number; state?: L0State; } export interface ErrorEvent extends L0ObservabilityEvent { type: "ERROR"; error: string; errorCode?: string; failureType: FailureType; recoveryStrategy: RecoveryStrategy; policy: RecoveryPolicy; } export type L0Event = SessionStartEvent | SessionEndEvent | SessionSummaryEvent | AttemptStartEvent | StreamInitEvent | StreamReadyEvent | AdapterDetectedEvent | AdapterWrapStartEvent | AdapterWrapEndEvent | TimeoutStartEvent | TimeoutResetEvent | TimeoutTriggeredEvent | NetworkErrorEvent | NetworkRecoveryEvent | ConnectionDroppedEvent | ConnectionRestoredEvent | AbortRequestedEvent | AbortCompletedEvent | GuardrailPhaseStartEvent | GuardrailRuleStartEvent | GuardrailRuleResultEvent | GuardrailRuleEndEvent | GuardrailPhaseEndEvent | GuardrailCallbackStartEvent | GuardrailCallbackEndEvent | DriftCheckStartEvent | DriftCheckResultEvent | DriftCheckEndEvent | DriftCheckSkippedEvent | CheckpointSavedEvent | ResumeStartEvent | RetryStartEvent | RetryAttemptEvent | RetryEndEvent | RetryGiveUpEvent | RetryFnStartEvent | RetryFnResultEvent | RetryFnErrorEvent | FallbackStartEvent | FallbackModelSelectedEvent | FallbackEndEvent | StructuredParseStartEvent | StructuredParseEndEvent | StructuredParseErrorEvent | StructuredValidationStartEvent | StructuredValidationEndEvent | StructuredValidationErrorEvent | StructuredAutoCorrectStartEvent | StructuredAutoCorrectEndEvent | ContinuationStartEvent | ToolRequestedEvent | ToolStartEvent | ToolResultEvent | ToolErrorEvent | ToolCompletedEvent | CompleteEvent | ErrorEvent; export declare function serializeEvent(event: L0ObservabilityEvent): string; export declare function deserializeEvent(json: string): L0ObservabilityEvent; //# sourceMappingURL=observability.d.ts.map