/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Config, ProviderRuntimeContext, SettingsService, AuthType, ProfileManager } from '@vybestack/llxprt-code-core';
import type { ProviderManager, Profile, IModel, LoadBalancerProfile } from '@vybestack/llxprt-code-core';
import { OAuthManager } from '../auth/oauth-manager.js';
import type { HistoryItemWithoutId } from '../ui/types.js';
import type { LoadedSettings } from '../config/settings.js';
import { createIsolatedRuntimeContext as createIsolatedRuntimeContextInternal, type IsolatedRuntimeActivationOptions, type IsolatedRuntimeContextHandle } from './runtimeContextFactory.js';
import { getLoadBalancerStats, getLoadBalancerLastSelected, getAllLoadBalancerStats } from './profileApplication.js';
export { createIsolatedRuntimeContextInternal as createIsolatedRuntimeContext };
export type { IsolatedRuntimeActivationOptions, IsolatedRuntimeContextHandle, IsolatedRuntimeContextOptions, } from './runtimeContextFactory.js';
export { getLoadBalancerStats, getLoadBalancerLastSelected, getAllLoadBalancerStats, };
export type StatelessHardeningPreference = 'legacy' | 'strict';
/**
 * @plan:PLAN-20251023-STATELESS-HARDENING.P07
 * @requirement:REQ-SP4-005
 * Configure the global CLI stateless guard preference. Tests and CLI bootstrap
 * can call this to opt into strict guards without environment toggles.
 */
export declare function configureCliStatelessHardening(preference: StatelessHardeningPreference | null): void;
/**
 * @plan:PLAN-20251023-STATELESS-HARDENING.P07
 * @requirement:REQ-SP4-005
 */
export declare function getCliStatelessHardeningOverride(): StatelessHardeningPreference | null;
/**
 * @plan:PLAN-20251023-STATELESS-HARDENING.P07
 * @requirement:REQ-SP4-005
 * Reports the currently resolved stateless hardening preference.
 */
export declare function getCliStatelessHardeningPreference(): StatelessHardeningPreference;
export declare function isCliStatelessProviderModeEnabled(): boolean;
export interface CliRuntimeServices {
    settingsService: SettingsService;
    config: Config;
    providerManager: ProviderManager;
    profileManager?: ProfileManager;
}
/**
 * @plan:PLAN-20251023-STATELESS-HARDENING.P08
 * @requirement:REQ-SP4-004
 * @requirement:REQ-SP4-005
 *
 * Acquire the active provider runtime context that CLI bootstrap registered.
 * Throws if the runtime has not yet been initialised.
 *
 * When stateless hardening is enabled, this enforces that all required
 * services (settingsService, config) are present in the runtime registry
 * before allowing provider operations.
 */
export declare function getCliRuntimeContext(): ProviderRuntimeContext;
/**
 * Obtain the services that CLI surfaces through the runtime context.
 */
export declare function getCliRuntimeServices(): CliRuntimeServices;
export declare function getCliProviderManager(options?: {
    allowBrowserEnvironment?: boolean;
    settings?: LoadedSettings;
    addItem?: (itemData: Omit<HistoryItemWithoutId, 'id'>, baseTimestamp: number) => number;
}): ProviderManager;
export declare function isCliRuntimeStatelessReady(): boolean;
/**
 * @plan:PLAN-20251023-STATELESS-HARDENING.P08
 * @requirement:REQ-SP4-004
 * @requirement:REQ-SP4-005
 *
 * Ensure the active provider runtime context is normalized and pushed into
 * ProviderManager before any provider invocation. This function enforces
 * stateless provider guarantees by requiring explicit runtime-scoped services
 * (settings, config, userMemory) before execution.
 *
 * When stateless hardening is enabled (runtime metadata/global preference),
 * this helper normalizes the current runtime context and registers it with
 * ProviderManager so downstream providers always receive call-scoped
 * configuration without relying on singleton fallbacks.
 */
export declare function ensureStatelessProviderReady(): void;
/**
 * @plan:PLAN-20251018-STATELESSPROVIDER2.P03
 * @requirement:REQ-SP2-002
 * @pseudocode multi-runtime-baseline.md lines 7-7
 * Delegate helper that activates an isolated runtime while merging metadata overrides per Step 6.
 */
export declare function activateIsolatedRuntimeContext(handle: IsolatedRuntimeContextHandle, options?: IsolatedRuntimeActivationOptions): Promise<void>;
export declare function registerCliProviderInfrastructure(manager: ProviderManager, oauthManager: OAuthManager): void;
export declare function resetCliProviderInfrastructure(runtimeId?: string): void;
export declare function getCliOAuthManager(): OAuthManager | null;
/**
 * Accessor for the active CLI Config instance registered with the runtime
 * context. Throws if the bootstrap failed to attach the Config.
 */
