@moltium/world-core 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AgentCard } from '@a2a-js/sdk';
2
2
  import { z } from 'zod';
3
3
  import winston from 'winston';
4
+ import { A2AMessageResponse } from '@moltium/core';
4
5
  import { Express } from 'express';
5
6
 
6
7
  /**
@@ -47,6 +48,34 @@ interface WorldConfig {
47
48
  rules?: WorldRule[];
48
49
  /** Pre-configured agent URLs to discover on startup */
49
50
  agentUrls?: string[];
51
+ /** World-defined actions that agents can execute */
52
+ actions?: WorldAction$1[];
53
+ /** Tick orchestration configuration */
54
+ orchestration?: {
55
+ /** Whether to broadcast tick context to agents (default: true) */
56
+ broadcastOnTick?: boolean;
57
+ /** Timeout for agent responses in ms (default: 10000) */
58
+ tickTimeout?: number;
59
+ /** Custom prompt template for tick broadcasts */
60
+ promptTemplate?: string;
61
+ };
62
+ }
63
+ /**
64
+ * ============================================================================
65
+ * WORLD ACTIONS
66
+ * ============================================================================
67
+ */
68
+ interface WorldAction$1 {
69
+ /** Action name (unique identifier) */
70
+ name: string;
71
+ /** Human-readable description */
72
+ description: string;
73
+ /** Parameter definitions */
74
+ parameters?: Record<string, {
75
+ type: 'string' | 'number' | 'boolean' | 'object';
76
+ required?: boolean;
77
+ description?: string;
78
+ }>;
50
79
  }
51
80
  /**
52
81
  * ============================================================================
@@ -774,6 +803,52 @@ declare const WorldConfigSchema: z.ZodObject<{
774
803
  }>>;
775
804
  rules: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
776
805
  agentUrls: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
806
+ actions: z.ZodOptional<z.ZodArray<z.ZodObject<{
807
+ name: z.ZodString;
808
+ description: z.ZodString;
809
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
810
+ type: z.ZodEnum<["string", "number", "boolean", "object"]>;
811
+ required: z.ZodOptional<z.ZodBoolean>;
812
+ description: z.ZodOptional<z.ZodString>;
813
+ }, "strip", z.ZodTypeAny, {
814
+ type: "string" | "number" | "boolean" | "object";
815
+ description?: string | undefined;
816
+ required?: boolean | undefined;
817
+ }, {
818
+ type: "string" | "number" | "boolean" | "object";
819
+ description?: string | undefined;
820
+ required?: boolean | undefined;
821
+ }>>>;
822
+ }, "strip", z.ZodTypeAny, {
823
+ name: string;
824
+ description: string;
825
+ parameters?: Record<string, {
826
+ type: "string" | "number" | "boolean" | "object";
827
+ description?: string | undefined;
828
+ required?: boolean | undefined;
829
+ }> | undefined;
830
+ }, {
831
+ name: string;
832
+ description: string;
833
+ parameters?: Record<string, {
834
+ type: "string" | "number" | "boolean" | "object";
835
+ description?: string | undefined;
836
+ required?: boolean | undefined;
837
+ }> | undefined;
838
+ }>, "many">>;
839
+ orchestration: z.ZodOptional<z.ZodObject<{
840
+ broadcastOnTick: z.ZodOptional<z.ZodBoolean>;
841
+ tickTimeout: z.ZodOptional<z.ZodNumber>;
842
+ promptTemplate: z.ZodOptional<z.ZodString>;
843
+ }, "strip", z.ZodTypeAny, {
844
+ broadcastOnTick?: boolean | undefined;
845
+ tickTimeout?: number | undefined;
846
+ promptTemplate?: string | undefined;
847
+ }, {
848
+ broadcastOnTick?: boolean | undefined;
849
+ tickTimeout?: number | undefined;
850
+ promptTemplate?: string | undefined;
851
+ }>>;
777
852
  }, "strip", z.ZodTypeAny, {
778
853
  name: string;
779
854
  server: {
@@ -852,6 +927,20 @@ declare const WorldConfigSchema: z.ZodObject<{
852
927
  } | undefined;
853
928
  rules?: any[] | undefined;
854
929
  agentUrls?: string[] | undefined;
930
+ actions?: {
931
+ name: string;
932
+ description: string;
933
+ parameters?: Record<string, {
934
+ type: "string" | "number" | "boolean" | "object";
935
+ description?: string | undefined;
936
+ required?: boolean | undefined;
937
+ }> | undefined;
938
+ }[] | undefined;
939
+ orchestration?: {
940
+ broadcastOnTick?: boolean | undefined;
941
+ tickTimeout?: number | undefined;
942
+ promptTemplate?: string | undefined;
943
+ } | undefined;
855
944
  }, {
856
945
  name: string;
857
946
  server: {
@@ -930,6 +1019,20 @@ declare const WorldConfigSchema: z.ZodObject<{
930
1019
  } | undefined;
931
1020
  rules?: any[] | undefined;
932
1021
  agentUrls?: string[] | undefined;
1022
+ actions?: {
1023
+ name: string;
1024
+ description: string;
1025
+ parameters?: Record<string, {
1026
+ type: "string" | "number" | "boolean" | "object";
1027
+ description?: string | undefined;
1028
+ required?: boolean | undefined;
1029
+ }> | undefined;
1030
+ }[] | undefined;
1031
+ orchestration?: {
1032
+ broadcastOnTick?: boolean | undefined;
1033
+ tickTimeout?: number | undefined;
1034
+ promptTemplate?: string | undefined;
1035
+ } | undefined;
933
1036
  }>;
934
1037
  /**
935
1038
  * Validate world configuration
@@ -1054,6 +1157,138 @@ declare const logger: winston.Logger;
1054
1157
  */
