import type { AssistantMessageEventStream } from "./kit/event-stream.js";
export type { AssistantMessageEventStream } from "./kit/event-stream.js";
export type KnownApi = "mock-ai" | "openai-completions" | "openai-responses" | "azure-openai-responses" | "openai-codex-responses" | "anthropic-messages" | "bedrock-converse-stream" | "google-generative-ai" | "google-vertex" | "kimi-openai-compatible" | "nvidia-openai-compatible";
export type Api = KnownApi | (string & {});
export type KnownProvider = "mock" | "amazon-bedrock" | "anthropic" | "google" | "google-vertex" | "openai" | "azure-openai-responses" | "openai-codex" | "github-copilot" | "xai" | "groq" | "cerebras" | "openrouter" | "vercel-ai-gateway" | "zai" | "mistral" | "minimax" | "minimax-cn" | "opencode" | "kimi" | "kimi-coding" | "sarvam" | "krutrim" | "nvidia";
export type Provider = KnownProvider | string;
export type ThinkingLevel = "minimal" | "low" | "medium" | "high" | "xhigh";
/** Per-level token allowances for reasoning, used only by token-budget providers. */
export interface ThinkingBudgets {
    minimal?: number;
    low?: number;
    medium?: number;
    high?: number;
}
export interface StreamOptions {
    temperature?: number;
    maxTokens?: number;
    signal?: AbortSignal;
    apiKey?: string;
    /**
     * Identifier a provider may use to tie related requests together, e.g. to
     * key prompt caching or routing. Providers that lack such a feature ignore it.
     */
    sessionId?: string;
    /**
     * Hook invoked with the outgoing provider payload right before it is sent.
     */
    onPayload?: (payload: unknown) => void;
    /**
     * Extra HTTP headers to attach to the request. These are combined with the
     * provider's defaults and may overwrite them. Providers that authenticate via
     * an SDK rather than raw HTTP (such as AWS Bedrock) do not apply them.
     */
    headers?: Record<string, string>;
}
export type ProviderStreamOptions = StreamOptions & Record<string, unknown>;
export interface SimpleStreamOptions extends StreamOptions {
    reasoning?: ThinkingLevel;
    /** Override the default reasoning budgets; only honored by token-budget providers. */
    thinkingBudgets?: ThinkingBudgets;
}
export type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (model: Model<TApi>, context: Context, options?: TOptions) => AssistantMessageEventStream;
export interface TextContent {
    type: "text";
    text: string;
    textSignature?: string;
}
export interface ThinkingContent {
    type: "thinking";
    thinking: string;
    thinkingSignature?: string;
}
export interface ImageContent {
    type: "image";
    data: string;
    mimeType: string;
}
export interface ToolCall {
    type: "toolCall";
    id: string;
    name: string;
    arguments: Record<string, any>;
    thoughtSignature?: string;
}
export interface Usage {
    input: number;
    output: number;
    cacheRead: number;
    cacheWrite: number;
    totalTokens: number;
    cost: {
        input: number;
        output: number;
        cacheRead: number;
        cacheWrite: number;
        total: number;
    };
}
export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
export interface UserMessage {
    role: "user";
    content: string | (TextContent | ImageContent)[];
    timestamp: number;
}
export interface AssistantMessage {
    role: "assistant";
    content: (TextContent | ThinkingContent | ToolCall)[];
    api: Api;
    provider: Provider;
    model: string;
    usage: Usage;
    stopReason: StopReason;
    errorMessage?: string;
    timestamp: number;
}
export interface ToolResultMessage<TDetails = any> {
    role: "toolResult";
    toolCallId: string;
    toolName: string;
    content: (TextContent | ImageContent)[];
    details?: TDetails;
    isError: boolean;
    timestamp: number;
}
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
import type { TSchema } from "@sinclair/typebox";
export interface JsonSchema {
    type?: string;
    description?: string;
    properties?: Record<string, JsonSchema>;
    required?: string[];
    additionalProperties?: boolean;
    items?: JsonSchema;
    enum?: unknown[];
    [key: string]: unknown;
}
export interface Tool<TParameters extends JsonSchema | TSchema = JsonSchema | TSchema> {
    name: string;
    description: string;
    parameters: TParameters;
}
export interface Context {
    systemPrompt?: string;
    messages: Message[];
    tools?: Tool[];
}
export type AssistantMessageEvent = {
    type: "start";
    partial: AssistantMessage;
} | {
    type: "text_start";
    contentIndex: number;
    partial: AssistantMessage;
} | {
    type: "text_delta";
    contentIndex: number;
    delta: string;
    partial: AssistantMessage;
} | {
    type: "text_end";
    contentIndex: number;
    content: string;
    partial: AssistantMessage;
} | {
    type: "thinking_start";
    contentIndex: number;
    partial: AssistantMessage;
} | {
    type: "thinking_delta";
    contentIndex: number;
    delta: string;
    partial: AssistantMessage;
} | {
    type: "thinking_end";
    contentIndex: number;
    content: string;
    partial: AssistantMessage;
} | {
    type: "toolcall_start";
    contentIndex: number;
    partial: AssistantMessage;
} | {
    type: "toolcall_delta";
    contentIndex: number;
    delta: string;
    partial: AssistantMessage;
} | {
    type: "toolcall_end";
    contentIndex: number;
    toolCall: ToolCall;
    partial: AssistantMessage;
} | {
    type: "done";
    reason: Extract<StopReason, "stop" | "length" | "toolUse">;
    message: AssistantMessage;
} | {
    type: "error";
    reason: Extract<StopReason, "aborted" | "error">;
    error: AssistantMessage;
};
/**
 * Per-endpoint quirks for OpenAI-compatible chat-completions backends.
 * When a field is left unset, the adapter infers a value from the base URL;
 * set it explicitly to pin behavior for a custom or self-hosted endpoint.
 */
