donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
57 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DownloadPdfTool = exports.DownloadPdfGptSchema = exports.DownloadPdfCoreSchema = void 0;
const v4_1 = require("zod/v4");
const ToolSchema_1 = require("../models/ToolSchema");
const Tool_1 = require("./Tool");
exports.DownloadPdfCoreSchema = v4_1.z.object({
url: v4_1.z.string().describe('The URL of the PDF file to be downloaded.'),
});
exports.DownloadPdfGptSchema = v4_1.z.object({
...ToolSchema_1.BaseGptArgsSchema.shape,
...exports.DownloadPdfCoreSchema.shape,
});
class DownloadPdfTool extends Tool_1.Tool {
constructor() {
super(DownloadPdfTool.NAME, 'Download the specified PDF file.', exports.DownloadPdfCoreSchema, exports.DownloadPdfGptSchema, false, undefined, ['web']);
}
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