@chaoslabs/ai-sdk 0.0.1 → 0.0.2
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/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/response.js +49 -5
- package/dist/schemas.d.ts +739 -492
- package/dist/schemas.js +221 -110
- package/dist/types.d.ts +171 -104
- package/dist/types.js +12 -19
- package/package.json +8 -2
package/dist/types.d.ts
CHANGED
|
@@ -90,152 +90,223 @@ export interface ChaosBlock {
|
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Union of all block types.
|
|
93
|
+
* Note: SDK adds 'type' field for consistency, server uses 'blockType'.
|
|
93
94
|
*/
|
|
94
|
-
export type Block =
|
|
95
|
+
export type Block = MarkdownBlock | TableBlock | ChartBlock | TransactionActionBlock | InteractiveBlock;
|
|
95
96
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
97
|
+
* Markdown content block.
|
|
98
|
+
* Server sends: { content: string } (no blockType)
|
|
99
|
+
*/
|
|
100
|
+
export interface MarkdownBlock {
|
|
101
|
+
type: 'markdown';
|
|
102
|
+
content: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Table column type.
|
|
106
|
+
*/
|
|
107
|
+
export type TableColumnType = 'text' | 'number' | 'currency' | 'percentage' | 'token' | 'date' | 'link' | 'boolean';
|
|
108
|
+
/**
|
|
109
|
+
* Table sort direction.
|
|
110
|
+
*/
|
|
111
|
+
export type TableSortDirection = 'asc' | 'desc';
|
|
112
|
+
/**
|
|
113
|
+
* Table column configuration.
|
|
98
114
|
*/
|
|
99
|
-
export
|
|
115
|
+
export interface TableColumnConfig {
|
|
116
|
+
type?: TableColumnType;
|
|
117
|
+
sortable?: boolean;
|
|
118
|
+
align?: 'left' | 'center' | 'right';
|
|
119
|
+
width?: string;
|
|
120
|
+
}
|
|
100
121
|
/**
|
|
101
122
|
* Table visualization block.
|
|
123
|
+
* Server sends: { blockType: "table", ... }
|
|
102
124
|
*/
|
|
103
125
|
export interface TableBlock {
|
|
104
126
|
type: 'table';
|
|
127
|
+
blockType?: 'table';
|
|
105
128
|
title: string;
|
|
106
129
|
tableHeaders: string[];
|
|
107
|
-
|
|
130
|
+
tableRows: Array<Array<string | number | boolean | null>>;
|
|
131
|
+
tableHeadersTypes?: Record<string, TableColumnType | 'currency' | 'percentage'> | null;
|
|
132
|
+
tableColumnConfigs?: Record<string, TableColumnConfig> | null;
|
|
133
|
+
tableHeadersMetadata?: Record<string, {
|
|
134
|
+
type?: string;
|
|
135
|
+
}> | null;
|
|
136
|
+
sourceName?: string | null;
|
|
137
|
+
defaultSortColumn?: string | null;
|
|
138
|
+
defaultSortDirection?: TableSortDirection | null;
|
|
139
|
+
maxRows?: number | null;
|
|
140
|
+
searchable?: boolean | null;
|
|
141
|
+
exportable?: boolean | null;
|
|
142
|
+
tool_params?: unknown;
|
|
143
|
+
tool_name?: string | null;
|
|
108
144
|
}
|
|
109
145
|
/**
|
|
110
|
-
*
|
|
146
|
+
* Chart series data point.
|
|
111
147
|
*/
|
|
112
|
-
export
|
|
113
|
-
|
|
114
|
-
|
|
148
|
+
export type ChartDataPoint = [number, number] | {
|
|
149
|
+
x: number | string;
|
|
150
|
+
y: number;
|
|
151
|
+
} | unknown[];
|
|
152
|
+
/**
|
|
153
|
+
* Chart series.
|
|
154
|
+
*/
|
|
155
|
+
export interface ChartSeries {
|
|
156
|
+
name: string;
|
|
157
|
+
data: ChartDataPoint[];
|
|
158
|
+
color?: string;
|
|
115
159
|
}
|
|
116
160
|
/**
|
|
117
|
-
*
|
|
161
|
+
* Chart segment for pie/donut charts.
|
|
118
162
|
*/
|
|
119
|
-
export interface
|
|
120
|
-
|
|
163
|
+
export interface ChartSegment {
|
|
164
|
+
label: string;
|
|
165
|
+
value: number;
|
|
166
|
+
color?: string;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Chart axis configuration.
|
|
170
|
+
*/
|
|
171
|
+
export interface ChartAxis {
|
|
172
|
+
title?: string;
|
|
173
|
+
min?: number;
|
|
174
|
+
max?: number;
|
|
175
|
+
type?: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Chart visualization block.
|
|
179
|
+
* Server sends: { blockType: "chart", data: [[label, value], ...], ... }
|
|
180
|
+
*/
|
|
181
|
+
export interface ChartBlock {
|
|
182
|
+
type: 'chart';
|
|
183
|
+
blockType?: 'chart';
|
|
121
184
|
title: string;
|
|
122
|
-
|
|
123
|
-
|
|
185
|
+
chartType?: 'pie' | 'donut' | 'line' | 'area' | 'bar' | 'timeseries' | null;
|
|
186
|
+
series?: ChartSeries[] | null;
|
|
187
|
+
segments?: ChartSegment[] | null;
|
|
188
|
+
/** Legacy data format from server: [[label, value], ...] */
|
|
189
|
+
data?: Array<[string, number]> | null;
|
|
190
|
+
categories?: string[] | null;
|
|
191
|
+
xAxis?: ChartAxis | null;
|
|
192
|
+
yAxis?: ChartAxis | null;
|
|
193
|
+
isCurrency?: boolean | null;
|
|
194
|
+
sourceName?: string | null;
|
|
195
|
+
timeframe?: string | null;
|
|
196
|
+
tool_params?: unknown;
|
|
197
|
+
tool_name?: string | null;
|
|
124
198
|
}
|
|
125
199
|
/**
|
|
126
|
-
*
|
|
127
|
-
* Covers all types that can appear in primitive params.
|
|
200
|
+
* Icon for primitive display.
|
|
128
201
|
*/
|
|
129
|
-
export
|
|
130
|
-
|
|
131
|
-
|
|
202
|
+
export interface PrimitiveIcon {
|
|
203
|
+
type: string;
|
|
204
|
+
value: string;
|
|
205
|
+
}
|
|
132
206
|
/**
|
|
133
|
-
*
|
|
134
|
-
* Common fields include: asset, amount, from_asset, to_asset, chain, destination_address, etc.
|
|
207
|
+
* Line item for primitive display.
|
|
135
208
|
*/
|
|
136
|
-
export
|
|
209
|
+
export interface PrimitiveLineItem {
|
|
210
|
+
label: string;
|
|
211
|
+
value: string;
|
|
212
|
+
icon?: PrimitiveIcon;
|
|
213
|
+
}
|
|
137
214
|
/**
|
|
138
|
-
* Display
|
|
215
|
+
* Display information for a primitive.
|
|
139
216
|
*/
|
|
140
217
|
export interface PrimitiveDisplay {
|
|
141
|
-
|
|
142
|
-
headline: string;
|
|
143
|
-
/** Formatted amount with symbol (e.g., "1.5 ETH (~$4,500)") */
|
|
144
|
-
amount?: string;
|
|
145
|
-
/** Action type: "Deposit", "Withdraw", "Stake", "Borrow", etc. */
|
|
218
|
+
headline?: string;
|
|
146
219
|
action_verb?: string;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
to_asset?: string;
|
|
151
|
-
/** Source chain for bridges */
|
|
152
|
-
from_chain?: string;
|
|
153
|
-
/** Destination chain for bridges */
|
|
154
|
-
to_chain?: string;
|
|
155
|
-
/** Protocol name (e.g., "Aave V3", "Lido", "GMX") */
|
|
156
|
-
protocol?: string;
|
|
157
|
-
/** Leverage multiplier (e.g., "10x") */
|
|
158
|
-
leverage?: string;
|
|
159
|
-
/** Direction: "Long", "Short", "Send", "Receive" */
|
|
160
|
-
direction?: string;
|
|
161
|
-
/** Full recipient address (never truncated) */
|
|
162
|
-
recipient?: string;
|
|
220
|
+
primary_icon?: PrimitiveIcon;
|
|
221
|
+
secondary_icon?: PrimitiveIcon;
|
|
222
|
+
line_items?: PrimitiveLineItem[];
|
|
163
223
|
}
|
|
164
224
|
/**
|
|
165
|
-
* A
|
|
225
|
+
* A primitive action (swap, supply, borrow, etc.)
|
|
166
226
|
*/
|
|
167
227
|
export interface Primitive {
|
|
168
|
-
/** Primitive type (e.g., 'swap', 'transfer', 'aave_deposit') */
|
|
169
228
|
primitive: string;
|
|
170
|
-
|
|
171
|
-
params: PrimitiveParams;
|
|
172
|
-
/** Pre-computed UI display fields */
|
|
229
|
+
params?: Record<string, unknown>;
|
|
173
230
|
display?: PrimitiveDisplay;
|
|
174
231
|
}
|
|
175
232
|
/**
|
|
176
|
-
*
|
|
177
|
-
*/
|
|
178
|
-
export interface InteractiveCardBlock {
|
|
179
|
-
type: 'interactive_card';
|
|
180
|
-
title: string;
|
|
181
|
-
body?: string;
|
|
182
|
-
style: 'options' | 'confirm_cancel';
|
|
183
|
-
options?: InteractiveOption[];
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* An option in an interactive card.
|
|
233
|
+
* Raw transaction data from server.
|
|
187
234
|
*/
|
|
188
|
-
export interface
|
|
189
|
-
|
|
190
|
-
|
|
235
|
+
export interface RawTransaction {
|
|
236
|
+
to?: string;
|
|
237
|
+
data?: string;
|
|
238
|
+
value?: string;
|
|
239
|
+
chainId?: number;
|
|
191
240
|
description?: string;
|
|
241
|
+
contractName?: string;
|
|
242
|
+
contractVerified?: boolean;
|
|
243
|
+
protocolName?: string;
|
|
244
|
+
contractIcon?: string;
|
|
192
245
|
}
|
|
193
246
|
/**
|
|
194
|
-
*
|
|
195
|
-
* Timestamp is in milliseconds (13-digit).
|
|
247
|
+
* Group of transactions.
|
|
196
248
|
*/
|
|
197
|
-
export
|
|
249
|
+
export interface TransactionGroup {
|
|
250
|
+
transactions?: RawTransaction[];
|
|
251
|
+
requiresApproval?: boolean;
|
|
252
|
+
verificationUnavailable?: boolean;
|
|
253
|
+
}
|
|
198
254
|
/**
|
|
199
|
-
*
|
|
255
|
+
* Risk information item.
|
|
200
256
|
*/
|
|
201
|
-
export interface
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
257
|
+
export interface RiskInfoItem {
|
|
258
|
+
id?: string;
|
|
259
|
+
severity?: 'info' | 'warning' | 'error' | 'critical';
|
|
260
|
+
title?: string;
|
|
261
|
+
message?: string;
|
|
206
262
|
}
|
|
207
263
|
/**
|
|
208
|
-
*
|
|
209
|
-
* Keys are timeframe strings: "24H", "7D", "30D", "90D".
|
|
264
|
+
* Risk assessment for a transaction.
|
|
210
265
|
*/
|
|
211
|
-
export
|
|
266
|
+
export interface Risks {
|
|
267
|
+
level?: string;
|
|
268
|
+
blockers?: string[];
|
|
269
|
+
warnings?: string[];
|
|
270
|
+
info?: RiskInfoItem[];
|
|
271
|
+
}
|
|
212
272
|
/**
|
|
213
|
-
*
|
|
273
|
+
* Transaction action block for DeFi operations.
|
|
274
|
+
* Server sends: { blockType: "transaction_action", primitives: [...], ... }
|
|
214
275
|
*/
|
|
215
|
-
export interface
|
|
216
|
-
type: '
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
276
|
+
export interface TransactionActionBlock {
|
|
277
|
+
type: 'transaction_action';
|
|
278
|
+
blockType?: 'transaction_action';
|
|
279
|
+
value?: Record<string, unknown>;
|
|
280
|
+
sequence?: boolean;
|
|
281
|
+
primitives?: Primitive[];
|
|
282
|
+
transactions?: TransactionGroup[];
|
|
283
|
+
needs_confirmation?: boolean;
|
|
284
|
+
notes?: string;
|
|
285
|
+
risks?: Risks;
|
|
286
|
+
metadata?: Record<string, unknown>;
|
|
287
|
+
tool_params?: unknown;
|
|
288
|
+
tool_name?: string | null;
|
|
220
289
|
}
|
|
221
290
|
/**
|
|
222
|
-
*
|
|
291
|
+
* Interactive option.
|
|
223
292
|
*/
|
|
224
|
-
export interface
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
293
|
+
export interface InteractiveOption {
|
|
294
|
+
id: string;
|
|
295
|
+
label: string;
|
|
296
|
+
description?: string;
|
|
297
|
+
value?: unknown;
|
|
228
298
|
}
|
|
229
299
|
/**
|
|
230
|
-
*
|
|
300
|
+
* Interactive block for user input.
|
|
301
|
+
* Server sends: { blockType: "interactive", ... }
|
|
231
302
|
*/
|
|
232
|
-
export interface
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
303
|
+
export interface InteractiveBlock {
|
|
304
|
+
type: 'interactive';
|
|
305
|
+
blockType?: 'interactive';
|
|
306
|
+
prompt?: string;
|
|
307
|
+
options?: InteractiveOption[];
|
|
308
|
+
allowCustom?: boolean;
|
|
309
|
+
multiSelect?: boolean;
|
|
239
310
|
}
|
|
240
311
|
/**
|
|
241
312
|
* Error information in a response.
|
|
@@ -273,17 +344,13 @@ export declare function isMarkdownBlock(block: Block): block is MarkdownBlock;
|
|
|
273
344
|
*/
|
|
274
345
|
export declare function isTransactionActionBlock(block: Block): block is TransactionActionBlock;
|
|
275
346
|
/**
|
|
276
|
-
* Check if a block is an interactive
|
|
277
|
-
*/
|
|
278
|
-
export declare function isInteractiveCardBlock(block: Block): block is InteractiveCardBlock;
|
|
279
|
-
/**
|
|
280
|
-
* Check if a block is a timeseries block.
|
|
347
|
+
* Check if a block is an interactive block.
|
|
281
348
|
*/
|
|
282
|
-
export declare function
|
|
349
|
+
export declare function isInteractiveBlock(block: Block): block is InteractiveBlock;
|
|
283
350
|
/**
|
|
284
|
-
* Check if a block is a
|
|
351
|
+
* Check if a block is a chart block.
|
|
285
352
|
*/
|
|
286
|
-
export declare function
|
|
353
|
+
export declare function isChartBlock(block: Block): block is ChartBlock;
|
|
287
354
|
/**
|
|
288
355
|
* Check if a content part is output text.
|
|
289
356
|
*/
|
|
@@ -301,10 +368,10 @@ export declare function extractText(response: Response): string;
|
|
|
301
368
|
*/
|
|
302
369
|
export declare function extractBlocks(response: Response): Block[];
|
|
303
370
|
/**
|
|
304
|
-
* Check if a response has any
|
|
371
|
+
* Check if a response has any transaction action blocks with risk levels.
|
|
305
372
|
*/
|
|
306
373
|
export declare function hasRisks(response: Response): boolean;
|
|
307
374
|
/**
|
|
308
|
-
* Check if a response has any
|
|
375
|
+
* Check if a response has any high-risk transaction action blocks.
|
|
309
376
|
*/
|
|
310
377
|
export declare function hasBlockers(response: Response): boolean;
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Chaos AI SDK V1 - Public Types
|
|
2
|
+
// Updated to match actual server response structure
|
|
2
3
|
/**
|
|
3
4
|
* HTTP error from the API.
|
|
4
5
|
*/
|
|
@@ -45,22 +46,16 @@ export function isTransactionActionBlock(block) {
|
|
|
45
46
|
return block.type === 'transaction_action';
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
|
-
* Check if a block is an interactive
|
|
49
|
+
* Check if a block is an interactive block.
|
|
49
50
|
*/
|
|
50
|
-
export function
|
|
51
|
-
return block.type === '
|
|
51
|
+
export function isInteractiveBlock(block) {
|
|
52
|
+
return block.type === 'interactive';
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
|
-
* Check if a block is a
|
|
55
|
+
* Check if a block is a chart block.
|
|
55
56
|
*/
|
|
56
|
-
export function
|
|
57
|
-
return block.type === '
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Check if a block is a pie chart block.
|
|
61
|
-
*/
|
|
62
|
-
export function isPieChartBlock(block) {
|
|
63
|
-
return block.type === 'pie_chart';
|
|
57
|
+
export function isChartBlock(block) {
|
|
58
|
+
return block.type === 'chart';
|
|
64
59
|
}
|
|
65
60
|
/**
|
|
66
61
|
* Check if a content part is output text.
|
|
@@ -106,21 +101,19 @@ export function extractBlocks(response) {
|
|
|
106
101
|
return blocks;
|
|
107
102
|
}
|
|
108
103
|
/**
|
|
109
|
-
* Check if a response has any
|
|
104
|
+
* Check if a response has any transaction action blocks with risk levels.
|
|
110
105
|
*/
|
|
111
106
|
export function hasRisks(response) {
|
|
112
107
|
const blocks = extractBlocks(response);
|
|
113
|
-
return blocks.some((block) => isTransactionActionBlock(block) &&
|
|
114
|
-
block.risks &&
|
|
115
|
-
(block.risks.warnings.length > 0 || (block.risks.blockers && block.risks.blockers.length > 0)));
|
|
108
|
+
return blocks.some((block) => isTransactionActionBlock(block) && block.risks?.level && block.risks.level !== 'low');
|
|
116
109
|
}
|
|
117
110
|
/**
|
|
118
|
-
* Check if a response has any
|
|
111
|
+
* Check if a response has any high-risk transaction action blocks.
|
|
119
112
|
*/
|
|
120
113
|
export function hasBlockers(response) {
|
|
121
114
|
const blocks = extractBlocks(response);
|
|
122
115
|
return blocks.some((block) => isTransactionActionBlock(block) &&
|
|
123
116
|
block.risks &&
|
|
124
|
-
block.risks.
|
|
125
|
-
|
|
117
|
+
((block.risks.level === 'high' || block.risks.level === 'critical') ||
|
|
118
|
+
(block.risks.blockers && block.risks.blockers.length > 0)));
|
|
126
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaoslabs/ai-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Chaos AI SDK - TypeScript SDK for the Chaos AI API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,11 @@
|
|
|
21
21
|
"typecheck": "tsc --noEmit",
|
|
22
22
|
"prepublishOnly": "bun run build",
|
|
23
23
|
"examples": "bun run examples/run-all.ts",
|
|
24
|
-
"examples:help": "bun run examples/run-all.ts --help"
|
|
24
|
+
"examples:help": "bun run examples/run-all.ts --help",
|
|
25
|
+
"docs:import": "bun run tools/sanity-cms/index.ts import:all",
|
|
26
|
+
"docs:import:dry": "bun run tools/sanity-cms/index.ts import:all --dry-run",
|
|
27
|
+
"docs:import:docs": "bun run tools/sanity-cms/index.ts import:docs",
|
|
28
|
+
"docs:import:changelog": "bun run tools/sanity-cms/index.ts import:changelog"
|
|
25
29
|
},
|
|
26
30
|
"keywords": [
|
|
27
31
|
"chaos",
|
|
@@ -46,7 +50,9 @@
|
|
|
46
50
|
"zod": "^4.0.0"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
53
|
+
"@sanity/client": "^6.28.1",
|
|
49
54
|
"@types/bun": "latest",
|
|
55
|
+
"nanoid": "^5.0.9",
|
|
50
56
|
"typescript": "^5.9.3"
|
|
51
57
|
}
|
|
52
58
|
}
|