donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
83 lines • 5.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupDonobuStack = setupDonobuStack;
const GptClientFactory_1 = require("../clients/GptClientFactory");
const GptClientPlugin_1 = require("../clients/GptClientPlugin");
const envVars_1 = require("../envVars");
const AgentsPersistenceSqlite_1 = require("../persistence/agents/AgentsPersistenceSqlite");
const DonobuSqliteDb_1 = require("../persistence/DonobuSqliteDb");
const EnvPersistenceRegistry_1 = require("../persistence/env/EnvPersistenceRegistry");
const FlowsPersistenceRegistry_1 = require("../persistence/flows/FlowsPersistenceRegistry");
const GptConfigsPersistenceSqlite_1 = require("../persistence/gptconfigs/GptConfigsPersistenceSqlite");
const PersistencePlugin_1 = require("../persistence/PersistencePlugin");
const SuitesPersistenceRegistry_1 = require("../persistence/suites/SuitesPersistenceRegistry");
const TestsPersistenceRegistry_1 = require("../persistence/tests/TestsPersistenceRegistry");
const TargetRuntimePlugin_1 = require("../targets/TargetRuntimePlugin");
const WebTargetRuntime_1 = require("../targets/WebTargetRuntime");
const AgentsManager_1 = require("./AgentsManager");
const DonobuFlowsManager_1 = require("./DonobuFlowsManager");
const EnvDataManager_1 = require("./EnvDataManager");
const GptConfigsManager_1 = require("./GptConfigsManager");
const PluginLoader_1 = require("./PluginLoader");
const SuitesManager_1 = require("./SuitesManager");
const TestsManager_1 = require("./TestsManager");
const ToolRegistry_1 = require("./ToolRegistry");
/**
* Create a new Donobu application stack.
*
* NOTE: The reason why we have the oddball {@link envPersistenceVolatile}
* parameter is because that can be used to hold a snapshot of the
* real NodeJS process's environment variables, of which, we generally
* should not do in hosted environments. However, if we are running
* within the context of being a library used for running Playwright tests,
* then having this snapshot is relevant so that tests can use normal
* environment variables.
*/
async function setupDonobuStack(donobuDeploymentEnvironment, controlPanelFactory, envPersistenceVolatile, environ = envVars_1.env.pick('ANTHROPIC_API_KEY', 'ANTHROPIC_MODEL_NAME', 'AWS_ACCESS_KEY_ID', 'AWS_BEDROCK_MODEL_NAME', 'AWS_SECRET_ACCESS_KEY', 'BASE64_GPT_CONFIG', 'BROWSERBASE_API_KEY', 'BROWSERBASE_PROJECT_ID', 'DONOBU_API_BASE_URL', 'DONOBU_API_KEY', 'DONOBU_PERSISTENCE_API_KEY', 'GOOGLE_GENERATIVE_AI_API_KEY', 'GOOGLE_GENERATIVE_AI_MODEL_NAME', 'OLLAMA_API_URL', 'OLLAMA_MODEL_NAME', 'OPENAI_API_KEY', 'OPENAI_API_MODEL_NAME', 'PERSISTENCE_PRIORITY')) {
const loadedPlugins = await loadDefaultPlugins();
const resolvedToolRegistry = await (0, ToolRegistry_1.createDefaultToolRegistry)(loadedPlugins.tools);
const persistencePlugins = new PersistencePlugin_1.PersistencePluginRegistry(loadedPlugins.persistencePlugins);
const gptClientPlugins = new GptClientPlugin_1.GptClientPluginRegistry(loadedPlugins.gptClientPlugins);
const targetRuntimePlugins = new TargetRuntimePlugin_1.TargetRuntimePluginRegistry(loadedPlugins.targetRuntimePlugins);
const gptClientFactory = new GptClientFactory_1.GptClientFactoryImpl(gptClientPlugins);
const sqliteDb = await (0, DonobuSqliteDb_1.getDonobuSqliteDatabase)();
const gptConfigsPersistence = await GptConfigsPersistenceSqlite_1.GptConfigsPersistenceSqlite.create(sqliteDb);
const gptConfigsManager = await GptConfigsManager_1.GptConfigsManager.create(gptConfigsPersistence, gptClientFactory);
const agentsPersistence = await AgentsPersistenceSqlite_1.AgentsPersistenceSqlite.create(sqliteDb);
const agentsManager = await AgentsManager_1.AgentsManager.create(agentsPersistence, gptConfigsManager);
const flowsPersistenceRegistry = await FlowsPersistenceRegistry_1.FlowsPersistenceRegistryImpl.fromEnvironment(environ, persistencePlugins);
const testsPersistenceRegistry = await TestsPersistenceRegistry_1.TestsPersistenceRegistryImpl.fromEnvironment(environ, flowsPersistenceRegistry);
const suitesPersistenceRegistry = await SuitesPersistenceRegistry_1.SuitesPersistenceRegistryImpl.fromEnvironment(environ);
const envPersistenceFactory = await EnvPersistenceRegistry_1.EnvPersistenceRegistryImpl.fromEnvironment(envPersistenceVolatile ?? null, environ, persistencePlugins);
const envDataManager = new EnvDataManager_1.EnvDataManager(envPersistenceFactory);
const flowsManager = new DonobuFlowsManager_1.DonobuFlowsManager(donobuDeploymentEnvironment, gptClientFactory, gptConfigsManager, agentsManager, flowsPersistenceRegistry, envDataManager, controlPanelFactory, environ, resolvedToolRegistry, targetRuntimePlugins, testsPersistenceRegistry);
const testsManager = new TestsManager_1.TestsManager(testsPersistenceRegistry, suitesPersistenceRegistry, flowsManager);
const suitesManager = new SuitesManager_1.SuitesManager(suitesPersistenceRegistry, testsPersistenceRegistry);
return {
toolRegistry: resolvedToolRegistry,
targetRuntimePlugins,
gptClientFactory,
gptConfigsPersistence,
gptConfigsManager,
agentsPersistence,
agentsManager,
flowsPersistenceRegistry,
flowsManager,
envDataManager,
testsPersistenceRegistry,
testsManager,
suitesPersistenceRegistry,
suitesManager,
};
}
/**
* Discover and load all plugins from disk, prepending the built-in web
* target runtime so it's always available.
*/
async function loadDefaultPlugins() {
const pluginLoader = await PluginLoader_1.PluginLoader.create();
const plugins = await pluginLoader.loadAllPlugins();
plugins.targetRuntimePlugins.unshift(WebTargetRuntime_1.webTargetRuntimePlugin);
return plugins;
}
//# sourceMappingURL=DonobuStack.js.map