1055
1158
  declare function createLogger(moduleName: string): winston.Logger;
1056
1159
 
1160
+ /**
1161
+ * ============================================================================
1162
+ * WORLD ACTION DEFINITIONS
1163
+ * ============================================================================
1164
+ *
1165
+ * Worlds define what actions agents can take. These are sent as context
1166
+ * during tick broadcasts so agents know their available options.
1167
+ */
1168
+ interface WorldAction {
1169
+ /** Action name (unique identifier) */
1170
+ name: string;
1171
+ /** Human-readable description */
1172
+ description: string;
1173
+ /** Parameter definitions */
1174
+ parameters?: Record<string, WorldActionParam>;
1175
+ }
1176
+ interface WorldActionParam {
1177
+ type: 'string' | 'number' | 'boolean' | 'object';
1178
+ required?: boolean;
1179
+ description?: string;
1180
+ }
1181
+ /**
1182
+ * Registry for world-defined actions.
1183
+ * Agents receive the registered actions as available options during tick broadcasts.
1184
+ */
1185
+ declare class WorldActionsRegistry {
1186
+ private actions;
1187
+ /**
1188
+ * Register a world action
1189
+ */
1190
+ register(action: WorldAction): void;
1191
+ /**
1192
+ * Register multiple actions at once
1193
+ */
1194
+ registerAll(actions: WorldAction[]): void;
1195
+ /**
1196
+ * Get all registered actions
1197
+ */
1198
+ getAll(): WorldAction[];
1199
+ /**
1200
+ * Get a specific action by name
1201
+ */
1202
+ get(name: string): WorldAction | undefined;
1203
+ /**
1204
+ * Check if an action exists
1205
+ */
1206
+ has(name: string): boolean;
1207
+ /**
1208
+ * Validate an action name and its parameters
1209
+ */
1210
+ validate(actionName: string, params: Record<string, any>): {
1211
+ valid: boolean;
1212
+ error?: string;
1213
+ };
1214
+ /**
1215
+ * Get action names as a simple list (for tick context)
1216
+ */
1217
+ getActionNames(): string[];
1218
+ /**
1219
+ * Get actions as a serializable summary (for tick context)
1220
+ */
1221
+ toSummary(): Array<{
1222
+ name: string;
1223
+ description: string;
1224
+ parameters?: Record<string, WorldActionParam>;
1225
+ }>;
1226
+ }
1227
+
1228
+ /**
1229
+ * ============================================================================
1230
+ * WORLD A2A CLIENT
1231
+ * ============================================================================
1232
+ *
1233
+ * Manages a pool of A2A clients for all admitted agents.
1234
+ * Used by the TickOrchestrator to broadcast tick context and collect responses,
1235
+ * and by the MessageRouter for agent-to-agent communication.
1236
+ */
1237
+ declare class WorldA2AClient {
1238
+ private clients;
1239
+ /**
1240
+ * Add an agent to the client pool
1241
+ */
1242
+ addAgent(agentUrl: string): void;
1243
+ /**
1244
+ * Remove an agent from the client pool
1245
+ */
1246
+ removeAgent(agentUrl: string): void;
1247
+ /**
1248
+ * Send an A2A message to a specific agent
1249
+ */
1250
+ sendToAgent(agentUrl: string, message: string, metadata?: Record<string, unknown>): Promise<A2AMessageResponse>;
1251
+ /**
1252
+ * Broadcast an A2A message to all agents in the pool
1253
+ */
1254
+ broadcastToAll(message: string, metadata?: Record<string, unknown>): Promise<Map<string, A2AMessageResponse>>;
1255
+ /**
1256
+ * Get the number of agents in the pool
1257
+ */
1258
+ get size(): number;
1259
+ /**
1260
+ * Check if an agent is in the pool
1261
+ */
1262
+ has(agentUrl: string): boolean;
1263
+ /**
1264
+ * Get all agent URLs in the pool
1265
+ */
1266
+ getAgentUrls(): string[];
1267
+ }
1268
+
1269
+ /**
1270
+ * ============================================================================
1271
+ * MESSAGE ROUTER
1272
+ * ============================================================================
1273
+ *
1274
+ * Routes agent-to-agent messages through the world hub.
1275
+ * Agents send messages to the world's /world/message endpoint,
1276
+ * and the router forwards them to the target agent(s) via A2A.
1277
+ */
1278
+ declare class MessageRouter {
1279
+ private a2aClient;
1280
+ private getAgents;
1281
+ constructor(a2aClient: WorldA2AClient, getAgents: () => AgentProfile[]);
1282
+ /**
1283
+ * Route a message from one agent to another
1284
+ */
1285
+ route(fromAgentUrl: string, toAgentUrl: string, message: string): Promise<A2AMessageResponse>;
1286
+ /**
1287
+ * Broadcast a message from one agent to all other agents in the world
1288
+ */
1289
+ routeToAll(fromAgentUrl: string, message: string): Promise<Map<string, A2AMessageResponse>>;
1290
+ }
1291
+
1057
1292
  /**
1058
1293
  * ============================================================================
1059
1294
  * WORLD ENGINE
@@ -1076,6 +1311,10 @@ declare class World {
1076
1311
  private evaluator;
1077
1312
  private tickInterval;
1078
1313
  private autoSaveInterval;
1314
+ private a2aClient;
1315
+ private actionsRegistry;
1316
+ private orchestrator;
1317
+ private messageRouter;
1079
1318
  constructor(config: WorldConfig);
1080
1319
  /**
1081
1320
  * Initialize the world (connect persistence, restore state, discover agents)
@@ -1105,6 +1344,14 @@ declare class World {
1105
1344
  * Get current world state
1106
1345
  */
