/**
 * AIGenerators.base.ts — AI 生成器公共工具 + 聊天路由层
 *
 * 包含：
 * - 构造函数与基础工具（getModels / getAllModels / _getToken / _authHeaders 等）
 * - 请求头规范化（_normalizeHeaders）
 * - 模型/provider 解析（_resolveLocalModelSettings / _detectProvider / _shouldPreferDirect）
 * - 直连路由决策（shouldRouteDirect）
 * - 聊天核心路由（chat / chatViaProxy / chatCompletion）
 * - 直连底层方法（callLLM / _callOpenAILLM / _callOpenRouterLLM / _callGoogleLLM）
 * - SSE 读取（_readSSETextResponse / _readSSEImageResponse / _readChatCompletionSSE / _readKeepworkProxySSE）
 * - 消息格式化工具（_normalizeMessages / _normalizeOpenAIChatMessages / _messagesToGeminiContents 等）
 * - Reasoning 处理（_normalizeReasoningOption / _buildReasoningBodyField 等）
 */
export declare const DEFAULT_CHAT_MODEL = "keepwork-flash";
export declare const DEFAULT_IMAGE_MODEL = "keepwork-image";
export declare const DEFAULT_VIDEO_MODEL = "keepwork-video";
/** 聊天消息（OpenAI 格式） */
export interface GenMessage {
    role: string;
    content: unknown;
    tool_calls?: GenToolCall[];
    tool_call_id?: string;
    [key: string]: unknown;
}
/** 工具调用 */
export interface GenToolCall {
    id?: string;
    type?: string;
    function?: {
        name?: string;
        arguments?: string;
    };
    index?: number;
}
/** SDK 最小接口 */
export interface AIGeneratorsSDKRef {
    baseURL?: string;
    token?: string | null;
    userApiKey?: string | null;
    localAPIKeySettings?: {
        resolveModelSettings: (model: string, opts?: unknown) => {
            model?: string;
            apiKey?: string;
            provider?: string;
            preferDirect?: boolean;
        };
        detectProvider?: (model: string) => string | null;
        getProviderApiKey?: (provider: string) => string | null;
    };
    get?: (url: string) => Promise<unknown>;
    cloudDrive?: {
        uploadTempFile: (file: File, opts?: {
            filename?: string;
            expire?: number;
        }) => Promise<{
            url?: string;
        }>;
    };
    [key: string]: unknown;
}
/** 本地模型设置 */
export interface LocalModelSettings {
    model?: string;
    apiKey?: string;
    provider?: string;
    preferDirect?: boolean;
}
/** 聊天选项 */
export interface GenChatOptions {
    messages?: GenMessage[];
    prompt?: string;
    model?: string;
    tools?: unknown[];
    stream?: boolean;
    temperature?: number;
    responseFormat?: string | {
        type: string;
    };
    reasoning?: boolean | object;
    knowledgeBaseCodes?: string[];
    apiCacheKey?: string | null;
    abortController?: AbortController;
    extraHeaders?: Record<string, string>;
    localModelSettings?: LocalModelSettings;
    directProvider?: string;
    apiKey?: string;
    preferDirect?: boolean;
    directOnly?: boolean;
    returnRaw?: boolean;
    extraBody?: Record<string, unknown>;
    modalities?: string[];
    outputModalities?: string[];
    output_modalities?: string[];
    images?: Array<{
        url?: string;
        image_url?: {
            url: string;
        };
        role?: string;
    }>;
    onMessage?: (fullText: string, delta?: unknown, raw?: unknown, meta?: unknown) => void;
    onReasoning?: (fullReasoning: string, delta?: string, raw?: unknown) => void;
    onToolCall?: (toolCall: GenToolCall) => void;
    onComplete?: (result: unknown, fullResponse?: unknown) => void;
    onError?: (error: Error) => void;
    onImage?: (url: string, raw?: unknown, meta?: unknown) => void;
    [key: string]: unknown;
}
/** shouldRouteDirect 返回值 */
export interface RouteDirectDecision {
    route: boolean;
    provider?: string;
    apiKey?: string;
}
/**
 * AIGeneratorsBase — AI 生成器公共工具 + 聊天路由基类。
 * 由 AIGenerators.media.ts 继承以添加 genImage / genVideo 等媒体生成方法。
 */
