UNPKG

donobu

Version:

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

40 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RunInlineJavaScriptCodeTool = exports.RunInlineJavaScriptCodeGptSchema = exports.RunInlineJavaScriptCodeCoreSchema = void 0; const v4_1 = require("zod/v4"); const ToolSchema_1 = require("../models/ToolSchema"); const TargetUtils_1 = require("../utils/TargetUtils"); const Tool_1 = require("./Tool"); exports.RunInlineJavaScriptCodeCoreSchema = v4_1.z.object({ javaScriptCode: v4_1.z.string().describe('The JavaScript code to run.'), }); exports.RunInlineJavaScriptCodeGptSchema = v4_1.z.object({ ...ToolSchema_1.BaseGptArgsSchema.shape, ...exports.RunInlineJavaScriptCodeCoreSchema.shape, }); class RunInlineJavaScriptCodeTool extends Tool_1.Tool { constructor() { super(RunInlineJavaScriptCodeTool.NAME, `Run arbitrary JavaScript code inside of the current webpage. The entire DOM is available, as well as the overall environment of the webpage itself. The JS code must be of the form: \`\`\` () => { // ...some code... return ...some result... } \`\`\``, exports.RunInlineJavaScriptCodeCoreSchema, exports.RunInlineJavaScriptCodeGptSchema, false, undefined, ['web']); } async call(context, parameters) { const result = await (0, TargetUtils_1.webPage)(context).evaluate(parameters.javaScriptCode); return { isSuccessful: true, forLlm: '' + JSON.stringify(result), metadata: null, }; } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.RunInlineJavaScriptCodeTool = RunInlineJavaScriptCodeTool; RunInlineJavaScriptCodeTool.NAME = 'runInlineJavaScriptCode'; //# sourceMappingURL=RunInlineJavaScriptCodeTool.js.map