import { runCodali, type CodaliMessage, type CodaliRequest, type CodaliResult } from "./CodaliApi.js"; import type { RunContext } from "../runcontext/RunContextResolver.js"; /** * OpenAI-compatible chat-completions adapter. * * okacam AI chat already speaks this shape. Rather than changing AI chat to * learn Codali's contract, Codali speaks AI chat's — the product points its * existing client at a different base URL and gets orchestration, tools, and * citations without a rewrite. * * The adapter is deliberately thin. It maps message shapes and nothing else; * all routing, tool selection and budget enforcement stay in the one code path * `runCodali` provides, so the adapter cannot drift from the CLI's behaviour. */ export interface ChatCompletionMessage { role: string; content: string | null; } export interface ChatCompletionRequest { model?: string; messages: ChatCompletionMessage[]; stream?: boolean; response_format?: { type?: string; json_schema?: { schema?: Record; }; }; /** Codali-specific extras, ignored by a plain OpenAI client. */ codali?: { runContext?: RunContext; /** See CodaliRequest. Operator-only; never set this for a tenant request. */ allowOperatorConfigFallback?: boolean; workspaceRoot?: string; mode?: CodaliRequest["mode"]; media?: CodaliRequest["media"]; budgets?: CodaliRequest["budgets"]; }; } export interface ChatCompletionResponse { id: string; object: "chat.completion"; created: number; model: string; choices: Array<{ index: number; message: { role: "assistant"; content: string; }; finish_reason: "stop" | "length" | "content_filter"; }>; usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number; }; /** * Codali's provenance, carried alongside the OpenAI shape. A plain client * ignores this; a product that wants citations reads it. Without it the * adapter would throw away the very thing that makes an orchestrated answer * trustworthy. */ codali: { status: CodaliResult["status"]; sources: CodaliResult["sources"]; artifacts: CodaliResult["artifacts"]; warnings: string[]; traceId: string; output?: unknown; }; } export declare const toCodaliMessages: (messages: readonly ChatCompletionMessage[]) => CodaliMessage[]; export interface ChatAdapterDependencies { run?: typeof runCodali; } export declare const handleChatCompletion: (request: ChatCompletionRequest, deps?: ChatAdapterDependencies) => Promise; //# sourceMappingURL=ChatCompletionsAdapter.d.ts.map