/** * ThinkHive SDK v3.0 - OpenAI Instrumentation * * Auto-instrumentation for OpenAI API calls including: * - Chat completions * - Assistants API * - Tool calls */ import type { ConversationMessage, SpanData } from '../core/types'; /** * Wrap an OpenAI chat completion call with tracing * * @example * ```typescript * import OpenAI from 'openai'; * import { wrapChatCompletion } from '@thinkhive/sdk/instrumentation/openai'; * * const openai = new OpenAI(); * * const result = await wrapChatCompletion( * () => openai.chat.completions.create({ * model: 'gpt-4', * messages: [{ role: 'user', content: 'Hello' }], * }), * { * model: 'gpt-4', * messages: [{ role: 'user', content: 'Hello' }], * } * ); * ``` */ export declare function wrapChatCompletion(fn: () => Promise, options?: { model?: string; messages?: Array<{ role: string; content: string; }>; temperature?: number; maxTokens?: number; }): Promise; /** * Wrap an OpenAI Assistants API call with tracing * * @example * ```typescript * import OpenAI from 'openai'; * import { wrapAssistantRun } from '@thinkhive/sdk/instrumentation/openai'; * * const openai = new OpenAI(); * * const run = await wrapAssistantRun( * () => openai.beta.threads.runs.create(threadId, { * assistant_id: assistantId, * }), * { assistantId, threadId } * ); * ``` */ export declare function wrapAssistantRun(fn: () => Promise, options: { assistantId: string; threadId: string; model?: string; }): Promise; /** * Wrap an OpenAI tool call with tracing * * @example * ```typescript * const result = await wrapToolCall( * () => executeMyTool(args), * { * toolName: 'search_orders', * toolCallId: 'call_abc123', * arguments: { orderId: '12345' }, * } * ); * ``` */ export declare function wrapToolCall(fn: () => Promise, options: { toolName: string; toolCallId?: string; arguments?: Record; }): Promise; /** * Extract conversation messages from OpenAI format */ export declare function extractConversationMessages(openaiMessages: Array<{ role: string; content: string | null; tool_calls?: Array<{ id: string; function: { name: string; arguments: string; }; }>; }>): ConversationMessage[]; /** * Extract span data from OpenAI response */ export declare function extractSpanData(response: { model?: string; usage?: { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; }; choices?: Array<{ message?: { tool_calls?: Array<{ id: string; function: { name: string; arguments: string; }; }>; }; finish_reason?: string; }>; }, durationMs: number): SpanData; /** * Auto-instrument OpenAI client * Call this during SDK init to automatically trace all OpenAI calls * * @example * ```typescript * import OpenAI from 'openai'; * import { instrumentOpenAIClient } from '@thinkhive/sdk/instrumentation/openai'; * * const openai = new OpenAI(); * instrumentOpenAIClient(openai); * * // All subsequent calls are automatically traced * const response = await openai.chat.completions.create({ ... }); * ``` */ export declare function instrumentOpenAIClient(client: any): void; /** * Remove instrumentation from OpenAI client */ export declare function uninstrumentOpenAIClient(client: any, originalCreate: any): void;