import { SchemaStreamChunk, SchemaStreamDefaultData } from 'schema-stream'; import { z } from 'zod'; import OpenAI from 'openai'; declare const MODE: { readonly FUNCTIONS: "FUNCTIONS"; readonly TOOLS: "TOOLS"; readonly JSON: "JSON"; readonly MD_JSON: "MD_JSON"; readonly JSON_SCHEMA: "JSON_SCHEMA"; readonly THINKING_MD_JSON: "THINKING_MD_JSON"; }; type ActivePath = (string | number | undefined)[]; type CompletedPaths = ActivePath[]; type CompletionMeta = { _activePath: ActivePath; _completedPaths: CompletedPaths; _isValid: boolean; }; type ZodStreamChunk = SchemaStreamChunk & { _meta: CompletionMeta; }; type ZodStreamValue = SchemaStreamChunk; type LogLevel = "debug" | "info" | "warn" | "error"; type ClientConfig = { debug?: boolean; }; type JsonSchema = z.core.JSONSchema.JSONSchema; type ParseParams = { name: string; description?: string; schema: JsonSchema; }; type Mode = keyof typeof MODE; type ResponseModel = { schema: T; name: string; description?: string; }; type ZodStreamCompletionParams = { response_model: { schema: T; name?: string; description?: string; }; data?: Record; completionPromise: (data?: Record) => Promise>; }; type ZodStreamDefaultData = SchemaStreamDefaultData; type InferStreamType = T extends { stream: true; } ? OpenAI.ChatCompletionCreateParamsStreaming : OpenAI.ChatCompletionCreateParamsNonStreaming; type FunctionParamsReturnType = T & { function_call: OpenAI.ChatCompletionFunctionCallOption; functions: OpenAI.ChatCompletionCreateParams.Function[]; }; type ToolFunctionParamsReturnType = T & { tool_choice: OpenAI.ChatCompletionToolChoiceOption; tools: OpenAI.ChatCompletionTool[]; }; type MessageBasedParamsReturnType = T; type JsonModeParamsReturnType = T & { response_format: { type: "json_object"; }; messages: OpenAI.ChatCompletionMessageParam[]; }; type JsonSchemaParamsReturnType> = T & { response_format: { type: "json_schema"; json_schema: { name: string; description?: string; schema: JsonSchema; strict: true; }; }; messages: OpenAI.ChatCompletionMessageParam[]; }; type ModeParamsReturnType = M extends typeof MODE.FUNCTIONS ? FunctionParamsReturnType : M extends typeof MODE.TOOLS ? ToolFunctionParamsReturnType : M extends typeof MODE.JSON ? JsonModeParamsReturnType : M extends typeof MODE.JSON_SCHEMA ? JsonSchemaParamsReturnType : MessageBasedParamsReturnType; declare class ZodStream { readonly debug: boolean; constructor({ debug }?: ClientConfig); private log; private chatCompletionStream; getSchemaStub({ schema, defaultData }: { schema: T; defaultData?: ZodStreamDefaultData; }): SchemaStreamChunk; create(params: ZodStreamCompletionParams): Promise, z.output, unknown>>; } /** Converts a Zod 4 input schema to the JSON Schema dialect accepted by Chat Completions. */ declare function responseModelToJsonSchema(schema: z.ZodObject): JsonSchema; declare function withResponseModel({ response_model: { name, schema, description }, mode, params }: { response_model: ResponseModel; mode: M; params: P; }): ModeParamsReturnType; /** * `OAIResponseFnArgsParser` parses a JSON string and extracts the function call arguments. * * @param {string} data - The JSON string to parse. * @returns {string} - The extracted function arguments. * */ declare function OAIResponseFnArgsParser(data: string | OpenAI.Chat.Completions.ChatCompletionChunk | OpenAI.Chat.Completions.ChatCompletion): string; /** * `OAIResponseToolArgsParser` parses a JSON string and extracts the tool call arguments. * * @param {string} data - The JSON string to parse. * @returns {Objstringect} - The extracted tool call arguments. * */ declare function OAIResponseToolArgsParser(data: string | OpenAI.Chat.Completions.ChatCompletionChunk | OpenAI.Chat.Completions.ChatCompletion): string; /** * `OAIResponseJSONParser` parses a JSON string and extracts the JSON content. * * @param {string} data - The JSON string to parse. * @returns {string} - The extracted JSON content. * * */ declare function OAIResponseJSONParser(data: string | OpenAI.Chat.Completions.ChatCompletionChunk | OpenAI.Chat.Completions.ChatCompletion): string; /** * `OAIResponseParser` parses a JSON string or a response object. * It checks if the input contains function call arguments. If it does, * it uses `OAIResponseFnArgsParser` to parse the input, otherwise, it uses `OAIResponseTextParser`. * * @param {string | Stream | OpenAI.Chat.Completions.ChatCompletion} data - The input to parse. * @returns {string} - The result of the appropriate parser. */ declare function OAIResponseParser(data: string | OpenAI.Chat.Completions.ChatCompletionChunk | OpenAI.Chat.Completions.ChatCompletion): string; interface OaiStreamArgs { res: AsyncIterable; } /** Converts OpenAI Chat Completion deltas into a backpressure-aware byte stream. */ declare function OAIStream({ res }: OaiStreamArgs): ReadableStream; /** Converts a byte stream of sequential JSON values into an async generator. */ declare function readableStreamToAsyncGenerator(stream: ReadableStream): AsyncGenerator; type CreateAgentParams = { defaultClientOptions: Partial & { model: OpenAI.ChatCompletionCreateParams["model"]; messages: OpenAI.ChatCompletionMessageParam[]; }; /** @default "TOOLS" */ mode?: Mode; client: OpenAI; response_model: { schema: T; name: string; description?: string; }; }; type AgentInstance = ReturnType>; type ConfigOverride = Partial; /** Creates a pre-configured Chat Completions client with schema-aware response parsing. */ declare function createAgent({ defaultClientOptions, response_model, mode, client }: CreateAgentParams): { completionStream: (configOverride?: ConfigOverride) => Promise>; completion: (configOverride?: ConfigOverride) => Promise>; }; declare function isPathComplete(activePath: ActivePath, data: { _meta: CompletionMeta; }): boolean; /** * Parses non streaming responses that may contain both thinking sections and JSON content. * Handles incomplete JSON, and nested markdown blocks. * Includes thinking content in the returned object. * * @param data - The raw response data * @returns an object with json and thinking fields */ declare function thinkingJsonParser(data: string | OpenAI.Chat.Completions.ChatCompletion): { json: string; thinking: string; }; export { type ActivePath, type AgentInstance, type ClientConfig, type CompletedPaths, type CompletionMeta, type ConfigOverride, type CreateAgentParams, type FunctionParamsReturnType, type InferStreamType, type JsonModeParamsReturnType, type JsonSchema, type JsonSchemaParamsReturnType, type LogLevel, MODE, type MessageBasedParamsReturnType, type Mode, type ModeParamsReturnType, OAIResponseFnArgsParser, OAIResponseJSONParser, OAIResponseParser, OAIResponseToolArgsParser, OAIStream, type ParseParams, type ResponseModel, type ToolFunctionParamsReturnType, type ZodStreamChunk, type ZodStreamCompletionParams, type ZodStreamDefaultData, type ZodStreamValue, createAgent, ZodStream as default, isPathComplete, readableStreamToAsyncGenerator, responseModelToJsonSchema, thinkingJsonParser, withResponseModel };