/** * Core types for LLM integration */ import type { z } from 'zod' /** * Message format - OpenAI standard (industry standard) */ export interface Message { role: 'system' | 'user' | 'assistant' | 'tool' content?: string | null tool_calls?: { id: string type: 'function' function: { name: string arguments: string // JSON string } }[] tool_call_id?: string name?: string } /** * Tool definition - uses Zod schema (LLM-agnostic) * Supports generics for type-safe parameters and return values */ export interface Tool { // name: string description?: string inputSchema: z.ZodType execute: (args: TParams) => Promise } /** * LLM Client interface * Note: Does not use generics because each tool in the tools array has different types */ export interface LLMClient { invoke( messages: Message[], tools: Record, abortSignal?: AbortSignal ): Promise } /** * Invoke result (strict typing, supports generics) */ export interface InvokeResult { toolCall: { // id?: string // OpenAI's tool_call_id name: string args: any } toolResult: TResult // Supports generics, but defaults to unknown usage: { promptTokens: number completionTokens: number totalTokens: number cachedTokens?: number // Prompt cache hits reasoningTokens?: number // OpenAI o1 series reasoning tokens } rawResponse?: unknown // Raw response for debugging } /** * OpenAI Client config */ export interface OpenAIClientConfig { model: string apiKey: string baseURL: string temperature?: number maxTokens?: number maxRetries?: number }