import OpenAI from 'openai'; import type { ChatCompletionTool, ChatCompletionToolChoiceOption } from 'openai/resources/chat/completions'; export interface LLMResponse { content: string; role: string; tool_calls?: Array<{ id: string; type: string; function: { name: string; arguments: string; }; }>; } type ChatRole = 'system' | 'user' | 'assistant' | 'tool'; interface ChatMessage { role: ChatRole; content: string | null; tool_call_id?: string; tool_calls?: Array<{ id: string; type: string; function: { name: string; arguments: string; }; }>; } export declare function getOpenAIClient(): Promise; /** * Reset the cached env-only OpenAI client so the next call rebuilds it. * * Useful for tests and for a settings screen that wants to force a rebuild * after updating credentials without depending on the cache-invalidation rule. * * @example * resetOpenAIClient(); */ export declare function resetOpenAIClient(): void; /** response_format payload for Chat Completions (json_schema / json_object). */ export type ResponseFormat = { type: 'json_object'; } | { type: 'json_schema'; json_schema: { name: string; schema: Record; strict?: boolean; }; }; /** * Per-service credential/transport options. Mirrors Python's per-agent * `api_key` / `base_url` so callers can pass credentials without relying on * process env, and can inject a custom `fetch` for browser-like runtimes. */ export interface OpenAIServiceOptions { apiKey?: string; baseURL?: string; fetch?: typeof fetch; dangerouslyAllowBrowser?: boolean; } export declare class OpenAIService { private model; private client; private options; constructor(model?: string, options?: OpenAIServiceOptions); private getClient; private temperatureParam; generateText(prompt: string, systemPrompt?: string, temperature?: number, tools?: ChatCompletionTool[], tool_choice?: ChatCompletionToolChoiceOption, responseFormat?: ResponseFormat, signal?: AbortSignal): Promise; generateChat(messages: ChatMessage[], temperature?: number, tools?: ChatCompletionTool[], tool_choice?: ChatCompletionToolChoiceOption, responseFormat?: ResponseFormat, signal?: AbortSignal): Promise; streamText(prompt: string, systemPrompt: string | undefined, temperature: number | undefined, onToken: (token: string) => void, tools?: ChatCompletionTool[], tool_choice?: ChatCompletionToolChoiceOption, onToolCall?: (toolCall: any) => void, signal?: AbortSignal): Promise; streamChat(messages: ChatMessage[], temperature: number | undefined, onToken: (token: string) => void, signal?: AbortSignal): Promise; /** * Streaming chat that also surfaces tool calls. Text deltas are emitted * through `onToken` as they arrive; tool-call fragments are accumulated * across chunks and returned once the stream ends. This is the building * block that lets a streaming agent interleave reasoning text with tool * use in a single request (instead of streaming XOR tools). * * @returns The full streamed text plus any accumulated tool calls. */ streamChatWithTools(messages: ChatMessage[], temperature?: number, tools?: ChatCompletionTool[], onToken?: (token: string) => void, tool_choice?: ChatCompletionToolChoiceOption, responseFormat?: ResponseFormat, signal?: AbortSignal): Promise; chatCompletion(messages: ChatMessage[], temperature?: number, tools?: ChatCompletionTool[], tool_choice?: ChatCompletionToolChoiceOption): Promise; } export {};