modelfusion 0.71.0 → 0.73.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/README.md +57 -45
- package/core/FunctionEvent.d.ts +5 -5
- package/core/api/ApiCallError.cjs +2 -1
- package/core/api/ApiCallError.d.ts +3 -3
- package/core/api/ApiCallError.js +2 -1
- package/core/api/postToApi.cjs +10 -3
- package/core/api/postToApi.js +10 -3
- package/guard/guard.cjs +5 -4
- package/guard/guard.d.ts +1 -1
- package/guard/guard.js +5 -4
- package/model-function/ModelCallEvent.d.ts +2 -2
- package/model-function/generate-structure/StructureGenerationEvent.d.ts +2 -2
- package/model-function/generate-structure/StructureParseError.cjs +10 -0
- package/model-function/generate-structure/StructureParseError.d.ts +8 -0
- package/model-function/generate-structure/StructureParseError.js +10 -0
- package/model-function/generate-structure/index.cjs +0 -3
- package/model-function/generate-structure/index.d.ts +0 -3
- package/model-function/generate-structure/index.js +0 -3
- package/model-function/index.cjs +0 -1
- package/model-function/index.d.ts +0 -1
- package/model-function/index.js +0 -1
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +3 -3
- package/model-provider/ollama/OllamaError.cjs +21 -7
- package/model-provider/ollama/OllamaError.d.ts +10 -3
- package/model-provider/ollama/OllamaError.js +21 -7
- package/model-provider/ollama/OllamaTextGenerationModel.cjs +2 -2
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +5 -5
- package/model-provider/ollama/OllamaTextGenerationModel.js +2 -2
- package/model-provider/openai/chat/OpenAIChatMessage.cjs +16 -25
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +10 -28
- package/model-provider/openai/chat/OpenAIChatMessage.js +16 -25
- package/model-provider/openai/chat/OpenAIChatModel.cjs +2 -48
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +15 -107
- package/model-provider/openai/chat/OpenAIChatModel.js +2 -48
- package/package.json +1 -1
- package/tool/Tool.cjs +5 -16
- package/tool/Tool.d.ts +9 -14
- package/tool/Tool.js +5 -16
- package/tool/ToolCall.d.ts +15 -0
- package/tool/ToolCallArgumentsValidationError.cjs +49 -0
- package/tool/ToolCallArgumentsValidationError.d.ts +23 -0
- package/tool/ToolCallArgumentsValidationError.js +45 -0
- package/tool/ToolCallError.cjs +34 -0
- package/tool/ToolCallError.d.ts +17 -0
- package/tool/ToolCallError.js +30 -0
- package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.cjs +4 -4
- package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.d.ts +1 -1
- package/{model-function/generate-tool-call → tool}/ToolCallGenerationError.js +2 -2
- package/{model-function/generate-tool-call/ToolCallParametersValidationError.cjs → tool/ToolCallParseError.cjs} +13 -13
- package/{model-function/generate-tool-call/ToolCallParametersValidationError.d.ts → tool/ToolCallParseError.d.ts} +6 -6
- package/{model-function/generate-tool-call/ToolCallParametersValidationError.js → tool/ToolCallParseError.js} +11 -11
- package/tool/ToolCallResult.d.ts +13 -0
- package/{model-function/generate-tool-call → tool}/ToolDefinition.d.ts +2 -2
- package/tool/ToolExecutionError.cjs +5 -4
- package/tool/ToolExecutionError.d.ts +4 -4
- package/tool/ToolExecutionError.js +5 -4
- package/tool/WebSearchTool.cjs +4 -4
- package/tool/WebSearchTool.d.ts +2 -2
- package/tool/WebSearchTool.js +4 -4
- package/tool/{ExecuteToolEvent.d.ts → execute-tool/ExecuteToolEvent.d.ts} +1 -1
- package/tool/{executeTool.cjs → execute-tool/executeTool.cjs} +15 -15
- package/tool/{executeTool.d.ts → execute-tool/executeTool.d.ts} +6 -6
- package/tool/{executeTool.js → execute-tool/executeTool.js} +15 -15
- package/tool/execute-tool/index.cjs +18 -0
- package/tool/execute-tool/index.d.ts +2 -0
- package/tool/execute-tool/index.js +2 -0
- package/tool/execute-tool/safeExecuteToolCall.cjs +34 -0
- package/tool/execute-tool/safeExecuteToolCall.d.ts +5 -0
- package/tool/execute-tool/safeExecuteToolCall.js +30 -0
- package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +59 -0
- package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +35 -0
- package/tool/generate-tool-call/TextGenerationToolCallModel.js +55 -0
- package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.d.ts +1 -1
- package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.d.ts +3 -3
- package/{model-function → tool}/generate-tool-call/generateToolCall.cjs +11 -11
- package/{model-function → tool}/generate-tool-call/generateToolCall.d.ts +3 -3
- package/{model-function → tool}/generate-tool-call/generateToolCall.js +11 -11
- package/tool/generate-tool-call/index.cjs +20 -0
- package/tool/generate-tool-call/index.d.ts +4 -0
- package/tool/generate-tool-call/index.js +4 -0
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.d.ts +1 -1
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.d.ts +3 -3
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.cjs +8 -8
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.d.ts +3 -3
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/generateToolCallsOrText.js +8 -8
- package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/index.cjs +0 -7
- package/tool/generate-tool-calls-or-text/index.d.ts +3 -0
- package/tool/generate-tool-calls-or-text/index.js +3 -0
- package/tool/index.cjs +12 -7
- package/tool/index.d.ts +12 -7
- package/tool/index.js +12 -7
- package/tool/{UseToolEvent.d.ts → use-tool/UseToolEvent.d.ts} +1 -1
- package/tool/use-tool/index.cjs +18 -0
- package/tool/use-tool/index.d.ts +2 -0
- package/tool/use-tool/index.js +2 -0
- package/tool/use-tool/useTool.cjs +30 -0
- package/tool/use-tool/useTool.d.ts +16 -0
- package/tool/use-tool/useTool.js +26 -0
- package/tool/use-tools-or-generate-text/UseToolsOrGenerateTextEvent.d.ts +7 -0
- package/tool/use-tools-or-generate-text/index.cjs +18 -0
- package/tool/use-tools-or-generate-text/index.d.ts +2 -0
- package/tool/use-tools-or-generate-text/index.js +2 -0
- package/tool/use-tools-or-generate-text/useToolsOrGenerateText.cjs +48 -0
- package/tool/use-tools-or-generate-text/useToolsOrGenerateText.d.ts +18 -0
- package/tool/use-tools-or-generate-text/useToolsOrGenerateText.js +44 -0
- package/util/getErrorMessage.cjs +3 -0
- package/util/getErrorMessage.d.ts +1 -1
- package/util/getErrorMessage.js +3 -0
- package/model-function/generate-structure/NoSuchStructureError.cjs +0 -17
- package/model-function/generate-structure/NoSuchStructureError.d.ts +0 -4
- package/model-function/generate-structure/NoSuchStructureError.js +0 -13
- package/model-function/generate-structure/StructureOrTextGenerationModel.d.ts +0 -26
- package/model-function/generate-structure/generateStructureOrText.cjs +0 -54
- package/model-function/generate-structure/generateStructureOrText.d.ts +0 -97
- package/model-function/generate-structure/generateStructureOrText.js +0 -50
- package/model-function/generate-tool-call/ToolCall.d.ts +0 -5
- package/model-function/generate-tool-call/index.d.ts +0 -10
- package/model-function/generate-tool-call/index.js +0 -10
- package/tool/NoSuchToolError.cjs +0 -25
- package/tool/NoSuchToolError.d.ts +0 -10
- package/tool/NoSuchToolError.js +0 -21
- package/tool/UseToolOrGenerateTextEvent.d.ts +0 -7
- package/tool/useTool.cjs +0 -40
- package/tool/useTool.d.ts +0 -15
- package/tool/useTool.js +0 -36
- package/tool/useToolOrGenerateText.cjs +0 -50
- package/tool/useToolOrGenerateText.d.ts +0 -23
- package/tool/useToolOrGenerateText.js +0 -46
- /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.cjs +0 -0
- /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.d.ts +0 -0
- /package/{model-function/generate-tool-call → tool}/NoSuchToolDefinitionError.js +0 -0
- /package/{model-function/generate-tool-call → tool}/ToolCall.cjs +0 -0
- /package/{model-function/generate-tool-call → tool}/ToolCall.js +0 -0
- /package/{model-function/generate-structure/StructureOrTextGenerationModel.cjs → tool/ToolCallResult.cjs} +0 -0
- /package/{model-function/generate-structure/StructureOrTextGenerationModel.js → tool/ToolCallResult.js} +0 -0
- /package/{model-function/generate-tool-call → tool}/ToolDefinition.cjs +0 -0
- /package/{model-function/generate-tool-call → tool}/ToolDefinition.js +0 -0
- /package/tool/{ExecuteToolEvent.cjs → execute-tool/ExecuteToolEvent.cjs} +0 -0
- /package/tool/{ExecuteToolEvent.js → execute-tool/ExecuteToolEvent.js} +0 -0
- /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.cjs +0 -0
- /package/{model-function → tool}/generate-tool-call/ToolCallGenerationEvent.js +0 -0
- /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.cjs +0 -0
- /package/{model-function → tool}/generate-tool-call/ToolCallGenerationModel.js +0 -0
- /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.cjs +0 -0
- /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationEvent.js +0 -0
- /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.cjs +0 -0
- /package/{model-function/generate-tool-call → tool/generate-tool-calls-or-text}/ToolCallsOrTextGenerationModel.js +0 -0
- /package/tool/{UseToolEvent.cjs → use-tool/UseToolEvent.cjs} +0 -0
- /package/tool/{UseToolEvent.js → use-tool/UseToolEvent.js} +0 -0
- /package/tool/{UseToolOrGenerateTextEvent.cjs → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.cjs} +0 -0
- /package/tool/{UseToolOrGenerateTextEvent.js → use-tools-or-generate-text/UseToolsOrGenerateTextEvent.js} +0 -0
package/tool/Tool.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import { FunctionOptions } from "../core/FunctionOptions.js";
|
2
2
|
import { JsonSchemaProducer } from "../core/schema/JsonSchemaProducer.js";
|
3
3
|
import { Schema } from "../core/schema/Schema.js";
|
4
|
-
import {
|
4
|
+
import { ToolDefinition } from "./ToolDefinition.js";
|
5
5
|
/**
|
6
6
|
* A tool is a function with a name, description and defined inputs that can be used
|
7
7
|
* by agents and chatbots.
|
8
8
|
*/
|
9
|
-
export declare class Tool<NAME extends string,
|
9
|
+
export declare class Tool<NAME extends string, PARAMETERS, RESULT> implements ToolDefinition<NAME, PARAMETERS> {
|
10
10
|
/**
|
11
11
|
* The name of the tool.
|
12
12
|
* It has to be a function name that matches the regular expression pattern '^[a-zA-Z0-9_-]{1,64}$'.
|
@@ -21,25 +21,20 @@ export declare class Tool<NAME extends string, INPUT, OUTPUT> {
|
|
21
21
|
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
22
22
|
* Use descriptions to make the input understandable for the language model.
|
23
23
|
*/
|
24
|
-
readonly
|
24
|
+
readonly parameters: Schema<PARAMETERS> & JsonSchemaProducer;
|
25
25
|
/**
|
26
26
|
* An optional schema of the output that the tool produces. This will be used to validate the output.
|
27
27
|
*/
|
28
|
-
readonly
|
28
|
+
readonly returnType?: Schema<RESULT>;
|
29
29
|
/**
|
30
30
|
* The actual execution function of the tool.
|
31
31
|
*/
|
32
|
-
readonly execute: (
|
33
|
-
constructor({ name, description,
|
32
|
+
readonly execute: (args: PARAMETERS, options?: FunctionOptions) => PromiseLike<RESULT>;
|
33
|
+
constructor({ name, description, parameters, returnType, execute, }: {
|
34
34
|
name: NAME;
|
35
35
|
description: string;
|
36
|
-
|
37
|
-
|
38
|
-
execute(
|
36
|
+
parameters: Schema<PARAMETERS> & JsonSchemaProducer;
|
37
|
+
returnType?: Schema<RESULT>;
|
38
|
+
execute(args: PARAMETERS, options?: FunctionOptions): PromiseLike<RESULT>;
|
39
39
|
});
|
40
|
-
/**
|
41
|
-
* Provides a structure definition with the name, description and schema of the input.
|
42
|
-
* This is used by `useTool`.
|
43
|
-
*/
|
44
|
-
get inputStructureDefinition(): StructureDefinition<NAME, INPUT>;
|
45
40
|
}
|
package/tool/Tool.js
CHANGED
@@ -5,7 +5,7 @@ const namePattern = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
5
5
|
* by agents and chatbots.
|
6
6
|
*/
|
7
7
|
export class Tool {
|
8
|
-
constructor({ name, description,
|
8
|
+
constructor({ name, description, parameters, returnType, execute, }) {
|
9
9
|
/**
|
10
10
|
* The name of the tool.
|
11
11
|
* It has to be a function name that matches the regular expression pattern '^[a-zA-Z0-9_-]{1,64}$'.
|
@@ -30,7 +30,7 @@ export class Tool {
|
|
30
30
|
* The schema of the input that the tool expects. The language model will use this to generate the input.
|
31
31
|
* Use descriptions to make the input understandable for the language model.
|
32
32
|
*/
|
33
|
-
Object.defineProperty(this, "
|
33
|
+
Object.defineProperty(this, "parameters", {
|
34
34
|
enumerable: true,
|
35
35
|
configurable: true,
|
36
36
|
writable: true,
|
@@ -39,7 +39,7 @@ export class Tool {
|
|
39
39
|
/**
|
40
40
|
* An optional schema of the output that the tool produces. This will be used to validate the output.
|
41
41
|
*/
|
42
|
-
Object.defineProperty(this, "
|
42
|
+
Object.defineProperty(this, "returnType", {
|
43
43
|
enumerable: true,
|
44
44
|
configurable: true,
|
45
45
|
writable: true,
|
@@ -63,19 +63,8 @@ export class Tool {
|
|
63
63
|
}
|
64
64
|
this.name = name;
|
65
65
|
this.description = description;
|
66
|
-
this.
|
67
|
-
this.
|
66
|
+
this.parameters = parameters;
|
67
|
+
this.returnType = returnType;
|
68
68
|
this.execute = execute;
|
69
69
|
}
|
70
|
-
/**
|
71
|
-
* Provides a structure definition with the name, description and schema of the input.
|
72
|
-
* This is used by `useTool`.
|
73
|
-
*/
|
74
|
-
get inputStructureDefinition() {
|
75
|
-
return {
|
76
|
-
name: this.name,
|
77
|
-
description: this.description,
|
78
|
-
schema: this.inputSchema,
|
79
|
-
};
|
80
|
-
}
|
81
70
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* A tool call contains all information required to execute a tool.
|
3
|
+
* It can be generated by a language model.
|
4
|
+
*
|
5
|
+
* @template NAME - The name of the tool as a string.
|
6
|
+
* @template PARAMETERS - The parameters for the tool.
|
7
|
+
*/
|
8
|
+
export interface ToolCall<NAME extends string, PARAMETERS> {
|
9
|
+
/** The id of the tool call. */
|
10
|
+
id: string;
|
11
|
+
/** The name of the tool. */
|
12
|
+
name: NAME;
|
13
|
+
/** The arguments for the tool. */
|
14
|
+
args: PARAMETERS;
|
15
|
+
}
|
@@ -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.
|
4
|
-
const getErrorMessage_js_1 = require("
|
5
|
-
class
|
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.
|
35
|
+
exports.ToolCallGenerationError = ToolCallGenerationError;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { getErrorMessage } from "
|
2
|
-
export class
|
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.
|
4
|
-
const getErrorMessage_js_1 = require("
|
5
|
-
class
|
6
|
-
constructor({ toolName,
|
7
|
-
super(`
|
8
|
-
`
|
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, "
|
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, "
|
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 = "
|
28
|
+
this.name = "ToolCallParseError";
|
29
29
|
this.toolName = toolName;
|
30
30
|
this.cause = cause;
|
31
|
-
this.
|
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
|
-
|
40
|
+
valueText: this.valueText,
|
41
41
|
};
|
42
42
|
}
|
43
43
|
}
|
44
|
-
exports.
|
44
|
+
exports.ToolCallParseError = ToolCallParseError;
|
@@ -1,18 +1,18 @@
|
|
1
|
-
export declare class
|
1
|
+
export declare class ToolCallParseError extends Error {
|
2
2
|
readonly toolName: string;
|
3
|
+
readonly valueText: string;
|
3
4
|
readonly cause: unknown;
|
4
|
-
|
5
|
-
constructor({ toolName, parameters, cause, }: {
|
5
|
+
constructor({ toolName, valueText, cause, }: {
|
6
6
|
toolName: string;
|
7
|
-
|
7
|
+
valueText: string;
|
8
8
|
cause: unknown;
|
9
9
|
});
|
10
10
|
toJSON(): {
|
11
11
|
name: string;
|
12
|
-
message: string;
|
13
12
|
cause: unknown;
|
13
|
+
message: string;
|
14
14
|
stack: string | undefined;
|
15
15
|
toolName: string;
|
16
|
-
|
16
|
+
valueText: string;
|
17
17
|
};
|
18
18
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { getErrorMessage } from "
|
2
|
-
export class
|
3
|
-
constructor({ toolName,
|
4
|
-
super(`
|
5
|
-
`
|
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
6
|
`Error message: ${getErrorMessage(cause)}`);
|
7
7
|
Object.defineProperty(this, "toolName", {
|
8
8
|
enumerable: true,
|
@@ -10,31 +10,31 @@ export class ToolCallParametersValidationError extends Error {
|
|
10
10
|
writable: true,
|
11
11
|
value: void 0
|
12
12
|
});
|
13
|
-
Object.defineProperty(this, "
|
13
|
+
Object.defineProperty(this, "valueText", {
|
14
14
|
enumerable: true,
|
15
15
|
configurable: true,
|
16
16
|
writable: true,
|
17
17
|
value: void 0
|
18
18
|
});
|
19
|
-
Object.defineProperty(this, "
|
19
|
+
Object.defineProperty(this, "cause", {
|
20
20
|
enumerable: true,
|
21
21
|
configurable: true,
|
22
22
|
writable: true,
|
23
23
|
value: void 0
|
24
24
|
});
|
25
|
-
this.name = "
|
25
|
+
this.name = "ToolCallParseError";
|
26
26
|
this.toolName = toolName;
|
27
27
|
this.cause = cause;
|
28
|
-
this.
|
28
|
+
this.valueText = valueText;
|
29
29
|
}
|
30
30
|
toJSON() {
|
31
31
|
return {
|
32
32
|
name: this.name,
|
33
|
-
message: this.message,
|
34
33
|
cause: this.cause,
|
34
|
+
message: this.message,
|
35
35
|
stack: this.stack,
|
36
36
|
toolName: this.toolName,
|
37
|
-
|
37
|
+
valueText: this.valueText,
|
38
38
|
};
|
39
39
|
}
|
40
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
|
+
});
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { JsonSchemaProducer } from "
|
2
|
-
import { Schema } from "
|
1
|
+
import { JsonSchemaProducer } from "../core/schema/JsonSchemaProducer.js";
|
2
|
+
import { Schema } from "../core/schema/Schema.js";
|
3
3
|
export interface ToolDefinition<NAME extends string, PARAMETERS> {
|
4
4
|
name: NAME;
|
5
5
|
description?: string;
|
@@ -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({
|
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({
|
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({
|
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
|
}
|
package/tool/WebSearchTool.cjs
CHANGED
@@ -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
|
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
|
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
|
-
|
51
|
-
|
50
|
+
parameters: createParameters(queryDescription),
|
51
|
+
returnType: RETURN_TYPE_SCHEMA,
|
52
52
|
execute,
|
53
53
|
});
|
54
54
|
}
|
package/tool/WebSearchTool.d.ts
CHANGED
@@ -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
|
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
|
47
|
+
readonly returnType: typeof RETURN_TYPE_SCHEMA;
|
48
48
|
constructor({ name, description, queryDescription, execute, }: {
|
49
49
|
name: NAME;
|
50
50
|
description: string;
|