@chaoslabs/ai-sdk 0.0.10 → 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 +156 -0
- package/README.md +44 -24
- 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 +10 -7
- 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.d.ts +204 -9
- package/dist/stream.js +12 -21
- 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 +7 -8
package/dist/primitives.d.ts
CHANGED
|
@@ -155,3 +155,461 @@ export declare function isLiquidityPrimitive(primitive: string): boolean;
|
|
|
155
155
|
* Check if a primitive is a transfer operation.
|
|
156
156
|
*/
|
|
157
157
|
export declare function isTransferPrimitive(primitive: string): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Parameters for a swap operation.
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const params: SwapParams = {
|
|
163
|
+
* token_in: 'ETH',
|
|
164
|
+
* token_out: 'USDC',
|
|
165
|
+
* amount_in: '1.0',
|
|
166
|
+
* slippage: 0.5
|
|
167
|
+
* };
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export interface SwapParams {
|
|
171
|
+
/** Token to swap from */
|
|
172
|
+
token_in: string;
|
|
173
|
+
/** Token to swap to */
|
|
174
|
+
token_out: string;
|
|
175
|
+
/** Amount of input token to swap */
|
|
176
|
+
amount_in?: string;
|
|
177
|
+
/** Exact amount of output token desired */
|
|
178
|
+
amount_out?: string;
|
|
179
|
+
/** Maximum slippage tolerance as percentage (e.g., 0.5 for 0.5%) */
|
|
180
|
+
slippage?: number;
|
|
181
|
+
/** DEX or aggregator to use */
|
|
182
|
+
protocol?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Parameters for a bridge operation.
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const params: BridgeParams = {
|
|
189
|
+
* asset: 'USDC',
|
|
190
|
+
* amount: '100',
|
|
191
|
+
* from_chain: 'ethereum',
|
|
192
|
+
* to_chain: 'arbitrum'
|
|
193
|
+
* };
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export interface BridgeParams {
|
|
197
|
+
/** Asset to bridge */
|
|
198
|
+
asset: string;
|
|
199
|
+
/** Amount to bridge */
|
|
200
|
+
amount: string;
|
|
201
|
+
/** Source chain */
|
|
202
|
+
from_chain: string;
|
|
203
|
+
/** Destination chain */
|
|
204
|
+
to_chain: string;
|
|
205
|
+
/** Recipient address on destination chain (defaults to sender) */
|
|
206
|
+
recipient?: string;
|
|
207
|
+
/** Bridge protocol to use */
|
|
208
|
+
protocol?: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Parameters for lending operations (supply, withdraw, borrow, repay).
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const params: LendingParams = {
|
|
215
|
+
* asset: 'USDC',
|
|
216
|
+
* amount: '1000',
|
|
217
|
+
* protocol: 'aave'
|
|
218
|
+
* };
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export interface LendingParams {
|
|
222
|
+
/** Asset to supply/withdraw/borrow/repay */
|
|
223
|
+
asset: string;
|
|
224
|
+
/** Amount of asset */
|
|
225
|
+
amount: string;
|
|
226
|
+
/** Lending protocol (e.g., 'aave', 'compound', 'morpho') */
|
|
227
|
+
protocol?: string;
|
|
228
|
+
/** Interest rate mode for borrow (1 = stable, 2 = variable) */
|
|
229
|
+
interest_rate_mode?: number;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Parameters for staking operations (stake, unstake, restake).
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const params: StakingParams = {
|
|
236
|
+
* amount: '10',
|
|
237
|
+
* protocol: 'lido'
|
|
238
|
+
* };
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export interface StakingParams {
|
|
242
|
+
/** Amount to stake/unstake */
|
|
243
|
+
amount: string;
|
|
244
|
+
/** Staking protocol (e.g., 'lido', 'rocketpool', 'eigenlayer') */
|
|
245
|
+
protocol?: string;
|
|
246
|
+
/** Operator address for delegation (restaking) */
|
|
247
|
+
operator?: string;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Parameters for claiming rewards.
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const params: ClaimParams = {
|
|
254
|
+
* protocol: 'aave',
|
|
255
|
+
* assets: ['USDC', 'DAI']
|
|
256
|
+
* };
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export interface ClaimParams {
|
|
260
|
+
/** Protocol to claim from */
|
|
261
|
+
protocol?: string;
|
|
262
|
+
/** Specific assets to claim rewards for */
|
|
263
|
+
assets?: string[];
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Parameters for liquidity operations (add/remove liquidity).
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* const params: LiquidityParams = {
|
|
270
|
+
* token_a: 'ETH',
|
|
271
|
+
* token_b: 'USDC',
|
|
272
|
+
* amount_a: '1.0',
|
|
273
|
+
* amount_b: '2000'
|
|
274
|
+
* };
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
export interface LiquidityParams {
|
|
278
|
+
/** First token in the pair */
|
|
279
|
+
token_a: string;
|
|
280
|
+
/** Second token in the pair */
|
|
281
|
+
token_b: string;
|
|
282
|
+
/** Amount of first token */
|
|
283
|
+
amount_a?: string;
|
|
284
|
+
/** Amount of second token */
|
|
285
|
+
amount_b?: string;
|
|
286
|
+
/** Percentage of position to remove (for remove_liquidity) */
|
|
287
|
+
percentage?: number;
|
|
288
|
+
/** Pool fee tier (e.g., 0.3 for 0.3%) */
|
|
289
|
+
fee_tier?: number;
|
|
290
|
+
/** DEX protocol */
|
|
291
|
+
protocol?: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Parameters for perpetual position operations.
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const params: PositionParams = {
|
|
298
|
+
* market: 'ETH-PERP',
|
|
299
|
+
* side: 'long',
|
|
300
|
+
* size: '1.0',
|
|
301
|
+
* leverage: 2
|
|
302
|
+
* };
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
export interface PositionParams {
|
|
306
|
+
/** Market identifier (e.g., 'ETH-PERP') */
|
|
307
|
+
market: string;
|
|
308
|
+
/** Position side: 'long' or 'short' */
|
|
309
|
+
side?: 'long' | 'short';
|
|
310
|
+
/** Position size */
|
|
311
|
+
size?: string;
|
|
312
|
+
/** Leverage multiplier */
|
|
313
|
+
leverage?: number;
|
|
314
|
+
/** Percentage of position to close */
|
|
315
|
+
percentage?: number;
|
|
316
|
+
/** Perpetuals protocol */
|
|
317
|
+
protocol?: string;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Parameters for vault deposit operations.
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const params: DepositParams = {
|
|
324
|
+
* vault: 'yearn-usdc',
|
|
325
|
+
* amount: '1000'
|
|
326
|
+
* };
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export interface DepositParams {
|
|
330
|
+
/** Vault identifier */
|
|
331
|
+
vault: string;
|
|
332
|
+
/** Amount to deposit */
|
|
333
|
+
amount: string;
|
|
334
|
+
/** Vault protocol */
|
|
335
|
+
protocol?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Parameters for minting operations (e.g., minting stablecoins).
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* const params: MintParams = {
|
|
342
|
+
* asset: 'DAI',
|
|
343
|
+
* amount: '1000',
|
|
344
|
+
* collateral: 'ETH'
|
|
345
|
+
* };
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export interface MintParams {
|
|
349
|
+
/** Asset to mint */
|
|
350
|
+
asset: string;
|
|
351
|
+
/** Amount to mint */
|
|
352
|
+
amount: string;
|
|
353
|
+
/** Collateral asset */
|
|
354
|
+
collateral?: string;
|
|
355
|
+
/** Protocol (e.g., 'maker') */
|
|
356
|
+
protocol?: string;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Parameters for token approval operations.
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const params: ApproveParams = {
|
|
363
|
+
* token: 'USDC',
|
|
364
|
+
* spender: '0x1234...',
|
|
365
|
+
* amount: '1000'
|
|
366
|
+
* };
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export interface ApproveParams {
|
|
370
|
+
/** Token to approve */
|
|
371
|
+
token: string;
|
|
372
|
+
/** Spender address */
|
|
373
|
+
spender: string;
|
|
374
|
+
/** Amount to approve (omit for unlimited) */
|
|
375
|
+
amount?: string;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Parameters for token transfer operations.
|
|
379
|
+
* @example
|
|
380
|
+
* ```typescript
|
|
381
|
+
* const params: TransferParams = {
|
|
382
|
+
* token: 'USDC',
|
|
383
|
+
* to: '0x1234...',
|
|
384
|
+
* amount: '100'
|
|
385
|
+
* };
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
export interface TransferParams {
|
|
389
|
+
/** Token to transfer */
|
|
390
|
+
token: string;
|
|
391
|
+
/** Recipient address */
|
|
392
|
+
to: string;
|
|
393
|
+
/** Amount to transfer */
|
|
394
|
+
amount: string;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Parameters for wrap/unwrap operations (e.g., ETH to WETH).
|
|
398
|
+
* @example
|
|
399
|
+
* ```typescript
|
|
400
|
+
* const params: WrapParams = {
|
|
401
|
+
* amount: '1.0'
|
|
402
|
+
* };
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
export interface WrapParams {
|
|
406
|
+
/** Amount to wrap/unwrap */
|
|
407
|
+
amount: string;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Icon for primitive display.
|
|
411
|
+
*/
|
|
412
|
+
export interface PrimitiveIcon {
|
|
413
|
+
type: 'url' | 'icon_id';
|
|
414
|
+
value: string;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Line item for primitive display.
|
|
418
|
+
*/
|
|
419
|
+
export interface PrimitiveLineItem {
|
|
420
|
+
label: string;
|
|
421
|
+
value: string;
|
|
422
|
+
icon?: PrimitiveIcon;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Display information for a primitive.
|
|
426
|
+
*/
|
|
427
|
+
export interface PrimitiveDisplay {
|
|
428
|
+
headline?: string;
|
|
429
|
+
action_verb?: string;
|
|
430
|
+
primary_icon?: PrimitiveIcon;
|
|
431
|
+
secondary_icon?: PrimitiveIcon;
|
|
432
|
+
line_items?: PrimitiveLineItem[];
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Base structure for a typed primitive with display info.
|
|
436
|
+
*/
|
|
437
|
+
interface TypedPrimitiveBase {
|
|
438
|
+
/** Display information for UI rendering */
|
|
439
|
+
display?: PrimitiveDisplay;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Swap primitive with typed params.
|
|
443
|
+
*/
|
|
444
|
+
export interface SwapPrimitive extends TypedPrimitiveBase {
|
|
445
|
+
primitive: typeof PRIMITIVE_SWAP;
|
|
446
|
+
params: SwapParams;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Bridge primitive with typed params.
|
|
450
|
+
*/
|
|
451
|
+
export interface BridgePrimitive extends TypedPrimitiveBase {
|
|
452
|
+
primitive: typeof PRIMITIVE_BRIDGE;
|
|
453
|
+
params: BridgeParams;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Supply primitive with typed params.
|
|
457
|
+
*/
|
|
458
|
+
export interface SupplyPrimitive extends TypedPrimitiveBase {
|
|
459
|
+
primitive: typeof PRIMITIVE_SUPPLY;
|
|
460
|
+
params: LendingParams;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Withdraw primitive with typed params.
|
|
464
|
+
*/
|
|
465
|
+
export interface WithdrawPrimitive extends TypedPrimitiveBase {
|
|
466
|
+
primitive: typeof PRIMITIVE_WITHDRAW;
|
|
467
|
+
params: LendingParams;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Borrow primitive with typed params.
|
|
471
|
+
*/
|
|
472
|
+
export interface BorrowPrimitive extends TypedPrimitiveBase {
|
|
473
|
+
primitive: typeof PRIMITIVE_BORROW;
|
|
474
|
+
params: LendingParams;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Repay primitive with typed params.
|
|
478
|
+
*/
|
|
479
|
+
export interface RepayPrimitive extends TypedPrimitiveBase {
|
|
480
|
+
primitive: typeof PRIMITIVE_REPAY;
|
|
481
|
+
params: LendingParams;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Stake primitive with typed params.
|
|
485
|
+
*/
|
|
486
|
+
export interface StakePrimitive extends TypedPrimitiveBase {
|
|
487
|
+
primitive: typeof PRIMITIVE_STAKE;
|
|
488
|
+
params: StakingParams;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Unstake primitive with typed params.
|
|
492
|
+
*/
|
|
493
|
+
export interface UnstakePrimitive extends TypedPrimitiveBase {
|
|
494
|
+
primitive: typeof PRIMITIVE_UNSTAKE;
|
|
495
|
+
params: StakingParams;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Claim primitive with typed params.
|
|
499
|
+
*/
|
|
500
|
+
export interface ClaimPrimitive extends TypedPrimitiveBase {
|
|
501
|
+
primitive: typeof PRIMITIVE_CLAIM;
|
|
502
|
+
params: ClaimParams;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Add liquidity primitive with typed params.
|
|
506
|
+
*/
|
|
507
|
+
export interface AddLiquidityPrimitive extends TypedPrimitiveBase {
|
|
508
|
+
primitive: typeof PRIMITIVE_ADD_LIQUIDITY;
|
|
509
|
+
params: LiquidityParams;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Remove liquidity primitive with typed params.
|
|
513
|
+
*/
|
|
514
|
+
export interface RemoveLiquidityPrimitive extends TypedPrimitiveBase {
|
|
515
|
+
primitive: typeof PRIMITIVE_REMOVE_LIQUIDITY;
|
|
516
|
+
params: LiquidityParams;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Open position primitive with typed params.
|
|
520
|
+
*/
|
|
521
|
+
export interface OpenPositionPrimitive extends TypedPrimitiveBase {
|
|
522
|
+
primitive: typeof PRIMITIVE_OPEN_POSITION;
|
|
523
|
+
params: PositionParams;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Close position primitive with typed params.
|
|
527
|
+
*/
|
|
528
|
+
export interface ClosePositionPrimitive extends TypedPrimitiveBase {
|
|
529
|
+
primitive: typeof PRIMITIVE_CLOSE_POSITION;
|
|
530
|
+
params: PositionParams;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Deposit primitive with typed params.
|
|
534
|
+
*/
|
|
535
|
+
export interface DepositPrimitive extends TypedPrimitiveBase {
|
|
536
|
+
primitive: typeof PRIMITIVE_DEPOSIT;
|
|
537
|
+
params: DepositParams;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Mint primitive with typed params.
|
|
541
|
+
*/
|
|
542
|
+
export interface MintPrimitive extends TypedPrimitiveBase {
|
|
543
|
+
primitive: typeof PRIMITIVE_MINT;
|
|
544
|
+
params: MintParams;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Burn primitive with typed params.
|
|
548
|
+
*/
|
|
549
|
+
export interface BurnPrimitive extends TypedPrimitiveBase {
|
|
550
|
+
primitive: typeof PRIMITIVE_BURN;
|
|
551
|
+
params: MintParams;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Restake primitive with typed params.
|
|
555
|
+
*/
|
|
556
|
+
export interface RestakePrimitive extends TypedPrimitiveBase {
|
|
557
|
+
primitive: typeof PRIMITIVE_RESTAKE;
|
|
558
|
+
params: StakingParams;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Approve primitive with typed params.
|
|
562
|
+
*/
|
|
563
|
+
export interface ApprovePrimitive extends TypedPrimitiveBase {
|
|
564
|
+
primitive: typeof PRIMITIVE_APPROVE;
|
|
565
|
+
params: ApproveParams;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Transfer primitive with typed params.
|
|
569
|
+
*/
|
|
570
|
+
export interface TransferPrimitive extends TypedPrimitiveBase {
|
|
571
|
+
primitive: typeof PRIMITIVE_TRANSFER;
|
|
572
|
+
params: TransferParams;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Wrap primitive with typed params.
|
|
576
|
+
*/
|
|
577
|
+
export interface WrapPrimitive extends TypedPrimitiveBase {
|
|
578
|
+
primitive: typeof PRIMITIVE_WRAP;
|
|
579
|
+
params: WrapParams;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Unwrap primitive with typed params.
|
|
583
|
+
*/
|
|
584
|
+
export interface UnwrapPrimitive extends TypedPrimitiveBase {
|
|
585
|
+
primitive: typeof PRIMITIVE_UNWRAP;
|
|
586
|
+
params: WrapParams;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Fallback for unknown primitive types.
|
|
590
|
+
* This ensures forward compatibility when new primitives are added.
|
|
591
|
+
*/
|
|
592
|
+
export interface UnknownPrimitive extends TypedPrimitiveBase {
|
|
593
|
+
primitive: string;
|
|
594
|
+
params: Record<string, unknown>;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Discriminated union of all typed primitives.
|
|
598
|
+
*
|
|
599
|
+
* Use type guards to narrow to specific primitive types and access
|
|
600
|
+
* typed params:
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```typescript
|
|
604
|
+
* import { isSwapPrimitive } from '@chaoslabs/ai-sdk';
|
|
605
|
+
*
|
|
606
|
+
* function handlePrimitive(p: TypedPrimitive) {
|
|
607
|
+
* if (isSwapPrimitive(p)) {
|
|
608
|
+
* // TypeScript knows p.params is SwapParams
|
|
609
|
+
* console.log(`Swapping ${p.params.token_in} for ${p.params.token_out}`);
|
|
610
|
+
* }
|
|
611
|
+
* }
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
export type Primitive = SwapPrimitive | BridgePrimitive | SupplyPrimitive | WithdrawPrimitive | BorrowPrimitive | RepayPrimitive | StakePrimitive | UnstakePrimitive | ClaimPrimitive | AddLiquidityPrimitive | RemoveLiquidityPrimitive | OpenPositionPrimitive | ClosePositionPrimitive | DepositPrimitive | MintPrimitive | BurnPrimitive | RestakePrimitive | ApprovePrimitive | TransferPrimitive | WrapPrimitive | UnwrapPrimitive | UnknownPrimitive;
|
|
615
|
+
export {};
|
package/dist/primitives.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// ============================================================================
|
|
6
6
|
// Primitive Type Constants
|
|
7
7
|
// ============================================================================
|
|
8
|
+
// import type { PrimitiveDisplay } from './types.js';
|
|
8
9
|
/**
|
|
9
10
|
* Swap tokens on a decentralized exchange.
|
|
10
11
|
* @example "Swap 1 ETH for USDC"
|
package/dist/request.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
import type { CreateResponseParams } from './types.js';
|
|
1
|
+
import type { CreateResponseParams, WalletInfo } from './types.js';
|
|
2
2
|
/** Model ID for wallet mode (v1 API) */
|
|
3
3
|
export declare const WALLET_MODEL = "WALLET_MODEL";
|
|
4
4
|
/** Model ID for ask mode (v1 API) */
|
|
5
5
|
export declare const ASK_MODEL = "ASK_MODEL";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Message format for previous_messages array.
|
|
8
|
+
*/
|
|
9
|
+
export interface PreviousMessage {
|
|
10
|
+
type: 'message';
|
|
11
|
+
role: 'user' | 'assistant';
|
|
12
|
+
content: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* V1 API request body for wallet mode with multi-wallet support.
|
|
8
16
|
*/
|
|
9
17
|
export interface V1WalletRequest {
|
|
10
18
|
model: string;
|
|
11
19
|
query: string;
|
|
12
20
|
user_id: string;
|
|
13
21
|
session_id: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
role: string;
|
|
17
|
-
content: string;
|
|
18
|
-
}[];
|
|
22
|
+
wallets?: WalletInfo[];
|
|
23
|
+
previous_messages?: PreviousMessage[];
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
26
|
* V1 API request body for ask mode.
|
|
@@ -25,13 +30,10 @@ export interface V1AskRequest {
|
|
|
25
30
|
query: string;
|
|
26
31
|
user_id: string;
|
|
27
32
|
session_id: string;
|
|
28
|
-
|
|
29
|
-
role: string;
|
|
30
|
-
content: string;
|
|
31
|
-
}[];
|
|
33
|
+
previous_messages?: PreviousMessage[];
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
|
-
* Transform SDK request to v1 wallet format.
|
|
36
|
+
* Transform SDK request to v1 wallet format with multi-wallet support.
|
|
35
37
|
*/
|
|
36
38
|
export declare function toV1WalletRequest(params: CreateResponseParams, sessionId: string): V1WalletRequest;
|
|
37
39
|
/**
|
package/dist/request.js
CHANGED
|
@@ -10,18 +10,18 @@ export const ASK_MODEL = 'ASK_MODEL';
|
|
|
10
10
|
// Request Builders
|
|
11
11
|
// ============================================================================
|
|
12
12
|
/**
|
|
13
|
-
* Transform SDK request to v1 wallet format.
|
|
13
|
+
* Transform SDK request to v1 wallet format with multi-wallet support.
|
|
14
14
|
*/
|
|
15
15
|
export function toV1WalletRequest(params, sessionId) {
|
|
16
16
|
const query = extractQuery(params.input);
|
|
17
|
-
const
|
|
17
|
+
const previousMessages = extractPriorMessages(params.input);
|
|
18
18
|
return {
|
|
19
19
|
model: params.model,
|
|
20
20
|
query,
|
|
21
21
|
user_id: params.metadata.user_id,
|
|
22
22
|
session_id: sessionId,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
...(params.metadata.wallets && { wallets: params.metadata.wallets }),
|
|
24
|
+
previous_messages: previousMessages.length > 0 ? previousMessages : undefined,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
@@ -29,13 +29,13 @@ export function toV1WalletRequest(params, sessionId) {
|
|
|
29
29
|
*/
|
|
30
30
|
export function toV1AskRequest(params, sessionId) {
|
|
31
31
|
const query = extractQuery(params.input);
|
|
32
|
-
const
|
|
32
|
+
const previousMessages = extractPriorMessages(params.input);
|
|
33
33
|
return {
|
|
34
34
|
model: params.model,
|
|
35
35
|
query,
|
|
36
36
|
user_id: params.metadata.user_id,
|
|
37
37
|
session_id: sessionId,
|
|
38
|
-
|
|
38
|
+
previous_messages: previousMessages.length > 0 ? previousMessages : undefined,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
// ============================================================================
|
|
@@ -59,18 +59,48 @@ function extractPriorMessages(input) {
|
|
|
59
59
|
const messages = [];
|
|
60
60
|
let lastUserIndex = -1;
|
|
61
61
|
for (let i = input.length - 1; i >= 0; i--) {
|
|
62
|
-
|
|
62
|
+
const item = input[i];
|
|
63
|
+
// Find the last actual user message (not an assistant message)
|
|
64
|
+
if (item.role === 'user' && !item.content.startsWith('[Assistant]: ')) {
|
|
63
65
|
lastUserIndex = i;
|
|
64
66
|
break;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
for (let i = 0; i < lastUserIndex; i++) {
|
|
68
70
|
const item = input[i];
|
|
69
|
-
if (item.type === 'message'
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (item.type === 'message') {
|
|
72
|
+
// Handle assistant role directly
|
|
73
|
+
if (item.role === 'assistant') {
|
|
74
|
+
messages.push({
|
|
75
|
+
type: 'message',
|
|
76
|
+
role: 'assistant',
|
|
77
|
+
content: item.content,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Also support legacy format with [Assistant]: prefix
|
|
81
|
+
else if (item.content.startsWith('[Assistant]: ')) {
|
|
82
|
+
messages.push({
|
|
83
|
+
type: 'message',
|
|
84
|
+
role: 'assistant',
|
|
85
|
+
content: item.content.replace('[Assistant]: ', ''),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Regular user message
|
|
89
|
+
else if (item.role === 'user') {
|
|
90
|
+
messages.push({
|
|
91
|
+
type: 'message',
|
|
92
|
+
role: 'user',
|
|
93
|
+
content: item.content,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// System messages (if needed for special instructions)
|
|
97
|
+
else if (item.role === 'system') {
|
|
98
|
+
messages.push({
|
|
99
|
+
type: 'message',
|
|
100
|
+
role: 'user',
|
|
101
|
+
content: item.content,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
74
104
|
}
|
|
75
105
|
}
|
|
76
106
|
return messages;
|
package/dist/response.js
CHANGED
|
@@ -76,33 +76,24 @@ function parseBlock(rawBlock) {
|
|
|
76
76
|
const result = parseRawBlock(rawBlock);
|
|
77
77
|
if (result.success) {
|
|
78
78
|
const block = result.data;
|
|
79
|
-
// Transform legacy chart data format
|
|
79
|
+
// Transform legacy chart data format - clean up null values for cleaner API
|
|
80
80
|
if (block.type === 'chart') {
|
|
81
81
|
const chartBlock = block;
|
|
82
|
-
//
|
|
83
|
-
if (chartBlock.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
// Clean up null to undefined for optional fields
|
|
83
|
+
if (chartBlock.chartType === 'pie') {
|
|
84
|
+
const pieBlock = chartBlock;
|
|
85
|
+
if (pieBlock.isCurrency === null)
|
|
86
|
+
pieBlock.isCurrency = undefined;
|
|
87
|
+
}
|
|
88
|
+
else if (chartBlock.chartType === 'timeseries') {
|
|
89
|
+
const timeseriesBlock = chartBlock;
|
|
90
|
+
if (timeseriesBlock.captions === null)
|
|
91
|
+
timeseriesBlock.captions = undefined;
|
|
92
|
+
if (timeseriesBlock.titleCryptoIcons === null)
|
|
93
|
+
timeseriesBlock.titleCryptoIcons = undefined;
|
|
94
|
+
if (timeseriesBlock.isCurrency === null)
|
|
95
|
+
timeseriesBlock.isCurrency = undefined;
|
|
88
96
|
}
|
|
89
|
-
// Clean up null values for cleaner API
|
|
90
|
-
if (chartBlock.segments === null)
|
|
91
|
-
chartBlock.segments = undefined;
|
|
92
|
-
if (chartBlock.series === null)
|
|
93
|
-
chartBlock.series = undefined;
|
|
94
|
-
if (chartBlock.categories === null)
|
|
95
|
-
chartBlock.categories = undefined;
|
|
96
|
-
if (chartBlock.xAxis === null)
|
|
97
|
-
chartBlock.xAxis = undefined;
|
|
98
|
-
if (chartBlock.yAxis === null)
|
|
99
|
-
chartBlock.yAxis = undefined;
|
|
100
|
-
if (chartBlock.sourceName === null)
|
|
101
|
-
chartBlock.sourceName = undefined;
|
|
102
|
-
if (chartBlock.timeframe === null)
|
|
103
|
-
chartBlock.timeframe = undefined;
|
|
104
|
-
if (chartBlock.isCurrency === null)
|
|
105
|
-
chartBlock.isCurrency = undefined;
|
|
106
97
|
}
|
|
107
98
|
return block;
|
|
108
99
|
}
|