@chaoslabs/ai-sdk 0.0.2 → 0.0.3
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/blocks.d.ts +108 -0
- package/dist/blocks.js +246 -0
- package/dist/conversation.d.ts +136 -0
- package/dist/conversation.js +230 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -0
- package/dist/primitives.d.ts +157 -0
- package/dist/primitives.js +220 -0
- package/dist/schemas.d.ts +405 -97
- package/dist/schemas.js +47 -18
- package/package.json +1 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// Chaos AI SDK - Conversation Management
|
|
2
|
+
//
|
|
3
|
+
// A class for managing multi-turn conversations with history tracking.
|
|
4
|
+
import { extractText } from './types.js';
|
|
5
|
+
import { WALLET_MODEL } from './request.js';
|
|
6
|
+
/**
|
|
7
|
+
* Manages a multi-turn conversation with history tracking.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { Chaos, Conversation } from '@chaoslabs/ai-sdk';
|
|
12
|
+
*
|
|
13
|
+
* const chaos = new Chaos({ apiKey: 'ck-...' });
|
|
14
|
+
* const conversation = new Conversation(chaos, {
|
|
15
|
+
* userId: 'user-123',
|
|
16
|
+
* walletId: '0x...',
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Send messages - history is tracked automatically
|
|
20
|
+
* const response1 = await conversation.send("What's my portfolio value?");
|
|
21
|
+
* const response2 = await conversation.send("Which asset has the highest allocation?");
|
|
22
|
+
*
|
|
23
|
+
* // Get conversation stats
|
|
24
|
+
* console.log(conversation.stats);
|
|
25
|
+
*
|
|
26
|
+
* // Reset for a new conversation
|
|
27
|
+
* conversation.reset();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export class Conversation {
|
|
31
|
+
client;
|
|
32
|
+
model;
|
|
33
|
+
maxHistoryLength;
|
|
34
|
+
history = [];
|
|
35
|
+
metadata;
|
|
36
|
+
userTurns = 0;
|
|
37
|
+
assistantTurns = 0;
|
|
38
|
+
startedAt;
|
|
39
|
+
lastMessageAt = null;
|
|
40
|
+
constructor(client, options) {
|
|
41
|
+
this.client = client;
|
|
42
|
+
this.model = options.model || WALLET_MODEL;
|
|
43
|
+
this.maxHistoryLength = options.maxHistoryLength || 50;
|
|
44
|
+
this.startedAt = new Date();
|
|
45
|
+
this.metadata = {
|
|
46
|
+
user_id: options.userId,
|
|
47
|
+
wallet_id: options.walletId,
|
|
48
|
+
session_id: options.sessionId || `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the current session ID.
|
|
53
|
+
*/
|
|
54
|
+
get sessionId() {
|
|
55
|
+
return this.metadata.session_id;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the conversation history.
|
|
59
|
+
*/
|
|
60
|
+
get messages() {
|
|
61
|
+
return [...this.history];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get conversation statistics.
|
|
65
|
+
*/
|
|
66
|
+
get stats() {
|
|
67
|
+
return {
|
|
68
|
+
userTurns: this.userTurns,
|
|
69
|
+
assistantTurns: this.assistantTurns,
|
|
70
|
+
totalMessages: this.history.length,
|
|
71
|
+
sessionId: this.metadata.session_id,
|
|
72
|
+
startedAt: this.startedAt,
|
|
73
|
+
lastMessageAt: this.lastMessageAt,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Send a message and get a response.
|
|
78
|
+
* Automatically manages conversation history.
|
|
79
|
+
*/
|
|
80
|
+
async send(message) {
|
|
81
|
+
// Add user message to history
|
|
82
|
+
this.addUserMessage(message);
|
|
83
|
+
// Send request with full history
|
|
84
|
+
const response = await this.client.chat.responses.create({
|
|
85
|
+
model: this.model,
|
|
86
|
+
input: [...this.history],
|
|
87
|
+
metadata: this.metadata,
|
|
88
|
+
});
|
|
89
|
+
// Add assistant response to history if successful
|
|
90
|
+
if (response.status === 'completed') {
|
|
91
|
+
const text = extractText(response);
|
|
92
|
+
if (text) {
|
|
93
|
+
this.addAssistantMessage(text);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.lastMessageAt = new Date();
|
|
97
|
+
return response;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Add a user message to the history without sending.
|
|
101
|
+
* Useful for restoring conversation state.
|
|
102
|
+
*/
|
|
103
|
+
addUserMessage(content) {
|
|
104
|
+
this.history.push({
|
|
105
|
+
type: 'message',
|
|
106
|
+
role: 'user',
|
|
107
|
+
content,
|
|
108
|
+
});
|
|
109
|
+
this.userTurns++;
|
|
110
|
+
this.trimHistory();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Add an assistant message to the history.
|
|
114
|
+
* Useful for restoring conversation state.
|
|
115
|
+
*/
|
|
116
|
+
addAssistantMessage(content) {
|
|
117
|
+
// Store assistant responses as user messages with prefix for context
|
|
118
|
+
// This matches the pattern used in the multi-turn example
|
|
119
|
+
this.history.push({
|
|
120
|
+
type: 'message',
|
|
121
|
+
role: 'user',
|
|
122
|
+
content: `[Assistant]: ${content}`,
|
|
123
|
+
});
|
|
124
|
+
this.assistantTurns++;
|
|
125
|
+
this.trimHistory();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Add a system message to the history.
|
|
129
|
+
*/
|
|
130
|
+
addSystemMessage(content) {
|
|
131
|
+
this.history.push({
|
|
132
|
+
type: 'message',
|
|
133
|
+
role: 'system',
|
|
134
|
+
content,
|
|
135
|
+
});
|
|
136
|
+
this.trimHistory();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Reset the conversation to start fresh.
|
|
140
|
+
* Generates a new session ID and clears history.
|
|
141
|
+
*/
|
|
142
|
+
reset() {
|
|
143
|
+
this.history = [];
|
|
144
|
+
this.userTurns = 0;
|
|
145
|
+
this.assistantTurns = 0;
|
|
146
|
+
this.startedAt = new Date();
|
|
147
|
+
this.lastMessageAt = null;
|
|
148
|
+
this.metadata.session_id = `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Clear the history but keep the same session ID.
|
|
152
|
+
*/
|
|
153
|
+
clearHistory() {
|
|
154
|
+
this.history = [];
|
|
155
|
+
this.userTurns = 0;
|
|
156
|
+
this.assistantTurns = 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Fork this conversation to create a branch.
|
|
160
|
+
* The new conversation has the same history but a new session ID.
|
|
161
|
+
*/
|
|
162
|
+
fork() {
|
|
163
|
+
const forked = new Conversation(this.client, {
|
|
164
|
+
model: this.model,
|
|
165
|
+
maxHistoryLength: this.maxHistoryLength,
|
|
166
|
+
userId: this.metadata.user_id,
|
|
167
|
+
walletId: this.metadata.wallet_id,
|
|
168
|
+
});
|
|
169
|
+
// Copy history
|
|
170
|
+
for (const msg of this.history) {
|
|
171
|
+
if (msg.role === 'user') {
|
|
172
|
+
if (msg.content.startsWith('[Assistant]: ')) {
|
|
173
|
+
forked.history.push(msg);
|
|
174
|
+
forked.assistantTurns++;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
forked.history.push(msg);
|
|
178
|
+
forked.userTurns++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
forked.history.push(msg);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return forked;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Serialize the conversation to JSON for persistence.
|
|
189
|
+
*/
|
|
190
|
+
toJSON() {
|
|
191
|
+
return {
|
|
192
|
+
sessionId: this.metadata.session_id,
|
|
193
|
+
history: [...this.history],
|
|
194
|
+
metadata: { ...this.metadata },
|
|
195
|
+
stats: this.stats,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Restore conversation state from JSON.
|
|
200
|
+
*/
|
|
201
|
+
static fromJSON(client, data) {
|
|
202
|
+
const conversation = new Conversation(client, {
|
|
203
|
+
userId: data.metadata.user_id,
|
|
204
|
+
walletId: data.metadata.wallet_id,
|
|
205
|
+
sessionId: data.sessionId,
|
|
206
|
+
});
|
|
207
|
+
// Restore history
|
|
208
|
+
for (const msg of data.history) {
|
|
209
|
+
conversation.history.push(msg);
|
|
210
|
+
if (msg.role === 'user') {
|
|
211
|
+
if (msg.content.startsWith('[Assistant]: ')) {
|
|
212
|
+
conversation.assistantTurns++;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
conversation.userTurns++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return conversation;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Trim history to stay within maxHistoryLength.
|
|
223
|
+
*/
|
|
224
|
+
trimHistory() {
|
|
225
|
+
if (this.history.length > this.maxHistoryLength) {
|
|
226
|
+
const excess = this.history.length - this.maxHistoryLength;
|
|
227
|
+
this.history = this.history.slice(excess);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,3 +6,8 @@ export { ChaosError, ChaosTimeoutError } from './types.js';
|
|
|
6
6
|
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock, isChartBlock, isTransactionActionBlock, isInteractiveBlock, isMarkdownBlock, isOutputText, isChaosBlock, } from './types.js';
|
|
7
7
|
export { BlockSchema, parseRawBlock, detectBlockType } from './schemas.js';
|
|
8
8
|
export type { BlockParsed } from './schemas.js';
|
|
9
|
+
export { Conversation } from './conversation.js';
|
|
10
|
+
export type { ConversationOptions, ConversationStats } from './conversation.js';
|
|
11
|
+
export { PRIMITIVE_SWAP, PRIMITIVE_SUPPLY, PRIMITIVE_WITHDRAW, PRIMITIVE_BORROW, PRIMITIVE_REPAY, PRIMITIVE_STAKE, PRIMITIVE_UNSTAKE, PRIMITIVE_CLAIM, PRIMITIVE_BRIDGE, PRIMITIVE_ADD_LIQUIDITY, PRIMITIVE_REMOVE_LIQUIDITY, PRIMITIVE_OPEN_POSITION, PRIMITIVE_CLOSE_POSITION, PRIMITIVE_DEPOSIT, PRIMITIVE_MINT, PRIMITIVE_BURN, PRIMITIVE_RESTAKE, PRIMITIVE_APPROVE, PRIMITIVE_TRANSFER, PRIMITIVE_WRAP, PRIMITIVE_UNWRAP, ALL_PRIMITIVES, LENDING_PRIMITIVES, TRADING_PRIMITIVES, STAKING_PRIMITIVES, LIQUIDITY_PRIMITIVES, TRANSFER_PRIMITIVES, isValidPrimitive, isLendingPrimitive, isTradingPrimitive, isStakingPrimitive, isLiquidityPrimitive, isTransferPrimitive, } from './primitives.js';
|
|
12
|
+
export type { PrimitiveType } from './primitives.js';
|
|
13
|
+
export { extractTableBlocks, extractChartBlocks, extractTransactionBlocks, extractMarkdownBlocks, extractInteractiveBlocks, findTableByTitle, findChartByTitle, findTransactionsByPrimitive, extractPrimitives, extractPrimitivesByType, getPrimitiveTypes, tableToObjects, getTableColumn, findTableRow, getTableDimensions, getChartData, getChartTotal, getChartPercentages, getAllWarnings, getAllBlockers, getHighestRiskLevel, countBlocksByType, hasBlocks, hasBlockType, } from './blocks.js';
|
package/dist/index.js
CHANGED
|
@@ -6,3 +6,29 @@ export { ChaosError, ChaosTimeoutError } from './types.js';
|
|
|
6
6
|
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock, isChartBlock, isTransactionActionBlock, isInteractiveBlock, isMarkdownBlock, isOutputText, isChaosBlock, } from './types.js';
|
|
7
7
|
// Export schemas for validation
|
|
8
8
|
export { BlockSchema, parseRawBlock, detectBlockType } from './schemas.js';
|
|
9
|
+
// Export Conversation class
|
|
10
|
+
export { Conversation } from './conversation.js';
|
|
11
|
+
// Export primitive constants and helpers
|
|
12
|
+
export {
|
|
13
|
+
// Primitive type constants
|
|
14
|
+
PRIMITIVE_SWAP, PRIMITIVE_SUPPLY, PRIMITIVE_WITHDRAW, PRIMITIVE_BORROW, PRIMITIVE_REPAY, PRIMITIVE_STAKE, PRIMITIVE_UNSTAKE, PRIMITIVE_CLAIM, PRIMITIVE_BRIDGE, PRIMITIVE_ADD_LIQUIDITY, PRIMITIVE_REMOVE_LIQUIDITY, PRIMITIVE_OPEN_POSITION, PRIMITIVE_CLOSE_POSITION, PRIMITIVE_DEPOSIT, PRIMITIVE_MINT, PRIMITIVE_BURN, PRIMITIVE_RESTAKE, PRIMITIVE_APPROVE, PRIMITIVE_TRANSFER, PRIMITIVE_WRAP, PRIMITIVE_UNWRAP,
|
|
15
|
+
// Primitive categories
|
|
16
|
+
ALL_PRIMITIVES, LENDING_PRIMITIVES, TRADING_PRIMITIVES, STAKING_PRIMITIVES, LIQUIDITY_PRIMITIVES, TRANSFER_PRIMITIVES,
|
|
17
|
+
// Primitive helpers
|
|
18
|
+
isValidPrimitive, isLendingPrimitive, isTradingPrimitive, isStakingPrimitive, isLiquidityPrimitive, isTransferPrimitive, } from './primitives.js';
|
|
19
|
+
// Export block utilities
|
|
20
|
+
export {
|
|
21
|
+
// Block extraction
|
|
22
|
+
extractTableBlocks, extractChartBlocks, extractTransactionBlocks, extractMarkdownBlocks, extractInteractiveBlocks,
|
|
23
|
+
// Block search
|
|
24
|
+
findTableByTitle, findChartByTitle, findTransactionsByPrimitive,
|
|
25
|
+
// Primitive extraction
|
|
26
|
+
extractPrimitives, extractPrimitivesByType, getPrimitiveTypes,
|
|
27
|
+
// Table utilities
|
|
28
|
+
tableToObjects, getTableColumn, findTableRow, getTableDimensions,
|
|
29
|
+
// Chart utilities
|
|
30
|
+
getChartData, getChartTotal, getChartPercentages,
|
|
31
|
+
// Risk utilities
|
|
32
|
+
getAllWarnings, getAllBlockers, getHighestRiskLevel,
|
|
33
|
+
// Block statistics
|
|
34
|
+
countBlocksByType, hasBlocks, hasBlockType, } from './blocks.js';
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swap tokens on a decentralized exchange.
|
|
3
|
+
* @example "Swap 1 ETH for USDC"
|
|
4
|
+
*/
|
|
5
|
+
export declare const PRIMITIVE_SWAP = "swap";
|
|
6
|
+
/**
|
|
7
|
+
* Supply assets to a lending protocol.
|
|
8
|
+
* @example "Supply 1000 USDC to Aave"
|
|
9
|
+
*/
|
|
10
|
+
export declare const PRIMITIVE_SUPPLY = "supply";
|
|
11
|
+
/**
|
|
12
|
+
* Withdraw supplied assets from a lending protocol.
|
|
13
|
+
* @example "Withdraw my USDC from Compound"
|
|
14
|
+
*/
|
|
15
|
+
export declare const PRIMITIVE_WITHDRAW = "withdraw";
|
|
16
|
+
/**
|
|
17
|
+
* Borrow assets from a lending protocol.
|
|
18
|
+
* @example "Borrow 500 DAI from Aave"
|
|
19
|
+
*/
|
|
20
|
+
export declare const PRIMITIVE_BORROW = "borrow";
|
|
21
|
+
/**
|
|
22
|
+
* Repay borrowed assets to a lending protocol.
|
|
23
|
+
* @example "Repay my DAI debt on Compound"
|
|
24
|
+
*/
|
|
25
|
+
export declare const PRIMITIVE_REPAY = "repay";
|
|
26
|
+
/**
|
|
27
|
+
* Stake tokens for rewards or governance.
|
|
28
|
+
* @example "Stake 10 ETH with Lido"
|
|
29
|
+
*/
|
|
30
|
+
export declare const PRIMITIVE_STAKE = "stake";
|
|
31
|
+
/**
|
|
32
|
+
* Unstake previously staked tokens.
|
|
33
|
+
* @example "Unstake my stETH"
|
|
34
|
+
*/
|
|
35
|
+
export declare const PRIMITIVE_UNSTAKE = "unstake";
|
|
36
|
+
/**
|
|
37
|
+
* Claim accrued rewards from protocols.
|
|
38
|
+
* @example "Claim my Aave rewards"
|
|
39
|
+
*/
|
|
40
|
+
export declare const PRIMITIVE_CLAIM = "claim";
|
|
41
|
+
/**
|
|
42
|
+
* Bridge assets between chains.
|
|
43
|
+
* @example "Bridge 100 USDC to Arbitrum"
|
|
44
|
+
*/
|
|
45
|
+
export declare const PRIMITIVE_BRIDGE = "bridge";
|
|
46
|
+
/**
|
|
47
|
+
* Provide liquidity to a pool.
|
|
48
|
+
* @example "Add liquidity to ETH-USDC pool"
|
|
49
|
+
*/
|
|
50
|
+
export declare const PRIMITIVE_ADD_LIQUIDITY = "add_liquidity";
|
|
51
|
+
/**
|
|
52
|
+
* Remove liquidity from a pool.
|
|
53
|
+
* @example "Remove liquidity from my ETH-USDC position"
|
|
54
|
+
*/
|
|
55
|
+
export declare const PRIMITIVE_REMOVE_LIQUIDITY = "remove_liquidity";
|
|
56
|
+
/**
|
|
57
|
+
* Open a perpetual futures position.
|
|
58
|
+
* @example "Open 2x long ETH position"
|
|
59
|
+
*/
|
|
60
|
+
export declare const PRIMITIVE_OPEN_POSITION = "open_position";
|
|
61
|
+
/**
|
|
62
|
+
* Close a perpetual futures position.
|
|
63
|
+
* @example "Close my ETH long"
|
|
64
|
+
*/
|
|
65
|
+
export declare const PRIMITIVE_CLOSE_POSITION = "close_position";
|
|
66
|
+
/**
|
|
67
|
+
* Deposit into a vault strategy.
|
|
68
|
+
* @example "Deposit 1000 USDC into Yearn"
|
|
69
|
+
*/
|
|
70
|
+
export declare const PRIMITIVE_DEPOSIT = "deposit";
|
|
71
|
+
/**
|
|
72
|
+
* Mint stablecoins or synthetic assets.
|
|
73
|
+
* @example "Mint 1000 DAI from my ETH collateral"
|
|
74
|
+
*/
|
|
75
|
+
export declare const PRIMITIVE_MINT = "mint";
|
|
76
|
+
/**
|
|
77
|
+
* Burn or repay minted assets.
|
|
78
|
+
* @example "Burn 500 DAI to reduce my debt"
|
|
79
|
+
*/
|
|
80
|
+
export declare const PRIMITIVE_BURN = "burn";
|
|
81
|
+
/**
|
|
82
|
+
* Restake assets for additional yield.
|
|
83
|
+
* @example "Restake my stETH on EigenLayer"
|
|
84
|
+
*/
|
|
85
|
+
export declare const PRIMITIVE_RESTAKE = "restake";
|
|
86
|
+
/**
|
|
87
|
+
* Approve token spending.
|
|
88
|
+
* @example "Approve USDC for Uniswap"
|
|
89
|
+
*/
|
|
90
|
+
export declare const PRIMITIVE_APPROVE = "approve";
|
|
91
|
+
/**
|
|
92
|
+
* Transfer tokens to another address.
|
|
93
|
+
* @example "Send 100 USDC to 0x..."
|
|
94
|
+
*/
|
|
95
|
+
export declare const PRIMITIVE_TRANSFER = "transfer";
|
|
96
|
+
/**
|
|
97
|
+
* Wrap native tokens (e.g., ETH to WETH).
|
|
98
|
+
* @example "Wrap 1 ETH to WETH"
|
|
99
|
+
*/
|
|
100
|
+
export declare const PRIMITIVE_WRAP = "wrap";
|
|
101
|
+
/**
|
|
102
|
+
* Unwrap wrapped tokens (e.g., WETH to ETH).
|
|
103
|
+
* @example "Unwrap 1 WETH to ETH"
|
|
104
|
+
*/
|
|
105
|
+
export declare const PRIMITIVE_UNWRAP = "unwrap";
|
|
106
|
+
/**
|
|
107
|
+
* All DeFi primitive types as a union type.
|
|
108
|
+
*/
|
|
109
|
+
export type PrimitiveType = typeof PRIMITIVE_SWAP | typeof PRIMITIVE_SUPPLY | typeof PRIMITIVE_WITHDRAW | typeof PRIMITIVE_BORROW | typeof PRIMITIVE_REPAY | typeof PRIMITIVE_STAKE | typeof PRIMITIVE_UNSTAKE | typeof PRIMITIVE_CLAIM | typeof PRIMITIVE_BRIDGE | typeof PRIMITIVE_ADD_LIQUIDITY | typeof PRIMITIVE_REMOVE_LIQUIDITY | typeof PRIMITIVE_OPEN_POSITION | typeof PRIMITIVE_CLOSE_POSITION | typeof PRIMITIVE_DEPOSIT | typeof PRIMITIVE_MINT | typeof PRIMITIVE_BURN | typeof PRIMITIVE_RESTAKE | typeof PRIMITIVE_APPROVE | typeof PRIMITIVE_TRANSFER | typeof PRIMITIVE_WRAP | typeof PRIMITIVE_UNWRAP;
|
|
110
|
+
/**
|
|
111
|
+
* All primitive type constants for iteration.
|
|
112
|
+
*/
|
|
113
|
+
export declare const ALL_PRIMITIVES: PrimitiveType[];
|
|
114
|
+
/**
|
|
115
|
+
* Lending-related primitives.
|
|
116
|
+
*/
|
|
117
|
+
export declare const LENDING_PRIMITIVES: PrimitiveType[];
|
|
118
|
+
/**
|
|
119
|
+
* Trading-related primitives.
|
|
120
|
+
*/
|
|
121
|
+
export declare const TRADING_PRIMITIVES: PrimitiveType[];
|
|
122
|
+
/**
|
|
123
|
+
* Staking-related primitives.
|
|
124
|
+
*/
|
|
125
|
+
export declare const STAKING_PRIMITIVES: PrimitiveType[];
|
|
126
|
+
/**
|
|
127
|
+
* Liquidity-related primitives.
|
|
128
|
+
*/
|
|
129
|
+
export declare const LIQUIDITY_PRIMITIVES: PrimitiveType[];
|
|
130
|
+
/**
|
|
131
|
+
* Transfer-related primitives.
|
|
132
|
+
*/
|
|
133
|
+
export declare const TRANSFER_PRIMITIVES: PrimitiveType[];
|
|
134
|
+
/**
|
|
135
|
+
* Check if a primitive type is valid.
|
|
136
|
+
*/
|
|
137
|
+
export declare function isValidPrimitive(primitive: string): primitive is PrimitiveType;
|
|
138
|
+
/**
|
|
139
|
+
* Check if a primitive is a lending operation.
|
|
140
|
+
*/
|
|
141
|
+
export declare function isLendingPrimitive(primitive: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if a primitive is a trading operation.
|
|
144
|
+
*/
|
|
145
|
+
export declare function isTradingPrimitive(primitive: string): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Check if a primitive is a staking operation.
|
|
148
|
+
*/
|
|
149
|
+
export declare function isStakingPrimitive(primitive: string): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Check if a primitive is a liquidity operation.
|
|
152
|
+
*/
|
|
153
|
+
export declare function isLiquidityPrimitive(primitive: string): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Check if a primitive is a transfer operation.
|
|
156
|
+
*/
|
|
157
|
+
export declare function isTransferPrimitive(primitive: string): boolean;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Chaos AI SDK - Primitive Constants
|
|
2
|
+
//
|
|
3
|
+
// Constants for all DeFi primitive types supported by the SDK.
|
|
4
|
+
// Use these when checking primitive types in TransactionActionBlocks.
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// Primitive Type Constants
|
|
7
|
+
// ============================================================================
|
|
8
|
+
/**
|
|
9
|
+
* Swap tokens on a decentralized exchange.
|
|
10
|
+
* @example "Swap 1 ETH for USDC"
|
|
11
|
+
*/
|
|
12
|
+
export const PRIMITIVE_SWAP = 'swap';
|
|
13
|
+
/**
|
|
14
|
+
* Supply assets to a lending protocol.
|
|
15
|
+
* @example "Supply 1000 USDC to Aave"
|
|
16
|
+
*/
|
|
17
|
+
export const PRIMITIVE_SUPPLY = 'supply';
|
|
18
|
+
/**
|
|
19
|
+
* Withdraw supplied assets from a lending protocol.
|
|
20
|
+
* @example "Withdraw my USDC from Compound"
|
|
21
|
+
*/
|
|
22
|
+
export const PRIMITIVE_WITHDRAW = 'withdraw';
|
|
23
|
+
/**
|
|
24
|
+
* Borrow assets from a lending protocol.
|
|
25
|
+
* @example "Borrow 500 DAI from Aave"
|
|
26
|
+
*/
|
|
27
|
+
export const PRIMITIVE_BORROW = 'borrow';
|
|
28
|
+
/**
|
|
29
|
+
* Repay borrowed assets to a lending protocol.
|
|
30
|
+
* @example "Repay my DAI debt on Compound"
|
|
31
|
+
*/
|
|
32
|
+
export const PRIMITIVE_REPAY = 'repay';
|
|
33
|
+
/**
|
|
34
|
+
* Stake tokens for rewards or governance.
|
|
35
|
+
* @example "Stake 10 ETH with Lido"
|
|
36
|
+
*/
|
|
37
|
+
export const PRIMITIVE_STAKE = 'stake';
|
|
38
|
+
/**
|
|
39
|
+
* Unstake previously staked tokens.
|
|
40
|
+
* @example "Unstake my stETH"
|
|
41
|
+
*/
|
|
42
|
+
export const PRIMITIVE_UNSTAKE = 'unstake';
|
|
43
|
+
/**
|
|
44
|
+
* Claim accrued rewards from protocols.
|
|
45
|
+
* @example "Claim my Aave rewards"
|
|
46
|
+
*/
|
|
47
|
+
export const PRIMITIVE_CLAIM = 'claim';
|
|
48
|
+
/**
|
|
49
|
+
* Bridge assets between chains.
|
|
50
|
+
* @example "Bridge 100 USDC to Arbitrum"
|
|
51
|
+
*/
|
|
52
|
+
export const PRIMITIVE_BRIDGE = 'bridge';
|
|
53
|
+
/**
|
|
54
|
+
* Provide liquidity to a pool.
|
|
55
|
+
* @example "Add liquidity to ETH-USDC pool"
|
|
56
|
+
*/
|
|
57
|
+
export const PRIMITIVE_ADD_LIQUIDITY = 'add_liquidity';
|
|
58
|
+
/**
|
|
59
|
+
* Remove liquidity from a pool.
|
|
60
|
+
* @example "Remove liquidity from my ETH-USDC position"
|
|
61
|
+
*/
|
|
62
|
+
export const PRIMITIVE_REMOVE_LIQUIDITY = 'remove_liquidity';
|
|
63
|
+
/**
|
|
64
|
+
* Open a perpetual futures position.
|
|
65
|
+
* @example "Open 2x long ETH position"
|
|
66
|
+
*/
|
|
67
|
+
export const PRIMITIVE_OPEN_POSITION = 'open_position';
|
|
68
|
+
/**
|
|
69
|
+
* Close a perpetual futures position.
|
|
70
|
+
* @example "Close my ETH long"
|
|
71
|
+
*/
|
|
72
|
+
export const PRIMITIVE_CLOSE_POSITION = 'close_position';
|
|
73
|
+
/**
|
|
74
|
+
* Deposit into a vault strategy.
|
|
75
|
+
* @example "Deposit 1000 USDC into Yearn"
|
|
76
|
+
*/
|
|
77
|
+
export const PRIMITIVE_DEPOSIT = 'deposit';
|
|
78
|
+
/**
|
|
79
|
+
* Mint stablecoins or synthetic assets.
|
|
80
|
+
* @example "Mint 1000 DAI from my ETH collateral"
|
|
81
|
+
*/
|
|
82
|
+
export const PRIMITIVE_MINT = 'mint';
|
|
83
|
+
/**
|
|
84
|
+
* Burn or repay minted assets.
|
|
85
|
+
* @example "Burn 500 DAI to reduce my debt"
|
|
86
|
+
*/
|
|
87
|
+
export const PRIMITIVE_BURN = 'burn';
|
|
88
|
+
/**
|
|
89
|
+
* Restake assets for additional yield.
|
|
90
|
+
* @example "Restake my stETH on EigenLayer"
|
|
91
|
+
*/
|
|
92
|
+
export const PRIMITIVE_RESTAKE = 'restake';
|
|
93
|
+
/**
|
|
94
|
+
* Approve token spending.
|
|
95
|
+
* @example "Approve USDC for Uniswap"
|
|
96
|
+
*/
|
|
97
|
+
export const PRIMITIVE_APPROVE = 'approve';
|
|
98
|
+
/**
|
|
99
|
+
* Transfer tokens to another address.
|
|
100
|
+
* @example "Send 100 USDC to 0x..."
|
|
101
|
+
*/
|
|
102
|
+
export const PRIMITIVE_TRANSFER = 'transfer';
|
|
103
|
+
/**
|
|
104
|
+
* Wrap native tokens (e.g., ETH to WETH).
|
|
105
|
+
* @example "Wrap 1 ETH to WETH"
|
|
106
|
+
*/
|
|
107
|
+
export const PRIMITIVE_WRAP = 'wrap';
|
|
108
|
+
/**
|
|
109
|
+
* Unwrap wrapped tokens (e.g., WETH to ETH).
|
|
110
|
+
* @example "Unwrap 1 WETH to ETH"
|
|
111
|
+
*/
|
|
112
|
+
export const PRIMITIVE_UNWRAP = 'unwrap';
|
|
113
|
+
/**
|
|
114
|
+
* All primitive type constants for iteration.
|
|
115
|
+
*/
|
|
116
|
+
export const ALL_PRIMITIVES = [
|
|
117
|
+
PRIMITIVE_SWAP,
|
|
118
|
+
PRIMITIVE_SUPPLY,
|
|
119
|
+
PRIMITIVE_WITHDRAW,
|
|
120
|
+
PRIMITIVE_BORROW,
|
|
121
|
+
PRIMITIVE_REPAY,
|
|
122
|
+
PRIMITIVE_STAKE,
|
|
123
|
+
PRIMITIVE_UNSTAKE,
|
|
124
|
+
PRIMITIVE_CLAIM,
|
|
125
|
+
PRIMITIVE_BRIDGE,
|
|
126
|
+
PRIMITIVE_ADD_LIQUIDITY,
|
|
127
|
+
PRIMITIVE_REMOVE_LIQUIDITY,
|
|
128
|
+
PRIMITIVE_OPEN_POSITION,
|
|
129
|
+
PRIMITIVE_CLOSE_POSITION,
|
|
130
|
+
PRIMITIVE_DEPOSIT,
|
|
131
|
+
PRIMITIVE_MINT,
|
|
132
|
+
PRIMITIVE_BURN,
|
|
133
|
+
PRIMITIVE_RESTAKE,
|
|
134
|
+
PRIMITIVE_APPROVE,
|
|
135
|
+
PRIMITIVE_TRANSFER,
|
|
136
|
+
PRIMITIVE_WRAP,
|
|
137
|
+
PRIMITIVE_UNWRAP,
|
|
138
|
+
];
|
|
139
|
+
/**
|
|
140
|
+
* Lending-related primitives.
|
|
141
|
+
*/
|
|
142
|
+
export const LENDING_PRIMITIVES = [
|
|
143
|
+
PRIMITIVE_SUPPLY,
|
|
144
|
+
PRIMITIVE_WITHDRAW,
|
|
145
|
+
PRIMITIVE_BORROW,
|
|
146
|
+
PRIMITIVE_REPAY,
|
|
147
|
+
];
|
|
148
|
+
/**
|
|
149
|
+
* Trading-related primitives.
|
|
150
|
+
*/
|
|
151
|
+
export const TRADING_PRIMITIVES = [
|
|
152
|
+
PRIMITIVE_SWAP,
|
|
153
|
+
PRIMITIVE_OPEN_POSITION,
|
|
154
|
+
PRIMITIVE_CLOSE_POSITION,
|
|
155
|
+
];
|
|
156
|
+
/**
|
|
157
|
+
* Staking-related primitives.
|
|
158
|
+
*/
|
|
159
|
+
export const STAKING_PRIMITIVES = [
|
|
160
|
+
PRIMITIVE_STAKE,
|
|
161
|
+
PRIMITIVE_UNSTAKE,
|
|
162
|
+
PRIMITIVE_RESTAKE,
|
|
163
|
+
PRIMITIVE_CLAIM,
|
|
164
|
+
];
|
|
165
|
+
/**
|
|
166
|
+
* Liquidity-related primitives.
|
|
167
|
+
*/
|
|
168
|
+
export const LIQUIDITY_PRIMITIVES = [
|
|
169
|
+
PRIMITIVE_ADD_LIQUIDITY,
|
|
170
|
+
PRIMITIVE_REMOVE_LIQUIDITY,
|
|
171
|
+
PRIMITIVE_DEPOSIT,
|
|
172
|
+
];
|
|
173
|
+
/**
|
|
174
|
+
* Transfer-related primitives.
|
|
175
|
+
*/
|
|
176
|
+
export const TRANSFER_PRIMITIVES = [
|
|
177
|
+
PRIMITIVE_BRIDGE,
|
|
178
|
+
PRIMITIVE_TRANSFER,
|
|
179
|
+
PRIMITIVE_WRAP,
|
|
180
|
+
PRIMITIVE_UNWRAP,
|
|
181
|
+
];
|
|
182
|
+
// ============================================================================
|
|
183
|
+
// Primitive Helpers
|
|
184
|
+
// ============================================================================
|
|
185
|
+
/**
|
|
186
|
+
* Check if a primitive type is valid.
|
|
187
|
+
*/
|
|
188
|
+
export function isValidPrimitive(primitive) {
|
|
189
|
+
return ALL_PRIMITIVES.includes(primitive);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check if a primitive is a lending operation.
|
|
193
|
+
*/
|
|
194
|
+
export function isLendingPrimitive(primitive) {
|
|
195
|
+
return LENDING_PRIMITIVES.includes(primitive);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if a primitive is a trading operation.
|
|
199
|
+
*/
|
|
200
|
+
export function isTradingPrimitive(primitive) {
|
|
201
|
+
return TRADING_PRIMITIVES.includes(primitive);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Check if a primitive is a staking operation.
|
|
205
|
+
*/
|
|
206
|
+
export function isStakingPrimitive(primitive) {
|
|
207
|
+
return STAKING_PRIMITIVES.includes(primitive);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Check if a primitive is a liquidity operation.
|
|
211
|
+
*/
|
|
212
|
+
export function isLiquidityPrimitive(primitive) {
|
|
213
|
+
return LIQUIDITY_PRIMITIVES.includes(primitive);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if a primitive is a transfer operation.
|
|
217
|
+
*/
|
|
218
|
+
export function isTransferPrimitive(primitive) {
|
|
219
|
+
return TRANSFER_PRIMITIVES.includes(primitive);
|
|
220
|
+
}
|