1107
1346
  getState(): WorldStateSnapshot;
1347
+ /**
1348
+ * Get the message router (for agent-to-agent communication via server)
1349
+ */
1350
+ getMessageRouter(): MessageRouter;
1351
+ /**
1352
+ * Get the actions registry
1353
+ */
1354
+ getActionsRegistry(): WorldActionsRegistry;
1108
1355
  /**
1109
1356
  * Log an event
1110
1357
  */
@@ -1262,6 +1509,103 @@ declare class BlockchainClient {
1262
1509
  getEntryFee(): Promise<string>;
1263
1510
  }
1264
1511
 
1512
+ /**
1513
+ * ============================================================================
1514
+ * ACTION PROCESSOR
1515
+ * ============================================================================
1516
+ *
1517
+ * Validates agent tick responses against world rules before applying.
1518
+ * Ensures agents only execute valid, permitted actions.
1519
+ */
1520
+ interface AgentTickResponse {
1521
+ agentUrl: string;
1522
+ action?: string;
1523
+ parameters?: Record<string, any>;
1524
+ message?: string;
1525
+ error?: string;
1526
+ }
1527
+ interface ProcessResult {
1528
+ accepted: boolean;
1529
+ violations: RuleViolation[];
1530
+ stateUpdates?: Record<string, any>;
1531
+ events?: WorldEvent[];
1532
+ }
1533
+ declare class ActionProcessor {
1534
+ private rules;
1535
+ private actionsRegistry;
1536
+ constructor(rules: WorldRule[], actionsRegistry: WorldActionsRegistry);
1537
+ /**
1538
+ * Process an agent's tick response: validate action and check rules
1539
+ */
1540
+ process(response: AgentTickResponse, agent: AgentProfile, worldContext: {
1541
+ phase: WorldPhase;
1542
+ tick: number;
1543
+ agents: Map<string, AgentProfile>;
1544
+ }): Promise<ProcessResult>;
1545
+ /**
1546
+ * Update the rules list
1547
+ */
1548
+ setRules(rules: WorldRule[]): void;
1549
+ }
1550
+
1551
+ /**
1552
+ * ============================================================================
1553
+ * TICK ORCHESTRATOR
1554
+ * ============================================================================
1555
+ *
1556
+ * Orchestrates the world tick loop:
1557
+ * 1. Build tick context (state, actions, agents)
1558
+ * 2. Broadcast to all agents via A2A
1559
+ * 3. Collect and parse responses
1560
+ * 4. Validate responses against rules
1561
+ * 5. Apply state updates and log events
1562
+ */
1563
+ interface TickResult {
1564
+ tick: number;
1565
+ responses: Map<string, AgentTickResponse>;
1566
+ events: WorldEvent[];
1567
+ stateUpdates: Record<string, any>;
1568
+ errors: Array<{
1569
+ agentUrl: string;
1570
+ error: string;
1571
+ }>;
1572
+ }
1573
+ interface OrchestrationConfig {
1574
+ /** Whether to broadcast tick context to agents (default: true) */
1575
+ broadcastOnTick?: boolean;
1576
+ /** Timeout for agent responses in ms (default: 10000) */
1577
+ tickTimeout?: number;
1578
+ /** Custom prompt template for tick broadcasts */
1579
+ promptTemplate?: string;
1580
+ }
1581
+ declare class TickOrchestrator {
1582
+ private a2aClient;
1583
+ private actionsRegistry;
1584
+ private actionProcessor;
1585
+ private orchestrationConfig;
1586
+ constructor(a2aClient: WorldA2AClient, actionsRegistry: WorldActionsRegistry, rules: WorldRule[], config?: OrchestrationConfig);
1587
+ /**
1588
+ * Execute a single world tick
1589
+ */
1590
+ executeTick(tick: number, agents: AgentProfile[], state: WorldStateSnapshot, worldName: string): Promise<TickResult>;
1591
+ /**
1592
+ * Build the tick context that gets sent to each agent
1593
+ */
1594
+ private buildTickContext;
1595
+ /**
1596
+ * Parse an A2A response into an AgentTickResponse
1597
+ */
1598
+ private parseAgentResponse;
1599
+ /**
1600
+ * Update orchestration config
1601
+ */
1602
+ setConfig(config: Partial<OrchestrationConfig>): void;
1603
+ /**
1604
+ * Update rules on the action processor
1605
+ */
1606
+ setRules(rules: WorldRule[]): void;
1607
+ }
1608
+
1265
1609
  /**
1266
1610
  * ============================================================================
1267
1611
  * WORLD HTTP SERVER
@@ -1281,4 +1625,4 @@ declare function createWorldApp(world: World): Express;
1281
1625
  */
