donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
180 lines • 9.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDefaultToolRegistry = createDefaultToolRegistry;
const AcknowledgeUserInstruction_1 = require("../tools/AcknowledgeUserInstruction");
const AnalyzePageTextTool_1 = require("../tools/AnalyzePageTextTool");
const AssertPageTextTool_1 = require("../tools/AssertPageTextTool");
const AssertPageTool_1 = require("../tools/AssertPageTool");
const AssertTool_1 = require("../tools/AssertTool");
const AuditTool_1 = require("../tools/AuditTool");
const ChangeWebBrowserTabTool_1 = require("../tools/ChangeWebBrowserTabTool");
const ChooseSelectOptionTool_1 = require("../tools/ChooseSelectOptionTool");
const ClickTool_1 = require("../tools/ClickTool");
const CreateBrowserCookieReportTool_1 = require("../tools/CreateBrowserCookieReportTool");
const DetectBrokenLinksTool_1 = require("../tools/DetectBrokenLinksTool");
const DoubleClickTool_1 = require("../tools/DoubleClickTool");
const DownloadPdfTool_1 = require("../tools/DownloadPdfTool");
const GoForwardOrBackTool_1 = require("../tools/GoForwardOrBackTool");
const GoToWebpageTool_1 = require("../tools/GoToWebpageTool");
const HandleBrowserDialogTool_1 = require("../tools/HandleBrowserDialogTool");
const HoverOverElementTool_1 = require("../tools/HoverOverElementTool");
const InputFakerTool_1 = require("../tools/InputFakerTool");
const InputRandomizedEmailAddressTool_1 = require("../tools/InputRandomizedEmailAddressTool");
const InputTextTool_1 = require("../tools/InputTextTool");
const MakeCommentTool_1 = require("../tools/MakeCommentTool");
const MarkObjectiveCompleteTool_1 = require("../tools/MarkObjectiveCompleteTool");
const MarkObjectiveNotCompletableTool_1 = require("../tools/MarkObjectiveNotCompletableTool");
const PauseForUserInteractionTool_1 = require("../tools/PauseForUserInteractionTool");
const PressKeyTool_1 = require("../tools/PressKeyTool");
const ReloadPageTool_1 = require("../tools/ReloadPageTool");
const RememberPageTextTool_1 = require("../tools/RememberPageTextTool");
const RunAccessibilityTestTool_1 = require("../tools/RunAccessibilityTestTool");
const RunInlineJavaScriptCodeTool_1 = require("../tools/RunInlineJavaScriptCodeTool");
const RunSandboxedJavaScriptCodeTool_1 = require("../tools/RunSandboxedJavaScriptCodeTool");
const SaveWebpageAsPdfTool_1 = require("../tools/SaveWebpageAsPdfTool");
const ScrollPageTool_1 = require("../tools/ScrollPageTool");
const SetRunModeTool_1 = require("../tools/SetRunModeTool");
const SummarizeLearningsTool_1 = require("../tools/SummarizeLearningsTool");
const TriggerDonobuFlowTool_1 = require("../tools/TriggerDonobuFlowTool");
const WaitTool_1 = require("../tools/WaitTool");
const PluginLoader_1 = require("./PluginLoader");
// ---------------------------------------------------------------------------
// Built-in tool catalog
// ---------------------------------------------------------------------------
const DEFAULT_TOOL_NAMES = new Set([
AnalyzePageTextTool_1.AnalyzePageTextTool.NAME,
AssertTool_1.AssertTool.NAME,
AssertPageTool_1.AssertPageTool.NAME,
ChangeWebBrowserTabTool_1.ChangeWebBrowserTabTool.NAME,
ChooseSelectOptionTool_1.ChooseSelectOptionTool.NAME,
ClickTool_1.ClickTool.NAME,
DoubleClickTool_1.DoubleClickTool.NAME,
GoForwardOrBackTool_1.GoForwardOrBackTool.NAME,
GoToWebpageTool_1.GoToWebpageTool.NAME,
HandleBrowserDialogTool_1.HandleBrowserDialogTool.NAME,
HoverOverElementTool_1.HoverOverElementTool.NAME,
InputFakerTool_1.InputFakerTool.NAME,
InputRandomizedEmailAddressTool_1.InputRandomizedEmailAddressTool.NAME,
InputTextTool_1.InputTextTool.NAME,
MakeCommentTool_1.MakeCommentTool.NAME,
MarkObjectiveCompleteTool_1.MarkObjectiveCompleteTool.NAME,
MarkObjectiveNotCompletableTool_1.MarkObjectiveNotCompletableTool.NAME,
PressKeyTool_1.PressKeyTool.NAME,
RememberPageTextTool_1.RememberPageTextTool.NAME,
SetRunModeTool_1.SetRunModeTool.NAME,
ScrollPageTool_1.ScrollPageTool.NAME,
WaitTool_1.WaitTool.NAME,
]);
function createPrepackagedTools() {
return [
new AcknowledgeUserInstruction_1.AcknowledgeUserInstructionTool(),
new AnalyzePageTextTool_1.AnalyzePageTextTool(),
new AuditTool_1.AuditTool(),
new AssertTool_1.AssertTool(),
new AssertPageTextTool_1.AssertPageTextTool(),
new AssertPageTool_1.AssertPageTool(),
new CreateBrowserCookieReportTool_1.CreateBrowserCookieReportTool(),
new ChangeWebBrowserTabTool_1.ChangeWebBrowserTabTool(),
new ChooseSelectOptionTool_1.ChooseSelectOptionTool(),
new ClickTool_1.ClickTool(),
new DoubleClickTool_1.DoubleClickTool(),
new DownloadPdfTool_1.DownloadPdfTool(),
new DetectBrokenLinksTool_1.DetectBrokenLinksTool(),
new GoForwardOrBackTool_1.GoForwardOrBackTool(),
new GoToWebpageTool_1.GoToWebpageTool(),
new HandleBrowserDialogTool_1.HandleBrowserDialogTool(),
new HoverOverElementTool_1.HoverOverElementTool(),
new InputFakerTool_1.InputFakerTool(),
new InputRandomizedEmailAddressTool_1.InputRandomizedEmailAddressTool(),
new InputTextTool_1.InputTextTool(),
new MakeCommentTool_1.MakeCommentTool(),
new MarkObjectiveCompleteTool_1.MarkObjectiveCompleteTool(),
new MarkObjectiveNotCompletableTool_1.MarkObjectiveNotCompletableTool(),
new PauseForUserInteractionTool_1.PauseForUserInteractionTool(),
new PressKeyTool_1.PressKeyTool(),
new ReloadPageTool_1.ReloadPageTool(),
new RememberPageTextTool_1.RememberPageTextTool(),
new RunAccessibilityTestTool_1.RunAccessibilityTestTool(),
new RunInlineJavaScriptCodeTool_1.RunInlineJavaScriptCodeTool(),
new RunSandboxedJavaScriptCodeTool_1.RunSandboxedJavaScriptCodeTool(),
new SaveWebpageAsPdfTool_1.SaveWebpageAsPdfTool(),
new ScrollPageTool_1.ScrollPageTool(),
new SetRunModeTool_1.SetRunModeTool(),
new SummarizeLearningsTool_1.SummarizeLearningsTool(),
new TriggerDonobuFlowTool_1.TriggerDonobuFlowTool(),
new WaitTool_1.WaitTool(),
];
}
function createMinimalTools() {
return [
new MarkObjectiveCompleteTool_1.MarkObjectiveCompleteTool(),
new MarkObjectiveNotCompletableTool_1.MarkObjectiveNotCompletableTool(),
];
}
// ---------------------------------------------------------------------------
// Default implementation
// ---------------------------------------------------------------------------
class DefaultToolRegistry {
constructor(_pluginTools, _minimalTools, _prepackagedTools, _defaultTools, _allTools) {
this._pluginTools = _pluginTools;
this._minimalTools = _minimalTools;
this._prepackagedTools = _prepackagedTools;
this._defaultTools = _defaultTools;
this._allTools = _allTools;
}
pluginTools() {
return this._pluginTools;
}
minimalTools() {
return this._minimalTools;
}
prepackagedTools() {
return this._prepackagedTools;
}
defaultTools() {
return this._defaultTools;
}
allTools() {
return this._allTools;
}
toolsForTarget(targetType) {
return this._allTools.filter((t) => t.supportedTargets.length === 0 ||
t.supportedTargets.includes(targetType));
}
}
// ---------------------------------------------------------------------------
// Factory
// ---------------------------------------------------------------------------
/**
* Creates the default {@link ToolRegistry} by loading plugins and eagerly
* computing every tool collection. This is the only async entry point —
* once the registry is created, all access is synchronous.
*
* @param preloadedPluginTools Plugin tools that have already been loaded
* (e.g. by the server entry point). When provided, the factory skips
* the filesystem scan entirely.
*/
async function createDefaultToolRegistry(preloadedPluginTools) {
// Resolve plugins — the only async step.
let pluginTools;
if (preloadedPluginTools) {
pluginTools = preloadedPluginTools;
}
else {
const loader = await PluginLoader_1.PluginLoader.create();
const { tools } = await loader.loadAllPlugins();
pluginTools = tools;
}
const minimalTools = createMinimalTools();
const prepackagedTools = createPrepackagedTools();
// allTools: prepackaged + plugins, plugins override by name.
const pluginsByName = new Map(pluginTools.map((t) => [t.name, t]));
const dedupedPrepackaged = prepackagedTools.filter((t) => !pluginsByName.has(t.name));
const allTools = [...dedupedPrepackaged, ...pluginTools];
// defaultTools: curated subset of prepackaged + all plugins.
const defaultPrepackaged = prepackagedTools.filter((t) => DEFAULT_TOOL_NAMES.has(t.name));
const dedupedDefaults = defaultPrepackaged.filter((t) => !pluginsByName.has(t.name));
const defaultTools = [...dedupedDefaults, ...pluginTools];
return new DefaultToolRegistry(pluginTools, minimalTools, prepackagedTools, defaultTools, allTools);
}
//# sourceMappingURL=ToolRegistry.js.map