@agentforge/core 0.16.8 → 0.16.10
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 +65 -15
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +65 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -494,10 +494,50 @@ function validateTool(tool) {
|
|
|
494
494
|
}
|
|
495
495
|
|
|
496
496
|
// src/tools/builder.ts
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
497
|
+
function cloneRelations(relations) {
|
|
498
|
+
if (!relations) {
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
requires: relations.requires ? [...relations.requires] : void 0,
|
|
503
|
+
suggests: relations.suggests ? [...relations.suggests] : void 0,
|
|
504
|
+
conflicts: relations.conflicts ? [...relations.conflicts] : void 0,
|
|
505
|
+
follows: relations.follows ? [...relations.follows] : void 0,
|
|
506
|
+
precedes: relations.precedes ? [...relations.precedes] : void 0
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
function cloneExampleValue(value, exampleIndex, field) {
|
|
510
|
+
try {
|
|
511
|
+
return structuredClone(value);
|
|
512
|
+
} catch (error) {
|
|
513
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
514
|
+
throw new TypeError(
|
|
515
|
+
`Invalid tool example at index ${exampleIndex}: "${field}" must be a structured-cloneable value. Received a non-cloneable value while building the tool metadata. Original error: ${reason}`
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function cloneExamples(examples) {
|
|
520
|
+
return examples?.map((example, index) => ({
|
|
521
|
+
...example,
|
|
522
|
+
input: cloneExampleValue(example.input, index, "input"),
|
|
523
|
+
output: example.output === void 0 ? void 0 : cloneExampleValue(example.output, index, "output")
|
|
524
|
+
}));
|
|
525
|
+
}
|
|
526
|
+
function cloneMetadata(metadata) {
|
|
527
|
+
return {
|
|
528
|
+
...metadata,
|
|
529
|
+
tags: metadata.tags ? [...metadata.tags] : void 0,
|
|
530
|
+
examples: cloneExamples(metadata.examples),
|
|
531
|
+
limitations: metadata.limitations ? [...metadata.limitations] : void 0,
|
|
532
|
+
relations: cloneRelations(metadata.relations)
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
var ToolBuilder = class _ToolBuilder {
|
|
536
|
+
constructor(metadata = {}, _schema, _invoke) {
|
|
537
|
+
this.metadata = metadata;
|
|
538
|
+
this._schema = _schema;
|
|
539
|
+
this._invoke = _invoke;
|
|
540
|
+
}
|
|
501
541
|
/**
|
|
502
542
|
* Set the tool name (required)
|
|
503
543
|
*
|
|
@@ -697,14 +737,13 @@ var ToolBuilder = class {
|
|
|
697
737
|
}
|
|
698
738
|
/**
|
|
699
739
|
* Set the input schema (required)
|
|
700
|
-
*
|
|
740
|
+
*
|
|
701
741
|
* All fields MUST have .describe() for LLM understanding!
|
|
702
|
-
*
|
|
742
|
+
*
|
|
703
743
|
* @param schema - Zod schema for input validation
|
|
704
744
|
*/
|
|
705
745
|
schema(schema) {
|
|
706
|
-
this.
|
|
707
|
-
return this;
|
|
746
|
+
return new _ToolBuilder(cloneMetadata(this.metadata), schema, this._invoke);
|
|
708
747
|
}
|
|
709
748
|
/**
|
|
710
749
|
* Set the implementation function (required)
|
|
@@ -712,8 +751,10 @@ var ToolBuilder = class {
|
|
|
712
751
|
* @param invoke - Async function that implements the tool
|
|
713
752
|
*/
|
|
714
753
|
implement(invoke) {
|
|
715
|
-
|
|
716
|
-
|
|
754
|
+
const wrappedInvoke = async function(input) {
|
|
755
|
+
return invoke.call(this, input);
|
|
756
|
+
};
|
|
757
|
+
return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrappedInvoke);
|
|
717
758
|
}
|
|
718
759
|
/**
|
|
719
760
|
* Set the implementation function with automatic error handling
|
|
@@ -739,9 +780,9 @@ var ToolBuilder = class {
|
|
|
739
780
|
* ```
|
|
740
781
|
*/
|
|
741
782
|
implementSafe(invoke) {
|
|
742
|
-
const safeInvoke = async (input)
|
|
783
|
+
const safeInvoke = async function(input) {
|
|
743
784
|
try {
|
|
744
|
-
const data = await invoke(input);
|
|
785
|
+
const data = await invoke.call(this, input);
|
|
745
786
|
return { success: true, data };
|
|
746
787
|
} catch (error) {
|
|
747
788
|
return {
|
|
@@ -750,8 +791,14 @@ var ToolBuilder = class {
|
|
|
750
791
|
};
|
|
751
792
|
}
|
|
752
793
|
};
|
|
753
|
-
|
|
754
|
-
|
|
794
|
+
const wrappedInvoke = async function(input) {
|
|
795
|
+
return safeInvoke.call(this, input);
|
|
796
|
+
};
|
|
797
|
+
return new _ToolBuilder(
|
|
798
|
+
cloneMetadata(this.metadata),
|
|
799
|
+
this._schema,
|
|
800
|
+
wrappedInvoke
|
|
801
|
+
);
|
|
755
802
|
}
|
|
756
803
|
/**
|
|
757
804
|
* Build the tool with validation
|
|
@@ -780,10 +827,13 @@ var ToolBuilder = class {
|
|
|
780
827
|
if (!this._invoke) {
|
|
781
828
|
throw new Error("Tool implementation is required. Use .implement() to set it.");
|
|
782
829
|
}
|
|
830
|
+
const invoke = this._invoke;
|
|
783
831
|
return createTool(
|
|
784
832
|
this.metadata,
|
|
785
833
|
this._schema,
|
|
786
|
-
|
|
834
|
+
async function(input) {
|
|
835
|
+
return invoke.call(this, input);
|
|
836
|
+
}
|
|
787
837
|
);
|
|
788
838
|
}
|
|
789
839
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -941,6 +941,7 @@ declare function validateTool(tool: Tool): {
|
|
|
941
941
|
* ```
|
|
942
942
|
*/
|
|
943
943
|
|
|
944
|
+
type ToolInvoke<TOutput> = (this: unknown, input: unknown) => Promise<TOutput>;
|
|
944
945
|
/**
|
|
945
946
|
* Builder for creating tools with a fluent API
|
|
946
947
|
*
|
|
@@ -951,6 +952,7 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
951
952
|
private metadata;
|
|
952
953
|
private _schema?;
|
|
953
954
|
private _invoke?;
|
|
955
|
+
constructor(metadata?: Partial<ToolMetadata>, _schema?: z.ZodSchema<TInput> | undefined, _invoke?: ToolInvoke<TOutput> | undefined);
|
|
954
956
|
/**
|
|
955
957
|
* Set the tool name (required)
|
|
956
958
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -941,6 +941,7 @@ declare function validateTool(tool: Tool): {
|
|
|
941
941
|
* ```
|
|
942
942
|
*/
|
|
943
943
|
|
|
944
|
+
type ToolInvoke<TOutput> = (this: unknown, input: unknown) => Promise<TOutput>;
|
|
944
945
|
/**
|
|
945
946
|
* Builder for creating tools with a fluent API
|
|
946
947
|
*
|
|
@@ -951,6 +952,7 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
951
952
|
private metadata;
|
|
952
953
|
private _schema?;
|
|
953
954
|
private _invoke?;
|
|
955
|
+
constructor(metadata?: Partial<ToolMetadata>, _schema?: z.ZodSchema<TInput> | undefined, _invoke?: ToolInvoke<TOutput> | undefined);
|
|
954
956
|
/**
|
|
955
957
|
* Set the tool name (required)
|
|
956
958
|
*
|
package/dist/index.js
CHANGED
|
@@ -319,10 +319,50 @@ function validateTool(tool) {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
// src/tools/builder.ts
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
322
|
+
function cloneRelations(relations) {
|
|
323
|
+
if (!relations) {
|
|
324
|
+
return void 0;
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
requires: relations.requires ? [...relations.requires] : void 0,
|
|
328
|
+
suggests: relations.suggests ? [...relations.suggests] : void 0,
|
|
329
|
+
conflicts: relations.conflicts ? [...relations.conflicts] : void 0,
|
|
330
|
+
follows: relations.follows ? [...relations.follows] : void 0,
|
|
331
|
+
precedes: relations.precedes ? [...relations.precedes] : void 0
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function cloneExampleValue(value, exampleIndex, field) {
|
|
335
|
+
try {
|
|
336
|
+
return structuredClone(value);
|
|
337
|
+
} catch (error) {
|
|
338
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
339
|
+
throw new TypeError(
|
|
340
|
+
`Invalid tool example at index ${exampleIndex}: "${field}" must be a structured-cloneable value. Received a non-cloneable value while building the tool metadata. Original error: ${reason}`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function cloneExamples(examples) {
|
|
345
|
+
return examples?.map((example, index) => ({
|
|
346
|
+
...example,
|
|
347
|
+
input: cloneExampleValue(example.input, index, "input"),
|
|
348
|
+
output: example.output === void 0 ? void 0 : cloneExampleValue(example.output, index, "output")
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
function cloneMetadata(metadata) {
|
|
352
|
+
return {
|
|
353
|
+
...metadata,
|
|
354
|
+
tags: metadata.tags ? [...metadata.tags] : void 0,
|
|
355
|
+
examples: cloneExamples(metadata.examples),
|
|
356
|
+
limitations: metadata.limitations ? [...metadata.limitations] : void 0,
|
|
357
|
+
relations: cloneRelations(metadata.relations)
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
var ToolBuilder = class _ToolBuilder {
|
|
361
|
+
constructor(metadata = {}, _schema, _invoke) {
|
|
362
|
+
this.metadata = metadata;
|
|
363
|
+
this._schema = _schema;
|
|
364
|
+
this._invoke = _invoke;
|
|
365
|
+
}
|
|
326
366
|
/**
|
|
327
367
|
* Set the tool name (required)
|
|
328
368
|
*
|
|
@@ -522,14 +562,13 @@ var ToolBuilder = class {
|
|
|
522
562
|
}
|
|
523
563
|
/**
|
|
524
564
|
* Set the input schema (required)
|
|
525
|
-
*
|
|
565
|
+
*
|
|
526
566
|
* All fields MUST have .describe() for LLM understanding!
|
|
527
|
-
*
|
|
567
|
+
*
|
|
528
568
|
* @param schema - Zod schema for input validation
|
|
529
569
|
*/
|
|
530
570
|
schema(schema) {
|
|
531
|
-
this.
|
|
532
|
-
return this;
|
|
571
|
+
return new _ToolBuilder(cloneMetadata(this.metadata), schema, this._invoke);
|
|
533
572
|
}
|
|
534
573
|
/**
|
|
535
574
|
* Set the implementation function (required)
|
|
@@ -537,8 +576,10 @@ var ToolBuilder = class {
|
|
|
537
576
|
* @param invoke - Async function that implements the tool
|
|
538
577
|
*/
|
|
539
578
|
implement(invoke) {
|
|
540
|
-
|
|
541
|
-
|
|
579
|
+
const wrappedInvoke = async function(input) {
|
|
580
|
+
return invoke.call(this, input);
|
|
581
|
+
};
|
|
582
|
+
return new _ToolBuilder(cloneMetadata(this.metadata), this._schema, wrappedInvoke);
|
|
542
583
|
}
|
|
543
584
|
/**
|
|
544
585
|
* Set the implementation function with automatic error handling
|
|
@@ -564,9 +605,9 @@ var ToolBuilder = class {
|
|
|
564
605
|
* ```
|
|
565
606
|
*/
|
|
566
607
|
implementSafe(invoke) {
|
|
567
|
-
const safeInvoke = async (input)
|
|
608
|
+
const safeInvoke = async function(input) {
|
|
568
609
|
try {
|
|
569
|
-
const data = await invoke(input);
|
|
610
|
+
const data = await invoke.call(this, input);
|
|
570
611
|
return { success: true, data };
|
|
571
612
|
} catch (error) {
|
|
572
613
|
return {
|
|
@@ -575,8 +616,14 @@ var ToolBuilder = class {
|
|
|
575
616
|
};
|
|
576
617
|
}
|
|
577
618
|
};
|
|
578
|
-
|
|
579
|
-
|
|
619
|
+
const wrappedInvoke = async function(input) {
|
|
620
|
+
return safeInvoke.call(this, input);
|
|
621
|
+
};
|
|
622
|
+
return new _ToolBuilder(
|
|
623
|
+
cloneMetadata(this.metadata),
|
|
624
|
+
this._schema,
|
|
625
|
+
wrappedInvoke
|
|
626
|
+
);
|
|
580
627
|
}
|
|
581
628
|
/**
|
|
582
629
|
* Build the tool with validation
|
|
@@ -605,10 +652,13 @@ var ToolBuilder = class {
|
|
|
605
652
|
if (!this._invoke) {
|
|
606
653
|
throw new Error("Tool implementation is required. Use .implement() to set it.");
|
|
607
654
|
}
|
|
655
|
+
const invoke = this._invoke;
|
|
608
656
|
return createTool(
|
|
609
657
|
this.metadata,
|
|
610
658
|
this._schema,
|
|
611
|
-
|
|
659
|
+
async function(input) {
|
|
660
|
+
return invoke.call(this, input);
|
|
661
|
+
}
|
|
612
662
|
);
|
|
613
663
|
}
|
|
614
664
|
};
|
package/package.json
CHANGED