donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
74 lines • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentsManager = void 0;
const envVars_1 = require("../envVars");
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);
await instance.initializeDefaultConfigurations();
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();
}
/**
* Automatically sets the 'flow-runner' agent config to the value at the
* DEFAULT_FLOW_RUNNER_GPT_CONFIG_NAME environment variable if it exists.
*/
async initializeDefaultConfigurations() {
const defaultFlowRunnerGptConfigName = process.env[envVars_1.ENV_VAR_NAMES.DEFAULT_FLOW_RUNNER_GPT_CONFIG_NAME];
if (defaultFlowRunnerGptConfigName) {
await this.set('flow-runner', defaultFlowRunnerGptConfigName);
}
}
}
exports.AgentsManager = AgentsManager;
//# sourceMappingURL=AgentsManager.js.map