import { D as KodaXReasoningMode, U as KodaXThinkingBudgetMap, V as KodaXThinkingDepth, r as KodaXProviderConfig, C as KodaXReasoningCapability, F as KodaXReasoningRequest, Q as KodaXTaskType, E as KodaXReasoningOverride, X as KodaXToolDefinition, m as KodaXMessage, z as KodaXProviderStreamOptions, J as KodaXStreamResult, q as KodaXProviderCapabilityProfile, h as KodaXCustomProviderConfig } from './types.d-B1uGoVTE.js';
import Anthropic from '@anthropic-ai/sdk';
import { K as KodaXBaseProvider } from './cost-tracker.d-B6vMoLLF.js';
import OpenAI from 'openai';

/**
 * KodaX AI Errors
 *
 * AI 层错误类型 - 提供结构化的错误处理
 */
/** 基础 KodaX 错误类 */
declare class KodaXError extends Error {
    readonly code: string;
    constructor(message: string, code?: string);
}
/** Provider 配置错误 */
declare class KodaXProviderError extends KodaXError {
    readonly provider?: string | undefined;
    constructor(message: string, provider?: string | undefined);
}
/** API 速率限制错误 */
declare class KodaXRateLimitError extends KodaXError {
    readonly retryAfter?: number | undefined;
    constructor(message: string, retryAfter?: number | undefined);
}
/** 网络错误 (超时, 连接被拒绝等) */
declare class KodaXNetworkError extends KodaXError {
    readonly isTimeout: boolean;
    constructor(message: string, isTimeout?: boolean);
}
/** Tool call ID 不匹配错误 */
declare class KodaXToolCallIdError extends KodaXError {
    constructor(message: string);
}

declare const KODAX_REASONING_MODE_SEQUENCE: KodaXReasoningMode[];
declare const KODAX_DEFAULT_THINKING_BUDGETS: KodaXThinkingBudgetMap;
declare const KODAX_REASONING_SAFETY_RESERVE = 4096;
declare function getReasoningCapability(config: KodaXProviderConfig): KodaXReasoningCapability;
declare function isReasoningEnabled(reasoning?: boolean | KodaXReasoningRequest): boolean;
declare function normalizeReasoningRequest(reasoning?: boolean | KodaXReasoningRequest): Required<KodaXReasoningRequest>;
declare function getDefaultThinkingDepthForMode(mode: KodaXReasoningMode): KodaXThinkingDepth;
declare function resolveThinkingBudget(config: KodaXProviderConfig, depth: KodaXThinkingDepth, taskType?: KodaXTaskType): number;
declare function clampThinkingBudget(requestedBudget: number, maxOutputTokens: number, safetyReserve?: number): number;
declare function mapDepthToOpenAIReasoningEffort(depth: KodaXThinkingDepth): 'low' | 'medium' | 'high' | undefined;

declare function reasoningCapabilityToOverride(capability: KodaXReasoningCapability): KodaXReasoningOverride | undefined;
declare function reasoningOverrideToCapability(override: KodaXReasoningOverride): KodaXReasoningCapability;
declare function buildReasoningOverrideKey(providerName: string, config: Pick<KodaXProviderConfig, 'baseUrl' | 'model'>, modelOverride?: string): string;
declare function loadReasoningOverride(providerName: string, config: Pick<KodaXProviderConfig, 'baseUrl' | 'model'>, modelOverride?: string): KodaXReasoningOverride | undefined;
declare function saveReasoningOverride(providerName: string, config: Pick<KodaXProviderConfig, 'baseUrl' | 'model'>, override: KodaXReasoningOverride, modelOverride?: string): void;
declare function clearReasoningOverride(providerName: string, config: Pick<KodaXProviderConfig, 'baseUrl' | 'model'>, modelOverride?: string): void;

/**
 * KodaX Anthropic Compatible Provider
 *
 * 支持 Anthropic API 格式的 Provider 基类
 */

