agentic-qe 2.7.4 → 2.8.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.
Files changed (519) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +67 -2
  3. package/dist/cli/commands/agent/spawn.d.ts +12 -1
  4. package/dist/cli/commands/agent/spawn.d.ts.map +1 -1
  5. package/dist/cli/commands/agent/spawn.js +95 -8
  6. package/dist/cli/commands/agent/spawn.js.map +1 -1
  7. package/dist/cli/index.js +91 -0
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/core/memory/HNSWVectorMemory.js +1 -1
  10. package/dist/edge/adapters/BrowserHNSWAdapter.d.ts +134 -0
  11. package/dist/edge/adapters/BrowserHNSWAdapter.d.ts.map +1 -0
  12. package/dist/edge/adapters/BrowserHNSWAdapter.js +484 -0
  13. package/dist/edge/adapters/BrowserHNSWAdapter.js.map +1 -0
  14. package/dist/edge/adapters/IndexedDBStorage.d.ts +114 -0
  15. package/dist/edge/adapters/IndexedDBStorage.d.ts.map +1 -0
  16. package/dist/edge/adapters/IndexedDBStorage.js +478 -0
  17. package/dist/edge/adapters/IndexedDBStorage.js.map +1 -0
  18. package/dist/edge/adapters/index.d.ts +12 -0
  19. package/dist/edge/adapters/index.d.ts.map +1 -0
  20. package/dist/edge/adapters/index.js +22 -0
  21. package/dist/edge/adapters/index.js.map +1 -0
  22. package/dist/edge/browser/BrowserAgent.d.ts +241 -0
  23. package/dist/edge/browser/BrowserAgent.d.ts.map +1 -0
  24. package/dist/edge/browser/BrowserAgent.js +743 -0
  25. package/dist/edge/browser/BrowserAgent.js.map +1 -0
  26. package/dist/edge/index.d.ts +34 -0
  27. package/dist/edge/index.d.ts.map +1 -0
  28. package/dist/edge/index.js +114 -0
  29. package/dist/edge/index.js.map +1 -0
  30. package/dist/edge/p2p/coordination/CoordinationManager.d.ts +181 -0
  31. package/dist/edge/p2p/coordination/CoordinationManager.d.ts.map +1 -0
  32. package/dist/edge/p2p/coordination/CoordinationManager.js +851 -0
  33. package/dist/edge/p2p/coordination/CoordinationManager.js.map +1 -0
  34. package/dist/edge/p2p/coordination/HealthMonitor.d.ts +143 -0
  35. package/dist/edge/p2p/coordination/HealthMonitor.d.ts.map +1 -0
  36. package/dist/edge/p2p/coordination/HealthMonitor.js +432 -0
  37. package/dist/edge/p2p/coordination/HealthMonitor.js.map +1 -0
  38. package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts +146 -0
  39. package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts.map +1 -0
  40. package/dist/edge/p2p/coordination/SyncOrchestrator.js +783 -0
  41. package/dist/edge/p2p/coordination/SyncOrchestrator.js.map +1 -0
  42. package/dist/edge/p2p/coordination/index.d.ts +70 -0
  43. package/dist/edge/p2p/coordination/index.d.ts.map +1 -0
  44. package/dist/edge/p2p/coordination/index.js +107 -0
  45. package/dist/edge/p2p/coordination/index.js.map +1 -0
  46. package/dist/edge/p2p/coordination/types.d.ts +572 -0
  47. package/dist/edge/p2p/coordination/types.d.ts.map +1 -0
  48. package/dist/edge/p2p/coordination/types.js +366 -0
  49. package/dist/edge/p2p/coordination/types.js.map +1 -0
  50. package/dist/edge/p2p/crdt/CRDTStore.d.ts +324 -0
  51. package/dist/edge/p2p/crdt/CRDTStore.d.ts.map +1 -0
  52. package/dist/edge/p2p/crdt/CRDTStore.js +839 -0
  53. package/dist/edge/p2p/crdt/CRDTStore.js.map +1 -0
  54. package/dist/edge/p2p/crdt/GCounter.d.ts +173 -0
  55. package/dist/edge/p2p/crdt/GCounter.d.ts.map +1 -0
  56. package/dist/edge/p2p/crdt/GCounter.js +394 -0
  57. package/dist/edge/p2p/crdt/GCounter.js.map +1 -0
  58. package/dist/edge/p2p/crdt/LWWRegister.d.ts +200 -0
  59. package/dist/edge/p2p/crdt/LWWRegister.d.ts.map +1 -0
  60. package/dist/edge/p2p/crdt/LWWRegister.js +456 -0
  61. package/dist/edge/p2p/crdt/LWWRegister.js.map +1 -0
  62. package/dist/edge/p2p/crdt/ORSet.d.ts +232 -0
  63. package/dist/edge/p2p/crdt/ORSet.d.ts.map +1 -0
  64. package/dist/edge/p2p/crdt/ORSet.js +723 -0
  65. package/dist/edge/p2p/crdt/ORSet.js.map +1 -0
  66. package/dist/edge/p2p/crdt/PatternCRDT.d.ts +366 -0
  67. package/dist/edge/p2p/crdt/PatternCRDT.d.ts.map +1 -0
  68. package/dist/edge/p2p/crdt/PatternCRDT.js +838 -0
  69. package/dist/edge/p2p/crdt/PatternCRDT.js.map +1 -0
  70. package/dist/edge/p2p/crdt/VectorClock.d.ts +274 -0
  71. package/dist/edge/p2p/crdt/VectorClock.d.ts.map +1 -0
  72. package/dist/edge/p2p/crdt/VectorClock.js +499 -0
  73. package/dist/edge/p2p/crdt/VectorClock.js.map +1 -0
  74. package/dist/edge/p2p/crdt/index.d.ts +87 -0
  75. package/dist/edge/p2p/crdt/index.d.ts.map +1 -0
  76. package/dist/edge/p2p/crdt/index.js +120 -0
  77. package/dist/edge/p2p/crdt/index.js.map +1 -0
  78. package/dist/edge/p2p/crdt/types.d.ts +667 -0
  79. package/dist/edge/p2p/crdt/types.d.ts.map +1 -0
  80. package/dist/edge/p2p/crdt/types.js +208 -0
  81. package/dist/edge/p2p/crdt/types.js.map +1 -0
  82. package/dist/edge/p2p/crypto/Identity.d.ts +139 -0
  83. package/dist/edge/p2p/crypto/Identity.d.ts.map +1 -0
  84. package/dist/edge/p2p/crypto/Identity.js +449 -0
  85. package/dist/edge/p2p/crypto/Identity.js.map +1 -0
  86. package/dist/edge/p2p/crypto/KeyManager.d.ts +196 -0
  87. package/dist/edge/p2p/crypto/KeyManager.d.ts.map +1 -0
  88. package/dist/edge/p2p/crypto/KeyManager.js +576 -0
  89. package/dist/edge/p2p/crypto/KeyManager.js.map +1 -0
  90. package/dist/edge/p2p/crypto/Signer.d.ts +164 -0
  91. package/dist/edge/p2p/crypto/Signer.d.ts.map +1 -0
  92. package/dist/edge/p2p/crypto/Signer.js +357 -0
  93. package/dist/edge/p2p/crypto/Signer.js.map +1 -0
  94. package/dist/edge/p2p/crypto/index.d.ts +90 -0
  95. package/dist/edge/p2p/crypto/index.d.ts.map +1 -0
  96. package/dist/edge/p2p/crypto/index.js +158 -0
  97. package/dist/edge/p2p/crypto/index.js.map +1 -0
  98. package/dist/edge/p2p/crypto/types.d.ts +217 -0
  99. package/dist/edge/p2p/crypto/types.d.ts.map +1 -0
  100. package/dist/edge/p2p/crypto/types.js +42 -0
  101. package/dist/edge/p2p/crypto/types.js.map +1 -0
  102. package/dist/edge/p2p/federated/FederatedCoordinator.d.ts +270 -0
  103. package/dist/edge/p2p/federated/FederatedCoordinator.d.ts.map +1 -0
  104. package/dist/edge/p2p/federated/FederatedCoordinator.js +824 -0
  105. package/dist/edge/p2p/federated/FederatedCoordinator.js.map +1 -0
  106. package/dist/edge/p2p/federated/FederatedRound.d.ts +295 -0
  107. package/dist/edge/p2p/federated/FederatedRound.d.ts.map +1 -0
  108. package/dist/edge/p2p/federated/FederatedRound.js +819 -0
  109. package/dist/edge/p2p/federated/FederatedRound.js.map +1 -0
  110. package/dist/edge/p2p/federated/GradientAggregator.d.ts +226 -0
  111. package/dist/edge/p2p/federated/GradientAggregator.d.ts.map +1 -0
  112. package/dist/edge/p2p/federated/GradientAggregator.js +826 -0
  113. package/dist/edge/p2p/federated/GradientAggregator.js.map +1 -0
  114. package/dist/edge/p2p/federated/ModelManager.d.ts +248 -0
  115. package/dist/edge/p2p/federated/ModelManager.d.ts.map +1 -0
  116. package/dist/edge/p2p/federated/ModelManager.js +724 -0
  117. package/dist/edge/p2p/federated/ModelManager.js.map +1 -0
  118. package/dist/edge/p2p/federated/index.d.ts +65 -0
  119. package/dist/edge/p2p/federated/index.d.ts.map +1 -0
  120. package/dist/edge/p2p/federated/index.js +110 -0
  121. package/dist/edge/p2p/federated/index.js.map +1 -0
  122. package/dist/edge/p2p/federated/types.d.ts +905 -0
  123. package/dist/edge/p2p/federated/types.d.ts.map +1 -0
  124. package/dist/edge/p2p/federated/types.js +339 -0
  125. package/dist/edge/p2p/federated/types.js.map +1 -0
  126. package/dist/edge/p2p/index.d.ts +156 -0
  127. package/dist/edge/p2p/index.d.ts.map +1 -0
  128. package/dist/edge/p2p/index.js +242 -0
  129. package/dist/edge/p2p/index.js.map +1 -0
  130. package/dist/edge/p2p/nat/ConnectivityTester.d.ts +128 -0
  131. package/dist/edge/p2p/nat/ConnectivityTester.d.ts.map +1 -0
  132. package/dist/edge/p2p/nat/ConnectivityTester.js +560 -0
  133. package/dist/edge/p2p/nat/ConnectivityTester.js.map +1 -0
  134. package/dist/edge/p2p/nat/HolePuncher.d.ts +159 -0
  135. package/dist/edge/p2p/nat/HolePuncher.d.ts.map +1 -0
  136. package/dist/edge/p2p/nat/HolePuncher.js +569 -0
  137. package/dist/edge/p2p/nat/HolePuncher.js.map +1 -0
  138. package/dist/edge/p2p/nat/NATDetector.d.ts +109 -0
  139. package/dist/edge/p2p/nat/NATDetector.d.ts.map +1 -0
  140. package/dist/edge/p2p/nat/NATDetector.js +472 -0
  141. package/dist/edge/p2p/nat/NATDetector.js.map +1 -0
  142. package/dist/edge/p2p/nat/TURNManager.d.ts +158 -0
  143. package/dist/edge/p2p/nat/TURNManager.d.ts.map +1 -0
  144. package/dist/edge/p2p/nat/TURNManager.js +547 -0
  145. package/dist/edge/p2p/nat/TURNManager.js.map +1 -0
  146. package/dist/edge/p2p/nat/index.d.ts +74 -0
  147. package/dist/edge/p2p/nat/index.d.ts.map +1 -0
  148. package/dist/edge/p2p/nat/index.js +104 -0
  149. package/dist/edge/p2p/nat/index.js.map +1 -0
  150. package/dist/edge/p2p/nat/types.d.ts +583 -0
  151. package/dist/edge/p2p/nat/types.d.ts.map +1 -0
  152. package/dist/edge/p2p/nat/types.js +267 -0
  153. package/dist/edge/p2p/nat/types.js.map +1 -0
  154. package/dist/edge/p2p/protocol/AgentChannel.d.ts +333 -0
  155. package/dist/edge/p2p/protocol/AgentChannel.d.ts.map +1 -0
  156. package/dist/edge/p2p/protocol/AgentChannel.js +914 -0
  157. package/dist/edge/p2p/protocol/AgentChannel.js.map +1 -0
  158. package/dist/edge/p2p/protocol/MessageEncoder.d.ts +147 -0
  159. package/dist/edge/p2p/protocol/MessageEncoder.d.ts.map +1 -0
  160. package/dist/edge/p2p/protocol/MessageEncoder.js +738 -0
  161. package/dist/edge/p2p/protocol/MessageEncoder.js.map +1 -0
  162. package/dist/edge/p2p/protocol/MessageRouter.d.ts +266 -0
  163. package/dist/edge/p2p/protocol/MessageRouter.d.ts.map +1 -0
  164. package/dist/edge/p2p/protocol/MessageRouter.js +808 -0
  165. package/dist/edge/p2p/protocol/MessageRouter.js.map +1 -0
  166. package/dist/edge/p2p/protocol/ProtocolHandler.d.ts +309 -0
  167. package/dist/edge/p2p/protocol/ProtocolHandler.d.ts.map +1 -0
  168. package/dist/edge/p2p/protocol/ProtocolHandler.js +930 -0
  169. package/dist/edge/p2p/protocol/ProtocolHandler.js.map +1 -0
  170. package/dist/edge/p2p/protocol/index.d.ts +114 -0
  171. package/dist/edge/p2p/protocol/index.d.ts.map +1 -0
  172. package/dist/edge/p2p/protocol/index.js +206 -0
  173. package/dist/edge/p2p/protocol/index.js.map +1 -0
  174. package/dist/edge/p2p/protocol/types.d.ts +737 -0
  175. package/dist/edge/p2p/protocol/types.d.ts.map +1 -0
  176. package/dist/edge/p2p/protocol/types.js +490 -0
  177. package/dist/edge/p2p/protocol/types.js.map +1 -0
  178. package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts +284 -0
  179. package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts.map +1 -0
  180. package/dist/edge/p2p/sharing/PatternBroadcaster.js +644 -0
  181. package/dist/edge/p2p/sharing/PatternBroadcaster.js.map +1 -0
  182. package/dist/edge/p2p/sharing/PatternIndex.d.ts +168 -0
  183. package/dist/edge/p2p/sharing/PatternIndex.d.ts.map +1 -0
  184. package/dist/edge/p2p/sharing/PatternIndex.js +781 -0
  185. package/dist/edge/p2p/sharing/PatternIndex.js.map +1 -0
  186. package/dist/edge/p2p/sharing/PatternSerializer.d.ts +163 -0
  187. package/dist/edge/p2p/sharing/PatternSerializer.d.ts.map +1 -0
  188. package/dist/edge/p2p/sharing/PatternSerializer.js +696 -0
  189. package/dist/edge/p2p/sharing/PatternSerializer.js.map +1 -0
  190. package/dist/edge/p2p/sharing/PatternSyncManager.d.ts +242 -0
  191. package/dist/edge/p2p/sharing/PatternSyncManager.d.ts.map +1 -0
  192. package/dist/edge/p2p/sharing/PatternSyncManager.js +859 -0
  193. package/dist/edge/p2p/sharing/PatternSyncManager.js.map +1 -0
  194. package/dist/edge/p2p/sharing/index.d.ts +90 -0
  195. package/dist/edge/p2p/sharing/index.d.ts.map +1 -0
  196. package/dist/edge/p2p/sharing/index.js +152 -0
  197. package/dist/edge/p2p/sharing/index.js.map +1 -0
  198. package/dist/edge/p2p/sharing/types.d.ts +796 -0
  199. package/dist/edge/p2p/sharing/types.d.ts.map +1 -0
  200. package/dist/edge/p2p/sharing/types.js +264 -0
  201. package/dist/edge/p2p/sharing/types.js.map +1 -0
  202. package/dist/edge/p2p/webrtc/ConnectionPool.d.ts +218 -0
  203. package/dist/edge/p2p/webrtc/ConnectionPool.d.ts.map +1 -0
  204. package/dist/edge/p2p/webrtc/ConnectionPool.js +562 -0
  205. package/dist/edge/p2p/webrtc/ConnectionPool.js.map +1 -0
  206. package/dist/edge/p2p/webrtc/ICEManager.d.ts +171 -0
  207. package/dist/edge/p2p/webrtc/ICEManager.d.ts.map +1 -0
  208. package/dist/edge/p2p/webrtc/ICEManager.js +490 -0
  209. package/dist/edge/p2p/webrtc/ICEManager.js.map +1 -0
  210. package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts +159 -0
  211. package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts.map +1 -0
  212. package/dist/edge/p2p/webrtc/PeerConnectionManager.js +735 -0
  213. package/dist/edge/p2p/webrtc/PeerConnectionManager.js.map +1 -0
  214. package/dist/edge/p2p/webrtc/SignalingClient.d.ts +191 -0
  215. package/dist/edge/p2p/webrtc/SignalingClient.d.ts.map +1 -0
  216. package/dist/edge/p2p/webrtc/SignalingClient.js +608 -0
  217. package/dist/edge/p2p/webrtc/SignalingClient.js.map +1 -0
  218. package/dist/edge/p2p/webrtc/index.d.ts +158 -0
  219. package/dist/edge/p2p/webrtc/index.d.ts.map +1 -0
  220. package/dist/edge/p2p/webrtc/index.js +164 -0
  221. package/dist/edge/p2p/webrtc/index.js.map +1 -0
  222. package/dist/edge/p2p/webrtc/types.d.ts +665 -0
  223. package/dist/edge/p2p/webrtc/types.d.ts.map +1 -0
  224. package/dist/edge/p2p/webrtc/types.js +245 -0
  225. package/dist/edge/p2p/webrtc/types.js.map +1 -0
  226. package/dist/edge/server/AgentSpawnAPI.d.ts +98 -0
  227. package/dist/edge/server/AgentSpawnAPI.d.ts.map +1 -0
  228. package/dist/edge/server/AgentSpawnAPI.js +264 -0
  229. package/dist/edge/server/AgentSpawnAPI.js.map +1 -0
  230. package/dist/edge/server/SignalingServer.d.ts +71 -0
  231. package/dist/edge/server/SignalingServer.d.ts.map +1 -0
  232. package/dist/edge/server/SignalingServer.js +429 -0
  233. package/dist/edge/server/SignalingServer.js.map +1 -0
  234. package/dist/edge/server/index.d.ts +64 -0
  235. package/dist/edge/server/index.d.ts.map +1 -0
  236. package/dist/edge/server/index.js +318 -0
  237. package/dist/edge/server/index.js.map +1 -0
  238. package/dist/edge/types/browser-agent.types.d.ts +455 -0
  239. package/dist/edge/types/browser-agent.types.d.ts.map +1 -0
  240. package/dist/edge/types/browser-agent.types.js +116 -0
  241. package/dist/edge/types/browser-agent.types.js.map +1 -0
  242. package/dist/edge/types/index.d.ts +11 -0
  243. package/dist/edge/types/index.d.ts.map +1 -0
  244. package/dist/edge/types/index.js +17 -0
  245. package/dist/edge/types/index.js.map +1 -0
  246. package/dist/edge/types/storage.types.d.ts +207 -0
  247. package/dist/edge/types/storage.types.d.ts.map +1 -0
  248. package/dist/edge/types/storage.types.js +47 -0
  249. package/dist/edge/types/storage.types.js.map +1 -0
  250. package/dist/edge/wasm/shims.d.ts +224 -0
  251. package/dist/edge/wasm/shims.d.ts.map +1 -0
  252. package/dist/edge/wasm/shims.js +667 -0
  253. package/dist/edge/wasm/shims.js.map +1 -0
  254. package/dist/mcp/handlers/NewDomainToolsHandler.d.ts +33 -0
  255. package/dist/mcp/handlers/NewDomainToolsHandler.d.ts.map +1 -0
  256. package/dist/mcp/handlers/NewDomainToolsHandler.js +305 -0
  257. package/dist/mcp/handlers/NewDomainToolsHandler.js.map +1 -0
  258. package/dist/mcp/handlers/filtered/index.d.ts +15 -19
  259. package/dist/mcp/handlers/filtered/index.d.ts.map +1 -1
  260. package/dist/mcp/handlers/filtered/index.js +16 -27
  261. package/dist/mcp/handlers/filtered/index.js.map +1 -1
  262. package/dist/mcp/handlers/integration/index.d.ts +5 -4
  263. package/dist/mcp/handlers/integration/index.d.ts.map +1 -1
  264. package/dist/mcp/handlers/integration/index.js +7 -7
  265. package/dist/mcp/handlers/integration/index.js.map +1 -1
  266. package/dist/mcp/server-instructions.d.ts +1 -1
  267. package/dist/mcp/server-instructions.js +1 -1
  268. package/dist/mcp/server.d.ts.map +1 -1
  269. package/dist/mcp/server.js +14 -0
  270. package/dist/mcp/server.js.map +1 -1
  271. package/dist/mcp/tools.d.ts +8 -0
  272. package/dist/mcp/tools.d.ts.map +1 -1
  273. package/dist/mcp/tools.js +412 -1
  274. package/dist/mcp/tools.js.map +1 -1
  275. package/dist/planning/GOAPPlanner.d.ts +1 -0
  276. package/dist/planning/GOAPPlanner.d.ts.map +1 -1
  277. package/dist/planning/GOAPPlanner.js +12 -0
  278. package/dist/planning/GOAPPlanner.js.map +1 -1
  279. package/package.json +29 -8
  280. package/dist/alerting/AlertManager.d.ts +0 -120
  281. package/dist/alerting/AlertManager.d.ts.map +0 -1
  282. package/dist/alerting/AlertManager.js +0 -345
  283. package/dist/alerting/AlertManager.js.map +0 -1
  284. package/dist/alerting/FeedbackRouter.d.ts +0 -98
  285. package/dist/alerting/FeedbackRouter.d.ts.map +0 -1
  286. package/dist/alerting/FeedbackRouter.js +0 -331
  287. package/dist/alerting/FeedbackRouter.js.map +0 -1
  288. package/dist/alerting/StrategyApplicator.d.ts +0 -120
  289. package/dist/alerting/StrategyApplicator.d.ts.map +0 -1
  290. package/dist/alerting/StrategyApplicator.js +0 -299
  291. package/dist/alerting/StrategyApplicator.js.map +0 -1
  292. package/dist/alerting/index.d.ts +0 -68
  293. package/dist/alerting/index.d.ts.map +0 -1
  294. package/dist/alerting/index.js +0 -112
  295. package/dist/alerting/index.js.map +0 -1
  296. package/dist/alerting/types.d.ts +0 -118
  297. package/dist/alerting/types.d.ts.map +0 -1
  298. package/dist/alerting/types.js +0 -11
  299. package/dist/alerting/types.js.map +0 -1
  300. package/dist/cli/commands/fleet/backup.d.ts +0 -49
  301. package/dist/cli/commands/fleet/backup.d.ts.map +0 -1
  302. package/dist/cli/commands/fleet/backup.js +0 -88
  303. package/dist/cli/commands/fleet/backup.js.map +0 -1
  304. package/dist/cli/commands/fleet/health.d.ts +0 -154
  305. package/dist/cli/commands/fleet/health.d.ts.map +0 -1
  306. package/dist/cli/commands/fleet/health.js +0 -483
  307. package/dist/cli/commands/fleet/health.js.map +0 -1
  308. package/dist/cli/commands/fleet/init.d.ts +0 -11
  309. package/dist/cli/commands/fleet/init.d.ts.map +0 -1
  310. package/dist/cli/commands/fleet/init.js +0 -91
  311. package/dist/cli/commands/fleet/init.js.map +0 -1
  312. package/dist/cli/commands/fleet/logs.d.ts +0 -21
  313. package/dist/cli/commands/fleet/logs.d.ts.map +0 -1
  314. package/dist/cli/commands/fleet/logs.js +0 -267
  315. package/dist/cli/commands/fleet/logs.js.map +0 -1
  316. package/dist/cli/commands/fleet/metrics.d.ts +0 -27
  317. package/dist/cli/commands/fleet/metrics.d.ts.map +0 -1
  318. package/dist/cli/commands/fleet/metrics.js +0 -369
  319. package/dist/cli/commands/fleet/metrics.js.map +0 -1
  320. package/dist/cli/commands/fleet/monitor.d.ts +0 -18
  321. package/dist/cli/commands/fleet/monitor.d.ts.map +0 -1
  322. package/dist/cli/commands/fleet/monitor.js +0 -237
  323. package/dist/cli/commands/fleet/monitor.js.map +0 -1
  324. package/dist/cli/commands/fleet/optimize.d.ts +0 -42
  325. package/dist/cli/commands/fleet/optimize.d.ts.map +0 -1
  326. package/dist/cli/commands/fleet/optimize.js +0 -135
  327. package/dist/cli/commands/fleet/optimize.js.map +0 -1
  328. package/dist/cli/commands/fleet/recover.d.ts +0 -22
  329. package/dist/cli/commands/fleet/recover.d.ts.map +0 -1
  330. package/dist/cli/commands/fleet/recover.js +0 -99
  331. package/dist/cli/commands/fleet/recover.js.map +0 -1
  332. package/dist/cli/commands/fleet/restart.d.ts +0 -18
  333. package/dist/cli/commands/fleet/restart.d.ts.map +0 -1
  334. package/dist/cli/commands/fleet/restart.js +0 -290
  335. package/dist/cli/commands/fleet/restart.js.map +0 -1
  336. package/dist/cli/commands/fleet/scale.d.ts +0 -9
  337. package/dist/cli/commands/fleet/scale.d.ts.map +0 -1
  338. package/dist/cli/commands/fleet/scale.js +0 -77
  339. package/dist/cli/commands/fleet/scale.js.map +0 -1
  340. package/dist/cli/commands/fleet/shutdown.d.ts +0 -19
  341. package/dist/cli/commands/fleet/shutdown.d.ts.map +0 -1
  342. package/dist/cli/commands/fleet/shutdown.js +0 -307
  343. package/dist/cli/commands/fleet/shutdown.js.map +0 -1
  344. package/dist/cli/commands/fleet/status.d.ts +0 -10
  345. package/dist/cli/commands/fleet/status.d.ts.map +0 -1
  346. package/dist/cli/commands/fleet/status.js +0 -97
  347. package/dist/cli/commands/fleet/status.js.map +0 -1
  348. package/dist/cli/commands/fleet/topology.d.ts +0 -23
  349. package/dist/cli/commands/fleet/topology.d.ts.map +0 -1
  350. package/dist/cli/commands/fleet/topology.js +0 -376
  351. package/dist/cli/commands/fleet/topology.js.map +0 -1
  352. package/dist/cli/commands/monitor/alerts.d.ts +0 -45
  353. package/dist/cli/commands/monitor/alerts.d.ts.map +0 -1
  354. package/dist/cli/commands/monitor/alerts.js +0 -168
  355. package/dist/cli/commands/monitor/alerts.js.map +0 -1
  356. package/dist/cli/commands/monitor/analyze.d.ts +0 -49
  357. package/dist/cli/commands/monitor/analyze.d.ts.map +0 -1
  358. package/dist/cli/commands/monitor/analyze.js +0 -209
  359. package/dist/cli/commands/monitor/analyze.js.map +0 -1
  360. package/dist/cli/commands/monitor/compare.d.ts +0 -38
  361. package/dist/cli/commands/monitor/compare.d.ts.map +0 -1
  362. package/dist/cli/commands/monitor/compare.js +0 -177
  363. package/dist/cli/commands/monitor/compare.js.map +0 -1
  364. package/dist/cli/commands/monitor/dashboard.d.ts +0 -34
  365. package/dist/cli/commands/monitor/dashboard.d.ts.map +0 -1
  366. package/dist/cli/commands/monitor/dashboard.js +0 -157
  367. package/dist/cli/commands/monitor/dashboard.js.map +0 -1
  368. package/dist/cli/commands/monitor/export.d.ts +0 -36
  369. package/dist/cli/commands/monitor/export.d.ts.map +0 -1
  370. package/dist/cli/commands/monitor/export.js +0 -157
  371. package/dist/cli/commands/monitor/export.js.map +0 -1
  372. package/dist/cli/commands/monitor/index.d.ts +0 -11
  373. package/dist/cli/commands/monitor/index.d.ts.map +0 -1
  374. package/dist/cli/commands/monitor/index.js +0 -14
  375. package/dist/cli/commands/monitor/index.js.map +0 -1
  376. package/dist/cli/commands/quality/baseline.d.ts +0 -27
  377. package/dist/cli/commands/quality/baseline.d.ts.map +0 -1
  378. package/dist/cli/commands/quality/baseline.js +0 -124
  379. package/dist/cli/commands/quality/baseline.js.map +0 -1
  380. package/dist/cli/commands/quality/compare.d.ts +0 -36
  381. package/dist/cli/commands/quality/compare.d.ts.map +0 -1
  382. package/dist/cli/commands/quality/compare.js +0 -136
  383. package/dist/cli/commands/quality/compare.js.map +0 -1
  384. package/dist/cli/commands/quality/decision.d.ts +0 -81
  385. package/dist/cli/commands/quality/decision.d.ts.map +0 -1
  386. package/dist/cli/commands/quality/decision.js +0 -319
  387. package/dist/cli/commands/quality/decision.js.map +0 -1
  388. package/dist/cli/commands/quality/gate.d.ts +0 -47
  389. package/dist/cli/commands/quality/gate.d.ts.map +0 -1
  390. package/dist/cli/commands/quality/gate.js +0 -205
  391. package/dist/cli/commands/quality/gate.js.map +0 -1
  392. package/dist/cli/commands/quality/index.d.ts +0 -17
  393. package/dist/cli/commands/quality/index.d.ts.map +0 -1
  394. package/dist/cli/commands/quality/index.js +0 -41
  395. package/dist/cli/commands/quality/index.js.map +0 -1
  396. package/dist/cli/commands/quality/policy.d.ts +0 -57
  397. package/dist/cli/commands/quality/policy.d.ts.map +0 -1
  398. package/dist/cli/commands/quality/policy.js +0 -359
  399. package/dist/cli/commands/quality/policy.js.map +0 -1
  400. package/dist/cli/commands/quality/risk.d.ts +0 -41
  401. package/dist/cli/commands/quality/risk.d.ts.map +0 -1
  402. package/dist/cli/commands/quality/risk.js +0 -255
  403. package/dist/cli/commands/quality/risk.js.map +0 -1
  404. package/dist/cli/commands/quality/trends.d.ts +0 -40
  405. package/dist/cli/commands/quality/trends.d.ts.map +0 -1
  406. package/dist/cli/commands/quality/trends.js +0 -122
  407. package/dist/cli/commands/quality/trends.js.map +0 -1
  408. package/dist/cli/commands/quality/validate.d.ts +0 -44
  409. package/dist/cli/commands/quality/validate.d.ts.map +0 -1
  410. package/dist/cli/commands/quality/validate.js +0 -234
  411. package/dist/cli/commands/quality/validate.js.map +0 -1
  412. package/dist/cli/commands/test/analyze-failures.d.ts +0 -39
  413. package/dist/cli/commands/test/analyze-failures.d.ts.map +0 -1
  414. package/dist/cli/commands/test/analyze-failures.js +0 -113
  415. package/dist/cli/commands/test/analyze-failures.js.map +0 -1
  416. package/dist/cli/commands/test/clean.d.ts +0 -3
  417. package/dist/cli/commands/test/clean.d.ts.map +0 -1
  418. package/dist/cli/commands/test/clean.js +0 -148
  419. package/dist/cli/commands/test/clean.js.map +0 -1
  420. package/dist/cli/commands/test/debug.d.ts +0 -3
  421. package/dist/cli/commands/test/debug.d.ts.map +0 -1
  422. package/dist/cli/commands/test/debug.js +0 -167
  423. package/dist/cli/commands/test/debug.js.map +0 -1
  424. package/dist/cli/commands/test/diff.d.ts +0 -3
  425. package/dist/cli/commands/test/diff.d.ts.map +0 -1
  426. package/dist/cli/commands/test/diff.js +0 -195
  427. package/dist/cli/commands/test/diff.js.map +0 -1
  428. package/dist/cli/commands/test/flakiness.d.ts +0 -32
  429. package/dist/cli/commands/test/flakiness.d.ts.map +0 -1
  430. package/dist/cli/commands/test/flakiness.js +0 -121
  431. package/dist/cli/commands/test/flakiness.js.map +0 -1
  432. package/dist/cli/commands/test/index.d.ts +0 -17
  433. package/dist/cli/commands/test/index.d.ts.map +0 -1
  434. package/dist/cli/commands/test/index.js +0 -45
  435. package/dist/cli/commands/test/index.js.map +0 -1
  436. package/dist/cli/commands/test/mutate.d.ts +0 -29
  437. package/dist/cli/commands/test/mutate.d.ts.map +0 -1
  438. package/dist/cli/commands/test/mutate.js +0 -163
  439. package/dist/cli/commands/test/mutate.js.map +0 -1
  440. package/dist/cli/commands/test/parallel.d.ts +0 -3
  441. package/dist/cli/commands/test/parallel.d.ts.map +0 -1
  442. package/dist/cli/commands/test/parallel.js +0 -117
  443. package/dist/cli/commands/test/parallel.js.map +0 -1
  444. package/dist/cli/commands/test/profile.d.ts +0 -3
  445. package/dist/cli/commands/test/profile.d.ts.map +0 -1
  446. package/dist/cli/commands/test/profile.js +0 -156
  447. package/dist/cli/commands/test/profile.js.map +0 -1
  448. package/dist/cli/commands/test/queue.d.ts +0 -3
  449. package/dist/cli/commands/test/queue.d.ts.map +0 -1
  450. package/dist/cli/commands/test/queue.js +0 -140
  451. package/dist/cli/commands/test/queue.js.map +0 -1
  452. package/dist/cli/commands/test/retry.d.ts +0 -3
  453. package/dist/cli/commands/test/retry.d.ts.map +0 -1
  454. package/dist/cli/commands/test/retry.js +0 -105
  455. package/dist/cli/commands/test/retry.js.map +0 -1
  456. package/dist/cli/commands/test/snapshot.d.ts +0 -3
  457. package/dist/cli/commands/test/snapshot.d.ts.map +0 -1
  458. package/dist/cli/commands/test/snapshot.js +0 -176
  459. package/dist/cli/commands/test/snapshot.js.map +0 -1
  460. package/dist/cli/commands/test/trace.d.ts +0 -3
  461. package/dist/cli/commands/test/trace.d.ts.map +0 -1
  462. package/dist/cli/commands/test/trace.js +0 -137
  463. package/dist/cli/commands/test/trace.js.map +0 -1
  464. package/dist/cli/commands/test/watch.d.ts +0 -3
  465. package/dist/cli/commands/test/watch.d.ts.map +0 -1
  466. package/dist/cli/commands/test/watch.js +0 -130
  467. package/dist/cli/commands/test/watch.js.map +0 -1
  468. package/dist/cli/index-spec.d.ts +0 -3
  469. package/dist/cli/index-spec.d.ts.map +0 -1
  470. package/dist/cli/index-spec.js +0 -154
  471. package/dist/cli/index-spec.js.map +0 -1
  472. package/dist/cli/index-working.d.ts +0 -7
  473. package/dist/cli/index-working.d.ts.map +0 -1
  474. package/dist/cli/index-working.js +0 -617
  475. package/dist/cli/index-working.js.map +0 -1
  476. package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts +0 -83
  477. package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts.map +0 -1
  478. package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js +0 -130
  479. package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js.map +0 -1
  480. package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts +0 -58
  481. package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts.map +0 -1
  482. package/dist/mcp/handlers/filtered/flaky-detector-filtered.js +0 -84
  483. package/dist/mcp/handlers/filtered/flaky-detector-filtered.js.map +0 -1
  484. package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts +0 -54
  485. package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts.map +0 -1
  486. package/dist/mcp/handlers/filtered/security-scanner-filtered.js +0 -73
  487. package/dist/mcp/handlers/filtered/security-scanner-filtered.js.map +0 -1
  488. package/dist/mcp/handlers/integration/contract-validate.d.ts +0 -10
  489. package/dist/mcp/handlers/integration/contract-validate.d.ts.map +0 -1
  490. package/dist/mcp/handlers/integration/contract-validate.js +0 -348
  491. package/dist/mcp/handlers/integration/contract-validate.js.map +0 -1
  492. package/dist/reporting/ResultAggregator.d.ts +0 -107
  493. package/dist/reporting/ResultAggregator.d.ts.map +0 -1
  494. package/dist/reporting/ResultAggregator.js +0 -435
  495. package/dist/reporting/ResultAggregator.js.map +0 -1
  496. package/dist/reporting/index.d.ts +0 -48
  497. package/dist/reporting/index.d.ts.map +0 -1
  498. package/dist/reporting/index.js +0 -154
  499. package/dist/reporting/index.js.map +0 -1
  500. package/dist/reporting/reporters/ControlLoopReporter.d.ts +0 -128
  501. package/dist/reporting/reporters/ControlLoopReporter.d.ts.map +0 -1
  502. package/dist/reporting/reporters/ControlLoopReporter.js +0 -417
  503. package/dist/reporting/reporters/ControlLoopReporter.js.map +0 -1
  504. package/dist/reporting/reporters/HumanReadableReporter.d.ts +0 -140
  505. package/dist/reporting/reporters/HumanReadableReporter.d.ts.map +0 -1
  506. package/dist/reporting/reporters/HumanReadableReporter.js +0 -524
  507. package/dist/reporting/reporters/HumanReadableReporter.js.map +0 -1
  508. package/dist/reporting/reporters/JSONReporter.d.ts +0 -251
  509. package/dist/reporting/reporters/JSONReporter.d.ts.map +0 -1
  510. package/dist/reporting/reporters/JSONReporter.js +0 -325
  511. package/dist/reporting/reporters/JSONReporter.js.map +0 -1
  512. package/dist/reporting/reporters/index.d.ts +0 -14
  513. package/dist/reporting/reporters/index.d.ts.map +0 -1
  514. package/dist/reporting/reporters/index.js +0 -19
  515. package/dist/reporting/reporters/index.js.map +0 -1
  516. package/dist/reporting/types.d.ts +0 -427
  517. package/dist/reporting/types.d.ts.map +0 -1
  518. package/dist/reporting/types.js +0 -12
  519. package/dist/reporting/types.js.map +0 -1
