/** * OpenAI-compat adapter — built on the official SDK, covering OpenAI and the * compat family (GLM, Kimi, DeepSeek, OpenRouter, ...) via base_url swap. * * Dialect digestion happens HERE, never in the union (ADR-0003): * - reasoning_content / reasoning deltas (DeepSeek, GLM, Qwen) → `thinking`; * - streaming tool calls: arguments arrive as fragmented deltas, keyed by * index; the first delta of an index carries the call id + name. The * adapter accumulates each call and emits `tool_call_end` with the parsed * JSON (or null — never a silent repair) at the end of the stream. * * Invariants: at least one `usage` precedes the final `stop` when the * provider reports usage (not all compat providers do); `stop` reason maps * from finish_reason. */ import OpenAI from "openai"; import type { ChatCompletionChunk } from "openai/resources/chat/completions"; import type { Adapter } from "@vincemakes/kiso-core"; /** Config accepted by the high-level factory (round 7: the provider owns its SDK). */ export interface OpenAICompatProviderConfig { readonly apiKey?: string; readonly baseUrl?: string; /** Headers the endpoint needs on every request, as the profile names * them (a gateway's session header, say). Sent as the SDK's default * headers; the credential stays in `apiKey`, never here. */ readonly headers?: Readonly>; /** MG-1 (A5): the adapter's replay identity — providerId as the runtime * resolved it (deepseek / zai / openai / custom). Absent = "custom" * with the baseUrl origin as the endpoint term. */ readonly scope?: OpenAICompatScope; } /** MG-1 (A5): the compat adapter's own half of the continuation scope. * apiId is constant ("openai-chat") and modelId is per-request; only the * provider identity and (for custom) the endpoint origin need injecting — * the generic compat wire cannot know WHICH provider it is. */ export interface OpenAICompatScope { readonly providerId: string; readonly endpoint?: string; } /** * High-level factory (round 7): builds the adapter FROM CONFIG, owning the SDK * inside this package. Consumers (and the runtime's lazy provider path) * import ONLY @vincemakes/kiso-provider-openai — the SDK stays a private dependency * of this package, so nested installs resolve it next to here, never * through a hoisted root. */ export declare function createOpenAICompatProvider(config?: OpenAICompatProviderConfig): Adapter; export interface OpenAICompatAdapterOptions { readonly scope?: OpenAICompatScope; } export declare function createOpenAICompatAdapter(client: OpenAI, adapterOpts?: OpenAICompatAdapterOptions): Adapter; export type { ChatCompletionChunk };