export class PromptMixin {
    /**
   * Validates the prompt keys and module keys
   * @param promptsDict
   * @param moduleDict
   */ validatePrompts(promptsDict, moduleDict) {
        for(const key in promptsDict){
            if (key.includes(":")) {
                throw new Error(`Prompt key ${key} cannot contain ':'.`);
            }
        }
        for(const key in moduleDict){
            if (key.includes(":")) {
                throw new Error(`Module key ${key} cannot contain ':'.`);
            }
        }
    }
    /**
   * Returns all prompts from the mixin and its modules
   */ getPrompts() {
        const promptsDict = this._getPrompts();
        const moduleDict = this._getPromptModules();
        this.validatePrompts(promptsDict, moduleDict);
        const allPrompts = {
            ...promptsDict
        };
        for (const [module_name, prompt_module] of Object.entries(moduleDict)){
            for (const [key, prompt] of Object.entries(prompt_module.getPrompts())){
                allPrompts[`${module_name}:${key}`] = prompt;
            }
        }
        return allPrompts;
    }
    /**
   * Updates the prompts in the mixin and its modules
   * @param promptsDict
   */ updatePrompts(promptsDict) {
        const promptModules = this._getPromptModules();
        this._updatePrompts(promptsDict);
        const subPromptDicts = {};
        for(const key in promptsDict){
            if (key.includes(":")) {
                const [module_name, sub_key] = key.split(":");
                if (!subPromptDicts[module_name]) {
                    subPromptDicts[module_name] = {};
                }
                subPromptDicts[module_name][sub_key] = promptsDict[key];
            }
        }
        for (const [module_name, subPromptDict] of Object.entries(subPromptDicts)){
            if (!promptModules[module_name]) {
                throw new Error(`Module ${module_name} not found.`);
            }
            const moduleToUpdate = promptModules[module_name];
            moduleToUpdate.updatePrompts(subPromptDict);
        }
    }
    // Must be implemented by subclasses
    _getPrompts() {
        return {};
    }
    _getPromptModules() {
        return {};
    }
    _updatePrompts(promptsDict) {
        return;
    }
}