declare abstract class KodaXAnthropicCompatProvider extends KodaXBaseProvider {
    abstract readonly name: string;
    readonly supportsThinking = true;
    protected abstract readonly config: KodaXProviderConfig;
    protected client: Anthropic;
    protected initClient(): void;
    protected onStaleConnection(): void;
    /**
     * FEATURE_116 (v0.7.37) — Wrap a string `system` prompt as a single
     * cacheable text block. v1 treats the entire system prompt as one cache
     * prefix (implicit boundary at the end). When upstream callers later
     * emit `KodaXContentBlock[]` with explicit `cache-boundary` markers
     * (Phase 1.4+), this helper switches to lowering those markers via
     * `lowerCacheBoundaries(blocks, 'attach')`.
     *
     * Escape hatch: setting `KODAX_DISABLE_PROMPT_CACHE=1` returns the
     * original string unchanged so prompt caching can be disabled at
     * runtime without redeploying.
     */
    protected applyCacheControlToSystem(systemText: string): string | Anthropic.Messages.TextBlockParam[];
    /**
     * FEATURE_116 (v0.7.37) — Mark the last tool definition as the cache
     * suffix for the tools array. The Anthropic API caches the entire
     * prefix up to and including the marked tool, so this is equivalent
     * to "all tool defs are cacheable".
     *
     * Returns a new array; never mutates input.
     */
    protected applyCacheControlToTools(tools: KodaXToolDefinition[]): Anthropic.Messages.Tool[];
    stream(messages: KodaXMessage[], tools: KodaXToolDefinition[], system: string, reasoning?: boolean | KodaXReasoningRequest, streamOptions?: KodaXProviderStreamOptions, signal?: AbortSignal): Promise<KodaXStreamResult>;
    supportsNonStreamingFallback(): boolean;
    complete(messages: KodaXMessage[], tools: KodaXToolDefinition[], system: string, reasoning?: boolean | KodaXReasoningRequest, streamOptions?: KodaXProviderStreamOptions, signal?: AbortSignal): Promise<KodaXStreamResult>;
    private serializeSystemMessageContent;
    private buildSystemPrompt;
    private convertMessages;
}

/**
 * KodaX OpenAI Compatible Provider
 *
 * 支持 OpenAI API 格式的 Provider 基类
 */

declare abstract class KodaXOpenAICompatProvider extends KodaXBaseProvider {
    abstract readonly name: string;
    readonly supportsThinking = true;
    protected abstract readonly config: KodaXProviderConfig;
    protected client: OpenAI;
    protected initClient(): void;
    protected onStaleConnection(): void;
    /**
     * FEATURE_116 (v0.7.37) — Strip any `cache-boundary` markers from
     * KodaXMessage content arrays before they reach OpenAI wire
     * serialization. OpenAI / DeepSeek auto-cache prefix tokens
     * server-side, so the client has no marker to lower; Kimi/Zhipu/通义
     * self-cache via separate `cache_id` endpoints that are deferred to
     * v0.7.45+ (FEATURE_102). Stripping is the correct universal action
     * for this base class.
     *
     * Idempotent: a message whose content is a string or contains no
     * boundaries returns the same reference. Safe to call multiple times.
     */
    protected stripCacheBoundariesFromMessages(messages: KodaXMessage[]): KodaXMessage[];
    /**
     * Collapse every `role: 'system'` message (the `system` parameter plus any
     * system messages embedded in `messages`) into a single top-of-wire system
     * content and return the remaining non-system messages. Some OpenAI-compat
     * gateways — notably third-party Qwen proxies — reject any system message
     * that is not at position 0, so this normalization guarantees the wire has
     * exactly one system entry regardless of what the upstream caller passed.
     *
     * Post-compact attachments, compaction summaries and handoff-time
     * `replaceSystemMessage` can all leave secondary `role: 'system'` entries
     * mid-transcript; merging here is the provider-layer bottleneck that keeps
     * callers from having to coordinate.
     */
    private normalizeSystemForWire;
    private appendExtraBody;
    private resetReasoningCapabilityParams;
    private applyReasoningCapability;
    private getFallbackTerms;
    stream(messages: KodaXMessage[], tools: KodaXToolDefinition[], system: string, reasoning?: boolean | KodaXReasoningRequest, streamOptions?: KodaXProviderStreamOptions, signal?: AbortSignal): Promise<KodaXStreamResult>;
    supportsNonStreamingFallback(): boolean;
    complete(messages: KodaXMessage[], tools: KodaXToolDefinition[], system: string, reasoning?: boolean | KodaXReasoningRequest, streamOptions?: KodaXProviderStreamOptions, signal?: AbortSignal): Promise<KodaXStreamResult>;
    private extractReasoningDelta;
    private serializeAssistantMessage;
    private serializeUserMessage;
    private serializeSystemMessage;
    private convertMessages;
}

/**
 * KodaX Provider Registry
 *
 * Provider 注册表 - 统一管理所有 Provider
 */

type ProviderName = 'anthropic' | 'openai' | 'deepseek' | 'kimi' | 'kimi-code' | 'qwen' | 'zhipu' | 'zhipu-coding' | 'minimax-coding' | 'mimo-coding' | 'ark-coding' | 'gemini-cli' | 'codex-cli';
type ProviderSnapshot = {
    model: string;
    models?: readonly string[];
    apiKeyEnv: string;
    reasoningCapability: KodaXReasoningCapability;
    modelReasoningCapabilities?: Partial<Record<string, KodaXReasoningCapability>>;
    capabilityProfile: KodaXProviderCapabilityProfile;
};
declare const KODAX_PROVIDER_SNAPSHOTS: Record<ProviderName, ProviderSnapshot>;
declare const KODAX_PROVIDERS: Record<string, () => KodaXBaseProvider>;
declare const KODAX_DEFAULT_PROVIDER: string;
declare function getProvider(name?: string): KodaXBaseProvider;
declare function isProviderConfigured(name: string): boolean;
declare function getProviderModel(name: string): string | null;
declare function getProviderConfiguredReasoningCapability(name: string, modelOverride?: string): KodaXReasoningCapability | 'unknown';
declare function getProviderConfiguredCapabilityProfile(name: string): KodaXProviderCapabilityProfile | null;
declare function getProviderList(): Array<{
    name: string;
    model: string;
    models: string[];
    configured: boolean;
    reasoningCapability: KodaXReasoningCapability;
    capabilityProfile: KodaXProviderCapabilityProfile;
}>;
declare function getProviderModels(name: string): string[];
declare function isProviderName(name: string): name is ProviderName;

