import type { KernelRecord } from "../types.js"; export type StreamEventName = "record.created" | "heartbeat" | "error" | "server_shutdown"; export interface StreamEvent { event: StreamEventName; data: Record; id: string | null; } export type DisconnectReason = "client_close" | "server_shutdown" | "lagged" | "transport_error" | "heartbeat_timeout"; export interface TransportRunResult { reason: DisconnectReason; lastCursor: string | null; error?: string; retryAfterMs?: number; } export interface TransportHooks { onOpen?: () => void; onRecord: (record: KernelRecord, cursor: string | null) => void; onHeartbeat?: () => void; } export interface TransportOpenOptions { endpoint: string; thread: string; cursor: string | null; sinceClock?: number; apiKey?: string; bearer?: string; signal: AbortSignal; heartbeatTimeoutMs: number; fetchImpl: typeof fetch; } export type TransportName = "sse" | "ws" | "http" | "ipc"; export interface RequestOp { kind: string; params: Record; } export type TransportFailureClass = "fail-hard" | "retryable" | "disabled" | "unauthorized"; export type TransportResult = { ok: true; data: unknown; } | { ok: false; class: TransportFailureClass; detail: string; }; export interface Transport { readonly name: TransportName; request?(op: RequestOp): Promise; run?(opts: TransportOpenOptions, hooks: TransportHooks): Promise; }