@elizaos/training 2.0.0-alpha.13 → 2.0.0-alpha.15
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/package.json +2 -2
- package/research-output/training-runs/training-run-1773726941205.json +38 -0
- package/scripts/rank_trajectories.ts +0 -1
- package/scripts/run_task_benchmark.ts +4 -11
- package/src/adapter.ts +96 -49
- package/src/archetypes/ArchetypeConfigService.ts +188 -185
- package/src/archetypes/derive-archetype.ts +47 -47
- package/src/archetypes/index.ts +2 -2
- package/src/benchmark/ArchetypeMatchupBenchmark.ts +70 -70
- package/src/benchmark/BenchmarkChartGenerator.ts +70 -69
- package/src/benchmark/BenchmarkDataGenerator.ts +136 -136
- package/src/benchmark/BenchmarkDataViewer.ts +32 -30
- package/src/benchmark/BenchmarkHistoryService.ts +13 -12
- package/src/benchmark/BenchmarkRunner.ts +87 -83
- package/src/benchmark/BenchmarkValidator.ts +48 -46
- package/src/benchmark/FastEvalRunner.ts +17 -16
- package/src/benchmark/MetricsValidator.ts +20 -21
- package/src/benchmark/MetricsVisualizer.ts +92 -85
- package/src/benchmark/ModelBenchmarkService.ts +90 -82
- package/src/benchmark/ModelRegistry.ts +44 -44
- package/src/benchmark/RulerBenchmarkIntegration.ts +24 -24
- package/src/benchmark/SimulationA2AInterface.ts +118 -118
- package/src/benchmark/SimulationEngine.ts +51 -51
- package/src/benchmark/TaskRunner.ts +87 -79
- package/src/benchmark/__tests__/BenchmarkRunner.test.ts +80 -80
- package/src/benchmark/__tests__/HeadToHead.test.ts +26 -26
- package/src/benchmark/index.ts +27 -27
- package/src/benchmark/parseSimulationMetrics.ts +32 -32
- package/src/benchmark/simulation-types.ts +10 -10
- package/src/dependencies.ts +34 -34
- package/src/generation/TrajectoryGenerator.ts +39 -37
- package/src/generation/index.ts +1 -1
- package/src/huggingface/HuggingFaceDatasetUploader.ts +72 -72
- package/src/huggingface/HuggingFaceIntegrationService.ts +59 -53
- package/src/huggingface/HuggingFaceModelUploader.ts +60 -59
- package/src/huggingface/index.ts +6 -6
- package/src/huggingface/shared/HuggingFaceUploadUtil.ts +32 -32
- package/src/index.ts +27 -27
- package/src/init-training.ts +6 -6
- package/src/metrics/TrajectoryMetricsExtractor.ts +70 -71
- package/src/metrics/__tests__/TrajectoryMetricsExtractor.test.ts +182 -182
- package/src/metrics/index.ts +2 -2
- package/src/rubrics/__tests__/index.test.ts +73 -73
- package/src/rubrics/ass-kisser.ts +6 -6
- package/src/rubrics/degen.ts +6 -6
- package/src/rubrics/goody-twoshoes.ts +6 -6
- package/src/rubrics/index.ts +50 -50
- package/src/rubrics/information-trader.ts +6 -6
- package/src/rubrics/infosec.ts +6 -6
- package/src/rubrics/liar.ts +6 -6
- package/src/rubrics/perps-trader.ts +6 -6
- package/src/rubrics/researcher.ts +6 -6
- package/src/rubrics/scammer.ts +6 -6
- package/src/rubrics/social-butterfly.ts +7 -7
- package/src/rubrics/super-predictor.ts +6 -6
- package/src/rubrics/trader.ts +5 -5
- package/src/scoring/ArchetypeScoringService.ts +56 -54
- package/src/scoring/JudgePromptBuilder.ts +96 -96
- package/src/scoring/LLMJudgeCache.ts +26 -23
- package/src/scoring/index.ts +3 -3
- package/src/training/AutomationPipeline.ts +149 -140
- package/src/training/BenchmarkService.ts +49 -45
- package/src/training/ConfigValidator.ts +38 -32
- package/src/training/MarketOutcomesTracker.ts +22 -12
- package/src/training/ModelDeployer.ts +15 -15
- package/src/training/ModelFetcher.ts +7 -7
- package/src/training/ModelSelectionService.ts +32 -32
- package/src/training/ModelUsageVerifier.ts +31 -24
- package/src/training/MultiModelOrchestrator.ts +44 -44
- package/src/training/RLModelConfig.ts +57 -57
- package/src/training/RewardBackpropagationService.ts +18 -17
- package/src/training/RulerScoringService.ts +73 -72
- package/src/training/TrainingMonitor.ts +29 -29
- package/src/training/TrajectoryRecorder.ts +25 -27
- package/src/training/__tests__/TrajectoryRecorder.test.ts +105 -105
- package/src/training/index.ts +36 -36
- package/src/training/logRLConfig.ts +7 -7
- package/src/training/pipeline.ts +13 -16
- package/src/training/storage/ModelStorageService.ts +32 -32
- package/src/training/storage/TrainingDataArchiver.ts +21 -21
- package/src/training/storage/index.ts +2 -2
- package/src/training/types.ts +6 -6
- package/src/training/window-utils.ts +14 -14
- package/src/utils/index.ts +7 -7
- package/src/utils/logger.ts +5 -5
- package/src/utils/snowflake.ts +1 -1
- package/src/utils/synthetic-detector.ts +7 -7
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { logger } from
|
|
22
|
-
import type { SimulationEngine } from
|
|
21
|
+
import { logger } from "../utils/logger";
|
|
22
|
+
import type { SimulationEngine } from "./SimulationEngine";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* A2A method parameter types
|
|
@@ -152,7 +152,7 @@ export interface ChatEntry {
|
|
|
152
152
|
* Union type for all A2A response types
|
|
153
153
|
*/
|
|
154
154
|
export type A2AResponse =
|
|
155
|
-
| { predictions: Omit<PredictionMarket,
|
|
155
|
+
| { predictions: Omit<PredictionMarket, "resolved">[] }
|
|
156
156
|
| BuySharesResult
|
|
157
157
|
| SellSharesResult
|
|
158
158
|
| { perpetuals: PerpetualMarket[] }
|
|
@@ -179,7 +179,7 @@ export interface BuySharesParams {
|
|
|
179
179
|
/** Market ID to buy shares in */
|
|
180
180
|
marketId: string;
|
|
181
181
|
/** Outcome to buy (YES or NO) */
|
|
182
|
-
outcome:
|
|
182
|
+
outcome: "YES" | "NO";
|
|
183
183
|
/** Amount to invest */
|
|
184
184
|
amount: number;
|
|
185
185
|
}
|
|
@@ -201,7 +201,7 @@ interface OpenPositionParams {
|
|
|
201
201
|
/** Ticker symbol */
|
|
202
202
|
ticker: string;
|
|
203
203
|
/** Position side (LONG or SHORT) */
|
|
204
|
-
side:
|
|
204
|
+
side: "LONG" | "SHORT";
|
|
205
205
|
/** Position size */
|
|
206
206
|
size: number;
|
|
207
207
|
/** Leverage multiplier */
|
|
@@ -335,9 +335,9 @@ export class SimulationA2AInterface {
|
|
|
335
335
|
*/
|
|
336
336
|
async sendRequest(
|
|
337
337
|
method: string,
|
|
338
|
-
params?: A2AMethodParams
|
|
338
|
+
params?: A2AMethodParams,
|
|
339
339
|
): Promise<A2AResponse> {
|
|
340
|
-
logger.debug(
|
|
340
|
+
logger.debug("Simulation A2A request", { method, params });
|
|
341
341
|
|
|
342
342
|
const actionStart = Date.now();
|
|
343
343
|
|
|
@@ -346,63 +346,63 @@ export class SimulationA2AInterface {
|
|
|
346
346
|
|
|
347
347
|
// Route to appropriate handler
|
|
348
348
|
switch (method) {
|
|
349
|
-
case
|
|
349
|
+
case "a2a.getPredictions":
|
|
350
350
|
result = this.handleGetPredictions(params);
|
|
351
351
|
break;
|
|
352
352
|
|
|
353
|
-
case
|
|
353
|
+
case "a2a.buyShares":
|
|
354
354
|
result = await this.handleBuyShares(params);
|
|
355
355
|
break;
|
|
356
356
|
|
|
357
|
-
case
|
|
357
|
+
case "a2a.sellShares":
|
|
358
358
|
result = await this.handleSellShares(params);
|
|
359
359
|
break;
|
|
360
360
|
|
|
361
|
-
case
|
|
361
|
+
case "a2a.getPerpetuals":
|
|
362
362
|
result = this.handleGetPerpetuals(params);
|
|
363
363
|
break;
|
|
364
364
|
|
|
365
|
-
case
|
|
365
|
+
case "a2a.openPosition":
|
|
366
366
|
result = await this.handleOpenPosition(params);
|
|
367
367
|
break;
|
|
368
368
|
|
|
369
|
-
case
|
|
369
|
+
case "a2a.closePosition":
|
|
370
370
|
result = await this.handleClosePosition(params);
|
|
371
371
|
break;
|
|
372
372
|
|
|
373
|
-
case
|
|
373
|
+
case "a2a.getFeed":
|
|
374
374
|
result = this.handleGetFeed(params);
|
|
375
375
|
break;
|
|
376
376
|
|
|
377
|
-
case
|
|
377
|
+
case "a2a.createPost":
|
|
378
378
|
result = await this.handleCreatePost(params);
|
|
379
379
|
break;
|
|
380
380
|
|
|
381
|
-
case
|
|
381
|
+
case "a2a.getChats":
|
|
382
382
|
result = this.handleGetChats(params);
|
|
383
383
|
break;
|
|
384
384
|
|
|
385
|
-
case
|
|
385
|
+
case "a2a.joinGroup":
|
|
386
386
|
result = await this.handleJoinGroup(params);
|
|
387
387
|
break;
|
|
388
388
|
|
|
389
|
-
case
|
|
389
|
+
case "a2a.getBalance":
|
|
390
390
|
result = this.handleGetBalance(params);
|
|
391
391
|
break;
|
|
392
392
|
|
|
393
|
-
case
|
|
393
|
+
case "a2a.getPortfolio":
|
|
394
394
|
result = this.handleGetPortfolio(params);
|
|
395
395
|
break;
|
|
396
396
|
|
|
397
|
-
case
|
|
397
|
+
case "a2a.getPositions":
|
|
398
398
|
result = this.handleGetPositions(params);
|
|
399
399
|
break;
|
|
400
400
|
|
|
401
|
-
case
|
|
401
|
+
case "a2a.getDashboard":
|
|
402
402
|
result = this.handleGetDashboard(params);
|
|
403
403
|
break;
|
|
404
404
|
|
|
405
|
-
case
|
|
405
|
+
case "a2a.getTrendingTags":
|
|
406
406
|
result = this.handleGetTrendingTags(params);
|
|
407
407
|
break;
|
|
408
408
|
|
|
@@ -413,11 +413,11 @@ export class SimulationA2AInterface {
|
|
|
413
413
|
// This allows the agent to make multiple A2A calls within a single tick
|
|
414
414
|
|
|
415
415
|
const duration = Date.now() - actionStart;
|
|
416
|
-
logger.debug(
|
|
416
|
+
logger.debug("Simulation A2A response", { method, duration });
|
|
417
417
|
|
|
418
418
|
return result;
|
|
419
419
|
} catch (error) {
|
|
420
|
-
logger.error(
|
|
420
|
+
logger.error("Simulation A2A error", { method, error });
|
|
421
421
|
throw error;
|
|
422
422
|
}
|
|
423
423
|
}
|
|
@@ -431,7 +431,7 @@ export class SimulationA2AInterface {
|
|
|
431
431
|
* @returns Object containing array of prediction markets
|
|
432
432
|
*/
|
|
433
433
|
private handleGetPredictions(_params: A2AMethodParams | undefined): {
|
|
434
|
-
predictions: Omit<PredictionMarket,
|
|
434
|
+
predictions: Omit<PredictionMarket, "resolved">[];
|
|
435
435
|
} {
|
|
436
436
|
const state = this.engine.getGameState();
|
|
437
437
|
|
|
@@ -457,17 +457,17 @@ export class SimulationA2AInterface {
|
|
|
457
457
|
* Type guard for BuySharesParams
|
|
458
458
|
*/
|
|
459
459
|
private isBuySharesParams(
|
|
460
|
-
params: A2AMethodParams
|
|
460
|
+
params: A2AMethodParams,
|
|
461
461
|
): params is BuySharesParams {
|
|
462
462
|
return (
|
|
463
|
-
typeof params ===
|
|
463
|
+
typeof params === "object" &&
|
|
464
464
|
params !== null &&
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
typeof params.marketId ===
|
|
469
|
-
(params.outcome ===
|
|
470
|
-
typeof params.amount ===
|
|
465
|
+
"marketId" in params &&
|
|
466
|
+
"outcome" in params &&
|
|
467
|
+
"amount" in params &&
|
|
468
|
+
typeof params.marketId === "string" &&
|
|
469
|
+
(params.outcome === "YES" || params.outcome === "NO") &&
|
|
470
|
+
typeof params.amount === "number" &&
|
|
471
471
|
params.amount > 0
|
|
472
472
|
);
|
|
473
473
|
}
|
|
@@ -482,24 +482,24 @@ export class SimulationA2AInterface {
|
|
|
482
482
|
* @throws Error if buy action fails
|
|
483
483
|
*/
|
|
484
484
|
private async handleBuyShares(
|
|
485
|
-
params: A2AMethodParams | undefined
|
|
485
|
+
params: A2AMethodParams | undefined,
|
|
486
486
|
): Promise<{ shares: number; avgPrice: number; positionId: string }> {
|
|
487
487
|
if (!params || !this.isBuySharesParams(params)) {
|
|
488
488
|
throw new Error(
|
|
489
|
-
'Invalid params: must be an object with marketId (string), outcome ("YES" | "NO"), and amount (positive number)'
|
|
489
|
+
'Invalid params: must be an object with marketId (string), outcome ("YES" | "NO"), and amount (positive number)',
|
|
490
490
|
);
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
const { marketId, outcome, amount } = params;
|
|
494
494
|
|
|
495
|
-
const result = await this.engine.performAction(
|
|
495
|
+
const result = await this.engine.performAction("buy_prediction", {
|
|
496
496
|
marketId,
|
|
497
497
|
outcome,
|
|
498
498
|
amount,
|
|
499
499
|
});
|
|
500
500
|
|
|
501
501
|
if (!result.success) {
|
|
502
|
-
throw new Error(result.error ||
|
|
502
|
+
throw new Error(result.error || "Failed to buy shares");
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
const { positionId, shares } = result.result as {
|
|
@@ -509,10 +509,10 @@ export class SimulationA2AInterface {
|
|
|
509
509
|
|
|
510
510
|
const state = this.engine.getGameState();
|
|
511
511
|
const market = state.predictionMarkets.find(
|
|
512
|
-
(m: { id: string }) => m.id === marketId
|
|
512
|
+
(m: { id: string }) => m.id === marketId,
|
|
513
513
|
);
|
|
514
514
|
const avgPrice = market
|
|
515
|
-
? outcome ===
|
|
515
|
+
? outcome === "YES"
|
|
516
516
|
? market.yesPrice
|
|
517
517
|
: market.noPrice
|
|
518
518
|
: 0.5;
|
|
@@ -524,15 +524,15 @@ export class SimulationA2AInterface {
|
|
|
524
524
|
* Type guard for SellSharesParams
|
|
525
525
|
*/
|
|
526
526
|
private isSellSharesParams(
|
|
527
|
-
params: A2AMethodParams
|
|
527
|
+
params: A2AMethodParams,
|
|
528
528
|
): params is SellSharesParams {
|
|
529
529
|
return (
|
|
530
|
-
typeof params ===
|
|
530
|
+
typeof params === "object" &&
|
|
531
531
|
params !== null &&
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
typeof params.marketId ===
|
|
535
|
-
typeof params.shares ===
|
|
532
|
+
"marketId" in params &&
|
|
533
|
+
"shares" in params &&
|
|
534
|
+
typeof params.marketId === "string" &&
|
|
535
|
+
typeof params.shares === "number" &&
|
|
536
536
|
params.shares > 0
|
|
537
537
|
);
|
|
538
538
|
}
|
|
@@ -547,11 +547,11 @@ export class SimulationA2AInterface {
|
|
|
547
547
|
* @throws Error if market not found
|
|
548
548
|
*/
|
|
549
549
|
private async handleSellShares(
|
|
550
|
-
params: A2AMethodParams | undefined
|
|
550
|
+
params: A2AMethodParams | undefined,
|
|
551
551
|
): Promise<{ proceeds: number }> {
|
|
552
552
|
if (!params || !this.isSellSharesParams(params)) {
|
|
553
553
|
throw new Error(
|
|
554
|
-
|
|
554
|
+
"Invalid params: must be an object with marketId (string) and shares (positive number)",
|
|
555
555
|
);
|
|
556
556
|
}
|
|
557
557
|
|
|
@@ -560,7 +560,7 @@ export class SimulationA2AInterface {
|
|
|
560
560
|
// Simplified: calculate proceeds based on current market price
|
|
561
561
|
const state = this.engine.getGameState();
|
|
562
562
|
const market = state.predictionMarkets.find(
|
|
563
|
-
(m: { id: string }) => m.id === marketId
|
|
563
|
+
(m: { id: string }) => m.id === marketId,
|
|
564
564
|
);
|
|
565
565
|
|
|
566
566
|
if (!market) {
|
|
@@ -604,20 +604,20 @@ export class SimulationA2AInterface {
|
|
|
604
604
|
* Type guard for OpenPositionParams
|
|
605
605
|
*/
|
|
606
606
|
private isOpenPositionParams(
|
|
607
|
-
params: A2AMethodParams
|
|
607
|
+
params: A2AMethodParams,
|
|
608
608
|
): params is OpenPositionParams {
|
|
609
609
|
return (
|
|
610
|
-
typeof params ===
|
|
610
|
+
typeof params === "object" &&
|
|
611
611
|
params !== null &&
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
typeof params.ticker ===
|
|
617
|
-
(params.side ===
|
|
618
|
-
typeof params.size ===
|
|
612
|
+
"ticker" in params &&
|
|
613
|
+
"side" in params &&
|
|
614
|
+
"size" in params &&
|
|
615
|
+
"leverage" in params &&
|
|
616
|
+
typeof params.ticker === "string" &&
|
|
617
|
+
(params.side === "LONG" || params.side === "SHORT") &&
|
|
618
|
+
typeof params.size === "number" &&
|
|
619
619
|
params.size > 0 &&
|
|
620
|
-
typeof params.leverage ===
|
|
620
|
+
typeof params.leverage === "number" &&
|
|
621
621
|
params.leverage >= 1
|
|
622
622
|
);
|
|
623
623
|
}
|
|
@@ -632,17 +632,17 @@ export class SimulationA2AInterface {
|
|
|
632
632
|
* @throws Error if open action fails
|
|
633
633
|
*/
|
|
634
634
|
private async handleOpenPosition(
|
|
635
|
-
params: A2AMethodParams | undefined
|
|
635
|
+
params: A2AMethodParams | undefined,
|
|
636
636
|
): Promise<{ positionId: string; entryPrice: number }> {
|
|
637
637
|
if (!params || !this.isOpenPositionParams(params)) {
|
|
638
638
|
throw new Error(
|
|
639
|
-
'Invalid params: must be an object with ticker (string), side ("LONG" | "SHORT"), size (positive number), and leverage (>= 1)'
|
|
639
|
+
'Invalid params: must be an object with ticker (string), side ("LONG" | "SHORT"), size (positive number), and leverage (>= 1)',
|
|
640
640
|
);
|
|
641
641
|
}
|
|
642
642
|
|
|
643
643
|
const { ticker, side, size, leverage } = params;
|
|
644
644
|
|
|
645
|
-
const result = await this.engine.performAction(
|
|
645
|
+
const result = await this.engine.performAction("open_perp", {
|
|
646
646
|
ticker,
|
|
647
647
|
side,
|
|
648
648
|
size,
|
|
@@ -650,14 +650,14 @@ export class SimulationA2AInterface {
|
|
|
650
650
|
});
|
|
651
651
|
|
|
652
652
|
if (!result.success) {
|
|
653
|
-
throw new Error(result.error ||
|
|
653
|
+
throw new Error(result.error || "Failed to open position");
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
const { positionId } = result.result as { positionId: string };
|
|
657
657
|
|
|
658
658
|
const state = this.engine.getGameState();
|
|
659
659
|
const market = state.perpetualMarkets.find(
|
|
660
|
-
(m: { ticker: string }) => m.ticker === ticker
|
|
660
|
+
(m: { ticker: string }) => m.ticker === ticker,
|
|
661
661
|
);
|
|
662
662
|
|
|
663
663
|
return {
|
|
@@ -670,13 +670,13 @@ export class SimulationA2AInterface {
|
|
|
670
670
|
* Type guard for ClosePositionParams
|
|
671
671
|
*/
|
|
672
672
|
private isClosePositionParams(
|
|
673
|
-
params: A2AMethodParams
|
|
673
|
+
params: A2AMethodParams,
|
|
674
674
|
): params is ClosePositionParams {
|
|
675
675
|
return (
|
|
676
|
-
typeof params ===
|
|
676
|
+
typeof params === "object" &&
|
|
677
677
|
params !== null &&
|
|
678
|
-
|
|
679
|
-
typeof params.positionId ===
|
|
678
|
+
"positionId" in params &&
|
|
679
|
+
typeof params.positionId === "string" &&
|
|
680
680
|
params.positionId.length > 0
|
|
681
681
|
);
|
|
682
682
|
}
|
|
@@ -691,22 +691,22 @@ export class SimulationA2AInterface {
|
|
|
691
691
|
* @throws Error if close action fails
|
|
692
692
|
*/
|
|
693
693
|
private async handleClosePosition(
|
|
694
|
-
params: A2AMethodParams | undefined
|
|
694
|
+
params: A2AMethodParams | undefined,
|
|
695
695
|
): Promise<{ pnl: number; exitPrice: number }> {
|
|
696
696
|
if (!params || !this.isClosePositionParams(params)) {
|
|
697
697
|
throw new Error(
|
|
698
|
-
|
|
698
|
+
"Invalid params: must be an object with positionId (non-empty string)",
|
|
699
699
|
);
|
|
700
700
|
}
|
|
701
701
|
|
|
702
702
|
const { positionId } = params;
|
|
703
703
|
|
|
704
|
-
const result = await this.engine.performAction(
|
|
704
|
+
const result = await this.engine.performAction("close_perp", {
|
|
705
705
|
positionId,
|
|
706
706
|
});
|
|
707
707
|
|
|
708
708
|
if (!result.success) {
|
|
709
|
-
throw new Error(result.error ||
|
|
709
|
+
throw new Error(result.error || "Failed to close position");
|
|
710
710
|
}
|
|
711
711
|
|
|
712
712
|
const { pnl } = result.result as { pnl: number };
|
|
@@ -750,16 +750,16 @@ export class SimulationA2AInterface {
|
|
|
750
750
|
* Type guard for CreatePostParams
|
|
751
751
|
*/
|
|
752
752
|
private isCreatePostParams(
|
|
753
|
-
params: A2AMethodParams
|
|
753
|
+
params: A2AMethodParams,
|
|
754
754
|
): params is CreatePostParams {
|
|
755
755
|
return (
|
|
756
|
-
typeof params ===
|
|
756
|
+
typeof params === "object" &&
|
|
757
757
|
params !== null &&
|
|
758
|
-
|
|
759
|
-
typeof params.content ===
|
|
758
|
+
"content" in params &&
|
|
759
|
+
typeof params.content === "string" &&
|
|
760
760
|
params.content.trim().length > 0 &&
|
|
761
|
-
(
|
|
762
|
-
? typeof params.marketId ===
|
|
761
|
+
("marketId" in params
|
|
762
|
+
? typeof params.marketId === "string" &&
|
|
763
763
|
params.marketId.trim().length > 0
|
|
764
764
|
: true)
|
|
765
765
|
);
|
|
@@ -775,23 +775,23 @@ export class SimulationA2AInterface {
|
|
|
775
775
|
* @throws Error if create action fails
|
|
776
776
|
*/
|
|
777
777
|
private async handleCreatePost(
|
|
778
|
-
params: A2AMethodParams | undefined
|
|
778
|
+
params: A2AMethodParams | undefined,
|
|
779
779
|
): Promise<{ postId: string }> {
|
|
780
780
|
if (!params || !this.isCreatePostParams(params)) {
|
|
781
781
|
throw new Error(
|
|
782
|
-
|
|
782
|
+
"Invalid params: must be an object with content (non-empty string) and optional marketId (non-empty string)",
|
|
783
783
|
);
|
|
784
784
|
}
|
|
785
785
|
|
|
786
786
|
const { content, marketId } = params;
|
|
787
787
|
|
|
788
|
-
const result = await this.engine.performAction(
|
|
788
|
+
const result = await this.engine.performAction("create_post", {
|
|
789
789
|
content,
|
|
790
790
|
marketId: marketId ?? null,
|
|
791
791
|
});
|
|
792
792
|
|
|
793
793
|
if (!result.success) {
|
|
794
|
-
throw new Error(result.error ||
|
|
794
|
+
throw new Error(result.error || "Failed to create post");
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
const { postId } = result.result as { postId: string };
|
|
@@ -821,7 +821,7 @@ export class SimulationA2AInterface {
|
|
|
821
821
|
lastActivity: g.lastActivity,
|
|
822
822
|
invited: g.invitedAgent ?? false,
|
|
823
823
|
messages: g.messages ?? [],
|
|
824
|
-
})
|
|
824
|
+
}),
|
|
825
825
|
);
|
|
826
826
|
|
|
827
827
|
return { chats };
|
|
@@ -831,13 +831,13 @@ export class SimulationA2AInterface {
|
|
|
831
831
|
* Type guard for JoinGroupParams
|
|
832
832
|
*/
|
|
833
833
|
private isJoinGroupParams(
|
|
834
|
-
params: A2AMethodParams
|
|
834
|
+
params: A2AMethodParams,
|
|
835
835
|
): params is JoinGroupParams {
|
|
836
836
|
return (
|
|
837
|
-
typeof params ===
|
|
837
|
+
typeof params === "object" &&
|
|
838
838
|
params !== null &&
|
|
839
|
-
|
|
840
|
-
typeof params.groupId ===
|
|
839
|
+
"groupId" in params &&
|
|
840
|
+
typeof params.groupId === "string" &&
|
|
841
841
|
params.groupId.length > 0
|
|
842
842
|
);
|
|
843
843
|
}
|
|
@@ -851,17 +851,17 @@ export class SimulationA2AInterface {
|
|
|
851
851
|
* @returns Object indicating success status
|
|
852
852
|
*/
|
|
853
853
|
private async handleJoinGroup(
|
|
854
|
-
params: A2AMethodParams | undefined
|
|
854
|
+
params: A2AMethodParams | undefined,
|
|
855
855
|
): Promise<{ success: boolean }> {
|
|
856
856
|
if (!params || !this.isJoinGroupParams(params)) {
|
|
857
857
|
throw new Error(
|
|
858
|
-
|
|
858
|
+
"Invalid params: must be an object with groupId (non-empty string)",
|
|
859
859
|
);
|
|
860
860
|
}
|
|
861
861
|
|
|
862
862
|
const { groupId } = params;
|
|
863
863
|
|
|
864
|
-
const result = await this.engine.performAction(
|
|
864
|
+
const result = await this.engine.performAction("join_group", {
|
|
865
865
|
groupId,
|
|
866
866
|
});
|
|
867
867
|
|
|
@@ -895,11 +895,11 @@ export class SimulationA2AInterface {
|
|
|
895
895
|
* @returns Object with balance, positions array, and total P&L
|
|
896
896
|
*/
|
|
897
897
|
private handleGetPortfolio(
|
|
898
|
-
_params: A2AMethodParams | undefined
|
|
898
|
+
_params: A2AMethodParams | undefined,
|
|
899
899
|
): PortfolioResult {
|
|
900
900
|
const state = this.engine.getGameState();
|
|
901
901
|
const agent = state.agents.find(
|
|
902
|
-
(a: { id: string }) => a.id === this.agentId
|
|
902
|
+
(a: { id: string }) => a.id === this.agentId,
|
|
903
903
|
);
|
|
904
904
|
|
|
905
905
|
// Calculate positions from agent's state
|
|
@@ -948,11 +948,11 @@ export class SimulationA2AInterface {
|
|
|
948
948
|
* @returns Object with balance, reputation, total P&L, and active positions count
|
|
949
949
|
*/
|
|
950
950
|
private handleGetDashboard(
|
|
951
|
-
_params: A2AMethodParams | undefined
|
|
951
|
+
_params: A2AMethodParams | undefined,
|
|
952
952
|
): DashboardResult {
|
|
953
953
|
const state = this.engine.getGameState();
|
|
954
954
|
const agent = state.agents.find(
|
|
955
|
-
(a: { id: string }) => a.id === this.agentId
|
|
955
|
+
(a: { id: string }) => a.id === this.agentId,
|
|
956
956
|
);
|
|
957
957
|
|
|
958
958
|
const pnl = (agent as { totalPnl?: number } | undefined)?.totalPnl || 0;
|
|
@@ -983,9 +983,9 @@ export class SimulationA2AInterface {
|
|
|
983
983
|
// Return some dummy trending tags for simulation
|
|
984
984
|
return {
|
|
985
985
|
tags: [
|
|
986
|
-
{ tag:
|
|
987
|
-
{ tag:
|
|
988
|
-
{ tag:
|
|
986
|
+
{ tag: "crypto", count: 150, trend: "up" },
|
|
987
|
+
{ tag: "ai", count: 120, trend: "up" },
|
|
988
|
+
{ tag: "markets", count: 90, trend: "stable" },
|
|
989
989
|
],
|
|
990
990
|
};
|
|
991
991
|
}
|
|
@@ -1013,10 +1013,10 @@ export class SimulationA2AInterface {
|
|
|
1013
1013
|
*/
|
|
1014
1014
|
async buyShares(
|
|
1015
1015
|
marketId: string,
|
|
1016
|
-
outcome:
|
|
1017
|
-
amount: number
|
|
1016
|
+
outcome: "YES" | "NO",
|
|
1017
|
+
amount: number,
|
|
1018
1018
|
): Promise<BuySharesResult> {
|
|
1019
|
-
return (await this.sendRequest(
|
|
1019
|
+
return (await this.sendRequest("a2a.buyShares", {
|
|
1020
1020
|
marketId,
|
|
1021
1021
|
outcome,
|
|
1022
1022
|
amount,
|
|
@@ -1034,9 +1034,9 @@ export class SimulationA2AInterface {
|
|
|
1034
1034
|
*/
|
|
1035
1035
|
async sellShares(
|
|
1036
1036
|
marketId: string,
|
|
1037
|
-
shares: number
|
|
1037
|
+
shares: number,
|
|
1038
1038
|
): Promise<SellSharesResult> {
|
|
1039
|
-
return (await this.sendRequest(
|
|
1039
|
+
return (await this.sendRequest("a2a.sellShares", {
|
|
1040
1040
|
marketId,
|
|
1041
1041
|
shares,
|
|
1042
1042
|
})) as SellSharesResult;
|
|
@@ -1055,13 +1055,13 @@ export class SimulationA2AInterface {
|
|
|
1055
1055
|
*/
|
|
1056
1056
|
async openPosition(
|
|
1057
1057
|
ticker: string,
|
|
1058
|
-
side:
|
|
1058
|
+
side: "long" | "short",
|
|
1059
1059
|
size: number,
|
|
1060
|
-
leverage: number
|
|
1060
|
+
leverage: number,
|
|
1061
1061
|
): Promise<OpenPositionResult> {
|
|
1062
|
-
return (await this.sendRequest(
|
|
1062
|
+
return (await this.sendRequest("a2a.openPosition", {
|
|
1063
1063
|
ticker,
|
|
1064
|
-
side: side.toUpperCase() as
|
|
1064
|
+
side: side.toUpperCase() as "LONG" | "SHORT",
|
|
1065
1065
|
size,
|
|
1066
1066
|
leverage,
|
|
1067
1067
|
})) as OpenPositionResult;
|
|
@@ -1076,7 +1076,7 @@ export class SimulationA2AInterface {
|
|
|
1076
1076
|
* @returns Result object with pnl and exitPrice
|
|
1077
1077
|
*/
|
|
1078
1078
|
async closePosition(positionId: string): Promise<ClosePositionResult> {
|
|
1079
|
-
return (await this.sendRequest(
|
|
1079
|
+
return (await this.sendRequest("a2a.closePosition", {
|
|
1080
1080
|
positionId,
|
|
1081
1081
|
})) as ClosePositionResult;
|
|
1082
1082
|
}
|
|
@@ -1092,11 +1092,11 @@ export class SimulationA2AInterface {
|
|
|
1092
1092
|
*/
|
|
1093
1093
|
async createPost(
|
|
1094
1094
|
content: string,
|
|
1095
|
-
type: string =
|
|
1095
|
+
type: string = "post",
|
|
1096
1096
|
): Promise<CreatePostResult> {
|
|
1097
|
-
return (await this.sendRequest(
|
|
1097
|
+
return (await this.sendRequest("a2a.createPost", {
|
|
1098
1098
|
content,
|
|
1099
|
-
marketId: type ===
|
|
1099
|
+
marketId: type === "market" ? undefined : undefined,
|
|
1100
1100
|
})) as CreatePostResult;
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
@@ -1111,9 +1111,9 @@ export class SimulationA2AInterface {
|
|
|
1111
1111
|
*/
|
|
1112
1112
|
async createComment(
|
|
1113
1113
|
postId: string,
|
|
1114
|
-
content: string
|
|
1114
|
+
content: string,
|
|
1115
1115
|
): Promise<CreateCommentResult> {
|
|
1116
|
-
return (await this.sendRequest(
|
|
1116
|
+
return (await this.sendRequest("a2a.createComment", {
|
|
1117
1117
|
content,
|
|
1118
1118
|
marketId: postId,
|
|
1119
1119
|
})) as CreateCommentResult;
|
|
@@ -1127,7 +1127,7 @@ export class SimulationA2AInterface {
|
|
|
1127
1127
|
* @returns Portfolio object with balance, positions, and P&L
|
|
1128
1128
|
*/
|
|
1129
1129
|
async getPortfolio(): Promise<PortfolioResult> {
|
|
1130
|
-
return (await this.sendRequest(
|
|
1130
|
+
return (await this.sendRequest("a2a.getPortfolio")) as PortfolioResult;
|
|
1131
1131
|
}
|
|
1132
1132
|
|
|
1133
1133
|
/**
|
|
@@ -1138,13 +1138,13 @@ export class SimulationA2AInterface {
|
|
|
1138
1138
|
* @returns Object with predictions and perps arrays
|
|
1139
1139
|
*/
|
|
1140
1140
|
async getMarkets(): Promise<{
|
|
1141
|
-
predictions: Omit<PredictionMarket,
|
|
1141
|
+
predictions: Omit<PredictionMarket, "resolved">[];
|
|
1142
1142
|
perps: PerpetualMarket[];
|
|
1143
1143
|
}> {
|
|
1144
|
-
const predictions = (await this.sendRequest(
|
|
1145
|
-
status:
|
|
1146
|
-
})) as { predictions: Omit<PredictionMarket,
|
|
1147
|
-
const perpetuals = (await this.sendRequest(
|
|
1144
|
+
const predictions = (await this.sendRequest("a2a.getPredictions", {
|
|
1145
|
+
status: "active",
|
|
1146
|
+
})) as { predictions: Omit<PredictionMarket, "resolved">[] };
|
|
1147
|
+
const perpetuals = (await this.sendRequest("a2a.getPerpetuals", {})) as {
|
|
1148
1148
|
perpetuals: PerpetualMarket[];
|
|
1149
1149
|
};
|
|
1150
1150
|
return {
|
|
@@ -1162,7 +1162,7 @@ export class SimulationA2AInterface {
|
|
|
1162
1162
|
* @returns Object with posts array
|
|
1163
1163
|
*/
|
|
1164
1164
|
async getFeed(limit = 20): Promise<{ posts: FeedPost[] }> {
|
|
1165
|
-
return (await this.sendRequest(
|
|
1165
|
+
return (await this.sendRequest("a2a.getFeed", { limit, offset: 0 })) as {
|
|
1166
1166
|
posts: FeedPost[];
|
|
1167
1167
|
};
|
|
1168
1168
|
}
|