import { ContentBlock } from "../messages/content/index.js";
import { UsageMetadata } from "../messages/metadata.js";
import { AIMessage } from "../messages/ai.js";
import { ChatModelStreamEvent } from "./event.js";

//#region src/language_models/stream.d.ts
/**
 * A buffer that caches emitted events for replay.
 *
 * Multiple consumers can independently iterate the same buffer —
 * each gets its own cursor. Events are never consumed or removed.
 *
 * @internal
 */
declare class ReplayBuffer {
  private events;
  private finished;
  private waiters;
  private error;
  push(event: ChatModelStreamEvent): void;
  finish(): void;
  setError(err: Error): void;
  iterate(): AsyncGenerator<ChatModelStreamEvent>;
}
/**
 * Typed stream for text content.
 *
 * - **Iterate**: yields incremental text deltas.
 * - **Await**: resolves to the complete concatenated text.
 * - **`.full`**: yields the running accumulated text after each delta.
 */
declare class TextContentStream implements AsyncIterable<string>, PromiseLike<string> {
  /** @internal */
  private _buffer;
  /** @internal */
  constructor(buffer: ReplayBuffer);
  /** Yields the accumulated text so far after each delta. */
  get full(): AsyncIterable<string>;
  /** Yields incremental text deltas. */
  [Symbol.asyncIterator](): AsyncIterator<string>;
  then<TResult1 = string, TResult2 = never>(onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
}
/**
 * Typed stream for tool calls.
 *
 * - **Iterate**: yields individual `ToolCall` objects as each completes.
 * - **Await**: resolves to the full array.
 * - **`.full`**: yields the accumulated array after each new tool call.
 */
declare class ToolCallsStream implements AsyncIterable<ContentBlock.Tools.ToolCall>, PromiseLike<Array<ContentBlock.Tools.ToolCall>> {
  /** @internal */
  private _buffer;
  /** @internal */
  constructor(buffer: ReplayBuffer);
  get full(): AsyncIterable<Array<ContentBlock.Tools.ToolCall>>;
  [Symbol.asyncIterator](): AsyncIterator<ContentBlock.Tools.ToolCall>;
  then<TResult1 = Array<ContentBlock.Tools.ToolCall>, TResult2 = never>(onfulfilled?: ((value: Array<ContentBlock.Tools.ToolCall>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
}
/**
 * Typed stream for reasoning content (chain-of-thought).
 * Same interface as {@link TextContentStream} but for reasoning blocks.
 */
declare class ReasoningContentStream implements AsyncIterable<string>, PromiseLike<string> {
  /** @internal */
  private _buffer;
  /** @internal */
  constructor(buffer: ReplayBuffer);
  get full(): AsyncIterable<string>;
  [Symbol.asyncIterator](): AsyncIterator<string>;
  then<TResult1 = string, TResult2 = never>(onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
}
/**
 * Typed stream for usage metadata.
 */
declare class UsageMetadataStream implements AsyncIterable<UsageMetadata>, PromiseLike<UsageMetadata | undefined> {
  /** @internal */
  private _buffer;
  /** @internal */
  constructor(buffer: ReplayBuffer);
  [Symbol.asyncIterator](): AsyncIterator<UsageMetadata>;
  then<TResult1 = UsageMetadata | undefined, TResult2 = never>(onfulfilled?: ((value: UsageMetadata | undefined) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
}
/**
 * The main stream object returned by chat model streaming.
 *
 * Implements `AsyncIterable<ChatModelStreamEvent>` for raw event access
 * and `PromiseLike<AIMessage>` for simple `await` usage.
 */
declare class ChatModelStream implements AsyncIterable<ChatModelStreamEvent>, PromiseLike<AIMessage> {
  /** @internal */
  private _buffer;
  /** @internal */
  constructor(source: AsyncIterable<ChatModelStreamEvent>);
  private _consume;
  [Symbol.asyncIterator](): AsyncIterator<ChatModelStreamEvent>;
  get text(): TextContentStream;
  get toolCalls(): ToolCallsStream;
  get reasoning(): ReasoningContentStream;
  get usage(): UsageMetadataStream;
  get output(): PromiseLike<AIMessage>;
  then<TResult1 = AIMessage, TResult2 = never>(onfulfilled?: ((value: AIMessage) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
  private _assembleMessage;
}
//#endregion
export { ChatModelStream, ReasoningContentStream, TextContentStream, ToolCallsStream, UsageMetadataStream };
//# sourceMappingURL=stream.d.ts.map