assistant-stream
Version:
Streaming utilities for AI assistants
51 lines • 1.75 kB
TypeScript
export type SSEEvent = {
event?: string;
data: string;
id?: string;
retry?: number;
};
export declare class SSEEventDecoderError extends Error {
readonly code: "invalid-limit" | "line-too-long" | "event-too-long";
constructor(code: "invalid-limit" | "line-too-long" | "event-too-long", message: string);
}
export type SSEEventDecoderOptions = {
trailing?: "drop" | "dispatch";
/** Maximum UTF-16 code units retained for one unterminated SSE line. */
maxLineLength?: number | undefined;
/** Maximum UTF-16 code units retained across the data lines of one event. */
maxEventLength?: number | undefined;
};
declare class SSEEventDecoderImpl {
private lineChunks;
private lineLength;
private linePreview;
private dataLines;
private eventLength;
private eventName;
private lastEventId;
private retry;
private pendingLF;
private started;
private finished;
private readonly stopAfter;
private readonly trailing;
private readonly maxLineLength;
private readonly maxEventLength;
constructor(options?: SSEEventDecoderOptions, stopAfter?: (event: SSEEvent) => boolean);
push(text: string): SSEEvent[];
flush(): SSEEvent | null;
private processLine;
private dispatchEvent;
private resetFrame;
private appendLineChunk;
private resetLine;
}
export declare const createSSEEventDecoder: (options: SSEEventDecoderOptions, stopAfter?: (event: SSEEvent) => boolean) => SSEEventDecoderImpl;
export declare class SSEEventDecoder {
private readonly decoder;
constructor(options?: SSEEventDecoderOptions);
push(text: string): SSEEvent[];
flush(): SSEEvent | null;
}
export {};
//# sourceMappingURL=SSEEventDecoder.d.ts.map