/**
 * LocalAPIKeySettings — per-model LLM API key and endpoint configuration
 * with a self-contained settings modal UI.
 *
 * Stores per-model overrides (modelId, apiKey, category).
 * When the SDK makes an LLM request
 * for a model that has local settings, those settings take priority over
 * the server-side defaults.
 *
 * Persistence is pluggable: pass `storage: 'personalPageStore'` to use
 * Keepwork cloud storage, or `storage: 'localStorage'` (default) for
 * browser-local persistence.
 *
 * Usage:
 *   const settings = sdk.localAPIKeySettings;
 *   await settings.load();
 *   settings.show();           // opens the config modal
 *   settings.show({ onClose: () => console.log('closed') });
 */
type LAKStrings = Record<string, string>;
/** 单个模型配置 */
interface ModelConfig {
    modelId: string;
    endpointId: string;
    apiKey: string;
    category: string;
    enabled: boolean;
    preferDirect: boolean;
    [key: string]: unknown;
}
/** 单 provider 设置 */
interface ProviderSetting {
    enabled: boolean;
    apiKey: string;
    preferDirect: boolean;
    [key: string]: unknown;
}
/** 构造选项 */
export interface LocalAPIKeySettingsOptions {
    storage?: 'personalPageStore' | 'localStorage';
    workspace?: string;
    /** 'zhCN' | 'enUS'，缺省时按系统语言自动检测 */
    lang?: string;
    [key: string]: unknown;
}
/** LocalAPIKeySettings 依赖的 SDK 表面 */
interface LAKStore {
    readFile(path: string): Promise<string>;
    createFile(path: string, content: string): Promise<unknown>;
    [key: string]: unknown;
}
interface LAKSdk {
    personalPageStore?: {
        withWorkspace(workspace: string, mountFolder?: string | null): LAKStore;
        [key: string]: unknown;
    };
    [key: string]: unknown;
}
export default class LocalAPIKeySettings {
    sdk: LAKSdk;
    storageMode: string;
    workspace: string;
    _enabled: boolean;
    _models: Map<string, ModelConfig>;
    _providerSettings: Record<string, ProviderSetting>;
    _abstractModelMap: Record<string, string>;
    _loaded: boolean;
    _loadPromise: Promise<void> | null;
    _saveTimer?: ReturnType<typeof setTimeout> | null;
    _overlay: HTMLElement | null;
    _activeCategory: string;
    _activePresetTab: boolean;
    _styleInjected: boolean;
    _showOptions?: Record<string, unknown>;
    _presetClickHandler?: (e: Event) => void;
    _lang: string;
    _strings: LAKStrings;
    [key: string]: unknown;
    /**
     * @param {object} sdk  - KeepworkSDK instance
     * @param {object} [options]
     * @param {'personalPageStore'|'localStorage'} [options.storage='localStorage']
     * @param {string} [options.workspace]
     */
    constructor(sdk: unknown, options?: LocalAPIKeySettingsOptions);
    /** Translate a key, optionally interpolating {placeholders}. */
    _t(key: string, vars?: Record<string, string>): string;
    get enabled(): boolean;
    set enabled(val: boolean);
    setModel(name: string, config?: Record<string, unknown>): void;
    removeModel(name: string): void;
    getModel(name: string): ModelConfig | undefined;
    listModels(category?: string): Array<ModelConfig & {
        name: string;
    }>;
    setAllModels(models: Array<Record<string, unknown>>): void;
    /**
     * Resolve a model ID (possibly abstract like 'keepwork-pro') to
     * { apiKey, realModelId }.
     * Resolution chain:
     *   1. If modelId is an abstract name, map it to a real model ID.
     *   2. Look up the real model ID in per-model settings.
     *   3. Fall back to provider-level defaults, using an explicit provider hint when supplied.
     */
    resolve(modelId: string, options?: Record<string, unknown>): Record<string, unknown> | null;
    _resolveAbstractTarget(abstractName: string, mappedModelId: string): string;
    _getAbstractDisplayValue(abstractName: string, mappedModelId: string): string;
    _getDropdownOptions(category: string): Array<{
        name: string;
        modelId: string;
    }>;
    /**
     * Resolve settings for requests that must remain on Keepwork's `/gpt/*`
     * endpoints. This intentionally strips any direct provider baseURL.
     * @param {string} modelId
     * @returns {{apiKey:string, realModelId?:string}|null}
     */
    resolveProxyConfig(modelId: string): Record<string, unknown> | null;
    /**
     * Resolve settings for direct provider compatibility checks.
     * @param {string} modelId
     * @returns {{apiKey:string, realModelId?:string}|null}
     */
    resolveDirectConfig(modelId: string, options?: Record<string, unknown>): Record<string, unknown> | null;
    /**
     * Set whether a provider should prefer direct browser calls over Keepwork proxy calls.
     * Defaults to false for every provider to preserve existing behavior.
     */
    setProviderPreferDirect(providerKey: string, preferDirect: boolean): void;
    /** Get the saved API key for a provider preset. */
    getProviderApiKey(providerKey: string): string;
    /**
     * Detect which service provider a model ID belongs to.
     * @param {string} modelId
     * @returns {string|null} provider key (e.g. 'doubao', 'openai') or null
     */
    detectProvider(modelId: string): string | null;
    /** Get the full abstract model map. */
    get abstractModelMap(): {
        [x: string]: string;
    };
    /** Set a single abstract mapping: keepwork-pro → real-model-id */
    setAbstractMapping(abstractName: string, realModelId: string): void;
    /** Remove an abstract mapping. */
    removeAbstractMapping(abstractName: string): void;
    /**
     * Reset all settings except API keys (per-provider + per-model) and the
     * abstract model mapping. Useful when the user wants to restore default
     * model lists / enabled flags / direct-call preferences without losing
     * the API keys they have already entered.
     */
    resetExceptApiKeysAndAbstractMap(): void;
    /** Get the real model ID for an abstract name (or return the name unchanged). */
    resolveAbstractName(name: string): string;
    /**
     * Resolve a display name (e.g. "Doubao Seedance 2.0 fast") to its modelId
     * (e.g. "seedance-2.0-fast").  Returns the input unchanged if no match found.
     * @param {string} name
     * @returns {string}
     */
    resolveModelName(name: string): string;
    get hasSettings(): boolean;
    /**
     * Resolve a model name/ID to { model, apiKey } for use by AIChat / AIChatRTC / AIGenerators.
     * Handles display-name resolution, abstract-name mapping, and enabled checks.
     * @param {string} model
     * @param {object|string} [options] - Optional { provider } hint, or provider key string.
     * @returns {{model: string, apiKey: string, provider?: string, preferDirect?: boolean}}
     */
    resolveModelSettings(model: string, options?: Record<string, unknown> | string): Record<string, unknown>;
    load(): Promise<void>;
    _getStore(): LAKStore | null;
    _doLoad(): Promise<void>;
    save(): Promise<void>;
    clear(): Promise<void>;
    _serializeData(): Record<string, unknown>;
    /**
     * Build a one-shot map of legacy Volcano Endpoint IDs to friendly model names.
     * Older builds persisted `modelId: 'ep-...'`; we transparently rewrite them.
     */
    _endpointIdToFriendlyName(endpointId: string): string | null;
    _applyData(data: Record<string, unknown>): void;
    /** Ensure _providerSettings has an entry for every SERVICE_PRESETS key. */
    _initProviderSettings(): void;
    _ensureDefaultServicePresets(): boolean;
    _getPresetProviderByModelName(name: string | undefined): string | null;
    _scheduleSave(): void;
    toJSON(): Record<string, unknown>;
    fromJSON(data: Record<string, unknown>): void;
    /**
     * Open the settings modal.
     * @param {object} [options]
     * @param {Function} [options.onClose]  - Called when the modal is dismissed.
     * @param {Function} [options.onSave]   - Called after settings are saved.
     * @param {string}   [options.title]    - Modal title override.
     * @param {string}   [options.lang]     - 'zhCN' | 'enUS' (auto-detected if omitted).
     * @param {boolean}  [options.fullscreen=false] - Use the full viewport instead of a centered dialog.
     */
    show(options?: Record<string, unknown>): void;
    /** Close the modal. */
    hide(): void;
    /** Toggle: show if hidden, hide if shown. */
    toggle(options?: Record<string, unknown>): void;
    _buildHTML(options?: Record<string, unknown>): string;
    _populateFields(): void;
    _renderModels(): void;
    /**
     * Return the "canonical" API key for a provider preset — the first
     * configured preset model's apiKey (matches what Presets tab shows).
     * Returns '' when no preset model for this provider is configured.
     */
    _getProviderPresetKey(providerKey: string | null): string;
    /** Set provider-level API key and propagate to models whose key matched the old value. */
    setProviderApiKey(providerKey: string, newApiKey: string): void;
    _updateCounts(): void;
    _renderActivePanel(): void;
    _switchToPresets(): void;
    _switchToCategory(cat: string): void;
    _renderPresets(): void;
    _bindPresetEvents(container: HTMLElement): void;
    _providerLabel(modelId: string): string;
    _bindEvents(): void;
    _injectStyles(): void;
    _esc(s: unknown): string;
    _attr(s: unknown): string;
    _eyeIcon(open: boolean): string;
}
export {};
//# sourceMappingURL=LocalAPIKeySettings.d.ts.map