streaming.d.mts 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. import { type ReadableStream } from "../internal/shim-types.mjs";
  2. import type { OpenAI } from "../client.mjs";
  3. export type ServerSentEvent = {
  4. event: string | null;
  5. data: string;
  6. raw: string[];
  7. };
  8. export declare class Stream<Item> implements AsyncIterable<Item> {
  9. #private;
  10. private iterator;
  11. controller: AbortController;
  12. constructor(iterator: () => AsyncIterator<Item>, controller: AbortController, client?: OpenAI);
  13. static fromSSEResponse<Item>(response: Response, controller: AbortController, client?: OpenAI): Stream<Item>;
  14. /**
  15. * Generates a Stream from a newline-separated ReadableStream
  16. * where each item is a JSON value.
  17. */
  18. static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController, client?: OpenAI): Stream<Item>;
  19. [Symbol.asyncIterator](): AsyncIterator<Item>;
  20. /**
  21. * Splits the stream into two streams which can be
  22. * independently read from at different speeds.
  23. */
  24. tee(): [Stream<Item>, Stream<Item>];
  25. /**
  26. * Converts this stream to a newline-separated ReadableStream of
  27. * JSON stringified values in the stream
  28. * which can be turned back into a Stream with `Stream.fromReadableStream()`.
  29. */
  30. toReadableStream(): ReadableStream;
  31. }
  32. export declare function _iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
  33. //# sourceMappingURL=streaming.d.mts.map