@agentforge/core 0.6.4 → 0.7.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 +39 -1
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +39 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -688,13 +688,51 @@ var ToolBuilder = class {
|
|
|
688
688
|
}
|
|
689
689
|
/**
|
|
690
690
|
* Set the implementation function (required)
|
|
691
|
-
*
|
|
691
|
+
*
|
|
692
692
|
* @param execute - Async function that implements the tool
|
|
693
693
|
*/
|
|
694
694
|
implement(execute) {
|
|
695
695
|
this._execute = execute;
|
|
696
696
|
return this;
|
|
697
697
|
}
|
|
698
|
+
/**
|
|
699
|
+
* Set the implementation function with automatic error handling
|
|
700
|
+
*
|
|
701
|
+
* Wraps the implementation in a try-catch block and returns a standardized
|
|
702
|
+
* result object with success/error information.
|
|
703
|
+
*
|
|
704
|
+
* @param execute - Async function that implements the tool
|
|
705
|
+
* @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* const tool = toolBuilder()
|
|
710
|
+
* .name('read-file')
|
|
711
|
+
* .schema(z.object({ path: z.string() }))
|
|
712
|
+
* .implementSafe(async ({ path }) => {
|
|
713
|
+
* return await fs.readFile(path, 'utf-8');
|
|
714
|
+
* })
|
|
715
|
+
* .build();
|
|
716
|
+
*
|
|
717
|
+
* // Result will be: { success: true, data: "file content" }
|
|
718
|
+
* // Or on error: { success: false, error: "ENOENT: no such file..." }
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
implementSafe(execute) {
|
|
722
|
+
const safeExecute = async (input) => {
|
|
723
|
+
try {
|
|
724
|
+
const data = await execute(input);
|
|
725
|
+
return { success: true, data };
|
|
726
|
+
} catch (error) {
|
|
727
|
+
return {
|
|
728
|
+
success: false,
|
|
729
|
+
error: error instanceof Error ? error.message : String(error)
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
this._execute = safeExecute;
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
698
736
|
/**
|
|
699
737
|
* Build the tool with validation
|
|
700
738
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -1070,6 +1070,34 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
1070
1070
|
* @param execute - Async function that implements the tool
|
|
1071
1071
|
*/
|
|
1072
1072
|
implement<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
|
|
1073
|
+
/**
|
|
1074
|
+
* Set the implementation function with automatic error handling
|
|
1075
|
+
*
|
|
1076
|
+
* Wraps the implementation in a try-catch block and returns a standardized
|
|
1077
|
+
* result object with success/error information.
|
|
1078
|
+
*
|
|
1079
|
+
* @param execute - Async function that implements the tool
|
|
1080
|
+
* @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* const tool = toolBuilder()
|
|
1085
|
+
* .name('read-file')
|
|
1086
|
+
* .schema(z.object({ path: z.string() }))
|
|
1087
|
+
* .implementSafe(async ({ path }) => {
|
|
1088
|
+
* return await fs.readFile(path, 'utf-8');
|
|
1089
|
+
* })
|
|
1090
|
+
* .build();
|
|
1091
|
+
*
|
|
1092
|
+
* // Result will be: { success: true, data: "file content" }
|
|
1093
|
+
* // Or on error: { success: false, error: "ENOENT: no such file..." }
|
|
1094
|
+
* ```
|
|
1095
|
+
*/
|
|
1096
|
+
implementSafe<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
|
|
1097
|
+
success: boolean;
|
|
1098
|
+
data?: T;
|
|
1099
|
+
error?: string;
|
|
1100
|
+
}>;
|
|
1073
1101
|
/**
|
|
1074
1102
|
* Build the tool with validation
|
|
1075
1103
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1070,6 +1070,34 @@ declare class ToolBuilder<TInput = unknown, TOutput = unknown> {
|
|
|
1070
1070
|
* @param execute - Async function that implements the tool
|
|
1071
1071
|
*/
|
|
1072
1072
|
implement<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, T>;
|
|
1073
|
+
/**
|
|
1074
|
+
* Set the implementation function with automatic error handling
|
|
1075
|
+
*
|
|
1076
|
+
* Wraps the implementation in a try-catch block and returns a standardized
|
|
1077
|
+
* result object with success/error information.
|
|
1078
|
+
*
|
|
1079
|
+
* @param execute - Async function that implements the tool
|
|
1080
|
+
* @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* const tool = toolBuilder()
|
|
1085
|
+
* .name('read-file')
|
|
1086
|
+
* .schema(z.object({ path: z.string() }))
|
|
1087
|
+
* .implementSafe(async ({ path }) => {
|
|
1088
|
+
* return await fs.readFile(path, 'utf-8');
|
|
1089
|
+
* })
|
|
1090
|
+
* .build();
|
|
1091
|
+
*
|
|
1092
|
+
* // Result will be: { success: true, data: "file content" }
|
|
1093
|
+
* // Or on error: { success: false, error: "ENOENT: no such file..." }
|
|
1094
|
+
* ```
|
|
1095
|
+
*/
|
|
1096
|
+
implementSafe<T>(execute: (input: TInput) => Promise<T>): ToolBuilder<TInput, {
|
|
1097
|
+
success: boolean;
|
|
1098
|
+
data?: T;
|
|
1099
|
+
error?: string;
|
|
1100
|
+
}>;
|
|
1073
1101
|
/**
|
|
1074
1102
|
* Build the tool with validation
|
|
1075
1103
|
*
|
package/dist/index.js
CHANGED
|
@@ -532,13 +532,51 @@ var ToolBuilder = class {
|
|
|
532
532
|
}
|
|
533
533
|
/**
|
|
534
534
|
* Set the implementation function (required)
|
|
535
|
-
*
|
|
535
|
+
*
|
|
536
536
|
* @param execute - Async function that implements the tool
|
|
537
537
|
*/
|
|
538
538
|
implement(execute) {
|
|
539
539
|
this._execute = execute;
|
|
540
540
|
return this;
|
|
541
541
|
}
|
|
542
|
+
/**
|
|
543
|
+
* Set the implementation function with automatic error handling
|
|
544
|
+
*
|
|
545
|
+
* Wraps the implementation in a try-catch block and returns a standardized
|
|
546
|
+
* result object with success/error information.
|
|
547
|
+
*
|
|
548
|
+
* @param execute - Async function that implements the tool
|
|
549
|
+
* @returns ToolBuilder with safe result type { success: boolean; data?: T; error?: string }
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```ts
|
|
553
|
+
* const tool = toolBuilder()
|
|
554
|
+
* .name('read-file')
|
|
555
|
+
* .schema(z.object({ path: z.string() }))
|
|
556
|
+
* .implementSafe(async ({ path }) => {
|
|
557
|
+
* return await fs.readFile(path, 'utf-8');
|
|
558
|
+
* })
|
|
559
|
+
* .build();
|
|
560
|
+
*
|
|
561
|
+
* // Result will be: { success: true, data: "file content" }
|
|
562
|
+
* // Or on error: { success: false, error: "ENOENT: no such file..." }
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
implementSafe(execute) {
|
|
566
|
+
const safeExecute = async (input) => {
|
|
567
|
+
try {
|
|
568
|
+
const data = await execute(input);
|
|
569
|
+
return { success: true, data };
|
|
570
|
+
} catch (error) {
|
|
571
|
+
return {
|
|
572
|
+
success: false,
|
|
573
|
+
error: error instanceof Error ? error.message : String(error)
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
this._execute = safeExecute;
|
|
578
|
+
return this;
|
|
579
|
+
}
|
|
542
580
|
/**
|
|
543
581
|
* Build the tool with validation
|
|
544
582
|
*
|