import type { IdentityPlugin } from "./plugin.js"; /** One SSE frame. Every field is optional; `data` may be multi-line (emitted as multiple `data:` lines). */ export interface SSEMessage { readonly data?: string; readonly event?: string; readonly id?: string; /** Client reconnection delay hint, ms (coerced to an integer). */ readonly retry?: number; /** A `: comment` line (e.g. a keep-alive ping). */ readonly comment?: string; } /** The stream handed to the `run` callback. */ export interface SSEStream { /** Enqueue an event frame. No-op once the stream is closed. */ send(message: SSEMessage): void; /** End the stream now. */ close(): void; /** Aborts when the client disconnects - use it to tear down subscriptions/loops. */ readonly signal: AbortSignal; } /** Minimal context shape `sse` needs - the live request, for its client-disconnect signal. */ export interface SSEContext { readonly req: Request; } export interface SSEInit { readonly status?: number; readonly headers?: ConstructorParameters[0]; /** Send a `: ` comment ping every N ms so idle proxies don't drop the connection. */ readonly keepAlive?: number; } /** * The stream handed to an `app.sse()` handler: `send` takes the route's TYPED event payload and * serializes it (JSON) into the SSE `data:` field - the compile-time half of the `sse` contract. */ export interface TypedSSEStream { /** Send one typed event. `init` sets the optional SSE frame fields (`event`, `id`, `retry`). */ send(event: Event, init?: Pick): void; /** Send a `: comment` line (e.g. an explicit ping). */ comment(text: string): void; /** End the stream now. */ close(): void; /** Aborts when the client disconnects - use it to tear down subscriptions/loops. */ readonly signal: AbortSignal; } /** Wrap a raw {@link SSEStream} in the typed, JSON-serializing surface `app.sse()` hands out. */ export declare function typedSSEStream(stream: SSEStream): TypedSSEStream; export declare function sse(c: SSEContext, run: (stream: SSEStream) => void | Promise, init?: SSEInit): Response; /** * Enable `.sse()` streaming routes: `.use(streaming())` installs the SSE runtime. Without it, an * `.sse()` route is a registration error, so the ReadableStream framing stays out of non-SSE bundles. * The `sse()` / `typedSSEStream()` helpers ship from this same subpath for use inside handlers. */ export declare function streaming(): IdentityPlugin; //# sourceMappingURL=sse.d.ts.map