import { type SetOptional } from 'type-fest'; import { type z } from 'zod'; import { type Model, type Msg } from '../index.js'; /** * A runner that iteratively calls the model and handles function calls. */ export type AIRunner = (params: string | AIRunner.Params, context?: Model.Ctx) => Promise>; export declare namespace AIRunner { /** Parameters to execute a runner */ type Params = SetOptional; type ModelParams = Partial>; /** Response from executing a runner */ type Response = { status: 'success'; messages: Msg[]; content: Content; } | { status: 'error'; messages: Msg[]; error: Error; }; /** Controls use of functions or tool_calls from OpenAI API */ type Mode = 'tools' | 'functions'; } /** * A function used to extract data using OpenAI function calling. */ export type ExtractFunction> = (params: string | AIRunner.Params, context?: Model.Ctx) => Promise>; export interface AIFunctionSpec { name: string; description?: string; parameters: Record; } /** * A function meant to be used with OpenAI function calling. */ export interface AIFunction = z.ZodObject, Return = any> { /** The implementation of the function, with arg parsing and validation. */ (input: string | Msg): Promise; /** The Zod schema for the arguments string. */ argsSchema: Schema; /** Parse the function arguments from a message. */ parseArgs(input: string | Msg): z.infer; /** The function spec for the OpenAI API `functions` property. */ spec: AIFunctionSpec; }