import { GatewayConfig } from './types.js';
import './index-1qIcnbG1.js';

interface FallbackLlmOptions {
    temperature?: number;
    maxTokens?: number;
    timeoutMs?: number;
    /** Override which agent persona's model chain to use (by ID from agents.list[]). */
    agentId?: string;
}
interface FallbackLlmResponse {
    content: string;
    modelUsed: string;
    usage?: {
        inputTokens?: number;
        outputTokens?: number;
        totalTokens?: number;
    };
}
interface FallbackLlmRuntimeContext {
    agentDir?: string;
    workspaceDir?: string;
}
/**
 * Generic fallback LLM client that uses the gateway's default AI configuration
 * and walks through the full fallback chain (primary + fallbacks).
 * Supports OpenAI and Anthropic API formats.
 */
declare class FallbackLlmClient {
    private gatewayConfig;
    private runtimeContext;
    constructor(gatewayConfig?: GatewayConfig, runtimeContext?: FallbackLlmRuntimeContext);
    /**
     * Check if fallback is available (gateway config has at least one model).
     */
    isAvailable(agentId?: string): boolean;
    /**
     * Make a chat completion request using the gateway's default AI chain.
     * Tries primary first, then each fallback in order.
     * When agentId is provided, uses that agent persona's model chain instead of defaults.
     */
    chatCompletion(messages: Array<{
        role: "system" | "user" | "assistant";
        content: string;
    }>, options?: FallbackLlmOptions): Promise<FallbackLlmResponse | null>;
    /**
     * Make a request with structured output (Zod schema).
     * Returns parsed JSON or null on failure.
     */
    parseWithSchema<T>(messages: Array<{
        role: "system" | "user" | "assistant";
        content: string;
    }>, schema: {
        parse: (data: unknown) => T;
    }, options?: FallbackLlmOptions): Promise<T | null>;
    /**
     * Like parseWithSchema but also returns the model that was used,
     * so callers can emit accurate trace events.
     */
    parseWithSchemaDetailed<T>(messages: Array<{
        role: "system" | "user" | "assistant";
        content: string;
    }>, schema: {
        parse: (data: unknown) => T;
    }, options?: FallbackLlmOptions): Promise<{
        result: T;
        modelUsed: string;
    } | null>;
    /**
     * Get the full model chain from gateway config.
     * Returns array of models in order: [primary, fallback1, fallback2, ...]
     *
     * When agentId is provided, looks up the matching entry in agents.list[]
     * and uses that persona's model chain. Falls back to agents.defaults.model
     * if agentId is not found or not provided.
     */
    private getModelChain;
    /**
     * Parse a "provider/model" string and look up its config.
     */
    private parseModelString;
    private resolveProviderConfig;
    private providerResolutionCandidates;
    /**
     * Look up a provider from the gateway's materialized models.json, which
     * contains all providers including built-in ones (openai-codex, google-vertex,
     * etc.) that aren't in the user's openclaw.json but are registered by
     * gateway plugins. Returns null if the provider isn't found there either.
     */
    private resolveFromModelsJson;
    /**
     * Try to call a single model.
     *
     * Uses the gateway's native getRuntimeAuthForModel when available — this
     * handles all provider-specific auth transforms (OAuth token exchange,
     * base URL overrides for codex/copilot/etc.) through the same codepath
     * the gateway itself uses. Falls back to resolveProviderApiKey for
     * simpler providers or when the runtime module isn't loaded.
     */
    private tryModel;
    /**
     * Resolve request-ready auth through the gateway's native runtime, which
     * handles provider-specific transforms (OAuth token exchange for codex/copilot,
     * base URL rewrite, etc.). Returns null if the runtime isn't available.
     */
    private resolveRuntimeAuth;
    /**
     * Resolve API key through the existing provider-level resolution (env vars,
     * secret refs, etc.). Used as fallback when gateway runtime auth isn't available.
     */
    private resolveFallbackApiKey;
    /**
     * Call OpenAI-compatible API.
     */
    private callOpenAI;
    /**
     * Call Ollama's native /api/chat transport. This lets benchmark-isolated
     * gateway configs route Remnic's own internal LLM calls to Ollama Cloud
     * without requiring an OpenAI-compatible shim.
     */
    private callOllamaChat;
    /**
     * Call an OpenAI-compatible Responses API.
     */
    private callOpenAIResponses;
    /**
     * Call Anthropic Messages API.
     */
    private callAnthropic;
}

export { FallbackLlmClient, type FallbackLlmOptions, type FallbackLlmResponse, type FallbackLlmRuntimeContext };
