/** * @file OpenAI-compatible HTTP backends for AI providers that expose a * chat-completions endpoint rather than a CLI — Fireworks * (`api.fireworks.ai`) and Synthetic (`api.synthetic.new`). The CLI path * (`spawn.mts`) drives an interactive agent binary; this path is for a * script/hook that needs a single completion from a model without an agent * harness (the way the local OpenCode setup reaches GLM-5.2 / Kimi-K2.6). Why * a separate module from `spawn.mts`: those are different surfaces. A CLI * agent gets tools + a permission mode + a working dir; an HTTP completion * gets a prompt + a model + (optionally) a reasoning effort and returns text. * Conflating them would force every HTTP call to carry meaningless CLI * lockdown fields. Lockdown equivalent: these calls send NO tools / * function-calling surface — they're plain completions, so there's no agentic * capability to constrain. The token is read from the env var the provider * config names (`FIREWORKS_API_KEY` / `SYNTHETIC_API_KEY`), NEVER passed * inline, and never logged — same token-hygiene rule as the rest of Socket. A * missing token throws with the exact env var to set. Wire format is the * OpenAI Chat Completions API (`POST {baseUrl}/chat/completions`), which both * providers implement. */ import type { AiEffort } from './types.js'; /** * An OpenAI-compatible HTTP provider. `id` is the slug prefix used in * `provider/model` references; `baseUrl` is the chat-completions API root; * `tokenEnv` names the env var holding the bearer token. */ export interface AiHttpProvider { readonly id: string; readonly baseUrl: string; readonly tokenEnv: string; } /** * Built-in OpenAI-compatible providers. Add an entry to support a new one — no * other call site changes. Base URLs are the documented chat-completions * roots. */ export declare const AI_HTTP_PROVIDERS: Readonly>; /** * Inputs to a single completion call. * * Required: `provider`, `model`, `prompt`. `effort` maps to the OpenAI * `reasoning_effort` field for models that support it and is left off for the * rest. */ export interface AiHttpCallOptions { /** * Provider id (a key of AI_HTTP_PROVIDERS) or a full AiHttpProvider. */ readonly provider: string | AiHttpProvider; /** * The provider's model id (e.g. `accounts/fireworks/models/glm-5p2`, * `hf:moonshotai/Kimi-K2.6`). */ readonly model: string; /** * The user prompt. */ readonly prompt: string; /** * Optional system prompt prepended as the `system` role message. */ readonly system?: string | undefined; /** * Reasoning effort (`reasoning_effort` field); omitted when absent. Only set * for a model that supports it — providers ignore or reject it otherwise. */ readonly effort?: AiEffort | undefined; /** * Sampling temperature; provider default when absent. */ readonly temperature?: number | undefined; /** * Per-call timeout (ms). */ readonly timeoutMs?: number | undefined; /** * An explicit bearer token that wins over env + keychain. When absent the * token resolves via `resolveProviderCredential` (env → keychain). */ readonly token?: string | undefined; /** * Skip the keychain fallback when resolving the token — env var only. Set in * headless contexts (CI, hooks) where a keychain auth prompt is * unacceptable. */ readonly allowEnvOnly?: boolean | undefined; } /** * Result of a completion: the assistant text plus the raw provider response for * callers that need usage / finish-reason detail. */ export interface AiHttpResult { readonly text: string; readonly raw: OpenAiChatResponse; } /** * The slice of the OpenAI chat-completions response we read. */ export interface OpenAiChatResponse { readonly choices?: ReadonlyArray<{ message?: { content?: string | undefined; } | undefined; }> | undefined; } /** * Build the chat-completions request body. Kept pure for testing — the effort → * `reasoning_effort` mapping + system-message prepend are the parts worth * asserting without a network call. */ export declare function buildChatRequestBody(options: AiHttpCallOptions): string; /** * Call an OpenAI-compatible chat-completions endpoint and return the assistant * text. The bearer token is read from the provider's `tokenEnv` env var — never * accepted as a parameter, never logged. Throws when the token env var is unset * — the error names the var to set — or when the response carries no message * text. * * @example * ;```ts * const { text } = await callAiHttpModel({ * provider: 'fireworks', * model: 'accounts/fireworks/models/glm-5p2', * prompt: 'Summarize this diff: …', * effort: 'high', * }) * ``` */ export declare function callAiHttpModel(options: AiHttpCallOptions): Promise; /** * Resolve a provider id / object to an AiHttpProvider. Throws with the known * provider set when an unknown id is passed. */ export declare function resolveAiHttpProvider(provider: string | AiHttpProvider): AiHttpProvider;