/** * A REAL OpenAI-compatible chat client for the agent's {@link ChatClientLike} seam. * * Until now the TypeScript engine could only be driven by {@link MockLlmProvider} * or a client the consumer hand-rolled; this is the shipped one, pointed at any * `/chat/completions` endpoint (the SmooAI gateway, or anything OpenAI-compatible) * with a base URL + API key. * * It is a thin adapter over the `openai` SDK, which this package already depends * on — the SDK owns the wire format, the SSE framing, timeouts and connection * retries, so the only thing this file adds is the two bits the SDK's parsed * response throws away: * * 1. **The gateway cost header.** Cost is reported ONLY in a response header, and * a plain `create({ stream: true })` hands back ONLY the stream — there is no * `Response` left to ask for headers, so the cost is not late, it is absent. * That is the regression core#102 fixed in Rust. `.withResponse()` keeps the * `Response` alongside the data, and the parsed cost is surfaced on the * documented seam ({@link responseGatewayCost}): `headers` on a non-streaming * response, `gatewayCostUsd` on a leading {@link ChatChunk} when streaming. * 2. **Nothing else.** The request body is passed through verbatim, so the * agent's `metadata` (core#100) and every other field reach the wire unchanged. * * {@link MockLlmProvider} remains the default/test seam. This is opt-in: nothing * constructs it for you, so an unwired consumer behaves exactly as before. * * ```ts * const agent = new SmoothAgent(createGatewayClient({ baseURL: 'https://llm.smoo.ai/v1', apiKey: key }), options); * ``` */ import OpenAI from 'openai'; import type { ChatClientLike } from './agent.js'; export interface GatewayClientOptions { /** The OpenAI-compatible base URL, e.g. `https://llm.smoo.ai/v1`. */ baseURL: string; /** Bearer key sent as `Authorization: Bearer `. */ apiKey: string; /** Request timeout in milliseconds. Defaults to the SDK's own default. */ timeoutMs?: number; /** Connection-level retries the SDK performs. Defaults to the SDK's own default. */ maxRetries?: number; } /** Build a gateway-backed {@link ChatClientLike} from a base URL + key. */ export declare function createGatewayClient(options: GatewayClientOptions): ChatClientLike; /** * Wrap an already-configured `openai` SDK client — for consumers that need to own * the SDK's construction (custom `fetch`, proxy agent, default headers) and just * want the cost-header plumbing on top. */ export declare function gatewayClientFrom(sdk: OpenAI): ChatClientLike; //# sourceMappingURL=gatewayClient.d.ts.map