UNPKG

donobu

Version:

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

33 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomToolRunnerTool = void 0; const JsonSchemaUtils_1 = require("../utils/JsonSchemaUtils"); const TargetUtils_1 = require("../utils/TargetUtils"); const Tool_1 = require("./Tool"); /** * This is a special Tool implementation that wraps a CustomTool to be used in a * flow. */ class CustomToolRunnerTool extends Tool_1.Tool { constructor(customTool) { const dynamicSchema = (0, JsonSchemaUtils_1.jsonSchemaToZod)(customTool.inputSchema); super(customTool.name, customTool.description, dynamicSchema, // Use the converted Zod schema dynamicSchema, // Same for both NonGPT and GPT false, undefined, ['web']); this.javascript = customTool.javascript; } async call(context, parameters) { const executableJavaScript = `(${this.javascript})(${JSON.stringify(parameters)})`; const result = await (0, TargetUtils_1.webPage)(context).evaluate(executableJavaScript, parameters); return { isSuccessful: true, forLlm: '' + JSON.stringify(result, null, 2), metadata: null, }; } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.CustomToolRunnerTool = CustomToolRunnerTool; //# sourceMappingURL=CustomToolRunnerTool.js.map