export interface OpenAICompletionsCompat {
    /** Does the endpoint accept the `store` flag? Inferred from the URL when omitted. */
    supportsStore?: boolean;
    /** Does the endpoint accept a `developer` role in place of `system`? Inferred from the URL when omitted. */
    supportsDeveloperRole?: boolean;
    /** Does the endpoint accept `reasoning_effort`? Inferred from the URL when omitted. */
    supportsReasoningEffort?: boolean;
    /** Does the endpoint emit usage when asked via `stream_options: { include_usage: true }`? Defaults to true. */
    supportsUsageInStreaming?: boolean;
    /** Name of the output-token cap field to send. Inferred from the URL when omitted. */
    maxTokensField?: "max_completion_tokens" | "max_tokens";
    /** Must tool-result messages carry a `name` field? Inferred from the URL when omitted. */
    requiresToolResultName?: boolean;
    /** Must an assistant turn sit between tool results and the next user turn? Inferred from the URL when omitted. */
    requiresAssistantAfterToolResult?: boolean;
    /** Must reasoning blocks be flattened to text wrapped in <thinking> tags? Inferred from the URL when omitted. */
    requiresThinkingAsText?: boolean;
    /** Must tool-call ids be coerced to the Mistral shape (exactly 9 alphanumerics)? Inferred from the URL when omitted. */
    requiresMistralToolIds?: boolean;
    /** Shape of the reasoning parameter: "openai" sends reasoning_effort, "zai" sends thinking: { type: "enabled" }. Defaults to "openai". */
    thinkingFormat?: "openai" | "zai";
    /** Routing hints applied only when the base URL targets OpenRouter. */
    openRouterRouting?: OpenRouterRouting;
}
/** Per-endpoint quirks for OpenAI Responses backends. Currently a placeholder. */
export interface OpenAIResponsesCompat {
}
/**
 * Upstream-routing hints for OpenRouter.
 * Lets the caller constrain which downstream providers OpenRouter may dispatch to.
 * @see https://openrouter.ai/docs/provider-routing
 */
export interface OpenRouterRouting {
    /** Restrict dispatch to exactly these provider slugs (e.g. ["amazon-bedrock", "anthropic"]). */
    only?: string[];
    /** Preferred provider slugs to attempt in sequence (e.g. ["anthropic", "openai"]). */
    order?: string[];
}
export interface Model<TApi extends Api> {
    id: string;
    name: string;
    api: TApi;
    provider: Provider;
    baseUrl: string;
    reasoning: boolean;
    input: ("text" | "image")[];
    cost: {
        input: number;
        output: number;
        cacheRead: number;
        cacheWrite: number;
    };
    contextWindow: number;
    maxTokens: number;
    headers?: Record<string, string>;
    /** Endpoint-quirk overrides for OpenAI-compatible APIs; inferred from baseUrl when absent. */
    compat?: TApi extends "openai-completions" ? OpenAICompletionsCompat : TApi extends "openai-responses" ? OpenAIResponsesCompat : never;
}
/** All API identifiers wired up by the built-in adapters. */
export declare const API_NAMES: readonly KnownApi[];
/** All provider identifiers the catalog recognizes. */
export declare const PROVIDER_NAMES: readonly KnownProvider[];
/** The full set of terminal stop reasons a stream can report. */
export declare const STOP_REASONS: readonly StopReason[];
export declare const isTextContent: (value: unknown) => value is TextContent;
export declare const isThinkingContent: (value: unknown) => value is ThinkingContent;
export declare const isImageContent: (value: unknown) => value is ImageContent;
export declare const isToolCall: (value: unknown) => value is ToolCall;
export declare const isUserMessage: (value: unknown) => value is UserMessage;
export declare const isAssistantMessage: (value: unknown) => value is AssistantMessage;
export declare const isToolResultMessage: (value: unknown) => value is ToolResultMessage;
export declare const isMessage: (value: unknown) => value is Message;
export declare function createZeroUsage(): Usage;
export declare function createAssistantMessage(params: {
    api: Api;
    provider: Provider;
    model: string;
    content?: AssistantMessage["content"];
    stopReason?: StopReason;
    errorMessage?: string;
}): AssistantMessage;
export declare function validateTool(tool: unknown): asserts tool is Tool;
export declare function validateMessage(message: unknown): asserts message is Message;
export declare function validateContext(context: unknown): asserts context is Context;
