@agentforge/tools 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,1720 @@
1
+ 'use strict';
2
+
3
+ var core = require('@agentforge/core');
4
+ var zod = require('zod');
5
+ var axios = require('axios');
6
+ var cheerio2 = require('cheerio');
7
+ var sync = require('csv-parse/sync');
8
+ var sync$1 = require('csv-stringify/sync');
9
+ var fastXmlParser = require('fast-xml-parser');
10
+ var fs = require('fs');
11
+ var path3 = require('path');
12
+ var dateFns = require('date-fns');
13
+
14
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n.default = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var axios__default = /*#__PURE__*/_interopDefault(axios);
35
+ var cheerio2__namespace = /*#__PURE__*/_interopNamespace(cheerio2);
36
+ var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
37
+
38
+ // src/web/http-client.ts
39
+ var HttpMethod = zod.z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]);
40
+ var httpRequestSchema = zod.z.object({
41
+ url: zod.z.string().url().describe("The URL to make the request to"),
42
+ method: HttpMethod.default("GET").describe("HTTP method to use"),
43
+ headers: zod.z.record(zod.z.string()).optional().describe("Optional HTTP headers"),
44
+ body: zod.z.any().optional().describe("Optional request body (for POST, PUT, PATCH)"),
45
+ timeout: zod.z.number().default(3e4).describe("Request timeout in milliseconds"),
46
+ params: zod.z.record(zod.z.string()).optional().describe("Optional URL query parameters")
47
+ });
48
+ var httpClient = core.toolBuilder().name("http-client").description("Make HTTP requests to web APIs and services. Supports GET, POST, PUT, DELETE, PATCH methods with custom headers and body.").category(core.ToolCategory.WEB).tags(["http", "api", "request", "web"]).schema(httpRequestSchema).implement(async (input) => {
49
+ const config = {
50
+ method: input.method,
51
+ url: input.url,
52
+ headers: input.headers,
53
+ data: input.body,
54
+ timeout: input.timeout,
55
+ params: input.params,
56
+ validateStatus: () => true
57
+ // Don't throw on any status code
58
+ };
59
+ const response = await axios__default.default(config);
60
+ return {
61
+ status: response.status,
62
+ statusText: response.statusText,
63
+ headers: response.headers,
64
+ data: response.data,
65
+ url: input.url,
66
+ method: input.method ?? "GET"
67
+ };
68
+ }).build();
69
+ var httpGet = core.toolBuilder().name("http-get").description("Make a simple HTTP GET request to a URL and return the response data.").category(core.ToolCategory.WEB).tags(["http", "get", "fetch", "web"]).schema(zod.z.object({
70
+ url: zod.z.string().url().describe("The URL to fetch"),
71
+ headers: zod.z.record(zod.z.string()).optional().describe("Optional HTTP headers"),
72
+ params: zod.z.record(zod.z.string()).optional().describe("Optional URL query parameters")
73
+ })).implement(async (input) => {
74
+ const response = await axios__default.default.get(input.url, {
75
+ headers: input.headers,
76
+ params: input.params,
77
+ timeout: 3e4
78
+ });
79
+ return response.data;
80
+ }).build();
81
+ var httpPost = core.toolBuilder().name("http-post").description("Make a simple HTTP POST request with JSON body and return the response data.").category(core.ToolCategory.WEB).tags(["http", "post", "api", "web"]).schema(zod.z.object({
82
+ url: zod.z.string().url().describe("The URL to post to"),
83
+ body: zod.z.any().describe("The request body (will be sent as JSON)"),
84
+ headers: zod.z.record(zod.z.string()).optional().describe("Optional HTTP headers")
85
+ })).implement(async (input) => {
86
+ const response = await axios__default.default.post(input.url, input.body, {
87
+ headers: {
88
+ "Content-Type": "application/json",
89
+ ...input.headers
90
+ },
91
+ timeout: 3e4
92
+ });
93
+ return response.data;
94
+ }).build();
95
+ var webScraper = core.toolBuilder().name("web-scraper").description("Scrape and extract data from web pages. Can extract text, HTML, links, images, and use CSS selectors to target specific elements.").category(core.ToolCategory.WEB).tags(["scraper", "web", "html", "extract", "parse"]).schema(zod.z.object({
96
+ url: zod.z.string().url().describe("The URL of the web page to scrape"),
97
+ selector: zod.z.string().optional().describe("Optional CSS selector to extract specific elements"),
98
+ extractText: zod.z.boolean().default(true).describe("Extract text content from the page"),
99
+ extractHtml: zod.z.boolean().default(false).describe("Extract raw HTML content"),
100
+ extractLinks: zod.z.boolean().default(false).describe("Extract all links from the page"),
101
+ extractImages: zod.z.boolean().default(false).describe("Extract all image URLs from the page"),
102
+ extractMetadata: zod.z.boolean().default(false).describe("Extract meta tags (title, description, etc.)"),
103
+ timeout: zod.z.number().default(3e4).describe("Request timeout in milliseconds")
104
+ })).implement(async (input) => {
105
+ const response = await axios__default.default.get(input.url, {
106
+ timeout: input.timeout,
107
+ headers: {
108
+ "User-Agent": "Mozilla/5.0 (compatible; AgentForge/1.0; +https://agentforge.dev)"
109
+ }
110
+ });
111
+ const html = response.data;
112
+ const $ = cheerio2__namespace.load(html);
113
+ const result = {
114
+ url: input.url
115
+ };
116
+ const $selected = input.selector ? $(input.selector) : $("body");
117
+ if (input.extractText) {
118
+ result.text = $selected.text().trim();
119
+ }
120
+ if (input.extractHtml) {
121
+ result.html = $selected.html() || "";
122
+ }
123
+ if (input.extractLinks) {
124
+ result.links = [];
125
+ $("a[href]").each((_, el) => {
126
+ const href = $(el).attr("href");
127
+ if (href) {
128
+ try {
129
+ const absoluteUrl = new URL(href, input.url).href;
130
+ result.links.push(absoluteUrl);
131
+ } catch {
132
+ result.links.push(href);
133
+ }
134
+ }
135
+ });
136
+ }
137
+ if (input.extractImages) {
138
+ result.images = [];
139
+ $("img[src]").each((_, el) => {
140
+ const src = $(el).attr("src");
141
+ if (src) {
142
+ try {
143
+ const absoluteUrl = new URL(src, input.url).href;
144
+ result.images.push(absoluteUrl);
145
+ } catch {
146
+ result.images.push(src);
147
+ }
148
+ }
149
+ });
150
+ }
151
+ if (input.extractMetadata) {
152
+ result.metadata = {};
153
+ const title = $("title").text() || $('meta[property="og:title"]').attr("content");
154
+ if (title) result.metadata.title = title;
155
+ const description = $('meta[name="description"]').attr("content") || $('meta[property="og:description"]').attr("content");
156
+ if (description) result.metadata.description = description;
157
+ $("meta[name], meta[property]").each((_, el) => {
158
+ const name = $(el).attr("name") || $(el).attr("property");
159
+ const content = $(el).attr("content");
160
+ if (name && content) {
161
+ result.metadata[name] = content;
162
+ }
163
+ });
164
+ }
165
+ if (input.selector) {
166
+ result.selected = $selected.map((_, el) => ({
167
+ text: $(el).text().trim(),
168
+ html: $(el).html()
169
+ })).get();
170
+ }
171
+ return result;
172
+ }).build();
173
+ var htmlParser = core.toolBuilder().name("html-parser").description("Parse HTML content and extract data using CSS selectors. Returns text, attributes, and structure of selected elements.").category(core.ToolCategory.WEB).tags(["html", "parser", "css", "selector", "extract"]).schema(zod.z.object({
174
+ html: zod.z.string().describe("The HTML content to parse"),
175
+ selector: zod.z.string().describe("CSS selector to find elements"),
176
+ extractText: zod.z.boolean().default(true).describe("Extract text content from selected elements"),
177
+ extractHtml: zod.z.boolean().default(false).describe("Extract inner HTML of selected elements"),
178
+ extractAttributes: zod.z.array(zod.z.string().describe("String value")).optional().describe('List of attributes to extract (e.g., ["href", "src", "class"])')
179
+ })).implement(async (input) => {
180
+ const $ = cheerio2__namespace.load(input.html);
181
+ const $selected = $(input.selector);
182
+ const results = $selected.map((_, el) => {
183
+ const $el = $(el);
184
+ const item = {};
185
+ if (input.extractText) {
186
+ item.text = $el.text().trim();
187
+ }
188
+ if (input.extractHtml) {
189
+ item.html = $el.html();
190
+ }
191
+ if (input.extractAttributes && input.extractAttributes.length > 0) {
192
+ item.attributes = {};
193
+ for (const attr of input.extractAttributes) {
194
+ const value = $el.attr(attr);
195
+ if (value !== void 0) {
196
+ item.attributes[attr] = value;
197
+ }
198
+ }
199
+ }
200
+ return item;
201
+ }).get();
202
+ return {
203
+ count: results.length,
204
+ results
205
+ };
206
+ }).build();
207
+ var extractLinks = core.toolBuilder().name("extract-links").description("Extract all links (anchor tags) from HTML content with their text and href attributes.").category(core.ToolCategory.WEB).tags(["html", "links", "extract", "anchor"]).schema(zod.z.object({
208
+ html: zod.z.string().describe("The HTML content to extract links from"),
209
+ baseUrl: zod.z.string().url().optional().describe("Optional base URL to resolve relative links")
210
+ })).implement(async (input) => {
211
+ const $ = cheerio2__namespace.load(input.html);
212
+ const links = [];
213
+ $("a[href]").each((_, el) => {
214
+ const $el = $(el);
215
+ let href = $el.attr("href") || "";
216
+ if (input.baseUrl && href) {
217
+ try {
218
+ href = new URL(href, input.baseUrl).href;
219
+ } catch {
220
+ }
221
+ }
222
+ links.push({
223
+ text: $el.text().trim(),
224
+ href,
225
+ title: $el.attr("title")
226
+ });
227
+ });
228
+ return {
229
+ count: links.length,
230
+ links
231
+ };
232
+ }).build();
233
+ var extractImages = core.toolBuilder().name("extract-images").description("Extract all images from HTML content with their src, alt, and other attributes.").category(core.ToolCategory.WEB).tags(["html", "images", "extract", "img"]).schema(zod.z.object({
234
+ html: zod.z.string().describe("The HTML content to extract images from"),
235
+ baseUrl: zod.z.string().url().optional().describe("Optional base URL to resolve relative image URLs")
236
+ })).implement(async (input) => {
237
+ const $ = cheerio2__namespace.load(input.html);
238
+ const images = [];
239
+ $("img[src]").each((_, el) => {
240
+ const $el = $(el);
241
+ let src = $el.attr("src") || "";
242
+ if (input.baseUrl && src) {
243
+ try {
244
+ src = new URL(src, input.baseUrl).href;
245
+ } catch {
246
+ }
247
+ }
248
+ images.push({
249
+ src,
250
+ alt: $el.attr("alt"),
251
+ title: $el.attr("title"),
252
+ width: $el.attr("width"),
253
+ height: $el.attr("height")
254
+ });
255
+ });
256
+ return {
257
+ count: images.length,
258
+ images
259
+ };
260
+ }).build();
261
+ var urlValidator = core.toolBuilder().name("url-validator").description("Validate and parse URLs. Returns detailed information about the URL structure including protocol, hostname, path, query parameters, and hash.").category(core.ToolCategory.WEB).tags(["url", "validator", "parse", "validate"]).schema(zod.z.object({
262
+ url: zod.z.string().describe("The URL to validate and parse")
263
+ })).implement(async (input) => {
264
+ try {
265
+ const parsed = new URL(input.url);
266
+ return {
267
+ valid: true,
268
+ url: parsed.href,
269
+ protocol: parsed.protocol,
270
+ hostname: parsed.hostname,
271
+ port: parsed.port,
272
+ pathname: parsed.pathname,
273
+ search: parsed.search,
274
+ hash: parsed.hash,
275
+ origin: parsed.origin
276
+ };
277
+ } catch (error) {
278
+ return {
279
+ valid: false,
280
+ error: error instanceof Error ? error.message : "Invalid URL"
281
+ };
282
+ }
283
+ }).build();
284
+ var urlBuilder = core.toolBuilder().name("url-builder").description("Build a URL from components (protocol, hostname, path, query parameters, hash).").category(core.ToolCategory.WEB).tags(["url", "builder", "construct"]).schema(zod.z.object({
285
+ protocol: zod.z.string().default("https").describe("Protocol (http, https, etc.)"),
286
+ hostname: zod.z.string().describe("Hostname or domain name"),
287
+ port: zod.z.string().optional().describe("Optional port number"),
288
+ pathname: zod.z.string().default("/").describe("URL path"),
289
+ query: zod.z.record(zod.z.string()).optional().describe("Query parameters as key-value pairs"),
290
+ hash: zod.z.string().optional().describe("URL hash/fragment")
291
+ })).implement(async (input) => {
292
+ const url = new URL(`${input.protocol}://${input.hostname}`);
293
+ if (input.port) {
294
+ url.port = input.port;
295
+ }
296
+ url.pathname = input.pathname ?? "/";
297
+ if (input.query) {
298
+ Object.entries(input.query).forEach(([key, value]) => {
299
+ url.searchParams.append(key, value);
300
+ });
301
+ }
302
+ if (input.hash) {
303
+ url.hash = input.hash;
304
+ }
305
+ return {
306
+ url: url.href,
307
+ components: {
308
+ protocol: url.protocol,
309
+ hostname: url.hostname,
310
+ port: url.port,
311
+ pathname: url.pathname,
312
+ search: url.search,
313
+ hash: url.hash,
314
+ origin: url.origin
315
+ }
316
+ };
317
+ }).build();
318
+ var urlQueryParser = core.toolBuilder().name("url-query-parser").description("Parse query parameters from a URL or query string into a key-value object.").category(core.ToolCategory.WEB).tags(["url", "query", "parse", "params"]).schema(zod.z.object({
319
+ input: zod.z.string().describe('URL or query string to parse (e.g., "?foo=bar&baz=qux" or full URL)')
320
+ })).implement(async (input) => {
321
+ let searchParams;
322
+ try {
323
+ const url = new URL(input.input);
324
+ searchParams = url.searchParams;
325
+ } catch {
326
+ const queryString = input.input.startsWith("?") ? input.input.slice(1) : input.input;
327
+ searchParams = new URLSearchParams(queryString);
328
+ }
329
+ const params = {};
330
+ searchParams.forEach((value, key) => {
331
+ if (params[key]) {
332
+ if (Array.isArray(params[key])) {
333
+ params[key].push(value);
334
+ } else {
335
+ params[key] = [params[key], value];
336
+ }
337
+ } else {
338
+ params[key] = value;
339
+ }
340
+ });
341
+ return {
342
+ params,
343
+ count: Object.keys(params).length
344
+ };
345
+ }).build();
346
+ var jsonParser = core.toolBuilder().name("json-parser").description("Parse JSON string into an object. Validates JSON syntax and returns parsed data or error details.").category(core.ToolCategory.UTILITY).tags(["json", "parse", "data"]).schema(zod.z.object({
347
+ json: zod.z.string().describe("JSON string to parse"),
348
+ strict: zod.z.boolean().default(true).describe("Use strict JSON parsing (no trailing commas, etc.)")
349
+ })).implement(async (input) => {
350
+ try {
351
+ const parsed = JSON.parse(input.json);
352
+ return {
353
+ success: true,
354
+ data: parsed,
355
+ type: Array.isArray(parsed) ? "array" : typeof parsed
356
+ };
357
+ } catch (error) {
358
+ return {
359
+ success: false,
360
+ error: error instanceof Error ? error.message : "Failed to parse JSON"
361
+ };
362
+ }
363
+ }).build();
364
+ var jsonStringify = core.toolBuilder().name("json-stringify").description("Convert an object to a JSON string with optional formatting (pretty print).").category(core.ToolCategory.UTILITY).tags(["json", "stringify", "format", "data"]).schema(zod.z.object({
365
+ data: zod.z.any().describe("Data to convert to JSON string"),
366
+ pretty: zod.z.boolean().default(false).describe("Format with indentation for readability"),
367
+ indent: zod.z.number().default(2).describe("Number of spaces for indentation (when pretty is true)")
368
+ })).implement(async (input) => {
369
+ try {
370
+ const json = input.pretty ? JSON.stringify(input.data, null, input.indent) : JSON.stringify(input.data);
371
+ return {
372
+ success: true,
373
+ json,
374
+ length: json.length
375
+ };
376
+ } catch (error) {
377
+ return {
378
+ success: false,
379
+ error: error instanceof Error ? error.message : "Failed to stringify data"
380
+ };
381
+ }
382
+ }).build();
383
+ var jsonQuery = core.toolBuilder().name("json-query").description('Query JSON data using dot notation path (e.g., "user.address.city"). Supports array indexing.').category(core.ToolCategory.UTILITY).tags(["json", "query", "path", "data"]).schema(zod.z.object({
384
+ data: zod.z.any().describe("JSON data to query"),
385
+ path: zod.z.string().describe('Dot notation path to query (e.g., "user.name" or "items[0].id")')
386
+ })).implement(async (input) => {
387
+ try {
388
+ const parts = input.path.split(".");
389
+ let current = input.data;
390
+ for (const part of parts) {
391
+ const arrayMatch = part.match(/^(\w+)\[(\d+)\]$/);
392
+ if (arrayMatch) {
393
+ const [, key, index] = arrayMatch;
394
+ current = current[key][parseInt(index, 10)];
395
+ } else {
396
+ current = current[part];
397
+ }
398
+ if (current === void 0) {
399
+ return {
400
+ success: false,
401
+ error: `Path not found: ${input.path}`
402
+ };
403
+ }
404
+ }
405
+ return {
406
+ success: true,
407
+ value: current,
408
+ type: Array.isArray(current) ? "array" : typeof current
409
+ };
410
+ } catch (error) {
411
+ return {
412
+ success: false,
413
+ error: error instanceof Error ? error.message : "Failed to query JSON"
414
+ };
415
+ }
416
+ }).build();
417
+ var jsonValidator = core.toolBuilder().name("json-validator").description("Validate JSON string syntax without parsing. Returns whether the JSON is valid and any error details.").category(core.ToolCategory.UTILITY).tags(["json", "validate", "check", "data"]).schema(zod.z.object({
418
+ json: zod.z.string().describe("JSON string to validate")
419
+ })).implement(async (input) => {
420
+ try {
421
+ JSON.parse(input.json);
422
+ return {
423
+ valid: true,
424
+ message: "Valid JSON"
425
+ };
426
+ } catch (error) {
427
+ return {
428
+ valid: false,
429
+ error: error instanceof Error ? error.message : "Invalid JSON"
430
+ };
431
+ }
432
+ }).build();
433
+ var jsonMerge = core.toolBuilder().name("json-merge").description("Merge two or more JSON objects. Later objects override earlier ones for conflicting keys.").category(core.ToolCategory.UTILITY).tags(["json", "merge", "combine", "data"]).schema(zod.z.object({
434
+ objects: zod.z.array(zod.z.any().describe("Object to merge")).describe("Array of objects to merge"),
435
+ deep: zod.z.boolean().default(false).describe("Perform deep merge (nested objects)")
436
+ })).implement(async (input) => {
437
+ if (input.deep) {
438
+ const deepMerge = (target, source) => {
439
+ const output = { ...target };
440
+ for (const key in source) {
441
+ if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
442
+ output[key] = deepMerge(output[key] || {}, source[key]);
443
+ } else {
444
+ output[key] = source[key];
445
+ }
446
+ }
447
+ return output;
448
+ };
449
+ return input.objects.reduce((acc, obj) => deepMerge(acc, obj), {});
450
+ } else {
451
+ return Object.assign({}, ...input.objects);
452
+ }
453
+ }).build();
454
+ var csvParser = core.toolBuilder().name("csv-parser").description("Parse CSV string into an array of objects. Supports custom delimiters, headers, and options.").category(core.ToolCategory.UTILITY).tags(["csv", "parse", "data", "table"]).schema(zod.z.object({
455
+ csv: zod.z.string().describe("CSV string to parse"),
456
+ delimiter: zod.z.string().default(",").describe("Column delimiter character"),
457
+ hasHeaders: zod.z.boolean().default(true).describe("First row contains column headers"),
458
+ skipEmptyLines: zod.z.boolean().default(true).describe("Skip empty lines in the CSV"),
459
+ trim: zod.z.boolean().default(true).describe("Trim whitespace from values")
460
+ })).implement(async (input) => {
461
+ try {
462
+ const records = sync.parse(input.csv, {
463
+ delimiter: input.delimiter,
464
+ columns: input.hasHeaders,
465
+ skip_empty_lines: input.skipEmptyLines,
466
+ trim: input.trim,
467
+ relax_column_count: true
468
+ });
469
+ return {
470
+ success: true,
471
+ data: records,
472
+ rowCount: records.length,
473
+ columnCount: records.length > 0 ? Object.keys(records[0]).length : 0
474
+ };
475
+ } catch (error) {
476
+ return {
477
+ success: false,
478
+ error: error instanceof Error ? error.message : "Failed to parse CSV"
479
+ };
480
+ }
481
+ }).build();
482
+ var csvGenerator = core.toolBuilder().name("csv-generator").description("Convert an array of objects to CSV string. Automatically extracts headers from object keys.").category(core.ToolCategory.UTILITY).tags(["csv", "generate", "stringify", "data"]).schema(zod.z.object({
483
+ data: zod.z.array(zod.z.record(zod.z.any().describe("Column value"))).describe("Array of objects to convert to CSV"),
484
+ delimiter: zod.z.string().default(",").describe("Column delimiter character"),
485
+ includeHeaders: zod.z.boolean().default(true).describe("Include header row with column names"),
486
+ columns: zod.z.array(zod.z.string().describe("String value")).optional().describe("Optional list of columns to include (in order)")
487
+ })).implement(async (input) => {
488
+ try {
489
+ const csv = sync$1.stringify(input.data, {
490
+ delimiter: input.delimiter,
491
+ header: input.includeHeaders,
492
+ columns: input.columns
493
+ });
494
+ return {
495
+ success: true,
496
+ csv,
497
+ rowCount: input.data.length
498
+ };
499
+ } catch (error) {
500
+ return {
501
+ success: false,
502
+ error: error instanceof Error ? error.message : "Failed to generate CSV"
503
+ };
504
+ }
505
+ }).build();
506
+ var csvToJson = core.toolBuilder().name("csv-to-json").description("Convert CSV string to JSON array. Each row becomes an object with column headers as keys.").category(core.ToolCategory.UTILITY).tags(["csv", "json", "convert", "data"]).schema(zod.z.object({
507
+ csv: zod.z.string().describe("CSV string to convert"),
508
+ delimiter: zod.z.string().default(",").describe("Column delimiter character"),
509
+ pretty: zod.z.boolean().default(false).describe("Format JSON with indentation")
510
+ })).implement(async (input) => {
511
+ try {
512
+ const records = sync.parse(input.csv, {
513
+ delimiter: input.delimiter,
514
+ columns: true,
515
+ skip_empty_lines: true,
516
+ trim: true
517
+ });
518
+ const json = input.pretty ? JSON.stringify(records, null, 2) : JSON.stringify(records);
519
+ return {
520
+ success: true,
521
+ json,
522
+ recordCount: records.length
523
+ };
524
+ } catch (error) {
525
+ return {
526
+ success: false,
527
+ error: error instanceof Error ? error.message : "Failed to convert CSV to JSON"
528
+ };
529
+ }
530
+ }).build();
531
+ var jsonToCsv = core.toolBuilder().name("json-to-csv").description("Convert JSON array to CSV string. Each object becomes a row with keys as column headers.").category(core.ToolCategory.UTILITY).tags(["json", "csv", "convert", "data"]).schema(zod.z.object({
532
+ json: zod.z.string().describe("JSON array string to convert"),
533
+ delimiter: zod.z.string().default(",").describe("Column delimiter character")
534
+ })).implement(async (input) => {
535
+ try {
536
+ const data = JSON.parse(input.json);
537
+ if (!Array.isArray(data)) {
538
+ return {
539
+ success: false,
540
+ error: "Input must be a JSON array"
541
+ };
542
+ }
543
+ const csv = sync$1.stringify(data, {
544
+ delimiter: input.delimiter,
545
+ header: true
546
+ });
547
+ return {
548
+ success: true,
549
+ csv,
550
+ rowCount: data.length
551
+ };
552
+ } catch (error) {
553
+ return {
554
+ success: false,
555
+ error: error instanceof Error ? error.message : "Failed to convert JSON to CSV"
556
+ };
557
+ }
558
+ }).build();
559
+ var xmlParser = core.toolBuilder().name("xml-parser").description("Parse XML string into a JavaScript object. Supports attributes, CDATA, and nested elements.").category(core.ToolCategory.UTILITY).tags(["xml", "parse", "data"]).schema(zod.z.object({
560
+ xml: zod.z.string().describe("XML string to parse"),
561
+ ignoreAttributes: zod.z.boolean().default(false).describe("Ignore XML attributes"),
562
+ parseAttributeValue: zod.z.boolean().default(true).describe("Parse attribute values (numbers, booleans)"),
563
+ trimValues: zod.z.boolean().default(true).describe("Trim whitespace from text values")
564
+ })).implement(async (input) => {
565
+ try {
566
+ const parser = new fastXmlParser.XMLParser({
567
+ ignoreAttributes: input.ignoreAttributes,
568
+ parseAttributeValue: input.parseAttributeValue,
569
+ trimValues: input.trimValues,
570
+ parseTagValue: true
571
+ });
572
+ const result = parser.parse(input.xml);
573
+ return {
574
+ success: true,
575
+ data: result
576
+ };
577
+ } catch (error) {
578
+ return {
579
+ success: false,
580
+ error: error instanceof Error ? error.message : "Failed to parse XML"
581
+ };
582
+ }
583
+ }).build();
584
+ var xmlGenerator = core.toolBuilder().name("xml-generator").description("Convert a JavaScript object to XML string. Supports attributes, CDATA, and nested elements.").category(core.ToolCategory.UTILITY).tags(["xml", "generate", "stringify", "data"]).schema(zod.z.object({
585
+ data: zod.z.any().describe("Object to convert to XML"),
586
+ rootName: zod.z.string().default("root").describe("Name of the root XML element"),
587
+ format: zod.z.boolean().default(false).describe("Format XML with indentation"),
588
+ indentSize: zod.z.number().default(2).describe("Number of spaces for indentation (when format is true)")
589
+ })).implement(async (input) => {
590
+ try {
591
+ const indentSize = input.indentSize ?? 2;
592
+ const rootName = input.rootName ?? "root";
593
+ const builder = new fastXmlParser.XMLBuilder({
594
+ format: input.format ?? false,
595
+ indentBy: " ".repeat(indentSize),
596
+ ignoreAttributes: false
597
+ });
598
+ const dataToConvert = input.data[rootName] ? input.data : { [rootName]: input.data };
599
+ const xml = builder.build(dataToConvert);
600
+ return {
601
+ success: true,
602
+ xml
603
+ };
604
+ } catch (error) {
605
+ return {
606
+ success: false,
607
+ error: error instanceof Error ? error.message : "Failed to generate XML"
608
+ };
609
+ }
610
+ }).build();
611
+ var xmlToJson = core.toolBuilder().name("xml-to-json").description("Convert XML string to JSON. Preserves structure and can include or exclude attributes.").category(core.ToolCategory.UTILITY).tags(["xml", "json", "convert", "data"]).schema(zod.z.object({
612
+ xml: zod.z.string().describe("XML string to convert"),
613
+ ignoreAttributes: zod.z.boolean().default(false).describe("Ignore XML attributes in conversion"),
614
+ pretty: zod.z.boolean().default(false).describe("Format JSON with indentation")
615
+ })).implement(async (input) => {
616
+ try {
617
+ const parser = new fastXmlParser.XMLParser({
618
+ ignoreAttributes: input.ignoreAttributes,
619
+ parseAttributeValue: true,
620
+ trimValues: true
621
+ });
622
+ const result = parser.parse(input.xml);
623
+ const json = input.pretty ? JSON.stringify(result, null, 2) : JSON.stringify(result);
624
+ return {
625
+ success: true,
626
+ json
627
+ };
628
+ } catch (error) {
629
+ return {
630
+ success: false,
631
+ error: error instanceof Error ? error.message : "Failed to convert XML to JSON"
632
+ };
633
+ }
634
+ }).build();
635
+ var jsonToXml = core.toolBuilder().name("json-to-xml").description("Convert JSON string to XML. Each object key becomes an XML element.").category(core.ToolCategory.UTILITY).tags(["json", "xml", "convert", "data"]).schema(zod.z.object({
636
+ json: zod.z.string().describe("JSON string to convert"),
637
+ rootName: zod.z.string().default("root").describe("Name of the root XML element"),
638
+ format: zod.z.boolean().default(false).describe("Format XML with indentation")
639
+ })).implement(async (input) => {
640
+ try {
641
+ const data = JSON.parse(input.json);
642
+ const rootName = input.rootName ?? "root";
643
+ const builder = new fastXmlParser.XMLBuilder({
644
+ format: input.format ?? false,
645
+ indentBy: " ",
646
+ ignoreAttributes: false
647
+ });
648
+ const dataToConvert = data[rootName] ? data : { [rootName]: data };
649
+ const xml = builder.build(dataToConvert);
650
+ return {
651
+ success: true,
652
+ xml
653
+ };
654
+ } catch (error) {
655
+ return {
656
+ success: false,
657
+ error: error instanceof Error ? error.message : "Failed to convert JSON to XML"
658
+ };
659
+ }
660
+ }).build();
661
+ var arrayFilter = core.toolBuilder().name("array-filter").description("Filter an array based on a property value. Supports equality, comparison, and contains operations.").category(core.ToolCategory.UTILITY).tags(["array", "filter", "data", "transform"]).schema(zod.z.object({
662
+ array: zod.z.array(zod.z.any().describe("Array element")).describe("Array to filter"),
663
+ property: zod.z.string().describe("Property name to filter by (use dot notation for nested properties)"),
664
+ operator: zod.z.enum(["equals", "not-equals", "greater-than", "less-than", "contains", "starts-with", "ends-with"]).describe("Comparison operator"),
665
+ value: zod.z.any().describe("Value to compare against")
666
+ })).implement(async (input) => {
667
+ const getNestedValue = (obj, path4) => {
668
+ return path4.split(".").reduce((current, key) => current?.[key], obj);
669
+ };
670
+ const filtered = input.array.filter((item) => {
671
+ const itemValue = getNestedValue(item, input.property);
672
+ switch (input.operator) {
673
+ case "equals":
674
+ return itemValue === input.value;
675
+ case "not-equals":
676
+ return itemValue !== input.value;
677
+ case "greater-than":
678
+ return itemValue > input.value;
679
+ case "less-than":
680
+ return itemValue < input.value;
681
+ case "contains":
682
+ return String(itemValue).includes(String(input.value));
683
+ case "starts-with":
684
+ return String(itemValue).startsWith(String(input.value));
685
+ case "ends-with":
686
+ return String(itemValue).endsWith(String(input.value));
687
+ default:
688
+ return false;
689
+ }
690
+ });
691
+ return {
692
+ filtered,
693
+ originalCount: input.array.length,
694
+ filteredCount: filtered.length
695
+ };
696
+ }).build();
697
+ var arrayMap = core.toolBuilder().name("array-map").description("Extract specific properties from each object in an array. Creates a new array with only the selected properties.").category(core.ToolCategory.UTILITY).tags(["array", "map", "data", "transform"]).schema(zod.z.object({
698
+ array: zod.z.array(zod.z.any().describe("Array element")).describe("Array to map"),
699
+ properties: zod.z.array(zod.z.string().describe("String value")).describe("List of property names to extract from each object")
700
+ })).implement(async (input) => {
701
+ const mapped = input.array.map((item) => {
702
+ const result = {};
703
+ for (const prop of input.properties) {
704
+ const value = prop.split(".").reduce((current, key) => current?.[key], item);
705
+ result[prop] = value;
706
+ }
707
+ return result;
708
+ });
709
+ return {
710
+ mapped,
711
+ count: mapped.length
712
+ };
713
+ }).build();
714
+ var arraySort = core.toolBuilder().name("array-sort").description("Sort an array by a property value. Supports ascending and descending order.").category(core.ToolCategory.UTILITY).tags(["array", "sort", "data", "transform"]).schema(zod.z.object({
715
+ array: zod.z.array(zod.z.any().describe("Array element")).describe("Array to sort"),
716
+ property: zod.z.string().describe("Property name to sort by (use dot notation for nested properties)"),
717
+ order: zod.z.enum(["asc", "desc"]).default("asc").describe("Sort order: ascending or descending")
718
+ })).implement(async (input) => {
719
+ const getNestedValue = (obj, path4) => {
720
+ return path4.split(".").reduce((current, key) => current?.[key], obj);
721
+ };
722
+ const sorted = [...input.array].sort((a, b) => {
723
+ const aValue = getNestedValue(a, input.property);
724
+ const bValue = getNestedValue(b, input.property);
725
+ if (aValue < bValue) return input.order === "asc" ? -1 : 1;
726
+ if (aValue > bValue) return input.order === "asc" ? 1 : -1;
727
+ return 0;
728
+ });
729
+ return {
730
+ sorted,
731
+ count: sorted.length
732
+ };
733
+ }).build();
734
+ var arrayGroupBy = core.toolBuilder().name("array-group-by").description("Group an array of objects by a property value. Returns an object with groups as keys.").category(core.ToolCategory.UTILITY).tags(["array", "group", "data", "transform"]).schema(zod.z.object({
735
+ array: zod.z.array(zod.z.any().describe("Array element")).describe("Array to group"),
736
+ property: zod.z.string().describe("Property name to group by")
737
+ })).implement(async (input) => {
738
+ const groups = {};
739
+ for (const item of input.array) {
740
+ const key = String(item[input.property]);
741
+ if (!groups[key]) {
742
+ groups[key] = [];
743
+ }
744
+ groups[key].push(item);
745
+ }
746
+ return {
747
+ groups,
748
+ groupCount: Object.keys(groups).length,
749
+ totalItems: input.array.length
750
+ };
751
+ }).build();
752
+ var objectPick = core.toolBuilder().name("object-pick").description("Create a new object with only the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "pick", "data", "transform"]).schema(zod.z.object({
753
+ object: zod.z.record(zod.z.any().describe("Property value")).describe("Source object"),
754
+ properties: zod.z.array(zod.z.string().describe("String value")).describe("List of property names to pick")
755
+ })).implement(async (input) => {
756
+ const picked = {};
757
+ for (const prop of input.properties) {
758
+ if (prop in input.object) {
759
+ picked[prop] = input.object[prop];
760
+ }
761
+ }
762
+ return picked;
763
+ }).build();
764
+ var objectOmit = core.toolBuilder().name("object-omit").description("Create a new object excluding the specified properties from the source object.").category(core.ToolCategory.UTILITY).tags(["object", "omit", "data", "transform"]).schema(zod.z.object({
765
+ object: zod.z.record(zod.z.any().describe("Property value")).describe("Source object"),
766
+ properties: zod.z.array(zod.z.string().describe("String value")).describe("List of property names to omit")
767
+ })).implement(async (input) => {
768
+ const omitted = { ...input.object };
769
+ for (const prop of input.properties) {
770
+ delete omitted[prop];
771
+ }
772
+ return omitted;
773
+ }).build();
774
+ var fileReader = core.toolBuilder().name("file-reader").description("Read the contents of a file from the file system. Supports text and binary files with various encodings.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "read", "io", "filesystem"]).schema(zod.z.object({
775
+ path: zod.z.string().describe("Path to the file to read"),
776
+ encoding: zod.z.enum(["utf8", "utf-8", "ascii", "base64", "hex", "binary"]).default("utf8").describe("File encoding")
777
+ })).implement(async (input) => {
778
+ try {
779
+ const content = await fs.promises.readFile(input.path, input.encoding);
780
+ const stats = await fs.promises.stat(input.path);
781
+ return {
782
+ success: true,
783
+ content,
784
+ size: stats.size,
785
+ path: input.path,
786
+ encoding: input.encoding
787
+ };
788
+ } catch (error) {
789
+ return {
790
+ success: false,
791
+ error: error instanceof Error ? error.message : "Failed to read file",
792
+ path: input.path
793
+ };
794
+ }
795
+ }).build();
796
+ var fileWriter = core.toolBuilder().name("file-writer").description("Write content to a file. Creates the file if it doesn't exist, or overwrites it if it does.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "write", "io", "filesystem"]).schema(zod.z.object({
797
+ path: zod.z.string().describe("Path to the file to write"),
798
+ content: zod.z.string().describe("Content to write to the file"),
799
+ encoding: zod.z.enum(["utf8", "utf-8", "ascii", "base64", "hex"]).default("utf8").describe("File encoding"),
800
+ createDirs: zod.z.boolean().default(false).describe("Create parent directories if they don't exist")
801
+ })).implement(async (input) => {
802
+ try {
803
+ if (input.createDirs) {
804
+ const dir = path3__namespace.dirname(input.path);
805
+ await fs.promises.mkdir(dir, { recursive: true });
806
+ }
807
+ await fs.promises.writeFile(input.path, input.content, input.encoding);
808
+ const stats = await fs.promises.stat(input.path);
809
+ return {
810
+ success: true,
811
+ path: input.path,
812
+ size: stats.size,
813
+ encoding: input.encoding
814
+ };
815
+ } catch (error) {
816
+ return {
817
+ success: false,
818
+ error: error instanceof Error ? error.message : "Failed to write file",
819
+ path: input.path
820
+ };
821
+ }
822
+ }).build();
823
+ var fileAppend = core.toolBuilder().name("file-append").description("Append content to the end of a file. Creates the file if it doesn't exist.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "append", "io", "filesystem"]).schema(zod.z.object({
824
+ path: zod.z.string().describe("Path to the file to append to"),
825
+ content: zod.z.string().describe("Content to append to the file"),
826
+ encoding: zod.z.enum(["utf8", "utf-8", "ascii"]).default("utf8").describe("File encoding")
827
+ })).implement(async (input) => {
828
+ try {
829
+ await fs.promises.appendFile(input.path, input.content, input.encoding);
830
+ const stats = await fs.promises.stat(input.path);
831
+ return {
832
+ success: true,
833
+ path: input.path,
834
+ size: stats.size
835
+ };
836
+ } catch (error) {
837
+ return {
838
+ success: false,
839
+ error: error instanceof Error ? error.message : "Failed to append to file",
840
+ path: input.path
841
+ };
842
+ }
843
+ }).build();
844
+ var fileDelete = core.toolBuilder().name("file-delete").description("Delete a file from the file system. Returns an error if the file doesn't exist.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "delete", "remove", "filesystem"]).schema(zod.z.object({
845
+ path: zod.z.string().describe("Path to the file to delete")
846
+ })).implement(async (input) => {
847
+ try {
848
+ await fs.promises.unlink(input.path);
849
+ return {
850
+ success: true,
851
+ path: input.path,
852
+ message: "File deleted successfully"
853
+ };
854
+ } catch (error) {
855
+ return {
856
+ success: false,
857
+ error: error instanceof Error ? error.message : "Failed to delete file",
858
+ path: input.path
859
+ };
860
+ }
861
+ }).build();
862
+ var fileExists = core.toolBuilder().name("file-exists").description("Check if a file or directory exists at the specified path.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "exists", "check", "filesystem"]).schema(zod.z.object({
863
+ path: zod.z.string().describe("Path to check")
864
+ })).implement(async (input) => {
865
+ try {
866
+ await fs.promises.access(input.path);
867
+ const stats = await fs.promises.stat(input.path);
868
+ return {
869
+ exists: true,
870
+ path: input.path,
871
+ isFile: stats.isFile(),
872
+ isDirectory: stats.isDirectory(),
873
+ size: stats.size,
874
+ modified: stats.mtime.toISOString()
875
+ };
876
+ } catch {
877
+ return {
878
+ exists: false,
879
+ path: input.path
880
+ };
881
+ }
882
+ }).build();
883
+ var directoryList = core.toolBuilder().name("directory-list").description("List all files and directories in a directory. Can optionally include file details and filter by extension.").category(core.ToolCategory.FILE_SYSTEM).tags(["directory", "list", "files", "filesystem"]).schema(zod.z.object({
884
+ path: zod.z.string().describe("Path to the directory to list"),
885
+ recursive: zod.z.boolean().default(false).describe("List files recursively in subdirectories"),
886
+ includeDetails: zod.z.boolean().default(false).describe("Include file size, type, and modification date"),
887
+ extension: zod.z.string().optional().describe('Optional file extension filter (e.g., ".txt", ".js")')
888
+ })).implement(async (input) => {
889
+ try {
890
+ const listFiles = async (dir, recursive) => {
891
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
892
+ const files2 = [];
893
+ for (const entry of entries) {
894
+ const fullPath = path3__namespace.join(dir, entry.name);
895
+ const relativePath = path3__namespace.relative(input.path, fullPath);
896
+ if (input.extension && !entry.name.endsWith(input.extension)) {
897
+ if (!entry.isDirectory() || !recursive) {
898
+ continue;
899
+ }
900
+ }
901
+ if (input.includeDetails) {
902
+ const stats = await fs.promises.stat(fullPath);
903
+ files2.push({
904
+ name: entry.name,
905
+ path: relativePath,
906
+ fullPath,
907
+ isFile: entry.isFile(),
908
+ isDirectory: entry.isDirectory(),
909
+ size: stats.size,
910
+ modified: stats.mtime.toISOString()
911
+ });
912
+ } else {
913
+ files2.push({
914
+ name: entry.name,
915
+ path: relativePath,
916
+ isFile: entry.isFile(),
917
+ isDirectory: entry.isDirectory()
918
+ });
919
+ }
920
+ if (recursive && entry.isDirectory()) {
921
+ const subFiles = await listFiles(fullPath, true);
922
+ files2.push(...subFiles);
923
+ }
924
+ }
925
+ return files2;
926
+ };
927
+ const files = await listFiles(input.path, input.recursive ?? false);
928
+ return {
929
+ success: true,
930
+ path: input.path,
931
+ files,
932
+ count: files.length
933
+ };
934
+ } catch (error) {
935
+ return {
936
+ success: false,
937
+ error: error instanceof Error ? error.message : "Failed to list directory",
938
+ path: input.path
939
+ };
940
+ }
941
+ }).build();
942
+ var directoryCreate = core.toolBuilder().name("directory-create").description("Create a new directory. Can optionally create parent directories if they don't exist.").category(core.ToolCategory.FILE_SYSTEM).tags(["directory", "create", "mkdir", "filesystem"]).schema(zod.z.object({
943
+ path: zod.z.string().describe("Path to the directory to create"),
944
+ recursive: zod.z.boolean().default(true).describe("Create parent directories if they don't exist")
945
+ })).implement(async (input) => {
946
+ try {
947
+ await fs.promises.mkdir(input.path, { recursive: input.recursive });
948
+ return {
949
+ success: true,
950
+ path: input.path,
951
+ message: "Directory created successfully"
952
+ };
953
+ } catch (error) {
954
+ return {
955
+ success: false,
956
+ error: error instanceof Error ? error.message : "Failed to create directory",
957
+ path: input.path
958
+ };
959
+ }
960
+ }).build();
961
+ var directoryDelete = core.toolBuilder().name("directory-delete").description("Delete a directory. Can optionally delete non-empty directories recursively.").category(core.ToolCategory.FILE_SYSTEM).tags(["directory", "delete", "remove", "filesystem"]).schema(zod.z.object({
962
+ path: zod.z.string().describe("Path to the directory to delete"),
963
+ recursive: zod.z.boolean().default(false).describe("Delete directory and all its contents")
964
+ })).implement(async (input) => {
965
+ try {
966
+ await fs.promises.rm(input.path, { recursive: input.recursive, force: false });
967
+ return {
968
+ success: true,
969
+ path: input.path,
970
+ message: "Directory deleted successfully"
971
+ };
972
+ } catch (error) {
973
+ return {
974
+ success: false,
975
+ error: error instanceof Error ? error.message : "Failed to delete directory",
976
+ path: input.path
977
+ };
978
+ }
979
+ }).build();
980
+ var fileSearch = core.toolBuilder().name("file-search").description("Search for files by name pattern in a directory. Supports wildcards and recursive search.").category(core.ToolCategory.FILE_SYSTEM).tags(["file", "search", "find", "filesystem"]).schema(zod.z.object({
981
+ directory: zod.z.string().describe("Directory to search in"),
982
+ pattern: zod.z.string().describe("File name pattern to search for (supports * wildcard)"),
983
+ recursive: zod.z.boolean().default(true).describe("Search in subdirectories"),
984
+ caseSensitive: zod.z.boolean().default(false).describe("Case-sensitive pattern matching")
985
+ })).implement(async (input) => {
986
+ try {
987
+ const searchFiles = async (dir) => {
988
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
989
+ const matches2 = [];
990
+ const regexPattern = input.pattern.replace(/\./g, "\\.").replace(/\*/g, ".*");
991
+ const regex = new RegExp(`^${regexPattern}$`, input.caseSensitive ? "" : "i");
992
+ for (const entry of entries) {
993
+ const fullPath = path3__namespace.join(dir, entry.name);
994
+ if (entry.isFile() && regex.test(entry.name)) {
995
+ matches2.push(fullPath);
996
+ }
997
+ if (input.recursive && entry.isDirectory()) {
998
+ const subMatches = await searchFiles(fullPath);
999
+ matches2.push(...subMatches);
1000
+ }
1001
+ }
1002
+ return matches2;
1003
+ };
1004
+ const matches = await searchFiles(input.directory);
1005
+ return {
1006
+ success: true,
1007
+ directory: input.directory,
1008
+ pattern: input.pattern,
1009
+ matches,
1010
+ count: matches.length
1011
+ };
1012
+ } catch (error) {
1013
+ return {
1014
+ success: false,
1015
+ error: error instanceof Error ? error.message : "Failed to search files",
1016
+ directory: input.directory
1017
+ };
1018
+ }
1019
+ }).build();
1020
+ var pathJoin = core.toolBuilder().name("path-join").description("Join multiple path segments into a single path. Handles platform-specific separators.").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "join", "filesystem"]).schema(zod.z.object({
1021
+ segments: zod.z.array(zod.z.string().describe("String value")).describe("Path segments to join")
1022
+ })).implement(async (input) => {
1023
+ const joined = path3__namespace.join(...input.segments);
1024
+ return {
1025
+ path: joined,
1026
+ segments: input.segments
1027
+ };
1028
+ }).build();
1029
+ var pathResolve = core.toolBuilder().name("path-resolve").description("Resolve a sequence of paths into an absolute path. Resolves relative paths from the current working directory.").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "resolve", "absolute", "filesystem"]).schema(zod.z.object({
1030
+ paths: zod.z.array(zod.z.string().describe("String value")).describe("Paths to resolve")
1031
+ })).implement(async (input) => {
1032
+ const resolved = path3__namespace.resolve(...input.paths);
1033
+ return {
1034
+ path: resolved,
1035
+ isAbsolute: path3__namespace.isAbsolute(resolved)
1036
+ };
1037
+ }).build();
1038
+ var pathParse = core.toolBuilder().name("path-parse").description("Parse a file path into its components (directory, filename, extension, etc.).").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "parse", "filesystem"]).schema(zod.z.object({
1039
+ path: zod.z.string().describe("File path to parse")
1040
+ })).implement(async (input) => {
1041
+ const parsed = path3__namespace.parse(input.path);
1042
+ return {
1043
+ root: parsed.root,
1044
+ dir: parsed.dir,
1045
+ base: parsed.base,
1046
+ name: parsed.name,
1047
+ ext: parsed.ext,
1048
+ isAbsolute: path3__namespace.isAbsolute(input.path)
1049
+ };
1050
+ }).build();
1051
+ var pathBasename = core.toolBuilder().name("path-basename").description("Get the last portion of a path (filename with extension). Optionally remove the extension.").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "basename", "filename", "filesystem"]).schema(zod.z.object({
1052
+ path: zod.z.string().describe("File path"),
1053
+ removeExtension: zod.z.boolean().default(false).describe("Remove the file extension")
1054
+ })).implement(async (input) => {
1055
+ const basename2 = input.removeExtension ? path3__namespace.basename(input.path, path3__namespace.extname(input.path)) : path3__namespace.basename(input.path);
1056
+ return {
1057
+ basename: basename2,
1058
+ extension: path3__namespace.extname(input.path)
1059
+ };
1060
+ }).build();
1061
+ var pathDirname = core.toolBuilder().name("path-dirname").description("Get the directory name of a path (everything except the last portion).").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "dirname", "directory", "filesystem"]).schema(zod.z.object({
1062
+ path: zod.z.string().describe("File path")
1063
+ })).implement(async (input) => {
1064
+ const dirname3 = path3__namespace.dirname(input.path);
1065
+ return {
1066
+ dirname: dirname3,
1067
+ basename: path3__namespace.basename(input.path)
1068
+ };
1069
+ }).build();
1070
+ var pathExtension = core.toolBuilder().name("path-extension").description('Get the file extension from a path (including the dot, e.g., ".txt").').category(core.ToolCategory.FILE_SYSTEM).tags(["path", "extension", "ext", "filesystem"]).schema(zod.z.object({
1071
+ path: zod.z.string().describe("File path")
1072
+ })).implement(async (input) => {
1073
+ const ext = path3__namespace.extname(input.path);
1074
+ return {
1075
+ extension: ext,
1076
+ hasExtension: ext.length > 0,
1077
+ filename: path3__namespace.basename(input.path, ext)
1078
+ };
1079
+ }).build();
1080
+ var pathRelative = core.toolBuilder().name("path-relative").description("Get the relative path from one path to another.").category(core.ToolCategory.FILE_SYSTEM).tags(["path", "relative", "filesystem"]).schema(zod.z.object({
1081
+ from: zod.z.string().describe("Source path"),
1082
+ to: zod.z.string().describe("Destination path")
1083
+ })).implement(async (input) => {
1084
+ const relative3 = path3__namespace.relative(input.from, input.to);
1085
+ return {
1086
+ relativePath: relative3,
1087
+ from: input.from,
1088
+ to: input.to
1089
+ };
1090
+ }).build();
1091
+ var pathNormalize = core.toolBuilder().name("path-normalize").description('Normalize a path by resolving ".." and "." segments and removing duplicate separators.').category(core.ToolCategory.FILE_SYSTEM).tags(["path", "normalize", "filesystem"]).schema(zod.z.object({
1092
+ path: zod.z.string().describe("Path to normalize")
1093
+ })).implement(async (input) => {
1094
+ const normalized = path3__namespace.normalize(input.path);
1095
+ return {
1096
+ normalized,
1097
+ original: input.path
1098
+ };
1099
+ }).build();
1100
+ var currentDateTime = core.toolBuilder().name("current-date-time").description("Get the current date and time in various formats (ISO, Unix timestamp, formatted string).").category(core.ToolCategory.UTILITY).tags(["date", "time", "now", "current"]).schema(zod.z.object({
1101
+ format: zod.z.enum(["iso", "unix", "custom"]).default("iso").describe("Output format"),
1102
+ customFormat: zod.z.string().optional().describe('Custom format string (e.g., "yyyy-MM-dd HH:mm:ss") when format is "custom"'),
1103
+ timezone: zod.z.string().optional().describe('Timezone (e.g., "America/New_York")')
1104
+ })).implement(async (input) => {
1105
+ const now = /* @__PURE__ */ new Date();
1106
+ let formatted;
1107
+ if (input.format === "iso") {
1108
+ formatted = now.toISOString();
1109
+ } else if (input.format === "unix") {
1110
+ formatted = Math.floor(now.getTime() / 1e3);
1111
+ } else if (input.format === "custom" && input.customFormat) {
1112
+ formatted = dateFns.format(now, input.customFormat);
1113
+ } else {
1114
+ formatted = now.toISOString();
1115
+ }
1116
+ return {
1117
+ formatted,
1118
+ iso: now.toISOString(),
1119
+ unix: Math.floor(now.getTime() / 1e3),
1120
+ year: now.getFullYear(),
1121
+ month: now.getMonth() + 1,
1122
+ day: now.getDate(),
1123
+ hour: now.getHours(),
1124
+ minute: now.getMinutes(),
1125
+ second: now.getSeconds()
1126
+ };
1127
+ }).build();
1128
+ var dateFormatter = core.toolBuilder().name("date-formatter").description("Format a date string or timestamp into a different format. Supports ISO, Unix timestamps, and custom formats.").category(core.ToolCategory.UTILITY).tags(["date", "format", "time"]).schema(zod.z.object({
1129
+ date: zod.z.string().describe("Date string or Unix timestamp to format"),
1130
+ outputFormat: zod.z.string().describe('Output format string (e.g., "yyyy-MM-dd", "MMM dd, yyyy")'),
1131
+ inputFormat: zod.z.string().optional().describe("Input format string (optional, auto-detected if not provided)")
1132
+ })).implement(async (input) => {
1133
+ try {
1134
+ let date;
1135
+ if (input.inputFormat) {
1136
+ date = dateFns.parse(input.date, input.inputFormat, /* @__PURE__ */ new Date());
1137
+ } else if (!isNaN(Number(input.date))) {
1138
+ date = new Date(Number(input.date) * 1e3);
1139
+ } else {
1140
+ date = new Date(input.date);
1141
+ }
1142
+ if (!dateFns.isValid(date)) {
1143
+ return {
1144
+ success: false,
1145
+ error: "Invalid date"
1146
+ };
1147
+ }
1148
+ const formatted = dateFns.format(date, input.outputFormat);
1149
+ return {
1150
+ success: true,
1151
+ formatted,
1152
+ iso: date.toISOString()
1153
+ };
1154
+ } catch (error) {
1155
+ return {
1156
+ success: false,
1157
+ error: error instanceof Error ? error.message : "Failed to format date"
1158
+ };
1159
+ }
1160
+ }).build();
1161
+ var dateArithmetic = core.toolBuilder().name("date-arithmetic").description("Add or subtract time from a date. Supports years, months, weeks, days, hours, minutes, and seconds.").category(core.ToolCategory.UTILITY).tags(["date", "time", "add", "subtract", "arithmetic"]).schema(zod.z.object({
1162
+ date: zod.z.string().describe("Starting date (ISO string or Unix timestamp)"),
1163
+ operation: zod.z.enum(["add", "subtract"]).describe("Operation to perform"),
1164
+ amount: zod.z.number().describe("Amount to add or subtract"),
1165
+ unit: zod.z.enum(["years", "months", "weeks", "days", "hours", "minutes", "seconds"]).describe("Time unit")
1166
+ })).implement(async (input) => {
1167
+ try {
1168
+ const date = new Date(input.date);
1169
+ if (!dateFns.isValid(date)) {
1170
+ return {
1171
+ success: false,
1172
+ error: "Invalid date"
1173
+ };
1174
+ }
1175
+ const duration = { [input.unit]: input.amount };
1176
+ const result = input.operation === "add" ? dateFns.add(date, duration) : dateFns.sub(date, duration);
1177
+ return {
1178
+ success: true,
1179
+ result: result.toISOString(),
1180
+ unix: Math.floor(result.getTime() / 1e3)
1181
+ };
1182
+ } catch (error) {
1183
+ return {
1184
+ success: false,
1185
+ error: error instanceof Error ? error.message : "Failed to perform date arithmetic"
1186
+ };
1187
+ }
1188
+ }).build();
1189
+ var dateDifference = core.toolBuilder().name("date-difference").description("Calculate the difference between two dates in various units (days, hours, minutes).").category(core.ToolCategory.UTILITY).tags(["date", "time", "difference", "duration"]).schema(zod.z.object({
1190
+ startDate: zod.z.string().describe("Start date (ISO string or Unix timestamp)"),
1191
+ endDate: zod.z.string().describe("End date (ISO string or Unix timestamp)"),
1192
+ unit: zod.z.enum(["days", "hours", "minutes"]).default("days").describe("Unit for the difference")
1193
+ })).implement(async (input) => {
1194
+ try {
1195
+ const start = new Date(input.startDate);
1196
+ const end = new Date(input.endDate);
1197
+ if (!dateFns.isValid(start) || !dateFns.isValid(end)) {
1198
+ return {
1199
+ success: false,
1200
+ error: "Invalid date(s)"
1201
+ };
1202
+ }
1203
+ let difference;
1204
+ if (input.unit === "days") {
1205
+ difference = dateFns.differenceInDays(end, start);
1206
+ } else if (input.unit === "hours") {
1207
+ difference = dateFns.differenceInHours(end, start);
1208
+ } else {
1209
+ difference = dateFns.differenceInMinutes(end, start);
1210
+ }
1211
+ return {
1212
+ success: true,
1213
+ difference,
1214
+ unit: input.unit,
1215
+ startDate: start.toISOString(),
1216
+ endDate: end.toISOString()
1217
+ };
1218
+ } catch (error) {
1219
+ return {
1220
+ success: false,
1221
+ error: error instanceof Error ? error.message : "Failed to calculate date difference"
1222
+ };
1223
+ }
1224
+ }).build();
1225
+ var dateComparison = core.toolBuilder().name("date-comparison").description("Compare two dates to determine if one is before, after, or equal to the other.").category(core.ToolCategory.UTILITY).tags(["date", "time", "compare", "comparison"]).schema(zod.z.object({
1226
+ date1: zod.z.string().describe("First date to compare"),
1227
+ date2: zod.z.string().describe("Second date to compare")
1228
+ })).implement(async (input) => {
1229
+ try {
1230
+ const d1 = new Date(input.date1);
1231
+ const d2 = new Date(input.date2);
1232
+ if (!dateFns.isValid(d1) || !dateFns.isValid(d2)) {
1233
+ return {
1234
+ success: false,
1235
+ error: "Invalid date(s)"
1236
+ };
1237
+ }
1238
+ return {
1239
+ success: true,
1240
+ date1IsBefore: dateFns.isBefore(d1, d2),
1241
+ date1IsAfter: dateFns.isAfter(d1, d2),
1242
+ datesAreEqual: d1.getTime() === d2.getTime(),
1243
+ date1: d1.toISOString(),
1244
+ date2: d2.toISOString()
1245
+ };
1246
+ } catch (error) {
1247
+ return {
1248
+ success: false,
1249
+ error: error instanceof Error ? error.message : "Failed to compare dates"
1250
+ };
1251
+ }
1252
+ }).build();
1253
+ var stringCaseConverter = core.toolBuilder().name("string-case-converter").description("Convert string to different cases: lowercase, uppercase, title case, camel case, snake case, kebab case.").category(core.ToolCategory.UTILITY).tags(["string", "case", "convert", "transform"]).schema(zod.z.object({
1254
+ text: zod.z.string().describe("Text to convert"),
1255
+ targetCase: zod.z.enum(["lowercase", "uppercase", "title", "camel", "snake", "kebab", "pascal"]).describe("Target case format")
1256
+ })).implement(async (input) => {
1257
+ let result;
1258
+ switch (input.targetCase) {
1259
+ case "lowercase":
1260
+ result = input.text.toLowerCase();
1261
+ break;
1262
+ case "uppercase":
1263
+ result = input.text.toUpperCase();
1264
+ break;
1265
+ case "title":
1266
+ result = input.text.toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
1267
+ break;
1268
+ case "camel":
1269
+ result = input.text.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase());
1270
+ break;
1271
+ case "snake":
1272
+ result = input.text.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
1273
+ break;
1274
+ case "kebab":
1275
+ result = input.text.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
1276
+ break;
1277
+ case "pascal":
1278
+ result = input.text.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()).replace(/^./, (char) => char.toUpperCase());
1279
+ break;
1280
+ default:
1281
+ result = input.text;
1282
+ }
1283
+ return {
1284
+ original: input.text,
1285
+ converted: result,
1286
+ targetCase: input.targetCase
1287
+ };
1288
+ }).build();
1289
+ var stringTrim = core.toolBuilder().name("string-trim").description("Remove whitespace from the beginning and/or end of a string. Supports trim, trim start, and trim end.").category(core.ToolCategory.UTILITY).tags(["string", "trim", "whitespace"]).schema(zod.z.object({
1290
+ text: zod.z.string().describe("Text to trim"),
1291
+ mode: zod.z.enum(["both", "start", "end"]).default("both").describe("Which side to trim"),
1292
+ characters: zod.z.string().optional().describe("Optional custom characters to trim (default: whitespace)")
1293
+ })).implement(async (input) => {
1294
+ let result;
1295
+ if (input.characters) {
1296
+ const chars = input.characters.split("").map((c) => c.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("");
1297
+ const regex = input.mode === "both" ? new RegExp(`^[${chars}]+|[${chars}]+$`, "g") : input.mode === "start" ? new RegExp(`^[${chars}]+`, "g") : new RegExp(`[${chars}]+$`, "g");
1298
+ result = input.text.replace(regex, "");
1299
+ } else {
1300
+ result = input.mode === "both" ? input.text.trim() : input.mode === "start" ? input.text.trimStart() : input.text.trimEnd();
1301
+ }
1302
+ return {
1303
+ original: input.text,
1304
+ trimmed: result,
1305
+ removed: input.text.length - result.length
1306
+ };
1307
+ }).build();
1308
+ var stringReplace = core.toolBuilder().name("string-replace").description("Replace occurrences of a substring or pattern in a string. Supports regex patterns and global replacement.").category(core.ToolCategory.UTILITY).tags(["string", "replace", "substitute"]).schema(zod.z.object({
1309
+ text: zod.z.string().describe("Text to search in"),
1310
+ search: zod.z.string().describe("String or regex pattern to search for"),
1311
+ replace: zod.z.string().describe("Replacement string"),
1312
+ global: zod.z.boolean().default(true).describe("Replace all occurrences (true) or just the first (false)"),
1313
+ caseInsensitive: zod.z.boolean().default(false).describe("Case-insensitive search")
1314
+ })).implement(async (input) => {
1315
+ const flags = (input.global ? "g" : "") + (input.caseInsensitive ? "i" : "");
1316
+ const regex = new RegExp(input.search, flags);
1317
+ const result = input.text.replace(regex, input.replace);
1318
+ const matches = input.text.match(regex);
1319
+ const count = matches ? matches.length : 0;
1320
+ return {
1321
+ original: input.text,
1322
+ result,
1323
+ replacements: count
1324
+ };
1325
+ }).build();
1326
+ var stringSplit = core.toolBuilder().name("string-split").description("Split a string into an array of substrings using a delimiter. Supports regex delimiters and limit.").category(core.ToolCategory.UTILITY).tags(["string", "split", "array"]).schema(zod.z.object({
1327
+ text: zod.z.string().describe("Text to split"),
1328
+ delimiter: zod.z.string().describe("Delimiter to split on (can be a regex pattern)"),
1329
+ limit: zod.z.number().optional().describe("Maximum number of splits")
1330
+ })).implement(async (input) => {
1331
+ const parts = input.text.split(input.delimiter, input.limit);
1332
+ return {
1333
+ parts,
1334
+ count: parts.length
1335
+ };
1336
+ }).build();
1337
+ var stringJoin = core.toolBuilder().name("string-join").description("Join an array of strings into a single string with a separator.").category(core.ToolCategory.UTILITY).tags(["string", "join", "array"]).schema(zod.z.object({
1338
+ parts: zod.z.array(zod.z.string().describe("String value")).describe("Array of strings to join"),
1339
+ separator: zod.z.string().default("").describe("Separator to use between parts")
1340
+ })).implement(async (input) => {
1341
+ const result = input.parts.join(input.separator);
1342
+ return {
1343
+ result,
1344
+ partCount: input.parts.length,
1345
+ length: result.length
1346
+ };
1347
+ }).build();
1348
+ var stringSubstring = core.toolBuilder().name("string-substring").description("Extract a substring from a string using start and end positions.").category(core.ToolCategory.UTILITY).tags(["string", "substring", "slice"]).schema(zod.z.object({
1349
+ text: zod.z.string().describe("Source text"),
1350
+ start: zod.z.number().describe("Start position (0-based)"),
1351
+ end: zod.z.number().optional().describe("End position (optional, defaults to end of string)")
1352
+ })).implement(async (input) => {
1353
+ const result = input.text.substring(input.start, input.end);
1354
+ return {
1355
+ result,
1356
+ length: result.length,
1357
+ start: input.start,
1358
+ end: input.end ?? input.text.length
1359
+ };
1360
+ }).build();
1361
+ var stringLength = core.toolBuilder().name("string-length").description("Get the length of a string in characters, words, or lines.").category(core.ToolCategory.UTILITY).tags(["string", "length", "count"]).schema(zod.z.object({
1362
+ text: zod.z.string().describe("Text to measure")
1363
+ })).implement(async (input) => {
1364
+ const words = input.text.trim().split(/\s+/).filter((w) => w.length > 0);
1365
+ const lines = input.text.split("\n");
1366
+ return {
1367
+ characters: input.text.length,
1368
+ words: words.length,
1369
+ lines: lines.length
1370
+ };
1371
+ }).build();
1372
+ var calculator = core.toolBuilder().name("calculator").description("Perform basic arithmetic operations: add, subtract, multiply, divide, power, modulo.").category(core.ToolCategory.UTILITY).tags(["math", "calculator", "arithmetic"]).schema(zod.z.object({
1373
+ operation: zod.z.enum(["add", "subtract", "multiply", "divide", "power", "modulo"]).describe("Mathematical operation to perform"),
1374
+ a: zod.z.number().describe("First number"),
1375
+ b: zod.z.number().describe("Second number")
1376
+ })).implement(async (input) => {
1377
+ let result;
1378
+ switch (input.operation) {
1379
+ case "add":
1380
+ result = input.a + input.b;
1381
+ break;
1382
+ case "subtract":
1383
+ result = input.a - input.b;
1384
+ break;
1385
+ case "multiply":
1386
+ result = input.a * input.b;
1387
+ break;
1388
+ case "divide":
1389
+ if (input.b === 0) {
1390
+ return {
1391
+ success: false,
1392
+ error: "Division by zero"
1393
+ };
1394
+ }
1395
+ result = input.a / input.b;
1396
+ break;
1397
+ case "power":
1398
+ result = Math.pow(input.a, input.b);
1399
+ break;
1400
+ case "modulo":
1401
+ result = input.a % input.b;
1402
+ break;
1403
+ default:
1404
+ return {
1405
+ success: false,
1406
+ error: "Unknown operation"
1407
+ };
1408
+ }
1409
+ return {
1410
+ success: true,
1411
+ result,
1412
+ operation: input.operation,
1413
+ a: input.a,
1414
+ b: input.b
1415
+ };
1416
+ }).build();
1417
+ var mathFunctions = core.toolBuilder().name("math-functions").description("Apply mathematical functions: sqrt, abs, round, floor, ceil, sin, cos, tan, log, exp.").category(core.ToolCategory.UTILITY).tags(["math", "functions", "trigonometry"]).schema(zod.z.object({
1418
+ function: zod.z.enum(["sqrt", "abs", "round", "floor", "ceil", "sin", "cos", "tan", "log", "exp"]).describe("Mathematical function to apply"),
1419
+ value: zod.z.number().describe("Input value")
1420
+ })).implement(async (input) => {
1421
+ let result;
1422
+ try {
1423
+ switch (input.function) {
1424
+ case "sqrt":
1425
+ result = Math.sqrt(input.value);
1426
+ break;
1427
+ case "abs":
1428
+ result = Math.abs(input.value);
1429
+ break;
1430
+ case "round":
1431
+ result = Math.round(input.value);
1432
+ break;
1433
+ case "floor":
1434
+ result = Math.floor(input.value);
1435
+ break;
1436
+ case "ceil":
1437
+ result = Math.ceil(input.value);
1438
+ break;
1439
+ case "sin":
1440
+ result = Math.sin(input.value);
1441
+ break;
1442
+ case "cos":
1443
+ result = Math.cos(input.value);
1444
+ break;
1445
+ case "tan":
1446
+ result = Math.tan(input.value);
1447
+ break;
1448
+ case "log":
1449
+ result = Math.log(input.value);
1450
+ break;
1451
+ case "exp":
1452
+ result = Math.exp(input.value);
1453
+ break;
1454
+ default:
1455
+ return {
1456
+ success: false,
1457
+ error: "Unknown function"
1458
+ };
1459
+ }
1460
+ if (isNaN(result) || !isFinite(result)) {
1461
+ return {
1462
+ success: false,
1463
+ error: "Invalid result (NaN or Infinity)"
1464
+ };
1465
+ }
1466
+ return {
1467
+ success: true,
1468
+ result,
1469
+ function: input.function,
1470
+ input: input.value
1471
+ };
1472
+ } catch (error) {
1473
+ return {
1474
+ success: false,
1475
+ error: error instanceof Error ? error.message : "Math operation failed"
1476
+ };
1477
+ }
1478
+ }).build();
1479
+ var randomNumber = core.toolBuilder().name("random-number").description("Generate a random number within a specified range. Supports integers and decimals.").category(core.ToolCategory.UTILITY).tags(["random", "number", "generator"]).schema(zod.z.object({
1480
+ min: zod.z.number().default(0).describe("Minimum value (inclusive)"),
1481
+ max: zod.z.number().default(1).describe("Maximum value (exclusive for decimals, inclusive for integers)"),
1482
+ integer: zod.z.boolean().default(false).describe("Generate an integer (true) or decimal (false)")
1483
+ })).implement(async (input) => {
1484
+ const min = input.min ?? 0;
1485
+ const max = input.max ?? 1;
1486
+ const integer = input.integer ?? false;
1487
+ let result;
1488
+ if (integer) {
1489
+ result = Math.floor(Math.random() * (max - min + 1)) + min;
1490
+ } else {
1491
+ result = Math.random() * (max - min) + min;
1492
+ }
1493
+ return {
1494
+ result,
1495
+ min,
1496
+ max,
1497
+ integer
1498
+ };
1499
+ }).build();
1500
+ var statistics = core.toolBuilder().name("statistics").description("Calculate statistics for an array of numbers: sum, average, min, max, median, standard deviation.").category(core.ToolCategory.UTILITY).tags(["math", "statistics", "average", "sum"]).schema(zod.z.object({
1501
+ numbers: zod.z.array(zod.z.number().describe("Number value")).describe("Array of numbers to analyze")
1502
+ })).implement(async (input) => {
1503
+ if (input.numbers.length === 0) {
1504
+ return {
1505
+ success: false,
1506
+ error: "Empty array"
1507
+ };
1508
+ }
1509
+ const sorted = [...input.numbers].sort((a, b) => a - b);
1510
+ const sum = input.numbers.reduce((acc, n) => acc + n, 0);
1511
+ const average = sum / input.numbers.length;
1512
+ const min = sorted[0];
1513
+ const max = sorted[sorted.length - 1];
1514
+ const mid = Math.floor(sorted.length / 2);
1515
+ const median = sorted.length % 2 === 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
1516
+ const variance = input.numbers.reduce((acc, n) => acc + Math.pow(n - average, 2), 0) / input.numbers.length;
1517
+ const stdDev = Math.sqrt(variance);
1518
+ return {
1519
+ success: true,
1520
+ count: input.numbers.length,
1521
+ sum,
1522
+ average,
1523
+ min,
1524
+ max,
1525
+ median,
1526
+ standardDeviation: stdDev,
1527
+ variance
1528
+ };
1529
+ }).build();
1530
+ var emailValidator = core.toolBuilder().name("email-validator").description("Validate if a string is a valid email address format.").category(core.ToolCategory.UTILITY).tags(["validation", "email", "validate"]).schema(zod.z.object({
1531
+ email: zod.z.string().describe("Email address to validate")
1532
+ })).implement(async (input) => {
1533
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1534
+ const valid = emailRegex.test(input.email);
1535
+ return {
1536
+ valid,
1537
+ email: input.email,
1538
+ message: valid ? "Valid email address" : "Invalid email address format"
1539
+ };
1540
+ }).build();
1541
+ var urlValidatorSimple = core.toolBuilder().name("url-validator-simple").description("Validate if a string is a valid URL format.").category(core.ToolCategory.UTILITY).tags(["validation", "url", "validate"]).schema(zod.z.object({
1542
+ url: zod.z.string().describe("URL to validate")
1543
+ })).implement(async (input) => {
1544
+ try {
1545
+ new URL(input.url);
1546
+ return {
1547
+ valid: true,
1548
+ url: input.url,
1549
+ message: "Valid URL"
1550
+ };
1551
+ } catch {
1552
+ return {
1553
+ valid: false,
1554
+ url: input.url,
1555
+ message: "Invalid URL format"
1556
+ };
1557
+ }
1558
+ }).build();
1559
+ var phoneValidator = core.toolBuilder().name("phone-validator").description("Validate if a string is a valid phone number format. Supports various international formats.").category(core.ToolCategory.UTILITY).tags(["validation", "phone", "validate"]).schema(zod.z.object({
1560
+ phone: zod.z.string().describe("Phone number to validate"),
1561
+ strict: zod.z.boolean().default(false).describe("Use strict validation (requires country code)")
1562
+ })).implement(async (input) => {
1563
+ const basicRegex = /^[\d\s\-\+\(\)]+$/;
1564
+ const strictRegex = /^\+?[1-9]\d{1,14}$/;
1565
+ const regex = input.strict ? strictRegex : basicRegex;
1566
+ const valid = regex.test(input.phone.replace(/\s/g, ""));
1567
+ return {
1568
+ valid,
1569
+ phone: input.phone,
1570
+ message: valid ? "Valid phone number format" : "Invalid phone number format"
1571
+ };
1572
+ }).build();
1573
+ var creditCardValidator = core.toolBuilder().name("credit-card-validator").description("Validate if a string is a valid credit card number using the Luhn algorithm.").category(core.ToolCategory.UTILITY).tags(["validation", "credit-card", "validate", "luhn"]).schema(zod.z.object({
1574
+ cardNumber: zod.z.string().describe("Credit card number to validate")
1575
+ })).implement(async (input) => {
1576
+ const cleaned = input.cardNumber.replace(/[\s\-]/g, "");
1577
+ if (!/^\d+$/.test(cleaned)) {
1578
+ return {
1579
+ valid: false,
1580
+ message: "Card number must contain only digits"
1581
+ };
1582
+ }
1583
+ let sum = 0;
1584
+ let isEven = false;
1585
+ for (let i = cleaned.length - 1; i >= 0; i--) {
1586
+ let digit = parseInt(cleaned[i], 10);
1587
+ if (isEven) {
1588
+ digit *= 2;
1589
+ if (digit > 9) {
1590
+ digit -= 9;
1591
+ }
1592
+ }
1593
+ sum += digit;
1594
+ isEven = !isEven;
1595
+ }
1596
+ const valid = sum % 10 === 0;
1597
+ return {
1598
+ valid,
1599
+ cardNumber: input.cardNumber,
1600
+ message: valid ? "Valid credit card number" : "Invalid credit card number (failed Luhn check)"
1601
+ };
1602
+ }).build();
1603
+ var ipValidator = core.toolBuilder().name("ip-validator").description("Validate if a string is a valid IPv4 or IPv6 address.").category(core.ToolCategory.UTILITY).tags(["validation", "ip", "validate", "network"]).schema(zod.z.object({
1604
+ ip: zod.z.string().describe("IP address to validate"),
1605
+ version: zod.z.enum(["v4", "v6", "any"]).default("any").describe("IP version to validate against")
1606
+ })).implement(async (input) => {
1607
+ const ipv4Regex = /^(\d{1,3}\.){3}\d{1,3}$/;
1608
+ const ipv6Regex = /^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
1609
+ let valid = false;
1610
+ let detectedVersion;
1611
+ if (input.version === "v4" || input.version === "any") {
1612
+ if (ipv4Regex.test(input.ip)) {
1613
+ const parts = input.ip.split(".");
1614
+ valid = parts.every((part) => {
1615
+ const num = parseInt(part, 10);
1616
+ return num >= 0 && num <= 255;
1617
+ });
1618
+ if (valid) detectedVersion = "IPv4";
1619
+ }
1620
+ }
1621
+ if (!valid && (input.version === "v6" || input.version === "any")) {
1622
+ if (ipv6Regex.test(input.ip)) {
1623
+ valid = true;
1624
+ detectedVersion = "IPv6";
1625
+ }
1626
+ }
1627
+ return {
1628
+ valid,
1629
+ ip: input.ip,
1630
+ version: detectedVersion,
1631
+ message: valid ? `Valid ${detectedVersion} address` : "Invalid IP address format"
1632
+ };
1633
+ }).build();
1634
+ var uuidValidator = core.toolBuilder().name("uuid-validator").description("Validate if a string is a valid UUID (v1, v3, v4, or v5).").category(core.ToolCategory.UTILITY).tags(["validation", "uuid", "validate", "guid"]).schema(zod.z.object({
1635
+ uuid: zod.z.string().describe("UUID to validate")
1636
+ })).implement(async (input) => {
1637
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1638
+ const valid = uuidRegex.test(input.uuid);
1639
+ let version;
1640
+ if (valid) {
1641
+ version = parseInt(input.uuid[14], 10);
1642
+ }
1643
+ return {
1644
+ valid,
1645
+ uuid: input.uuid,
1646
+ version,
1647
+ message: valid ? `Valid UUID v${version}` : "Invalid UUID format"
1648
+ };
1649
+ }).build();
1650
+
1651
+ exports.arrayFilter = arrayFilter;
1652
+ exports.arrayGroupBy = arrayGroupBy;
1653
+ exports.arrayMap = arrayMap;
1654
+ exports.arraySort = arraySort;
1655
+ exports.calculator = calculator;
1656
+ exports.creditCardValidator = creditCardValidator;
1657
+ exports.csvGenerator = csvGenerator;
1658
+ exports.csvParser = csvParser;
1659
+ exports.csvToJson = csvToJson;
1660
+ exports.currentDateTime = currentDateTime;
1661
+ exports.dateArithmetic = dateArithmetic;
1662
+ exports.dateComparison = dateComparison;
1663
+ exports.dateDifference = dateDifference;
1664
+ exports.dateFormatter = dateFormatter;
1665
+ exports.directoryCreate = directoryCreate;
1666
+ exports.directoryDelete = directoryDelete;
1667
+ exports.directoryList = directoryList;
1668
+ exports.emailValidator = emailValidator;
1669
+ exports.extractImages = extractImages;
1670
+ exports.extractLinks = extractLinks;
1671
+ exports.fileAppend = fileAppend;
1672
+ exports.fileDelete = fileDelete;
1673
+ exports.fileExists = fileExists;
1674
+ exports.fileReader = fileReader;
1675
+ exports.fileSearch = fileSearch;
1676
+ exports.fileWriter = fileWriter;
1677
+ exports.htmlParser = htmlParser;
1678
+ exports.httpClient = httpClient;
1679
+ exports.httpGet = httpGet;
1680
+ exports.httpPost = httpPost;
1681
+ exports.ipValidator = ipValidator;
1682
+ exports.jsonMerge = jsonMerge;
1683
+ exports.jsonParser = jsonParser;
1684
+ exports.jsonQuery = jsonQuery;
1685
+ exports.jsonStringify = jsonStringify;
1686
+ exports.jsonToCsv = jsonToCsv;
1687
+ exports.jsonToXml = jsonToXml;
1688
+ exports.jsonValidator = jsonValidator;
1689
+ exports.mathFunctions = mathFunctions;
1690
+ exports.objectOmit = objectOmit;
1691
+ exports.objectPick = objectPick;
1692
+ exports.pathBasename = pathBasename;
1693
+ exports.pathDirname = pathDirname;
1694
+ exports.pathExtension = pathExtension;
1695
+ exports.pathJoin = pathJoin;
1696
+ exports.pathNormalize = pathNormalize;
1697
+ exports.pathParse = pathParse;
1698
+ exports.pathRelative = pathRelative;
1699
+ exports.pathResolve = pathResolve;
1700
+ exports.phoneValidator = phoneValidator;
1701
+ exports.randomNumber = randomNumber;
1702
+ exports.statistics = statistics;
1703
+ exports.stringCaseConverter = stringCaseConverter;
1704
+ exports.stringJoin = stringJoin;
1705
+ exports.stringLength = stringLength;
1706
+ exports.stringReplace = stringReplace;
1707
+ exports.stringSplit = stringSplit;
1708
+ exports.stringSubstring = stringSubstring;
1709
+ exports.stringTrim = stringTrim;
1710
+ exports.urlBuilder = urlBuilder;
1711
+ exports.urlQueryParser = urlQueryParser;
1712
+ exports.urlValidator = urlValidator;
1713
+ exports.urlValidatorSimple = urlValidatorSimple;
1714
+ exports.uuidValidator = uuidValidator;
1715
+ exports.webScraper = webScraper;
1716
+ exports.xmlGenerator = xmlGenerator;
1717
+ exports.xmlParser = xmlParser;
1718
+ exports.xmlToJson = xmlToJson;
1719
+ //# sourceMappingURL=index.cjs.map
1720
+ //# sourceMappingURL=index.cjs.map