@illalabs/interfaces 0.3.0-canary.2110efe9 → 0.3.0-canary.3f75ecce
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/errors/endpoints/chat/ChatBaseError.d.ts +16 -5
- package/dist/errors/endpoints/chat/ChatBaseError.d.ts.map +1 -1
- 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 +5 -3
- package/dist/interfaces/chat/response.d.ts.map +1 -1
- package/dist/schemas/chatContext.d.ts +79 -648
- package/dist/schemas/chatContext.d.ts.map +1 -1
- package/dist/schemas/chatRequestBody.d.ts +256 -2172
- package/dist/schemas/chatRequestBody.d.ts.map +1 -1
- package/dist/schemas/chatRequestBody.js +5 -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 +2 -0
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +2 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/messages.d.ts +95 -1037
- package/dist/schemas/messages.d.ts.map +1 -1
- package/dist/schemas/messages.js +10 -121
- package/dist/schemas/messages.js.map +1 -1
- package/dist/schemas/telemetryEvents.d.ts +1159 -0
- package/dist/schemas/telemetryEvents.d.ts.map +1 -0
- package/dist/schemas/telemetryEvents.js +250 -0
- package/dist/schemas/telemetryEvents.js.map +1 -0
- 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/actions/tools/defiFetchListingsAction.d.ts +1 -2
- package/dist/types/actions/tools/defiFetchListingsAction.d.ts.map +1 -1
- package/dist/types/actions/tools/defiFetchListingsAction.js +1 -1
- package/dist/types/actions/tools/defiFetchListingsAction.js.map +1 -1
- package/dist/types/actions/tools/defiPositionsAction.d.ts +1 -2
- package/dist/types/actions/tools/defiPositionsAction.d.ts.map +1 -1
- package/dist/types/actions/tools/defiPositionsAction.js +1 -1
- package/dist/types/actions/tools/defiPositionsAction.js.map +1 -1
- package/dist/types/actions/tools/defiSupplyAction.d.ts +1 -2
- package/dist/types/actions/tools/defiSupplyAction.d.ts.map +1 -1
- package/dist/types/actions/tools/defiSupplyAction.js +1 -1
- package/dist/types/actions/tools/defiSupplyAction.js.map +1 -1
- package/dist/types/actions/tools/defiWithdrawAction.d.ts +1 -2
- package/dist/types/actions/tools/defiWithdrawAction.d.ts.map +1 -1
- package/dist/types/actions/tools/defiWithdrawAction.js +1 -1
- package/dist/types/actions/tools/defiWithdrawAction.js.map +1 -1
- package/dist/types/actions/tools/exchangeRateAction.d.ts +1 -2
- package/dist/types/actions/tools/exchangeRateAction.d.ts.map +1 -1
- package/dist/types/actions/tools/exchangeRateAction.js +1 -1
- package/dist/types/actions/tools/exchangeRateAction.js.map +1 -1
- package/dist/types/actions/tools/getWalletBalanceAction.d.ts +1 -2
- package/dist/types/actions/tools/getWalletBalanceAction.d.ts.map +1 -1
- package/dist/types/actions/tools/getWalletBalanceAction.js +1 -1
- package/dist/types/actions/tools/getWalletBalanceAction.js.map +1 -1
- package/dist/types/actions/tools/tokenTransferAction.d.ts +1 -2
- package/dist/types/actions/tools/tokenTransferAction.d.ts.map +1 -1
- package/dist/types/actions/tools/tokenTransferAction.js +1 -1
- package/dist/types/actions/tools/tokenTransferAction.js.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.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/dist/types/streaming.d.ts +81 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +2 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/telemetry.d.ts +139 -0
- package/dist/types/telemetry.d.ts.map +1 -0
- package/dist/types/telemetry.js +7 -0
- package/dist/types/telemetry.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryEvents.d.ts","sourceRoot":"","sources":["../../src/schemas/telemetryEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,yLAatB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAInC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;EAE/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;EAExC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;EAKpC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOlC,CAAC;AAEH;;G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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAa/B,CAAC;AAqCH;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAShC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQ/B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;EAInC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIhC,CAAC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Telemetry event type enum values.
|
|
4
|
+
* Used to infer TelemetryEventType in types/telemetry.ts
|
|
5
|
+
*/
|
|
6
|
+
export const telemetryEventTypes = [
|
|
7
|
+
"iteration_start",
|
|
8
|
+
"iteration_end",
|
|
9
|
+
"tool_call_batch",
|
|
10
|
+
"tool_result",
|
|
11
|
+
"scratchpad_reset",
|
|
12
|
+
"llm_start",
|
|
13
|
+
"llm_end",
|
|
14
|
+
"text_delta",
|
|
15
|
+
"finish",
|
|
16
|
+
"error",
|
|
17
|
+
"connected",
|
|
18
|
+
"stream_end",
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* Base telemetry event schema with common fields
|
|
22
|
+
*/
|
|
23
|
+
export const baseTelemetryEventSchema = z.object({
|
|
24
|
+
requestId: z.string(),
|
|
25
|
+
type: z.enum(telemetryEventTypes),
|
|
26
|
+
timestamp: z.number().optional(),
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Connected event schema - emitted when connected to telemetry stream
|
|
30
|
+
*/
|
|
31
|
+
export const connectedEventSchema = baseTelemetryEventSchema.extend({
|
|
32
|
+
type: z.literal("connected"),
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Stream end telemetry event schema - emitted when stream ends
|
|
36
|
+
*/
|
|
37
|
+
export const streamEndTelemetryEventSchema = baseTelemetryEventSchema.extend({
|
|
38
|
+
type: z.literal("stream_end"),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Iteration start event schema - emitted when an iteration starts
|
|
42
|
+
*/
|
|
43
|
+
export const iterationStartEventSchema = baseTelemetryEventSchema.extend({
|
|
44
|
+
type: z.literal("iteration_start"),
|
|
45
|
+
data: z.object({
|
|
46
|
+
iteration: z.number(),
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Iteration end event schema - emitted when an iteration ends
|
|
51
|
+
*/
|
|
52
|
+
export const iterationEndEventSchema = baseTelemetryEventSchema.extend({
|
|
53
|
+
type: z.literal("iteration_end"),
|
|
54
|
+
data: z.object({
|
|
55
|
+
iteration: z.number(),
|
|
56
|
+
hasToolCalls: z.boolean(),
|
|
57
|
+
shouldContinue: z.boolean(),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Tool call batch event schema - emitted when tool calls are batched for execution
|
|
62
|
+
*/
|
|
63
|
+
export const toolCallBatchEventSchema = baseTelemetryEventSchema.extend({
|
|
64
|
+
type: z.literal("tool_call_batch"),
|
|
65
|
+
data: z.object({
|
|
66
|
+
iteration: z.number(),
|
|
67
|
+
tools: z.array(z.object({
|
|
68
|
+
toolCallId: z.string(),
|
|
69
|
+
toolName: z.string(),
|
|
70
|
+
})),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Tool result event schema - emitted when a tool execution completes
|
|
75
|
+
*/
|
|
76
|
+
export const toolResultEventSchema = baseTelemetryEventSchema.extend({
|
|
77
|
+
type: z.literal("tool_result"),
|
|
78
|
+
data: z.discriminatedUnion("status", [
|
|
79
|
+
z.object({
|
|
80
|
+
toolCallId: z.string(),
|
|
81
|
+
toolName: z.string(),
|
|
82
|
+
status: z.literal("pending"),
|
|
83
|
+
}),
|
|
84
|
+
z.object({
|
|
85
|
+
toolCallId: z.string(),
|
|
86
|
+
toolName: z.string(),
|
|
87
|
+
status: z.literal("success"),
|
|
88
|
+
}),
|
|
89
|
+
z.object({
|
|
90
|
+
toolCallId: z.string(),
|
|
91
|
+
toolName: z.string(),
|
|
92
|
+
status: z.literal("failure"),
|
|
93
|
+
error: z.string(),
|
|
94
|
+
}),
|
|
95
|
+
]),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Scratchpad reset event schema - emitted when the scratchpad is reset
|
|
99
|
+
*/
|
|
100
|
+
export const scratchpadResetEventSchema = baseTelemetryEventSchema.extend({
|
|
101
|
+
type: z.literal("scratchpad_reset"),
|
|
102
|
+
data: z.object({
|
|
103
|
+
reason: z.string(),
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* LLM start event schema - emitted when LLM generation starts
|
|
108
|
+
*/
|
|
109
|
+
export const llmStartEventSchema = baseTelemetryEventSchema.extend({
|
|
110
|
+
type: z.literal("llm_start"),
|
|
111
|
+
data: z.object({
|
|
112
|
+
iteration: z.number(),
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* LLM end event schema - emitted when LLM generation ends
|
|
117
|
+
*/
|
|
118
|
+
export const llmEndEventSchema = baseTelemetryEventSchema.extend({
|
|
119
|
+
type: z.literal("llm_end"),
|
|
120
|
+
data: z.object({
|
|
121
|
+
iteration: z.number(),
|
|
122
|
+
hasText: z.boolean(),
|
|
123
|
+
toolCallCount: z.number(),
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Text delta event schema - emitted when a text chunk is received from LLM
|
|
128
|
+
*/
|
|
129
|
+
export const textDeltaEventSchema = baseTelemetryEventSchema.extend({
|
|
130
|
+
type: z.literal("text_delta"),
|
|
131
|
+
data: z.object({
|
|
132
|
+
delta: z.string(),
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* Finish event schema - emitted when orchestration finishes
|
|
137
|
+
*/
|
|
138
|
+
export const finishEventSchema = baseTelemetryEventSchema.extend({
|
|
139
|
+
type: z.literal("finish"),
|
|
140
|
+
data: z.object({
|
|
141
|
+
totalIterations: z.number(),
|
|
142
|
+
hasPendingTools: z.boolean(),
|
|
143
|
+
hasToolErrors: z.boolean(),
|
|
144
|
+
}),
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* Error telemetry event schema - emitted when an error occurs.
|
|
148
|
+
* The data field is always present per the ErrorEvent type definition.
|
|
149
|
+
*/
|
|
150
|
+
export const errorTelemetryEventSchema = baseTelemetryEventSchema.extend({
|
|
151
|
+
type: z.literal("error"),
|
|
152
|
+
data: z.object({
|
|
153
|
+
message: z.string(),
|
|
154
|
+
code: z.string().optional(),
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
/**
|
|
158
|
+
* Schema for validating telemetry events.
|
|
159
|
+
* Discriminated union using the "type" field.
|
|
160
|
+
*/
|
|
161
|
+
export const telemetryEventSchema = z.discriminatedUnion("type", [
|
|
162
|
+
connectedEventSchema,
|
|
163
|
+
streamEndTelemetryEventSchema,
|
|
164
|
+
iterationStartEventSchema,
|
|
165
|
+
iterationEndEventSchema,
|
|
166
|
+
toolCallBatchEventSchema,
|
|
167
|
+
toolResultEventSchema,
|
|
168
|
+
scratchpadResetEventSchema,
|
|
169
|
+
llmStartEventSchema,
|
|
170
|
+
llmEndEventSchema,
|
|
171
|
+
textDeltaEventSchema,
|
|
172
|
+
finishEventSchema,
|
|
173
|
+
errorTelemetryEventSchema,
|
|
174
|
+
]);
|
|
175
|
+
/**
|
|
176
|
+
* Message schema for result events.
|
|
177
|
+
* Uses z.custom<ModelMessage>() to ensure type compatibility with the AI SDK's
|
|
178
|
+
* ModelMessage type. Runtime validation of the message structure happens at the
|
|
179
|
+
* API layer; this schema trusts the structure and preserves the correct TypeScript type.
|
|
180
|
+
*/
|
|
181
|
+
const messageSchema = z.custom();
|
|
182
|
+
/**
|
|
183
|
+
* Pending tool call schema for result events
|
|
184
|
+
*/
|
|
185
|
+
const pendingToolCallSchema = z.object({
|
|
186
|
+
toolCallId: z.string(),
|
|
187
|
+
toolName: z.string(),
|
|
188
|
+
toolInput: z.unknown(),
|
|
189
|
+
});
|
|
190
|
+
/**
|
|
191
|
+
* Tool error schema for result events
|
|
192
|
+
*/
|
|
193
|
+
const toolErrorSchema = z.object({
|
|
194
|
+
toolCallId: z.string(),
|
|
195
|
+
toolName: z.string(),
|
|
196
|
+
error: z.string(),
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* Incomplete tool call schema for result events
|
|
200
|
+
*/
|
|
201
|
+
const incompleteToolCallSchema = z.object({
|
|
202
|
+
toolCallId: z.string(),
|
|
203
|
+
toolName: z.string(),
|
|
204
|
+
toolInput: z.unknown().optional(),
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* Schema for validating result events from the streaming endpoint.
|
|
208
|
+
* Uses type: "result" as discriminator for consistency with other event schemas.
|
|
209
|
+
* Also includes status: 200 for backward compatibility with CoreApiChatSuccessResponse.
|
|
210
|
+
*/
|
|
211
|
+
export const resultEventDataSchema = z.object({
|
|
212
|
+
type: z.literal("result"),
|
|
213
|
+
status: z.literal(200),
|
|
214
|
+
messages: z.array(messageSchema),
|
|
215
|
+
text: z.string(),
|
|
216
|
+
pendingTools: z.array(pendingToolCallSchema).optional(),
|
|
217
|
+
incompleteTools: z.array(incompleteToolCallSchema).optional(),
|
|
218
|
+
toolErrors: z.array(toolErrorSchema).optional(),
|
|
219
|
+
requestId: z.string(),
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* Schema for validating error events from the streaming endpoint
|
|
223
|
+
*/
|
|
224
|
+
export const errorEventDataSchema = z.object({
|
|
225
|
+
type: z.literal("error"),
|
|
226
|
+
requestId: z.string(),
|
|
227
|
+
timestamp: z.number().optional(),
|
|
228
|
+
data: z.object({
|
|
229
|
+
message: z.string(),
|
|
230
|
+
code: z.string().optional(),
|
|
231
|
+
}),
|
|
232
|
+
});
|
|
233
|
+
/**
|
|
234
|
+
* Schema for validating stream_end events from the streaming endpoint
|
|
235
|
+
*/
|
|
236
|
+
export const streamEndEventDataSchema = z.object({
|
|
237
|
+
type: z.literal("stream_end"),
|
|
238
|
+
requestId: z.string(),
|
|
239
|
+
timestamp: z.number().optional(),
|
|
240
|
+
});
|
|
241
|
+
/**
|
|
242
|
+
* Unified discriminated union for all stream event data types.
|
|
243
|
+
* Uses "type" as the discriminator field for runtime validation.
|
|
244
|
+
*/
|
|
245
|
+
export const streamEventDataSchema = z.discriminatedUnion("type", [
|
|
246
|
+
resultEventDataSchema,
|
|
247
|
+
errorEventDataSchema,
|
|
248
|
+
streamEndEventDataSchema,
|
|
249
|
+
]);
|
|
250
|
+
//# sourceMappingURL=telemetryEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetryEvents.js","sourceRoot":"","sources":["../../src/schemas/telemetryEvents.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,iBAAiB;IACjB,eAAe;IACf,iBAAiB;IACjB,aAAa;IACb,kBAAkB;IAClB,WAAW;IACX,SAAS;IACT,YAAY;IACZ,QAAQ;IACR,OAAO;IACP,WAAW;IACX,YAAY;CACN,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,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E;CACnC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC9D,qBAAqB;IACrB,oBAAoB;IACpB,wBAAwB;CAC3B,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,EAAE,EAAE,IAAI,EAAE;YAC/B,IAAI,EAAE,OAAO;YACb,MAAM;SACT,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;OAOG;IAC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C,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,IAAI,CAAC,GAAG,SAAS;IAIjC;;;OAGG;IACI,QAAQ,IAAI,aAAa,GAAG,SAAS;IAI5C;;;;OAIG;IACI,gBAAgB,IAA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