// --------------------------------------------------------------------------- // Provider types // --------------------------------------------------------------------------- export type ProviderName = 'Anthropic' | 'OpenAI' | 'FireworksAI' | 'ClaudeCode'; export interface ProviderConfig { apiKey: string; model: string; } export interface ModelEntry { use: 'builder' | 'chat'; provider: ProviderName; configuration: ProviderConfig; imageQuality: 'standard' | 'hd'; instructions?: string; logCompletions?: boolean; } export interface Provider { name: ProviderName; builderModels: string[]; chatModels: string[]; detectModel(model: string): boolean; } // --------------------------------------------------------------------------- // Multimodal content // --------------------------------------------------------------------------- export interface TextBlock { type: 'text'; text: string; } export interface ImageBlock { type: 'image'; mediaType: string; data: string; } export type ContentBlock = TextBlock | ImageBlock; export type MessageContent = string | ContentBlock[]; /** Type guard: returns true when content is a multimodal ContentBlock array. */ export function isMultimodalContent(content: MessageContent): content is ContentBlock[] { return Array.isArray(content); } // --------------------------------------------------------------------------- // Messages // --------------------------------------------------------------------------- export interface Message { role: string; content: string; name?: string; } export interface SystemMessage extends Message { role: 'system'; } export interface UserMessage { role: 'user'; content: MessageContent; name?: string; } // --------------------------------------------------------------------------- // Tool use // --------------------------------------------------------------------------- export interface ToolDefinition { name: string; description: string; input_schema: Record; } export type ToolHandler = (input: Record) => Promise; // --------------------------------------------------------------------------- // Completions // --------------------------------------------------------------------------- export interface AgentCompletion { completed: boolean; value?: TValue; error?: Error; } export interface PromptCompletionArgs { prompt: UserMessage; system?: SystemMessage; history?: Message[]; temperature?: number; jsonMode?: boolean; /** JSON schema for structured output. When provided, the model is asked to return JSON conforming to this schema. */ jsonSchema?: Record; /** When true, system content is wrapped with cache_control for Anthropic prompt caching. */ cacheSystem?: boolean; /** JSON schema for structured output via constrained decoding (Anthropic output_config). */ outputSchema?: Record; /** Tools the model may invoke before producing its final answer. */ tools?: ToolDefinition[]; /** Executors for each tool name. Required when `tools` is set. */ toolHandlers?: Record; /** Max tool-use rounds before the loop aborts. Default: 3. */ maxToolIterations?: number; /** Fired once per tool-use iteration with the names of tools about to execute. */ onToolCall?: (names: string[]) => void; } export type completePrompt = (args: PromptCompletionArgs) => Promise>; // --------------------------------------------------------------------------- // Agent args // --------------------------------------------------------------------------- export interface AgentArgs { completePrompt: completePrompt; } // --------------------------------------------------------------------------- // Errors // --------------------------------------------------------------------------- export class RequestError extends Error { readonly status: number; constructor(message: string, status: number, name?: string) { super(message); this.status = status; this.name = name ?? 'RequestError'; } }