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,738 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Message Encoder for Agent-to-Agent Protocol
|
|
4
|
+
*
|
|
5
|
+
* Provides binary message encoding using a MessagePack-style format with
|
|
6
|
+
* compression support for large payloads and schema versioning for
|
|
7
|
+
* forward/backward compatibility.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Binary serialization/deserialization
|
|
11
|
+
* - Compression for payloads > 1KB
|
|
12
|
+
* - Schema versioning for compatibility
|
|
13
|
+
* - Message validation
|
|
14
|
+
* - Efficient encoding for common types
|
|
15
|
+
*
|
|
16
|
+
* @module edge/p2p/protocol/MessageEncoder
|
|
17
|
+
* @version 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.JsonMessageEncoder = exports.MessageEncoder = void 0;
|
|
21
|
+
exports.createMessageEncoder = createMessageEncoder;
|
|
22
|
+
exports.createJsonEncoder = createJsonEncoder;
|
|
23
|
+
const types_1 = require("./types");
|
|
24
|
+
// ============================================
|
|
25
|
+
// Encoder Constants
|
|
26
|
+
// ============================================
|
|
27
|
+
/**
|
|
28
|
+
* Magic bytes for protocol identification
|
|
29
|
+
*/
|
|
30
|
+
const MAGIC_BYTES = new Uint8Array([0x41, 0x51, 0x45, 0x50]); // "AQEP" - Agentic QE Protocol
|
|
31
|
+
/**
|
|
32
|
+
* Schema version for binary format
|
|
33
|
+
*/
|
|
34
|
+
const BINARY_SCHEMA_VERSION = 1;
|
|
35
|
+
/**
|
|
36
|
+
* Type markers for binary encoding
|
|
37
|
+
*/
|
|
38
|
+
var TypeMarker;
|
|
39
|
+
(function (TypeMarker) {
|
|
40
|
+
TypeMarker[TypeMarker["NULL"] = 0] = "NULL";
|
|
41
|
+
TypeMarker[TypeMarker["FALSE"] = 1] = "FALSE";
|
|
42
|
+
TypeMarker[TypeMarker["TRUE"] = 2] = "TRUE";
|
|
43
|
+
TypeMarker[TypeMarker["UINT8"] = 3] = "UINT8";
|
|
44
|
+
TypeMarker[TypeMarker["UINT16"] = 4] = "UINT16";
|
|
45
|
+
TypeMarker[TypeMarker["UINT32"] = 5] = "UINT32";
|
|
46
|
+
TypeMarker[TypeMarker["INT8"] = 6] = "INT8";
|
|
47
|
+
TypeMarker[TypeMarker["INT16"] = 7] = "INT16";
|
|
48
|
+
TypeMarker[TypeMarker["INT32"] = 8] = "INT32";
|
|
49
|
+
TypeMarker[TypeMarker["FLOAT64"] = 9] = "FLOAT64";
|
|
50
|
+
TypeMarker[TypeMarker["STRING8"] = 10] = "STRING8";
|
|
51
|
+
TypeMarker[TypeMarker["STRING16"] = 11] = "STRING16";
|
|
52
|
+
TypeMarker[TypeMarker["STRING32"] = 12] = "STRING32";
|
|
53
|
+
TypeMarker[TypeMarker["BINARY8"] = 13] = "BINARY8";
|
|
54
|
+
TypeMarker[TypeMarker["BINARY16"] = 14] = "BINARY16";
|
|
55
|
+
TypeMarker[TypeMarker["BINARY32"] = 15] = "BINARY32";
|
|
56
|
+
TypeMarker[TypeMarker["ARRAY8"] = 16] = "ARRAY8";
|
|
57
|
+
TypeMarker[TypeMarker["ARRAY16"] = 17] = "ARRAY16";
|
|
58
|
+
TypeMarker[TypeMarker["ARRAY32"] = 18] = "ARRAY32";
|
|
59
|
+
TypeMarker[TypeMarker["MAP8"] = 19] = "MAP8";
|
|
60
|
+
TypeMarker[TypeMarker["MAP16"] = 20] = "MAP16";
|
|
61
|
+
TypeMarker[TypeMarker["MAP32"] = 21] = "MAP32";
|
|
62
|
+
TypeMarker[TypeMarker["EXTENSION"] = 22] = "EXTENSION";
|
|
63
|
+
})(TypeMarker || (TypeMarker = {}));
|
|
64
|
+
/**
|
|
65
|
+
* Compression flag in header
|
|
66
|
+
*/
|
|
67
|
+
const COMPRESSION_FLAG = 0x80;
|
|
68
|
+
// ============================================
|
|
69
|
+
// MessageEncoder Class
|
|
70
|
+
// ============================================
|
|
71
|
+
/**
|
|
72
|
+
* Binary message encoder/decoder
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const encoder = new MessageEncoder();
|
|
77
|
+
*
|
|
78
|
+
* // Encode envelope
|
|
79
|
+
* const binary = await encoder.encode(envelope);
|
|
80
|
+
*
|
|
81
|
+
* // Decode envelope
|
|
82
|
+
* const decoded = await encoder.decode(binary);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
class MessageEncoder {
|
|
86
|
+
constructor() {
|
|
87
|
+
this.textEncoder = new TextEncoder();
|
|
88
|
+
this.textDecoder = new TextDecoder();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Encode a protocol envelope to binary
|
|
92
|
+
*
|
|
93
|
+
* @param envelope - Protocol envelope to encode
|
|
94
|
+
* @returns Binary data
|
|
95
|
+
*/
|
|
96
|
+
async encode(envelope) {
|
|
97
|
+
// Validate envelope
|
|
98
|
+
this.validateEnvelope(envelope);
|
|
99
|
+
// Serialize to JSON first (for payload)
|
|
100
|
+
const jsonPayload = JSON.stringify(envelope.payload);
|
|
101
|
+
const payloadBytes = this.textEncoder.encode(jsonPayload);
|
|
102
|
+
// Check if compression is needed
|
|
103
|
+
let compressedPayload = null;
|
|
104
|
+
let isCompressed = false;
|
|
105
|
+
if (payloadBytes.length > types_1.COMPRESSION_THRESHOLD) {
|
|
106
|
+
try {
|
|
107
|
+
compressedPayload = await this.compress(payloadBytes);
|
|
108
|
+
// Only use compression if it actually reduces size
|
|
109
|
+
if (compressedPayload.length < payloadBytes.length * 0.9) {
|
|
110
|
+
isCompressed = true;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
compressedPayload = null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Compression failed, use uncompressed
|
|
118
|
+
compressedPayload = null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const finalPayload = isCompressed ? compressedPayload : payloadBytes;
|
|
122
|
+
// Build binary message
|
|
123
|
+
const parts = [];
|
|
124
|
+
// 1. Magic bytes (4 bytes)
|
|
125
|
+
parts.push(MAGIC_BYTES);
|
|
126
|
+
// 2. Version and flags (1 byte)
|
|
127
|
+
const flags = isCompressed ? COMPRESSION_FLAG : 0;
|
|
128
|
+
parts.push(new Uint8Array([BINARY_SCHEMA_VERSION | flags]));
|
|
129
|
+
// 3. Header (variable length)
|
|
130
|
+
const headerBytes = this.encodeHeader(envelope.header, isCompressed);
|
|
131
|
+
parts.push(this.encodeLength(headerBytes.length));
|
|
132
|
+
parts.push(headerBytes);
|
|
133
|
+
// 4. Signature (variable length)
|
|
134
|
+
const signatureBytes = this.textEncoder.encode(envelope.signature);
|
|
135
|
+
parts.push(this.encodeLength(signatureBytes.length));
|
|
136
|
+
parts.push(signatureBytes);
|
|
137
|
+
// 5. Signer public key (variable length)
|
|
138
|
+
const signerKeyBytes = this.textEncoder.encode(envelope.signerPublicKey);
|
|
139
|
+
parts.push(this.encodeLength(signerKeyBytes.length));
|
|
140
|
+
parts.push(signerKeyBytes);
|
|
141
|
+
// 6. Routing info (optional)
|
|
142
|
+
if (envelope.routing) {
|
|
143
|
+
parts.push(new Uint8Array([1])); // Has routing
|
|
144
|
+
const routingBytes = this.encodeRouting(envelope.routing);
|
|
145
|
+
parts.push(this.encodeLength(routingBytes.length));
|
|
146
|
+
parts.push(routingBytes);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
parts.push(new Uint8Array([0])); // No routing
|
|
150
|
+
}
|
|
151
|
+
// 7. Metadata (optional)
|
|
152
|
+
if (envelope.metadata) {
|
|
153
|
+
parts.push(new Uint8Array([1])); // Has metadata
|
|
154
|
+
const metadataBytes = this.encodeMetadata(envelope.metadata);
|
|
155
|
+
parts.push(this.encodeLength(metadataBytes.length));
|
|
156
|
+
parts.push(metadataBytes);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
parts.push(new Uint8Array([0])); // No metadata
|
|
160
|
+
}
|
|
161
|
+
// 8. Payload (variable length)
|
|
162
|
+
parts.push(this.encodeLength(finalPayload.length));
|
|
163
|
+
parts.push(finalPayload);
|
|
164
|
+
// Combine all parts
|
|
165
|
+
const totalLength = parts.reduce((sum, p) => sum + p.length, 0);
|
|
166
|
+
if (totalLength > types_1.MAX_MESSAGE_SIZE) {
|
|
167
|
+
throw new types_1.ProtocolError(`Message size ${totalLength} exceeds maximum ${types_1.MAX_MESSAGE_SIZE}`, types_1.ProtocolErrorCode.MESSAGE_TOO_LARGE);
|
|
168
|
+
}
|
|
169
|
+
const result = new Uint8Array(totalLength);
|
|
170
|
+
let offset = 0;
|
|
171
|
+
for (const part of parts) {
|
|
172
|
+
result.set(part, offset);
|
|
173
|
+
offset += part.length;
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Decode binary data to protocol envelope
|
|
179
|
+
*
|
|
180
|
+
* @param data - Binary data to decode
|
|
181
|
+
* @returns Protocol envelope
|
|
182
|
+
*/
|
|
183
|
+
async decode(data) {
|
|
184
|
+
if (data.length < 6) {
|
|
185
|
+
throw new types_1.ProtocolError('Message too short', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
186
|
+
}
|
|
187
|
+
let offset = 0;
|
|
188
|
+
// 1. Verify magic bytes
|
|
189
|
+
const magic = data.slice(0, 4);
|
|
190
|
+
if (!this.arrayEquals(magic, MAGIC_BYTES)) {
|
|
191
|
+
throw new types_1.ProtocolError('Invalid magic bytes', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
192
|
+
}
|
|
193
|
+
offset = 4;
|
|
194
|
+
// 2. Read version and flags
|
|
195
|
+
const versionAndFlags = data[offset++];
|
|
196
|
+
const version = versionAndFlags & 0x7f;
|
|
197
|
+
const isCompressed = (versionAndFlags & COMPRESSION_FLAG) !== 0;
|
|
198
|
+
if (version > BINARY_SCHEMA_VERSION) {
|
|
199
|
+
throw new types_1.ProtocolError(`Unsupported schema version ${version}`, types_1.ProtocolErrorCode.UNSUPPORTED_VERSION);
|
|
200
|
+
}
|
|
201
|
+
// 3. Read header
|
|
202
|
+
const { value: headerLength, bytesRead: headerLenBytes } = this.decodeLength(data.slice(offset));
|
|
203
|
+
offset += headerLenBytes;
|
|
204
|
+
const headerBytes = data.slice(offset, offset + headerLength);
|
|
205
|
+
offset += headerLength;
|
|
206
|
+
const header = this.decodeHeader(headerBytes, isCompressed);
|
|
207
|
+
// 4. Read signature
|
|
208
|
+
const { value: sigLength, bytesRead: sigLenBytes } = this.decodeLength(data.slice(offset));
|
|
209
|
+
offset += sigLenBytes;
|
|
210
|
+
const signature = this.textDecoder.decode(data.slice(offset, offset + sigLength));
|
|
211
|
+
offset += sigLength;
|
|
212
|
+
// 5. Read signer public key
|
|
213
|
+
const { value: keyLength, bytesRead: keyLenBytes } = this.decodeLength(data.slice(offset));
|
|
214
|
+
offset += keyLenBytes;
|
|
215
|
+
const signerPublicKey = this.textDecoder.decode(data.slice(offset, offset + keyLength));
|
|
216
|
+
offset += keyLength;
|
|
217
|
+
// 6. Read routing (optional)
|
|
218
|
+
const hasRouting = data[offset++] === 1;
|
|
219
|
+
let routing;
|
|
220
|
+
if (hasRouting) {
|
|
221
|
+
const { value: routingLength, bytesRead: routingLenBytes } = this.decodeLength(data.slice(offset));
|
|
222
|
+
offset += routingLenBytes;
|
|
223
|
+
const routingBytes = data.slice(offset, offset + routingLength);
|
|
224
|
+
offset += routingLength;
|
|
225
|
+
routing = this.decodeRouting(routingBytes);
|
|
226
|
+
}
|
|
227
|
+
// 7. Read metadata (optional)
|
|
228
|
+
const hasMetadata = data[offset++] === 1;
|
|
229
|
+
let metadata;
|
|
230
|
+
if (hasMetadata) {
|
|
231
|
+
const { value: metadataLength, bytesRead: metadataLenBytes } = this.decodeLength(data.slice(offset));
|
|
232
|
+
offset += metadataLenBytes;
|
|
233
|
+
const metadataBytes = data.slice(offset, offset + metadataLength);
|
|
234
|
+
offset += metadataLength;
|
|
235
|
+
metadata = this.decodeMetadata(metadataBytes);
|
|
236
|
+
}
|
|
237
|
+
// 8. Read payload
|
|
238
|
+
const { value: payloadLength, bytesRead: payloadLenBytes } = this.decodeLength(data.slice(offset));
|
|
239
|
+
offset += payloadLenBytes;
|
|
240
|
+
let payloadBytes = data.slice(offset, offset + payloadLength);
|
|
241
|
+
// Decompress if needed
|
|
242
|
+
if (isCompressed) {
|
|
243
|
+
payloadBytes = new Uint8Array(await this.decompress(payloadBytes));
|
|
244
|
+
}
|
|
245
|
+
const payloadJson = this.textDecoder.decode(payloadBytes);
|
|
246
|
+
const payload = JSON.parse(payloadJson);
|
|
247
|
+
return {
|
|
248
|
+
header,
|
|
249
|
+
payload,
|
|
250
|
+
signature,
|
|
251
|
+
signerPublicKey,
|
|
252
|
+
routing,
|
|
253
|
+
metadata,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Validate envelope structure
|
|
258
|
+
*/
|
|
259
|
+
validateEnvelope(envelope) {
|
|
260
|
+
if (!envelope.header) {
|
|
261
|
+
throw new types_1.ProtocolError('Missing header', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
262
|
+
}
|
|
263
|
+
if (!envelope.header.messageId) {
|
|
264
|
+
throw new types_1.ProtocolError('Missing message ID', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
265
|
+
}
|
|
266
|
+
if (!envelope.header.version) {
|
|
267
|
+
throw new types_1.ProtocolError('Missing protocol version', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
268
|
+
}
|
|
269
|
+
if (!envelope.signature) {
|
|
270
|
+
throw new types_1.ProtocolError('Missing signature', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
271
|
+
}
|
|
272
|
+
if (!envelope.signerPublicKey) {
|
|
273
|
+
throw new types_1.ProtocolError('Missing signer public key', types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
274
|
+
}
|
|
275
|
+
// Validate message type
|
|
276
|
+
if (!Object.values(types_1.MessageType).includes(envelope.header.type)) {
|
|
277
|
+
throw new types_1.ProtocolError(`Invalid message type: ${envelope.header.type}`, types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
278
|
+
}
|
|
279
|
+
// Validate priority
|
|
280
|
+
if (!Object.values(types_1.MessagePriority).includes(envelope.header.priority)) {
|
|
281
|
+
throw new types_1.ProtocolError(`Invalid priority: ${envelope.header.priority}`, types_1.ProtocolErrorCode.INVALID_MESSAGE);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get estimated encoded size without actually encoding
|
|
286
|
+
*/
|
|
287
|
+
estimateSize(envelope) {
|
|
288
|
+
const jsonPayload = JSON.stringify(envelope.payload);
|
|
289
|
+
const headerEstimate = 200; // Header typically ~150-200 bytes
|
|
290
|
+
const signatureEstimate = 128; // Base64 signature ~88 bytes + overhead
|
|
291
|
+
const routingEstimate = envelope.routing ? 100 : 0;
|
|
292
|
+
const metadataEstimate = envelope.metadata ? 100 : 0;
|
|
293
|
+
return (4 + // Magic
|
|
294
|
+
1 + // Version/flags
|
|
295
|
+
headerEstimate +
|
|
296
|
+
signatureEstimate +
|
|
297
|
+
jsonPayload.length +
|
|
298
|
+
routingEstimate +
|
|
299
|
+
metadataEstimate);
|
|
300
|
+
}
|
|
301
|
+
// ============================================
|
|
302
|
+
// Private Encoding Methods
|
|
303
|
+
// ============================================
|
|
304
|
+
/**
|
|
305
|
+
* Encode protocol header to binary
|
|
306
|
+
*/
|
|
307
|
+
encodeHeader(header, isCompressed) {
|
|
308
|
+
const obj = {
|
|
309
|
+
v: header.version,
|
|
310
|
+
id: header.messageId,
|
|
311
|
+
cid: header.correlationId,
|
|
312
|
+
t: this.encodeMessageType(header.type),
|
|
313
|
+
p: header.priority,
|
|
314
|
+
s: header.senderId,
|
|
315
|
+
r: header.recipientId,
|
|
316
|
+
ts: header.timestamp,
|
|
317
|
+
ttl: header.ttl,
|
|
318
|
+
hc: header.hopCount,
|
|
319
|
+
mh: header.maxHops,
|
|
320
|
+
c: isCompressed,
|
|
321
|
+
d: this.encodeDeliverySemantics(header.delivery),
|
|
322
|
+
rt: this.encodeRoutingMode(header.routing),
|
|
323
|
+
sv: header.schemaVersion,
|
|
324
|
+
};
|
|
325
|
+
return this.textEncoder.encode(JSON.stringify(obj));
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Decode protocol header from binary
|
|
329
|
+
*/
|
|
330
|
+
decodeHeader(data, isCompressed) {
|
|
331
|
+
const json = this.textDecoder.decode(data);
|
|
332
|
+
const obj = JSON.parse(json);
|
|
333
|
+
return {
|
|
334
|
+
version: obj.v || types_1.PROTOCOL_VERSION,
|
|
335
|
+
messageId: obj.id,
|
|
336
|
+
correlationId: obj.cid,
|
|
337
|
+
type: this.decodeMessageType(obj.t),
|
|
338
|
+
priority: obj.p ?? types_1.MessagePriority.NORMAL,
|
|
339
|
+
senderId: obj.s,
|
|
340
|
+
recipientId: obj.r,
|
|
341
|
+
timestamp: obj.ts,
|
|
342
|
+
ttl: obj.ttl,
|
|
343
|
+
hopCount: obj.hc ?? 0,
|
|
344
|
+
maxHops: obj.mh ?? 5,
|
|
345
|
+
compressed: isCompressed,
|
|
346
|
+
delivery: this.decodeDeliverySemantics(obj.d),
|
|
347
|
+
routing: this.decodeRoutingMode(obj.rt),
|
|
348
|
+
schemaVersion: obj.sv ?? 1,
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Encode routing info to binary
|
|
353
|
+
*/
|
|
354
|
+
encodeRouting(routing) {
|
|
355
|
+
const obj = {
|
|
356
|
+
m: this.encodeRoutingMode(routing.mode),
|
|
357
|
+
t: routing.targets,
|
|
358
|
+
r: routing.roomId,
|
|
359
|
+
p: routing.path,
|
|
360
|
+
rn: routing.relayNodes,
|
|
361
|
+
es: routing.excludeSender,
|
|
362
|
+
};
|
|
363
|
+
return this.textEncoder.encode(JSON.stringify(obj));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Decode routing info from binary
|
|
367
|
+
*/
|
|
368
|
+
decodeRouting(data) {
|
|
369
|
+
const json = this.textDecoder.decode(data);
|
|
370
|
+
const obj = JSON.parse(json);
|
|
371
|
+
return {
|
|
372
|
+
mode: this.decodeRoutingMode(obj.m),
|
|
373
|
+
targets: obj.t,
|
|
374
|
+
roomId: obj.r,
|
|
375
|
+
path: obj.p,
|
|
376
|
+
relayNodes: obj.rn,
|
|
377
|
+
excludeSender: obj.es,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Encode metadata to binary
|
|
382
|
+
*/
|
|
383
|
+
encodeMetadata(metadata) {
|
|
384
|
+
const obj = {
|
|
385
|
+
os: metadata.originalSize,
|
|
386
|
+
cs: metadata.compressedSize,
|
|
387
|
+
ch: metadata.channel,
|
|
388
|
+
tid: metadata.traceId,
|
|
389
|
+
sid: metadata.spanId,
|
|
390
|
+
psid: metadata.parentSpanId,
|
|
391
|
+
tags: metadata.tags,
|
|
392
|
+
rc: metadata.retryCount,
|
|
393
|
+
qt: metadata.queueTime,
|
|
394
|
+
};
|
|
395
|
+
return this.textEncoder.encode(JSON.stringify(obj));
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Decode metadata from binary
|
|
399
|
+
*/
|
|
400
|
+
decodeMetadata(data) {
|
|
401
|
+
const json = this.textDecoder.decode(data);
|
|
402
|
+
const obj = JSON.parse(json);
|
|
403
|
+
return {
|
|
404
|
+
originalSize: obj.os,
|
|
405
|
+
compressedSize: obj.cs,
|
|
406
|
+
channel: obj.ch,
|
|
407
|
+
traceId: obj.tid,
|
|
408
|
+
spanId: obj.sid,
|
|
409
|
+
parentSpanId: obj.psid,
|
|
410
|
+
tags: obj.tags,
|
|
411
|
+
retryCount: obj.rc,
|
|
412
|
+
queueTime: obj.qt,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Encode variable-length integer
|
|
417
|
+
*/
|
|
418
|
+
encodeLength(length) {
|
|
419
|
+
if (length < 128) {
|
|
420
|
+
return new Uint8Array([length]);
|
|
421
|
+
}
|
|
422
|
+
else if (length < 16384) {
|
|
423
|
+
return new Uint8Array([0x80 | (length >> 7), length & 0x7f]);
|
|
424
|
+
}
|
|
425
|
+
else if (length < 2097152) {
|
|
426
|
+
return new Uint8Array([
|
|
427
|
+
0x80 | (length >> 14),
|
|
428
|
+
0x80 | ((length >> 7) & 0x7f),
|
|
429
|
+
length & 0x7f,
|
|
430
|
+
]);
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
return new Uint8Array([
|
|
434
|
+
0x80 | (length >> 21),
|
|
435
|
+
0x80 | ((length >> 14) & 0x7f),
|
|
436
|
+
0x80 | ((length >> 7) & 0x7f),
|
|
437
|
+
length & 0x7f,
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Decode variable-length integer
|
|
443
|
+
*/
|
|
444
|
+
decodeLength(data) {
|
|
445
|
+
let value = 0;
|
|
446
|
+
let bytesRead = 0;
|
|
447
|
+
for (let i = 0; i < 4; i++) {
|
|
448
|
+
const byte = data[i];
|
|
449
|
+
bytesRead++;
|
|
450
|
+
if (byte & 0x80) {
|
|
451
|
+
value = (value << 7) | (byte & 0x7f);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
value = (value << 7) | byte;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return { value, bytesRead };
|
|
459
|
+
}
|
|
460
|
+
// ============================================
|
|
461
|
+
// Compression Methods
|
|
462
|
+
// ============================================
|
|
463
|
+
/**
|
|
464
|
+
* Compress data using CompressionStream API
|
|
465
|
+
*/
|
|
466
|
+
async compress(data) {
|
|
467
|
+
// Check if CompressionStream is available
|
|
468
|
+
if (typeof CompressionStream === 'undefined') {
|
|
469
|
+
// Fallback: use simple DEFLATE-like compression
|
|
470
|
+
return this.simpleCompress(data);
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
const stream = new CompressionStream('deflate-raw');
|
|
474
|
+
const writer = stream.writable.getWriter();
|
|
475
|
+
const reader = stream.readable.getReader();
|
|
476
|
+
// Write data - need to create a new buffer to satisfy TypeScript
|
|
477
|
+
const buffer = new Uint8Array(data).buffer;
|
|
478
|
+
writer.write(new Uint8Array(buffer));
|
|
479
|
+
writer.close();
|
|
480
|
+
// Read compressed data
|
|
481
|
+
const chunks = [];
|
|
482
|
+
while (true) {
|
|
483
|
+
const { done, value } = await reader.read();
|
|
484
|
+
if (done)
|
|
485
|
+
break;
|
|
486
|
+
chunks.push(value);
|
|
487
|
+
}
|
|
488
|
+
// Combine chunks
|
|
489
|
+
const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
490
|
+
const result = new Uint8Array(totalLength);
|
|
491
|
+
let offset = 0;
|
|
492
|
+
for (const chunk of chunks) {
|
|
493
|
+
result.set(chunk, offset);
|
|
494
|
+
offset += chunk.length;
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
throw new types_1.ProtocolError('Compression failed', types_1.ProtocolErrorCode.COMPRESSION_ERROR);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Decompress data using DecompressionStream API
|
|
504
|
+
*/
|
|
505
|
+
async decompress(data) {
|
|
506
|
+
// Check if DecompressionStream is available
|
|
507
|
+
if (typeof DecompressionStream === 'undefined') {
|
|
508
|
+
// Fallback: use simple decompression
|
|
509
|
+
return this.simpleDecompress(data);
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
const stream = new DecompressionStream('deflate-raw');
|
|
513
|
+
const writer = stream.writable.getWriter();
|
|
514
|
+
const reader = stream.readable.getReader();
|
|
515
|
+
// Write compressed data - need to create a new buffer to satisfy TypeScript
|
|
516
|
+
const buffer = new Uint8Array(data).buffer;
|
|
517
|
+
writer.write(new Uint8Array(buffer));
|
|
518
|
+
writer.close();
|
|
519
|
+
// Read decompressed data
|
|
520
|
+
const chunks = [];
|
|
521
|
+
while (true) {
|
|
522
|
+
const { done, value } = await reader.read();
|
|
523
|
+
if (done)
|
|
524
|
+
break;
|
|
525
|
+
chunks.push(value);
|
|
526
|
+
}
|
|
527
|
+
// Combine chunks
|
|
528
|
+
const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
|
|
529
|
+
const result = new Uint8Array(totalLength);
|
|
530
|
+
let offset = 0;
|
|
531
|
+
for (const chunk of chunks) {
|
|
532
|
+
result.set(chunk, offset);
|
|
533
|
+
offset += chunk.length;
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
throw new types_1.ProtocolError('Decompression failed', types_1.ProtocolErrorCode.DECOMPRESSION_ERROR);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Simple compression fallback (RLE-like)
|
|
543
|
+
*/
|
|
544
|
+
simpleCompress(data) {
|
|
545
|
+
// Very simple run-length encoding for repeated bytes
|
|
546
|
+
const output = [];
|
|
547
|
+
let i = 0;
|
|
548
|
+
while (i < data.length) {
|
|
549
|
+
const byte = data[i];
|
|
550
|
+
let count = 1;
|
|
551
|
+
// Count consecutive identical bytes (max 127)
|
|
552
|
+
while (i + count < data.length && data[i + count] === byte && count < 127) {
|
|
553
|
+
count++;
|
|
554
|
+
}
|
|
555
|
+
if (count >= 3) {
|
|
556
|
+
// Encode as RLE: [0xFF, count, byte]
|
|
557
|
+
output.push(0xff, count, byte);
|
|
558
|
+
i += count;
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
// Literal byte (escape 0xFF with another 0xFF)
|
|
562
|
+
if (byte === 0xff) {
|
|
563
|
+
output.push(0xff, 0x00);
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
output.push(byte);
|
|
567
|
+
}
|
|
568
|
+
i++;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return new Uint8Array(output);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Simple decompression fallback
|
|
575
|
+
*/
|
|
576
|
+
simpleDecompress(data) {
|
|
577
|
+
const output = [];
|
|
578
|
+
let i = 0;
|
|
579
|
+
while (i < data.length) {
|
|
580
|
+
const byte = data[i];
|
|
581
|
+
if (byte === 0xff) {
|
|
582
|
+
const next = data[i + 1];
|
|
583
|
+
if (next === 0x00) {
|
|
584
|
+
// Escaped 0xFF
|
|
585
|
+
output.push(0xff);
|
|
586
|
+
i += 2;
|
|
587
|
+
}
|
|
588
|
+
else if (next > 0) {
|
|
589
|
+
// RLE: repeat data[i+2] for 'next' times
|
|
590
|
+
const repeatByte = data[i + 2];
|
|
591
|
+
for (let j = 0; j < next; j++) {
|
|
592
|
+
output.push(repeatByte);
|
|
593
|
+
}
|
|
594
|
+
i += 3;
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
throw new types_1.ProtocolError('Invalid RLE encoding', types_1.ProtocolErrorCode.DECOMPRESSION_ERROR);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
output.push(byte);
|
|
602
|
+
i++;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return new Uint8Array(output);
|
|
606
|
+
}
|
|
607
|
+
// ============================================
|
|
608
|
+
// Type Encoding Helpers
|
|
609
|
+
// ============================================
|
|
610
|
+
encodeMessageType(type) {
|
|
611
|
+
const map = {
|
|
612
|
+
[types_1.MessageType.REQUEST]: 0,
|
|
613
|
+
[types_1.MessageType.RESPONSE]: 1,
|
|
614
|
+
[types_1.MessageType.EVENT]: 2,
|
|
615
|
+
[types_1.MessageType.HEARTBEAT]: 3,
|
|
616
|
+
[types_1.MessageType.ERROR]: 4,
|
|
617
|
+
[types_1.MessageType.ACK]: 5,
|
|
618
|
+
[types_1.MessageType.NACK]: 6,
|
|
619
|
+
[types_1.MessageType.HANDSHAKE]: 7,
|
|
620
|
+
[types_1.MessageType.HANDSHAKE_ACK]: 8,
|
|
621
|
+
[types_1.MessageType.CLOSE]: 9,
|
|
622
|
+
};
|
|
623
|
+
return map[type] ?? 0;
|
|
624
|
+
}
|
|
625
|
+
decodeMessageType(value) {
|
|
626
|
+
const map = {
|
|
627
|
+
0: types_1.MessageType.REQUEST,
|
|
628
|
+
1: types_1.MessageType.RESPONSE,
|
|
629
|
+
2: types_1.MessageType.EVENT,
|
|
630
|
+
3: types_1.MessageType.HEARTBEAT,
|
|
631
|
+
4: types_1.MessageType.ERROR,
|
|
632
|
+
5: types_1.MessageType.ACK,
|
|
633
|
+
6: types_1.MessageType.NACK,
|
|
634
|
+
7: types_1.MessageType.HANDSHAKE,
|
|
635
|
+
8: types_1.MessageType.HANDSHAKE_ACK,
|
|
636
|
+
9: types_1.MessageType.CLOSE,
|
|
637
|
+
};
|
|
638
|
+
return map[value] ?? types_1.MessageType.REQUEST;
|
|
639
|
+
}
|
|
640
|
+
encodeDeliverySemantics(delivery) {
|
|
641
|
+
const map = {
|
|
642
|
+
[types_1.DeliverySemantics.AT_MOST_ONCE]: 0,
|
|
643
|
+
[types_1.DeliverySemantics.AT_LEAST_ONCE]: 1,
|
|
644
|
+
[types_1.DeliverySemantics.EXACTLY_ONCE]: 2,
|
|
645
|
+
};
|
|
646
|
+
return map[delivery] ?? 1;
|
|
647
|
+
}
|
|
648
|
+
decodeDeliverySemantics(value) {
|
|
649
|
+
const map = {
|
|
650
|
+
0: types_1.DeliverySemantics.AT_MOST_ONCE,
|
|
651
|
+
1: types_1.DeliverySemantics.AT_LEAST_ONCE,
|
|
652
|
+
2: types_1.DeliverySemantics.EXACTLY_ONCE,
|
|
653
|
+
};
|
|
654
|
+
return map[value] ?? types_1.DeliverySemantics.AT_LEAST_ONCE;
|
|
655
|
+
}
|
|
656
|
+
encodeRoutingMode(mode) {
|
|
657
|
+
const map = {
|
|
658
|
+
[types_1.RoutingMode.UNICAST]: 0,
|
|
659
|
+
[types_1.RoutingMode.BROADCAST]: 1,
|
|
660
|
+
[types_1.RoutingMode.MULTICAST]: 2,
|
|
661
|
+
[types_1.RoutingMode.RELAY]: 3,
|
|
662
|
+
};
|
|
663
|
+
return map[mode] ?? 0;
|
|
664
|
+
}
|
|
665
|
+
decodeRoutingMode(value) {
|
|
666
|
+
const map = {
|
|
667
|
+
0: types_1.RoutingMode.UNICAST,
|
|
668
|
+
1: types_1.RoutingMode.BROADCAST,
|
|
669
|
+
2: types_1.RoutingMode.MULTICAST,
|
|
670
|
+
3: types_1.RoutingMode.RELAY,
|
|
671
|
+
};
|
|
672
|
+
return map[value] ?? types_1.RoutingMode.UNICAST;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Compare two Uint8Arrays for equality
|
|
676
|
+
*/
|
|
677
|
+
arrayEquals(a, b) {
|
|
678
|
+
if (a.length !== b.length)
|
|
679
|
+
return false;
|
|
680
|
+
for (let i = 0; i < a.length; i++) {
|
|
681
|
+
if (a[i] !== b[i])
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
exports.MessageEncoder = MessageEncoder;
|
|
688
|
+
// ============================================
|
|
689
|
+
// JSON Encoder (Fallback)
|
|
690
|
+
// ============================================
|
|
691
|
+
/**
|
|
692
|
+
* JSON-based encoder for debugging and compatibility
|
|
693
|
+
*/
|
|
694
|
+
class JsonMessageEncoder {
|
|
695
|
+
/**
|
|
696
|
+
* Encode envelope to JSON string
|
|
697
|
+
*/
|
|
698
|
+
encode(envelope) {
|
|
699
|
+
return JSON.stringify(envelope);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Decode JSON string to envelope
|
|
703
|
+
*/
|
|
704
|
+
decode(data) {
|
|
705
|
+
return JSON.parse(data);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Encode envelope to Uint8Array (UTF-8 JSON)
|
|
709
|
+
*/
|
|
710
|
+
encodeBinary(envelope) {
|
|
711
|
+
const json = this.encode(envelope);
|
|
712
|
+
return new TextEncoder().encode(json);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Decode Uint8Array (UTF-8 JSON) to envelope
|
|
716
|
+
*/
|
|
717
|
+
decodeBinary(data) {
|
|
718
|
+
const json = new TextDecoder().decode(data);
|
|
719
|
+
return this.decode(json);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
exports.JsonMessageEncoder = JsonMessageEncoder;
|
|
723
|
+
// ============================================
|
|
724
|
+
// Factory Functions
|
|
725
|
+
// ============================================
|
|
726
|
+
/**
|
|
727
|
+
* Create a new message encoder
|
|
728
|
+
*/
|
|
729
|
+
function createMessageEncoder() {
|
|
730
|
+
return new MessageEncoder();
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Create a new JSON encoder (for debugging)
|
|
734
|
+
*/
|
|
735
|
+
function createJsonEncoder() {
|
|
736
|
+
return new JsonMessageEncoder();
|
|
737
|
+
}
|
|
738
|
+
//# sourceMappingURL=MessageEncoder.js.map
|