import { BaseMessage, BaseMessageChunk, BaseMessageLike } from "../messages/base.js";
import { AIMessageChunk } from "../messages/ai.js";
import { MessageOutputVersion } from "../messages/message.js";
import { ChatGenerationChunk, ChatResult, Generation, LLMResult } from "../outputs.js";
import { BaseCache } from "../caches/index.js";
import { SerializableSchema } from "../utils/standard_schema.js";
import { ZodV3Like, ZodV4Like } from "../utils/types/zod.js";
import { ChatModelStreamEvent } from "./event.js";
import { CallbackManagerForLLMRun, Callbacks } from "../callbacks/manager.js";
import { RunnableConfig } from "../runnables/types.js";
import { IterableReadableStream } from "../utils/stream.js";
import { EventStreamCallbackHandlerInput, StreamEvent } from "../tracers/event_stream.js";
import { Runnable, RunnableToolLike } from "../runnables/base.js";
import { BasePromptValueInterface } from "../prompt_values.js";
import { BaseLanguageModel, BaseLanguageModelCallOptions, BaseLanguageModelInput, BaseLanguageModelParams, StructuredOutputMethodOptions, ToolDefinition } from "./base.js";
import { StructuredToolInterface, StructuredToolParams } from "../tools/types.js";
import { ChatModelStream } from "./stream.js";

//#region src/language_models/chat_models.d.ts
type ToolChoice = string | Record<string, any> | "auto" | "any";
/**
 * Represents a serialized chat model.
 */
type SerializedChatModel = {
  _model: string;
  _type: string;
} & Record<string, any>;
/**
 * Represents a serialized large language model.
 */
type SerializedLLM = {
  _model: string;
  _type: string;
} & Record<string, any>;
/**
 * Represents the parameters for a base chat model.
 */
type BaseChatModelParams = BaseLanguageModelParams & {
  /**
   * Whether to disable streaming.
   *
   * If streaming is bypassed, then `stream()` will defer to
   * `invoke()`.
   *
   * - If true, will always bypass streaming case.
   * - If false (default), will always use streaming case if available.
   */
  disableStreaming?: boolean;
  /**
   * Version of `AIMessage` output format to store in message content.
   *
   * `AIMessage.contentBlocks` will lazily parse the contents of `content` into a
   * standard format. This flag can be used to additionally store the standard format
   * as the message content, e.g., for serialization purposes.
   *
   * - "v0": provider-specific format in content (can lazily parse with `.contentBlocks`)
   * - "v1": standardized format in content (consistent with `.contentBlocks`)
   *
   * You can also set `LC_OUTPUT_VERSION` as an environment variable to "v1" to
   * enable this by default.
   *
   * @default "v0"
   */
  outputVersion?: MessageOutputVersion;
};
/**
 * Represents the call options for a base chat model.
 */
type BaseChatModelCallOptions = BaseLanguageModelCallOptions & {
  /**
   * Specifies how the chat model should use tools.
   * @default undefined
   *
   * Possible values:
   * - "auto": The model may choose to use any of the provided tools, or none.
   * - "any": The model must use one of the provided tools.
   * - "none": The model must not use any tools.
   * - A string (not "auto", "any", or "none"): The name of a specific tool the model must use.
   * - An object: A custom schema specifying tool choice parameters. Specific to the provider.
   *
   * Note: Not all providers support tool_choice. An error will be thrown
   * if used with an unsupported model.
   */
  tool_choice?: ToolChoice;
  /**
   * Version of `AIMessage` output format to store in message content.
   *
   * `AIMessage.contentBlocks` will lazily parse the contents of `content` into a
   * standard format. This flag can be used to additionally store the standard format
   * as the message content, e.g., for serialization purposes.
   *
   * - "v0": provider-specific format in content (can lazily parse with `.contentBlocks`)
   * - "v1": standardized format in content (consistent with `.contentBlocks`)
   *
   * You can also set `LC_OUTPUT_VERSION` as an environment variable to "v1" to
   * enable this by default.
   *
   * @default "v0"
   */
  outputVersion?: MessageOutputVersion;
};
type LangSmithParams = {
  ls_provider?: string;
  ls_model_name?: string;
  ls_model_type: "chat";
  ls_temperature?: number;
  ls_max_tokens?: number;
  ls_stop?: Array<string>;
  ls_integration?: string;
};
type BindToolsInput = StructuredToolInterface | Record<string, any> | ToolDefinition | RunnableToolLike | StructuredToolParams;
/**
 * Base class for chat models. It extends the BaseLanguageModel class and
 * provides methods for generating chat based on input messages.
 */
