UNPKG

@auto-browse/auto-browse

Version:
42 lines (41 loc) 1.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.browser_save_pdf = void 0; const tools_1 = require("@langchain/core/tools"); const zod_1 = require("zod"); const context_1 = require("../browser/context"); const os_1 = __importDefault(require("os")); const path_1 = __importDefault(require("path")); /** * Schema for saving PDF * Includes dummy property to satisfy Gemini's API requirement for non-empty object properties */ const pdfSchema = zod_1.z.object({ _: zod_1.z .string() .optional() .describe("No parameters required for this operation"), }); exports.browser_save_pdf = (0, tools_1.tool)(async () => { try { console.log(`[Save PDF Tool] Starting operation`); const page = context_1.context.existingPage(); const fileName = path_1.default.join(os_1.default.tmpdir(), `/page-${new Date().toISOString()}.pdf`); console.log(`[Save PDF Tool] Saving PDF to:`, fileName); await page.pdf({ path: fileName }); console.log(`[Save PDF Tool] Operation successful`); return `Saved as ${fileName}`; } catch (error) { const errorMessage = `Failed to save PDF: ${error instanceof Error ? error.message : "Unknown error"}`; console.error(`[Save PDF Tool] Error:`, errorMessage); return errorMessage; } }, { name: "savePdf", description: "Save page as PDF", schema: pdfSchema, });