import { DEFAULT_MAX_TOOL_CALLS, DEFAULT_MAX_RETRIES, DEFAULT_REQUEST_TIMEOUT, DEFAULT_MAX_TOKENS, DEFAULT_TOOL_EXECUTION, DEFAULT_OPENAI_BASE_URL, DEFAULT_ANTHROPIC_BASE_URL, DEFAULT_GEMINI_BASE_URL, DEFAULT_DEEPSEEK_BASE_URL, DEFAULT_OPENROUTER_BASE_URL, DEFAULT_OLLAMA_BASE_URL, DEFAULT_XAI_BASE_URL, DEFAULT_MISTRAL_BASE_URL, DEFAULT_BEDROCK_REGION } from "./constants.js";
export class Configuration {
    _openaiApiKey;
    _openaiApiBase;
    _anthropicApiKey;
    _anthropicApiBase;
    _geminiApiKey;
    _geminiApiBase;
    _deepseekApiKey;
    _deepseekApiBase;
    _ollamaApiBase;
    _openrouterApiKey;
    _openrouterApiBase;
    _xaiApiKey;
    _xaiApiBase;
    _mistralApiKey;
    _mistralApiBase;
    _bedrockApiKey;
    _bedrockAccessKeyId;
    _bedrockSecretAccessKey;
    _bedrockSessionToken;
    _bedrockRegion;
    _bedrockGuardrailIdentifier;
    _bedrockGuardrailVersion;
    _debug;
    _provider;
    get openaiApiKey() {
        return this._openaiApiKey ?? process.env.OPENAI_API_KEY?.trim();
    }
    set openaiApiKey(v) {
        this._openaiApiKey = v;
    }
    get openaiApiBase() {
        return this._openaiApiBase ?? process.env.OPENAI_API_BASE?.trim() ?? DEFAULT_OPENAI_BASE_URL;
    }
    set openaiApiBase(v) {
        this._openaiApiBase = v;
    }
    get anthropicApiKey() {
        return this._anthropicApiKey ?? process.env.ANTHROPIC_API_KEY?.trim();
    }
    set anthropicApiKey(v) {
        this._anthropicApiKey = v;
    }
    get anthropicApiBase() {
        return (this._anthropicApiBase ?? process.env.ANTHROPIC_API_BASE?.trim() ?? DEFAULT_ANTHROPIC_BASE_URL);
    }
    set anthropicApiBase(v) {
        this._anthropicApiBase = v;
    }
    get geminiApiKey() {
        return this._geminiApiKey ?? process.env.GEMINI_API_KEY?.trim();
    }
    set geminiApiKey(v) {
        this._geminiApiKey = v;
    }
    get geminiApiBase() {
        return this._geminiApiBase ?? process.env.GEMINI_API_BASE?.trim() ?? DEFAULT_GEMINI_BASE_URL;
    }
    set geminiApiBase(v) {
        this._geminiApiBase = v;
    }
    get deepseekApiKey() {
        return this._deepseekApiKey ?? process.env.DEEPSEEK_API_KEY?.trim();
    }
    set deepseekApiKey(v) {
        this._deepseekApiKey = v;
    }
    get deepseekApiBase() {
        return (this._deepseekApiBase ?? process.env.DEEPSEEK_API_BASE?.trim() ?? DEFAULT_DEEPSEEK_BASE_URL);
    }
    set deepseekApiBase(v) {
        this._deepseekApiBase = v;
    }
    get ollamaApiBase() {
        return this._ollamaApiBase ?? process.env.OLLAMA_API_BASE?.trim() ?? DEFAULT_OLLAMA_BASE_URL;
    }
    set ollamaApiBase(v) {
        this._ollamaApiBase = v;
    }
    get openrouterApiKey() {
        return this._openrouterApiKey ?? process.env.OPENROUTER_API_KEY?.trim();
    }
    set openrouterApiKey(v) {
        this._openrouterApiKey = v;
    }
    get openrouterApiBase() {
        return (this._openrouterApiBase ??
            process.env.OPENROUTER_API_BASE?.trim() ??
            DEFAULT_OPENROUTER_BASE_URL);
    }
    set openrouterApiBase(v) {
        this._openrouterApiBase = v;
    }
    get xaiApiKey() {
        return this._xaiApiKey ?? process.env.XAI_API_KEY?.trim();
    }
    set xaiApiKey(v) {
        this._xaiApiKey = v;
    }
    get xaiApiBase() {
        return this._xaiApiBase ?? process.env.XAI_API_BASE?.trim() ?? DEFAULT_XAI_BASE_URL;
    }
    set xaiApiBase(v) {
        this._xaiApiBase = v;
    }
    get mistralApiKey() {
        return this._mistralApiKey ?? process.env.MISTRAL_API_KEY?.trim();
    }
    set mistralApiKey(v) {
        this._mistralApiKey = v;
    }
    get mistralApiBase() {
        return this._mistralApiBase ?? process.env.MISTRAL_API_BASE?.trim() ?? DEFAULT_MISTRAL_BASE_URL;
    }
    set mistralApiBase(v) {
        this._mistralApiBase = v;
    }
    // AWS Bedrock configuration
    get bedrockApiKey() {
        return this._bedrockApiKey ?? process.env.AWS_BEARER_TOKEN_BEDROCK?.trim();
    }
    set bedrockApiKey(v) {
        this._bedrockApiKey = v;
    }
    get bedrockAccessKeyId() {
        return this._bedrockAccessKeyId ?? process.env.AWS_ACCESS_KEY_ID?.trim();
    }
    set bedrockAccessKeyId(v) {
        this._bedrockAccessKeyId = v;
    }
    get bedrockSecretAccessKey() {
        return this._bedrockSecretAccessKey ?? process.env.AWS_SECRET_ACCESS_KEY?.trim();
    }
    set bedrockSecretAccessKey(v) {
        this._bedrockSecretAccessKey = v;
    }
    get bedrockSessionToken() {
        return this._bedrockSessionToken ?? process.env.AWS_SESSION_TOKEN?.trim();
    }
    set bedrockSessionToken(v) {
        this._bedrockSessionToken = v;
    }
    get bedrockRegion() {
        return this._bedrockRegion ?? process.env.AWS_REGION?.trim() ?? DEFAULT_BEDROCK_REGION;
    }
    set bedrockRegion(v) {
        this._bedrockRegion = v;
    }
    get bedrockGuardrailIdentifier() {
        return this._bedrockGuardrailIdentifier ?? process.env.AWS_GUARDRAIL_ID?.trim();
    }
    set bedrockGuardrailIdentifier(v) {
        this._bedrockGuardrailIdentifier = v;
    }
    get bedrockGuardrailVersion() {
        return this._bedrockGuardrailVersion ?? process.env.AWS_GUARDRAIL_VERSION?.trim();
    }
    set bedrockGuardrailVersion(v) {
        this._bedrockGuardrailVersion = v;
    }
    get debug() {
        return this._debug ?? process.env.NODELLM_DEBUG === "true";
    }
    set debug(v) {
        this._debug = v;
    }
    get provider() {
        return this._provider ?? process.env.NODELLM_PROVIDER?.trim();
    }
    set provider(v) {
        this._provider = v;
    }
    maxToolCalls = DEFAULT_MAX_TOOL_CALLS;
    maxRetries = DEFAULT_MAX_RETRIES;
    requestTimeout = DEFAULT_REQUEST_TIMEOUT;
    maxTokens = DEFAULT_MAX_TOKENS;
    toolExecution = DEFAULT_TOOL_EXECUTION;
    /**
     * Returns a plain object with all configuration values.
     * This is useful for cloning or serialization.
     * It handles getters (lazy-loaded values) correctly.
     */
    toPlainObject() {
        const plain = { ...this }; // Capture all enumerable "own" properties (custom keys, overrides)
        // Capture all getters from the class prototype (lazy-loaded values)
        const prototype = Object.getPrototypeOf(this);
        const propertyNames = Object.getOwnPropertyNames(prototype);
        for (const name of propertyNames) {
            if (name === "constructor")
                continue;
            const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
            if (descriptor && descriptor.get) {
                // Trigger the getter to snapshot the live value (including env fallbacks)
                plain[name] = Reflect.get(this, name);
            }
        }
        return plain;
    }
}
export const config = new Configuration();
