UNPKG

donobu

Version:

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

73 lines 3.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SuitesPersistenceRegistryImpl = void 0; const DonobuSqliteDb_1 = require("../DonobuSqliteDb"); const PersistencePlugin_1 = require("../PersistencePlugin"); const SuitesPersistenceDonobuApi_1 = require("./SuitesPersistenceDonobuApi"); const SuitesPersistenceSqlite_1 = require("./SuitesPersistenceSqlite"); const SuitesPersistenceVolatile_1 = require("./SuitesPersistenceVolatile"); class SuitesPersistenceRegistryImpl { constructor(layers) { this.layers = layers; if (layers.length === 0) { throw new Error('No valid suite persistence implementation available!'); } } static async fromEnvironment(environ, persistencePlugins = new PersistencePlugin_1.PersistencePluginRegistry()) { const donobuApiBaseUrl = environ.data.DONOBU_API_BASE_URL; // Persistence credential resolution: prefer the primary DONOBU_API_KEY // (which also drives the inference fallback chain in // DonobuFlowsManager.createGptClient), then fall back to the // persistence-only DONOBU_PERSISTENCE_API_KEY for hosts that route // inference through an explicit gpt-config and don't want their // persistence credential to short-circuit the agent lookup. const donobuApiKey = environ.data.DONOBU_API_KEY ?? environ.data.DONOBU_PERSISTENCE_API_KEY; const layers = []; for (const key of environ.data.PERSISTENCE_PRIORITY) { switch (key) { case 'DONOBU': if (donobuApiKey && donobuApiBaseUrl) { layers.push({ key, persistence: new SuitesPersistenceDonobuApi_1.SuitesPersistenceDonobuApi(donobuApiBaseUrl, donobuApiKey), }); } break; case 'LOCAL': layers.push({ key, persistence: await SuitesPersistenceSqlite_1.SuitesPersistenceSqlite.create(await (0, DonobuSqliteDb_1.getDonobuSqliteDatabase)()), }); break; case 'RAM': layers.push({ key, persistence: new SuitesPersistenceVolatile_1.SuitesPersistenceVolatile() }); break; default: { const plugin = persistencePlugins.get(key); if (plugin?.createSuitesPersistence) { const impl = await plugin.createSuitesPersistence(); if (impl) { layers.push({ key, persistence: impl }); } } break; } } } return new SuitesPersistenceRegistryImpl(layers); } async get() { return this.layers[0].persistence; } async getAll() { return this.layers.map((layer) => layer.persistence); } async getEntries() { return this.layers; } async getByKey(key) { return this.layers.find((layer) => layer.key === key)?.persistence; } } exports.SuitesPersistenceRegistryImpl = SuitesPersistenceRegistryImpl; //# sourceMappingURL=SuitesPersistenceRegistry.js.map