/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { Signal } from '@lumino/signaling';
import { coreStore } from '../state/index.js';
export const FORCE_ACTIVATE_RUNTIMES_PLUGINS = false;
export class DatalayerConfiguration {
    _configuration = coreStore.getState().configuration;
    _configurationChanged;
    constructor() {
        this._configurationChanged = new Signal(this);
    }
    set configuration(configuration) {
        this._configuration = configuration;
        this._configurationChanged.emit(configuration);
    }
    get configuration() {
        return this._configuration;
    }
    get configurationChanged() {
        return this._configurationChanged;
    }
}
/**
 * Default configuration values for Datalayer
 */
export const DEFAULT_DATALAYER_CONFIG = {
    runUrl: 'https://oss.datalayer.run',
    credits: 100,
    cpuEnvironment: 'ai-agents-env',
    gpuEnvironment: 'ai-env',
};
/**
 * Type guard to check if a config object is a valid IDatalayerConfig
 */
export function isDatalayerConfig(config) {
    return (config &&
        typeof config === 'object' &&
        typeof config.runUrl === 'string' &&
        typeof config.token === 'string' &&
        typeof config.credits === 'number' &&
        typeof config.cpuEnvironment === 'string' &&
        typeof config.gpuEnvironment === 'string');
}
/**
 * Helper function to merge partial config with defaults
 * @param config Partial configuration to merge
 * @returns Complete configuration with defaults applied, or undefined if required fields missing
 */
export function mergeConfigWithDefaults(config) {
    if (!config)
        return undefined;
    // If we have required fields (token and runUrl), merge with defaults for optional fields
    if (config.token && config.runUrl) {
        return {
            runUrl: config.runUrl,
            token: config.token,
            credits: config.credits ?? DEFAULT_DATALAYER_CONFIG.credits,
            cpuEnvironment: config.cpuEnvironment ?? DEFAULT_DATALAYER_CONFIG.cpuEnvironment,
            gpuEnvironment: config.gpuEnvironment ?? DEFAULT_DATALAYER_CONFIG.gpuEnvironment,
        };
    }
    // If missing required fields, return undefined
    return undefined;
}
export default DatalayerConfiguration;
