import { APIUserAbortError, OpenAIError } from 'openai/error'; export declare class EventStream { #private; controller: AbortController; constructor(); protected _run(this: EventStream, executor: () => Promise): void; protected _connected(this: EventStream): void; get ended(): boolean; get errored(): boolean; get aborted(): boolean; abort(): void; /** * Adds the listener function to the end of the listeners array for the event. * No checks are made to see if the listener has already been added. Multiple calls passing * the same combination of event and listener will result in the listener being added, and * called, multiple times. * @returns this ChatCompletionStream, so that calls can be chained */ on(event: Event, listener: EventListener): this; /** * Removes the specified listener from the listener array for the event. * off() will remove, at most, one instance of a listener from the listener array. If any single * listener has been added multiple times to the listener array for the specified event, then * off() must be called multiple times to remove each instance. * @returns this ChatCompletionStream, so that calls can be chained */ off(event: Event, listener: EventListener): this; /** * Adds a one-time listener function for the event. The next time the event is triggered, * this listener is removed and then invoked. * @returns this ChatCompletionStream, so that calls can be chained */ once(event: Event, listener: EventListener): this; /** * This is similar to `.once()`, but returns a Promise that resolves the next time * the event is triggered, instead of calling a listener callback. * @returns a Promise that resolves the next time given event is triggered, * or rejects if an error is emitted. (If you request the 'error' event, * returns a promise that resolves with the error). * * Example: * * const message = await stream.emitted('message') // rejects if the stream errors */ emitted(event: Event): Promise extends [infer Param] ? Param : EventParameters extends [] ? void : EventParameters>; done(): Promise; _emit(event: Event, ...args: EventParameters): void; _emit(event: Event, ...args: EventParameters): void; protected _emitFinal(): void; } type EventListener = Events[EventType]; export type EventParameters = { [Event in EventType]: EventListener extends (...args: infer P) => any ? P : never; }[EventType]; export interface BaseEvents { connect: () => void; error: (error: OpenAIError) => void; abort: (error: APIUserAbortError) => void; end: () => void; } export {}; //# sourceMappingURL=EventStream.d.ts.map