@@ -0,0 +1,819 @@
1
+ "use strict";
2
+ /**
3
+ * Federated Round Coordinator
4
+ *
5
+ * Coordinates training rounds across peers in a federated learning session.
6
+ * Handles participant selection, round lifecycle management, update collection,
7
+ * timeout handling, and minimum participation thresholds.
8
+ *
9
+ * @module edge/p2p/federated/FederatedRound
10
+ * @version 1.0.0
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.FederatedRound = exports.RoundEventType = void 0;
14
+ exports.createFederatedRound = createFederatedRound;
15
+ const types_1 = require("./types");
16
+ /**
17
+ * Round event types
18
+ */
19
+ var RoundEventType;
20
+ (function (RoundEventType) {
21
+ RoundEventType["STATUS_CHANGED"] = "status_changed";
22
+ RoundEventType["PARTICIPANT_JOINED"] = "participant_joined";
23
+ RoundEventType["PARTICIPANT_DROPPED"] = "participant_dropped";
24
+ RoundEventType["UPDATE_RECEIVED"] = "update_received";
25
+ RoundEventType["AGGREGATION_STARTED"] = "aggregation_started";
26
+ RoundEventType["AGGREGATION_COMPLETED"] = "aggregation_completed";
27
+ RoundEventType["ROUND_COMPLETED"] = "round_completed";
28
+ RoundEventType["ROUND_FAILED"] = "round_failed";
29
+ RoundEventType["ROUND_TIMED_OUT"] = "round_timed_out";
30
+ })(RoundEventType || (exports.RoundEventType = RoundEventType = {}));
31
+ // ============================================
32
+ // FederatedRound Class
33
+ // ============================================
34
+ /**
35
+ * Manages a single federated learning round
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const round = new FederatedRound({
40
+ * sessionId: 'session-1',
41
+ * roundNumber: 5,
42
+ * federatedConfig: config,
43
+ * globalModel: currentModel,
44
+ * availableParticipants: participants,
45
+ * aggregator: aggregator,
46
+ * sendMessage: async (id, msg) => channel.send(id, msg),
47
+ * broadcastMessage: async (msg) => channel.broadcast(msg),
48
+ * });
49
+ *
50
+ * await round.start();
51
+ *
52
+ * // Handle join requests
53
+ * round.handleJoinRequest(request);
54
+ *
55
+ * // Handle update submissions
56
+ * round.handleUpdateSubmission(submission);
57
+ *
58
+ * // Wait for round completion
59
+ * const result = await round.waitForCompletion();
60
+ * ```
61
+ */
62
+ class FederatedRound {
63
+ constructor(config) {
64
+ this.eventHandlers = [];
65
+ this.timeoutTimer = null;
66
+ this.collectionTimer = null;
67
+ this.completionPromise = null;
68
+ this.completionResolve = null;
69
+ this.completionReject = null;
70
+ this.config = config;
71
+ // Initialize round state
72
+ this.state = {
73
+ roundId: `${config.sessionId}-round-${config.roundNumber}`,
74
+ roundNumber: config.roundNumber,
75
+ status: types_1.RoundStatus.PREPARING,
76
+ participants: new Map(),
77
+ updates: new Map(),
78
+ startingModel: config.globalModel,
79
+ startedAt: 0,
80
+ targetParticipants: Math.min(config.federatedConfig.maxParticipants, config.availableParticipants.size),
81
+ minParticipants: Math.max(1, Math.ceil(config.availableParticipants.size * config.federatedConfig.minParticipation)),
82
+ timeoutAt: 0,
83
+ metrics: this.createInitialMetrics(),
84
+ errors: [],
85
+ };
86
+ }
87
+ // ============================================
88
+ // Lifecycle Methods
89
+ // ============================================
90
+ /**
91
+ * Start the round
92
+ */
93
+ async start() {
94
+ if (this.state.status !== types_1.RoundStatus.PREPARING) {
95
+ throw new types_1.FederatedError('Round already started', types_1.FederatedErrorCode.ROUND_NOT_FOUND);
96
+ }
97
+ this.state.startedAt = Date.now();
98
+ this.state.timeoutAt = this.state.startedAt + this.config.federatedConfig.roundTimeout;
99
+ // Set up completion promise
100
+ this.completionPromise = new Promise((resolve, reject) => {
101
+ this.completionResolve = resolve;
102
+ this.completionReject = reject;
103
+ });
104
+ // Select participants
105
+ const selectedParticipants = this.selectParticipants();
106
+ if (selectedParticipants.length < this.state.minParticipants) {
107
+ this.fail(new types_1.FederatedError(`Insufficient participants: ${selectedParticipants.length} < ${this.state.minParticipants}`, types_1.FederatedErrorCode.INSUFFICIENT_PARTICIPANTS));
108
+ return;
109
+ }
110
+ // Transition to awaiting participants
111
+ this.updateStatus(types_1.RoundStatus.AWAITING_PARTICIPANTS);
112
+ // Create round announcement
113
+ const announcement = this.createRoundAnnouncement();
114
+ // Send announcements to selected participants
115
+ await this.announceRound(selectedParticipants, announcement);
116
+ // Start timeout timer
117
+ this.startTimeoutTimer();
118
+ // Start collection phase after brief delay
119
+ setTimeout(() => {
120
+ if (this.state.status === types_1.RoundStatus.AWAITING_PARTICIPANTS) {
121
+ this.updateStatus(types_1.RoundStatus.ANNOUNCED);
122
+ // Start collecting after announcement phase
123
+ setTimeout(() => {
124
+ if (this.state.status === types_1.RoundStatus.ANNOUNCED ||
125
+ this.state.status === types_1.RoundStatus.AWAITING_PARTICIPANTS) {
126
+ this.updateStatus(types_1.RoundStatus.COLLECTING);
127
+ }
128
+ }, 1000); // 1 second for announcements to propagate
129
+ }
130
+ }, 100);
131
+ }
132
+ /**
133
+ * Cancel the round
134
+ */
135
+ cancel(reason = 'Round cancelled') {
136
+ if (this.isFinished())
137
+ return;
138
+ this.cleanup();
139
+ this.updateStatus(types_1.RoundStatus.CANCELLED);
140
+ this.addError('CANCELLED', reason, true);
141
+ if (this.completionReject) {
142
+ this.completionReject(new types_1.FederatedError(reason, types_1.FederatedErrorCode.ROUND_NOT_FOUND));
143
+ }
144
+ }
145
+ /**
146
+ * Wait for round completion
147
+ */
148
+ async waitForCompletion() {
149
+ if (!this.completionPromise) {
150
+ throw new types_1.FederatedError('Round not started', types_1.FederatedErrorCode.ROUND_NOT_FOUND);
151
+ }
152
+ return this.completionPromise;
153
+ }
154
+ /**
155
+ * Check if round is finished
156
+ */
157
+ isFinished() {
158
+ return [
159
+ types_1.RoundStatus.COMPLETED,
160
+ types_1.RoundStatus.FAILED,
161
+ types_1.RoundStatus.CANCELLED,
162
+ types_1.RoundStatus.TIMED_OUT,
163
+ ].includes(this.state.status);
164
+ }
165
+ // ============================================
166
+ // Participant Management
167
+ // ============================================
168
+ /**
169
+ * Handle join request from participant
170
+ */
171
+ async handleJoinRequest(request) {
172
+ // Validate request
173
+ if (request.roundId !== this.state.roundId) {
174
+ return {
175
+ type: 'join_response',
176
+ accepted: false,
177
+ rejectionReason: 'Wrong round ID',
178
+ };
179
+ }
180
+ // Check if still accepting participants
181
+ if (this.state.status !== types_1.RoundStatus.AWAITING_PARTICIPANTS &&
182
+ this.state.status !== types_1.RoundStatus.ANNOUNCED &&
183
+ this.state.status !== types_1.RoundStatus.COLLECTING) {
184
+ return {
185
+ type: 'join_response',
186
+ accepted: false,
187
+ rejectionReason: 'Round not accepting participants',
188
+ };
189
+ }
190
+ // Check if already joined
191
+ if (this.state.participants.has(request.participantId)) {
192
+ return {
193
+ type: 'join_response',
194
+ accepted: false,
195
+ rejectionReason: 'Already joined',
196
+ };
197
+ }
198
+ // Check participant limit
199
+ if (this.state.participants.size >= this.config.federatedConfig.maxParticipants) {
200
+ return {
201
+ type: 'join_response',
202
+ accepted: false,
203
+ rejectionReason: 'Round at capacity',
204
+ };
205
+ }
206
+ // Calculate participant weight
207
+ const totalSamples = this.getTotalSamples() + request.sampleCount;
208
+ const weight = request.sampleCount / totalSamples;
209
+ // Create participant record
210
+ const participant = {
211
+ participantId: request.participantId,
212
+ sampleCount: request.sampleCount,
213
+ weight,
214
+ hasSubmitted: false,
215
+ joinedAt: Date.now(),
216
+ capabilities: request.capabilities,
217
+ };
218
+ this.state.participants.set(request.participantId, participant);
219
+ this.state.metrics.participantsJoined++;
220
+ this.state.metrics.totalSamples += request.sampleCount;
221
+ // Recalculate weights for all participants
222
+ this.recalculateWeights();
223
+ this.emitEvent({
224
+ type: RoundEventType.PARTICIPANT_JOINED,
225
+ timestamp: Date.now(),
226
+ details: { participantId: request.participantId },
227
+ });
228
+ return {
229
+ type: 'join_response',
230
+ accepted: true,
231
+ weight: participant.weight,
232
+ model: this.state.startingModel,
233
+ };
234
+ }
235
+ /**
236
+ * Handle participant dropout
237
+ */
238
+ handleParticipantDropout(participantId) {
239
+ const participant = this.state.participants.get(participantId);
240
+ if (!participant)
241
+ return;
242
+ // Remove participant
243
+ this.state.participants.delete(participantId);
244
+ this.state.updates.delete(participantId);
245
+ // Recalculate weights
246
+ this.recalculateWeights();
247
+ // Update metrics
248
+ this.state.metrics.totalSamples -= participant.sampleCount;
249
+ this.emitEvent({
250
+ type: RoundEventType.PARTICIPANT_DROPPED,
251
+ timestamp: Date.now(),
252
+ details: { participantId },
253
+ });
254
+ // Check if we still have minimum participants
255
+ if (this.state.participants.size < this.state.minParticipants &&
256
+ !this.isFinished()) {
257
+ this.fail(new types_1.FederatedError('Dropped below minimum participants', types_1.FederatedErrorCode.INSUFFICIENT_PARTICIPANTS));
258
+ }
259
+ }
260
+ // ============================================
261
+ // Update Collection
262
+ // ============================================
263
+ /**
264
+ * Handle update submission from participant
265
+ */
266
+ async handleUpdateSubmission(submission) {
267
+ // Validate submission
268
+ if (submission.roundId !== this.state.roundId) {
269
+ return false;
270
+ }
271
+ // Check if collecting
272
+ if (this.state.status !== types_1.RoundStatus.COLLECTING &&
273
+ this.state.status !== types_1.RoundStatus.ANNOUNCED) {
274
+ return false;
275
+ }
276
+ // Check if participant joined
277
+ const participant = this.state.participants.get(submission.update.participantId);
278
+ if (!participant) {
279
+ return false;
280
+ }
281
+ // Check if already submitted
282
+ if (participant.hasSubmitted) {
283
+ return false;
284
+ }
285
+ // Store update
286
+ this.state.updates.set(submission.update.participantId, submission.update);
287
+ participant.hasSubmitted = true;
288
+ participant.submittedAt = Date.now();
289
+ // Update metrics
290
+ this.state.metrics.participantsSubmitted++;
291
+ this.state.metrics.participationRate =
292
+ this.state.metrics.participantsSubmitted / this.state.participants.size;
293
+ this.emitEvent({
294
+ type: RoundEventType.UPDATE_RECEIVED,
295
+ timestamp: Date.now(),
296
+ details: {
297
+ participantId: submission.update.participantId,
298
+ sampleCount: submission.update.sampleCount,
299
+ },
300
+ });
301
+ // Check if we have enough updates to aggregate
302
+ await this.checkAggregationTrigger();
303
+ return true;
304
+ }
305
+ /**
306
+ * Check if we should trigger aggregation
307
+ */
308
+ async checkAggregationTrigger() {
309
+ // All participants submitted
310
+ if (this.state.updates.size >= this.state.participants.size) {
311
+ await this.startAggregation();
312
+ return;
313
+ }
314
+ // Enough participants and timeout approaching
315
+ const timeRemaining = this.state.timeoutAt - Date.now();
316
+ const enoughParticipants = this.state.updates.size >= this.state.minParticipants;
317
+ const timeoutApproaching = timeRemaining < this.config.federatedConfig.roundTimeout * 0.2;
318
+ if (enoughParticipants && timeoutApproaching) {
319
+ await this.startAggregation();
320
+ }
321
+ }
322
+ // ============================================
323
+ // Aggregation
324
+ // ============================================
325
+ /**
326
+ * Start aggregation phase
327
+ */
328
+ async startAggregation() {
329
+ if (this.state.status === types_1.RoundStatus.AGGREGATING ||
330
+ this.state.status === types_1.RoundStatus.DISTRIBUTING ||
331
+ this.isFinished()) {
332
+ return;
333
+ }
334
+ this.updateStatus(types_1.RoundStatus.AGGREGATING);
335
+ this.emitEvent({
336
+ type: RoundEventType.AGGREGATION_STARTED,
337
+ timestamp: Date.now(),
338
+ details: { updateCount: this.state.updates.size },
339
+ });
340
+ try {
341
+ const aggregationStart = Date.now();
342
+ // Get updates array
343
+ const updates = Array.from(this.state.updates.values());
344
+ // Perform aggregation
345
+ const result = await this.config.aggregator.aggregate(updates, this.state.startingModel);
346
+ // Update metrics
347
+ this.state.metrics.aggregationTime = Date.now() - aggregationStart;
348
+ this.state.metrics.aggregatedLoss = this.computeAggregatedLoss(updates);
349
+ this.state.aggregatedModel = result.aggregatedWeights;
350
+ this.emitEvent({
351
+ type: RoundEventType.AGGREGATION_COMPLETED,
352
+ timestamp: Date.now(),
353
+ details: {
354
+ aggregationTime: this.state.metrics.aggregationTime,
355
+ updateCount: result.updateCount,
356
+ },
357
+ });
358
+ // Distribute result
359
+ await this.distributeResult(result);
360
+ // Complete round
361
+ this.complete(result);
362
+ }
363
+ catch (error) {
364
+ this.fail(error instanceof Error ? error : new Error(String(error)));
365
+ }
366
+ }
367
+ /**
368
+ * Distribute aggregation result to participants
369
+ */
370
+ async distributeResult(result) {
371
+ this.updateStatus(types_1.RoundStatus.DISTRIBUTING);
372
+ const broadcast = {
373
+ type: 'aggregation_result',
374
+ sessionId: this.config.sessionId,
375
+ roundId: this.state.roundId,
376
+ model: result.aggregatedWeights,
377
+ metrics: this.state.metrics,
378
+ };
379
+ try {
380
+ await this.config.broadcastMessage(broadcast);
381
+ }
382
+ catch (error) {
383
+ this.addError('DISTRIBUTION_ERROR', `Failed to distribute result: ${error}`, true);
384
+ }
385
+ }
386
+ /**
387
+ * Complete the round successfully
388
+ */
389
+ complete(result) {
390
+ this.cleanup();
391
+ this.state.endedAt = Date.now();
392
+ this.state.metrics.duration = this.state.endedAt - this.state.startedAt;
393
+ this.updateStatus(types_1.RoundStatus.COMPLETED);
394
+ this.emitEvent({
395
+ type: RoundEventType.ROUND_COMPLETED,
396
+ timestamp: Date.now(),
397
+ details: {
398
+ roundNumber: this.state.roundNumber,
399
+ metrics: this.state.metrics,
400
+ },
401
+ });
402
+ if (this.completionResolve) {
403
+ this.completionResolve(result);
404
+ }
405
+ }
406
+ /**
407
+ * Fail the round
408
+ */
409
+ fail(error) {
410
+ this.cleanup();
411
+ this.state.endedAt = Date.now();
412
+ this.state.metrics.duration = this.state.endedAt - this.state.startedAt;
413
+ this.addError('ROUND_FAILED', error.message, false);
414
+ this.updateStatus(types_1.RoundStatus.FAILED);
415
+ this.emitEvent({
416
+ type: RoundEventType.ROUND_FAILED,
417
+ timestamp: Date.now(),
418
+ details: { error: error.message },
419
+ });
420
+ if (this.completionReject) {
421
+ this.completionReject(error);
422
+ }
423
+ }
424
+ // ============================================
425
+ // Participant Selection
426
+ // ============================================
427
+ /**
428
+ * Select participants for this round
429
+ */
430
+ selectParticipants() {
431
+ const available = Array.from(this.config.availableParticipants.values());
432
+ const strategy = this.config.federatedConfig.selectionStrategy;
433
+ const targetCount = Math.min(this.config.federatedConfig.maxParticipants, available.length);
434
+ switch (strategy) {
435
+ case types_1.SelectionStrategy.RANDOM:
436
+ return this.randomSelection(available, targetCount);
437
+ case types_1.SelectionStrategy.IMPORTANCE:
438
+ return this.importanceSelection(available, targetCount);
439
+ case types_1.SelectionStrategy.DIVERSITY:
440
+ return this.diversitySelection(available, targetCount);
441
+ case types_1.SelectionStrategy.ROUND_ROBIN:
442
+ return this.roundRobinSelection(available, targetCount);
443
+ case types_1.SelectionStrategy.ACTIVE:
444
+ return this.activeSelection(available, targetCount);
445
+ case types_1.SelectionStrategy.POWER_OF_CHOICE:
446
+ return this.powerOfChoiceSelection(available, targetCount);
447
+ default:
448
+ return this.randomSelection(available, targetCount);
449
+ }
450
+ }
451
+ /**
452
+ * Random selection strategy
453
+ */
454
+ randomSelection(available, targetCount) {
455
+ const shuffled = [...available].sort(() => Math.random() - 0.5);
456
+ return shuffled.slice(0, targetCount);
457
+ }
458
+ /**
459
+ * Importance sampling based on data size
460
+ */
461
+ importanceSelection(available, targetCount) {
462
+ const totalSamples = available.reduce((sum, p) => sum + p.sampleCount, 0);
463
+ // Calculate selection probabilities
464
+ const probabilities = available.map((p) => ({
465
+ participant: p,
466
+ probability: p.sampleCount / totalSamples,
467
+ }));
468
+ // Weighted sampling without replacement
469
+ const selected = [];
470
+ const remaining = [...probabilities];
471
+ while (selected.length < targetCount && remaining.length > 0) {
472
+ const totalProb = remaining.reduce((sum, p) => sum + p.probability, 0);
473
+ let random = Math.random() * totalProb;
474
+ for (let i = 0; i < remaining.length; i++) {
475
+ random -= remaining[i].probability;
476
+ if (random <= 0) {
477
+ selected.push(remaining[i].participant);
478
+ remaining.splice(i, 1);
479
+ break;
480
+ }
481
+ }
482
+ }
483
+ return selected;
484
+ }
485
+ /**
486
+ * Diversity-based selection
487
+ */
488
+ diversitySelection(available, targetCount) {
489
+ // Sort by diversity score (descending)
490
+ const sorted = [...available].sort((a, b) => (b.diversityScore ?? 0) - (a.diversityScore ?? 0));
491
+ return sorted.slice(0, targetCount);
492
+ }
493
+ /**
494
+ * Round-robin selection
495
+ */
496
+ roundRobinSelection(available, targetCount) {
497
+ // Sort by last participation (oldest first)
498
+ const sorted = [...available].sort((a, b) => (a.lastParticipation ?? 0) - (b.lastParticipation ?? 0));
499
+ return sorted.slice(0, targetCount);
500
+ }
501
+ /**
502
+ * Active learning-based selection
503
+ */
504
+ activeSelection(available, targetCount) {
505
+ // Combine factors: trust score, diversity, recency
506
+ const scored = available.map((p) => ({
507
+ participant: p,
508
+ score: p.trustScore * 0.4 +
509
+ (p.diversityScore ?? 0.5) * 0.3 +
510
+ (1 - Math.min(1, ((Date.now() - (p.lastParticipation ?? 0)) / (24 * 60 * 60 * 1000)))) * 0.3,
511
+ }));
512
+ scored.sort((a, b) => b.score - a.score);
513
+ return scored.slice(0, targetCount).map((s) => s.participant);
514
+ }
515
+ /**
516
+ * Power-of-choice selection
517
+ */
518
+ powerOfChoiceSelection(available, targetCount) {
519
+ // For each slot, pick best of d random candidates
520
+ const d = 2; // Power of 2 choices
521
+ const selected = [];
522
+ const remaining = [...available];
523
+ while (selected.length < targetCount && remaining.length > 0) {
524
+ // Pick d random candidates
525
+ const candidates = [];
526
+ for (let i = 0; i < Math.min(d, remaining.length); i++) {
527
+ const idx = Math.floor(Math.random() * remaining.length);
528
+ candidates.push(remaining[idx]);
529
+ }
530
+ // Select best candidate (by sample count)
531
+ const best = candidates.reduce((a, b) => a.sampleCount > b.sampleCount ? a : b);
532
+ selected.push(best);
533
+ remaining.splice(remaining.indexOf(best), 1);
534
+ }
535
+ return selected;
536
+ }
537
+ // ============================================
538
+ // Round Communication
539
+ // ============================================
540
+ /**
541
+ * Create round announcement message
542
+ */
543
+ createRoundAnnouncement() {
544
+ const config = this.config.federatedConfig;
545
+ const trainingConfig = {
546
+ epochs: config.localEpochs,
547
+ batchSize: config.batchSize,
548
+ learningRate: config.learningRate,
549
+ updateType: types_1.UpdateType.GRADIENTS,
550
+ applyDifferentialPrivacy: config.differentialPrivacy?.enabled ?? false,
551
+ dpConfig: config.differentialPrivacy,
552
+ compressionConfig: config.compression,
553
+ };
554
+ return {
555
+ type: 'round_announcement',
556
+ sessionId: this.config.sessionId,
557
+ roundId: this.state.roundId,
558
+ roundNumber: this.state.roundNumber,
559
+ modelVersion: this.state.startingModel.version,
560
+ modelChecksum: this.state.startingModel.checksum,
561
+ trainingConfig,
562
+ deadline: this.state.timeoutAt,
563
+ minParticipants: this.state.minParticipants,
564
+ };
565
+ }
566
+ /**
567
+ * Send round announcements to selected participants
568
+ */
569
+ async announceRound(participants, announcement) {
570
+ const sendPromises = participants.map(async (p) => {
571
+ try {
572
+ await this.config.sendMessage(p.participantId, announcement);
573
+ }
574
+ catch (error) {
575
+ this.addError('ANNOUNCEMENT_ERROR', `Failed to announce to ${p.participantId}: ${error}`, true);
576
+ }
577
+ });
578
+ await Promise.all(sendPromises);
579
+ }
580
+ // ============================================
581
+ // Timeout Handling
582
+ // ============================================
583
+ /**
584
+ * Start the round timeout timer
585
+ */
586
+ startTimeoutTimer() {
587
+ const timeout = this.config.federatedConfig.roundTimeout;
588
+ this.timeoutTimer = setTimeout(() => {
589
+ this.handleTimeout();
590
+ }, timeout);
591
+ }
592
+ /**
593
+ * Handle round timeout
594
+ */
595
+ handleTimeout() {
596
+ if (this.isFinished())
597
+ return;
598
+ // Check if we have minimum participants
599
+ if (this.state.updates.size >= this.state.minParticipants) {
600
+ // Proceed with aggregation
601
+ this.startAggregation();
602
+ }
603
+ else {
604
+ // Fail the round
605
+ this.cleanup();
606
+ this.state.endedAt = Date.now();
607
+ this.state.metrics.duration = this.state.endedAt - this.state.startedAt;
608
+ this.addError('TIMEOUT', `Round timed out with only ${this.state.updates.size}/${this.state.minParticipants} updates`, false);
609
+ this.updateStatus(types_1.RoundStatus.TIMED_OUT);
610
+ this.emitEvent({
611
+ type: RoundEventType.ROUND_TIMED_OUT,
612
+ timestamp: Date.now(),
613
+ details: {
614
+ updatesReceived: this.state.updates.size,
615
+ minRequired: this.state.minParticipants,
616
+ },
617
+ });
618
+ if (this.completionReject) {
619
+ this.completionReject(new types_1.FederatedError('Round timed out', types_1.FederatedErrorCode.ROUND_TIMEOUT));
620
+ }
621
+ }
622
+ }
623
+ // ============================================
624
+ // Helper Methods
625
+ // ============================================
626
+ /**
627
+ * Get total samples across joined participants
628
+ */
629
+ getTotalSamples() {
630
+ let total = 0;
631
+ for (const p of this.state.participants.values()) {
632
+ total += p.sampleCount;
633
+ }
634
+ return total;
635
+ }
636
+ /**
637
+ * Recalculate weights for all participants
638
+ */
639
+ recalculateWeights() {
640
+ const totalSamples = this.getTotalSamples();
641
+ if (totalSamples === 0)
642
+ return;
643
+ for (const participant of this.state.participants.values()) {
644
+ participant.weight = participant.sampleCount / totalSamples;
645
+ }
646
+ }
647
+ /**
648
+ * Compute aggregated loss from updates
649
+ */
650
+ computeAggregatedLoss(updates) {
651
+ if (updates.length === 0)
652
+ return 0;
653
+ const totalSamples = updates.reduce((sum, u) => sum + u.sampleCount, 0);
654
+ let weightedLoss = 0;
655
+ for (const update of updates) {
656
+ const weight = update.sampleCount / totalSamples;
657
+ weightedLoss += weight * update.localLoss;
658
+ }
659
+ return weightedLoss;
660
+ }
661
+ /**
662
+ * Create initial metrics object
663
+ */
664
+ createInitialMetrics() {
665
+ return {
666
+ participantsJoined: 0,
667
+ participantsSubmitted: 0,
668
+ participationRate: 0,
669
+ totalSamples: 0,
670
+ aggregatedLoss: 0,
671
+ lossImprovement: 0,
672
+ duration: 0,
673
+ communicationBytes: 0,
674
+ };
675
+ }
676
+ /**
677
+ * Update round status
678
+ */
679
+ updateStatus(status) {
680
+ const previousStatus = this.state.status;
681
+ this.state.status = status;
682
+ this.emitEvent({
683
+ type: RoundEventType.STATUS_CHANGED,
684
+ timestamp: Date.now(),
685
+ details: { from: previousStatus, to: status },
686
+ });
687
+ }
688
+ /**
689
+ * Add an error to the round
690
+ */
691
+ addError(type, message, recoverable) {
692
+ this.state.errors.push({
693
+ type,
694
+ message,
695
+ timestamp: Date.now(),
696
+ recoverable,
697
+ });
698
+ }
699
+ /**
700
+ * Cleanup timers and resources
701
+ */
702
+ cleanup() {
703
+ if (this.timeoutTimer) {
704
+ clearTimeout(this.timeoutTimer);
705
+ this.timeoutTimer = null;
706
+ }
707
+ if (this.collectionTimer) {
708
+ clearTimeout(this.collectionTimer);
709
+ this.collectionTimer = null;
710
+ }
711
+ }
712
+ // ============================================
713
+ // Event Handling
714
+ // ============================================
715
+ /**
716
+ * Add event handler
717
+ */
718
+ on(handler) {
719
+ this.eventHandlers.push(handler);
720
+ }
721
+ /**
722
+ * Remove event handler
723
+ */
724
+ off(handler) {
725
+ const index = this.eventHandlers.indexOf(handler);
726
+ if (index !== -1) {
727
+ this.eventHandlers.splice(index, 1);
728
+ }
729
+ }
730
+ /**
731
+ * Emit event to handlers
732
+ */
733
+ emitEvent(event) {
734
+ for (const handler of this.eventHandlers) {
735
+ try {
736
+ handler(event);
737
+ }
738
+ catch {
739
+ // Ignore handler errors
740
+ }
741
+ }
742
+ }
743
+ // ============================================
744
+ // Getters
745
+ // ============================================
746
+ /**
747
+ * Get round ID
748
+ */
749
+ getRoundId() {
750
+ return this.state.roundId;
751
+ }
752
+ /**
753
+ * Get round number
754
+ */
755
+ getRoundNumber() {
756
+ return this.state.roundNumber;
757
+ }
758
+ /**
759
+ * Get current status
760
+ */
761
+ getStatus() {
762
+ return this.state.status;
763
+ }
764
+ /**
765
+ * Get round state
766
+ */
767
+ getState() {
768
+ return { ...this.state };
769
+ }
770
+ /**
771
+ * Get round metrics
772
+ */
773
+ getMetrics() {
774
+ return { ...this.state.metrics };
775
+ }
776
+ /**
777
+ * Get participants
778
+ */
779
+ getParticipants() {
780
+ return new Map(this.state.participants);
781
+ }
782
+ /**
783
+ * Get updates received
784
+ */
785
+ getUpdates() {
786
+ return new Map(this.state.updates);
787
+ }
788
+ /**
789
+ * Get aggregated model
790
+ */
791
+ getAggregatedModel() {
792
+ return this.state.aggregatedModel;
793
+ }
794
+ /**
795
+ * Get errors
796
+ */
797
+ getErrors() {
798
+ return [...this.state.errors];
799
+ }
800
+ /**
801
+ * Get time remaining until timeout
802
+ */
803
+ getTimeRemaining() {
804
+ if (this.isFinished())
805
+ return 0;
806
+ return Math.max(0, this.state.timeoutAt - Date.now());
807
+ }
808
+ }
809
+ exports.FederatedRound = FederatedRound;
810
+ // ============================================
811
+ // Factory Function
812
+ // ============================================
813
+ /**
814
+ * Create a new federated round
815
+ */
816
+ function createFederatedRound(config) {
817
+ return new FederatedRound(config);
818
+ }
819
+ //# sourceMappingURL=FederatedRound.js.map