toolwire 0.1.1

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,719 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // node_modules/tsup/assets/cjs_shims.js
34
+ var getImportMetaUrl, importMetaUrl;
35
+ var init_cjs_shims = __esm({
36
+ "node_modules/tsup/assets/cjs_shims.js"() {
37
+ "use strict";
38
+ getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
39
+ importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+ }
41
+ });
42
+
43
+ // src/schema.ts
44
+ function resolveJsonSchema(schema) {
45
+ const hit = cache.get(schema);
46
+ if (hit !== void 0) return hit;
47
+ const result = compute(schema);
48
+ cache.set(schema, result);
49
+ return result;
50
+ }
51
+ function compute(schema) {
52
+ const toJSONSchemaV4 = zodNs["toJSONSchema"];
53
+ if (typeof toJSONSchemaV4 === "function") {
54
+ const { $schema: _$schema, ...clean } = toJSONSchemaV4(schema);
55
+ return clean;
56
+ }
57
+ try {
58
+ const pkg = _require("zod-to-json-schema");
59
+ const { $schema: _$schema, ...clean } = pkg.zodToJsonSchema(schema, {
60
+ $refStrategy: "none"
61
+ });
62
+ return clean;
63
+ } catch {
64
+ throw new Error(
65
+ "toolwire: Cannot convert Zod schema to JSON Schema.\n \u2022 Zod v4: ensure zod@^4.0.0 is installed.\n \u2022 Zod v3: run `npm install zod-to-json-schema`.\n \u2022 Or supply a pre-computed schema via the `_jsonSchema` option in tool()."
66
+ );
67
+ }
68
+ }
69
+ var import_node_module, zodNs, _require, cache;
70
+ var init_schema = __esm({
71
+ "src/schema.ts"() {
72
+ "use strict";
73
+ init_cjs_shims();
74
+ import_node_module = require("module");
75
+ zodNs = __toESM(require("zod"), 1);
76
+ _require = (0, import_node_module.createRequire)(importMetaUrl);
77
+ cache = /* @__PURE__ */ new WeakMap();
78
+ }
79
+ });
80
+
81
+ // src/tool.ts
82
+ function tool(config) {
83
+ if (!NAME_RE.test(config.name)) {
84
+ throw new Error(
85
+ `toolwire: Invalid tool name "${config.name}". Names must be 1\u201364 characters containing only letters, digits, underscores, or hyphens.`
86
+ );
87
+ }
88
+ const inputSchema = config._jsonSchema ?? resolveJsonSchema(config.input);
89
+ const outputSchema = config.output ? resolveJsonSchema(config.output) : void 0;
90
+ const def = {
91
+ name: config.name,
92
+ description: config.description,
93
+ input: config.input,
94
+ output: config.output,
95
+ handler: config.handler,
96
+ timeout: config.timeout ?? DEFAULTS.timeout,
97
+ retries: config.retries ?? DEFAULTS.retries,
98
+ annotations: config.annotations ?? {},
99
+ inputSchema,
100
+ outputSchema
101
+ };
102
+ return Object.freeze(def);
103
+ }
104
+ var NAME_RE, DEFAULTS;
105
+ var init_tool = __esm({
106
+ "src/tool.ts"() {
107
+ "use strict";
108
+ init_cjs_shims();
109
+ init_schema();
110
+ NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
111
+ DEFAULTS = {
112
+ timeout: 3e4,
113
+ retries: 0
114
+ };
115
+ }
116
+ });
117
+
118
+ // src/errors.ts
119
+ function err(code, toolName, message, llmMessage, retryable, extras) {
120
+ return { code, toolName, message, llmMessage, retryable, ...extras };
121
+ }
122
+ function makeNotFoundError(toolName, available) {
123
+ const list = available.length > 0 ? `Available tools: ${available.join(", ")}.` : "No tools are currently registered.";
124
+ return err(
125
+ "NOT_FOUND",
126
+ toolName,
127
+ `Tool "${toolName}" is not registered`,
128
+ `The tool "${toolName}" does not exist. ${list} Please use one of the available tools.`,
129
+ true
130
+ );
131
+ }
132
+ function makeDisabledError(toolName) {
133
+ return err(
134
+ "DISABLED",
135
+ toolName,
136
+ `Tool "${toolName}" is currently disabled`,
137
+ `The tool "${toolName}" is currently disabled and cannot be called. Please try a different approach or wait until it is re-enabled.`,
138
+ false
139
+ );
140
+ }
141
+ function makeValidationInputError(toolName, issues) {
142
+ const lines = issues.map((i) => ` - ${i.path.length > 0 ? i.path.join(".") : "(root)"}: ${i.message}`).join("\n");
143
+ return err(
144
+ "VALIDATION_INPUT",
145
+ toolName,
146
+ `Invalid input for tool "${toolName}"`,
147
+ `Your call to "${toolName}" had invalid arguments:
148
+ ${lines}
149
+
150
+ Please fix these and try again.`,
151
+ true,
152
+ { issues }
153
+ );
154
+ }
155
+ function makeValidationOutputError(toolName, issues) {
156
+ return err(
157
+ "VALIDATION_OUTPUT",
158
+ toolName,
159
+ `Tool "${toolName}" returned an invalid response format`,
160
+ `The tool "${toolName}" returned an unexpected response and could not be used. This is a bug in the tool implementation, not in your call. Please try a different approach.`,
161
+ false,
162
+ { issues }
163
+ );
164
+ }
165
+ function makeTimeoutError(toolName, timeoutMs) {
166
+ return err(
167
+ "TIMEOUT",
168
+ toolName,
169
+ `Tool "${toolName}" timed out after ${timeoutMs}ms`,
170
+ `The tool "${toolName}" timed out after ${timeoutMs}ms. This may be a temporary issue \u2014 please wait a moment before retrying.`,
171
+ true,
172
+ { retryAfterMs: Math.min(timeoutMs, 5e3) }
173
+ );
174
+ }
175
+ function makeExecutionError(toolName, cause, attempts) {
176
+ const msg = cause instanceof Error ? cause.message : String(cause);
177
+ const attemptStr = attempts > 1 ? ` after ${attempts} attempt(s)` : "";
178
+ return err(
179
+ "EXECUTION",
180
+ toolName,
181
+ `Tool "${toolName}" failed${attemptStr}: ${msg}`,
182
+ `The tool "${toolName}" encountered an error${attemptStr}: ${msg}. All retries have been exhausted \u2014 please try a different approach.`,
183
+ false,
184
+ { cause }
185
+ );
186
+ }
187
+ function makeFailure(toolName, error, durationMs) {
188
+ return { success: false, toolName, error, durationMs };
189
+ }
190
+ var init_errors = __esm({
191
+ "src/errors.ts"() {
192
+ "use strict";
193
+ init_cjs_shims();
194
+ }
195
+ });
196
+
197
+ // src/middleware.ts
198
+ async function runBefore(middleware, toolName, args) {
199
+ let current = args;
200
+ for (const mw of middleware) {
201
+ if (mw.beforeCall) {
202
+ const next = await mw.beforeCall(toolName, current);
203
+ if (next !== void 0) current = next;
204
+ }
205
+ }
206
+ return current;
207
+ }
208
+ async function runAfter(middleware, toolName, args, result) {
209
+ let current = result;
210
+ for (let i = middleware.length - 1; i >= 0; i--) {
211
+ const mw = middleware[i];
212
+ if (mw?.afterCall) {
213
+ const next = await mw.afterCall(toolName, args, current);
214
+ if (next !== void 0) current = next;
215
+ }
216
+ }
217
+ return current;
218
+ }
219
+ async function runOnError(middleware, toolName, args, failure) {
220
+ for (const mw of middleware) {
221
+ if (mw.onError) {
222
+ const recovery = await mw.onError(toolName, args, failure);
223
+ if (recovery !== void 0) return recovery;
224
+ }
225
+ }
226
+ return failure;
227
+ }
228
+ var init_middleware = __esm({
229
+ "src/middleware.ts"() {
230
+ "use strict";
231
+ init_cjs_shims();
232
+ }
233
+ });
234
+
235
+ // src/adapters/anthropic.ts
236
+ function toAnthropic(tools) {
237
+ return tools.map((t) => ({
238
+ name: t.name,
239
+ description: t.description,
240
+ input_schema: t.inputSchema
241
+ }));
242
+ }
243
+ var init_anthropic = __esm({
244
+ "src/adapters/anthropic.ts"() {
245
+ "use strict";
246
+ init_cjs_shims();
247
+ }
248
+ });
249
+
250
+ // src/adapters/gemini.ts
251
+ function toGemini(tools) {
252
+ return {
253
+ functionDeclarations: tools.map((t) => ({
254
+ name: t.name,
255
+ description: t.description,
256
+ parametersJsonSchema: t.inputSchema
257
+ }))
258
+ };
259
+ }
260
+ var init_gemini = __esm({
261
+ "src/adapters/gemini.ts"() {
262
+ "use strict";
263
+ init_cjs_shims();
264
+ }
265
+ });
266
+
267
+ // src/adapters/openai.ts
268
+ function toOpenAI(tools, options) {
269
+ return tools.map((t) => {
270
+ const fn = {
271
+ name: t.name,
272
+ description: t.description,
273
+ parameters: t.inputSchema
274
+ };
275
+ if (options?.strict !== void 0) {
276
+ fn.strict = options.strict;
277
+ }
278
+ return { type: "function", function: fn };
279
+ });
280
+ }
281
+ var init_openai = __esm({
282
+ "src/adapters/openai.ts"() {
283
+ "use strict";
284
+ init_cjs_shims();
285
+ }
286
+ });
287
+
288
+ // src/adapters/vercel-ai.ts
289
+ function toVercelAI(tools) {
290
+ return Object.fromEntries(
291
+ tools.map((t) => [
292
+ t.name,
293
+ {
294
+ description: t.description,
295
+ parameters: t.input
296
+ }
297
+ ])
298
+ );
299
+ }
300
+ var init_vercel_ai = __esm({
301
+ "src/adapters/vercel-ai.ts"() {
302
+ "use strict";
303
+ init_cjs_shims();
304
+ }
305
+ });
306
+
307
+ // src/discovery.ts
308
+ var discovery_exports = {};
309
+ __export(discovery_exports, {
310
+ fromDir: () => fromDir,
311
+ fromManifest: () => fromManifest
312
+ });
313
+ async function fromDir(dirPath) {
314
+ const absPath = (0, import_node_path.resolve)(dirPath);
315
+ let files;
316
+ try {
317
+ files = await (0, import_promises.readdir)(absPath);
318
+ } catch (err2) {
319
+ throw new Error(
320
+ `toolwire: Cannot read directory "${absPath}": ${err2 instanceof Error ? err2.message : String(err2)}`
321
+ );
322
+ }
323
+ const toolFiles = files.filter((f) => /\.(js|mjs|cjs)$/.test(f));
324
+ const discovered = [];
325
+ for (const file of toolFiles) {
326
+ const fileUrl = (0, import_node_url.pathToFileURL)((0, import_node_path.join)(absPath, file)).href;
327
+ try {
328
+ const mod = await import(fileUrl);
329
+ discovered.push(...extractTools(mod));
330
+ } catch (err2) {
331
+ console.warn(
332
+ `toolwire: Skipping "${file}" (failed to import):`,
333
+ err2 instanceof Error ? err2.message : err2
334
+ );
335
+ }
336
+ }
337
+ return new ToolRegistry(discovered);
338
+ }
339
+ async function fromManifest(url) {
340
+ let manifest;
341
+ try {
342
+ const response = await fetch(url);
343
+ if (!response.ok) {
344
+ throw new Error(`HTTP ${response.status} ${response.statusText}`);
345
+ }
346
+ manifest = await response.json();
347
+ } catch (err2) {
348
+ throw new Error(
349
+ `toolwire: Failed to fetch manifest from "${url}": ${err2 instanceof Error ? err2.message : String(err2)}`
350
+ );
351
+ }
352
+ if (manifest.version !== "1.0" || !Array.isArray(manifest.tools)) {
353
+ throw new Error(
354
+ 'toolwire: Invalid manifest. Expected { version: "1.0", tools: [...] }'
355
+ );
356
+ }
357
+ const { z } = await import("zod");
358
+ const tools = manifest.tools.map(
359
+ (entry) => tool({
360
+ name: entry.name,
361
+ description: entry.description,
362
+ input: z.record(z.string(), z.unknown()),
363
+ _jsonSchema: entry.inputSchema,
364
+ handler: async (input) => {
365
+ const res = await fetch(entry.endpoint, {
366
+ method: "POST",
367
+ headers: { "Content-Type": "application/json" },
368
+ body: JSON.stringify(input)
369
+ });
370
+ if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);
371
+ return res.json();
372
+ }
373
+ })
374
+ );
375
+ return new ToolRegistry(tools);
376
+ }
377
+ function isToolDefinition(value) {
378
+ return typeof value === "object" && value !== null && typeof value["name"] === "string" && typeof value["description"] === "string" && typeof value["handler"] === "function";
379
+ }
380
+ function extractTools(mod) {
381
+ if (isToolDefinition(mod["default"])) {
382
+ return [mod["default"]];
383
+ }
384
+ if (Array.isArray(mod["tools"])) {
385
+ const found = mod["tools"].filter(isToolDefinition);
386
+ if (found.length > 0) return found;
387
+ }
388
+ return Object.entries(mod).filter(([key]) => key !== "default" && key !== "tools").map(([, value]) => value).filter(isToolDefinition);
389
+ }
390
+ var import_promises, import_node_path, import_node_url;
391
+ var init_discovery = __esm({
392
+ "src/discovery.ts"() {
393
+ "use strict";
394
+ init_cjs_shims();
395
+ import_promises = require("fs/promises");
396
+ import_node_path = require("path");
397
+ import_node_url = require("url");
398
+ init_registry();
399
+ init_tool();
400
+ }
401
+ });
402
+
403
+ // src/registry.ts
404
+ function registry(tools = [], options = {}) {
405
+ return new ToolRegistry(tools, options);
406
+ }
407
+ async function withTimeout(fn, ms, toolName) {
408
+ const controller = new AbortController();
409
+ const timer = setTimeout(() => {
410
+ controller.abort(
411
+ new DOMException(`Tool "${toolName}" timed out after ${ms}ms`, "AbortError")
412
+ );
413
+ }, ms);
414
+ const execution = Promise.resolve().then(() => fn(controller.signal));
415
+ const timeoutRace = new Promise((_, reject) => {
416
+ controller.signal.addEventListener("abort", () => reject(controller.signal.reason), {
417
+ once: true
418
+ });
419
+ });
420
+ try {
421
+ return await Promise.race([execution, timeoutRace]);
422
+ } finally {
423
+ clearTimeout(timer);
424
+ execution.catch(() => void 0);
425
+ }
426
+ }
427
+ function isAbortError(err2) {
428
+ return err2 instanceof Error && (err2.name === "AbortError" || err2 instanceof DOMException && err2.name === "AbortError");
429
+ }
430
+ function sleep(ms) {
431
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
432
+ }
433
+ var ToolRegistry;
434
+ var init_registry = __esm({
435
+ "src/registry.ts"() {
436
+ "use strict";
437
+ init_cjs_shims();
438
+ init_errors();
439
+ init_middleware();
440
+ init_anthropic();
441
+ init_gemini();
442
+ init_openai();
443
+ init_vercel_ai();
444
+ ToolRegistry = class {
445
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
446
+ tools = /* @__PURE__ */ new Map();
447
+ disabledTools = /* @__PURE__ */ new Set();
448
+ _middleware = [];
449
+ options;
450
+ constructor(tools = [], options = {}) {
451
+ this.options = options;
452
+ for (const t of tools) {
453
+ this.tools.set(t.name, t);
454
+ }
455
+ }
456
+ // ---------------------------------------------------------------------------
457
+ // Tool management
458
+ // ---------------------------------------------------------------------------
459
+ /** Add one or more tools. Returns `this` for chaining. */
460
+ register(tools) {
461
+ const list = Array.isArray(tools) ? tools : [tools];
462
+ for (const t of list) this.tools.set(t.name, t);
463
+ return this;
464
+ }
465
+ /**
466
+ * Replace a registered tool in-place (hot-swap).
467
+ * Useful for swapping slow tools with cached versions mid-run.
468
+ */
469
+ swap(name, newTool) {
470
+ if (!this.tools.has(name)) {
471
+ throw new Error(`toolwire: Cannot swap "${name}" \u2014 it is not registered.`);
472
+ }
473
+ this.tools.set(name, newTool);
474
+ return this;
475
+ }
476
+ /** Temporarily prevent a tool from being called. */
477
+ disable(name) {
478
+ if (!this.tools.has(name)) {
479
+ throw new Error(`toolwire: Cannot disable "${name}" \u2014 it is not registered.`);
480
+ }
481
+ this.disabledTools.add(name);
482
+ return this;
483
+ }
484
+ /** Re-enable a previously disabled tool. */
485
+ enable(name) {
486
+ if (!this.tools.has(name)) {
487
+ throw new Error(`toolwire: Cannot enable "${name}" \u2014 it is not registered.`);
488
+ }
489
+ this.disabledTools.delete(name);
490
+ return this;
491
+ }
492
+ /** Add middleware. Returns `this` for chaining. */
493
+ use(middleware) {
494
+ const list = Array.isArray(middleware) ? middleware : [middleware];
495
+ this._middleware.push(...list);
496
+ return this;
497
+ }
498
+ /** Return the names of all registered tools (including disabled ones). */
499
+ list() {
500
+ return [...this.tools.keys()];
501
+ }
502
+ /** Return a tool definition by name, or undefined if not found. */
503
+ get(name) {
504
+ return this.tools.get(name);
505
+ }
506
+ /**
507
+ * Return a human-readable list of enabled tools.
508
+ * Handy for injecting into a system prompt.
509
+ */
510
+ describe() {
511
+ const enabled = [...this.tools.values()].filter(
512
+ (t) => !this.disabledTools.has(t.name)
513
+ );
514
+ if (enabled.length === 0) return "No tools are currently available.";
515
+ return enabled.map((t) => `- ${t.name}: ${t.description}`).join("\n");
516
+ }
517
+ // ---------------------------------------------------------------------------
518
+ // Execution
519
+ // ---------------------------------------------------------------------------
520
+ /**
521
+ * Execute a tool call from an LLM.
522
+ * Always resolves (never throws) — check `result.success` to distinguish outcomes.
523
+ */
524
+ async call(request) {
525
+ const start = Date.now();
526
+ const { name: toolName, arguments: rawArgs } = request;
527
+ const toolDef = this.tools.get(toolName);
528
+ if (!toolDef) {
529
+ return runOnError(
530
+ this._middleware,
531
+ toolName,
532
+ rawArgs,
533
+ makeFailure(toolName, makeNotFoundError(toolName, this.list()), Date.now() - start)
534
+ );
535
+ }
536
+ if (this.disabledTools.has(toolName)) {
537
+ return runOnError(
538
+ this._middleware,
539
+ toolName,
540
+ rawArgs,
541
+ makeFailure(toolName, makeDisabledError(toolName), Date.now() - start)
542
+ );
543
+ }
544
+ const parsed = toolDef.input.safeParse(rawArgs);
545
+ if (!parsed.success) {
546
+ return runOnError(
547
+ this._middleware,
548
+ toolName,
549
+ rawArgs,
550
+ makeFailure(
551
+ toolName,
552
+ makeValidationInputError(toolName, parsed.error.issues),
553
+ Date.now() - start
554
+ )
555
+ );
556
+ }
557
+ let args = parsed.data;
558
+ try {
559
+ args = await runBefore(this._middleware, toolName, args);
560
+ } catch (err2) {
561
+ return runOnError(
562
+ this._middleware,
563
+ toolName,
564
+ rawArgs,
565
+ makeFailure(toolName, makeExecutionError(toolName, err2, 1), Date.now() - start)
566
+ );
567
+ }
568
+ const timeout = toolDef.timeout ?? this.options.defaultTimeout ?? 3e4;
569
+ const maxAttempts = toolDef.retries + 1;
570
+ let lastError;
571
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
572
+ try {
573
+ const data = await withTimeout(
574
+ (signal) => toolDef.handler(args, { signal, attempt }),
575
+ timeout,
576
+ toolName
577
+ );
578
+ let output = data;
579
+ if (toolDef.output) {
580
+ const outParsed = toolDef.output.safeParse(data);
581
+ if (!outParsed.success) {
582
+ return runOnError(
583
+ this._middleware,
584
+ toolName,
585
+ rawArgs,
586
+ makeFailure(
587
+ toolName,
588
+ makeValidationOutputError(toolName, outParsed.error.issues),
589
+ Date.now() - start
590
+ )
591
+ );
592
+ }
593
+ output = outParsed.data;
594
+ }
595
+ const raw = {
596
+ success: true,
597
+ data: output,
598
+ toolName,
599
+ durationMs: Date.now() - start
600
+ };
601
+ return await runAfter(this._middleware, toolName, rawArgs, raw);
602
+ } catch (err2) {
603
+ lastError = err2;
604
+ if (isAbortError(err2)) {
605
+ return runOnError(
606
+ this._middleware,
607
+ toolName,
608
+ rawArgs,
609
+ makeFailure(toolName, makeTimeoutError(toolName, timeout), Date.now() - start)
610
+ );
611
+ }
612
+ if (attempt < maxAttempts - 1) {
613
+ await sleep(100 * 2 ** attempt);
614
+ }
615
+ }
616
+ }
617
+ return runOnError(
618
+ this._middleware,
619
+ toolName,
620
+ rawArgs,
621
+ makeFailure(
622
+ toolName,
623
+ makeExecutionError(toolName, lastError, maxAttempts),
624
+ Date.now() - start
625
+ )
626
+ );
627
+ }
628
+ // ---------------------------------------------------------------------------
629
+ // Provider adapters
630
+ // ---------------------------------------------------------------------------
631
+ /** Export tool schemas in OpenAI function-calling format. */
632
+ toOpenAI(options) {
633
+ return toOpenAI(this.enabledTools(), options);
634
+ }
635
+ /** Export tool schemas in Anthropic tool-use format. */
636
+ toAnthropic() {
637
+ return toAnthropic(this.enabledTools());
638
+ }
639
+ /** Export tool schemas in Google Gemini format. */
640
+ toGemini() {
641
+ return toGemini(this.enabledTools());
642
+ }
643
+ /** Export tool schemas in Vercel AI SDK format (passes Zod schemas directly). */
644
+ toVercelAI() {
645
+ return toVercelAI(this.enabledTools());
646
+ }
647
+ // ---------------------------------------------------------------------------
648
+ // Static factory methods
649
+ // ---------------------------------------------------------------------------
650
+ /** Load tools from a directory of compiled JS/MJS files. */
651
+ static async fromDir(dirPath) {
652
+ const { fromDir: fromDir2 } = await Promise.resolve().then(() => (init_discovery(), discovery_exports));
653
+ return fromDir2(dirPath);
654
+ }
655
+ /** Load tools from a remote JSON manifest. */
656
+ static async fromManifest(url) {
657
+ const { fromManifest: fromManifest2 } = await Promise.resolve().then(() => (init_discovery(), discovery_exports));
658
+ return fromManifest2(url);
659
+ }
660
+ // ---------------------------------------------------------------------------
661
+ // Private helpers
662
+ // ---------------------------------------------------------------------------
663
+ enabledTools() {
664
+ return [...this.tools.values()].filter((t) => !this.disabledTools.has(t.name));
665
+ }
666
+ };
667
+ }
668
+ });
669
+
670
+ // src/index.ts
671
+ var index_exports = {};
672
+ __export(index_exports, {
673
+ ToolRegistry: () => ToolRegistry,
674
+ fromDir: () => fromDir,
675
+ fromManifest: () => fromManifest,
676
+ makeDisabledError: () => makeDisabledError,
677
+ makeExecutionError: () => makeExecutionError,
678
+ makeFailure: () => makeFailure,
679
+ makeNotFoundError: () => makeNotFoundError,
680
+ makeTimeoutError: () => makeTimeoutError,
681
+ makeValidationInputError: () => makeValidationInputError,
682
+ makeValidationOutputError: () => makeValidationOutputError,
683
+ registry: () => registry,
684
+ toAnthropic: () => toAnthropic,
685
+ toGemini: () => toGemini,
686
+ toOpenAI: () => toOpenAI,
687
+ toVercelAI: () => toVercelAI,
688
+ tool: () => tool
689
+ });
690
+ module.exports = __toCommonJS(index_exports);
691
+ init_cjs_shims();
692
+ init_tool();
693
+ init_registry();
694
+ init_openai();
695
+ init_anthropic();
696
+ init_gemini();
697
+ init_vercel_ai();
698
+ init_discovery();
699
+ init_errors();
700
+ // Annotate the CommonJS export names for ESM import in node:
701
+ 0 && (module.exports = {
702
+ ToolRegistry,
703
+ fromDir,
704
+ fromManifest,
705
+ makeDisabledError,
706
+ makeExecutionError,
707
+ makeFailure,
708
+ makeNotFoundError,
709
+ makeTimeoutError,
710
+ makeValidationInputError,
711
+ makeValidationOutputError,
712
+ registry,
713
+ toAnthropic,
714
+ toGemini,
715
+ toOpenAI,
716
+ toVercelAI,
717
+ tool
718
+ });
719
+ //# sourceMappingURL=index.cjs.map