1282
1626
  declare function startWorldServer(world: World): Promise<void>;
1283
1627
 
1284
- export { type AdmissionDecision, type AdmissionRules, AdmissionRulesSchema, AgentEvaluator, type AgentProfile, BlockchainClient, type BlockchainConfig, BlockchainConfigSchema, CardFetcher, type EventFilter$1 as EventFilter, type FetchResult, InMemoryAdapter, type PersistenceAdapter, type PersistenceConfig, PersistenceConfigSchema, type RuleContext, type RuleViolation, type TokenConfig, TokenConfigSchema, World, type WorldConfig, WorldConfigSchema, type WorldEvent, type WorldPhase, type WorldRule, type WorldStateSnapshot, type WorldTypeModule, createLogger, createPersistence, createWorldApp, isValidWorldConfig, logger, normalizeAgentUrl, profileFromCard, startWorldServer, validateWorldConfig };
1628
+ export { ActionProcessor, type AdmissionDecision, type AdmissionRules, AdmissionRulesSchema, AgentEvaluator, type AgentProfile, type AgentTickResponse, BlockchainClient, type BlockchainConfig, BlockchainConfigSchema, CardFetcher, type EventFilter$1 as EventFilter, type FetchResult, InMemoryAdapter, MessageRouter, type OrchestrationConfig, type PersistenceAdapter, type PersistenceConfig, PersistenceConfigSchema, type ProcessResult, type RuleContext, type RuleViolation, TickOrchestrator, type TickResult, type TokenConfig, TokenConfigSchema, World, WorldA2AClient, type WorldAction$1 as WorldAction, type WorldActionParam, WorldActionsRegistry, type WorldConfig, WorldConfigSchema, type WorldEvent, type WorldPhase, type WorldRule, type WorldStateSnapshot, type WorldTypeModule, createLogger, createPersistence, createWorldApp, isValidWorldConfig, logger, normalizeAgentUrl, profileFromCard, startWorldServer, validateWorldConfig };