UNPKG

donobu

Version:

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

48 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DownloadPdfTool = void 0; const Tool_1 = require("./Tool"); class DownloadPdfTool extends Tool_1.Tool { constructor() { super(DownloadPdfTool.NAME, 'Download the specified PDF file.', 'DownloadPdfToolCoreParameters', 'DownloadPdfToolGptParameters'); } async call(context, parameters) { const url = parameters.url; if (!url.toLowerCase().endsWith('.pdf')) { return { isSuccessful: false, forLlm: 'The provided URL does not point to a PDF file.', metadata: null, }; } try { const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const pdfBytes = Buffer.from(await response.arrayBuffer()); const filename = new Date().toISOString() + '.pdf'; await context.persistence.setFlowFile(context.metadata.id, filename, pdfBytes); return { isSuccessful: true, forLlm: `Successfully downloaded the PDF file: ${filename}`, metadata: { pdfFilename: filename, }, }; } catch (e) { return { isSuccessful: false, forLlm: `Failed to download the PDF file: ${e.message}`, metadata: null, }; } } async callFromGpt(context, parameters) { return this.call(context, parameters); } } exports.DownloadPdfTool = DownloadPdfTool; DownloadPdfTool.NAME = 'downloadPdf'; //# sourceMappingURL=DownloadPdfTool.js.map