agentic-qe 2.7.3 → 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 +130 -0
- package/README.md +67 -2
- package/dist/agents/AccessibilityAllyAgent.d.ts +0 -7
- package/dist/agents/AccessibilityAllyAgent.d.ts.map +1 -1
- package/dist/agents/AccessibilityAllyAgent.js +0 -15
- package/dist/agents/AccessibilityAllyAgent.js.map +1 -1
- package/dist/agents/ApiContractValidatorAgent.js +4 -4
- package/dist/agents/ApiContractValidatorAgent.js.map +1 -1
- package/dist/agents/BaseAgent.d.ts +2 -0
- package/dist/agents/BaseAgent.d.ts.map +1 -1
- package/dist/agents/BaseAgent.js +43 -41
- package/dist/agents/BaseAgent.js.map +1 -1
- package/dist/agents/CodeComplexityAnalyzerAgent.d.ts +0 -8
- package/dist/agents/CodeComplexityAnalyzerAgent.d.ts.map +1 -1
- package/dist/agents/CodeComplexityAnalyzerAgent.js +0 -15
- package/dist/agents/CodeComplexityAnalyzerAgent.js.map +1 -1
- package/dist/agents/CodeIntelligenceAgent.d.ts +0 -1
- package/dist/agents/CodeIntelligenceAgent.d.ts.map +1 -1
- package/dist/agents/CodeIntelligenceAgent.js +0 -2
- package/dist/agents/CodeIntelligenceAgent.js.map +1 -1
- package/dist/agents/DeploymentReadinessAgent.d.ts.map +1 -1
- package/dist/agents/DeploymentReadinessAgent.js +30 -30
- package/dist/agents/DeploymentReadinessAgent.js.map +1 -1
- package/dist/agents/FlakyTestHunterAgent.d.ts +0 -10
- package/dist/agents/FlakyTestHunterAgent.d.ts.map +1 -1
- package/dist/agents/FlakyTestHunterAgent.js +10 -20
- package/dist/agents/FlakyTestHunterAgent.js.map +1 -1
- package/dist/agents/FleetCommanderAgent.d.ts.map +1 -1
- package/dist/agents/FleetCommanderAgent.js +28 -28
- package/dist/agents/FleetCommanderAgent.js.map +1 -1
- package/dist/agents/LearningAgent.js +1 -1
- package/dist/agents/LearningAgent.js.map +1 -1
- package/dist/agents/PerformanceTesterAgent.d.ts.map +1 -1
- package/dist/agents/PerformanceTesterAgent.js +25 -25
- package/dist/agents/PerformanceTesterAgent.js.map +1 -1
- package/dist/agents/ProductionIntelligenceAgent.d.ts.map +1 -1
- package/dist/agents/ProductionIntelligenceAgent.js +20 -20
- package/dist/agents/ProductionIntelligenceAgent.js.map +1 -1
- package/dist/agents/QXPartnerAgent.d.ts +0 -8
- package/dist/agents/QXPartnerAgent.d.ts.map +1 -1
- package/dist/agents/QXPartnerAgent.js +0 -15
- package/dist/agents/QXPartnerAgent.js.map +1 -1
- package/dist/agents/QualityAnalyzerAgent.d.ts +0 -7
- package/dist/agents/QualityAnalyzerAgent.d.ts.map +1 -1
- package/dist/agents/QualityAnalyzerAgent.js +0 -16
- package/dist/agents/QualityAnalyzerAgent.js.map +1 -1
- package/dist/agents/RegressionRiskAnalyzerAgent.d.ts.map +1 -1
- package/dist/agents/RegressionRiskAnalyzerAgent.js +18 -18
- package/dist/agents/RegressionRiskAnalyzerAgent.js.map +1 -1
- package/dist/agents/RequirementsValidatorAgent.d.ts.map +1 -1
- package/dist/agents/RequirementsValidatorAgent.js +21 -21
- package/dist/agents/RequirementsValidatorAgent.js.map +1 -1
- package/dist/agents/SecurityScannerAgent.d.ts.map +1 -1
- package/dist/agents/SecurityScannerAgent.js +38 -38
- package/dist/agents/SecurityScannerAgent.js.map +1 -1
- package/dist/agents/TestDataArchitectAgent.d.ts.map +1 -1
- package/dist/agents/TestDataArchitectAgent.js +29 -29
- package/dist/agents/TestDataArchitectAgent.js.map +1 -1
- package/dist/agents/TestExecutorAgent.d.ts +0 -7
- package/dist/agents/TestExecutorAgent.d.ts.map +1 -1
- package/dist/agents/TestExecutorAgent.js +35 -51
- package/dist/agents/TestExecutorAgent.js.map +1 -1
- package/dist/agents/TestGeneratorAgent.d.ts +0 -7
- package/dist/agents/TestGeneratorAgent.d.ts.map +1 -1
- package/dist/agents/TestGeneratorAgent.js +0 -16
- package/dist/agents/TestGeneratorAgent.js.map +1 -1
- package/dist/agents/adapters/AgentLLMAdapter.d.ts.map +1 -1
- package/dist/agents/adapters/AgentLLMAdapter.js +5 -4
- package/dist/agents/adapters/AgentLLMAdapter.js.map +1 -1
- package/dist/agents/adapters/CoordinatorAdapter.d.ts.map +1 -1
- package/dist/agents/adapters/CoordinatorAdapter.js +2 -1
- package/dist/agents/adapters/CoordinatorAdapter.js.map +1 -1
- package/dist/agents/n8n/N8nAPIClient.d.ts.map +1 -1
- package/dist/agents/n8n/N8nAPIClient.js +3 -2
- package/dist/agents/n8n/N8nAPIClient.js.map +1 -1
- package/dist/agents/n8n/N8nAuditPersistence.d.ts.map +1 -1
- package/dist/agents/n8n/N8nAuditPersistence.js +2 -1
- package/dist/agents/n8n/N8nAuditPersistence.js.map +1 -1
- package/dist/agents/n8n/N8nBaseAgent.js +1 -1
- package/dist/agents/n8n/N8nBaseAgent.js.map +1 -1
- package/dist/agents/n8n/N8nComplianceValidatorAgent.js +1 -1
- package/dist/agents/n8n/N8nComplianceValidatorAgent.js.map +1 -1
- package/dist/agents/n8n/N8nMonitoringValidatorAgent.js +1 -1
- package/dist/agents/n8n/N8nMonitoringValidatorAgent.js.map +1 -1
- package/dist/agents/n8n/N8nReplayabilityTesterAgent.js +1 -1
- package/dist/agents/n8n/N8nReplayabilityTesterAgent.js.map +1 -1
- package/dist/agents/n8n/N8nSecurityAuditorAgent.js +1 -1
- package/dist/agents/n8n/N8nSecurityAuditorAgent.js.map +1 -1
- package/dist/agents/pool/AgentPool.d.ts.map +1 -1
- package/dist/agents/pool/AgentPool.js +2 -1
- package/dist/agents/pool/AgentPool.js.map +1 -1
- package/dist/agents/pool/QEAgentPoolFactory.d.ts.map +1 -1
- package/dist/agents/pool/QEAgentPoolFactory.js +2 -1
- package/dist/agents/pool/QEAgentPoolFactory.js.map +1 -1
- 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/persistence/migrations/all-migrations.d.ts.map +1 -1
- package/dist/persistence/migrations/all-migrations.js +44 -1
- package/dist/persistence/migrations/all-migrations.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 +15 -2
- package/dist/planning/GOAPPlanner.js.map +1 -1
- package/dist/planning/PlanLearning.d.ts.map +1 -1
- package/dist/planning/PlanLearning.js +2 -1
- package/dist/planning/PlanLearning.js.map +1 -1
- package/dist/planning/PlanSimilarity.d.ts.map +1 -1
- package/dist/planning/PlanSimilarity.js +2 -1
- package/dist/planning/PlanSimilarity.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,930 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Protocol Handler for Agent-to-Agent Communication
|
|
4
|
+
*
|
|
5
|
+
* Manages protocol state machine, message signing/verification using Ed25519,
|
|
6
|
+
* heartbeat/keepalive management, protocol version negotiation, and rate limiting.
|
|
7
|
+
*
|
|
8
|
+
* @module edge/p2p/protocol/ProtocolHandler
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ProtocolHandler = exports.ProtocolEventType = void 0;
|
|
13
|
+
exports.createProtocolHandler = createProtocolHandler;
|
|
14
|
+
const crypto_1 = require("../crypto");
|
|
15
|
+
const types_1 = require("./types");
|
|
16
|
+
const MessageEncoder_1 = require("./MessageEncoder");
|
|
17
|
+
/**
|
|
18
|
+
* Protocol handler event types
|
|
19
|
+
*/
|
|
20
|
+
var ProtocolEventType;
|
|
21
|
+
(function (ProtocolEventType) {
|
|
22
|
+
ProtocolEventType["STATE_CHANGED"] = "state_changed";
|
|
23
|
+
ProtocolEventType["MESSAGE_SIGNED"] = "message_signed";
|
|
24
|
+
ProtocolEventType["MESSAGE_VERIFIED"] = "message_verified";
|
|
25
|
+
ProtocolEventType["VERIFICATION_FAILED"] = "verification_failed";
|
|
26
|
+
ProtocolEventType["HANDSHAKE_STARTED"] = "handshake_started";
|
|
27
|
+
ProtocolEventType["HANDSHAKE_COMPLETED"] = "handshake_completed";
|
|
28
|
+
ProtocolEventType["HANDSHAKE_FAILED"] = "handshake_failed";
|
|
29
|
+
ProtocolEventType["HEARTBEAT_SENT"] = "heartbeat_sent";
|
|
30
|
+
ProtocolEventType["HEARTBEAT_RECEIVED"] = "heartbeat_received";
|
|
31
|
+
ProtocolEventType["HEARTBEAT_TIMEOUT"] = "heartbeat_timeout";
|
|
32
|
+
ProtocolEventType["RATE_LIMITED"] = "rate_limited";
|
|
33
|
+
ProtocolEventType["CLOSING"] = "closing";
|
|
34
|
+
ProtocolEventType["CLOSED"] = "closed";
|
|
35
|
+
})(ProtocolEventType || (exports.ProtocolEventType = ProtocolEventType = {}));
|
|
36
|
+
// ============================================
|
|
37
|
+
// ProtocolHandler Class
|
|
38
|
+
// ============================================
|
|
39
|
+
/**
|
|
40
|
+
* Protocol handler for agent-to-agent communication
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const handler = new ProtocolHandler({
|
|
45
|
+
* identity: myIdentity,
|
|
46
|
+
* keyPair: myKeyPair,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Start handshake
|
|
50
|
+
* const handshakeEnvelope = await handler.createHandshake();
|
|
51
|
+
*
|
|
52
|
+
* // Process incoming handshake
|
|
53
|
+
* const result = await handler.processHandshake(receivedEnvelope);
|
|
54
|
+
*
|
|
55
|
+
* // Create signed message
|
|
56
|
+
* const envelope = await handler.createMessage(MessageType.REQUEST, payload);
|
|
57
|
+
*
|
|
58
|
+
* // Verify incoming message
|
|
59
|
+
* const verified = await handler.verifyMessage(receivedEnvelope);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
class ProtocolHandler {
|
|
63
|
+
constructor(config) {
|
|
64
|
+
this.state = types_1.ProtocolState.IDLE;
|
|
65
|
+
this.eventHandlers = [];
|
|
66
|
+
// Session state
|
|
67
|
+
this.sessionId = null;
|
|
68
|
+
this.remoteIdentity = null;
|
|
69
|
+
this.agreedVersion = types_1.PROTOCOL_VERSION;
|
|
70
|
+
this.agreedFeatures = [];
|
|
71
|
+
// Heartbeat state
|
|
72
|
+
this.heartbeatSequence = 0;
|
|
73
|
+
this.lastHeartbeatSent = 0;
|
|
74
|
+
this.lastHeartbeatReceived = 0;
|
|
75
|
+
this.heartbeatTimer = null;
|
|
76
|
+
this.heartbeatTimeoutTimer = null;
|
|
77
|
+
// Message tracking
|
|
78
|
+
this.messageSequence = 0;
|
|
79
|
+
this.processedMessages = new Set();
|
|
80
|
+
this.messageTimestamps = new Map();
|
|
81
|
+
// Tracing
|
|
82
|
+
this.currentTraceId = null;
|
|
83
|
+
this.identity = config.identity;
|
|
84
|
+
this.keyPair = config.keyPair;
|
|
85
|
+
this.config = {
|
|
86
|
+
identity: config.identity,
|
|
87
|
+
keyPair: config.keyPair,
|
|
88
|
+
supportedVersions: config.supportedVersions ?? [types_1.PROTOCOL_VERSION],
|
|
89
|
+
features: config.features ?? types_1.DEFAULT_FEATURES,
|
|
90
|
+
heartbeatInterval: config.heartbeatInterval ?? types_1.DEFAULT_HEARTBEAT_INTERVAL,
|
|
91
|
+
heartbeatTimeout: config.heartbeatTimeout ?? types_1.DEFAULT_HEARTBEAT_INTERVAL * 2,
|
|
92
|
+
rateLimit: config.rateLimit ?? {},
|
|
93
|
+
enableTracing: config.enableTracing ?? false,
|
|
94
|
+
metadata: config.metadata ?? {},
|
|
95
|
+
};
|
|
96
|
+
this.rateLimitConfig = {
|
|
97
|
+
...types_1.DEFAULT_RATE_LIMIT,
|
|
98
|
+
...this.config.rateLimit,
|
|
99
|
+
};
|
|
100
|
+
this.rateLimitBucket = {
|
|
101
|
+
tokens: this.rateLimitConfig.burstSize,
|
|
102
|
+
lastRefill: Date.now(),
|
|
103
|
+
messageCount: 0,
|
|
104
|
+
byteCount: 0,
|
|
105
|
+
};
|
|
106
|
+
this.encoder = new MessageEncoder_1.MessageEncoder();
|
|
107
|
+
if (this.config.enableTracing) {
|
|
108
|
+
this.currentTraceId = (0, types_1.generateTraceId)();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// ============================================
|
|
112
|
+
// State Management
|
|
113
|
+
// ============================================
|
|
114
|
+
/**
|
|
115
|
+
* Get current protocol state
|
|
116
|
+
*/
|
|
117
|
+
getState() {
|
|
118
|
+
return this.state;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Transition to a new state
|
|
122
|
+
*/
|
|
123
|
+
transitionTo(newState, reason) {
|
|
124
|
+
const oldState = this.state;
|
|
125
|
+
this.state = newState;
|
|
126
|
+
const transition = {
|
|
127
|
+
from: oldState,
|
|
128
|
+
to: newState,
|
|
129
|
+
reason,
|
|
130
|
+
timestamp: Date.now(),
|
|
131
|
+
};
|
|
132
|
+
this.emit({
|
|
133
|
+
type: ProtocolEventType.STATE_CHANGED,
|
|
134
|
+
timestamp: Date.now(),
|
|
135
|
+
details: transition,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Validate state transition
|
|
140
|
+
*/
|
|
141
|
+
validateStateTransition(targetState) {
|
|
142
|
+
const validTransitions = {
|
|
143
|
+
[types_1.ProtocolState.IDLE]: [types_1.ProtocolState.CONNECTING, types_1.ProtocolState.CLOSED],
|
|
144
|
+
[types_1.ProtocolState.CONNECTING]: [
|
|
145
|
+
types_1.ProtocolState.ACTIVE,
|
|
146
|
+
types_1.ProtocolState.ERROR,
|
|
147
|
+
types_1.ProtocolState.CLOSED,
|
|
148
|
+
],
|
|
149
|
+
[types_1.ProtocolState.ACTIVE]: [types_1.ProtocolState.CLOSING, types_1.ProtocolState.ERROR],
|
|
150
|
+
[types_1.ProtocolState.CLOSING]: [types_1.ProtocolState.CLOSED, types_1.ProtocolState.ERROR],
|
|
151
|
+
[types_1.ProtocolState.CLOSED]: [types_1.ProtocolState.IDLE],
|
|
152
|
+
[types_1.ProtocolState.ERROR]: [types_1.ProtocolState.IDLE, types_1.ProtocolState.CLOSED],
|
|
153
|
+
};
|
|
154
|
+
if (!validTransitions[this.state].includes(targetState)) {
|
|
155
|
+
throw new types_1.ProtocolError(`Invalid state transition from ${this.state} to ${targetState}`, types_1.ProtocolErrorCode.INVALID_STATE);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// ============================================
|
|
159
|
+
// Handshake
|
|
160
|
+
// ============================================
|
|
161
|
+
/**
|
|
162
|
+
* Create handshake message to initiate connection
|
|
163
|
+
*/
|
|
164
|
+
async createHandshake() {
|
|
165
|
+
if (this.state !== types_1.ProtocolState.IDLE) {
|
|
166
|
+
throw new types_1.ProtocolError('Can only initiate handshake from IDLE state', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
167
|
+
}
|
|
168
|
+
this.transitionTo(types_1.ProtocolState.CONNECTING, 'Initiating handshake');
|
|
169
|
+
// Generate challenge for identity proof
|
|
170
|
+
const challenge = crypto_1.Signer.generateChallenge();
|
|
171
|
+
// Create identity proof
|
|
172
|
+
const identityProof = await crypto_1.Signer.createIdentityProof(this.keyPair, this.identity, challenge);
|
|
173
|
+
const payload = {
|
|
174
|
+
identityProof: {
|
|
175
|
+
agentId: identityProof.agentId,
|
|
176
|
+
publicKey: identityProof.publicKey,
|
|
177
|
+
challenge: identityProof.challenge,
|
|
178
|
+
signature: identityProof.signature,
|
|
179
|
+
timestamp: identityProof.timestamp,
|
|
180
|
+
expiresIn: identityProof.expiresIn,
|
|
181
|
+
},
|
|
182
|
+
supportedVersions: this.config.supportedVersions,
|
|
183
|
+
preferredVersion: types_1.PROTOCOL_VERSION,
|
|
184
|
+
features: this.config.features,
|
|
185
|
+
metadata: this.config.metadata,
|
|
186
|
+
};
|
|
187
|
+
const envelope = await this.createMessage(types_1.MessageType.HANDSHAKE, payload, '*');
|
|
188
|
+
this.emit({
|
|
189
|
+
type: ProtocolEventType.HANDSHAKE_STARTED,
|
|
190
|
+
timestamp: Date.now(),
|
|
191
|
+
});
|
|
192
|
+
return envelope;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Process incoming handshake and create acknowledgment
|
|
196
|
+
*/
|
|
197
|
+
async processHandshake(envelope) {
|
|
198
|
+
// Verify message signature
|
|
199
|
+
const verified = await this.verifyMessage(envelope);
|
|
200
|
+
if (!verified) {
|
|
201
|
+
this.transitionTo(types_1.ProtocolState.ERROR, 'Handshake signature verification failed');
|
|
202
|
+
return {
|
|
203
|
+
success: false,
|
|
204
|
+
error: new types_1.ProtocolError('Handshake signature verification failed', types_1.ProtocolErrorCode.INVALID_SIGNATURE),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const payload = envelope.payload;
|
|
208
|
+
// Verify identity proof
|
|
209
|
+
const proofResult = await crypto_1.Signer.verifyIdentityProof({
|
|
210
|
+
agentId: payload.identityProof.agentId,
|
|
211
|
+
publicKey: payload.identityProof.publicKey,
|
|
212
|
+
challenge: payload.identityProof.challenge,
|
|
213
|
+
signature: payload.identityProof.signature,
|
|
214
|
+
timestamp: payload.identityProof.timestamp,
|
|
215
|
+
expiresIn: payload.identityProof.expiresIn,
|
|
216
|
+
});
|
|
217
|
+
if (!proofResult.valid) {
|
|
218
|
+
this.transitionTo(types_1.ProtocolState.ERROR, 'Identity proof verification failed');
|
|
219
|
+
return {
|
|
220
|
+
success: false,
|
|
221
|
+
error: new types_1.ProtocolError(`Identity proof verification failed: ${proofResult.error}`, types_1.ProtocolErrorCode.AUTHENTICATION_FAILED),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
// Negotiate version
|
|
225
|
+
const agreedVersion = this.negotiateVersion(payload.supportedVersions);
|
|
226
|
+
if (!agreedVersion) {
|
|
227
|
+
this.transitionTo(types_1.ProtocolState.ERROR, 'No common protocol version');
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
error: new types_1.ProtocolError('No common protocol version supported', types_1.ProtocolErrorCode.UNSUPPORTED_VERSION),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
// Negotiate features
|
|
234
|
+
const agreedFeatures = this.negotiateFeatures(payload.features);
|
|
235
|
+
// Create session
|
|
236
|
+
this.sessionId = (0, types_1.generateSessionId)();
|
|
237
|
+
this.remoteIdentity = {
|
|
238
|
+
agentId: payload.identityProof.agentId,
|
|
239
|
+
publicKey: payload.identityProof.publicKey,
|
|
240
|
+
createdAt: new Date().toISOString(),
|
|
241
|
+
metadata: payload.metadata,
|
|
242
|
+
};
|
|
243
|
+
this.agreedVersion = agreedVersion;
|
|
244
|
+
this.agreedFeatures = agreedFeatures;
|
|
245
|
+
if (this.state === types_1.ProtocolState.IDLE) {
|
|
246
|
+
this.transitionTo(types_1.ProtocolState.CONNECTING, 'Received handshake');
|
|
247
|
+
}
|
|
248
|
+
this.emit({
|
|
249
|
+
type: ProtocolEventType.HANDSHAKE_COMPLETED,
|
|
250
|
+
timestamp: Date.now(),
|
|
251
|
+
details: {
|
|
252
|
+
remoteAgentId: this.remoteIdentity.agentId,
|
|
253
|
+
agreedVersion,
|
|
254
|
+
agreedFeatures,
|
|
255
|
+
sessionId: this.sessionId,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
return {
|
|
259
|
+
success: true,
|
|
260
|
+
agreedVersion,
|
|
261
|
+
agreedFeatures,
|
|
262
|
+
sessionId: this.sessionId,
|
|
263
|
+
remoteIdentity: this.remoteIdentity,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Create handshake acknowledgment
|
|
268
|
+
*/
|
|
269
|
+
async createHandshakeAck(result) {
|
|
270
|
+
if (!result.success) {
|
|
271
|
+
throw new types_1.ProtocolError('Cannot acknowledge failed handshake', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
272
|
+
}
|
|
273
|
+
const payload = {
|
|
274
|
+
agreedVersion: result.agreedVersion,
|
|
275
|
+
agreedFeatures: result.agreedFeatures,
|
|
276
|
+
sessionId: result.sessionId,
|
|
277
|
+
timestamp: Date.now(),
|
|
278
|
+
publicKey: this.identity.publicKey,
|
|
279
|
+
};
|
|
280
|
+
const envelope = await this.createMessage(types_1.MessageType.HANDSHAKE_ACK, payload, result.remoteIdentity.agentId);
|
|
281
|
+
// Transition to active state
|
|
282
|
+
this.transitionTo(types_1.ProtocolState.ACTIVE, 'Handshake acknowledgment sent');
|
|
283
|
+
// Start heartbeat
|
|
284
|
+
this.startHeartbeat();
|
|
285
|
+
return envelope;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Process handshake acknowledgment
|
|
289
|
+
*/
|
|
290
|
+
async processHandshakeAck(envelope) {
|
|
291
|
+
if (this.state !== types_1.ProtocolState.CONNECTING) {
|
|
292
|
+
throw new types_1.ProtocolError('Not expecting handshake acknowledgment', types_1.ProtocolErrorCode.INVALID_STATE);
|
|
293
|
+
}
|
|
294
|
+
// Verify signature
|
|
295
|
+
const verified = await this.verifyMessage(envelope);
|
|
296
|
+
if (!verified) {
|
|
297
|
+
this.transitionTo(types_1.ProtocolState.ERROR, 'Handshake ack signature verification failed');
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
const payload = envelope.payload;
|
|
301
|
+
// Store session info
|
|
302
|
+
this.sessionId = payload.sessionId;
|
|
303
|
+
this.agreedVersion = payload.agreedVersion;
|
|
304
|
+
this.agreedFeatures = payload.agreedFeatures;
|
|
305
|
+
this.remoteIdentity = {
|
|
306
|
+
agentId: envelope.header.senderId,
|
|
307
|
+
publicKey: payload.publicKey,
|
|
308
|
+
createdAt: new Date().toISOString(),
|
|
309
|
+
};
|
|
310
|
+
// Transition to active
|
|
311
|
+
this.transitionTo(types_1.ProtocolState.ACTIVE, 'Handshake acknowledgment received');
|
|
312
|
+
// Start heartbeat
|
|
313
|
+
this.startHeartbeat();
|
|
314
|
+
this.emit({
|
|
315
|
+
type: ProtocolEventType.HANDSHAKE_COMPLETED,
|
|
316
|
+
timestamp: Date.now(),
|
|
317
|
+
details: {
|
|
318
|
+
sessionId: this.sessionId,
|
|
319
|
+
agreedVersion: this.agreedVersion,
|
|
320
|
+
agreedFeatures: this.agreedFeatures,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Negotiate protocol version
|
|
327
|
+
*/
|
|
328
|
+
negotiateVersion(remoteVersions) {
|
|
329
|
+
// Find highest common version
|
|
330
|
+
const commonVersions = this.config.supportedVersions.filter((v) => remoteVersions.includes(v));
|
|
331
|
+
if (commonVersions.length === 0) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
// Sort by version (semantic versioning)
|
|
335
|
+
commonVersions.sort((a, b) => {
|
|
336
|
+
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
|
|
337
|
+
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
|
|
338
|
+
return bMajor - aMajor || bMinor - aMinor || bPatch - aPatch;
|
|
339
|
+
});
|
|
340
|
+
return commonVersions[0];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Negotiate features
|
|
344
|
+
*/
|
|
345
|
+
negotiateFeatures(remoteFeatures) {
|
|
346
|
+
return this.config.features.filter((f) => remoteFeatures.includes(f));
|
|
347
|
+
}
|
|
348
|
+
// ============================================
|
|
349
|
+
// Message Creation and Signing
|
|
350
|
+
// ============================================
|
|
351
|
+
/**
|
|
352
|
+
* Create a signed protocol envelope
|
|
353
|
+
*/
|
|
354
|
+
async createMessage(type, payload, recipientId = '*', options = {}) {
|
|
355
|
+
// Check rate limit
|
|
356
|
+
const rateLimitStatus = this.checkRateLimit(1, 0);
|
|
357
|
+
if (rateLimitStatus.limited) {
|
|
358
|
+
this.emit({
|
|
359
|
+
type: ProtocolEventType.RATE_LIMITED,
|
|
360
|
+
timestamp: Date.now(),
|
|
361
|
+
details: rateLimitStatus,
|
|
362
|
+
});
|
|
363
|
+
throw new types_1.ProtocolError(`Rate limited. Retry after ${rateLimitStatus.retryAfter}ms`, types_1.ProtocolErrorCode.RATE_LIMITED, true);
|
|
364
|
+
}
|
|
365
|
+
// Create header
|
|
366
|
+
const header = {
|
|
367
|
+
version: this.agreedVersion,
|
|
368
|
+
messageId: (0, types_1.generateMessageId)(),
|
|
369
|
+
correlationId: options.correlationId,
|
|
370
|
+
type,
|
|
371
|
+
priority: options.priority ?? types_1.MessagePriority.NORMAL,
|
|
372
|
+
senderId: this.identity.agentId,
|
|
373
|
+
recipientId,
|
|
374
|
+
timestamp: Date.now(),
|
|
375
|
+
ttl: options.ttl ?? types_1.DEFAULT_MESSAGE_TTL,
|
|
376
|
+
hopCount: 0,
|
|
377
|
+
maxHops: 5,
|
|
378
|
+
compressed: false,
|
|
379
|
+
delivery: options.delivery ?? types_1.DeliverySemantics.AT_LEAST_ONCE,
|
|
380
|
+
routing: options.routing ?? types_1.RoutingMode.UNICAST,
|
|
381
|
+
schemaVersion: 1,
|
|
382
|
+
};
|
|
383
|
+
// Create metadata
|
|
384
|
+
const metadata = {};
|
|
385
|
+
if (this.config.enableTracing) {
|
|
386
|
+
metadata.traceId = this.currentTraceId ?? (0, types_1.generateTraceId)();
|
|
387
|
+
metadata.spanId = (0, types_1.generateSpanId)();
|
|
388
|
+
}
|
|
389
|
+
// Create message to sign
|
|
390
|
+
const messageToSign = {
|
|
391
|
+
header,
|
|
392
|
+
payload,
|
|
393
|
+
};
|
|
394
|
+
// Sign message
|
|
395
|
+
const signedMessage = await crypto_1.Signer.sign(this.keyPair, this.identity, messageToSign, true);
|
|
396
|
+
const envelope = {
|
|
397
|
+
header,
|
|
398
|
+
payload,
|
|
399
|
+
signature: signedMessage.signature,
|
|
400
|
+
signerPublicKey: signedMessage.signerPublicKey,
|
|
401
|
+
metadata,
|
|
402
|
+
};
|
|
403
|
+
// Consume rate limit token
|
|
404
|
+
this.consumeRateLimit(1, JSON.stringify(payload).length);
|
|
405
|
+
// Track message
|
|
406
|
+
this.messageSequence++;
|
|
407
|
+
this.messageTimestamps.set(header.messageId, Date.now());
|
|
408
|
+
this.emit({
|
|
409
|
+
type: ProtocolEventType.MESSAGE_SIGNED,
|
|
410
|
+
timestamp: Date.now(),
|
|
411
|
+
details: { messageId: header.messageId, type },
|
|
412
|
+
});
|
|
413
|
+
return envelope;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Verify a signed protocol envelope
|
|
417
|
+
*/
|
|
418
|
+
async verifyMessage(envelope) {
|
|
419
|
+
try {
|
|
420
|
+
// Check for duplicates (replay protection)
|
|
421
|
+
if (this.processedMessages.has(envelope.header.messageId)) {
|
|
422
|
+
throw new types_1.ProtocolError('Duplicate message', types_1.ProtocolErrorCode.DUPLICATE);
|
|
423
|
+
}
|
|
424
|
+
// Check TTL
|
|
425
|
+
const age = Date.now() - envelope.header.timestamp;
|
|
426
|
+
if (age > envelope.header.ttl) {
|
|
427
|
+
throw new types_1.ProtocolError('Message expired', types_1.ProtocolErrorCode.TTL_EXPIRED);
|
|
428
|
+
}
|
|
429
|
+
// Check hop count
|
|
430
|
+
if (envelope.header.hopCount > envelope.header.maxHops) {
|
|
431
|
+
throw new types_1.ProtocolError('Max hops exceeded', types_1.ProtocolErrorCode.MAX_HOPS_EXCEEDED);
|
|
432
|
+
}
|
|
433
|
+
// Verify signature
|
|
434
|
+
const messageToVerify = {
|
|
435
|
+
header: envelope.header,
|
|
436
|
+
payload: envelope.payload,
|
|
437
|
+
};
|
|
438
|
+
// Create canonical JSON for verification
|
|
439
|
+
const canonical = crypto_1.Signer.canonicalizeJson(messageToVerify);
|
|
440
|
+
const encoder = new TextEncoder();
|
|
441
|
+
const messageBytes = encoder.encode(canonical);
|
|
442
|
+
// Recreate the signing context
|
|
443
|
+
const signingContext = {
|
|
444
|
+
payload: canonical,
|
|
445
|
+
publicKey: envelope.signerPublicKey,
|
|
446
|
+
signedAt: new Date(envelope.header.timestamp).toISOString(),
|
|
447
|
+
nonce: undefined, // The nonce was included in the original signing
|
|
448
|
+
};
|
|
449
|
+
const signedMessage = {
|
|
450
|
+
payload: messageToVerify,
|
|
451
|
+
signature: envelope.signature,
|
|
452
|
+
signerPublicKey: envelope.signerPublicKey,
|
|
453
|
+
signerId: envelope.header.senderId,
|
|
454
|
+
signedAt: new Date(envelope.header.timestamp).toISOString(),
|
|
455
|
+
};
|
|
456
|
+
const verifyResult = await crypto_1.Signer.verify(signedMessage);
|
|
457
|
+
if (!verifyResult.valid) {
|
|
458
|
+
this.emit({
|
|
459
|
+
type: ProtocolEventType.VERIFICATION_FAILED,
|
|
460
|
+
timestamp: Date.now(),
|
|
461
|
+
details: {
|
|
462
|
+
messageId: envelope.header.messageId,
|
|
463
|
+
error: verifyResult.error,
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
// Verify sender identity matches signature
|
|
469
|
+
if (verifyResult.signerId !== envelope.header.senderId) {
|
|
470
|
+
this.emit({
|
|
471
|
+
type: ProtocolEventType.VERIFICATION_FAILED,
|
|
472
|
+
timestamp: Date.now(),
|
|
473
|
+
details: {
|
|
474
|
+
messageId: envelope.header.messageId,
|
|
475
|
+
error: 'Sender ID mismatch',
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
// Mark message as processed
|
|
481
|
+
this.processedMessages.add(envelope.header.messageId);
|
|
482
|
+
// Cleanup old processed messages (keep last 10000)
|
|
483
|
+
if (this.processedMessages.size > 10000) {
|
|
484
|
+
const oldest = Array.from(this.processedMessages).slice(0, 5000);
|
|
485
|
+
for (const id of oldest) {
|
|
486
|
+
this.processedMessages.delete(id);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
this.emit({
|
|
490
|
+
type: ProtocolEventType.MESSAGE_VERIFIED,
|
|
491
|
+
timestamp: Date.now(),
|
|
492
|
+
details: { messageId: envelope.header.messageId },
|
|
493
|
+
});
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
this.emit({
|
|
498
|
+
type: ProtocolEventType.VERIFICATION_FAILED,
|
|
499
|
+
timestamp: Date.now(),
|
|
500
|
+
details: {
|
|
501
|
+
messageId: envelope.header.messageId,
|
|
502
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
503
|
+
},
|
|
504
|
+
});
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
// ============================================
|
|
509
|
+
// Heartbeat Management
|
|
510
|
+
// ============================================
|
|
511
|
+
/**
|
|
512
|
+
* Start heartbeat timer
|
|
513
|
+
*/
|
|
514
|
+
startHeartbeat() {
|
|
515
|
+
if (this.heartbeatTimer)
|
|
516
|
+
return;
|
|
517
|
+
this.heartbeatTimer = setInterval(() => {
|
|
518
|
+
this.sendHeartbeat();
|
|
519
|
+
}, this.config.heartbeatInterval);
|
|
520
|
+
// Send initial heartbeat
|
|
521
|
+
this.sendHeartbeat();
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Stop heartbeat timer
|
|
525
|
+
*/
|
|
526
|
+
stopHeartbeat() {
|
|
527
|
+
if (this.heartbeatTimer) {
|
|
528
|
+
clearInterval(this.heartbeatTimer);
|
|
529
|
+
this.heartbeatTimer = null;
|
|
530
|
+
}
|
|
531
|
+
if (this.heartbeatTimeoutTimer) {
|
|
532
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
533
|
+
this.heartbeatTimeoutTimer = null;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Send heartbeat message
|
|
538
|
+
*/
|
|
539
|
+
async sendHeartbeat() {
|
|
540
|
+
if (this.state !== types_1.ProtocolState.ACTIVE)
|
|
541
|
+
return null;
|
|
542
|
+
const payload = {
|
|
543
|
+
sequence: ++this.heartbeatSequence,
|
|
544
|
+
timestamp: Date.now(),
|
|
545
|
+
isResponse: false,
|
|
546
|
+
stats: {
|
|
547
|
+
messagesSent: this.messageSequence,
|
|
548
|
+
messagesReceived: this.processedMessages.size,
|
|
549
|
+
queueSize: 0, // Will be filled by router
|
|
550
|
+
},
|
|
551
|
+
};
|
|
552
|
+
try {
|
|
553
|
+
const envelope = await this.createMessage(types_1.MessageType.HEARTBEAT, payload, this.remoteIdentity?.agentId ?? '*', { priority: types_1.MessagePriority.HIGH });
|
|
554
|
+
this.lastHeartbeatSent = Date.now();
|
|
555
|
+
// Start timeout timer
|
|
556
|
+
this.startHeartbeatTimeout();
|
|
557
|
+
this.emit({
|
|
558
|
+
type: ProtocolEventType.HEARTBEAT_SENT,
|
|
559
|
+
timestamp: Date.now(),
|
|
560
|
+
details: { sequence: this.heartbeatSequence },
|
|
561
|
+
});
|
|
562
|
+
return envelope;
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Process incoming heartbeat
|
|
570
|
+
*/
|
|
571
|
+
async processHeartbeat(envelope) {
|
|
572
|
+
const payload = envelope.payload;
|
|
573
|
+
this.lastHeartbeatReceived = Date.now();
|
|
574
|
+
// Clear timeout timer
|
|
575
|
+
if (this.heartbeatTimeoutTimer) {
|
|
576
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
577
|
+
this.heartbeatTimeoutTimer = null;
|
|
578
|
+
}
|
|
579
|
+
this.emit({
|
|
580
|
+
type: ProtocolEventType.HEARTBEAT_RECEIVED,
|
|
581
|
+
timestamp: Date.now(),
|
|
582
|
+
details: {
|
|
583
|
+
sequence: payload.sequence,
|
|
584
|
+
latency: payload.isResponse ? Date.now() - payload.originalTimestamp : undefined,
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
// If this is a request, send response
|
|
588
|
+
if (!payload.isResponse) {
|
|
589
|
+
const responsePayload = {
|
|
590
|
+
sequence: payload.sequence,
|
|
591
|
+
timestamp: Date.now(),
|
|
592
|
+
isResponse: true,
|
|
593
|
+
originalTimestamp: payload.timestamp,
|
|
594
|
+
stats: {
|
|
595
|
+
messagesSent: this.messageSequence,
|
|
596
|
+
messagesReceived: this.processedMessages.size,
|
|
597
|
+
queueSize: 0,
|
|
598
|
+
},
|
|
599
|
+
};
|
|
600
|
+
return this.createMessage(types_1.MessageType.HEARTBEAT, responsePayload, envelope.header.senderId, {
|
|
601
|
+
priority: types_1.MessagePriority.HIGH,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
return null;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Start heartbeat timeout timer
|
|
608
|
+
*/
|
|
609
|
+
startHeartbeatTimeout() {
|
|
610
|
+
if (this.heartbeatTimeoutTimer) {
|
|
611
|
+
clearTimeout(this.heartbeatTimeoutTimer);
|
|
612
|
+
}
|
|
613
|
+
this.heartbeatTimeoutTimer = setTimeout(() => {
|
|
614
|
+
this.handleHeartbeatTimeout();
|
|
615
|
+
}, this.config.heartbeatTimeout);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Handle heartbeat timeout
|
|
619
|
+
*/
|
|
620
|
+
handleHeartbeatTimeout() {
|
|
621
|
+
this.emit({
|
|
622
|
+
type: ProtocolEventType.HEARTBEAT_TIMEOUT,
|
|
623
|
+
timestamp: Date.now(),
|
|
624
|
+
details: {
|
|
625
|
+
lastSent: this.lastHeartbeatSent,
|
|
626
|
+
lastReceived: this.lastHeartbeatReceived,
|
|
627
|
+
},
|
|
628
|
+
});
|
|
629
|
+
// Transition to error state after timeout
|
|
630
|
+
this.transitionTo(types_1.ProtocolState.ERROR, 'Heartbeat timeout');
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Get heartbeat latency (ms)
|
|
634
|
+
*/
|
|
635
|
+
getHeartbeatLatency() {
|
|
636
|
+
if (this.lastHeartbeatSent === 0 || this.lastHeartbeatReceived === 0) {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
return this.lastHeartbeatReceived - this.lastHeartbeatSent;
|
|
640
|
+
}
|
|
641
|
+
// ============================================
|
|
642
|
+
// Rate Limiting
|
|
643
|
+
// ============================================
|
|
644
|
+
/**
|
|
645
|
+
* Check rate limit without consuming
|
|
646
|
+
*/
|
|
647
|
+
checkRateLimit(messages, bytes) {
|
|
648
|
+
this.refillBucket();
|
|
649
|
+
const limited = this.rateLimitBucket.tokens < messages ||
|
|
650
|
+
this.rateLimitBucket.byteCount + bytes > this.rateLimitConfig.bytesPerSecond;
|
|
651
|
+
const remaining = Math.floor(this.rateLimitBucket.tokens);
|
|
652
|
+
const resetIn = this.rateLimitConfig.windowSize - (Date.now() - this.rateLimitBucket.lastRefill);
|
|
653
|
+
return {
|
|
654
|
+
limited,
|
|
655
|
+
currentRate: this.rateLimitBucket.messageCount,
|
|
656
|
+
remaining,
|
|
657
|
+
resetIn: Math.max(0, resetIn),
|
|
658
|
+
retryAfter: limited ? resetIn : undefined,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Consume rate limit tokens
|
|
663
|
+
*/
|
|
664
|
+
consumeRateLimit(messages, bytes) {
|
|
665
|
+
this.rateLimitBucket.tokens -= messages;
|
|
666
|
+
this.rateLimitBucket.messageCount += messages;
|
|
667
|
+
this.rateLimitBucket.byteCount += bytes;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Refill rate limit bucket based on elapsed time
|
|
671
|
+
*/
|
|
672
|
+
refillBucket() {
|
|
673
|
+
const now = Date.now();
|
|
674
|
+
const elapsed = now - this.rateLimitBucket.lastRefill;
|
|
675
|
+
if (elapsed >= this.rateLimitConfig.windowSize) {
|
|
676
|
+
// Full reset
|
|
677
|
+
this.rateLimitBucket.tokens = this.rateLimitConfig.burstSize;
|
|
678
|
+
this.rateLimitBucket.messageCount = 0;
|
|
679
|
+
this.rateLimitBucket.byteCount = 0;
|
|
680
|
+
this.rateLimitBucket.lastRefill = now;
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
// Partial refill
|
|
684
|
+
const refillRate = this.rateLimitConfig.messagesPerSecond / (1000 / this.rateLimitConfig.windowSize);
|
|
685
|
+
const refillAmount = (elapsed / this.rateLimitConfig.windowSize) * refillRate;
|
|
686
|
+
this.rateLimitBucket.tokens = Math.min(this.rateLimitConfig.burstSize, this.rateLimitBucket.tokens + refillAmount);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Get current rate limit status
|
|
691
|
+
*/
|
|
692
|
+
getRateLimitStatus() {
|
|
693
|
+
return this.checkRateLimit(0, 0);
|
|
694
|
+
}
|
|
695
|
+
// ============================================
|
|
696
|
+
// Message Creation Helpers
|
|
697
|
+
// ============================================
|
|
698
|
+
/**
|
|
699
|
+
* Create request message
|
|
700
|
+
*/
|
|
701
|
+
async createRequest(method, params, recipientId, timeout) {
|
|
702
|
+
const payload = {
|
|
703
|
+
method,
|
|
704
|
+
params,
|
|
705
|
+
timeout,
|
|
706
|
+
};
|
|
707
|
+
return this.createMessage(types_1.MessageType.REQUEST, payload, recipientId);
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Create response message
|
|
711
|
+
*/
|
|
712
|
+
async createResponse(correlationId, result, recipientId) {
|
|
713
|
+
const payload = {
|
|
714
|
+
success: true,
|
|
715
|
+
result,
|
|
716
|
+
};
|
|
717
|
+
return this.createMessage(types_1.MessageType.RESPONSE, payload, recipientId, { correlationId });
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Create error response
|
|
721
|
+
*/
|
|
722
|
+
async createErrorResponse(correlationId, error, recipientId) {
|
|
723
|
+
const payload = {
|
|
724
|
+
success: false,
|
|
725
|
+
error: error.toInfo(),
|
|
726
|
+
};
|
|
727
|
+
return this.createMessage(types_1.MessageType.RESPONSE, payload, recipientId, { correlationId });
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Create event message
|
|
731
|
+
*/
|
|
732
|
+
async createEvent(event, data, recipientId = '*', requiresAck = false) {
|
|
733
|
+
const payload = {
|
|
734
|
+
event,
|
|
735
|
+
data,
|
|
736
|
+
requiresAck,
|
|
737
|
+
};
|
|
738
|
+
return this.createMessage(types_1.MessageType.EVENT, payload, recipientId, {
|
|
739
|
+
routing: recipientId === '*' ? types_1.RoutingMode.BROADCAST : types_1.RoutingMode.UNICAST,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Create acknowledgment message
|
|
744
|
+
*/
|
|
745
|
+
async createAck(messageId, recipientId) {
|
|
746
|
+
const payload = {
|
|
747
|
+
messageId,
|
|
748
|
+
timestamp: Date.now(),
|
|
749
|
+
};
|
|
750
|
+
return this.createMessage(types_1.MessageType.ACK, payload, recipientId, {
|
|
751
|
+
priority: types_1.MessagePriority.HIGH,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Create negative acknowledgment message
|
|
756
|
+
*/
|
|
757
|
+
async createNack(messageId, reason, code, recipientId) {
|
|
758
|
+
const payload = {
|
|
759
|
+
messageId,
|
|
760
|
+
reason,
|
|
761
|
+
code,
|
|
762
|
+
retryable: (0, types_1.isRetryableError)(code),
|
|
763
|
+
};
|
|
764
|
+
return this.createMessage(types_1.MessageType.NACK, payload, recipientId, {
|
|
765
|
+
priority: types_1.MessagePriority.HIGH,
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
// ============================================
|
|
769
|
+
// Connection Close
|
|
770
|
+
// ============================================
|
|
771
|
+
/**
|
|
772
|
+
* Create close message
|
|
773
|
+
*/
|
|
774
|
+
async createClose(code = types_1.CloseCode.NORMAL, reason = 'Connection closed', reconnect = false) {
|
|
775
|
+
this.validateStateTransition(types_1.ProtocolState.CLOSING);
|
|
776
|
+
this.transitionTo(types_1.ProtocolState.CLOSING, reason);
|
|
777
|
+
this.emit({
|
|
778
|
+
type: ProtocolEventType.CLOSING,
|
|
779
|
+
timestamp: Date.now(),
|
|
780
|
+
details: { code, reason, reconnect },
|
|
781
|
+
});
|
|
782
|
+
const payload = {
|
|
783
|
+
code,
|
|
784
|
+
reason,
|
|
785
|
+
reconnect,
|
|
786
|
+
};
|
|
787
|
+
return this.createMessage(types_1.MessageType.CLOSE, payload, this.remoteIdentity?.agentId ?? '*', { priority: types_1.MessagePriority.CRITICAL });
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Process close message
|
|
791
|
+
*/
|
|
792
|
+
processClose(envelope) {
|
|
793
|
+
const payload = envelope.payload;
|
|
794
|
+
this.transitionTo(types_1.ProtocolState.CLOSED, payload.reason);
|
|
795
|
+
this.stopHeartbeat();
|
|
796
|
+
this.emit({
|
|
797
|
+
type: ProtocolEventType.CLOSED,
|
|
798
|
+
timestamp: Date.now(),
|
|
799
|
+
details: payload,
|
|
800
|
+
});
|
|
801
|
+
return payload;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Close connection
|
|
805
|
+
*/
|
|
806
|
+
close() {
|
|
807
|
+
this.stopHeartbeat();
|
|
808
|
+
if (this.state !== types_1.ProtocolState.CLOSED) {
|
|
809
|
+
this.transitionTo(types_1.ProtocolState.CLOSED, 'Local close');
|
|
810
|
+
}
|
|
811
|
+
this.emit({
|
|
812
|
+
type: ProtocolEventType.CLOSED,
|
|
813
|
+
timestamp: Date.now(),
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
// ============================================
|
|
817
|
+
// Events
|
|
818
|
+
// ============================================
|
|
819
|
+
/**
|
|
820
|
+
* Add event handler
|
|
821
|
+
*/
|
|
822
|
+
on(handler) {
|
|
823
|
+
this.eventHandlers.push(handler);
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Remove event handler
|
|
827
|
+
*/
|
|
828
|
+
off(handler) {
|
|
829
|
+
const index = this.eventHandlers.indexOf(handler);
|
|
830
|
+
if (index !== -1) {
|
|
831
|
+
this.eventHandlers.splice(index, 1);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Emit event to handlers
|
|
836
|
+
*/
|
|
837
|
+
emit(event) {
|
|
838
|
+
for (const handler of this.eventHandlers) {
|
|
839
|
+
try {
|
|
840
|
+
handler(event);
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
// Ignore handler errors
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
// ============================================
|
|
848
|
+
// Getters
|
|
849
|
+
// ============================================
|
|
850
|
+
/**
|
|
851
|
+
* Get session ID
|
|
852
|
+
*/
|
|
853
|
+
getSessionId() {
|
|
854
|
+
return this.sessionId;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Get remote identity
|
|
858
|
+
*/
|
|
859
|
+
getRemoteIdentity() {
|
|
860
|
+
return this.remoteIdentity;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Get agreed protocol version
|
|
864
|
+
*/
|
|
865
|
+
getAgreedVersion() {
|
|
866
|
+
return this.agreedVersion;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Get agreed features
|
|
870
|
+
*/
|
|
871
|
+
getAgreedFeatures() {
|
|
872
|
+
return [...this.agreedFeatures];
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Check if a feature is enabled
|
|
876
|
+
*/
|
|
877
|
+
hasFeature(feature) {
|
|
878
|
+
return this.agreedFeatures.includes(feature);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Get local identity
|
|
882
|
+
*/
|
|
883
|
+
getLocalIdentity() {
|
|
884
|
+
return this.identity;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Get message encoder
|
|
888
|
+
*/
|
|
889
|
+
getEncoder() {
|
|
890
|
+
return this.encoder;
|
|
891
|
+
}
|
|
892
|
+
// ============================================
|
|
893
|
+
// Reset
|
|
894
|
+
// ============================================
|
|
895
|
+
/**
|
|
896
|
+
* Reset handler state
|
|
897
|
+
*/
|
|
898
|
+
reset() {
|
|
899
|
+
this.stopHeartbeat();
|
|
900
|
+
this.state = types_1.ProtocolState.IDLE;
|
|
901
|
+
this.sessionId = null;
|
|
902
|
+
this.remoteIdentity = null;
|
|
903
|
+
this.agreedVersion = types_1.PROTOCOL_VERSION;
|
|
904
|
+
this.agreedFeatures = [];
|
|
905
|
+
this.heartbeatSequence = 0;
|
|
906
|
+
this.lastHeartbeatSent = 0;
|
|
907
|
+
this.lastHeartbeatReceived = 0;
|
|
908
|
+
this.messageSequence = 0;
|
|
909
|
+
this.processedMessages.clear();
|
|
910
|
+
this.messageTimestamps.clear();
|
|
911
|
+
// Reset rate limit bucket
|
|
912
|
+
this.rateLimitBucket = {
|
|
913
|
+
tokens: this.rateLimitConfig.burstSize,
|
|
914
|
+
lastRefill: Date.now(),
|
|
915
|
+
messageCount: 0,
|
|
916
|
+
byteCount: 0,
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
exports.ProtocolHandler = ProtocolHandler;
|
|
921
|
+
// ============================================
|
|
922
|
+
// Factory Functions
|
|
923
|
+
// ============================================
|
|
924
|
+
/**
|
|
925
|
+
* Create a new protocol handler
|
|
926
|
+
*/
|
|
927
|
+
function createProtocolHandler(config) {
|
|
928
|
+
return new ProtocolHandler(config);
|
|
929
|
+
}
|
|
930
|
+
//# sourceMappingURL=ProtocolHandler.js.map
|