/**
 * Custom Provider Factory
 *
 * Creates KodaXBaseProvider instances from KodaXCustomProviderConfig.
 * Supports both OpenAI and Anthropic protocol families.
 */

declare function validateCustomProviderConfig(custom: KodaXCustomProviderConfig): void;
declare function createCustomProvider(custom: KodaXCustomProviderConfig): KodaXBaseProvider;

/**
 * Register custom providers from config. Replaces all existing custom providers.
 */
declare function registerCustomProviders(configs: KodaXCustomProviderConfig[]): void;
/**
 * Get a custom provider instance by name.
 * Returns undefined if not found in custom registry.
 * Note: This will throw if the provider's API key env var is not set.
 */
declare function getCustomProvider(name: string): KodaXBaseProvider | undefined;
/**
 * Check if a name refers to a custom provider.
 */
declare function isCustomProviderName(name: string): boolean;
/**
 * Get all custom provider names without instantiation.
 */
declare function getCustomProviderNames(): string[];
/**
 * Get display info for all registered custom providers.
 * Reads metadata from stored config without instantiating providers,
 * so it won't throw for unconfigured providers.
 */
declare function getCustomProviderList(): Array<{
    name: string;
    model: string;
    models: string[];
    configured: boolean;
    reasoningCapability: string;
    capabilityProfile: KodaXProviderCapabilityProfile;
    custom: true;
}>;
/**
 * Get available model IDs for a custom provider.
 * Reads from stored config without instantiation.
 * Returns undefined if not a custom provider.
 */
declare function getCustomProviderModels(name: string): string[] | undefined;

type ModelProviderFactory = () => KodaXBaseProvider;
declare function registerModelProvider(name: string, factory: ModelProviderFactory): () => void;
declare function getRuntimeModelProvider(name: string): KodaXBaseProvider | undefined;
declare function isRuntimeModelProviderName(name: string): boolean;
declare function getRuntimeModelProviderNames(): string[];
declare function clearRuntimeModelProviders(): void;

/**
 * Unified Provider Resolver
 *
 * Resolves provider instances by checking built-in registry first,
 * then custom providers. Built-in takes precedence on name collision.
 */

/**
 * Resolve a provider by name. Built-in providers take precedence over custom.
 * @throws Error if provider is not found in either registry.
 */
declare function resolveProvider(name: string): KodaXBaseProvider;
/**
 * Check if a name refers to any known provider (built-in or custom).
 */
declare function isKnownProvider(name: string): boolean;
/**
 * Get all available provider names (built-in + custom).
 */
declare function getAvailableProviderNames(): string[];

export { getProviderList as A, getProviderModel as B, getProviderModels as C, getReasoningCapability as D, getRuntimeModelProvider as E, getRuntimeModelProviderNames as F, isCustomProviderName as G, isKnownProvider as H, isProviderConfigured as I, isProviderName as J, KODAX_DEFAULT_PROVIDER as K, isReasoningEnabled as L, isRuntimeModelProviderName as M, loadReasoningOverride as N, mapDepthToOpenAIReasoningEffort as O, normalizeReasoningRequest as Q, reasoningCapabilityToOverride as R, reasoningOverrideToCapability as S, registerCustomProviders as T, registerModelProvider as U, resolveProvider as V, resolveThinkingBudget as W, saveReasoningOverride as X, validateCustomProviderConfig as Y, KODAX_DEFAULT_THINKING_BUDGETS as a, KODAX_PROVIDERS as b, KODAX_PROVIDER_SNAPSHOTS as c, KODAX_REASONING_MODE_SEQUENCE as d, KODAX_REASONING_SAFETY_RESERVE as e, KodaXAnthropicCompatProvider as f, KodaXError as g, KodaXNetworkError as h, KodaXOpenAICompatProvider as i, KodaXProviderError as j, KodaXRateLimitError as k, KodaXToolCallIdError as l, buildReasoningOverrideKey as m, clampThinkingBudget as n, clearReasoningOverride as o, clearRuntimeModelProviders as p, createCustomProvider as q, getAvailableProviderNames as r, getCustomProvider as s, getCustomProviderList as t, getCustomProviderModels as u, getCustomProviderNames as v, getDefaultThinkingDepthForMode as w, getProvider as x, getProviderConfiguredCapabilityProfile as y, getProviderConfiguredReasoningCapability as z };
export type { ProviderName as P };
