@chaoslabs/ai-sdk 0.0.11 → 1.0.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/CHANGELOG.md +98 -0
- package/README.md +42 -13
- package/dist/blocks.d.ts +12 -4
- package/dist/blocks.js +18 -6
- package/dist/conversation.d.ts +5 -2
- package/dist/conversation.js +15 -25
- package/dist/index.d.ts +9 -6
- package/dist/index.js +33 -2
- package/dist/primitives.d.ts +458 -0
- package/dist/primitives.js +1 -0
- package/dist/request.d.ts +14 -12
- package/dist/request.js +42 -12
- package/dist/response.js +15 -24
- package/dist/schemas.d.ts +5728 -577
- package/dist/schemas.js +583 -92
- package/dist/stream.js +8 -4
- package/dist/type-guards.d.ts +316 -0
- package/dist/type-guards.js +373 -0
- package/dist/types.d.ts +87 -110
- package/dist/types.js +3 -2
- package/package.json +6 -8
package/dist/stream.js
CHANGED
|
@@ -34,7 +34,11 @@ export function parseAgentStatus(msg) {
|
|
|
34
34
|
if (msg.type !== "agent_status_change") {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
const status = msg.content?.status;
|
|
38
|
+
if (!status || !VALID_STATUSES.includes(status)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return status;
|
|
38
42
|
}
|
|
39
43
|
const TERMINAL_STATUSES = ["done", "error", "cancelled"];
|
|
40
44
|
export function isTerminalStatus(status) {
|
|
@@ -47,19 +51,19 @@ export function extractAgentMessageText(msg) {
|
|
|
47
51
|
if (msg.type !== "agent_message") {
|
|
48
52
|
return null;
|
|
49
53
|
}
|
|
50
|
-
return msg.content
|
|
54
|
+
return msg.content?.data?.message ?? null;
|
|
51
55
|
}
|
|
52
56
|
export function extractSuggestions(msg) {
|
|
53
57
|
if (msg.type !== "follow_up_suggestions") {
|
|
54
58
|
return [];
|
|
55
59
|
}
|
|
56
|
-
return msg.content
|
|
60
|
+
return msg.content?.data?.followUpQueries ?? [];
|
|
57
61
|
}
|
|
58
62
|
export function extractReportBlock(msg) {
|
|
59
63
|
if (msg.type !== "report") {
|
|
60
64
|
return null;
|
|
61
65
|
}
|
|
62
|
-
return msg.content
|
|
66
|
+
return msg.content?.data ?? null;
|
|
63
67
|
}
|
|
64
68
|
// ============================================================================
|
|
65
69
|
// Stream Parser
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import type { Block, ChartBlock, InfoBlock, CodeBlock } from './types.js';
|
|
2
|
+
import type { Primitive, SwapPrimitive, BridgePrimitive, SupplyPrimitive, WithdrawPrimitive, BorrowPrimitive, RepayPrimitive, StakePrimitive, UnstakePrimitive, ClaimPrimitive, AddLiquidityPrimitive, RemoveLiquidityPrimitive, OpenPositionPrimitive, ClosePositionPrimitive, DepositPrimitive, MintPrimitive, BurnPrimitive, RestakePrimitive, ApprovePrimitive, TransferPrimitive, WrapPrimitive, UnwrapPrimitive } from './primitives.js';
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a primitive is a swap operation.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* if (isSwapPrimitive(primitive)) {
|
|
9
|
+
* // TypeScript knows primitive.params is SwapParams
|
|
10
|
+
* console.log(primitive.params.token_in);
|
|
11
|
+
* console.log(primitive.params.token_out);
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function isSwapPrimitive(p: Primitive): p is SwapPrimitive;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if a primitive is a bridge operation.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* if (isBridgePrimitive(primitive)) {
|
|
22
|
+
* // TypeScript knows primitive.params is BridgeParams
|
|
23
|
+
* console.log(primitive.params.from_chain);
|
|
24
|
+
* console.log(primitive.params.to_chain);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function isBridgePrimitive(p: Primitive): p is BridgePrimitive;
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if a primitive is a supply operation.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* if (isSupplyPrimitive(primitive)) {
|
|
35
|
+
* // TypeScript knows primitive.params is LendingParams
|
|
36
|
+
* console.log(primitive.params.asset);
|
|
37
|
+
* console.log(primitive.params.amount);
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function isSupplyPrimitive(p: Primitive): p is SupplyPrimitive;
|
|
42
|
+
/**
|
|
43
|
+
* Type guard to check if a primitive is a withdraw operation.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* if (isWithdrawPrimitive(primitive)) {
|
|
48
|
+
* // TypeScript knows primitive.params is LendingParams
|
|
49
|
+
* console.log(primitive.params.asset);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function isWithdrawPrimitive(p: Primitive): p is WithdrawPrimitive;
|
|
54
|
+
/**
|
|
55
|
+
* Type guard to check if a primitive is a borrow operation.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* if (isBorrowPrimitive(primitive)) {
|
|
60
|
+
* // TypeScript knows primitive.params is LendingParams
|
|
61
|
+
* console.log(primitive.params.asset);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function isBorrowPrimitive(p: Primitive): p is BorrowPrimitive;
|
|
66
|
+
/**
|
|
67
|
+
* Type guard to check if a primitive is a repay operation.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* if (isRepayPrimitive(primitive)) {
|
|
72
|
+
* // TypeScript knows primitive.params is LendingParams
|
|
73
|
+
* console.log(primitive.params.asset);
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function isRepayPrimitive(p: Primitive): p is RepayPrimitive;
|
|
78
|
+
/**
|
|
79
|
+
* Type guard to check if a primitive is a stake operation.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* if (isStakePrimitive(primitive)) {
|
|
84
|
+
* // TypeScript knows primitive.params is StakingParams
|
|
85
|
+
* console.log(primitive.params.amount);
|
|
86
|
+
* console.log(primitive.params.protocol);
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function isStakePrimitive(p: Primitive): p is StakePrimitive;
|
|
91
|
+
/**
|
|
92
|
+
* Type guard to check if a primitive is an unstake operation.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* if (isUnstakePrimitive(primitive)) {
|
|
97
|
+
* // TypeScript knows primitive.params is StakingParams
|
|
98
|
+
* console.log(primitive.params.amount);
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function isUnstakePrimitive(p: Primitive): p is UnstakePrimitive;
|
|
103
|
+
/**
|
|
104
|
+
* Type guard to check if a primitive is a claim operation.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* if (isClaimPrimitive(primitive)) {
|
|
109
|
+
* // TypeScript knows primitive.params is ClaimParams
|
|
110
|
+
* console.log(primitive.params.protocol);
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function isClaimPrimitive(p: Primitive): p is ClaimPrimitive;
|
|
115
|
+
/**
|
|
116
|
+
* Type guard to check if a primitive is an add liquidity operation.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* if (isAddLiquidityPrimitive(primitive)) {
|
|
121
|
+
* // TypeScript knows primitive.params is LiquidityParams
|
|
122
|
+
* console.log(primitive.params.token_a);
|
|
123
|
+
* console.log(primitive.params.token_b);
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function isAddLiquidityPrimitive(p: Primitive): p is AddLiquidityPrimitive;
|
|
128
|
+
/**
|
|
129
|
+
* Type guard to check if a primitive is a remove liquidity operation.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* if (isRemoveLiquidityPrimitive(primitive)) {
|
|
134
|
+
* // TypeScript knows primitive.params is LiquidityParams
|
|
135
|
+
* console.log(primitive.params.token_a);
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function isRemoveLiquidityPrimitive(p: Primitive): p is RemoveLiquidityPrimitive;
|
|
140
|
+
/**
|
|
141
|
+
* Type guard to check if a primitive is an open position operation.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* if (isOpenPositionPrimitive(primitive)) {
|
|
146
|
+
* // TypeScript knows primitive.params is PositionParams
|
|
147
|
+
* console.log(primitive.params.market);
|
|
148
|
+
* console.log(primitive.params.side);
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function isOpenPositionPrimitive(p: Primitive): p is OpenPositionPrimitive;
|
|
153
|
+
/**
|
|
154
|
+
* Type guard to check if a primitive is a close position operation.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* if (isClosePositionPrimitive(primitive)) {
|
|
159
|
+
* // TypeScript knows primitive.params is PositionParams
|
|
160
|
+
* console.log(primitive.params.market);
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare function isClosePositionPrimitive(p: Primitive): p is ClosePositionPrimitive;
|
|
165
|
+
/**
|
|
166
|
+
* Type guard to check if a primitive is a deposit operation.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* if (isDepositPrimitive(primitive)) {
|
|
171
|
+
* // TypeScript knows primitive.params is DepositParams
|
|
172
|
+
* console.log(primitive.params.vault);
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare function isDepositPrimitive(p: Primitive): p is DepositPrimitive;
|
|
177
|
+
/**
|
|
178
|
+
* Type guard to check if a primitive is a mint operation.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* if (isMintPrimitive(primitive)) {
|
|
183
|
+
* // TypeScript knows primitive.params is MintParams
|
|
184
|
+
* console.log(primitive.params.asset);
|
|
185
|
+
* console.log(primitive.params.collateral);
|
|
186
|
+
* }
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export declare function isMintPrimitive(p: Primitive): p is MintPrimitive;
|
|
190
|
+
/**
|
|
191
|
+
* Type guard to check if a primitive is a burn operation.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* if (isBurnPrimitive(primitive)) {
|
|
196
|
+
* // TypeScript knows primitive.params is MintParams
|
|
197
|
+
* console.log(primitive.params.asset);
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export declare function isBurnPrimitive(p: Primitive): p is BurnPrimitive;
|
|
202
|
+
/**
|
|
203
|
+
* Type guard to check if a primitive is a restake operation.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* if (isRestakePrimitive(primitive)) {
|
|
208
|
+
* // TypeScript knows primitive.params is StakingParams
|
|
209
|
+
* console.log(primitive.params.amount);
|
|
210
|
+
* console.log(primitive.params.operator);
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export declare function isRestakePrimitive(p: Primitive): p is RestakePrimitive;
|
|
215
|
+
/**
|
|
216
|
+
* Type guard to check if a primitive is an approve operation.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* if (isApprovePrimitive(primitive)) {
|
|
221
|
+
* // TypeScript knows primitive.params is ApproveParams
|
|
222
|
+
* console.log(primitive.params.token);
|
|
223
|
+
* console.log(primitive.params.spender);
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
export declare function isApprovePrimitive(p: Primitive): p is ApprovePrimitive;
|
|
228
|
+
/**
|
|
229
|
+
* Type guard to check if a primitive is a transfer operation.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* if (isTransferPrimitive(primitive)) {
|
|
234
|
+
* // TypeScript knows primitive.params is TransferParams
|
|
235
|
+
* console.log(primitive.params.token);
|
|
236
|
+
* console.log(primitive.params.to);
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export declare function isTransferPrimitive(p: Primitive): p is TransferPrimitive;
|
|
241
|
+
/**
|
|
242
|
+
* Type guard to check if a primitive is a wrap operation.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* if (isWrapPrimitive(primitive)) {
|
|
247
|
+
* // TypeScript knows primitive.params is WrapParams
|
|
248
|
+
* console.log(primitive.params.amount);
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare function isWrapPrimitive(p: Primitive): p is WrapPrimitive;
|
|
253
|
+
/**
|
|
254
|
+
* Type guard to check if a primitive is an unwrap operation.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* if (isUnwrapPrimitive(primitive)) {
|
|
259
|
+
* // TypeScript knows primitive.params is WrapParams
|
|
260
|
+
* console.log(primitive.params.amount);
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
export declare function isUnwrapPrimitive(p: Primitive): p is UnwrapPrimitive;
|
|
265
|
+
import type { PieChartBlock, TimeseriesChartBlock } from './types.js';
|
|
266
|
+
export type { PieChartBlock, TimeseriesChartBlock };
|
|
267
|
+
/**
|
|
268
|
+
* Type guard to check if a chart block is a pie chart.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* if (isPieChartBlock(block)) {
|
|
273
|
+
* // TypeScript knows block.chartType is 'pie'
|
|
274
|
+
* const data = block.data; // [[label, value], ...]
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export declare function isPieChartBlock(block: ChartBlock): block is PieChartBlock;
|
|
279
|
+
/**
|
|
280
|
+
* Type guard to check if a chart block is a timeseries chart.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* if (isTimeseriesChartBlock(block)) {
|
|
285
|
+
* // TypeScript knows block.chartType is 'timeseries'
|
|
286
|
+
* const series = block.series;
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
export declare function isTimeseriesChartBlock(block: ChartBlock): block is TimeseriesChartBlock;
|
|
291
|
+
/**
|
|
292
|
+
* Type guard to check if a block is an info block.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* if (isInfoBlock(block)) {
|
|
297
|
+
* // TypeScript knows block is InfoBlock
|
|
298
|
+
* console.log(block.message);
|
|
299
|
+
* console.log(block.severity);
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*/
|
|
303
|
+
export declare function isInfoBlock(block: Block): block is InfoBlock;
|
|
304
|
+
/**
|
|
305
|
+
* Type guard to check if a block is a code block.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* if (isCodeBlock(block)) {
|
|
310
|
+
* // TypeScript knows block is CodeBlock
|
|
311
|
+
* console.log(block.code);
|
|
312
|
+
* console.log(block.language);
|
|
313
|
+
* }
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
export declare function isCodeBlock(block: Block): block is CodeBlock;
|