UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

62 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AgentsManager = void 0; const GptConfigNotFoundException_1 = require("../exceptions/GptConfigNotFoundException"); /** * This class is responsible for mapping Donobu agents to GPT configurations. */ class AgentsManager { constructor(agentsPersistence, gptConfigsManager) { this.agentsPersistence = agentsPersistence; this.gptConfigsManager = gptConfigsManager; } static async create(agentsPersistence, gptConfigsManager) { const instance = new AgentsManager(agentsPersistence, gptConfigsManager); return instance; } /** * Set the given Donobu agent's with the given GPT configuration by name. If * the given GPT configuration name is non-null, and there is no corresponding * GPT configuration with that name, an exception is thrown. */ async set(agent, gptConfigName) { if (gptConfigName) { // Verify that the given config exists at all. This will throw if it does // not. await this.gptConfigsManager.get(gptConfigName); } await this.agentsPersistence.set(agent, gptConfigName); } /** * Return the GPT configuration name associated with the given Donobu agent. */ async get(agent) { const configName = await this.agentsPersistence.get(agent); if (configName) { try { // Verify that a config exists by that name at all. This will throw if // it does not. await this.gptConfigsManager.get(configName); return configName; } catch (error) { if (error instanceof GptConfigNotFoundException_1.GptConfigNotFoundException) { // Data consistency issue. Attempt to heal. await this.set(agent, null); return null; } else { throw error; } } } else { return null; } } async getAll() { return this.agentsPersistence.getAll(); } } exports.AgentsManager = AgentsManager; //# sourceMappingURL=AgentsManager.js.map