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.
- package/CHANGELOG.md +104 -0
- package/README.md +67 -2
- package/dist/cli/commands/agent/spawn.d.ts +12 -1
- package/dist/cli/commands/agent/spawn.d.ts.map +1 -1
- package/dist/cli/commands/agent/spawn.js +95 -8
- package/dist/cli/commands/agent/spawn.js.map +1 -1
- package/dist/cli/index.js +91 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/memory/HNSWVectorMemory.js +1 -1
- package/dist/edge/adapters/BrowserHNSWAdapter.d.ts +134 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.d.ts.map +1 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.js +484 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.js.map +1 -0
- package/dist/edge/adapters/IndexedDBStorage.d.ts +114 -0
- package/dist/edge/adapters/IndexedDBStorage.d.ts.map +1 -0
- package/dist/edge/adapters/IndexedDBStorage.js +478 -0
- package/dist/edge/adapters/IndexedDBStorage.js.map +1 -0
- package/dist/edge/adapters/index.d.ts +12 -0
- package/dist/edge/adapters/index.d.ts.map +1 -0
- package/dist/edge/adapters/index.js +22 -0
- package/dist/edge/adapters/index.js.map +1 -0
- package/dist/edge/browser/BrowserAgent.d.ts +241 -0
- package/dist/edge/browser/BrowserAgent.d.ts.map +1 -0
- package/dist/edge/browser/BrowserAgent.js +743 -0
- package/dist/edge/browser/BrowserAgent.js.map +1 -0
- package/dist/edge/index.d.ts +34 -0
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +114 -0
- package/dist/edge/index.js.map +1 -0
- package/dist/edge/p2p/coordination/CoordinationManager.d.ts +181 -0
- package/dist/edge/p2p/coordination/CoordinationManager.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/CoordinationManager.js +851 -0
- package/dist/edge/p2p/coordination/CoordinationManager.js.map +1 -0
- package/dist/edge/p2p/coordination/HealthMonitor.d.ts +143 -0
- package/dist/edge/p2p/coordination/HealthMonitor.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/HealthMonitor.js +432 -0
- package/dist/edge/p2p/coordination/HealthMonitor.js.map +1 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts +146 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.js +783 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.js.map +1 -0
- package/dist/edge/p2p/coordination/index.d.ts +70 -0
- package/dist/edge/p2p/coordination/index.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/index.js +107 -0
- package/dist/edge/p2p/coordination/index.js.map +1 -0
- package/dist/edge/p2p/coordination/types.d.ts +572 -0
- package/dist/edge/p2p/coordination/types.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/types.js +366 -0
- package/dist/edge/p2p/coordination/types.js.map +1 -0
- package/dist/edge/p2p/crdt/CRDTStore.d.ts +324 -0
- package/dist/edge/p2p/crdt/CRDTStore.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/CRDTStore.js +839 -0
- package/dist/edge/p2p/crdt/CRDTStore.js.map +1 -0
- package/dist/edge/p2p/crdt/GCounter.d.ts +173 -0
- package/dist/edge/p2p/crdt/GCounter.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/GCounter.js +394 -0
- package/dist/edge/p2p/crdt/GCounter.js.map +1 -0
- package/dist/edge/p2p/crdt/LWWRegister.d.ts +200 -0
- package/dist/edge/p2p/crdt/LWWRegister.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/LWWRegister.js +456 -0
- package/dist/edge/p2p/crdt/LWWRegister.js.map +1 -0
- package/dist/edge/p2p/crdt/ORSet.d.ts +232 -0
- package/dist/edge/p2p/crdt/ORSet.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/ORSet.js +723 -0
- package/dist/edge/p2p/crdt/ORSet.js.map +1 -0
- package/dist/edge/p2p/crdt/PatternCRDT.d.ts +366 -0
- package/dist/edge/p2p/crdt/PatternCRDT.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/PatternCRDT.js +838 -0
- package/dist/edge/p2p/crdt/PatternCRDT.js.map +1 -0
- package/dist/edge/p2p/crdt/VectorClock.d.ts +274 -0
- package/dist/edge/p2p/crdt/VectorClock.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/VectorClock.js +499 -0
- package/dist/edge/p2p/crdt/VectorClock.js.map +1 -0
- package/dist/edge/p2p/crdt/index.d.ts +87 -0
- package/dist/edge/p2p/crdt/index.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/index.js +120 -0
- package/dist/edge/p2p/crdt/index.js.map +1 -0
- package/dist/edge/p2p/crdt/types.d.ts +667 -0
- package/dist/edge/p2p/crdt/types.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/types.js +208 -0
- package/dist/edge/p2p/crdt/types.js.map +1 -0
- package/dist/edge/p2p/crypto/Identity.d.ts +139 -0
- package/dist/edge/p2p/crypto/Identity.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/Identity.js +449 -0
- package/dist/edge/p2p/crypto/Identity.js.map +1 -0
- package/dist/edge/p2p/crypto/KeyManager.d.ts +196 -0
- package/dist/edge/p2p/crypto/KeyManager.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/KeyManager.js +576 -0
- package/dist/edge/p2p/crypto/KeyManager.js.map +1 -0
- package/dist/edge/p2p/crypto/Signer.d.ts +164 -0
- package/dist/edge/p2p/crypto/Signer.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/Signer.js +357 -0
- package/dist/edge/p2p/crypto/Signer.js.map +1 -0
- package/dist/edge/p2p/crypto/index.d.ts +90 -0
- package/dist/edge/p2p/crypto/index.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/index.js +158 -0
- package/dist/edge/p2p/crypto/index.js.map +1 -0
- package/dist/edge/p2p/crypto/types.d.ts +217 -0
- package/dist/edge/p2p/crypto/types.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/types.js +42 -0
- package/dist/edge/p2p/crypto/types.js.map +1 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.d.ts +270 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.d.ts.map +1 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.js +824 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.js.map +1 -0
- package/dist/edge/p2p/federated/FederatedRound.d.ts +295 -0
- package/dist/edge/p2p/federated/FederatedRound.d.ts.map +1 -0
- package/dist/edge/p2p/federated/FederatedRound.js +819 -0
- package/dist/edge/p2p/federated/FederatedRound.js.map +1 -0
- package/dist/edge/p2p/federated/GradientAggregator.d.ts +226 -0
- package/dist/edge/p2p/federated/GradientAggregator.d.ts.map +1 -0
- package/dist/edge/p2p/federated/GradientAggregator.js +826 -0
- package/dist/edge/p2p/federated/GradientAggregator.js.map +1 -0
- package/dist/edge/p2p/federated/ModelManager.d.ts +248 -0
- package/dist/edge/p2p/federated/ModelManager.d.ts.map +1 -0
- package/dist/edge/p2p/federated/ModelManager.js +724 -0
- package/dist/edge/p2p/federated/ModelManager.js.map +1 -0
- package/dist/edge/p2p/federated/index.d.ts +65 -0
- package/dist/edge/p2p/federated/index.d.ts.map +1 -0
- package/dist/edge/p2p/federated/index.js +110 -0
- package/dist/edge/p2p/federated/index.js.map +1 -0
- package/dist/edge/p2p/federated/types.d.ts +905 -0
- package/dist/edge/p2p/federated/types.d.ts.map +1 -0
- package/dist/edge/p2p/federated/types.js +339 -0
- package/dist/edge/p2p/federated/types.js.map +1 -0
- package/dist/edge/p2p/index.d.ts +156 -0
- package/dist/edge/p2p/index.d.ts.map +1 -0
- package/dist/edge/p2p/index.js +242 -0
- package/dist/edge/p2p/index.js.map +1 -0
- package/dist/edge/p2p/nat/ConnectivityTester.d.ts +128 -0
- package/dist/edge/p2p/nat/ConnectivityTester.d.ts.map +1 -0
- package/dist/edge/p2p/nat/ConnectivityTester.js +560 -0
- package/dist/edge/p2p/nat/ConnectivityTester.js.map +1 -0
- package/dist/edge/p2p/nat/HolePuncher.d.ts +159 -0
- package/dist/edge/p2p/nat/HolePuncher.d.ts.map +1 -0
- package/dist/edge/p2p/nat/HolePuncher.js +569 -0
- package/dist/edge/p2p/nat/HolePuncher.js.map +1 -0
- package/dist/edge/p2p/nat/NATDetector.d.ts +109 -0
- package/dist/edge/p2p/nat/NATDetector.d.ts.map +1 -0
- package/dist/edge/p2p/nat/NATDetector.js +472 -0
- package/dist/edge/p2p/nat/NATDetector.js.map +1 -0
- package/dist/edge/p2p/nat/TURNManager.d.ts +158 -0
- package/dist/edge/p2p/nat/TURNManager.d.ts.map +1 -0
- package/dist/edge/p2p/nat/TURNManager.js +547 -0
- package/dist/edge/p2p/nat/TURNManager.js.map +1 -0
- package/dist/edge/p2p/nat/index.d.ts +74 -0
- package/dist/edge/p2p/nat/index.d.ts.map +1 -0
- package/dist/edge/p2p/nat/index.js +104 -0
- package/dist/edge/p2p/nat/index.js.map +1 -0
- package/dist/edge/p2p/nat/types.d.ts +583 -0
- package/dist/edge/p2p/nat/types.d.ts.map +1 -0
- package/dist/edge/p2p/nat/types.js +267 -0
- package/dist/edge/p2p/nat/types.js.map +1 -0
- package/dist/edge/p2p/protocol/AgentChannel.d.ts +333 -0
- package/dist/edge/p2p/protocol/AgentChannel.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/AgentChannel.js +914 -0
- package/dist/edge/p2p/protocol/AgentChannel.js.map +1 -0
- package/dist/edge/p2p/protocol/MessageEncoder.d.ts +147 -0
- package/dist/edge/p2p/protocol/MessageEncoder.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/MessageEncoder.js +738 -0
- package/dist/edge/p2p/protocol/MessageEncoder.js.map +1 -0
- package/dist/edge/p2p/protocol/MessageRouter.d.ts +266 -0
- package/dist/edge/p2p/protocol/MessageRouter.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/MessageRouter.js +808 -0
- package/dist/edge/p2p/protocol/MessageRouter.js.map +1 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.d.ts +309 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.js +930 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.js.map +1 -0
- package/dist/edge/p2p/protocol/index.d.ts +114 -0
- package/dist/edge/p2p/protocol/index.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/index.js +206 -0
- package/dist/edge/p2p/protocol/index.js.map +1 -0
- package/dist/edge/p2p/protocol/types.d.ts +737 -0
- package/dist/edge/p2p/protocol/types.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/types.js +490 -0
- package/dist/edge/p2p/protocol/types.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts +284 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.js +644 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternIndex.d.ts +168 -0
- package/dist/edge/p2p/sharing/PatternIndex.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternIndex.js +781 -0
- package/dist/edge/p2p/sharing/PatternIndex.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternSerializer.d.ts +163 -0
- package/dist/edge/p2p/sharing/PatternSerializer.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternSerializer.js +696 -0
- package/dist/edge/p2p/sharing/PatternSerializer.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.d.ts +242 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.js +859 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.js.map +1 -0
- package/dist/edge/p2p/sharing/index.d.ts +90 -0
- package/dist/edge/p2p/sharing/index.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/index.js +152 -0
- package/dist/edge/p2p/sharing/index.js.map +1 -0
- package/dist/edge/p2p/sharing/types.d.ts +796 -0
- package/dist/edge/p2p/sharing/types.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/types.js +264 -0
- package/dist/edge/p2p/sharing/types.js.map +1 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.d.ts +218 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.js +562 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.js.map +1 -0
- package/dist/edge/p2p/webrtc/ICEManager.d.ts +171 -0
- package/dist/edge/p2p/webrtc/ICEManager.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/ICEManager.js +490 -0
- package/dist/edge/p2p/webrtc/ICEManager.js.map +1 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts +159 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.js +735 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.js.map +1 -0
- package/dist/edge/p2p/webrtc/SignalingClient.d.ts +191 -0
- package/dist/edge/p2p/webrtc/SignalingClient.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/SignalingClient.js +608 -0
- package/dist/edge/p2p/webrtc/SignalingClient.js.map +1 -0
- package/dist/edge/p2p/webrtc/index.d.ts +158 -0
- package/dist/edge/p2p/webrtc/index.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/index.js +164 -0
- package/dist/edge/p2p/webrtc/index.js.map +1 -0
- package/dist/edge/p2p/webrtc/types.d.ts +665 -0
- package/dist/edge/p2p/webrtc/types.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/types.js +245 -0
- package/dist/edge/p2p/webrtc/types.js.map +1 -0
- package/dist/edge/server/AgentSpawnAPI.d.ts +98 -0
- package/dist/edge/server/AgentSpawnAPI.d.ts.map +1 -0
- package/dist/edge/server/AgentSpawnAPI.js +264 -0
- package/dist/edge/server/AgentSpawnAPI.js.map +1 -0
- package/dist/edge/server/SignalingServer.d.ts +71 -0
- package/dist/edge/server/SignalingServer.d.ts.map +1 -0
- package/dist/edge/server/SignalingServer.js +429 -0
- package/dist/edge/server/SignalingServer.js.map +1 -0
- package/dist/edge/server/index.d.ts +64 -0
- package/dist/edge/server/index.d.ts.map +1 -0
- package/dist/edge/server/index.js +318 -0
- package/dist/edge/server/index.js.map +1 -0
- package/dist/edge/types/browser-agent.types.d.ts +455 -0
- package/dist/edge/types/browser-agent.types.d.ts.map +1 -0
- package/dist/edge/types/browser-agent.types.js +116 -0
- package/dist/edge/types/browser-agent.types.js.map +1 -0
- package/dist/edge/types/index.d.ts +11 -0
- package/dist/edge/types/index.d.ts.map +1 -0
- package/dist/edge/types/index.js +17 -0
- package/dist/edge/types/index.js.map +1 -0
- package/dist/edge/types/storage.types.d.ts +207 -0
- package/dist/edge/types/storage.types.d.ts.map +1 -0
- package/dist/edge/types/storage.types.js +47 -0
- package/dist/edge/types/storage.types.js.map +1 -0
- package/dist/edge/wasm/shims.d.ts +224 -0
- package/dist/edge/wasm/shims.d.ts.map +1 -0
- package/dist/edge/wasm/shims.js +667 -0
- package/dist/edge/wasm/shims.js.map +1 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.d.ts +33 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.d.ts.map +1 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.js +305 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.js.map +1 -0
- package/dist/mcp/handlers/filtered/index.d.ts +15 -19
- package/dist/mcp/handlers/filtered/index.d.ts.map +1 -1
- package/dist/mcp/handlers/filtered/index.js +16 -27
- package/dist/mcp/handlers/filtered/index.js.map +1 -1
- package/dist/mcp/handlers/integration/index.d.ts +5 -4
- package/dist/mcp/handlers/integration/index.d.ts.map +1 -1
- package/dist/mcp/handlers/integration/index.js +7 -7
- package/dist/mcp/handlers/integration/index.js.map +1 -1
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.js +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +14 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +8 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +412 -1
- package/dist/mcp/tools.js.map +1 -1
- package/dist/planning/GOAPPlanner.d.ts +1 -0
- package/dist/planning/GOAPPlanner.d.ts.map +1 -1
- package/dist/planning/GOAPPlanner.js +12 -0
- package/dist/planning/GOAPPlanner.js.map +1 -1
- package/package.json +29 -8
- package/dist/alerting/AlertManager.d.ts +0 -120
- package/dist/alerting/AlertManager.d.ts.map +0 -1
- package/dist/alerting/AlertManager.js +0 -345
- package/dist/alerting/AlertManager.js.map +0 -1
- package/dist/alerting/FeedbackRouter.d.ts +0 -98
- package/dist/alerting/FeedbackRouter.d.ts.map +0 -1
- package/dist/alerting/FeedbackRouter.js +0 -331
- package/dist/alerting/FeedbackRouter.js.map +0 -1
- package/dist/alerting/StrategyApplicator.d.ts +0 -120
- package/dist/alerting/StrategyApplicator.d.ts.map +0 -1
- package/dist/alerting/StrategyApplicator.js +0 -299
- package/dist/alerting/StrategyApplicator.js.map +0 -1
- package/dist/alerting/index.d.ts +0 -68
- package/dist/alerting/index.d.ts.map +0 -1
- package/dist/alerting/index.js +0 -112
- package/dist/alerting/index.js.map +0 -1
- package/dist/alerting/types.d.ts +0 -118
- package/dist/alerting/types.d.ts.map +0 -1
- package/dist/alerting/types.js +0 -11
- package/dist/alerting/types.js.map +0 -1
- package/dist/cli/commands/fleet/backup.d.ts +0 -49
- package/dist/cli/commands/fleet/backup.d.ts.map +0 -1
- package/dist/cli/commands/fleet/backup.js +0 -88
- package/dist/cli/commands/fleet/backup.js.map +0 -1
- package/dist/cli/commands/fleet/health.d.ts +0 -154
- package/dist/cli/commands/fleet/health.d.ts.map +0 -1
- package/dist/cli/commands/fleet/health.js +0 -483
- package/dist/cli/commands/fleet/health.js.map +0 -1
- package/dist/cli/commands/fleet/init.d.ts +0 -11
- package/dist/cli/commands/fleet/init.d.ts.map +0 -1
- package/dist/cli/commands/fleet/init.js +0 -91
- package/dist/cli/commands/fleet/init.js.map +0 -1
- package/dist/cli/commands/fleet/logs.d.ts +0 -21
- package/dist/cli/commands/fleet/logs.d.ts.map +0 -1
- package/dist/cli/commands/fleet/logs.js +0 -267
- package/dist/cli/commands/fleet/logs.js.map +0 -1
- package/dist/cli/commands/fleet/metrics.d.ts +0 -27
- package/dist/cli/commands/fleet/metrics.d.ts.map +0 -1
- package/dist/cli/commands/fleet/metrics.js +0 -369
- package/dist/cli/commands/fleet/metrics.js.map +0 -1
- package/dist/cli/commands/fleet/monitor.d.ts +0 -18
- package/dist/cli/commands/fleet/monitor.d.ts.map +0 -1
- package/dist/cli/commands/fleet/monitor.js +0 -237
- package/dist/cli/commands/fleet/monitor.js.map +0 -1
- package/dist/cli/commands/fleet/optimize.d.ts +0 -42
- package/dist/cli/commands/fleet/optimize.d.ts.map +0 -1
- package/dist/cli/commands/fleet/optimize.js +0 -135
- package/dist/cli/commands/fleet/optimize.js.map +0 -1
- package/dist/cli/commands/fleet/recover.d.ts +0 -22
- package/dist/cli/commands/fleet/recover.d.ts.map +0 -1
- package/dist/cli/commands/fleet/recover.js +0 -99
- package/dist/cli/commands/fleet/recover.js.map +0 -1
- package/dist/cli/commands/fleet/restart.d.ts +0 -18
- package/dist/cli/commands/fleet/restart.d.ts.map +0 -1
- package/dist/cli/commands/fleet/restart.js +0 -290
- package/dist/cli/commands/fleet/restart.js.map +0 -1
- package/dist/cli/commands/fleet/scale.d.ts +0 -9
- package/dist/cli/commands/fleet/scale.d.ts.map +0 -1
- package/dist/cli/commands/fleet/scale.js +0 -77
- package/dist/cli/commands/fleet/scale.js.map +0 -1
- package/dist/cli/commands/fleet/shutdown.d.ts +0 -19
- package/dist/cli/commands/fleet/shutdown.d.ts.map +0 -1
- package/dist/cli/commands/fleet/shutdown.js +0 -307
- package/dist/cli/commands/fleet/shutdown.js.map +0 -1
- package/dist/cli/commands/fleet/status.d.ts +0 -10
- package/dist/cli/commands/fleet/status.d.ts.map +0 -1
- package/dist/cli/commands/fleet/status.js +0 -97
- package/dist/cli/commands/fleet/status.js.map +0 -1
- package/dist/cli/commands/fleet/topology.d.ts +0 -23
- package/dist/cli/commands/fleet/topology.d.ts.map +0 -1
- package/dist/cli/commands/fleet/topology.js +0 -376
- package/dist/cli/commands/fleet/topology.js.map +0 -1
- package/dist/cli/commands/monitor/alerts.d.ts +0 -45
- package/dist/cli/commands/monitor/alerts.d.ts.map +0 -1
- package/dist/cli/commands/monitor/alerts.js +0 -168
- package/dist/cli/commands/monitor/alerts.js.map +0 -1
- package/dist/cli/commands/monitor/analyze.d.ts +0 -49
- package/dist/cli/commands/monitor/analyze.d.ts.map +0 -1
- package/dist/cli/commands/monitor/analyze.js +0 -209
- package/dist/cli/commands/monitor/analyze.js.map +0 -1
- package/dist/cli/commands/monitor/compare.d.ts +0 -38
- package/dist/cli/commands/monitor/compare.d.ts.map +0 -1
- package/dist/cli/commands/monitor/compare.js +0 -177
- package/dist/cli/commands/monitor/compare.js.map +0 -1
- package/dist/cli/commands/monitor/dashboard.d.ts +0 -34
- package/dist/cli/commands/monitor/dashboard.d.ts.map +0 -1
- package/dist/cli/commands/monitor/dashboard.js +0 -157
- package/dist/cli/commands/monitor/dashboard.js.map +0 -1
- package/dist/cli/commands/monitor/export.d.ts +0 -36
- package/dist/cli/commands/monitor/export.d.ts.map +0 -1
- package/dist/cli/commands/monitor/export.js +0 -157
- package/dist/cli/commands/monitor/export.js.map +0 -1
- package/dist/cli/commands/monitor/index.d.ts +0 -11
- package/dist/cli/commands/monitor/index.d.ts.map +0 -1
- package/dist/cli/commands/monitor/index.js +0 -14
- package/dist/cli/commands/monitor/index.js.map +0 -1
- package/dist/cli/commands/quality/baseline.d.ts +0 -27
- package/dist/cli/commands/quality/baseline.d.ts.map +0 -1
- package/dist/cli/commands/quality/baseline.js +0 -124
- package/dist/cli/commands/quality/baseline.js.map +0 -1
- package/dist/cli/commands/quality/compare.d.ts +0 -36
- package/dist/cli/commands/quality/compare.d.ts.map +0 -1
- package/dist/cli/commands/quality/compare.js +0 -136
- package/dist/cli/commands/quality/compare.js.map +0 -1
- package/dist/cli/commands/quality/decision.d.ts +0 -81
- package/dist/cli/commands/quality/decision.d.ts.map +0 -1
- package/dist/cli/commands/quality/decision.js +0 -319
- package/dist/cli/commands/quality/decision.js.map +0 -1
- package/dist/cli/commands/quality/gate.d.ts +0 -47
- package/dist/cli/commands/quality/gate.d.ts.map +0 -1
- package/dist/cli/commands/quality/gate.js +0 -205
- package/dist/cli/commands/quality/gate.js.map +0 -1
- package/dist/cli/commands/quality/index.d.ts +0 -17
- package/dist/cli/commands/quality/index.d.ts.map +0 -1
- package/dist/cli/commands/quality/index.js +0 -41
- package/dist/cli/commands/quality/index.js.map +0 -1
- package/dist/cli/commands/quality/policy.d.ts +0 -57
- package/dist/cli/commands/quality/policy.d.ts.map +0 -1
- package/dist/cli/commands/quality/policy.js +0 -359
- package/dist/cli/commands/quality/policy.js.map +0 -1
- package/dist/cli/commands/quality/risk.d.ts +0 -41
- package/dist/cli/commands/quality/risk.d.ts.map +0 -1
- package/dist/cli/commands/quality/risk.js +0 -255
- package/dist/cli/commands/quality/risk.js.map +0 -1
- package/dist/cli/commands/quality/trends.d.ts +0 -40
- package/dist/cli/commands/quality/trends.d.ts.map +0 -1
- package/dist/cli/commands/quality/trends.js +0 -122
- package/dist/cli/commands/quality/trends.js.map +0 -1
- package/dist/cli/commands/quality/validate.d.ts +0 -44
- package/dist/cli/commands/quality/validate.d.ts.map +0 -1
- package/dist/cli/commands/quality/validate.js +0 -234
- package/dist/cli/commands/quality/validate.js.map +0 -1
- package/dist/cli/commands/test/analyze-failures.d.ts +0 -39
- package/dist/cli/commands/test/analyze-failures.d.ts.map +0 -1
- package/dist/cli/commands/test/analyze-failures.js +0 -113
- package/dist/cli/commands/test/analyze-failures.js.map +0 -1
- package/dist/cli/commands/test/clean.d.ts +0 -3
- package/dist/cli/commands/test/clean.d.ts.map +0 -1
- package/dist/cli/commands/test/clean.js +0 -148
- package/dist/cli/commands/test/clean.js.map +0 -1
- package/dist/cli/commands/test/debug.d.ts +0 -3
- package/dist/cli/commands/test/debug.d.ts.map +0 -1
- package/dist/cli/commands/test/debug.js +0 -167
- package/dist/cli/commands/test/debug.js.map +0 -1
- package/dist/cli/commands/test/diff.d.ts +0 -3
- package/dist/cli/commands/test/diff.d.ts.map +0 -1
- package/dist/cli/commands/test/diff.js +0 -195
- package/dist/cli/commands/test/diff.js.map +0 -1
- package/dist/cli/commands/test/flakiness.d.ts +0 -32
- package/dist/cli/commands/test/flakiness.d.ts.map +0 -1
- package/dist/cli/commands/test/flakiness.js +0 -121
- package/dist/cli/commands/test/flakiness.js.map +0 -1
- package/dist/cli/commands/test/index.d.ts +0 -17
- package/dist/cli/commands/test/index.d.ts.map +0 -1
- package/dist/cli/commands/test/index.js +0 -45
- package/dist/cli/commands/test/index.js.map +0 -1
- package/dist/cli/commands/test/mutate.d.ts +0 -29
- package/dist/cli/commands/test/mutate.d.ts.map +0 -1
- package/dist/cli/commands/test/mutate.js +0 -163
- package/dist/cli/commands/test/mutate.js.map +0 -1
- package/dist/cli/commands/test/parallel.d.ts +0 -3
- package/dist/cli/commands/test/parallel.d.ts.map +0 -1
- package/dist/cli/commands/test/parallel.js +0 -117
- package/dist/cli/commands/test/parallel.js.map +0 -1
- package/dist/cli/commands/test/profile.d.ts +0 -3
- package/dist/cli/commands/test/profile.d.ts.map +0 -1
- package/dist/cli/commands/test/profile.js +0 -156
- package/dist/cli/commands/test/profile.js.map +0 -1
- package/dist/cli/commands/test/queue.d.ts +0 -3
- package/dist/cli/commands/test/queue.d.ts.map +0 -1
- package/dist/cli/commands/test/queue.js +0 -140
- package/dist/cli/commands/test/queue.js.map +0 -1
- package/dist/cli/commands/test/retry.d.ts +0 -3
- package/dist/cli/commands/test/retry.d.ts.map +0 -1
- package/dist/cli/commands/test/retry.js +0 -105
- package/dist/cli/commands/test/retry.js.map +0 -1
- package/dist/cli/commands/test/snapshot.d.ts +0 -3
- package/dist/cli/commands/test/snapshot.d.ts.map +0 -1
- package/dist/cli/commands/test/snapshot.js +0 -176
- package/dist/cli/commands/test/snapshot.js.map +0 -1
- package/dist/cli/commands/test/trace.d.ts +0 -3
- package/dist/cli/commands/test/trace.d.ts.map +0 -1
- package/dist/cli/commands/test/trace.js +0 -137
- package/dist/cli/commands/test/trace.js.map +0 -1
- package/dist/cli/commands/test/watch.d.ts +0 -3
- package/dist/cli/commands/test/watch.d.ts.map +0 -1
- package/dist/cli/commands/test/watch.js +0 -130
- package/dist/cli/commands/test/watch.js.map +0 -1
- package/dist/cli/index-spec.d.ts +0 -3
- package/dist/cli/index-spec.d.ts.map +0 -1
- package/dist/cli/index-spec.js +0 -154
- package/dist/cli/index-spec.js.map +0 -1
- package/dist/cli/index-working.d.ts +0 -7
- package/dist/cli/index-working.d.ts.map +0 -1
- package/dist/cli/index-working.js +0 -617
- package/dist/cli/index-working.js.map +0 -1
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts +0 -83
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js +0 -130
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js.map +0 -1
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts +0 -58
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js +0 -84
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js.map +0 -1
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts +0 -54
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js +0 -73
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js.map +0 -1
- package/dist/mcp/handlers/integration/contract-validate.d.ts +0 -10
- package/dist/mcp/handlers/integration/contract-validate.d.ts.map +0 -1
- package/dist/mcp/handlers/integration/contract-validate.js +0 -348
- package/dist/mcp/handlers/integration/contract-validate.js.map +0 -1
- package/dist/reporting/ResultAggregator.d.ts +0 -107
- package/dist/reporting/ResultAggregator.d.ts.map +0 -1
- package/dist/reporting/ResultAggregator.js +0 -435
- package/dist/reporting/ResultAggregator.js.map +0 -1
- package/dist/reporting/index.d.ts +0 -48
- package/dist/reporting/index.d.ts.map +0 -1
- package/dist/reporting/index.js +0 -154
- package/dist/reporting/index.js.map +0 -1
- package/dist/reporting/reporters/ControlLoopReporter.d.ts +0 -128
- package/dist/reporting/reporters/ControlLoopReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/ControlLoopReporter.js +0 -417
- package/dist/reporting/reporters/ControlLoopReporter.js.map +0 -1
- package/dist/reporting/reporters/HumanReadableReporter.d.ts +0 -140
- package/dist/reporting/reporters/HumanReadableReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/HumanReadableReporter.js +0 -524
- package/dist/reporting/reporters/HumanReadableReporter.js.map +0 -1
- package/dist/reporting/reporters/JSONReporter.d.ts +0 -251
- package/dist/reporting/reporters/JSONReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/JSONReporter.js +0 -325
- package/dist/reporting/reporters/JSONReporter.js.map +0 -1
- package/dist/reporting/reporters/index.d.ts +0 -14
- package/dist/reporting/reporters/index.d.ts.map +0 -1
- package/dist/reporting/reporters/index.js +0 -19
- package/dist/reporting/reporters/index.js.map +0 -1
- package/dist/reporting/types.d.ts +0 -427
- package/dist/reporting/types.d.ts.map +0 -1
- package/dist/reporting/types.js +0 -12
- package/dist/reporting/types.js.map +0 -1
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Channel for High-Level Agent-to-Agent Communication
|
|
4
|
+
*
|
|
5
|
+
* Provides a high-level API for agent-to-agent communication including
|
|
6
|
+
* request/response patterns with correlation IDs, event subscription/publication,
|
|
7
|
+
* typed message handlers, channel lifecycle management, and metrics collection.
|
|
8
|
+
*
|
|
9
|
+
* @module edge/p2p/protocol/AgentChannel
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AgentChannel = exports.ChannelEventType = void 0;
|
|
14
|
+
exports.createAgentChannel = createAgentChannel;
|
|
15
|
+
exports.createAgentChannels = createAgentChannels;
|
|
16
|
+
const types_1 = require("./types");
|
|
17
|
+
const MessageEncoder_1 = require("./MessageEncoder");
|
|
18
|
+
const MessageRouter_1 = require("./MessageRouter");
|
|
19
|
+
const ProtocolHandler_1 = require("./ProtocolHandler");
|
|
20
|
+
/**
|
|
21
|
+
* Channel event types
|
|
22
|
+
*/
|
|
23
|
+
var ChannelEventType;
|
|
24
|
+
(function (ChannelEventType) {
|
|
25
|
+
ChannelEventType["OPENED"] = "opened";
|
|
26
|
+
ChannelEventType["CLOSED"] = "closed";
|
|
27
|
+
ChannelEventType["ERROR"] = "error";
|
|
28
|
+
ChannelEventType["RECONNECTING"] = "reconnecting";
|
|
29
|
+
ChannelEventType["RECONNECTED"] = "reconnected";
|
|
30
|
+
ChannelEventType["MESSAGE_RECEIVED"] = "message_received";
|
|
31
|
+
ChannelEventType["MESSAGE_SENT"] = "message_sent";
|
|
32
|
+
ChannelEventType["STATE_CHANGED"] = "state_changed";
|
|
33
|
+
})(ChannelEventType || (exports.ChannelEventType = ChannelEventType = {}));
|
|
34
|
+
// ============================================
|
|
35
|
+
// AgentChannel Class
|
|
36
|
+
// ============================================
|
|
37
|
+
/**
|
|
38
|
+
* High-level agent-to-agent communication channel
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const channel = new AgentChannel({
|
|
43
|
+
* localIdentity: myIdentity,
|
|
44
|
+
* localKeyPair: myKeyPair,
|
|
45
|
+
* remoteAgentId: 'remote-agent-id',
|
|
46
|
+
* connectionManager: peerManager,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Open channel
|
|
50
|
+
* await channel.open();
|
|
51
|
+
*
|
|
52
|
+
* // Register request handler
|
|
53
|
+
* channel.onRequest('get-data', async (params) => {
|
|
54
|
+
* return { data: 'response' };
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Send request
|
|
58
|
+
* const result = await channel.request('process-task', { taskId: '123' });
|
|
59
|
+
*
|
|
60
|
+
* // Subscribe to events
|
|
61
|
+
* channel.subscribe('task-completed', (data) => {
|
|
62
|
+
* console.log('Task completed:', data);
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Publish event
|
|
66
|
+
* await channel.publish('status-update', { status: 'active' });
|
|
67
|
+
*
|
|
68
|
+
* // Close channel
|
|
69
|
+
* await channel.close();
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
class AgentChannel {
|
|
73
|
+
constructor(options) {
|
|
74
|
+
// State
|
|
75
|
+
this.isOpen = false;
|
|
76
|
+
this.isClosing = false;
|
|
77
|
+
this.reconnectAttempts = 0;
|
|
78
|
+
this.openedAt = null;
|
|
79
|
+
// Request/Response tracking
|
|
80
|
+
this.pendingRequests = new Map();
|
|
81
|
+
this.requestHandlers = new Map();
|
|
82
|
+
// Event subscriptions
|
|
83
|
+
this.eventSubscriptions = [];
|
|
84
|
+
// Event handlers
|
|
85
|
+
this.channelEventHandlers = [];
|
|
86
|
+
this.errorHandlers = [];
|
|
87
|
+
this.stateChangeHandlers = [];
|
|
88
|
+
// Reconnection
|
|
89
|
+
this.reconnectTimer = null;
|
|
90
|
+
this.localIdentity = options.localIdentity;
|
|
91
|
+
this.localKeyPair = options.localKeyPair;
|
|
92
|
+
this.remoteAgentId = options.remoteAgentId;
|
|
93
|
+
this.connectionManager = options.connectionManager;
|
|
94
|
+
this.config = {
|
|
95
|
+
localAgentId: options.localIdentity.agentId,
|
|
96
|
+
remoteAgentId: options.remoteAgentId,
|
|
97
|
+
protocolVersion: options.config?.protocolVersion,
|
|
98
|
+
features: options.config?.features ?? [
|
|
99
|
+
types_1.ProtocolFeature.COMPRESSION,
|
|
100
|
+
types_1.ProtocolFeature.REQUEST_RESPONSE,
|
|
101
|
+
types_1.ProtocolFeature.PUB_SUB,
|
|
102
|
+
types_1.ProtocolFeature.RELIABLE_DELIVERY,
|
|
103
|
+
],
|
|
104
|
+
rateLimit: options.config?.rateLimit,
|
|
105
|
+
queue: options.config?.queue,
|
|
106
|
+
requestTimeout: options.config?.requestTimeout ?? types_1.DEFAULT_REQUEST_TIMEOUT,
|
|
107
|
+
heartbeatInterval: options.config?.heartbeatInterval,
|
|
108
|
+
autoReconnect: options.config?.autoReconnect ?? true,
|
|
109
|
+
maxReconnectAttempts: options.config?.maxReconnectAttempts ?? 5,
|
|
110
|
+
};
|
|
111
|
+
// Initialize protocol handler
|
|
112
|
+
this.protocolHandler = new ProtocolHandler_1.ProtocolHandler({
|
|
113
|
+
identity: this.localIdentity,
|
|
114
|
+
keyPair: this.localKeyPair,
|
|
115
|
+
features: this.config.features,
|
|
116
|
+
heartbeatInterval: this.config.heartbeatInterval,
|
|
117
|
+
rateLimit: this.config.rateLimit,
|
|
118
|
+
});
|
|
119
|
+
// Initialize encoder
|
|
120
|
+
this.encoder = new MessageEncoder_1.MessageEncoder();
|
|
121
|
+
// Initialize router
|
|
122
|
+
this.router = new MessageRouter_1.MessageRouter({
|
|
123
|
+
queue: this.config.queue,
|
|
124
|
+
enableRetry: true,
|
|
125
|
+
enableDeadLetter: true,
|
|
126
|
+
});
|
|
127
|
+
// Initialize stats
|
|
128
|
+
this.stats = this.createInitialStats();
|
|
129
|
+
// Setup event forwarding
|
|
130
|
+
this.setupEventForwarding();
|
|
131
|
+
}
|
|
132
|
+
// ============================================
|
|
133
|
+
// Lifecycle
|
|
134
|
+
// ============================================
|
|
135
|
+
/**
|
|
136
|
+
* Open the channel and establish connection
|
|
137
|
+
*/
|
|
138
|
+
async open() {
|
|
139
|
+
if (this.isOpen) {
|
|
140
|
+
throw new types_1.ProtocolError('Channel already open', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
141
|
+
}
|
|
142
|
+
if (this.isClosing) {
|
|
143
|
+
throw new types_1.ProtocolError('Channel is closing', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
// Register with router
|
|
147
|
+
this.registerWithRouter();
|
|
148
|
+
// Create handshake
|
|
149
|
+
const handshakeEnvelope = await this.protocolHandler.createHandshake();
|
|
150
|
+
// Encode and send handshake
|
|
151
|
+
await this.sendEnvelope(handshakeEnvelope);
|
|
152
|
+
// Wait for handshake acknowledgment (handled in message processing)
|
|
153
|
+
// For now, mark as open after handshake is sent
|
|
154
|
+
// In production, this should wait for HANDSHAKE_ACK
|
|
155
|
+
this.isOpen = true;
|
|
156
|
+
this.openedAt = Date.now();
|
|
157
|
+
this.stats.openedAt = this.openedAt;
|
|
158
|
+
this.emitChannelEvent({
|
|
159
|
+
type: ChannelEventType.OPENED,
|
|
160
|
+
timestamp: Date.now(),
|
|
161
|
+
details: { remoteAgentId: this.remoteAgentId },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
this.handleError(error instanceof types_1.ProtocolError
|
|
166
|
+
? error
|
|
167
|
+
: new types_1.ProtocolError(error instanceof Error ? error.message : 'Failed to open channel', types_1.ProtocolErrorCode.PROTOCOL_ERROR));
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Close the channel gracefully
|
|
173
|
+
*/
|
|
174
|
+
async close(reason = 'Channel closed') {
|
|
175
|
+
if (!this.isOpen || this.isClosing)
|
|
176
|
+
return;
|
|
177
|
+
this.isClosing = true;
|
|
178
|
+
try {
|
|
179
|
+
// Create and send close message
|
|
180
|
+
const closeEnvelope = await this.protocolHandler.createClose(types_1.CloseCode.NORMAL, reason, false);
|
|
181
|
+
await this.sendEnvelope(closeEnvelope);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Ignore send errors during close
|
|
185
|
+
}
|
|
186
|
+
this.cleanup();
|
|
187
|
+
this.isOpen = false;
|
|
188
|
+
this.isClosing = false;
|
|
189
|
+
this.emitChannelEvent({
|
|
190
|
+
type: ChannelEventType.CLOSED,
|
|
191
|
+
timestamp: Date.now(),
|
|
192
|
+
details: { reason },
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if channel is open
|
|
197
|
+
*/
|
|
198
|
+
isChannelOpen() {
|
|
199
|
+
return this.isOpen && !this.isClosing;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get channel state
|
|
203
|
+
*/
|
|
204
|
+
getState() {
|
|
205
|
+
return this.protocolHandler.getState();
|
|
206
|
+
}
|
|
207
|
+
// ============================================
|
|
208
|
+
// Request/Response Pattern
|
|
209
|
+
// ============================================
|
|
210
|
+
/**
|
|
211
|
+
* Send a request and wait for response
|
|
212
|
+
*
|
|
213
|
+
* @param method - Method name to call
|
|
214
|
+
* @param params - Request parameters
|
|
215
|
+
* @param timeout - Optional timeout override
|
|
216
|
+
* @returns Promise resolving to response data
|
|
217
|
+
*/
|
|
218
|
+
async request(method, params, timeout) {
|
|
219
|
+
if (!this.isChannelOpen()) {
|
|
220
|
+
throw new types_1.ProtocolError('Channel not open', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
221
|
+
}
|
|
222
|
+
const correlationId = (0, types_1.generateMessageId)();
|
|
223
|
+
const requestTimeout = timeout ?? this.config.requestTimeout ?? types_1.DEFAULT_REQUEST_TIMEOUT;
|
|
224
|
+
return new Promise((resolve, reject) => {
|
|
225
|
+
// Create timeout
|
|
226
|
+
const timer = setTimeout(() => {
|
|
227
|
+
const pending = this.pendingRequests.get(correlationId);
|
|
228
|
+
if (pending) {
|
|
229
|
+
this.pendingRequests.delete(correlationId);
|
|
230
|
+
reject(new types_1.ProtocolError(`Request timed out: ${method}`, types_1.ProtocolErrorCode.TIMEOUT));
|
|
231
|
+
}
|
|
232
|
+
}, requestTimeout);
|
|
233
|
+
// Track pending request
|
|
234
|
+
const pending = {
|
|
235
|
+
correlationId,
|
|
236
|
+
method,
|
|
237
|
+
sentAt: Date.now(),
|
|
238
|
+
timeout: requestTimeout,
|
|
239
|
+
resolve: resolve,
|
|
240
|
+
reject,
|
|
241
|
+
timer,
|
|
242
|
+
};
|
|
243
|
+
this.pendingRequests.set(correlationId, pending);
|
|
244
|
+
// Send request
|
|
245
|
+
this.sendRequest(method, params, correlationId).catch((error) => {
|
|
246
|
+
this.pendingRequests.delete(correlationId);
|
|
247
|
+
clearTimeout(timer);
|
|
248
|
+
reject(error);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Register a request handler
|
|
254
|
+
*/
|
|
255
|
+
onRequest(method, handler) {
|
|
256
|
+
this.requestHandlers.set(method, handler);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Remove a request handler
|
|
260
|
+
*/
|
|
261
|
+
offRequest(method) {
|
|
262
|
+
this.requestHandlers.delete(method);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Send a request (internal)
|
|
266
|
+
*/
|
|
267
|
+
async sendRequest(method, params, correlationId) {
|
|
268
|
+
const envelope = await this.protocolHandler.createRequest(method, params, this.remoteAgentId, this.config.requestTimeout);
|
|
269
|
+
// Override correlation ID
|
|
270
|
+
envelope.header.correlationId = correlationId;
|
|
271
|
+
await this.sendEnvelope(envelope);
|
|
272
|
+
this.stats.requestsSent++;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Handle incoming request
|
|
276
|
+
*/
|
|
277
|
+
async handleRequest(envelope) {
|
|
278
|
+
const { method, params } = envelope.payload;
|
|
279
|
+
const correlationId = envelope.header.messageId;
|
|
280
|
+
const handler = this.requestHandlers.get(method);
|
|
281
|
+
if (!handler) {
|
|
282
|
+
// Send error response
|
|
283
|
+
const errorEnvelope = await this.protocolHandler.createErrorResponse(correlationId, new types_1.ProtocolError(`Unknown method: ${method}`, types_1.ProtocolErrorCode.INVALID_MESSAGE), envelope.header.senderId);
|
|
284
|
+
await this.sendEnvelope(errorEnvelope);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const result = await handler(params, envelope);
|
|
289
|
+
const responseEnvelope = await this.protocolHandler.createResponse(correlationId, result, envelope.header.senderId);
|
|
290
|
+
await this.sendEnvelope(responseEnvelope);
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
const protocolError = error instanceof types_1.ProtocolError
|
|
294
|
+
? error
|
|
295
|
+
: new types_1.ProtocolError(error instanceof Error ? error.message : 'Request handler failed', types_1.ProtocolErrorCode.PROTOCOL_ERROR);
|
|
296
|
+
const errorEnvelope = await this.protocolHandler.createErrorResponse(correlationId, protocolError, envelope.header.senderId);
|
|
297
|
+
await this.sendEnvelope(errorEnvelope);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Handle incoming response
|
|
302
|
+
*/
|
|
303
|
+
handleResponse(envelope) {
|
|
304
|
+
const correlationId = envelope.header.correlationId;
|
|
305
|
+
if (!correlationId)
|
|
306
|
+
return;
|
|
307
|
+
const pending = this.pendingRequests.get(correlationId);
|
|
308
|
+
if (!pending)
|
|
309
|
+
return;
|
|
310
|
+
this.pendingRequests.delete(correlationId);
|
|
311
|
+
clearTimeout(pending.timer);
|
|
312
|
+
// Update latency stats
|
|
313
|
+
const latency = Date.now() - pending.sentAt;
|
|
314
|
+
this.updateLatencyStats(latency);
|
|
315
|
+
const { success, result, error } = envelope.payload;
|
|
316
|
+
if (success) {
|
|
317
|
+
this.stats.responsesReceived++;
|
|
318
|
+
pending.resolve(result);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
pending.reject(error
|
|
322
|
+
? types_1.ProtocolError.fromInfo(error)
|
|
323
|
+
: new types_1.ProtocolError('Request failed', types_1.ProtocolErrorCode.PROTOCOL_ERROR));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// ============================================
|
|
327
|
+
// Event Pub/Sub Pattern
|
|
328
|
+
// ============================================
|
|
329
|
+
/**
|
|
330
|
+
* Subscribe to an event
|
|
331
|
+
*
|
|
332
|
+
* @param event - Event name to subscribe to
|
|
333
|
+
* @param handler - Event handler function
|
|
334
|
+
*/
|
|
335
|
+
subscribe(event, handler) {
|
|
336
|
+
this.eventSubscriptions.push({
|
|
337
|
+
event,
|
|
338
|
+
handler: handler,
|
|
339
|
+
once: false,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Subscribe to an event (one time)
|
|
344
|
+
*/
|
|
345
|
+
subscribeOnce(event, handler) {
|
|
346
|
+
this.eventSubscriptions.push({
|
|
347
|
+
event,
|
|
348
|
+
handler: handler,
|
|
349
|
+
once: true,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Unsubscribe from an event
|
|
354
|
+
*/
|
|
355
|
+
unsubscribe(event, handler) {
|
|
356
|
+
if (handler) {
|
|
357
|
+
this.eventSubscriptions = this.eventSubscriptions.filter((sub) => !(sub.event === event && sub.handler === handler));
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this.eventSubscriptions = this.eventSubscriptions.filter((sub) => sub.event !== event);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Publish an event
|
|
365
|
+
*/
|
|
366
|
+
async publish(event, data, requiresAck = false) {
|
|
367
|
+
if (!this.isChannelOpen()) {
|
|
368
|
+
throw new types_1.ProtocolError('Channel not open', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
369
|
+
}
|
|
370
|
+
const envelope = await this.protocolHandler.createEvent(event, data, this.remoteAgentId, requiresAck);
|
|
371
|
+
await this.sendEnvelope(envelope);
|
|
372
|
+
this.stats.eventsPublished++;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Broadcast an event to all connected peers
|
|
376
|
+
*/
|
|
377
|
+
async broadcast(event, data) {
|
|
378
|
+
if (!this.isChannelOpen()) {
|
|
379
|
+
throw new types_1.ProtocolError('Channel not open', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
380
|
+
}
|
|
381
|
+
const envelope = await this.protocolHandler.createEvent(event, data, '*', false);
|
|
382
|
+
const encodedData = await this.encoder.encode(envelope);
|
|
383
|
+
await this.router.broadcast(envelope, encodedData);
|
|
384
|
+
this.stats.eventsPublished++;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Handle incoming event
|
|
388
|
+
*/
|
|
389
|
+
handleEvent(envelope) {
|
|
390
|
+
const { event, data, requiresAck } = envelope.payload;
|
|
391
|
+
// Find matching subscriptions
|
|
392
|
+
const matchingSubscriptions = this.eventSubscriptions.filter((sub) => sub.event === event);
|
|
393
|
+
// Remove one-time subscriptions
|
|
394
|
+
this.eventSubscriptions = this.eventSubscriptions.filter((sub) => !(sub.event === event && sub.once));
|
|
395
|
+
// Invoke handlers
|
|
396
|
+
for (const subscription of matchingSubscriptions) {
|
|
397
|
+
try {
|
|
398
|
+
subscription.handler(data, envelope);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
// Emit error but don't stop other handlers
|
|
402
|
+
this.handleError(new types_1.ProtocolError(`Event handler error: ${error instanceof Error ? error.message : 'Unknown'}`, types_1.ProtocolErrorCode.PROTOCOL_ERROR));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
this.stats.eventsReceived++;
|
|
406
|
+
// Send acknowledgment if required
|
|
407
|
+
if (requiresAck) {
|
|
408
|
+
this.sendAck(envelope.header.messageId, envelope.header.senderId).catch(() => {
|
|
409
|
+
// Ignore ack send errors
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// ============================================
|
|
414
|
+
// Message Handling
|
|
415
|
+
// ============================================
|
|
416
|
+
/**
|
|
417
|
+
* Process incoming message data
|
|
418
|
+
*/
|
|
419
|
+
async processIncomingData(data) {
|
|
420
|
+
try {
|
|
421
|
+
// Decode message
|
|
422
|
+
const dataBuffer = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
423
|
+
const envelope = await this.encoder.decode(dataBuffer);
|
|
424
|
+
// Verify message
|
|
425
|
+
const verified = await this.protocolHandler.verifyMessage(envelope);
|
|
426
|
+
if (!verified) {
|
|
427
|
+
throw new types_1.ProtocolError('Message verification failed', types_1.ProtocolErrorCode.INVALID_SIGNATURE);
|
|
428
|
+
}
|
|
429
|
+
// Update stats
|
|
430
|
+
this.stats.messagesReceived++;
|
|
431
|
+
this.stats.bytesReceived += dataBuffer.length;
|
|
432
|
+
this.stats.lastActivityAt = Date.now();
|
|
433
|
+
// Route to appropriate handler
|
|
434
|
+
await this.routeIncomingMessage(envelope);
|
|
435
|
+
this.emitChannelEvent({
|
|
436
|
+
type: ChannelEventType.MESSAGE_RECEIVED,
|
|
437
|
+
timestamp: Date.now(),
|
|
438
|
+
details: {
|
|
439
|
+
type: envelope.header.type,
|
|
440
|
+
messageId: envelope.header.messageId,
|
|
441
|
+
},
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
this.handleError(error instanceof types_1.ProtocolError
|
|
446
|
+
? error
|
|
447
|
+
: new types_1.ProtocolError(`Failed to process message: ${error instanceof Error ? error.message : 'Unknown'}`, types_1.ProtocolErrorCode.DESERIALIZATION_ERROR));
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Route incoming message to handler
|
|
452
|
+
*/
|
|
453
|
+
async routeIncomingMessage(envelope) {
|
|
454
|
+
switch (envelope.header.type) {
|
|
455
|
+
case types_1.MessageType.REQUEST:
|
|
456
|
+
await this.handleRequest(envelope);
|
|
457
|
+
break;
|
|
458
|
+
case types_1.MessageType.RESPONSE:
|
|
459
|
+
this.handleResponse(envelope);
|
|
460
|
+
break;
|
|
461
|
+
case types_1.MessageType.EVENT:
|
|
462
|
+
this.handleEvent(envelope);
|
|
463
|
+
break;
|
|
464
|
+
case types_1.MessageType.HEARTBEAT:
|
|
465
|
+
await this.handleHeartbeat(envelope);
|
|
466
|
+
break;
|
|
467
|
+
case types_1.MessageType.HANDSHAKE:
|
|
468
|
+
await this.handleIncomingHandshake(envelope);
|
|
469
|
+
break;
|
|
470
|
+
case types_1.MessageType.HANDSHAKE_ACK:
|
|
471
|
+
await this.handleHandshakeAck(envelope);
|
|
472
|
+
break;
|
|
473
|
+
case types_1.MessageType.ACK:
|
|
474
|
+
this.handleAck(envelope);
|
|
475
|
+
break;
|
|
476
|
+
case types_1.MessageType.NACK:
|
|
477
|
+
this.handleNack(envelope);
|
|
478
|
+
break;
|
|
479
|
+
case types_1.MessageType.CLOSE:
|
|
480
|
+
this.handleClose(envelope);
|
|
481
|
+
break;
|
|
482
|
+
case types_1.MessageType.ERROR:
|
|
483
|
+
this.handleErrorMessage(envelope);
|
|
484
|
+
break;
|
|
485
|
+
default:
|
|
486
|
+
// Unknown message type
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Handle incoming handshake
|
|
492
|
+
*/
|
|
493
|
+
async handleIncomingHandshake(envelope) {
|
|
494
|
+
const result = await this.protocolHandler.processHandshake(envelope);
|
|
495
|
+
if (result.success) {
|
|
496
|
+
const ackEnvelope = await this.protocolHandler.createHandshakeAck(result);
|
|
497
|
+
await this.sendEnvelope(ackEnvelope);
|
|
498
|
+
this.isOpen = true;
|
|
499
|
+
this.openedAt = Date.now();
|
|
500
|
+
this.stats.openedAt = this.openedAt;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Handle handshake acknowledgment
|
|
505
|
+
*/
|
|
506
|
+
async handleHandshakeAck(envelope) {
|
|
507
|
+
await this.protocolHandler.processHandshakeAck(envelope);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Handle heartbeat
|
|
511
|
+
*/
|
|
512
|
+
async handleHeartbeat(envelope) {
|
|
513
|
+
const response = await this.protocolHandler.processHeartbeat(envelope);
|
|
514
|
+
if (response) {
|
|
515
|
+
await this.sendEnvelope(response);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Handle acknowledgment
|
|
520
|
+
*/
|
|
521
|
+
handleAck(envelope) {
|
|
522
|
+
const payload = envelope.payload;
|
|
523
|
+
this.router.processAck(payload.messageId);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Handle negative acknowledgment
|
|
527
|
+
*/
|
|
528
|
+
handleNack(envelope) {
|
|
529
|
+
const payload = envelope.payload;
|
|
530
|
+
this.router.processNack(payload.messageId, payload.reason, payload.retryable);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Handle close message
|
|
534
|
+
*/
|
|
535
|
+
handleClose(envelope) {
|
|
536
|
+
const payload = this.protocolHandler.processClose(envelope);
|
|
537
|
+
this.cleanup();
|
|
538
|
+
this.isOpen = false;
|
|
539
|
+
if (payload.reconnect && this.config.autoReconnect) {
|
|
540
|
+
this.scheduleReconnect();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Handle error message
|
|
545
|
+
*/
|
|
546
|
+
handleErrorMessage(envelope) {
|
|
547
|
+
const payload = envelope.payload;
|
|
548
|
+
this.handleError(types_1.ProtocolError.fromInfo(payload));
|
|
549
|
+
}
|
|
550
|
+
// ============================================
|
|
551
|
+
// Sending
|
|
552
|
+
// ============================================
|
|
553
|
+
/**
|
|
554
|
+
* Send an envelope over the channel
|
|
555
|
+
*/
|
|
556
|
+
async sendEnvelope(envelope) {
|
|
557
|
+
const encodedData = await this.encoder.encode(envelope);
|
|
558
|
+
// Update stats
|
|
559
|
+
this.stats.messagesSent++;
|
|
560
|
+
this.stats.bytesSent += encodedData.length;
|
|
561
|
+
this.stats.lastActivityAt = Date.now();
|
|
562
|
+
// Route through router for delivery tracking
|
|
563
|
+
await this.router.route(envelope, encodedData);
|
|
564
|
+
this.emitChannelEvent({
|
|
565
|
+
type: ChannelEventType.MESSAGE_SENT,
|
|
566
|
+
timestamp: Date.now(),
|
|
567
|
+
details: {
|
|
568
|
+
type: envelope.header.type,
|
|
569
|
+
messageId: envelope.header.messageId,
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Send acknowledgment
|
|
575
|
+
*/
|
|
576
|
+
async sendAck(messageId, recipientId) {
|
|
577
|
+
const ackEnvelope = await this.protocolHandler.createAck(messageId, recipientId);
|
|
578
|
+
await this.sendEnvelope(ackEnvelope);
|
|
579
|
+
}
|
|
580
|
+
// ============================================
|
|
581
|
+
// Router Integration
|
|
582
|
+
// ============================================
|
|
583
|
+
/**
|
|
584
|
+
* Register this channel with the router
|
|
585
|
+
*/
|
|
586
|
+
registerWithRouter() {
|
|
587
|
+
const peer = {
|
|
588
|
+
peerId: this.remoteAgentId,
|
|
589
|
+
isConnected: true,
|
|
590
|
+
send: async (data) => {
|
|
591
|
+
// Send through WebRTC connection manager if available
|
|
592
|
+
if (this.connectionManager) {
|
|
593
|
+
const dataToSend = typeof data === 'string' ? data : data;
|
|
594
|
+
this.connectionManager.send(this.remoteAgentId, 'reliable', {
|
|
595
|
+
type: 'protocol-message',
|
|
596
|
+
data: typeof dataToSend === 'string' ? dataToSend : Array.from(dataToSend),
|
|
597
|
+
timestamp: Date.now(),
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
this.router.registerPeer(peer);
|
|
603
|
+
}
|
|
604
|
+
// ============================================
|
|
605
|
+
// Error Handling
|
|
606
|
+
// ============================================
|
|
607
|
+
/**
|
|
608
|
+
* Register error handler
|
|
609
|
+
*/
|
|
610
|
+
onError(handler) {
|
|
611
|
+
this.errorHandlers.push(handler);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Remove error handler
|
|
615
|
+
*/
|
|
616
|
+
offError(handler) {
|
|
617
|
+
const index = this.errorHandlers.indexOf(handler);
|
|
618
|
+
if (index !== -1) {
|
|
619
|
+
this.errorHandlers.splice(index, 1);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Handle error
|
|
624
|
+
*/
|
|
625
|
+
handleError(error, envelope) {
|
|
626
|
+
for (const handler of this.errorHandlers) {
|
|
627
|
+
try {
|
|
628
|
+
handler(error, envelope);
|
|
629
|
+
}
|
|
630
|
+
catch {
|
|
631
|
+
// Ignore handler errors
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
this.emitChannelEvent({
|
|
635
|
+
type: ChannelEventType.ERROR,
|
|
636
|
+
timestamp: Date.now(),
|
|
637
|
+
details: { error: error.message, code: error.code },
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
// ============================================
|
|
641
|
+
// State Change Handling
|
|
642
|
+
// ============================================
|
|
643
|
+
/**
|
|
644
|
+
* Register state change handler
|
|
645
|
+
*/
|
|
646
|
+
onStateChange(handler) {
|
|
647
|
+
this.stateChangeHandlers.push(handler);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Remove state change handler
|
|
651
|
+
*/
|
|
652
|
+
offStateChange(handler) {
|
|
653
|
+
const index = this.stateChangeHandlers.indexOf(handler);
|
|
654
|
+
if (index !== -1) {
|
|
655
|
+
this.stateChangeHandlers.splice(index, 1);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
// ============================================
|
|
659
|
+
// Reconnection
|
|
660
|
+
// ============================================
|
|
661
|
+
/**
|
|
662
|
+
* Schedule reconnection attempt
|
|
663
|
+
*/
|
|
664
|
+
scheduleReconnect() {
|
|
665
|
+
if (!this.config.autoReconnect)
|
|
666
|
+
return;
|
|
667
|
+
if (this.reconnectAttempts >= (this.config.maxReconnectAttempts ?? 5))
|
|
668
|
+
return;
|
|
669
|
+
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
|
|
670
|
+
this.reconnectTimer = setTimeout(() => {
|
|
671
|
+
this.attemptReconnect();
|
|
672
|
+
}, delay);
|
|
673
|
+
this.emitChannelEvent({
|
|
674
|
+
type: ChannelEventType.RECONNECTING,
|
|
675
|
+
timestamp: Date.now(),
|
|
676
|
+
details: { attempt: this.reconnectAttempts + 1, delay },
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Attempt to reconnect
|
|
681
|
+
*/
|
|
682
|
+
async attemptReconnect() {
|
|
683
|
+
this.reconnectAttempts++;
|
|
684
|
+
this.stats.reconnectionCount++;
|
|
685
|
+
try {
|
|
686
|
+
this.protocolHandler.reset();
|
|
687
|
+
await this.open();
|
|
688
|
+
this.reconnectAttempts = 0;
|
|
689
|
+
this.emitChannelEvent({
|
|
690
|
+
type: ChannelEventType.RECONNECTED,
|
|
691
|
+
timestamp: Date.now(),
|
|
692
|
+
details: { attempts: this.stats.reconnectionCount },
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
catch {
|
|
696
|
+
if (this.reconnectAttempts < (this.config.maxReconnectAttempts ?? 5)) {
|
|
697
|
+
this.scheduleReconnect();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
// ============================================
|
|
702
|
+
// Statistics
|
|
703
|
+
// ============================================
|
|
704
|
+
/**
|
|
705
|
+
* Get channel statistics
|
|
706
|
+
*/
|
|
707
|
+
getStats() {
|
|
708
|
+
return {
|
|
709
|
+
...this.stats,
|
|
710
|
+
state: this.protocolHandler.getState(),
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Create initial stats object
|
|
715
|
+
*/
|
|
716
|
+
createInitialStats() {
|
|
717
|
+
return {
|
|
718
|
+
messagesSent: 0,
|
|
719
|
+
messagesReceived: 0,
|
|
720
|
+
bytesSent: 0,
|
|
721
|
+
bytesReceived: 0,
|
|
722
|
+
requestsSent: 0,
|
|
723
|
+
responsesReceived: 0,
|
|
724
|
+
eventsPublished: 0,
|
|
725
|
+
eventsReceived: 0,
|
|
726
|
+
averageLatency: 0,
|
|
727
|
+
state: types_1.ProtocolState.IDLE,
|
|
728
|
+
lastActivityAt: 0,
|
|
729
|
+
openedAt: 0,
|
|
730
|
+
reconnectionCount: 0,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Update latency statistics
|
|
735
|
+
*/
|
|
736
|
+
updateLatencyStats(latency) {
|
|
737
|
+
const count = this.stats.responsesReceived;
|
|
738
|
+
this.stats.averageLatency =
|
|
739
|
+
this.stats.averageLatency + (latency - this.stats.averageLatency) / count;
|
|
740
|
+
}
|
|
741
|
+
// ============================================
|
|
742
|
+
// Events
|
|
743
|
+
// ============================================
|
|
744
|
+
/**
|
|
745
|
+
* Add channel event handler
|
|
746
|
+
*/
|
|
747
|
+
on(handler) {
|
|
748
|
+
this.channelEventHandlers.push(handler);
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Remove channel event handler
|
|
752
|
+
*/
|
|
753
|
+
off(handler) {
|
|
754
|
+
const index = this.channelEventHandlers.indexOf(handler);
|
|
755
|
+
if (index !== -1) {
|
|
756
|
+
this.channelEventHandlers.splice(index, 1);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Emit channel event
|
|
761
|
+
*/
|
|
762
|
+
emitChannelEvent(event) {
|
|
763
|
+
for (const handler of this.channelEventHandlers) {
|
|
764
|
+
try {
|
|
765
|
+
handler(event);
|
|
766
|
+
}
|
|
767
|
+
catch {
|
|
768
|
+
// Ignore handler errors
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Setup event forwarding from protocol handler and router
|
|
774
|
+
*/
|
|
775
|
+
setupEventForwarding() {
|
|
776
|
+
// Forward protocol handler events
|
|
777
|
+
this.protocolHandler.on((event) => {
|
|
778
|
+
if (event.type === ProtocolHandler_1.ProtocolEventType.STATE_CHANGED) {
|
|
779
|
+
const transition = event.details;
|
|
780
|
+
for (const handler of this.stateChangeHandlers) {
|
|
781
|
+
try {
|
|
782
|
+
handler(transition);
|
|
783
|
+
}
|
|
784
|
+
catch {
|
|
785
|
+
// Ignore
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
this.emitChannelEvent({
|
|
789
|
+
type: ChannelEventType.STATE_CHANGED,
|
|
790
|
+
timestamp: event.timestamp,
|
|
791
|
+
details: transition,
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
// Forward router events
|
|
796
|
+
this.router.on((event) => {
|
|
797
|
+
if (event.type === MessageRouter_1.RouterEventType.MESSAGE_FAILED) {
|
|
798
|
+
this.emitChannelEvent({
|
|
799
|
+
type: ChannelEventType.ERROR,
|
|
800
|
+
timestamp: event.timestamp,
|
|
801
|
+
details: { messageId: event.messageId, ...(event.details || {}) },
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
// ============================================
|
|
807
|
+
// Cleanup
|
|
808
|
+
// ============================================
|
|
809
|
+
/**
|
|
810
|
+
* Cleanup resources
|
|
811
|
+
*/
|
|
812
|
+
cleanup() {
|
|
813
|
+
// Cancel reconnect timer
|
|
814
|
+
if (this.reconnectTimer) {
|
|
815
|
+
clearTimeout(this.reconnectTimer);
|
|
816
|
+
this.reconnectTimer = null;
|
|
817
|
+
}
|
|
818
|
+
// Reject pending requests
|
|
819
|
+
for (const [, pending] of Array.from(this.pendingRequests.entries())) {
|
|
820
|
+
clearTimeout(pending.timer);
|
|
821
|
+
pending.reject(new types_1.ProtocolError('Channel closed', types_1.ProtocolErrorCode.CONNECTION_CLOSED));
|
|
822
|
+
}
|
|
823
|
+
this.pendingRequests.clear();
|
|
824
|
+
// Clear subscriptions
|
|
825
|
+
this.eventSubscriptions = [];
|
|
826
|
+
// Stop protocol handler
|
|
827
|
+
this.protocolHandler.close();
|
|
828
|
+
// Clear router
|
|
829
|
+
this.router.destroy();
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Destroy the channel and release all resources
|
|
833
|
+
*/
|
|
834
|
+
destroy() {
|
|
835
|
+
this.cleanup();
|
|
836
|
+
this.channelEventHandlers = [];
|
|
837
|
+
this.errorHandlers = [];
|
|
838
|
+
this.stateChangeHandlers = [];
|
|
839
|
+
this.requestHandlers.clear();
|
|
840
|
+
}
|
|
841
|
+
// ============================================
|
|
842
|
+
// Getters
|
|
843
|
+
// ============================================
|
|
844
|
+
/**
|
|
845
|
+
* Get local agent ID
|
|
846
|
+
*/
|
|
847
|
+
getLocalAgentId() {
|
|
848
|
+
return this.localIdentity.agentId;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Get remote agent ID
|
|
852
|
+
*/
|
|
853
|
+
getRemoteAgentId() {
|
|
854
|
+
return this.remoteAgentId;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Get session ID
|
|
858
|
+
*/
|
|
859
|
+
getSessionId() {
|
|
860
|
+
return this.protocolHandler.getSessionId();
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Get agreed features
|
|
864
|
+
*/
|
|
865
|
+
getAgreedFeatures() {
|
|
866
|
+
return this.protocolHandler.getAgreedFeatures();
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Check if a feature is enabled
|
|
870
|
+
*/
|
|
871
|
+
hasFeature(feature) {
|
|
872
|
+
return this.protocolHandler.hasFeature(feature);
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Get heartbeat latency
|
|
876
|
+
*/
|
|
877
|
+
getHeartbeatLatency() {
|
|
878
|
+
return this.protocolHandler.getHeartbeatLatency();
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Get rate limit status
|
|
882
|
+
*/
|
|
883
|
+
getRateLimitStatus() {
|
|
884
|
+
return this.protocolHandler.getRateLimitStatus();
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
exports.AgentChannel = AgentChannel;
|
|
888
|
+
// ============================================
|
|
889
|
+
// Factory Functions
|
|
890
|
+
// ============================================
|
|
891
|
+
/**
|
|
892
|
+
* Create a new agent channel
|
|
893
|
+
*/
|
|
894
|
+
function createAgentChannel(options) {
|
|
895
|
+
return new AgentChannel(options);
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Create multiple channels for an agent
|
|
899
|
+
*/
|
|
900
|
+
function createAgentChannels(localIdentity, localKeyPair, remoteAgentIds, connectionManager, config) {
|
|
901
|
+
const channels = new Map();
|
|
902
|
+
for (const remoteAgentId of remoteAgentIds) {
|
|
903
|
+
const channel = new AgentChannel({
|
|
904
|
+
localIdentity,
|
|
905
|
+
localKeyPair,
|
|
906
|
+
remoteAgentId,
|
|
907
|
+
connectionManager,
|
|
908
|
+
config,
|
|
909
|
+
});
|
|
910
|
+
channels.set(remoteAgentId, channel);
|
|
911
|
+
}
|
|
912
|
+
return channels;
|
|
913
|
+
}
|
|
914
|
+
//# sourceMappingURL=AgentChannel.js.map
|