import type { ProviderFactory } from '@wrongstack/core/registry'; import { type Capabilities, type Message, type Provider, ProviderError, type Request, type Response, type StreamEvent, type Usage, type Tool as WrongStackTool } from '@wrongstack/core/types'; import { type LanguageModel, type LanguageModelUsage, type ModelMessage, Output, type TextStreamPart, type ToolSet } from 'ai'; /** * Decide whether a configured `baseUrl` may be used as the Gateway WIRE base. * * The Gateway speaks two protocols on two paths: an OpenAI-shaped model list at * `/v1`, and its own wire protocol at `/v4/ai`, to which the AI SDK appends * `/language-model`. Only the former is in `PROVIDER_DEFINITIONS` (auto-discovery * needs it), and the catalog add-flow used to persist it as `providers..baseUrl` * — which then overrode the SDK's wire default and made every request 404 on * `/v1/language-model`. * * So for the Vercel-hosted Gateway we forward nothing and let the SDK supply its * own wire URL. That heals configs already carrying the discovery base, and keeps * us correct when the SDK bumps `/v4` to a later version. A base URL on any other * host is a self-hosted or proxied gateway and is passed through untouched. */ export declare function resolveGatewayWireBaseUrl(baseUrl: string | undefined): string | undefined; export interface AiGatewayProviderOptions { apiKey: string; id?: string | undefined; baseUrl?: string | undefined; headers?: Record | undefined; capabilities?: Capabilities | undefined; /** Test seam and an escape hatch for callers that already own an AI SDK model. */ resolveModel?: ((modelId: string) => LanguageModel) | undefined; /** Test seam; production callers should use AI SDK's streamText implementation. */ streamTextImpl?: AiSdkStreamText | undefined; } interface AiSdkStreamResult { stream: AsyncIterable>; } interface AiSdkStreamTextInput { model: LanguageModel; system?: string | undefined; messages: ModelMessage[]; tools?: ToolSet | undefined; toolChoice?: 'auto' | 'required' | 'none' | { type: 'tool'; toolName: string; } | undefined; maxOutputTokens?: number | undefined; temperature?: number | undefined; topP?: number | undefined; topK?: number | undefined; frequencyPenalty?: number | undefined; presencePenalty?: number | undefined; seed?: number | undefined; reasoning?: 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | undefined; stopSequences?: string[] | undefined; providerOptions?: Record> | undefined; output?: Output.Output | undefined; abortSignal: AbortSignal; maxRetries: number; } type AiSdkStreamText = (input: AiSdkStreamTextInput) => AiSdkStreamResult; /** * Vercel AI Gateway transport for WrongStack. * * This adapter deliberately performs one model step only. Tools are declared * without execute functions, so permission checks and execution remain owned by * WrongStack's ToolExecutor. AI SDK retries are also disabled because the core * provider runner owns retry and cross-provider fallback policy. */ export declare class AiGatewayProvider implements Provider { readonly id: string; readonly capabilities: Capabilities; private readonly resolveModel; private readonly streamTextImpl; constructor(options: AiGatewayProviderOptions); stream(req: Request, opts: { signal: AbortSignal; }): AsyncIterable; complete(req: Request, opts: { signal: AbortSignal; }): Promise; } export interface AiGatewayFactoryOptions { type?: string | undefined; capabilities?: Capabilities | undefined; } /** Registerable factory for config entries with `type: "ai-gateway"`. */ export declare function createAiGatewayProviderFactory(options?: AiGatewayFactoryOptions): ProviderFactory; export declare function convertMessages(messages: Message[]): ModelMessage[]; export declare function convertTools(tools: WrongStackTool[]): ToolSet; export declare function convertUsage(usage: LanguageModelUsage): Usage; /** * Per-stream bookkeeping. `convertAiSdkStreamPart` is otherwise a pure * per-part mapping, but two WrongStack events are only correct in the context * of the parts that came before them. */ export interface AiSdkStreamState { /** Tool call ids already announced with `tool_use_start`. */ startedToolIds: Set; /** Monotonic index for `content_block_stop`. */ blockIndex: number; } export declare function createStreamState(): AiSdkStreamState; export declare function convertAiSdkStreamPart(part: TextStreamPart, providerId?: string, state?: AiSdkStreamState): Iterable; export declare function toProviderError(error: unknown, providerId?: string): ProviderError; /** * Map `Request.responseFormat` onto an AI SDK output spec. AI SDK resolves * these to the model's NATIVE `responseFormat` — no synthetic tool is * introduced — so the stream still arrives as text parts. */ export declare function convertResponseFormat(format: Request['responseFormat']): Output.Output | undefined; /** * Provider-namespaced passthrough options. * * The `gateway` namespace is always safe — the Gateway owns it. Upstream * namespaces are only emitted when the model id actually routes there, so a * Google-only knob never rides along on an Anthropic request. */ export declare function convertProviderOptions(req: Request): Record>; export {}; //# sourceMappingURL=ai-gateway.d.ts.map