@chaoslabs/ai-sdk 0.0.1
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/LICENSE +41 -0
- package/README.md +241 -0
- package/dist/client.d.ts +77 -0
- package/dist/client.js +167 -0
- package/dist/converter.d.ts +5 -0
- package/dist/converter.js +159 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/request.d.ts +48 -0
- package/dist/request.js +93 -0
- package/dist/response.d.ts +24 -0
- package/dist/response.js +111 -0
- package/dist/schemas.d.ts +547 -0
- package/dist/schemas.js +143 -0
- package/dist/types.d.ts +310 -0
- package/dist/types.js +126 -0
- package/package.json +52 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the Chaos client.
|
|
3
|
+
*/
|
|
4
|
+
export interface ChaosConfig {
|
|
5
|
+
/** API key for authentication */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** Base URL for the API (defaults to https://ai-staging.chaoslabs.co) */
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
/** Request timeout in milliseconds (defaults to 120000) */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Parameters for creating a response.
|
|
14
|
+
*/
|
|
15
|
+
export interface CreateResponseParams {
|
|
16
|
+
/**
|
|
17
|
+
* Model to use for the response.
|
|
18
|
+
* - 'WALLET_MODEL': Wallet mode for DeFi operations
|
|
19
|
+
* - 'ASK_MODEL': Ask mode for research
|
|
20
|
+
*/
|
|
21
|
+
model: string;
|
|
22
|
+
/** Input messages for the conversation */
|
|
23
|
+
input: InputItem[];
|
|
24
|
+
/** Whether to stream the response */
|
|
25
|
+
stream?: boolean;
|
|
26
|
+
/** Metadata for the request */
|
|
27
|
+
metadata: RequestMetadata;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* An input message in the conversation.
|
|
31
|
+
*/
|
|
32
|
+
export interface InputItem {
|
|
33
|
+
type: 'message';
|
|
34
|
+
role: 'user' | 'system';
|
|
35
|
+
content: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Request metadata including user and session identifiers.
|
|
39
|
+
*/
|
|
40
|
+
export interface RequestMetadata {
|
|
41
|
+
/** User identifier */
|
|
42
|
+
user_id: string;
|
|
43
|
+
/** Session identifier for conversation continuity */
|
|
44
|
+
session_id: string;
|
|
45
|
+
/** Wallet identifier (required for WALLET_MODEL) */
|
|
46
|
+
wallet_id: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A response from the Chaos API.
|
|
50
|
+
*/
|
|
51
|
+
export interface Response {
|
|
52
|
+
/** Unique response identifier */
|
|
53
|
+
id: string;
|
|
54
|
+
/** Object type */
|
|
55
|
+
object: 'response';
|
|
56
|
+
/** Model used */
|
|
57
|
+
model: string;
|
|
58
|
+
/** Response status */
|
|
59
|
+
status: 'completed' | 'failed';
|
|
60
|
+
/** Output items */
|
|
61
|
+
output: OutputItem[];
|
|
62
|
+
/** Error information if status is 'failed' */
|
|
63
|
+
error?: ResponseError;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* An output item in the response.
|
|
67
|
+
*/
|
|
68
|
+
export interface OutputItem {
|
|
69
|
+
type: 'message';
|
|
70
|
+
role: 'assistant';
|
|
71
|
+
content: ContentPart[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Content part within an output message.
|
|
75
|
+
*/
|
|
76
|
+
export type ContentPart = OutputText | ChaosBlock;
|
|
77
|
+
/**
|
|
78
|
+
* Text content part.
|
|
79
|
+
*/
|
|
80
|
+
export interface OutputText {
|
|
81
|
+
type: 'output_text';
|
|
82
|
+
text: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Chaos block content part.
|
|
86
|
+
*/
|
|
87
|
+
export interface ChaosBlock {
|
|
88
|
+
type: 'chaos.block';
|
|
89
|
+
block: Block;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Union of all block types.
|
|
93
|
+
*/
|
|
94
|
+
export type Block = TableBlock | MarkdownBlock | TransactionActionBlock | InteractiveCardBlock | TimeseriesBlock | PieChartBlock;
|
|
95
|
+
/**
|
|
96
|
+
* A cell value in a table row.
|
|
97
|
+
* Can be a string (text, addresses, asset names) or number (amounts, percentages).
|
|
98
|
+
*/
|
|
99
|
+
export type TableCellValue = string | number;
|
|
100
|
+
/**
|
|
101
|
+
* Table visualization block.
|
|
102
|
+
*/
|
|
103
|
+
export interface TableBlock {
|
|
104
|
+
type: 'table';
|
|
105
|
+
title: string;
|
|
106
|
+
tableHeaders: string[];
|
|
107
|
+
rows: TableCellValue[][];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Markdown content block.
|
|
111
|
+
*/
|
|
112
|
+
export interface MarkdownBlock {
|
|
113
|
+
type: 'markdown';
|
|
114
|
+
content: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Transaction action block for DeFi operations.
|
|
118
|
+
*/
|
|
119
|
+
export interface TransactionActionBlock {
|
|
120
|
+
type: 'transaction_action';
|
|
121
|
+
title: string;
|
|
122
|
+
primitives: Primitive[];
|
|
123
|
+
risks?: Risks;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* JSON-compatible primitive parameter value.
|
|
127
|
+
* Covers all types that can appear in primitive params.
|
|
128
|
+
*/
|
|
129
|
+
export type PrimitiveParamValue = string | number | boolean | null | PrimitiveParamValue[] | {
|
|
130
|
+
[key: string]: PrimitiveParamValue;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Parameters for a primitive operation.
|
|
134
|
+
* Common fields include: asset, amount, from_asset, to_asset, chain, destination_address, etc.
|
|
135
|
+
*/
|
|
136
|
+
export type PrimitiveParams = Record<string, PrimitiveParamValue>;
|
|
137
|
+
/**
|
|
138
|
+
* Display fields for a primitive (pre-computed UI-friendly values).
|
|
139
|
+
*/
|
|
140
|
+
export interface PrimitiveDisplay {
|
|
141
|
+
/** Main action line (e.g., "ETH -> USDC", "Deposit to Aave") */
|
|
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. */
|
|
146
|
+
action_verb?: string;
|
|
147
|
+
/** Source asset for swaps/bridges */
|
|
148
|
+
from_asset?: string;
|
|
149
|
+
/** Destination asset for swaps/bridges */
|
|
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;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A DeFi primitive operation.
|
|
166
|
+
*/
|
|
167
|
+
export interface Primitive {
|
|
168
|
+
/** Primitive type (e.g., 'swap', 'transfer', 'aave_deposit') */
|
|
169
|
+
primitive: string;
|
|
170
|
+
/** Primitive-specific parameters */
|
|
171
|
+
params: PrimitiveParams;
|
|
172
|
+
/** Pre-computed UI display fields */
|
|
173
|
+
display?: PrimitiveDisplay;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Interactive card block for user input.
|
|
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.
|
|
187
|
+
*/
|
|
188
|
+
export interface InteractiveOption {
|
|
189
|
+
id: string;
|
|
190
|
+
label: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* A single data point in a timeseries: [timestamp_ms, value].
|
|
195
|
+
* Timestamp is in milliseconds (13-digit).
|
|
196
|
+
*/
|
|
197
|
+
export type TimeseriesDataPoint = [number, number];
|
|
198
|
+
/**
|
|
199
|
+
* A series in a timeseries chart.
|
|
200
|
+
*/
|
|
201
|
+
export interface TimeseriesSeries {
|
|
202
|
+
/** Series label (e.g., "ETH", "BTC") */
|
|
203
|
+
label: string;
|
|
204
|
+
/** Array of [timestamp_ms, value] data points */
|
|
205
|
+
data: TimeseriesDataPoint[];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Timeseries data organized by timeframe.
|
|
209
|
+
* Keys are timeframe strings: "24H", "7D", "30D", "90D".
|
|
210
|
+
*/
|
|
211
|
+
export type TimeseriesData = Record<string, TimeseriesSeries[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Time series chart block.
|
|
214
|
+
*/
|
|
215
|
+
export interface TimeseriesBlock {
|
|
216
|
+
type: 'timeseries';
|
|
217
|
+
title: string;
|
|
218
|
+
/** Series data organized by timeframe */
|
|
219
|
+
data: TimeseriesData;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Pie chart block.
|
|
223
|
+
*/
|
|
224
|
+
export interface PieChartBlock {
|
|
225
|
+
type: 'pie_chart';
|
|
226
|
+
title: string;
|
|
227
|
+
data: [string, number][];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Risk assessment for a transaction.
|
|
231
|
+
*/
|
|
232
|
+
export interface Risks {
|
|
233
|
+
/** Overall risk level */
|
|
234
|
+
level: 'low' | 'medium' | 'high' | 'critical';
|
|
235
|
+
/** Warning messages */
|
|
236
|
+
warnings: string[];
|
|
237
|
+
/** Blocker messages that prevent execution */
|
|
238
|
+
blockers?: string[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Error information in a response.
|
|
242
|
+
*/
|
|
243
|
+
export interface ResponseError {
|
|
244
|
+
message: string;
|
|
245
|
+
type: string;
|
|
246
|
+
code: string;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* HTTP error from the API.
|
|
250
|
+
*/
|
|
251
|
+
export declare class ChaosError extends Error {
|
|
252
|
+
readonly status?: number | undefined;
|
|
253
|
+
readonly code?: string | undefined;
|
|
254
|
+
readonly type?: string | undefined;
|
|
255
|
+
constructor(message: string, status?: number | undefined, code?: string | undefined, type?: string | undefined);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Timeout error.
|
|
259
|
+
*/
|
|
260
|
+
export declare class ChaosTimeoutError extends ChaosError {
|
|
261
|
+
constructor(timeoutMs: number);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Check if a block is a table block.
|
|
265
|
+
*/
|
|
266
|
+
export declare function isTableBlock(block: Block): block is TableBlock;
|
|
267
|
+
/**
|
|
268
|
+
* Check if a block is a markdown block.
|
|
269
|
+
*/
|
|
270
|
+
export declare function isMarkdownBlock(block: Block): block is MarkdownBlock;
|
|
271
|
+
/**
|
|
272
|
+
* Check if a block is a transaction action block.
|
|
273
|
+
*/
|
|
274
|
+
export declare function isTransactionActionBlock(block: Block): block is TransactionActionBlock;
|
|
275
|
+
/**
|
|
276
|
+
* Check if a block is an interactive card block.
|
|
277
|
+
*/
|
|
278
|
+
export declare function isInteractiveCardBlock(block: Block): block is InteractiveCardBlock;
|
|
279
|
+
/**
|
|
280
|
+
* Check if a block is a timeseries block.
|
|
281
|
+
*/
|
|
282
|
+
export declare function isTimeseriesBlock(block: Block): block is TimeseriesBlock;
|
|
283
|
+
/**
|
|
284
|
+
* Check if a block is a pie chart block.
|
|
285
|
+
*/
|
|
286
|
+
export declare function isPieChartBlock(block: Block): block is PieChartBlock;
|
|
287
|
+
/**
|
|
288
|
+
* Check if a content part is output text.
|
|
289
|
+
*/
|
|
290
|
+
export declare function isOutputText(part: ContentPart): part is OutputText;
|
|
291
|
+
/**
|
|
292
|
+
* Check if a content part is a chaos block.
|
|
293
|
+
*/
|
|
294
|
+
export declare function isChaosBlock(part: ContentPart): part is ChaosBlock;
|
|
295
|
+
/**
|
|
296
|
+
* Extract all text content from a response.
|
|
297
|
+
*/
|
|
298
|
+
export declare function extractText(response: Response): string;
|
|
299
|
+
/**
|
|
300
|
+
* Extract all blocks from a response.
|
|
301
|
+
*/
|
|
302
|
+
export declare function extractBlocks(response: Response): Block[];
|
|
303
|
+
/**
|
|
304
|
+
* Check if a response has any risks.
|
|
305
|
+
*/
|
|
306
|
+
export declare function hasRisks(response: Response): boolean;
|
|
307
|
+
/**
|
|
308
|
+
* Check if a response has any blockers.
|
|
309
|
+
*/
|
|
310
|
+
export declare function hasBlockers(response: Response): boolean;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Chaos AI SDK V1 - Public Types
|
|
2
|
+
/**
|
|
3
|
+
* HTTP error from the API.
|
|
4
|
+
*/
|
|
5
|
+
export class ChaosError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
code;
|
|
8
|
+
type;
|
|
9
|
+
constructor(message, status, code, type) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.name = 'ChaosError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Timeout error.
|
|
19
|
+
*/
|
|
20
|
+
export class ChaosTimeoutError extends ChaosError {
|
|
21
|
+
constructor(timeoutMs) {
|
|
22
|
+
super(`Request timed out after ${timeoutMs}ms`);
|
|
23
|
+
this.name = 'ChaosTimeoutError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Type Guards
|
|
28
|
+
// ============================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Check if a block is a table block.
|
|
31
|
+
*/
|
|
32
|
+
export function isTableBlock(block) {
|
|
33
|
+
return block.type === 'table';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if a block is a markdown block.
|
|
37
|
+
*/
|
|
38
|
+
export function isMarkdownBlock(block) {
|
|
39
|
+
return block.type === 'markdown';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a block is a transaction action block.
|
|
43
|
+
*/
|
|
44
|
+
export function isTransactionActionBlock(block) {
|
|
45
|
+
return block.type === 'transaction_action';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a block is an interactive card block.
|
|
49
|
+
*/
|
|
50
|
+
export function isInteractiveCardBlock(block) {
|
|
51
|
+
return block.type === 'interactive_card';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if a block is a timeseries block.
|
|
55
|
+
*/
|
|
56
|
+
export function isTimeseriesBlock(block) {
|
|
57
|
+
return block.type === 'timeseries';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if a block is a pie chart block.
|
|
61
|
+
*/
|
|
62
|
+
export function isPieChartBlock(block) {
|
|
63
|
+
return block.type === 'pie_chart';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a content part is output text.
|
|
67
|
+
*/
|
|
68
|
+
export function isOutputText(part) {
|
|
69
|
+
return part.type === 'output_text';
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check if a content part is a chaos block.
|
|
73
|
+
*/
|
|
74
|
+
export function isChaosBlock(part) {
|
|
75
|
+
return part.type === 'chaos.block';
|
|
76
|
+
}
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// Helper Functions
|
|
79
|
+
// ============================================================================
|
|
80
|
+
/**
|
|
81
|
+
* Extract all text content from a response.
|
|
82
|
+
*/
|
|
83
|
+
export function extractText(response) {
|
|
84
|
+
const texts = [];
|
|
85
|
+
for (const item of response.output) {
|
|
86
|
+
for (const part of item.content) {
|
|
87
|
+
if (isOutputText(part)) {
|
|
88
|
+
texts.push(part.text);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return texts.join('\n');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Extract all blocks from a response.
|
|
96
|
+
*/
|
|
97
|
+
export function extractBlocks(response) {
|
|
98
|
+
const blocks = [];
|
|
99
|
+
for (const item of response.output) {
|
|
100
|
+
for (const part of item.content) {
|
|
101
|
+
if (isChaosBlock(part)) {
|
|
102
|
+
blocks.push(part.block);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return blocks;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Check if a response has any risks.
|
|
110
|
+
*/
|
|
111
|
+
export function hasRisks(response) {
|
|
112
|
+
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)));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a response has any blockers.
|
|
119
|
+
*/
|
|
120
|
+
export function hasBlockers(response) {
|
|
121
|
+
const blocks = extractBlocks(response);
|
|
122
|
+
return blocks.some((block) => isTransactionActionBlock(block) &&
|
|
123
|
+
block.risks &&
|
|
124
|
+
block.risks.blockers &&
|
|
125
|
+
block.risks.blockers.length > 0);
|
|
126
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chaoslabs/ai-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Chaos AI SDK - TypeScript SDK for the Chaos AI API",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"prepublishOnly": "bun run build",
|
|
23
|
+
"examples": "bun run examples/run-all.ts",
|
|
24
|
+
"examples:help": "bun run examples/run-all.ts --help"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"chaos",
|
|
28
|
+
"ai",
|
|
29
|
+
"sdk",
|
|
30
|
+
"defi",
|
|
31
|
+
"blockchain",
|
|
32
|
+
"wallet",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
35
|
+
"author": "Chaos Labs <support@chaoslabs.xyz>",
|
|
36
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/ChaosLabsInc/ai-sdk.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/ChaosLabsInc/ai-sdk#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/ChaosLabsInc/ai-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"zod": "^4.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/bun": "latest",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
}
|
|
52
|
+
}
|