export declare function getCliRuntimeConfig(): Config;
export declare function getActiveModelName(): string;
export declare function getActiveProviderStatus(): ProviderRuntimeStatus;
export declare function listAvailableModels(providerName?: string): Promise<IModel[]>;
export declare function getActiveProviderMetrics(): ReturnType<ProviderManager['getProviderMetrics']>;
export declare function getSessionTokenUsage(): {
    input: number;
    output: number;
    cache: number;
    tool: number;
    thought: number;
    total: number;
};
export declare function getEphemeralSettings(): Record<string, unknown>;
export declare function getEphemeralSetting(key: string): unknown;
export declare function setEphemeralSetting(key: string, value: unknown): void;
export declare function clearEphemeralSetting(key: string): void;
export declare function getActiveModelParams(): Record<string, unknown>;
export declare function setActiveModelParam(name: string, value: unknown): void;
export declare function clearActiveModelParam(name: string): void;
export declare function buildRuntimeProfileSnapshot(): Profile;
export interface ProfileLoadOptions {
    profileName?: string;
}
export interface ProfileLoadResult {
    profileName?: string;
    providerName: string;
    modelName: string;
    infoMessages: string[];
    warnings: string[];
    providerChanged: boolean;
    authType?: AuthType;
    baseUrl?: string;
    didFallback: boolean;
    requestedProvider: string | null;
}
export interface RuntimeDiagnosticsSnapshot {
    providerName: string | null;
    modelName: string | null;
    profileName: string | null;
    modelParams: Record<string, unknown>;
    ephemeralSettings: Record<string, unknown>;
}
export declare function applyProfileSnapshot(profile: Profile, options?: ProfileLoadOptions): Promise<ProfileLoadResult>;
export declare function saveProfileSnapshot(profileName: string, additionalConfig?: Partial<Profile>): Promise<Profile>;
/**
 * @deprecated This function saves old-style load balancer profiles (type='loadbalancer').
 * The old architecture did round-robin at profile-load time (selecting a profile once).
 * Use the new subProfiles architecture instead which does per-request load balancing.
 * This function is kept for backward compatibility only.
 */
export declare function saveLoadBalancerProfile(profileName: string, profile: LoadBalancerProfile): Promise<void>;
export declare function loadProfileByName(profileName: string): Promise<ProfileLoadResult>;
export declare function deleteProfileByName(profileName: string): Promise<void>;
export declare function listSavedProfiles(): Promise<string[]>;
export declare function getActiveProfileName(): string | null;
export declare function setDefaultProfileName(profileName: string | null): void;
export declare function getRuntimeDiagnosticsSnapshot(): RuntimeDiagnosticsSnapshot;
export declare function listProviders(): string[];
export declare function getActiveProviderName(): string;
/**
 * Register or update the active CLI runtime context.
 */
export declare function setCliRuntimeContext(settingsService: SettingsService, config?: Config, options?: {
    metadata?: ProviderRuntimeContext['metadata'];
    runtimeId?: string;
    profileManager?: ProfileManager;
}): void;
export interface ProviderSwitchResult {
    changed: boolean;
    previousProvider: string | null;
    nextProvider: string;
    defaultModel?: string;
    authType?: AuthType;
    infoMessages: string[];
}
export interface ApiKeyUpdateResult {
    changed: boolean;
    providerName: string;
    message: string;
    isPaidMode?: boolean;
    authType?: AuthType;
}
export interface BaseUrlUpdateResult {
    changed: boolean;
    providerName: string;
    message: string;
    baseUrl?: string;
}
export interface ToolFormatState {
    providerName: string;
    currentFormat: string | null;
    override: string | null;
    isAutoDetected: boolean;
}
export type ToolFormatOverrideLiteral = 'auto' | 'openai' | 'qwen' | 'kimi' | 'hermes' | 'xml' | 'anthropic' | 'deepseek' | 'gemma' | 'llama';
export interface ProviderRuntimeStatus {
    providerName: string | null;
    modelName: string | null;
    displayLabel: string;
    isPaidMode?: boolean;
    authType?: AuthType;
    baseURL?: string;
}
export declare function switchActiveProvider(providerName: string, options?: {
    autoOAuth?: boolean;
    preserveEphemerals?: string[];
    addItem?: (itemData: Omit<HistoryItemWithoutId, 'id'>, baseTimestamp: number) => number;
}): Promise<ProviderSwitchResult>;
export interface ModelChangeResult {
    providerName: string;
    previousModel?: string;
    nextModel: string;
    authRefreshed: boolean;
}
export declare function updateActiveProviderApiKey(apiKey: string | null): Promise<ApiKeyUpdateResult>;
export declare function updateActiveProviderBaseUrl(baseUrl: string | null): Promise<BaseUrlUpdateResult>;
export declare function getActiveToolFormatState(): Promise<ToolFormatState>;
export declare function setActiveToolFormatOverride(formatName: ToolFormatOverrideLiteral | null): Promise<ToolFormatState>;
/**
 * Update the active model for the current provider while keeping Config and
 * SettingsService in sync.
 *
 * @plan:PLAN-20250218-STATELESSPROVIDER.P06
 * @requirement:REQ-SP-005
 * @pseudocode:cli-runtime.md line 10
 */
export declare function setActiveModel(modelName: string): Promise<ModelChangeResult>;
/**
 * Apply CLI argument overrides to configuration.
 * Must be called AFTER provider manager creation (so getCliRuntimeServices() works)
 * but BEFORE provider switching (so auth is ready).
 *
 * This function applies CLI arguments in the correct order to ensure they override
 * profile settings:
 * 1. Apply --key (overrides profile auth-key)
 * 2. Apply --keyfile (overrides profile auth-keyfile)
 * 3. Apply --set arguments (overrides profile ephemerals)
 * 4. Apply --baseurl (overrides profile base-url)
 *
 * @param argv - CLI arguments
 * @param bootstrapArgs - Bootstrap parsed arguments (used for bundle compatibility)
 */
export declare function applyCliArgumentOverrides(argv: {
    key?: string;
    keyfile?: string;
    set?: string[];
    baseurl?: string;
}, bootstrapArgs?: {
    keyOverride?: string | null;
    keyfileOverride?: string | null;
    setOverrides?: string[] | null;
    baseurlOverride?: string | null;
}): Promise<void>;
