UNPKG

@ai2070/l0

Version:

L0: The Missing Reliability Substrate for AI

172 lines 5.46 kB
export const EventCategory = { SESSION: "SESSION", STREAM: "STREAM", ADAPTER: "ADAPTER", TIMEOUT: "TIMEOUT", NETWORK: "NETWORK", ABORT: "ABORT", GUARDRAIL: "GUARDRAIL", DRIFT: "DRIFT", CHECKPOINT: "CHECKPOINT", RESUME: "RESUME", RETRY: "RETRY", FALLBACK: "FALLBACK", STRUCTURED: "STRUCTURED", CONTINUATION: "CONTINUATION", TOOL: "TOOL", COMPLETION: "COMPLETION", }; export const SessionEvents = { SESSION_START: "SESSION_START", SESSION_END: "SESSION_END", SESSION_SUMMARY: "SESSION_SUMMARY", ATTEMPT_START: "ATTEMPT_START", }; export const StreamEvents = { STREAM_INIT: "STREAM_INIT", STREAM_READY: "STREAM_READY", TOKEN: "TOKEN", }; export const AdapterEvents = { ADAPTER_DETECTED: "ADAPTER_DETECTED", ADAPTER_WRAP_START: "ADAPTER_WRAP_START", ADAPTER_WRAP_END: "ADAPTER_WRAP_END", }; export const TimeoutEvents = { TIMEOUT_START: "TIMEOUT_START", TIMEOUT_RESET: "TIMEOUT_RESET", TIMEOUT_TRIGGERED: "TIMEOUT_TRIGGERED", }; export const NetworkEvents = { NETWORK_ERROR: "NETWORK_ERROR", NETWORK_RECOVERY: "NETWORK_RECOVERY", CONNECTION_DROPPED: "CONNECTION_DROPPED", CONNECTION_RESTORED: "CONNECTION_RESTORED", }; export const AbortEvents = { ABORT_REQUESTED: "ABORT_REQUESTED", ABORT_COMPLETED: "ABORT_COMPLETED", }; export const GuardrailEvents = { GUARDRAIL_PHASE_START: "GUARDRAIL_PHASE_START", GUARDRAIL_RULE_START: "GUARDRAIL_RULE_START", GUARDRAIL_RULE_RESULT: "GUARDRAIL_RULE_RESULT", GUARDRAIL_RULE_END: "GUARDRAIL_RULE_END", GUARDRAIL_PHASE_END: "GUARDRAIL_PHASE_END", GUARDRAIL_CALLBACK_START: "GUARDRAIL_CALLBACK_START", GUARDRAIL_CALLBACK_END: "GUARDRAIL_CALLBACK_END", }; export const DriftEvents = { DRIFT_CHECK_START: "DRIFT_CHECK_START", DRIFT_CHECK_RESULT: "DRIFT_CHECK_RESULT", DRIFT_CHECK_END: "DRIFT_CHECK_END", DRIFT_CHECK_SKIPPED: "DRIFT_CHECK_SKIPPED", }; export const CheckpointEvents = { CHECKPOINT_SAVED: "CHECKPOINT_SAVED", }; export const ResumeEvents = { RESUME_START: "RESUME_START", }; export const RetryEvents = { RETRY_START: "RETRY_START", RETRY_ATTEMPT: "RETRY_ATTEMPT", RETRY_END: "RETRY_END", RETRY_GIVE_UP: "RETRY_GIVE_UP", RETRY_FN_START: "RETRY_FN_START", RETRY_FN_RESULT: "RETRY_FN_RESULT", RETRY_FN_ERROR: "RETRY_FN_ERROR", }; export const FallbackEvents = { FALLBACK_START: "FALLBACK_START", FALLBACK_MODEL_SELECTED: "FALLBACK_MODEL_SELECTED", FALLBACK_END: "FALLBACK_END", }; export const StructuredEvents = { STRUCTURED_PARSE_START: "STRUCTURED_PARSE_START", STRUCTURED_PARSE_END: "STRUCTURED_PARSE_END", STRUCTURED_PARSE_ERROR: "STRUCTURED_PARSE_ERROR", STRUCTURED_VALIDATION_START: "STRUCTURED_VALIDATION_START", STRUCTURED_VALIDATION_END: "STRUCTURED_VALIDATION_END", STRUCTURED_VALIDATION_ERROR: "STRUCTURED_VALIDATION_ERROR", STRUCTURED_AUTO_CORRECT_START: "STRUCTURED_AUTO_CORRECT_START", STRUCTURED_AUTO_CORRECT_END: "STRUCTURED_AUTO_CORRECT_END", }; export const ContinuationEvents = { CONTINUATION_START: "CONTINUATION_START", }; export const ToolEvents = { TOOL_REQUESTED: "TOOL_REQUESTED", TOOL_START: "TOOL_START", TOOL_RESULT: "TOOL_RESULT", TOOL_ERROR: "TOOL_ERROR", TOOL_COMPLETED: "TOOL_COMPLETED", }; export const CompletionEvents = { COMPLETE: "COMPLETE", ERROR: "ERROR", }; export const EventType = { ...SessionEvents, ...StreamEvents, ...AdapterEvents, ...TimeoutEvents, ...NetworkEvents, ...AbortEvents, ...GuardrailEvents, ...DriftEvents, ...CheckpointEvents, ...ResumeEvents, ...RetryEvents, ...FallbackEvents, ...StructuredEvents, ...ContinuationEvents, ...ToolEvents, ...CompletionEvents, }; export const EventTypesByCategory = { [EventCategory.SESSION]: SessionEvents, [EventCategory.STREAM]: StreamEvents, [EventCategory.ADAPTER]: AdapterEvents, [EventCategory.TIMEOUT]: TimeoutEvents, [EventCategory.NETWORK]: NetworkEvents, [EventCategory.ABORT]: AbortEvents, [EventCategory.GUARDRAIL]: GuardrailEvents, [EventCategory.DRIFT]: DriftEvents, [EventCategory.CHECKPOINT]: CheckpointEvents, [EventCategory.RESUME]: ResumeEvents, [EventCategory.RETRY]: RetryEvents, [EventCategory.FALLBACK]: FallbackEvents, [EventCategory.STRUCTURED]: StructuredEvents, [EventCategory.CONTINUATION]: ContinuationEvents, [EventCategory.TOOL]: ToolEvents, [EventCategory.COMPLETION]: CompletionEvents, }; export function serializeEvent(event) { return JSON.stringify(event, (_key, value) => { if (value instanceof Error) { const serialized = {}; for (const key of Object.keys(value)) { serialized[key] = value[key]; } serialized.name = value.name; serialized.message = value.message; serialized.stack = value.stack; serialized.__type = "Error"; return serialized; } return value; }); } export function deserializeEvent(json) { return JSON.parse(json, (_key, value) => { if (value?.__type === "Error") { const err = new Error(value.message); err.name = value.name; err.stack = value.stack; return err; } return value; }); } //# sourceMappingURL=observability.js.map