/** * OpenAI Provider Implementation * * Implements the Provider interface for OpenAI's Chat Completions API. * Handles message format translation between Foundation's internal format * (which uses Anthropic-style messages) and OpenAI's format. * * Key differences from Anthropic format: * - System prompt goes in messages array as role: "system" * - Tool schemas use "parameters" instead of "input_schema" * - Tool calls are in a separate "tool_calls" array, not content blocks * - Tool results use role: "tool" messages, not tool_result content blocks */ import { BaseProvider } from './base.js'; import type { CompletionRequest, CompletionResponse, StreamChunk, ProviderConfig } from './types.js'; /** * OpenAI provider adapter. * * Translates between Foundation's internal message format and OpenAI's * Chat Completions API format. Supports both streaming and non-streaming * completion requests. */ export declare class OpenAIProvider extends BaseProvider { readonly name: string; private static readonly DEFAULT_BASE_URL; constructor(config: ProviderConfig); /** * Build headers for OpenAI API requests. * Adds organization header if configured. */ protected buildHeaders(): Record; /** * Execute a completion request and return the full response. */ complete(request: CompletionRequest): Promise; /** * Execute a streaming completion request. */ completeStream(request: CompletionRequest): AsyncIterable; /** * Check if the provider is available and configured correctly. */ healthCheck(): Promise; /** * Translate Foundation request to OpenAI format. * * Note: Newer OpenAI models (gpt-4o, gpt-4-turbo, o1, etc.) require * max_completion_tokens instead of max_tokens. We detect model type * and use the appropriate parameter. */ private translateRequest; /** * Check if we're using the actual OpenAI API (not a compatible third-party API). * Third-party OpenAI-compatible APIs (Z.AI, DeepSeek, local LLMs, etc.) typically * use the standard max_tokens parameter, not max_completion_tokens. */ private isActualOpenAIAPI; /** * Check if a model requires max_completion_tokens instead of max_tokens. * Newer OpenAI models (gpt-4o, gpt-4-turbo, gpt-5.x, o1, o3, etc.) use the new parameter. * * IMPORTANT: This only applies to the actual OpenAI API. Third-party OpenAI-compatible * APIs (Z.AI, DeepSeek, Ollama, etc.) use the standard max_tokens parameter. */ private modelRequiresMaxCompletionTokens; /** * Translate messages from Foundation format to OpenAI format. * * Key translations: * - Content blocks are flattened to strings * - tool_use blocks become tool_calls array on assistant messages * - tool_result blocks become separate role: "tool" messages */ private translateMessages; /** * Translate tools from Foundation format to OpenAI format. */ private translateTools; /** * Translate OpenAI response to Foundation format. */ private translateResponse; /** * Translate OpenAI streaming chunk to Foundation StreamChunk format. * * OpenAI streams deltas that need to be accumulated for tool calls. * Text content can be yielded immediately. */ private translateStreamChunk; } //# sourceMappingURL=openai.d.ts.map