78 lines
1.6 KiB
TypeScript
78 lines
1.6 KiB
TypeScript
/**
|
|
* 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<TParams = any, TResult = any> {
|
|
// name: string
|
|
description?: string
|
|
inputSchema: z.ZodType<TParams>
|
|
execute: (args: TParams) => Promise<TResult>
|
|
}
|
|
|
|
/**
|
|
* 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<string, Tool>,
|
|
abortSignal?: AbortSignal
|
|
): Promise<InvokeResult>
|
|
}
|
|
|
|
/**
|
|
* Invoke result (strict typing, supports generics)
|
|
*/
|
|
export interface InvokeResult<TResult = unknown> {
|
|
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
|
|
}
|