UNPKG

@kddd/artinet-sdk

Version:

TypeScript SDK for the Agent2Agent (A2A) Protocol

84 lines 3.63 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.bundle = bundle; const log_js_1 = require("../logging/log.js"); const esbuild = __importStar(require("esbuild")); const node_url_1 = require("node:url"); /** * Bundles a given JavaScript or TypeScript file into a single minified ES module string. * This utility leverages `esbuild` for efficient bundling, minification, and sourcemap generation. * It's designed to prepare agent code for deployment by packaging it and its local dependencies. * * @param filePath - The URL of the entry point file to bundle. * @returns A promise that resolves to a string containing the bundled and minified code. * @throws An error if the file path does not exist, is not a file, or if bundling fails for any reason. */ async function bundle(filePath) { const entryPath = (0, node_url_1.fileURLToPath)(filePath); (0, log_js_1.logDebug)(`bundler: `, `Attempting to recursively read imports starting from:`, entryPath); try { const fs = await import("node:fs"); const stats = fs.statSync(entryPath); if (!stats.isFile()) { (0, log_js_1.logError)(`bundler: `, `Filepath is not a file:`, entryPath); throw new Error(`// BUNDLING FAILED: Filepath is not a file: ${entryPath}`); } (0, log_js_1.logDebug)(`bundler: `, `Filepath exists:`, entryPath); } catch (err) { (0, log_js_1.logError)(`bundler: `, `Filepath does not exist:`, entryPath); throw new Error(`// BUNDLING FAILED: Filepath does not exist: ${entryPath}`); } try { const result = await esbuild.build({ entryPoints: [entryPath], bundle: true, minify: true, sourcemap: false, platform: "node", format: "esm", write: false, }); const output = result?.outputFiles?.[0]?.text ?? ""; (0, log_js_1.logDebug)(`bundler: Successfully read and bundled code:`, output.length.toString()); return output; } catch (err) { (0, log_js_1.logError)(`bundler: `, `Error during recursive read:`, err.message); throw new Error(`// BUNDLING FAILED: ${err.message}`); } } //# sourceMappingURL=bundler.js.map