export declare class AIGeneratorsBase {
    sdk: AIGeneratorsSDKRef;
    /** 全量模型列表缓存（getAllModels 使用） */
    _allModelsCache?: unknown[];
    constructor(sdk: AIGeneratorsSDKRef);
    /** Keepwork gpt API 基础 URL */
    get _apiBase(): string;
    /**
     * 获取预设的常用模型列表。
     * @param type - 'chat' | 'image' | 'video'
     */
    getModels(type?: 'chat' | 'image' | 'video'): string[];
    /**
     * 从 Keepwork 获取完整模型列表（内存缓存）。
     * @param opts.forceRefresh - 是否绕过缓存（默认 false）
     */
    getAllModels(opts?: {
        forceRefresh?: boolean;
    }): Promise<unknown[]>;
    /** 获取认证 token（sdk.token → localStorage 回退）。 */
    _getToken(): string | null;
    /**
     * 规范化请求头对象（过滤 null/undefined，拒绝含非 Latin-1 字符的 value）。
     * 用于防止 fetch API 因非法头值崩溃。
     */
    _normalizeHeaders(headers?: Record<string, unknown>, context?: string): Record<string, string>;
    /**
     * 构建 Keepwork API 鉴权请求头（含 Authorization / user-api-key）。
     * @param extra - 额外请求头
     */
    _authHeaders(extra?: Record<string, string>): Record<string, string>;
    /**
     * 解析模型的本地配置（model / apiKey / provider / preferDirect）。
     * 若 SDK 无 localAPIKeySettings 则直接返回 `{ model }`。
     */
    _resolveLocalModelSettings(model?: string, provider?: string): LocalModelSettings;
    /** 判断是否应优先使用直连路由。 */
    _shouldPreferDirect(localModelSettings: LocalModelSettings, opts?: GenChatOptions): boolean;
    /** 解析直连 provider 名称（caller > localModelSettings > 自动检测）。 */
    _directProvider(localModelSettings: LocalModelSettings, opts?: GenChatOptions): string | null;
    /**
     * 决定 chat 请求是否应绕过 Keepwork proxy 直连 provider。
     *
     * 规则：
     * - strict（无 key 则抛出）：directOnly=true 或 preferDirect=true 或 明确指定 apiKey+directProvider
     * - lenient（无 key 则回退代理）：localModelSettings.preferDirect=true
     *
     * @throws 严格模式下无 API key 时抛出
     */
    shouldRouteDirect(options?: GenChatOptions, localModelSettings?: LocalModelSettings | null): RouteDirectDecision;
    /**
     * 根据 model 名称自动检测 provider（OpenRouter / Doubao / Qwen / Claude / Gemini / OpenAI）。
     * 返回 null 表示无法识别（使用 Keepwork proxy）。
     */
    _detectProvider(model: string): string | null;
    /** 将 messages + prompt 规范化为消息数组（至少需要其中一个）。 */
    _normalizeMessages(messages?: GenMessage[], prompt?: string): GenMessage[];
    /** 将消息数组规范化为 OpenAI Chat Completions 格式（含 tool_calls / tool 消息处理）。 */
    _normalizeOpenAIChatMessages(messages: GenMessage[], prompt?: string): GenMessage[];
    /** 将 OpenAI 格式消息转换为 Gemini contents 格式。 */
    _messagesToGeminiContents(messages: GenMessage[]): Array<{
        role: string;
        parts: unknown[];
    }>;
    /** 将消息 content 转换为 Gemini parts 格式（支持文本/图片/视频）。 */
    _contentToGeminiParts(content: unknown): unknown[];
    /** 将 URL 转换为 Gemini file_data 或 inline_data part。 */
    _urlToGeminiFilePart(url: string, fallbackMimeType: string, videoMetadata?: unknown): unknown;
    _extractOpenAIText(data: Record<string, unknown>): string;
    _extractGeminiText(data: Record<string, unknown>): string;
    _extractReasoningText(data: Record<string, unknown>): string;
    _shouldDisableReasoning(model: string): boolean;
    _requiresReasoning(model: string): boolean;
    _normalizeReasoningOption(model: string, reasoning: unknown): unknown;
    _buildReasoningBodyField(provider: string, reasoning: unknown): {
        key: string;
        value: unknown;
    } | null;
    _keepworkChatHeaders(extra?: Record<string, string>): Record<string, string>;
    /**
     * 统一聊天入口：自动判断直连或 proxy 路由。
     * 两种传输路径都发出相同的回调格式（onMessage / onToolCall / onComplete / onError）。
     */
    chat(options?: GenChatOptions): Promise<unknown>;
    /**
     * 通过 Keepwork `/gpt/chat` proxy 发送聊天请求。
     * 支持流式和非流式两种模式，统一发出 AIChat 兼容的回调。
     */
    chatViaProxy(options?: GenChatOptions): Promise<unknown>;
    /** @private 解析 Keepwork proxy SSE 流，返回累积文本。 */
    _readKeepworkProxySSE(response: Response, { onMessage, onReasoning, onToolCall, onComplete }?: {
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        onToolCall?: GenChatOptions['onToolCall'];
        onComplete?: GenChatOptions['onComplete'];
    }): Promise<string>;
    /**
     * 直接调用 OpenAI/OpenRouter 等 provider（支持 tool-calls、streaming）。
     * 在绕过 Keepwork proxy 时使用。
     */
    chatCompletion(options?: GenChatOptions): Promise<unknown>;
    /** @private 解析 OpenAI/OpenRouter chat-completion SSE，返回累积文本。 */
    _readChatCompletionSSE(response: Response, { onMessage, onReasoning, onToolCall, onComplete }?: {
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        onToolCall?: GenChatOptions['onToolCall'];
        onComplete?: GenChatOptions['onComplete'];
    }): Promise<string>;
    callLLM(options?: GenChatOptions & {
        returnRaw?: boolean;
    }): Promise<unknown>;
    _callOpenAILLM(opts: {
        model: string;
        apiKey: string;
        messages: GenMessage[];
        stream?: boolean;
        temperature?: number;
        responseFormat?: unknown;
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        abortController?: AbortController;
        extraHeaders?: Record<string, string>;
    }): Promise<{
        text: string;
        data?: unknown;
    }>;
    _callOpenRouterLLM(opts: {
        model: string;
        apiKey: string;
        messages: GenMessage[];
        stream?: boolean;
        temperature?: number;
        responseFormat?: unknown;
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        onImage?: GenChatOptions['onImage'];
        abortController?: AbortController;
        extraHeaders?: Record<string, string>;
        extraBody?: Record<string, unknown>;
    }): Promise<{
        text: string;
        imageUrl?: string;
        data?: unknown;
        reasoning?: string;
    }>;
    _callGoogleLLM(opts: {
        model: string;
        apiKey: string;
        messages: GenMessage[];
        stream?: boolean;
        temperature?: number;
        responseFormat?: unknown;
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        abortController?: AbortController;
        extraHeaders?: Record<string, string>;
    }): Promise<{
        text: string;
        data?: unknown;
    }>;
    _readSSETextResponse(resp: Response, provider: string, callbacks?: {
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
    }): Promise<string>;
    _readSSEImageResponse(resp: Response, provider: string, callbacks?: {
        onMessage?: GenChatOptions['onMessage'];
        onReasoning?: GenChatOptions['onReasoning'];
        onImage?: GenChatOptions['onImage'];
    }): Promise<{
        text: string;
        reasoning: string;
        imageUrl: string;
        data: unknown;
    }>;
    _extractGeneratedImageUrl(data: unknown): string | null;
    _findFirstImageInValue(value: unknown): string | null;
}
//# sourceMappingURL=AIGenerators.base.d.ts.map