@illalabs/interfaces 0.3.0-canary.2110efe9 → 0.3.0-canary.361ed2fa
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/external.d.ts +1 -0
- package/dist/external.d.ts.map +1 -1
- package/dist/external.js +1 -0
- package/dist/external.js.map +1 -1
- package/dist/interfaces/chat/response.d.ts +3 -3
- package/dist/interfaces/chat/response.d.ts.map +1 -1
- package/dist/schemas/chatContext.d.ts +74 -659
- package/dist/schemas/chatContext.d.ts.map +1 -1
- package/dist/schemas/chatRequestBody.d.ts +232 -2206
- package/dist/schemas/chatRequestBody.d.ts.map +1 -1
- package/dist/schemas/chatRequestBody.js +3 -3
- package/dist/schemas/chatRequestBody.js.map +1 -1
- package/dist/schemas/executionCheckerQueryParams.d.ts +2 -2
- package/dist/schemas/illaTools.d.ts +266 -0
- package/dist/schemas/illaTools.d.ts.map +1 -0
- package/dist/schemas/illaTools.js +58 -0
- package/dist/schemas/illaTools.js.map +1 -0
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +1 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/messages.d.ts +74 -1048
- package/dist/schemas/messages.d.ts.map +1 -1
- package/dist/schemas/messages.js +3 -127
- package/dist/schemas/messages.js.map +1 -1
- package/dist/tools/IllaToolError.d.ts +113 -0
- package/dist/tools/IllaToolError.d.ts.map +1 -0
- package/dist/tools/IllaToolError.js +143 -0
- package/dist/tools/IllaToolError.js.map +1 -0
- package/dist/tools/IllaToolOutcome.d.ts +131 -0
- package/dist/tools/IllaToolOutcome.d.ts.map +1 -0
- package/dist/tools/IllaToolOutcome.js +191 -0
- package/dist/tools/IllaToolOutcome.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types/actions/tools/bridgeAction.d.ts +1 -1
- package/dist/types/actions/tools/bridgeAction.d.ts.map +1 -1
- package/dist/types/messages.d.ts +3 -6
- package/dist/types/messages.d.ts.map +1 -1
- package/dist/types/messages.js +1 -1
- package/dist/types/messages.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/schemas/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/schemas/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,qBAAqB;;;;;;;yBAUkB,CAAC,CAAC,OAAO,CAAC,mCAAmC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAalD,CAAC,CAAC,OAAO,CAAC,mCAAmC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWjF,CAAC;AAEd,eAAO,MAAM,YAAY;;;;;;;;;EAKZ,CAAC;AAEd,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAAiC,CAAC;AAEjE,eAAO,MAAM,aAAa,yEAAoC,CAAC"}
|
package/dist/schemas/messages.js
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
.object({
|
|
4
|
-
toolCallId: z.string(),
|
|
5
|
-
toolName: z.string(),
|
|
6
|
-
result: z.unknown(),
|
|
7
|
-
error: z.unknown().optional(),
|
|
8
|
-
})
|
|
9
|
-
.strict();
|
|
2
|
+
import { IllaToolOutcomeSchema } from "./illaTools.js";
|
|
10
3
|
export const PendingToolCallSchema = z
|
|
11
4
|
.object({
|
|
12
5
|
type: z.literal("tool-call"),
|
|
@@ -40,129 +33,12 @@ export const PendingToolCallSchema = z
|
|
|
40
33
|
]),
|
|
41
34
|
})
|
|
42
35
|
.strict();
|
|
43
|
-
export const
|
|
44
|
-
export const MessageSchema = z.string();
|
|
45
|
-
export const ToolIncompletePartSchema = z
|
|
46
|
-
.object({
|
|
47
|
-
type: z.literal("tool-incomplete"),
|
|
48
|
-
toolCallId: z.string(),
|
|
49
|
-
toolName: z.string(),
|
|
50
|
-
args: z.unknown(),
|
|
51
|
-
missingParams: z.array(z.string()),
|
|
52
|
-
humanReadableDescription: z.string(),
|
|
53
|
-
})
|
|
54
|
-
.strict();
|
|
55
|
-
export const ToolErrorPartSchema = z
|
|
56
|
-
.object({
|
|
57
|
-
type: z.literal("tool-error"),
|
|
58
|
-
toolCallId: z.string(),
|
|
59
|
-
toolName: z.string(),
|
|
60
|
-
error: z.unknown(),
|
|
61
|
-
})
|
|
62
|
-
.strict();
|
|
63
|
-
export const TextPartSchema = z
|
|
36
|
+
export const PromptSchema = z
|
|
64
37
|
.object({
|
|
65
38
|
type: z.literal("text"),
|
|
66
39
|
text: z.string(),
|
|
67
40
|
})
|
|
68
41
|
.strict();
|
|
69
|
-
|
|
70
|
-
* Discriminated union schema for tool calls based on toolName
|
|
71
|
-
* Each tool has its own specific args schema
|
|
72
|
-
*/
|
|
73
|
-
export const ToolCallPartSchema = z.discriminatedUnion("toolName", [
|
|
74
|
-
z
|
|
75
|
-
.object({
|
|
76
|
-
type: z.literal("tool-call"),
|
|
77
|
-
toolCallId: z.string(),
|
|
78
|
-
toolName: z.literal("tokenTransfer"),
|
|
79
|
-
args: z.unknown(),
|
|
80
|
-
})
|
|
81
|
-
.strict(),
|
|
82
|
-
z
|
|
83
|
-
.object({
|
|
84
|
-
type: z.literal("tool-call"),
|
|
85
|
-
toolCallId: z.string(),
|
|
86
|
-
toolName: z.literal("swap"),
|
|
87
|
-
args: z.unknown(),
|
|
88
|
-
})
|
|
89
|
-
.strict(),
|
|
90
|
-
z
|
|
91
|
-
.object({
|
|
92
|
-
type: z.literal("tool-call"),
|
|
93
|
-
toolCallId: z.string(),
|
|
94
|
-
toolName: z.literal("bridge"),
|
|
95
|
-
args: z.unknown(),
|
|
96
|
-
})
|
|
97
|
-
.strict(),
|
|
98
|
-
z
|
|
99
|
-
.object({
|
|
100
|
-
type: z.literal("tool-call"),
|
|
101
|
-
toolCallId: z.string(),
|
|
102
|
-
toolName: z.literal("exchangeRate"),
|
|
103
|
-
args: z.unknown(),
|
|
104
|
-
})
|
|
105
|
-
.strict(),
|
|
106
|
-
z
|
|
107
|
-
.object({
|
|
108
|
-
type: z.literal("tool-call"),
|
|
109
|
-
toolCallId: z.string(),
|
|
110
|
-
toolName: z.literal("getWalletBalance"),
|
|
111
|
-
args: z.unknown(),
|
|
112
|
-
})
|
|
113
|
-
.strict(),
|
|
114
|
-
z
|
|
115
|
-
.object({
|
|
116
|
-
type: z.literal("tool-call"),
|
|
117
|
-
toolCallId: z.string(),
|
|
118
|
-
toolName: z.literal("defiFetchListings"),
|
|
119
|
-
args: z.unknown(),
|
|
120
|
-
})
|
|
121
|
-
.strict(),
|
|
122
|
-
z
|
|
123
|
-
.object({
|
|
124
|
-
type: z.literal("tool-call"),
|
|
125
|
-
toolCallId: z.string(),
|
|
126
|
-
toolName: z.literal("defiSupply"),
|
|
127
|
-
args: z.unknown(),
|
|
128
|
-
})
|
|
129
|
-
.strict(),
|
|
130
|
-
z
|
|
131
|
-
.object({
|
|
132
|
-
type: z.literal("tool-call"),
|
|
133
|
-
toolCallId: z.string(),
|
|
134
|
-
toolName: z.literal("defiWithdraw"),
|
|
135
|
-
args: z.unknown(),
|
|
136
|
-
})
|
|
137
|
-
.strict(),
|
|
138
|
-
z
|
|
139
|
-
.object({
|
|
140
|
-
type: z.literal("tool-call"),
|
|
141
|
-
toolCallId: z.string(),
|
|
142
|
-
toolName: z.literal("defiPositions"),
|
|
143
|
-
args: z.unknown(),
|
|
144
|
-
})
|
|
145
|
-
.strict(),
|
|
146
|
-
]);
|
|
147
|
-
export const ToolResultPartSchema = z
|
|
148
|
-
.object({
|
|
149
|
-
type: z.literal("tool-result"),
|
|
150
|
-
toolCallId: z.string(),
|
|
151
|
-
toolName: z.string(),
|
|
152
|
-
result: z.unknown(),
|
|
153
|
-
})
|
|
154
|
-
.strict();
|
|
155
|
-
export const CoreMessageSchema = z
|
|
156
|
-
.object({
|
|
157
|
-
role: z.enum(["user", "assistant", "tool", "system"]),
|
|
158
|
-
content: z.array(z.union([
|
|
159
|
-
TextPartSchema,
|
|
160
|
-
ToolCallPartSchema,
|
|
161
|
-
ToolResultPartSchema,
|
|
162
|
-
ToolIncompletePartSchema,
|
|
163
|
-
ToolErrorPartSchema,
|
|
164
|
-
])),
|
|
165
|
-
})
|
|
166
|
-
.strict();
|
|
42
|
+
export const ToolOutcomesSchema = z.array(IllaToolOutcomeSchema);
|
|
167
43
|
export const HistorySchema = z.array(z.custom());
|
|
168
44
|
//# sourceMappingURL=messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/schemas/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/schemas/messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBA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OAAO,CAAC,MAAM,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC;KACD,MAAM,EAAE,CAAC;AAEd,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { IllaToolErrorData, IllaToolExecutionErrorData, IllaToolInputErrorData } from "../internal.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an error that occurred during tool call validation or execution.
|
|
4
|
+
* This is a structured error class that distinguishes between input validation
|
|
5
|
+
* errors and execution errors.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Create an input validation error
|
|
10
|
+
* const inputError = IllaToolError.input('call-123', 'tokenTransfer', [
|
|
11
|
+
* { path: 'amount', message: 'Amount is required' }
|
|
12
|
+
* ]);
|
|
13
|
+
*
|
|
14
|
+
* // Create an execution error
|
|
15
|
+
* const execError = IllaToolError.execution('call-123', 'tokenTransfer', 'Network timeout');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class IllaToolError {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly data: IllaToolErrorData;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new IllaToolError instance
|
|
24
|
+
* @param id - The tool call ID this error is associated with
|
|
25
|
+
* @param name - The name of the tool/action that errored
|
|
26
|
+
* @param data - The structured error data
|
|
27
|
+
*/
|
|
28
|
+
private constructor();
|
|
29
|
+
/**
|
|
30
|
+
* The type of error ("input" or "execution")
|
|
31
|
+
*/
|
|
32
|
+
get type(): "input" | "execution";
|
|
33
|
+
/**
|
|
34
|
+
* Creates an input validation error
|
|
35
|
+
* @param id - The tool call ID
|
|
36
|
+
* @param name - The tool/action name
|
|
37
|
+
* @param errors - Array of validation errors with path and message
|
|
38
|
+
* @returns A new IllaToolError representing input validation failure
|
|
39
|
+
*/
|
|
40
|
+
static input(id: string, name: string, errors: Array<{
|
|
41
|
+
path: string;
|
|
42
|
+
message: string;
|
|
43
|
+
}>): IllaToolError;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an execution error
|
|
46
|
+
* @param id - The tool call ID
|
|
47
|
+
* @param name - The tool/action name
|
|
48
|
+
* @param message - Human-readable error message
|
|
49
|
+
* @param details - Optional additional error details
|
|
50
|
+
* @returns A new IllaToolError representing execution failure
|
|
51
|
+
*/
|
|
52
|
+
static execution(id: string, name: string, message: string, details?: unknown): IllaToolError;
|
|
53
|
+
/**
|
|
54
|
+
* Parses and validates unknown input to create an IllaToolError instance.
|
|
55
|
+
* Expects an object with id, name, and data properties.
|
|
56
|
+
*
|
|
57
|
+
* @param input - Unknown input to parse
|
|
58
|
+
* @returns A new IllaToolError instance
|
|
59
|
+
* @throws ZodError if the input doesn't match the expected schema
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const error = IllaToolError.parse({
|
|
64
|
+
* id: 'call-123',
|
|
65
|
+
* name: 'tokenTransfer',
|
|
66
|
+
* data: { type: 'execution', message: 'Failed' }
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
static parse(input: unknown): IllaToolError;
|
|
71
|
+
/**
|
|
72
|
+
* Parses error data and creates an IllaToolError with the provided id and name.
|
|
73
|
+
* Useful when reconstructing from IllaToolOutcome where id/name are separate.
|
|
74
|
+
*
|
|
75
|
+
* @param id - The tool call ID
|
|
76
|
+
* @param name - The tool/action name
|
|
77
|
+
* @param data - Unknown error data to parse
|
|
78
|
+
* @returns A new IllaToolError instance
|
|
79
|
+
* @throws ZodError if the data doesn't match the expected schema
|
|
80
|
+
*/
|
|
81
|
+
static parseData(id: string, name: string, data: unknown): IllaToolError;
|
|
82
|
+
/**
|
|
83
|
+
* Check if this is an input validation error
|
|
84
|
+
*/
|
|
85
|
+
isInputError(): this is IllaToolError & {
|
|
86
|
+
data: IllaToolInputErrorData;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Check if this is an execution error
|
|
90
|
+
*/
|
|
91
|
+
isExecutionError(): this is IllaToolError & {
|
|
92
|
+
data: IllaToolExecutionErrorData;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Get the validation errors if this is an input error
|
|
96
|
+
* @returns Array of validation errors or undefined if not an input error
|
|
97
|
+
*/
|
|
98
|
+
getValidationErrors(): Array<{
|
|
99
|
+
path: string;
|
|
100
|
+
message: string;
|
|
101
|
+
}> | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Get the error message
|
|
104
|
+
* @returns The error message (for execution errors) or a summary of validation errors
|
|
105
|
+
*/
|
|
106
|
+
getMessage(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Convert to a plain JSON object for serialization
|
|
109
|
+
* @returns The error data object
|
|
110
|
+
*/
|
|
111
|
+
toJSON(): IllaToolErrorData;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=IllaToolError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IllaToolError.d.ts","sourceRoot":"","sources":["../../src/tools/IllaToolError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,iBAAiB,EACjB,0BAA0B,EAC1B,sBAAsB,EACzB,MAAM,gBAAgB,CAAC;AAGxB;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAa;aAQF,EAAE,EAAE,MAAM;aACV,IAAI,EAAE,MAAM;aACZ,IAAI,EAAE,iBAAiB;IAT3C;;;;;OAKG;IACH,OAAO;IAMP;;OAEG;IACH,IAAW,IAAI,IAAI,OAAO,GAAG,WAAW,CAEvC;IAED;;;;;;OAMG;WACW,KAAK,CACf,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GACjD,aAAa;IAOhB;;;;;;;OAOG;WACW,SAAS,CACnB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,GAClB,aAAa;IAQhB;;;;;;;;;;;;;;;;OAgBG;WACW,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa;IAKlD;;;;;;;;;OASG;WACW,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,aAAa;IAK/E;;OAEG;IACI,YAAY,IAAI,IAAI,IAAI,aAAa,GAAG;QAAE,IAAI,EAAE,sBAAsB,CAAA;KAAE;IAI/E;;OAEG;IACI,gBAAgB,IAAI,IAAI,IAAI,aAAa,GAAG;QAAE,IAAI,EAAE,0BAA0B,CAAA;KAAE;IAIvF;;;OAGG;IACI,mBAAmB,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,SAAS;IAOlF;;;OAGG;IACI,UAAU,IAAI,MAAM;IAQ3B;;;OAGG;IACI,MAAM,IAAI,iBAAiB;CAGrC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { IllaToolErrorDataSchema, IllaToolErrorSchema } from "../internal.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents an error that occurred during tool call validation or execution.
|
|
4
|
+
* This is a structured error class that distinguishes between input validation
|
|
5
|
+
* errors and execution errors.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Create an input validation error
|
|
10
|
+
* const inputError = IllaToolError.input('call-123', 'tokenTransfer', [
|
|
11
|
+
* { path: 'amount', message: 'Amount is required' }
|
|
12
|
+
* ]);
|
|
13
|
+
*
|
|
14
|
+
* // Create an execution error
|
|
15
|
+
* const execError = IllaToolError.execution('call-123', 'tokenTransfer', 'Network timeout');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class IllaToolError {
|
|
19
|
+
id;
|
|
20
|
+
name;
|
|
21
|
+
data;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new IllaToolError instance
|
|
24
|
+
* @param id - The tool call ID this error is associated with
|
|
25
|
+
* @param name - The name of the tool/action that errored
|
|
26
|
+
* @param data - The structured error data
|
|
27
|
+
*/
|
|
28
|
+
constructor(id, name, data) {
|
|
29
|
+
this.id = id;
|
|
30
|
+
this.name = name;
|
|
31
|
+
this.data = data;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The type of error ("input" or "execution")
|
|
35
|
+
*/
|
|
36
|
+
get type() {
|
|
37
|
+
return this.data.type;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates an input validation error
|
|
41
|
+
* @param id - The tool call ID
|
|
42
|
+
* @param name - The tool/action name
|
|
43
|
+
* @param errors - Array of validation errors with path and message
|
|
44
|
+
* @returns A new IllaToolError representing input validation failure
|
|
45
|
+
*/
|
|
46
|
+
static input(id, name, errors) {
|
|
47
|
+
return new IllaToolError(id, name, {
|
|
48
|
+
type: "input",
|
|
49
|
+
errors,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates an execution error
|
|
54
|
+
* @param id - The tool call ID
|
|
55
|
+
* @param name - The tool/action name
|
|
56
|
+
* @param message - Human-readable error message
|
|
57
|
+
* @param details - Optional additional error details
|
|
58
|
+
* @returns A new IllaToolError representing execution failure
|
|
59
|
+
*/
|
|
60
|
+
static execution(id, name, message, details) {
|
|
61
|
+
return new IllaToolError(id, name, {
|
|
62
|
+
type: "execution",
|
|
63
|
+
message,
|
|
64
|
+
details,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Parses and validates unknown input to create an IllaToolError instance.
|
|
69
|
+
* Expects an object with id, name, and data properties.
|
|
70
|
+
*
|
|
71
|
+
* @param input - Unknown input to parse
|
|
72
|
+
* @returns A new IllaToolError instance
|
|
73
|
+
* @throws ZodError if the input doesn't match the expected schema
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const error = IllaToolError.parse({
|
|
78
|
+
* id: 'call-123',
|
|
79
|
+
* name: 'tokenTransfer',
|
|
80
|
+
* data: { type: 'execution', message: 'Failed' }
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static parse(input) {
|
|
85
|
+
const parsed = IllaToolErrorSchema.parse(input);
|
|
86
|
+
return new IllaToolError(parsed.id, parsed.name, parsed.data);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Parses error data and creates an IllaToolError with the provided id and name.
|
|
90
|
+
* Useful when reconstructing from IllaToolOutcome where id/name are separate.
|
|
91
|
+
*
|
|
92
|
+
* @param id - The tool call ID
|
|
93
|
+
* @param name - The tool/action name
|
|
94
|
+
* @param data - Unknown error data to parse
|
|
95
|
+
* @returns A new IllaToolError instance
|
|
96
|
+
* @throws ZodError if the data doesn't match the expected schema
|
|
97
|
+
*/
|
|
98
|
+
static parseData(id, name, data) {
|
|
99
|
+
const parsedData = IllaToolErrorDataSchema.parse(data);
|
|
100
|
+
return new IllaToolError(id, name, parsedData);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check if this is an input validation error
|
|
104
|
+
*/
|
|
105
|
+
isInputError() {
|
|
106
|
+
return this.data.type === "input";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if this is an execution error
|
|
110
|
+
*/
|
|
111
|
+
isExecutionError() {
|
|
112
|
+
return this.data.type === "execution";
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the validation errors if this is an input error
|
|
116
|
+
* @returns Array of validation errors or undefined if not an input error
|
|
117
|
+
*/
|
|
118
|
+
getValidationErrors() {
|
|
119
|
+
if (this.isInputError()) {
|
|
120
|
+
return this.data.errors;
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the error message
|
|
126
|
+
* @returns The error message (for execution errors) or a summary of validation errors
|
|
127
|
+
*/
|
|
128
|
+
getMessage() {
|
|
129
|
+
if (this.data.type === "execution") {
|
|
130
|
+
return this.data.message;
|
|
131
|
+
}
|
|
132
|
+
const errors = this.data.errors;
|
|
133
|
+
return errors.map((error) => `${error.path}: ${error.message}`).join(", ");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert to a plain JSON object for serialization
|
|
137
|
+
* @returns The error data object
|
|
138
|
+
*/
|
|
139
|
+
toJSON() {
|
|
140
|
+
return this.data;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=IllaToolError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IllaToolError.js","sourceRoot":"","sources":["../../src/tools/IllaToolError.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE9E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,aAAa;IAQF;IACA;IACA;IATpB;;;;;OAKG;IACH,YACoB,EAAU,EACV,IAAY,EACZ,IAAuB;QAFvB,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAmB;IACxC,CAAC;IAEJ;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CACf,EAAU,EACV,IAAY,EACZ,MAAgD;QAEhD,OAAO,IAAI,aAAa,CAAC,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W,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;QAC7B,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/E,CAAC;IAED;;;OAGG;IACI,MAAM;QACT,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CACJ"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { IllaToolOutcomeJSON } from "../internal.js";
|
|
2
|
+
import { IllaToolError } from "./IllaToolError.js";
|
|
3
|
+
/**
|
|
4
|
+
* Represents the outcome of a tool execution, which can be either a success or an error.
|
|
5
|
+
* This implements the Result/Either pattern for explicit error handling.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of the successful result
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Create a successful outcome
|
|
12
|
+
* const success = IllaToolOutcome.success('call-123', 'tokenTransfer', { txHash: '0x...' });
|
|
13
|
+
*
|
|
14
|
+
* // Create an error outcome
|
|
15
|
+
* const error = IllaToolOutcome.error('call-123', 'tokenTransfer',
|
|
16
|
+
* IllaToolError.execution('call-123', 'tokenTransfer', 'Transaction failed')
|
|
17
|
+
* );
|
|
18
|
+
*
|
|
19
|
+
* // Handle the outcome
|
|
20
|
+
* if (outcome.isSuccess()) {
|
|
21
|
+
* console.log('Result:', outcome.getResult());
|
|
22
|
+
* } else {
|
|
23
|
+
* console.error('Error:', outcome.getError()?.getMessage());
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class IllaToolOutcome<T = unknown> {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
private readonly _result?;
|
|
31
|
+
private readonly _error?;
|
|
32
|
+
private readonly _isError;
|
|
33
|
+
private constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Creates a successful outcome
|
|
36
|
+
* @param id - The tool call ID
|
|
37
|
+
* @param name - The tool/action name
|
|
38
|
+
* @param result - The successful result value
|
|
39
|
+
* @returns A new IllaToolOutcome representing success
|
|
40
|
+
*/
|
|
41
|
+
static success<T>(id: string, name: string, result: T): IllaToolOutcome<T>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates an error outcome
|
|
44
|
+
* @param id - The tool call ID
|
|
45
|
+
* @param name - The tool/action name
|
|
46
|
+
* @param error - The error that occurred
|
|
47
|
+
* @returns A new IllaToolOutcome representing failure
|
|
48
|
+
*/
|
|
49
|
+
static error(id: string, name: string, error: IllaToolError): IllaToolOutcome<never>;
|
|
50
|
+
/**
|
|
51
|
+
* Parses and validates unknown input to create an IllaToolOutcome instance.
|
|
52
|
+
* Expects an object with id, name, and either result or error properties.
|
|
53
|
+
*
|
|
54
|
+
* @template T - The expected type of the result (defaults to unknown)
|
|
55
|
+
* @param input - Unknown input to parse
|
|
56
|
+
* @returns A new IllaToolOutcome instance
|
|
57
|
+
* @throws ZodError if the input doesn't match the expected schema
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // Parse a success outcome
|
|
62
|
+
* const success = IllaToolOutcome.parse<{ txHash: string }>({
|
|
63
|
+
* id: 'call-123',
|
|
64
|
+
* name: 'tokenTransfer',
|
|
65
|
+
* result: { txHash: '0x...' }
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Parse an error outcome
|
|
69
|
+
* const error = IllaToolOutcome.parse({
|
|
70
|
+
* id: 'call-456',
|
|
71
|
+
* name: 'swap',
|
|
72
|
+
* error: { type: 'execution', message: 'Failed' }
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static parse<T = unknown>(input: unknown): IllaToolOutcome<T>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if this outcome represents a successful execution
|
|
79
|
+
*/
|
|
80
|
+
isSuccess(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Check if this outcome represents an error
|
|
83
|
+
*/
|
|
84
|
+
isError(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Get the successful result value
|
|
87
|
+
* @returns The result value or undefined if this is an error outcome
|
|
88
|
+
*/
|
|
89
|
+
getResult(): T | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Get the error
|
|
92
|
+
* @returns The error or undefined if this is a success outcome
|
|
93
|
+
*/
|
|
94
|
+
getError(): IllaToolError | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Get the result or throw if this is an error
|
|
97
|
+
* @returns The result value
|
|
98
|
+
* @throws Error if this is an error outcome
|
|
99
|
+
*/
|
|
100
|
+
getResultOrThrow(): T;
|
|
101
|
+
/**
|
|
102
|
+
* Map the result value to a new type
|
|
103
|
+
* @param fn - Function to transform the result
|
|
104
|
+
* @returns A new IllaToolOutcome with the transformed result, or the same error
|
|
105
|
+
*/
|
|
106
|
+
map<U>(fn: (result: T) => U): IllaToolOutcome<U>;
|
|
107
|
+
/**
|
|
108
|
+
* Chain another operation that returns an IllaToolOutcome
|
|
109
|
+
* @param fn - Function that takes the result and returns a new IllaToolOutcome
|
|
110
|
+
* @returns The result of fn if successful, or the original error
|
|
111
|
+
*/
|
|
112
|
+
flatMap<U>(fn: (result: T) => IllaToolOutcome<U>): IllaToolOutcome<U>;
|
|
113
|
+
/**
|
|
114
|
+
* Execute a function if this is a success
|
|
115
|
+
* @param fn - Function to execute with the result
|
|
116
|
+
* @returns This outcome (for chaining)
|
|
117
|
+
*/
|
|
118
|
+
onSuccess(fn: (result: T) => void): this;
|
|
119
|
+
/**
|
|
120
|
+
* Execute a function if this is an error
|
|
121
|
+
* @param fn - Function to execute with the error
|
|
122
|
+
* @returns This outcome (for chaining)
|
|
123
|
+
*/
|
|
124
|
+
onError(fn: (error: IllaToolError) => void): this;
|
|
125
|
+
/**
|
|
126
|
+
* Convert to a plain JSON object for serialization
|
|
127
|
+
* @returns An object with either result or error
|
|
128
|
+
*/
|
|
129
|
+
toJSON(): IllaToolOutcomeJSON;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=IllaToolOutcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IllaToolOutcome.d.ts","sourceRoot":"","sources":["../../src/tools/IllaToolOutcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,eAAe,CAAC,CAAC,GAAG,OAAO;aAEhB,EAAE,EAAE,MAAM;aACV,IAAI,EAAE,MAAM;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL7B,OAAO;IAQP;;;;;;OAMG;WACW,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC;IAIjF;;;;;;OAMG;WACW,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,eAAe,CAAC,KAAK,CAAC;IAI3F;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACW,KAAK,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,eAAe,CAAC,CAAC,CAAC;IAWpE;;OAEG;IACI,SAAS,IAAI,OAAO;IAI3B;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACI,SAAS,I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