import { Message } from "./Message.js"; import { ContentPart, MessageContent } from "./Content.js"; import { ChatOptions } from "./ChatOptions.js"; import { Provider, Usage, ChatChunk, ThinkingConfig, ToolChoice } from "../providers/Provider.js"; import { Stream } from "../streaming/Stream.js"; import { ToolResolvable } from "./Tool.js"; import { Schema } from "../schema/Schema.js"; import { z } from "zod"; import { ToolExecutionMode } from "../constants.js"; export interface AskOptions { images?: string[]; files?: string[]; temperature?: number; maxTokens?: number; headers?: Record; maxToolCalls?: number; requestTimeout?: number; thinking?: ThinkingConfig; prediction?: string | ContentPart[]; signal?: AbortSignal; inputs?: Record; } import { ChatResponseString } from "./ChatResponse.js"; export declare class Chat { private readonly provider; private model; private readonly options; private messages; private systemMessages; private executor; private middlewares; constructor(provider: Provider, model: string, options?: ChatOptions, retryConfig?: { attempts: number; delayMs: number; }); /** * Read-only access to message history */ get history(): readonly Message[]; get modelId(): string; /** * Aggregate usage across the entire conversation */ get totalUsage(): Usage; /** * Add a tool to the chat session (fluent API) * Supports passing a tool instance or a tool class (which will be instantiated). */ withTool(tool: ToolResolvable): this; /** * Add multiple tools to the chat session. * Supports passing Tool classes (which will be instantiated) or instances. * Can replace existing tools if options.replace is true. * * @example * chat.withTools([WeatherTool, new CalculatorTool()], { replace: true, choice: 'required' }); */ withTools(tools: ToolResolvable[], options?: { replace?: boolean; choice?: ToolChoice; calls?: "one" | "many" | number; }): this; /** * Control whether/how tools are called. * - 'auto': (Default) Model decides. * - 'none': Model cannot call tools. * - 'required': Model must call at least one tool. * - string: Force a specific tool by name. */ withToolChoice(choice: ToolChoice): this; /** * Control whether the model may return one or multiple tool calls. * - 'many': (Default) Parallel tool calling allowed. * - 'one' or 1: Only one tool call allowed in a single response. */ withToolCalls(calls: "one" | "many" | number): this; /** * Add instructions (system prompt) to the chat. * By default, it appends a new system message. * If { replace: true } is passed, it removes all previous system messages first. */ withInstructions(instruction: string, options?: { replace?: boolean; }): this; /** * Alias for withInstructions */ withSystemPrompt(instruction: string, options?: { replace?: boolean; }): this; /** * Alias for withInstructions */ system(instruction: string, options?: { replace?: boolean; }): this; /** * Add a message manually to the chat history. * Useful for rehydrating sessions from a database. */ add(role: "user" | "assistant" | "system" | "developer" | "tool", content: string | MessageContent): this; /** * Add a raw Message object to the chat history. */ addMessage(message: Message): this; /** * Add multiple messages to the chat history. */ addMessages(messages: Message[]): this; /** * Set the temperature for the chat session. * Controls randomness: 0.0 (deterministic) to 1.0 (creative). */ withTemperature(temp: number): this; /** * Switch the model used for this chat session. */ withModel(model: string): this; /** * Set custom headers for the chat session. * Merges with existing headers. */ withRequestOptions(options: { headers?: Record; responseFormat?: unknown; }): this; /** * Set provider-specific parameters. * These will be merged into the final request payload. */ withParams(params: Record): this; /** * Enforce a specific schema for the output. * Can accept a Schema object or a Zod schema/JSON Schema directly. */ withSchema(schema: Schema | z.ZodType | Record | null): Chat; /** * Provide a prediction of the expected output to reduce latency. * Particularly useful for code-editing agents modifying existing text. */ withPrediction(prediction: string | ContentPart[] | null): this; /** * Enable and configure extended thinking for reasoning models. */ withThinking(config: ThinkingConfig): this; /** * Shortcut to set thinking effort. */ withEffort(effort: "low" | "medium" | "high" | "none"): this; onNewMessage(handler: () => void): this; onEndMessage(handler: (message: ChatResponseString) => void): this; onToolCall(handler: (toolCall: unknown) => void): this; onToolResult(handler: (result: unknown) => void): this; /** * Called when a tool call starts. */ onToolCallStart(handler: (toolCall: unknown) => void): this; /** * Called when a tool call ends successfully. */ onToolCallEnd(handler: (toolCall: unknown, result: unknown) => void): this; onToolCallError(handler: (toolCall: unknown, error: Error) => "STOP" | "CONTINUE" | "RETRY" | void | Promise<"STOP" | "CONTINUE" | "RETRY" | void>): this; /** * Set the tool execution mode. * - "auto": (Default) Automatically execute all tool calls. * - "confirm": Call onConfirmToolCall before executing each tool. * - "dry-run": Propose tool calls but do not execute them. */ withToolExecution(mode: ToolExecutionMode): this; /** * Hook for confirming tool execution in "confirm" mode. * Return true to proceed, false to cancel the specific call. */ onConfirmToolCall(handler: (toolCall: unknown) => Promise | boolean): this; /** * Add a hook to process messages before sending to the LLM. * Useful for PII detection, redaction, and input moderation. */ beforeRequest(handler: (messages: Message[]) => Promise): this; /** * Add a hook to process the response before returning it. * Useful for output redaction, compliance, and post-moderation. */ afterResponse(handler: (response: ChatResponseString) => Promise): this; /** * Ask the model a question */ ask(content: string | ContentPart[], options?: AskOptions): Promise; /** * Streams the model's response to a user question. */ stream(content: string | ContentPart[], options?: AskOptions): Stream; /** * Normalizes a ToolResolvable into a ToolDefinition. */ private normalizeTool; } //# sourceMappingURL=Chat.d.ts.map