declare abstract class BaseChatModel<CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions, OutputMessageType extends BaseMessageChunk = AIMessageChunk> extends BaseLanguageModel<OutputMessageType, CallOptions> {
  ParsedCallOptions: Omit<CallOptions, Exclude<keyof RunnableConfig, "signal" | "timeout" | "maxConcurrency">>;
  lc_namespace: string[];
  disableStreaming: boolean;
  outputVersion?: MessageOutputVersion;
  get callKeys(): string[];
  constructor(fields: BaseChatModelParams);
  _combineLLMOutput?(...llmOutputs: LLMResult["llmOutput"][]): LLMResult["llmOutput"];
  protected _separateRunnableConfigFromCallOptionsCompat(options?: Partial<CallOptions>): [RunnableConfig, this["ParsedCallOptions"]];
  /**
   * Bind tool-like objects to this chat model.
   *
   * @param tools A list of tool definitions to bind to this chat model.
   * Can be a structured tool, an OpenAI formatted tool, or an object
   * matching the provider's specific tool schema.
   * @param kwargs Any additional parameters to bind.
   */
  bindTools?(tools: BindToolsInput[], kwargs?: Partial<CallOptions>): Runnable<BaseLanguageModelInput, OutputMessageType, CallOptions>;
  /**
   * Invokes the chat model with a single input.
   * @param input The input for the language model.
   * @param options The call options.
   * @returns A Promise that resolves to a BaseMessageChunk.
   */
  invoke(input: BaseLanguageModelInput, options?: Partial<CallOptions>): Promise<OutputMessageType>;
  _streamResponseChunks(_messages: BaseMessage[], _options: this["ParsedCallOptions"], _runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
  /**
   * Stream chat model events using the new content-block-centric protocol.
   *
   * Override this method to provide native event streaming from the provider SDK.
   * The default implementation bridges from `_streamResponseChunks` by
   * synthesizing lifecycle events from `ChatGenerationChunk` objects.
   *
   * ## Event lifecycle
   *
   * ```
   * MessageStart
   *   -> ContentBlockStart(index, contentBlock)
   *     -> ContentBlockDelta(index, delta) ...
   *   -> ContentBlockFinish(index, contentBlock)
   * -> MessageFinish(reason, usage?)
   * ```
   *
   * Content blocks may interleave (e.g., parallel tool calls). The only
   * invariant: a block's start precedes its deltas, and its deltas precede
   * its finish.
   *
   * @param messages - The input messages.
   * @param options - Parsed call options.
   * @param runManager - Optional callback manager for the run.
   * @returns An async generator of {@link ChatModelStreamEvent}.
   */
  _streamChatModelEvents(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatModelStreamEvent>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v2";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v2";
    encoding: "text/event-stream";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v1";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v1";
    encoding: "text/event-stream";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v1" | "v2";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} without a `version`
   * option for content-block streaming instead.
   */
  streamEvents(input: BaseLanguageModelInput, options: Partial<CallOptions> & {
    version: "v1" | "v2";
    encoding: "text/event-stream";
  }, streamOptions?: Omit<EventStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
  /**
   * Create a {@link ChatModelStream} for the given input.
   *
   * Returns a stream object that is both `AsyncIterable<ChatModelStreamEvent>`
   * and `PromiseLike<AIMessage>`, with typed sub-stream accessors for
   * `.text`, `.toolCalls`, `.reasoning`, and `.usage`.
   *
   * @param input - The input messages.
   * @param options - Optional call options.
   * @returns A {@link ChatModelStream}.
   *
   * When `options.version` is `"v1"` or `"v2"`, this delegates to
   * {@link Runnable.streamEvents} for callback-based tracing events instead.
   * That path is deprecated on chat models; prefer calling `streamEvents()`
   * without a `version` option.
   *
   * @example
   * ```ts
   * const stream = model.streamEvents([{ role: "user", content: "Hello" }]);
   *
   * // Stream text
   * for await (const token of stream.text) {
   *   process.stdout.write(token);
   * }
   *
   * // Stream tool calls
   * for await (const toolCall of stream.toolCalls) {
   *   console.log(toolCall);
   * }
   *
   * // Stream reasoning
   * for await (const reasoning of stream.reasoning) {
   *   console.log(reasoning);
   * }
   *
   * // Stream usage
   * for await (const usage of stream.usage) {
   *   console.log(usage);
   * }
   *
   * // Or await the full message
   * const message = await stream;
   * ```
   */
  streamEvents(input: BaseLanguageModelInput, options?: Partial<CallOptions>): ChatModelStream;
  /**
   * @deprecated Use {@link BaseChatModel.streamEvents} instead. This method will be removed in the next major version.
   */
  streamV2(input: BaseLanguageModelInput, options?: Partial<CallOptions>): ChatModelStream;
  _streamIterator(input: BaseLanguageModelInput, options?: Partial<CallOptions>): AsyncGenerator<OutputMessageType>;
  getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
  /**
   * Wraps getLsParams() and always appends ls_integration.
   * This ensures the integration tag is present even when
   * partner packages fully override getLsParams().
   */
  getLsParamsWithDefaults(options: this["ParsedCallOptions"]): LangSmithParams;
  /** @ignore */
  _generateUncached(messages: BaseMessageLike[][], parsedOptions: this["ParsedCallOptions"], handledOptions: RunnableConfig, startedRunManagers?: CallbackManagerForLLMRun[]): Promise<LLMResult>;
  _generateCached({
    messages,
    cache,
    llmStringKey,
    parsedOptions,
    handledOptions
  }: {
    messages: BaseMessageLike[][];
    cache: BaseCache<Generation[]>;
    llmStringKey: string;
    parsedOptions: any;
    handledOptions: RunnableConfig;
  }): Promise<LLMResult & {
    missingPromptIndices: number[];
    startedRunManagers?: CallbackManagerForLLMRun[];
  }>;
  /**
   * Generates chat based on the input messages.
   * @param messages An array of arrays of BaseMessage instances.
   * @param options The call options or an array of stop sequences.
   * @param callbacks The callbacks for the language model.
   * @returns A Promise that resolves to an LLMResult.
   */
  generate(messages: BaseMessageLike[][], options?: string[] | Partial<CallOptions>, callbacks?: Callbacks): Promise<LLMResult>;
  /**
   * Get the parameters used to invoke the model
   */
  invocationParams(_options?: this["ParsedCallOptions"]): any;
  _modelType(): string;
  abstract _llmType(): string;
  /**
   * Generates a prompt based on the input prompt values.
   * @param promptValues An array of BasePromptValue instances.
   * @param options The call options or an array of stop sequences.
   * @param callbacks The callbacks for the language model.
   * @returns A Promise that resolves to an LLMResult.
   */
  generatePrompt(promptValues: BasePromptValueInterface[], options?: string[] | Partial<CallOptions>, callbacks?: Callbacks): Promise<LLMResult>;
  abstract _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: SerializableSchema<RunOutput>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: SerializableSchema<RunOutput>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
    raw: BaseMessage;
    parsed: RunOutput;
  }>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: ZodV4Like<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: ZodV4Like<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
    raw: BaseMessage;
    parsed: RunOutput;
  }>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: ZodV3Like<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
  withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(outputSchema: ZodV3Like<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
    raw: BaseMessage;
    parsed: RunOutput;
  }>;
}
/**
 * An abstract class that extends BaseChatModel and provides a simple
 * implementation of _generate.
 */
declare abstract class SimpleChatModel<CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions> extends BaseChatModel<CallOptions> {
  abstract _call(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<string>;
  _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
}
//#endregion
export { BaseChatModel, BaseChatModelCallOptions, BaseChatModelParams, BindToolsInput, LangSmithParams, SerializedChatModel, SerializedLLM, SimpleChatModel, ToolChoice };
//# sourceMappingURL=chat_models.d.ts.map