/** * OpenAI-Compatible API Utilities * * Shared utility functions for OpenAI API compatibility layer. */ import type { ExecRequest } from "../api/agent-service"; import type { OpenAIMessage, OpenAIStreamChunk } from "./types"; /** * Generate a unique completion ID */ export declare function generateCompletionId(): string; /** * Convert OpenAI messages array to a prompt string for Cursor. * Handles the full message history including: * - system messages (prepended) * - user messages * - assistant messages (including those with tool_calls) * - tool result messages (role: "tool") * * For multi-turn conversations with tool calls, this formats the conversation * so the model can see what tools were called and their results. */ export declare function messagesToPrompt(messages: OpenAIMessage[]): string; /** * Map exec request to OpenAI tool call format */ export declare function mapExecRequestToTool(execReq: ExecRequest): { toolName: string | null; toolArgs: Record | null; }; /** * Create an error response in OpenAI format */ export declare function createErrorResponse(message: string, type?: string, status?: number): Response; /** * Create an SSE chunk string from data */ export declare function createSSEChunk(data: object): string; /** * Create an SSE done signal */ export declare function createSSEDone(): string; /** * Create a streaming SSE response */ export declare function makeStreamResponse(readable: ReadableStream): Response; /** * Create CORS preflight response */ export declare function handleCORS(): Response; /** * Determine model owner based on model name */ export declare function getModelOwner(displayName: string): string; /** * Create an OpenAI stream chunk */ export declare function createStreamChunk(completionId: string, model: string, created: number, delta: { role?: "assistant"; content?: string | null; tool_calls?: OpenAIStreamChunk["choices"][0]["delta"]["tool_calls"]; }, finishReason?: "stop" | "length" | "content_filter" | "tool_calls" | null): OpenAIStreamChunk; /** * Generate a tool call ID from completion ID and index */ export declare function generateToolCallId(completionId: string, index: number): string;