UNPKG

donobu

Version:

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

83 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestsPersistenceRegistryImpl = void 0; const DonobuSqliteDb_1 = require("../DonobuSqliteDb"); const PersistencePlugin_1 = require("../PersistencePlugin"); const TestsPersistenceDonobuApi_1 = require("./TestsPersistenceDonobuApi"); const TestsPersistenceSqlite_1 = require("./TestsPersistenceSqlite"); const TestsPersistenceVolatile_1 = require("./TestsPersistenceVolatile"); class TestsPersistenceRegistryImpl { constructor(layers) { this.layers = layers; if (layers.length === 0) { throw new Error('No valid test persistence implementation available!'); } } static async fromEnvironment(environ, /** * Flows registry — used by the volatile tests layer to compute * flow-derived sort keys (flow_count, latest_flow_created_at). * Optional: when omitted, the volatile layer falls back to * best-effort no-op sorting on those keys. */ flowsRegistry, 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 TestsPersistenceDonobuApi_1.TestsPersistenceDonobuApi(donobuApiBaseUrl, donobuApiKey), }); } break; case 'LOCAL': layers.push({ key, persistence: await TestsPersistenceSqlite_1.TestsPersistenceSqlite.create(await (0, DonobuSqliteDb_1.getDonobuSqliteDatabase)()), }); break; case 'RAM': layers.push({ key, persistence: new TestsPersistenceVolatile_1.TestsPersistenceVolatile(undefined, flowsRegistry ? () => flowsRegistry.get() : undefined), }); break; default: { const plugin = persistencePlugins.get(key); if (plugin?.createTestsPersistence) { const impl = await plugin.createTestsPersistence(); if (impl) { layers.push({ key, persistence: impl }); } } break; } } } return new TestsPersistenceRegistryImpl(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.TestsPersistenceRegistryImpl = TestsPersistenceRegistryImpl; //# sourceMappingURL=TestsPersistenceRegistry.js.map