modelfusion 0.70.0 → 0.72.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.
Files changed (138) hide show
  1. package/README.md +61 -49
  2. package/core/FunctionEvent.d.ts +5 -5
  3. package/guard/guard.cjs +5 -4
  4. package/guard/guard.d.ts +1 -1
  5. package/guard/guard.js +5 -4
  6. package/model-function/ModelCallEvent.d.ts +4 -3
  7. package/model-function/generate-structure/StructureGenerationEvent.d.ts +2 -2
  8. package/model-function/generate-structure/StructureParseError.cjs +10 -0
  9. package/model-function/generate-structure/StructureParseError.d.ts +8 -0
  10. package/model-function/generate-structure/StructureParseError.js +10 -0
  11. package/model-function/generate-structure/index.cjs +0 -3
  12. package/model-function/generate-structure/index.d.ts +0 -3
  13. package/model-function/generate-structure/index.js +0 -3
  14. package/model-function/index.cjs +0 -1
  15. package/model-function/index.d.ts +0 -1
  16. package/model-function/index.js +0 -1
  17. package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
  18. package/model-provider/openai/chat/OpenAIChatMessage.cjs +16 -25
  19. package/model-provider/openai/chat/OpenAIChatMessage.d.ts +14 -29
  20. package/model-provider/openai/chat/OpenAIChatMessage.js +16 -25
  21. package/model-provider/openai/chat/OpenAIChatModel.cjs +28 -48
  22. package/model-provider/openai/chat/OpenAIChatModel.d.ts +23 -68
  23. package/model-provider/openai/chat/OpenAIChatModel.js +28 -48
  24. package/package.json +2 -2
  25. package/{model-function/generate-tool-call/ToolCallParametersValidationError.js → tool/NoSuchToolDefinitionError.cjs} +9 -8
  26. package/{model-function/generate-tool-call/ToolCallParametersValidationError.d.ts → tool/NoSuchToolDefinitionError.d.ts} +2 -3
  27. package/tool/NoSuchToolDefinitionError.js +37 -0
  28. package/tool/Tool.cjs +5 -16
  29. package/tool/Tool.d.ts +9 -14
  30. package/tool/Tool.js +5 -16
  31. package/tool/ToolCall.d.ts +15 -0
  32. package/tool/ToolCallArgumentsValidationError.cjs +49 -0
  33. package/tool/ToolCallArgumentsValidationError.d.ts +23 -0
  34. package/tool/ToolCallArgumentsValidationError.js +45 -0
  35. package/tool/ToolCallError.cjs +34 -0
  36. package/tool/ToolCallError.d.ts +17 -0
  37. package/tool/ToolCallError.js +30 -0
  38. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.cjs +4 -4
  39. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.d.ts +1 -1
  40. package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.js +2 -2
  41. package/{model-function/generate-tool-call/ToolCallParametersValidationError.cjs → tool/ToolCallParseError.cjs} +13 -13
  42. package/tool/ToolCallParseError.d.ts +18 -0
  43. package/tool/ToolCallParseError.js +40 -0
  44. package/tool/ToolCallResult.d.ts +13 -0
  45. package/tool/ToolDefinition.d.ts +7 -0
  46. package/tool/ToolExecutionError.cjs +5 -4
  47. package/tool/ToolExecutionError.d.ts +4 -4
  48. package/tool/ToolExecutionError.js +5 -4
  49. package/tool/WebSearchTool.cjs +4 -4
  50. package/tool/WebSearchTool.d.ts +2 -2
  51. package/tool/WebSearchTool.js +4 -4
  52. package/tool/{ExecuteToolEvent.d.ts → execute-tool/ExecuteToolEvent.d.ts} +1 -1
  53. package/tool/{executeTool.cjs → execute-tool/executeTool.cjs} +15 -15
  54. package/tool/{executeTool.d.ts → execute-tool/executeTool.d.ts} +6 -6
  55. package/tool/{executeTool.js → execute-tool/executeTool.js} +15 -15
  56. package/tool/execute-tool/index.cjs +18 -0
  57. package/tool/execute-tool/index.d.ts +2 -0
  58. package/tool/execute-tool/index.js +2 -0
  59. package/tool/execute-tool/safeExecuteToolCall.cjs +34 -0
  60. package/tool/execute-tool/safeExecuteToolCall.d.ts +5 -0
  61. package/tool/execute-tool/safeExecuteToolCall.js +30 -0
  62. package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +59 -0
  63. package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +35 -0
  64. package/tool/generate-tool-call/TextGenerationToolCallModel.js +55 -0
  65. package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.d.ts +1 -1
  66. package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.d.ts +5 -5
  67. package/{model-function → tool}/generate-tool-call/generateToolCall.cjs +13 -12
  68. package/{model-function → tool}/generate-tool-call/generateToolCall.d.ts +7 -12
  69. package/{model-function → tool}/generate-tool-call/generateToolCall.js +13 -12
  70. package/{model-function → tool}/generate-tool-call/index.cjs +1 -2
  71. package/{model-function → tool}/generate-tool-call/index.d.ts +1 -2
  72. package/{model-function → tool}/generate-tool-call/index.js +1 -2
  73. package/tool/generate-tool-calls-or-text/ToolCallsOrTextGenerationEvent.d.ts +23 -0
  74. package/tool/generate-tool-calls-or-text/ToolCallsOrTextGenerationModel.cjs +2 -0
  75. package/tool/generate-tool-calls-or-text/ToolCallsOrTextGenerationModel.d.ts +21 -0
  76. package/tool/generate-tool-calls-or-text/ToolCallsOrTextGenerationModel.js +1 -0
  77. package/tool/generate-tool-calls-or-text/generateToolCallsOrText.cjs +63 -0
  78. package/tool/generate-tool-calls-or-text/generateToolCallsOrText.d.ts +33 -0
  79. package/tool/generate-tool-calls-or-text/generateToolCallsOrText.js +59 -0
  80. package/tool/generate-tool-calls-or-text/index.cjs +19 -0
  81. package/tool/generate-tool-calls-or-text/index.d.ts +3 -0
  82. package/tool/generate-tool-calls-or-text/index.js +3 -0
  83. package/tool/index.cjs +12 -7
  84. package/tool/index.d.ts +12 -7
  85. package/tool/index.js +12 -7
  86. package/tool/use-tool/UseToolEvent.cjs +2 -0
  87. package/tool/{UseToolEvent.d.ts → use-tool/UseToolEvent.d.ts} +1 -1
  88. package/tool/use-tool/UseToolEvent.js +1 -0
  89. package/tool/use-tool/index.cjs +18 -0
  90. package/tool/use-tool/index.d.ts +2 -0
  91. package/tool/use-tool/index.js +2 -0
  92. package/tool/use-tool/useTool.cjs +30 -0
  93. package/tool/use-tool/useTool.d.ts +16 -0
  94. package/tool/use-tool/useTool.js +26 -0
  95. package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.cjs +2 -0
  96. package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.d.ts +7 -0
  97. package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.js +1 -0
  98. package/tool/use-tools-or-generate-text/index.cjs +18 -0
  99. package/tool/use-tools-or-generate-text/index.d.ts +2 -0
  100. package/tool/use-tools-or-generate-text/index.js +2 -0
  101. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.cjs +48 -0
  102. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.d.ts +18 -0
  103. package/tool/use-tools-or-generate-text/useToolsOrGenerateText.js +44 -0
  104. package/util/getErrorMessage.cjs +3 -0
  105. package/util/getErrorMessage.d.ts +1 -1
  106. package/util/getErrorMessage.js +3 -0
  107. package/model-function/generate-structure/NoSuchStructureError.cjs +0 -17
  108. package/model-function/generate-structure/NoSuchStructureError.d.ts +0 -4
  109. package/model-function/generate-structure/NoSuchStructureError.js +0 -13
  110. package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +0 -26
  111. package/model-function/generate-structure/generateStructureOrText.cjs +0 -54
  112. package/model-function/generate-structure/generateStructureOrText.d.ts +0 -97
  113. package/model-function/generate-structure/generateStructureOrText.js +0 -50
  114. package/model-function/generate-tool-call/ToolCallDefinition.d.ts +0 -7
  115. package/tool/NoSuchToolError.cjs +0 -25
  116. package/tool/NoSuchToolError.d.ts +0 -10
  117. package/tool/NoSuchToolError.js +0 -21
  118. package/tool/UseToolOrGenerateTextEvent.d.ts +0 -7
  119. package/tool/useTool.cjs +0 -40
  120. package/tool/useTool.d.ts +0 -15
  121. package/tool/useTool.js +0 -36
  122. package/tool/useToolOrGenerateText.cjs +0 -50
  123. package/tool/useToolOrGenerateText.d.ts +0 -23
  124. package/tool/useToolOrGenerateText.js +0 -46
  125. /package/{model-function/generate-structure/StructureOrTextGenerationModel.cjs → tool/ToolCall.cjs} +0 -0
  126. /package/{model-function/generate-structure/StructureOrTextGenerationModel.js → tool/ToolCall.js} +0 -0
  127. /package/{model-function/generate-tool-call/ToolCallDefinition.cjs → tool/ToolCallResult.cjs} +0 -0
  128. /package/{model-function/generate-tool-call/ToolCallDefinition.js → tool/ToolCallResult.js} +0 -0
  129. /package/{model-function/generate-tool-call/ToolCallGenerationEvent.cjs → tool/ToolDefinition.cjs} +0 -0
  130. /package/{model-function/generate-tool-call/ToolCallGenerationEvent.js → tool/ToolDefinition.js} +0 -0
  131. /package/tool/{ExecuteToolEvent.cjs → execute-tool/ExecuteToolEvent.cjs} +0 -0
  132. /package/tool/{ExecuteToolEvent.js → execute-tool/ExecuteToolEvent.js} +0 -0
  133. /package/{model-function/generate-tool-call/ToolCallGenerationModel.cjs → tool/generate-tool-call/ToolCallGenerationEvent.cjs} +0 -0
  134. /package/{model-function/generate-tool-call/ToolCallGenerationModel.js → tool/generate-tool-call/ToolCallGenerationEvent.js} +0 -0
  135. /package/tool/{UseToolEvent.cjs → generate-tool-call/ToolCallGenerationModel.cjs} +0 -0
  136. /package/tool/{UseToolEvent.js → generate-tool-call/ToolCallGenerationModel.js} +0 -0
  137. /package/tool/{UseToolOrGenerateTextEvent.cjs → generate-tool-calls-or-text/ToolCallsOrTextGenerationEvent.cjs} +0 -0
  138. /package/tool/{UseToolOrGenerateTextEvent.js → generate-tool-calls-or-text/ToolCallsOrTextGenerationEvent.js} +0 -0
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolCallArgumentsValidationError = void 0;
4
+ const getErrorMessage_js_1 = require("../util/getErrorMessage.cjs");
5
+ /**
6
+ * Thrown when the arguments of a tool call are invalid.
7
+ *
8
+ * This typically means they don't match the parameters schema that is expected the tool.
9
+ */
10
+ class ToolCallArgumentsValidationError extends Error {
11
+ constructor({ toolName, args, cause, }) {
12
+ super(`Argument validation failed for tool '${toolName}'.\n` +
13
+ `Arguments: ${JSON.stringify(args)}.\n` +
14
+ `Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
15
+ Object.defineProperty(this, "toolName", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "cause", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "args", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ this.name = "ToolCallArgumentsValidationError";
34
+ this.toolName = toolName;
35
+ this.cause = cause;
36
+ this.args = args;
37
+ }
38
+ toJSON() {
39
+ return {
40
+ name: this.name,
41
+ message: this.message,
42
+ cause: this.cause,
43
+ stack: this.stack,
44
+ toolName: this.toolName,
45
+ args: this.args,
46
+ };
47
+ }
48
+ }
49
+ exports.ToolCallArgumentsValidationError = ToolCallArgumentsValidationError;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Thrown when the arguments of a tool call are invalid.
3
+ *
4
+ * This typically means they don't match the parameters schema that is expected the tool.
5
+ */
6
+ export declare class ToolCallArgumentsValidationError extends Error {
7
+ readonly toolName: string;
8
+ readonly cause: unknown;
9
+ readonly args: unknown;
10
+ constructor({ toolName, args, cause, }: {
11
+ toolName: string;
12
+ args: unknown;
13
+ cause: unknown;
14
+ });
15
+ toJSON(): {
16
+ name: string;
17
+ message: string;
18
+ cause: unknown;
19
+ stack: string | undefined;
20
+ toolName: string;
21
+ args: unknown;
22
+ };
23
+ }
@@ -0,0 +1,45 @@
1
+ import { getErrorMessage } from "../util/getErrorMessage.js";
2
+ /**
3
+ * Thrown when the arguments of a tool call are invalid.
4
+ *
5
+ * This typically means they don't match the parameters schema that is expected the tool.
6
+ */
7
+ export class ToolCallArgumentsValidationError extends Error {
8
+ constructor({ toolName, args, cause, }) {
9
+ super(`Argument validation failed for tool '${toolName}'.\n` +
10
+ `Arguments: ${JSON.stringify(args)}.\n` +
11
+ `Error message: ${getErrorMessage(cause)}`);
12
+ Object.defineProperty(this, "toolName", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "cause", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "args", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ this.name = "ToolCallArgumentsValidationError";
31
+ this.toolName = toolName;
32
+ this.cause = cause;
33
+ this.args = args;
34
+ }
35
+ toJSON() {
36
+ return {
37
+ name: this.name,
38
+ message: this.message,
39
+ cause: this.cause,
40
+ stack: this.stack,
41
+ toolName: this.toolName,
42
+ args: this.args,
43
+ };
44
+ }
45
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolCallError = void 0;
4
+ const getErrorMessage_js_1 = require("../util/getErrorMessage.cjs");
5
+ class ToolCallError extends Error {
6
+ constructor({ cause, toolCall, message = (0, getErrorMessage_js_1.getErrorMessage)(cause), }) {
7
+ super(`Tool call for tool '${toolCall.name}' failed: ${message}`);
8
+ Object.defineProperty(this, "toolCall", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: void 0
13
+ });
14
+ Object.defineProperty(this, "cause", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ this.name = "ToolCallError";
21
+ this.toolCall = toolCall;
22
+ this.cause = cause;
23
+ }
24
+ toJSON() {
25
+ return {
26
+ name: this.name,
27
+ cause: this.cause,
28
+ message: this.message,
29
+ stack: this.stack,
30
+ toolCall: this.toolCall,
31
+ };
32
+ }
33
+ }
34
+ exports.ToolCallError = ToolCallError;
@@ -0,0 +1,17 @@
1
+ import { ToolCall } from "./ToolCall.js";
2
+ export declare class ToolCallError extends Error {
3
+ readonly toolCall: ToolCall<string, unknown>;
4
+ readonly cause: unknown | undefined;
5
+ constructor({ cause, toolCall, message, }: {
6
+ toolCall: ToolCall<string, unknown>;
7
+ cause?: unknown;
8
+ message?: string;
9
+ });
10
+ toJSON(): {
11
+ name: string;
12
+ cause: unknown;
13
+ message: string;
14
+ stack: string | undefined;
15
+ toolCall: ToolCall<string, unknown>;
16
+ };
17
+ }
@@ -0,0 +1,30 @@
1
+ import { getErrorMessage } from "../util/getErrorMessage.js";
2
+ export class ToolCallError extends Error {
3
+ constructor({ cause, toolCall, message = getErrorMessage(cause), }) {
4
+ super(`Tool call for tool '${toolCall.name}' failed: ${message}`);
5
+ Object.defineProperty(this, "toolCall", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "cause", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ this.name = "ToolCallError";
18
+ this.toolCall = toolCall;
19
+ this.cause = cause;
20
+ }
21
+ toJSON() {
22
+ return {
23
+ name: this.name,
24
+ cause: this.cause,
25
+ message: this.message,
26
+ stack: this.stack,
27
+ toolCall: this.toolCall,
28
+ };
29
+ }
30
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolCallsGenerationError = void 0;
4
- const getErrorMessage_js_1 = require("../../util/getErrorMessage.cjs");
5
- class ToolCallsGenerationError extends Error {
3
+ exports.ToolCallGenerationError = void 0;
4
+ const getErrorMessage_js_1 = require("../util/getErrorMessage.cjs");
5
+ class ToolCallGenerationError extends Error {
6
6
  constructor({ toolName, cause }) {
7
7
  super(`Tool call generation failed for tool '${toolName}'. ` +
8
8
  `Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
@@ -32,4 +32,4 @@ class ToolCallsGenerationError extends Error {
32
32
  };
33
33
  }
34
34
  }
35
- exports.ToolCallsGenerationError = ToolCallsGenerationError;
35
+ exports.ToolCallGenerationError = ToolCallGenerationError;
@@ -1,4 +1,4 @@
1
- export declare class ToolCallsGenerationError extends Error {
1
+ export declare class ToolCallGenerationError extends Error {
2
2
  readonly toolName: string;
3
3
  readonly cause: unknown;
4
4
  constructor({ toolName, cause }: {
@@ -1,5 +1,5 @@
1
- import { getErrorMessage } from "../../util/getErrorMessage.js";
2
- export class ToolCallsGenerationError extends Error {
1
+ import { getErrorMessage } from "../util/getErrorMessage.js";
2
+ export class ToolCallGenerationError extends Error {
3
3
  constructor({ toolName, cause }) {
4
4
  super(`Tool call generation failed for tool '${toolName}'. ` +
5
5
  `Error message: ${getErrorMessage(cause)}`);
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolCallParametersValidationError = void 0;
4
- const getErrorMessage_js_1 = require("../../util/getErrorMessage.cjs");
5
- class ToolCallParametersValidationError extends Error {
6
- constructor({ toolName, parameters, cause, }) {
7
- super(`Parameter validation failed for tool '${toolName}'. ` +
8
- `Value: ${JSON.stringify(parameters)}.\n` +
3
+ exports.ToolCallParseError = void 0;
4
+ const getErrorMessage_js_1 = require("../util/getErrorMessage.cjs");
5
+ class ToolCallParseError extends Error {
6
+ constructor({ toolName, valueText, cause, }) {
7
+ super(`Tool call parsing failed for '${toolName}'. ` +
8
+ `Value: ${valueText}.\n` +
9
9
  `Error message: ${(0, getErrorMessage_js_1.getErrorMessage)(cause)}`);
10
10
  Object.defineProperty(this, "toolName", {
11
11
  enumerable: true,
@@ -13,32 +13,32 @@ class ToolCallParametersValidationError extends Error {
13
13
  writable: true,
14
14
  value: void 0
15
15
  });
16
- Object.defineProperty(this, "cause", {
16
+ Object.defineProperty(this, "valueText", {
17
17
  enumerable: true,
18
18
  configurable: true,
19
19
  writable: true,
20
20
  value: void 0
21
21
  });
22
- Object.defineProperty(this, "parameters", {
22
+ Object.defineProperty(this, "cause", {
23
23
  enumerable: true,
24
24
  configurable: true,
25
25
  writable: true,
26
26
  value: void 0
27
27
  });
28
- this.name = "ToolCallParametersValidationError";
28
+ this.name = "ToolCallParseError";
29
29
  this.toolName = toolName;
30
30
  this.cause = cause;
31
- this.parameters = parameters;
31
+ this.valueText = valueText;
32
32
  }
33
33
  toJSON() {
34
34
  return {
35
35
  name: this.name,
36
- message: this.message,
37
36
  cause: this.cause,
37
+ message: this.message,
38
38
  stack: this.stack,
39
39
  toolName: this.toolName,
40
- parameter: this.parameters,
40
+ valueText: this.valueText,
41
41
  };
42
42
  }
43
43
  }
44
- exports.ToolCallParametersValidationError = ToolCallParametersValidationError;
44
+ exports.ToolCallParseError = ToolCallParseError;
@@ -0,0 +1,18 @@
1
+ export declare class ToolCallParseError extends Error {
2
+ readonly toolName: string;
3
+ readonly valueText: string;
4
+ readonly cause: unknown;
5
+ constructor({ toolName, valueText, cause, }: {
6
+ toolName: string;
7
+ valueText: string;
8
+ cause: unknown;
9
+ });
10
+ toJSON(): {
11
+ name: string;
12
+ cause: unknown;
13
+ message: string;
14
+ stack: string | undefined;
15
+ toolName: string;
16
+ valueText: string;
17
+ };
18
+ }
@@ -0,0 +1,40 @@
1
+ import { getErrorMessage } from "../util/getErrorMessage.js";
2
+ export class ToolCallParseError extends Error {
3
+ constructor({ toolName, valueText, cause, }) {
4
+ super(`Tool call parsing failed for '${toolName}'. ` +
5
+ `Value: ${valueText}.\n` +
6
+ `Error message: ${getErrorMessage(cause)}`);
7
+ Object.defineProperty(this, "toolName", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ Object.defineProperty(this, "valueText", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ Object.defineProperty(this, "cause", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ this.name = "ToolCallParseError";
26
+ this.toolName = toolName;
27
+ this.cause = cause;
28
+ this.valueText = valueText;
29
+ }
30
+ toJSON() {
31
+ return {
32
+ name: this.name,
33
+ cause: this.cause,
34
+ message: this.message,
35
+ stack: this.stack,
36
+ toolName: this.toolName,
37
+ valueText: this.valueText,
38
+ };
39
+ }
40
+ }
@@ -0,0 +1,13 @@
1
+ import { ToolCall } from "./ToolCall.js";
2
+ import { ToolCallError } from "./ToolCallError.js";
3
+ export type ToolCallResult<NAME extends string, PARAMETERS, RETURN_TYPE> = {
4
+ tool: NAME;
5
+ toolCall: ToolCall<NAME, PARAMETERS>;
6
+ args: PARAMETERS;
7
+ } & ({
8
+ ok: true;
9
+ result: RETURN_TYPE;
10
+ } | {
11
+ ok: false;
12
+ result: ToolCallError;
13
+ });
@@ -0,0 +1,7 @@
1
+ import { JsonSchemaProducer } from "../core/schema/JsonSchemaProducer.js";
2
+ import { Schema } from "../core/schema/Schema.js";
3
+ export interface ToolDefinition<NAME extends string, PARAMETERS> {
4
+ name: NAME;
5
+ description?: string;
6
+ parameters: Schema<PARAMETERS> & JsonSchemaProducer;
7
+ }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ToolExecutionError = void 0;
4
+ const getErrorMessage_js_1 = require("../util/getErrorMessage.cjs");
4
5
  class ToolExecutionError extends Error {
5
- constructor({ message = "unknown error", toolName, input, cause, }) {
6
- super(`Error executing tool ${toolName}: ${message}`);
6
+ constructor({ toolName, input, cause, message = (0, getErrorMessage_js_1.getErrorMessage)(cause), }) {
7
+ super(`Error executing tool '${toolName}': ${message}`);
7
8
  Object.defineProperty(this, "toolName", {
8
9
  enumerable: true,
9
10
  configurable: true,
@@ -30,11 +31,11 @@ class ToolExecutionError extends Error {
30
31
  toJSON() {
31
32
  return {
32
33
  name: this.name,
33
- toolName: this.toolName,
34
- input: this.input,
35
34
  cause: this.cause,
36
35
  message: this.message,
37
36
  stack: this.stack,
37
+ toolName: this.toolName,
38
+ input: this.input,
38
39
  };
39
40
  }
40
41
  }
@@ -2,18 +2,18 @@ export declare class ToolExecutionError extends Error {
2
2
  readonly toolName: string;
3
3
  readonly input: unknown;
4
4
  readonly cause: unknown;
5
- constructor({ message, toolName, input, cause, }: {
5
+ constructor({ toolName, input, cause, message, }: {
6
6
  toolName: string;
7
7
  input: unknown;
8
- message: string | undefined;
9
8
  cause: unknown | undefined;
9
+ message?: string;
10
10
  });
11
11
  toJSON(): {
12
12
  name: string;
13
- toolName: string;
14
- input: unknown;
15
13
  cause: unknown;
16
14
  message: string;
17
15
  stack: string | undefined;
16
+ toolName: string;
17
+ input: unknown;
18
18
  };
19
19
  }
@@ -1,6 +1,7 @@
1
+ import { getErrorMessage } from "../util/getErrorMessage.js";
1
2
  export class ToolExecutionError extends Error {
2
- constructor({ message = "unknown error", toolName, input, cause, }) {
3
- super(`Error executing tool ${toolName}: ${message}`);
3
+ constructor({ toolName, input, cause, message = getErrorMessage(cause), }) {
4
+ super(`Error executing tool '${toolName}': ${message}`);
4
5
  Object.defineProperty(this, "toolName", {
5
6
  enumerable: true,
6
7
  configurable: true,
@@ -27,11 +28,11 @@ export class ToolExecutionError extends Error {
27
28
  toJSON() {
28
29
  return {
29
30
  name: this.name,
30
- toolName: this.toolName,
31
- input: this.input,
32
31
  cause: this.cause,
33
32
  message: this.message,
34
33
  stack: this.stack,
34
+ toolName: this.toolName,
35
+ input: this.input,
35
36
  };
36
37
  }
37
38
  }
@@ -4,7 +4,7 @@ exports.WebSearchTool = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const ZodSchema_js_1 = require("../core/schema/ZodSchema.cjs");
6
6
  const Tool_js_1 = require("./Tool.cjs");
7
- const OUTPUT_SCHEMA = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
7
+ const RETURN_TYPE_SCHEMA = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
8
8
  results: zod_1.z.array(zod_1.z.object({
9
9
  title: zod_1.z.string(),
10
10
  link: zod_1.z.string().url(),
@@ -12,7 +12,7 @@ const OUTPUT_SCHEMA = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
12
12
  })),
13
13
  }));
14
14
  // expose the schemas to library consumers:
15
- const createInputSchema = (description) =>
15
+ const createParameters = (description) =>
16
16
  // same structure, but with description:
17
17
  new ZodSchema_js_1.ZodSchema(zod_1.z.object({
18
18
  query: zod_1.z.string().describe(description),
@@ -47,8 +47,8 @@ class WebSearchTool extends Tool_js_1.Tool {
47
47
  super({
48
48
  name,
49
49
  description,
50
- inputSchema: createInputSchema(queryDescription),
51
- outputSchema: OUTPUT_SCHEMA,
50
+ parameters: createParameters(queryDescription),
51
+ returnType: RETURN_TYPE_SCHEMA,
52
52
  execute,
53
53
  });
54
54
  }
@@ -1,7 +1,7 @@
1
1
  import { FunctionOptions } from "../core/FunctionOptions.js";
2
2
  import { ZodSchema } from "../core/schema/ZodSchema.js";
3
3
  import { Tool } from "./Tool.js";
4
- declare const OUTPUT_SCHEMA: ZodSchema<{
4
+ declare const RETURN_TYPE_SCHEMA: ZodSchema<{
5
5
  results: {
6
6
  link: string;
7
7
  title: string;
@@ -44,7 +44,7 @@ export type WebSearchToolOutput = {
44
44
  * ```
45
45
  */
46
46
  export declare class WebSearchTool<NAME extends string> extends Tool<NAME, WebSearchToolInput, WebSearchToolOutput> {
47
- readonly outputSchema: typeof OUTPUT_SCHEMA;
47
+ readonly returnType: typeof RETURN_TYPE_SCHEMA;
48
48
  constructor({ name, description, queryDescription, execute, }: {
49
49
  name: NAME;
50
50
  description: string;
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ZodSchema } from "../core/schema/ZodSchema.js";
3
3
  import { Tool } from "./Tool.js";
4
- const OUTPUT_SCHEMA = new ZodSchema(z.object({
4
+ const RETURN_TYPE_SCHEMA = new ZodSchema(z.object({
5
5
  results: z.array(z.object({
6
6
  title: z.string(),
7
7
  link: z.string().url(),
@@ -9,7 +9,7 @@ const OUTPUT_SCHEMA = new ZodSchema(z.object({
9
9
  })),
10
10
  }));
11
11
  // expose the schemas to library consumers:
12
- const createInputSchema = (description) =>
12
+ const createParameters = (description) =>
13
13
  // same structure, but with description:
14
14
  new ZodSchema(z.object({
15
15
  query: z.string().describe(description),
@@ -44,8 +44,8 @@ export class WebSearchTool extends Tool {
44
44
  super({
45
45
  name,
46
46
  description,
47
- inputSchema: createInputSchema(queryDescription),
48
- outputSchema: OUTPUT_SCHEMA,
47
+ parameters: createParameters(queryDescription),
48
+ returnType: RETURN_TYPE_SCHEMA,
49
49
  execute,
50
50
  });
51
51
  }
@@ -1,4 +1,4 @@
1
- import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../core/FunctionEvent.js";
1
+ import { BaseFunctionFinishedEvent, BaseFunctionStartedEvent } from "../../core/FunctionEvent.js";
2
2
  export interface ExecuteToolStartedEvent extends BaseFunctionStartedEvent {
3
3
  functionType: "execute-tool";
4
4
  toolName: string;
@@ -2,23 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.executeTool = void 0;
4
4
  const nanoid_1 = require("nanoid");
5
- const FunctionEventSource_js_1 = require("../core/FunctionEventSource.cjs");
6
- const GlobalFunctionLogging_js_1 = require("../core/GlobalFunctionLogging.cjs");
7
- const GlobalFunctionObservers_js_1 = require("../core/GlobalFunctionObservers.cjs");
8
- const AbortError_js_1 = require("../core/api/AbortError.cjs");
9
- const getFunctionCallLogger_js_1 = require("../core/getFunctionCallLogger.cjs");
10
- const getRun_js_1 = require("../core/getRun.cjs");
11
- const DurationMeasurement_js_1 = require("../util/DurationMeasurement.cjs");
12
- const runSafe_js_1 = require("../util/runSafe.cjs");
13
- const ToolExecutionError_js_1 = require("./ToolExecutionError.cjs");
5
+ const FunctionEventSource_js_1 = require("../../core/FunctionEventSource.cjs");
6
+ const GlobalFunctionLogging_js_1 = require("../../core/GlobalFunctionLogging.cjs");
7
+ const GlobalFunctionObservers_js_1 = require("../../core/GlobalFunctionObservers.cjs");
8
+ const AbortError_js_1 = require("../../core/api/AbortError.cjs");
9
+ const getFunctionCallLogger_js_1 = require("../../core/getFunctionCallLogger.cjs");
10
+ const getRun_js_1 = require("../../core/getRun.cjs");
11
+ const DurationMeasurement_js_1 = require("../../util/DurationMeasurement.cjs");
12
+ const runSafe_js_1 = require("../../util/runSafe.cjs");
13
+ const ToolExecutionError_js_1 = require("../ToolExecutionError.cjs");
14
14
  async function executeTool(// eslint-disable-line @typescript-eslint/no-explicit-any
15
- tool, input, options) {
16
- const fullResponse = await doExecuteTool(tool, input, options);
15
+ tool, args, options) {
16
+ const fullResponse = await doExecuteTool(tool, args, options);
17
17
  return options?.returnType === "full" ? fullResponse : fullResponse.output;
18
18
  }
19
19
  exports.executeTool = executeTool;
20
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- async function doExecuteTool(tool, input, options) {
21
+ async function doExecuteTool(tool, args, options) {
22
22
  const run = await (0, getRun_js_1.getRun)(options?.run);
23
23
  const eventSource = new FunctionEventSource_js_1.FunctionEventSource({
24
24
  observers: [
@@ -39,7 +39,7 @@ async function doExecuteTool(tool, input, options) {
39
39
  userId: run?.userId,
40
40
  functionId: options?.functionId,
41
41
  toolName: tool.name,
42
- input,
42
+ input: args,
43
43
  };
44
44
  eventSource.notify({
45
45
  ...metadata,
@@ -47,7 +47,7 @@ async function doExecuteTool(tool, input, options) {
47
47
  timestamp: durationMeasurement.startDate,
48
48
  startTimestamp: durationMeasurement.startDate,
49
49
  });
50
- const result = await (0, runSafe_js_1.runSafe)(() => tool.execute(input, {
50
+ const result = await (0, runSafe_js_1.runSafe)(() => tool.execute(args, {
51
51
  functionId: options?.functionId,
52
52
  logging: options?.logging,
53
53
  observers: options?.observers,
@@ -81,7 +81,7 @@ async function doExecuteTool(tool, input, options) {
81
81
  });
82
82
  throw new ToolExecutionError_js_1.ToolExecutionError({
83
83
  toolName: tool.name,
84
- input,
84
+ input: args,
85
85
  cause: result.error,
86
86
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
87
  message: result.error?.message,
@@ -1,5 +1,5 @@
1
- import { FunctionOptions } from "../core/FunctionOptions.js";
2
- import { Tool } from "./Tool.js";
1
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
2
+ import { Tool } from "../Tool.js";
3
3
  export type ExecuteToolMetadata = {
4
4
  callId: string;
5
5
  runId?: string;
@@ -11,16 +11,16 @@ export type ExecuteToolMetadata = {
11
11
  durationInMs: number;
12
12
  };
13
13
  /**
14
- * `executeTool` directly executes a tool with the given parameters.
14
+ * `executeTool` executes a tool with the given parameters.
15
15
  */
16
16
  export declare function executeTool<TOOL extends Tool<any, any, any>>(// eslint-disable-line @typescript-eslint/no-explicit-any
17
- tool: TOOL, input: TOOL["inputSchema"]["_type"], options?: FunctionOptions & {
17
+ tool: TOOL, args: TOOL["parameters"]["_type"], options?: FunctionOptions & {
18
18
  returnType?: "output";
19
19
  }): Promise<ReturnType<TOOL["execute"]>>;
20
20
  export declare function executeTool<TOOL extends Tool<any, any, any>>(// eslint-disable-line @typescript-eslint/no-explicit-any
21
- tool: TOOL, input: TOOL["inputSchema"]["_type"], options: FunctionOptions & {
21
+ tool: TOOL, args: TOOL["parameters"]["_type"], options: FunctionOptions & {
22
22
  returnType: "full";
23
23
  }): Promise<{
24
- output: ReturnType<TOOL["execute"]>;
24
+ output: Awaited<ReturnType<TOOL["execute"]>>;
25
25
  metadata: ExecuteToolMetadata;
26
26
  }>;