UNPKG

donobu

Version:

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

43 lines 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RunSandboxedJavaScriptCodeTool = void 0; const Tool_1 = require("./Tool"); const playwright_1 = require("playwright"); class RunSandboxedJavaScriptCodeTool extends Tool_1.Tool { constructor() { super(RunSandboxedJavaScriptCodeTool.NAME, `Run arbitrary JavaScript code in a sandboxed environment. Unlike the ` + `"runInlineJavaScriptCode" tool, this tool does not have access to current ` + `webpage's DOM or environment. The JS code must be of the form:\n` + '```\n' + '() => {\n' + ' // ...some code...\n' + ' return ...some result...\n' + '}\n' + '```', 'RunSandboxedJavaScriptCodeToolCoreParameters', 'RunSandboxedJavaScriptCodeToolGptParameters'); } async call(_context, parameters) { const sandBoxedBrowser = await playwright_1.chromium.launch({ headless: true, chromiumSandbox: true, }); const sandBoxedPage = await sandBoxedBrowser.newPage(); try { const result = await sandBoxedPage.evaluate(parameters.javaScriptCode); return { isSuccessful: true, forLlm: '' + JSON.stringify(result), metadata: null, }; } finally { await sandBoxedPage.close(); await sandBoxedBrowser.close(); } } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.RunSandboxedJavaScriptCodeTool = RunSandboxedJavaScriptCodeTool; RunSandboxedJavaScriptCodeTool.NAME = 'runSandboxedJavaScriptCode'; //# sourceMappingURL=RunSandboxedJavaScriptCodeTool.js.map