agent-comms 1.28.0 → 1.29.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -1
- package/dist/core/comms-store.d.ts +4 -37
- package/dist/core/comms-store.d.ts.map +1 -1
- package/dist/core/comms-store.js +3 -3
- package/dist/core/identity-store.d.ts.map +1 -1
- package/dist/core/identity-store.js +2 -1
- package/dist/core/identity-store.js.map +1 -1
- package/dist/core/identity.d.ts +6 -0
- package/dist/core/identity.d.ts.map +1 -1
- package/dist/core/identity.js +17 -0
- package/dist/core/identity.js.map +1 -1
- package/dist/core/mesh-store.d.ts +12 -3
- package/dist/core/mesh-store.d.ts.map +1 -1
- package/dist/core/mesh-store.js +52 -33
- package/dist/core/mesh-store.js.map +1 -1
- package/dist/core/store.d.ts +1 -27
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +0 -62
- package/dist/core/store.js.map +1 -1
- package/dist/core/tls-transport.d.ts +12 -9
- package/dist/core/tls-transport.d.ts.map +1 -1
- package/dist/core/tls-transport.js +62 -25
- package/dist/core/tls-transport.js.map +1 -1
- package/dist/core/tool.d.ts +34 -5
- package/dist/core/tool.d.ts.map +1 -1
- package/dist/core/tool.js +41 -0
- package/dist/core/tool.js.map +1 -1
- package/dist/core/wire-protocol.d.ts +3 -2
- package/dist/core/wire-protocol.d.ts.map +1 -1
- package/dist/core/wire-protocol.js +3 -2
- package/dist/core/wire-protocol.js.map +1 -1
- package/dist/test/approval.integration.test.js +320 -285
- package/dist/test/approval.integration.test.js.map +1 -1
- package/dist/test/become-coordinator-actual-port.integration.test.js +0 -19
- package/dist/test/become-coordinator-actual-port.integration.test.js.map +1 -1
- package/dist/test/coordinator-socket-error.integration.test.js +2 -0
- package/dist/test/coordinator-socket-error.integration.test.js.map +1 -1
- package/dist/test/delivery-receipt.helper.js +15 -0
- package/dist/test/delivery-receipt.helper.js.map +1 -1
- package/dist/test/downtime-replay.test.js +5 -2
- package/dist/test/downtime-replay.test.js.map +1 -1
- package/dist/test/federation.integration.test.js +2 -0
- package/dist/test/federation.integration.test.js.map +1 -1
- package/dist/test/identity-device-id.test.d.ts +5 -0
- package/dist/test/identity-device-id.test.d.ts.map +1 -0
- package/dist/test/identity-device-id.test.js +35 -0
- package/dist/test/identity-device-id.test.js.map +1 -0
- package/dist/test/listener-policy.integration.test.js +214 -158
- package/dist/test/listener-policy.integration.test.js.map +1 -1
- package/dist/test/mesh-e2e.integration.test.js +2 -0
- package/dist/test/mesh-e2e.integration.test.js.map +1 -1
- package/dist/test/mesh-smoke.integration.test.d.ts +2 -4
- package/dist/test/mesh-smoke.integration.test.d.ts.map +1 -1
- package/dist/test/mesh-smoke.integration.test.js +28 -5
- package/dist/test/mesh-smoke.integration.test.js.map +1 -1
- package/dist/test/state-sync-convergence.test.js +5 -2
- package/dist/test/state-sync-convergence.test.js.map +1 -1
- package/dist/test/test-transport.d.ts +8 -0
- package/dist/test/test-transport.d.ts.map +1 -0
- package/dist/test/test-transport.js +29 -0
- package/dist/test/test-transport.js.map +1 -0
- package/dist/test/visibility.integration.test.js +6 -0
- package/dist/test/visibility.integration.test.js.map +1 -1
- package/package.json +2 -2
- package/dist/core/tcp-transport.d.ts +0 -85
- package/dist/core/tcp-transport.d.ts.map +0 -1
- package/dist/core/tcp-transport.js +0 -659
- package/dist/core/tcp-transport.js.map +0 -1
- package/dist/core/ws-transport.d.ts +0 -79
- package/dist/core/ws-transport.d.ts.map +0 -1
- package/dist/core/ws-transport.js +0 -622
- package/dist/core/ws-transport.js.map +0 -1
- package/dist/test/ws-broadcast-window.integration.test.d.ts +0 -7
- package/dist/test/ws-broadcast-window.integration.test.d.ts.map +0 -1
- package/dist/test/ws-broadcast-window.integration.test.js +0 -94
- package/dist/test/ws-broadcast-window.integration.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ExaDev/agent-comms)
|
|
4
4
|
[](https://www.npmjs.com/package/agent-comms)
|
|
5
|
-
[](https://github.com/ExaDev/agent-comms/releases/tag/v1.29.0)
|
|
6
6
|
[](https://github.com/ExaDev/agent-comms/actions)
|
|
7
7
|
|
|
8
8
|
Cross-harness communication mesh for LLM agents: rooms, DMs, presence, and visibility over TCP with zero filesystem dependencies.
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CommsStore — abstract interface for the agent communication store.
|
|
3
3
|
*
|
|
4
|
-
* Two implementations:
|
|
5
|
-
* FileStore — filesystem-backed, no server process (fallback)
|
|
6
|
-
* MeshStore — TCP peer mesh, in-memory, real-time push (preferred)
|
|
4
|
+
* Two implementations: FileStore — filesystem-backed, no server process (fallback) MeshStore — TCP peer mesh, in-memory, real-time push (preferred)
|
|
7
5
|
*
|
|
8
6
|
* Bridges depend on this interface, not on a specific implementation.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately excludes listener management, federation, and connection approval: those are transport concerns MeshStore alone can support -- FileStore has no network transport to manage listeners on, federate through, or approve inbound connections for. Widening this interface to cover them (as it once did, via always-throwing FileStore stubs) is what forced server.ts and the bridge controller to reach past CommsStore into the concrete MeshStore anyway; CommsTool, the one consumer that genuinely needs to expose these when a MeshStore backs it, takes them as an optional extension (see MeshOnlyFeatures in tool.ts) rather than the shared interface pretending every implementation supports them.
|
|
9
9
|
*/
|
|
10
|
-
import type { AgentIdentity, DeliveryEvent, DmMessage,
|
|
11
|
-
import type { ListenerInfo } from "./transport.js";
|
|
12
|
-
import type { FedLink } from "./federation.js";
|
|
10
|
+
import type { AgentIdentity, DeliveryEvent, DmMessage, Room, RoomMessage, RoomType, StreamingBehavior, Visibility } from "./types.js";
|
|
13
11
|
export interface CommsStore {
|
|
14
12
|
readIdentity(harness: string, cwd: string): Promise<{
|
|
15
13
|
id: string;
|
|
@@ -46,37 +44,6 @@ export interface CommsStore {
|
|
|
46
44
|
sendDm(from: string, to: string, content: string, streamingBehavior?: StreamingBehavior): Promise<DmMessage>;
|
|
47
45
|
deliver(agentId: string, event: DeliveryEvent): Promise<void>;
|
|
48
46
|
drainDelivery(agentId: string): Promise<DeliveryEvent[]>;
|
|
49
|
-
addListener(host: string, port: number, policy: string): Promise<string>;
|
|
50
|
-
removeListener(id: string): Promise<void>;
|
|
51
|
-
listListeners(): ListenerInfo[];
|
|
52
|
-
getNetworkInterfaces(): NetworkInterface[];
|
|
53
|
-
fedConnect(host: string, port: number, name?: string): Promise<string>;
|
|
54
|
-
fedDisconnect(linkId: string): Promise<void>;
|
|
55
|
-
fedLinks(): FedLink[];
|
|
56
|
-
/** This instance's own federation TLS fingerprint, to hand to an operator on the other side to pin. */
|
|
57
|
-
getFederationFingerprint(): string;
|
|
58
|
-
/** Pin a remote mesh's certificate fingerprint as trusted for federation, inbound or outbound. */
|
|
59
|
-
fedTrust(fingerprint: string): Promise<void>;
|
|
60
|
-
/** Remove a previously pinned federation fingerprint. */
|
|
61
|
-
fedUntrust(fingerprint: string): Promise<void>;
|
|
62
|
-
/** List currently trusted federation fingerprints. */
|
|
63
|
-
fedTrustedFingerprints(): string[];
|
|
64
|
-
/** Start accepting inbound federation links on host:port. Rejects any connection whose certificate isn't pinned via fedTrust(). */
|
|
65
|
-
fedListen(host: string, port: number): Promise<void>;
|
|
66
|
-
/** Stop accepting new inbound federation connections. Existing links are unaffected. */
|
|
67
|
-
fedStopListening(): Promise<void>;
|
|
68
|
-
acceptConnection(connectionId: string): Promise<void>;
|
|
69
|
-
rejectConnection(connectionId: string, reason: string): Promise<void>;
|
|
70
|
-
listPendingConnections(): {
|
|
71
|
-
connectionId: string;
|
|
72
|
-
peerId: string;
|
|
73
|
-
dataPort: number;
|
|
74
|
-
name: string;
|
|
75
|
-
fingerprint: string;
|
|
76
|
-
}[];
|
|
77
|
-
connectToRemote(host: string, port: number): Promise<void>;
|
|
78
|
-
/** Start only the data server without connecting to a coordinator. */
|
|
79
|
-
startDataServerOnly(): Promise<void>;
|
|
80
47
|
init(): Promise<void>;
|
|
81
48
|
}
|
|
82
49
|
//# sourceMappingURL=comms-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comms-store.d.ts","sourceRoot":"","sources":["../../src/core/comms-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"comms-store.d.ts","sourceRoot":"","sources":["../../src/core/comms-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,UAAU;IAEzB,YAAY,CACV,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IACvC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGvE,aAAa,CAAC,IAAI,EAAE;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,UAAU,EAAE,UAAU,CAAC;QACvB,IAAI,EAAE,MAAM,EAAE,CAAC;KAChB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACzD,WAAW,CACT,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CACZ,IAAI,CAAC,aAAa,EA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,OAAO,CAAC,IAAI,CAAC,CAAC;IAG5D,eAAe,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,iBAAiB,GACpC,OAAO,CAAC,WAAW,CAAC,CAAC;IACxB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAGzE,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,iBAAiB,GACpC,OAAO,CAAC,SAAS,CAAC,CAAC;IAGtB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAGzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
package/dist/core/comms-store.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CommsStore — abstract interface for the agent communication store.
|
|
3
3
|
*
|
|
4
|
-
* Two implementations:
|
|
5
|
-
* FileStore — filesystem-backed, no server process (fallback)
|
|
6
|
-
* MeshStore — TCP peer mesh, in-memory, real-time push (preferred)
|
|
4
|
+
* Two implementations: FileStore — filesystem-backed, no server process (fallback) MeshStore — TCP peer mesh, in-memory, real-time push (preferred)
|
|
7
5
|
*
|
|
8
6
|
* Bridges depend on this interface, not on a specific implementation.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately excludes listener management, federation, and connection approval: those are transport concerns MeshStore alone can support -- FileStore has no network transport to manage listeners on, federate through, or approve inbound connections for. Widening this interface to cover them (as it once did, via always-throwing FileStore stubs) is what forced server.ts and the bridge controller to reach past CommsStore into the concrete MeshStore anyway; CommsTool, the one consumer that genuinely needs to expose these when a MeshStore backs it, takes them as an optional extension (see MeshOnlyFeatures in tool.ts) rather than the shared interface pretending every implementation supports them.
|
|
9
9
|
*/
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=comms-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-store.d.ts","sourceRoot":"","sources":["../../src/core/identity-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"identity-store.d.ts","sourceRoot":"","sources":["../../src/core/identity-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,4EAA4E;AAC5E,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAkFD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAgBrE;AAsCD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAK5D"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import * as fs from "node:fs";
|
|
9
9
|
import * as os from "node:os";
|
|
10
10
|
import * as path from "node:path";
|
|
11
|
-
import { generateIdentity, getCertificateFingerprint, CERTIFICATE_VALIDITY_MS, } from "./identity.js";
|
|
11
|
+
import { generateIdentity, getCertificateFingerprint, deriveDeviceId, CERTIFICATE_VALIDITY_MS, } from "./identity.js";
|
|
12
12
|
/** Renew during the final twelfth of the certificate's validity. */
|
|
13
13
|
const RENEWAL_MARGIN_MS = CERTIFICATE_VALIDITY_MS / 12;
|
|
14
14
|
function isStoredIdentity(value) {
|
|
@@ -105,6 +105,7 @@ function loadStoredIdentity(identityFile) {
|
|
|
105
105
|
privateKey: parsed.privateKey,
|
|
106
106
|
certificate: parsed.certificate,
|
|
107
107
|
fingerprint: getCertificateFingerprint(parsed.certificate),
|
|
108
|
+
deviceId: deriveDeviceId(parsed.privateKey),
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-store.js","sourceRoot":"","sources":["../../src/core/identity-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,eAAe,CAAC;AAWvB,oEAAoE;AACpE,MAAM,iBAAiB,GAAG,uBAAuB,GAAG,EAAE,CAAC;AAQvD,SAAS,gBAAgB,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,IACE,CAAC,CAAC,YAAY,IAAI,KAAK,CAAC;QACxB,CAAC,CAAC,aAAa,IAAI,KAAK,CAAC;QACzB,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC;QAEvB,OAAO,KAAK,CAAC;IACf,OAAO,CACL,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QACpC,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ;QACrC,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,CACpC,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,SAAS,CAAC,IAAkB;IAKnC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IA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mBAAmB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,CACnJ,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,YAAoB;IAC1C,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;IACpC,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAkB;IACpD,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,WAAW,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC;QAC1C,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
package/dist/core/identity.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface PeerIdentity {
|
|
|
19
19
|
certificate: string;
|
|
20
20
|
/** SHA-256 fingerprint of the certificate (DER), hex-encoded with colons. */
|
|
21
21
|
fingerprint: string;
|
|
22
|
+
/**
|
|
23
|
+
* SHA-256 of the raw, uncompressed SEC1 public-key point -- wire-mesh's own device-id derivation (never the certificate's DER encoding, which embeds a serial number and validity window that change on every reissue even for an identical key; this is the exact instability fingerprint already has). Additive: nothing in this codebase reads it yet. `fingerprint` remains what MeshStore.peerId is set to until the substrate migration cuts over to this field instead.
|
|
24
|
+
*/
|
|
25
|
+
deviceId: Uint8Array;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* Generate a fresh cryptographic identity: ECDSA P-256 keypair and self-signed
|
|
@@ -38,4 +42,6 @@ export declare function getCertificateFingerprint(certificate: string): string;
|
|
|
38
42
|
* Compute the SHA-256 fingerprint of a certificate already presented as raw DER bytes — the shape `tls.TLSSocket.getPeerCertificate().raw` returns for a live connection. Same hashing and formatting as `getCertificateFingerprint`, so a value pinned from a PEM certificate compares equal to the fingerprint of that same certificate presented live over a socket.
|
|
39
43
|
*/
|
|
40
44
|
export declare function fingerprintDer(der: Buffer): string;
|
|
45
|
+
/** Derives wire-mesh's own device-id (SHA-256 of the raw, uncompressed SEC1 public-key point) from a PEM-encoded EC private key. */
|
|
46
|
+
export declare function deriveDeviceId(privateKeyPem: string): Uint8Array;
|
|
41
47
|
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,QAA4B,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;CACtB;AA6MD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAsE/C;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGrE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKlD;AAaD,oIAAoI;AACpI,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,CAYhE"}
|
package/dist/core/identity.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* fingerprint (and therefore the peer/agent ID) stable.
|
|
12
12
|
*/
|
|
13
13
|
import { createHash, createPublicKey, createSign, generateKeyPairSync, randomBytes, } from "node:crypto";
|
|
14
|
+
/** The uncompressed SEC1 point tag byte (RFC 5480 §2.2): 0x04 marks what follows as raw X||Y, never compressed or hybrid encoding. */
|
|
15
|
+
const UNCOMPRESSED_POINT_TAG = 0x04;
|
|
14
16
|
// ─── Types ──────────────────────────────────────────────────────────────────
|
|
15
17
|
/** Self-signed certificate validity. Exported so identity persistence can derive its renewal margin. */
|
|
16
18
|
export const CERTIFICATE_VALIDITY_MS = 365 * 24 * 60 * 60 * 1000;
|
|
@@ -224,6 +226,7 @@ export function generateIdentity() {
|
|
|
224
226
|
privateKey: keyPair.privateKey,
|
|
225
227
|
certificate,
|
|
226
228
|
fingerprint: getCertificateFingerprint(certificate),
|
|
229
|
+
deviceId: deriveDeviceId(keyPair.privateKey),
|
|
227
230
|
};
|
|
228
231
|
}
|
|
229
232
|
/**
|
|
@@ -253,6 +256,20 @@ function pemToDer(pem) {
|
|
|
253
256
|
.replace(/\s/g, "");
|
|
254
257
|
return Buffer.from(b64, "base64");
|
|
255
258
|
}
|
|
259
|
+
/** Derives wire-mesh's own device-id (SHA-256 of the raw, uncompressed SEC1 public-key point) from a PEM-encoded EC private key. */
|
|
260
|
+
export function deriveDeviceId(privateKeyPem) {
|
|
261
|
+
const publicKey = createPublicKey(privateKeyPem);
|
|
262
|
+
const jwk = publicKey.export({ format: "jwk" });
|
|
263
|
+
if (jwk.x === undefined || jwk.y === undefined) {
|
|
264
|
+
throw new Error("expected an EC JWK with x/y coordinates");
|
|
265
|
+
}
|
|
266
|
+
const rawPublicKey = Buffer.concat([
|
|
267
|
+
Buffer.from([UNCOMPRESSED_POINT_TAG]),
|
|
268
|
+
Buffer.from(jwk.x, "base64url"),
|
|
269
|
+
Buffer.from(jwk.y, "base64url"),
|
|
270
|
+
]);
|
|
271
|
+
return createHash("sha256").update(rawPublicKey).digest();
|
|
272
|
+
}
|
|
256
273
|
/** Encode DER bytes as a PEM certificate string. */
|
|
257
274
|
function derToCertificatePem(der) {
|
|
258
275
|
const b64 = der.toString("base64").match(/.{1,64}/g);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,+EAA+E;AAE/E,wGAAwG;AACxG,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,UAAU,EACV,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,sIAAsI;AACtI,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,+EAA+E;AAE/E,wGAAwG;AACxG,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAejE,8EAA8E;AAE9E,iCAAiC;AACjC,SAAS,SAAS,CAAC,MAAc;IAC/B,IAAI,MAAM,GAAG,IAAI;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,IAAI,MAAM,GAAG,KAAK;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC;AAED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C;AAED,oIAAoI;AACpI,MAAM,UAAU,cAAc,CAAC,aAAqB;IAClD,MAAM,SAAS,GAAG,eAAe,CAAC,aAAa,CAAC,CAAC;IACjD,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAChD,IAAI,GAAG,CAAC,CAAC,KAAK,SAAS,IAAI,GAAG,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,CAAC,sBAAsB,CAAC,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC;KAChC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC;AAC5D,CAAC;AAED,oDAAoD;AACpD,SAAS,mBAAmB,CAAC,GAAW;IACtC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,GAAG,IAAI,EAAE,CAAC;IACxB,OAAO;QACL,6BAA6B;QAC7B,GAAG,KAAK;QACR,2BAA2B;QAC3B,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
* Delivery events are pushed directly over the transport — no polling,
|
|
8
8
|
* no filesystem.
|
|
9
9
|
*
|
|
10
|
-
* Transport is
|
|
11
|
-
*
|
|
10
|
+
* Transport is set via setTransport() (e.g. TlsTransport for encrypted
|
|
11
|
+
* connections) before init() or any other transport-using method is called
|
|
12
|
+
* -- there is no default, since every real bridge builds its own transport
|
|
13
|
+
* from this store's own events getter, which needs the store to already
|
|
14
|
+
* exist.
|
|
12
15
|
*/
|
|
13
16
|
import type { SerialisedState } from "./wire-protocol.js";
|
|
14
17
|
import { DiscoveryManager } from "./discovery.js";
|
|
@@ -41,6 +44,10 @@ export declare class MeshStore implements CommsStore {
|
|
|
41
44
|
onDelivery: ((agentId: string, event: DeliveryEvent) => void | Promise<void>) | undefined;
|
|
42
45
|
/** Fires for every state patch — both locally generated and remote. */
|
|
43
46
|
onPatch: ((patch: MeshStatePatch) => void | Promise<void>) | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Fires for a transport-level error a caller may want to observe (a connection rejected for presenting a certificate that doesn't match its claimed peer ID, this store's own inability to join or create a mesh, etc). Previously wired to `this.events.onError` inside this class's own methods, but the `events` getter never actually implemented `onError` on the object it returns, so every one of those calls was silently a no-op -- this store had no way to observe its own transport failures at all. Left undefined by default (matching onDelivery/onPatch): a caller that wants visibility sets it, exactly like those two.
|
|
49
|
+
*/
|
|
50
|
+
onError: ((error: Error) => void) | undefined;
|
|
44
51
|
/** Serialise the full mesh state for state_sync messages. */
|
|
45
52
|
serialise(): SerialisedState;
|
|
46
53
|
private lastLocalDeliveryKey;
|
|
@@ -48,8 +55,10 @@ export declare class MeshStore implements CommsStore {
|
|
|
48
55
|
discovery: DiscoveryManager;
|
|
49
56
|
federation: FederationManager;
|
|
50
57
|
constructor(coordinatorPort?: number);
|
|
51
|
-
/**
|
|
58
|
+
/** Sets the transport (e.g. TlsTransport for encrypted connections). Must be called before init() or any other transport-using method. */
|
|
52
59
|
setTransport(transport: MeshTransport): void;
|
|
60
|
+
/** The set transport, or throws if setTransport() hasn't been called yet -- the single place every transport-using method reads through, so the "must call setTransport() first" contract is enforced at one boundary rather than checked ad hoc at each call site. */
|
|
61
|
+
private requireTransport;
|
|
53
62
|
init(): Promise<void>;
|
|
54
63
|
private handlePeerList;
|
|
55
64
|
private handlePeerJoined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh-store.d.ts","sourceRoot":"","sources":["../../src/core/mesh-store.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mesh-store.d.ts","sourceRoot":"","sources":["../../src/core/mesh-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EAAe,cAAc,EAAY,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAEV,aAAa,EACb,eAAe,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EAEb,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,gBAAgB,CAAC;AA2CnE,qBAAa,SAAU,YAAW,UAAU;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,QAAQ,CAAoC;IACpD,OAAO,CAAC,GAAG,CAAkC;IAC7C,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,aAAa,CAAqC;IAE1D,OAAO,CAAC,SAAS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no polling,
|
|
8
8
|
* no filesystem.
|
|
9
9
|
*
|
|
10
|
-
* Transport is
|
|
11
|
-
*
|
|
10
|
+
* Transport is set via setTransport() (e.g. TlsTransport for encrypted
|
|
11
|
+
* connections) before init() or any other transport-using method is called
|
|
12
|
+
* -- there is no default, since every real bridge builds its own transport
|
|
13
|
+
* from this store's own events getter, which needs the store to already
|
|
14
|
+
* exist.
|
|
12
15
|
*/
|
|
13
16
|
import * as os from "node:os";
|
|
14
17
|
import { nanoid } from "./nanoid.js";
|
|
15
18
|
import { CommsError } from "./store.js";
|
|
16
|
-
import { TcpTransport } from "./tcp-transport.js";
|
|
17
19
|
import { dmKey, normaliseWireState } from "./wire-protocol.js";
|
|
18
20
|
import { DiscoveryManager } from "./discovery.js";
|
|
19
21
|
import { MdnsDiscoveryBackend } from "./discovery-mdns.js";
|
|
@@ -72,13 +74,18 @@ export class MeshStore {
|
|
|
72
74
|
pendingMarkReadTimers = [];
|
|
73
75
|
/** Whether the mesh has a live coordinator connection. */
|
|
74
76
|
get connected() {
|
|
75
|
-
return (this.
|
|
77
|
+
return (this.requireTransport().isCoordinator ||
|
|
78
|
+
this.requireTransport().hasCoordinatorConnection);
|
|
76
79
|
}
|
|
77
80
|
// -- Pending inbound connections awaiting approval --
|
|
78
81
|
pendingInboundConnections = new Map();
|
|
79
82
|
onDelivery;
|
|
80
83
|
/** Fires for every state patch — both locally generated and remote. */
|
|
81
84
|
onPatch;
|
|
85
|
+
/**
|
|
86
|
+
* Fires for a transport-level error a caller may want to observe (a connection rejected for presenting a certificate that doesn't match its claimed peer ID, this store's own inability to join or create a mesh, etc). Previously wired to `this.events.onError` inside this class's own methods, but the `events` getter never actually implemented `onError` on the object it returns, so every one of those calls was silently a no-op -- this store had no way to observe its own transport failures at all. Left undefined by default (matching onDelivery/onPatch): a caller that wants visibility sets it, exactly like those two.
|
|
87
|
+
*/
|
|
88
|
+
onError;
|
|
82
89
|
/** Serialise the full mesh state for state_sync messages. */
|
|
83
90
|
serialise() {
|
|
84
91
|
return {
|
|
@@ -97,9 +104,6 @@ export class MeshStore {
|
|
|
97
104
|
this.peerId = nanoid(8);
|
|
98
105
|
this.startedAt = new Date().toISOString();
|
|
99
106
|
this.coordinatorPort = coordinatorPort;
|
|
100
|
-
// Wire up transport with this store's event handlers.
|
|
101
|
-
// TcpTransport is the default; callers can replace via setTransport().
|
|
102
|
-
this.transport = new TcpTransport(this.events);
|
|
103
107
|
// Discovery manager — registers available backends
|
|
104
108
|
this.discovery = new DiscoveryManager();
|
|
105
109
|
this.discovery.registerBackend(new MdnsDiscoveryBackend());
|
|
@@ -116,10 +120,17 @@ export class MeshStore {
|
|
|
116
120
|
getFederatedRoomMemberships: () => this.getFederatedRoomMembershipsForFed(),
|
|
117
121
|
});
|
|
118
122
|
}
|
|
119
|
-
/**
|
|
123
|
+
/** Sets the transport (e.g. TlsTransport for encrypted connections). Must be called before init() or any other transport-using method. */
|
|
120
124
|
setTransport(transport) {
|
|
121
125
|
this.transport = transport;
|
|
122
126
|
}
|
|
127
|
+
/** The set transport, or throws if setTransport() hasn't been called yet -- the single place every transport-using method reads through, so the "must call setTransport() first" contract is enforced at one boundary rather than checked ad hoc at each call site. */
|
|
128
|
+
requireTransport() {
|
|
129
|
+
if (this.transport === undefined) {
|
|
130
|
+
throw new Error("MeshStore: no transport set; call setTransport() before using the store");
|
|
131
|
+
}
|
|
132
|
+
return this.transport;
|
|
133
|
+
}
|
|
123
134
|
// -----------------------------------------------------------------------
|
|
124
135
|
// Mesh lifecycle
|
|
125
136
|
// -----------------------------------------------------------------------
|
|
@@ -127,11 +138,11 @@ export class MeshStore {
|
|
|
127
138
|
if (this.initialised)
|
|
128
139
|
return;
|
|
129
140
|
this.initialised = true;
|
|
130
|
-
await this.
|
|
141
|
+
await this.requireTransport().startDataServer();
|
|
131
142
|
// Register our own peer info
|
|
132
143
|
this.peerInfo.set(this.peerId, {
|
|
133
144
|
id: this.peerId,
|
|
134
|
-
port: this.
|
|
145
|
+
port: this.requireTransport().dataPort,
|
|
135
146
|
startedAt: this.startedAt,
|
|
136
147
|
});
|
|
137
148
|
// Try joining an existing mesh; fall back to becoming coordinator.
|
|
@@ -144,12 +155,12 @@ export class MeshStore {
|
|
|
144
155
|
// cache bug), so we only try once.
|
|
145
156
|
let connected = false;
|
|
146
157
|
try {
|
|
147
|
-
await this.
|
|
158
|
+
await this.requireTransport().connectToCoordinator(COORDINATOR_HOST, this.coordinatorPort, this.peerId, this.requireTransport().dataPort);
|
|
148
159
|
connected = true;
|
|
149
160
|
}
|
|
150
161
|
catch {
|
|
151
162
|
try {
|
|
152
|
-
await this.
|
|
163
|
+
await this.requireTransport().becomeCoordinator(COORDINATOR_HOST, this.coordinatorPort);
|
|
153
164
|
this.startStaleCheck();
|
|
154
165
|
connected = true;
|
|
155
166
|
}
|
|
@@ -166,7 +177,7 @@ export class MeshStore {
|
|
|
166
177
|
"Running without mesh — agent-comms will be unavailable."));
|
|
167
178
|
return;
|
|
168
179
|
}
|
|
169
|
-
this.
|
|
180
|
+
this.requireTransport().unref();
|
|
170
181
|
}
|
|
171
182
|
// -----------------------------------------------------------------------
|
|
172
183
|
// TransportEvents — callbacks from the transport layer
|
|
@@ -174,12 +185,17 @@ export class MeshStore {
|
|
|
174
185
|
handlePeerList(peers) {
|
|
175
186
|
for (const peer of peers) {
|
|
176
187
|
this.peerInfo.set(peer.id, peer);
|
|
177
|
-
|
|
188
|
+
// The list always includes this store's own entry — dialling yourself is a wasted connection attempt (and, on some platforms, an immediate self-inflicted ECONNRESET) that never needs to happen.
|
|
189
|
+
if (peer.id === this.peerId)
|
|
190
|
+
continue;
|
|
191
|
+
void this.requireTransport().connectToPeer(peer, this.peerId);
|
|
178
192
|
}
|
|
179
193
|
}
|
|
180
194
|
handlePeerJoined(peer) {
|
|
181
195
|
this.peerInfo.set(peer.id, peer);
|
|
182
|
-
|
|
196
|
+
if (peer.id === this.peerId)
|
|
197
|
+
return;
|
|
198
|
+
void this.requireTransport().connectToPeer(peer, this.peerId);
|
|
183
199
|
}
|
|
184
200
|
async handleIntroduction(handle, msg) {
|
|
185
201
|
const newPeer = {
|
|
@@ -193,18 +209,18 @@ export class MeshStore {
|
|
|
193
209
|
method: "peer_list",
|
|
194
210
|
peers: [...this.peerInfo.values()],
|
|
195
211
|
};
|
|
196
|
-
await this.
|
|
212
|
+
await this.requireTransport().send(handle, peerList);
|
|
197
213
|
// Broadcast arrival to all existing peers
|
|
198
214
|
const joined = { method: "peer_joined", peer: newPeer };
|
|
199
|
-
await this.
|
|
215
|
+
await this.requireTransport().broadcast(joined);
|
|
200
216
|
// Connect to the new peer's data server
|
|
201
|
-
void this.
|
|
217
|
+
void this.requireTransport().connectToPeer(newPeer, this.peerId);
|
|
202
218
|
}
|
|
203
219
|
async handlePeerConnected(handle, _info) {
|
|
204
220
|
// If we have state and the peer doesn't, send state sync
|
|
205
221
|
if (this.agents.size > 0) {
|
|
206
222
|
const state = this.serialise();
|
|
207
|
-
await this.
|
|
223
|
+
await this.requireTransport().send(handle, {
|
|
208
224
|
method: "state_sync",
|
|
209
225
|
state,
|
|
210
226
|
});
|
|
@@ -304,11 +320,11 @@ export class MeshStore {
|
|
|
304
320
|
}
|
|
305
321
|
async handleBecomeCoordinator(peerList) {
|
|
306
322
|
// Take over as coordinator using the data server we already have
|
|
307
|
-
await this.
|
|
323
|
+
await this.requireTransport().becomeCoordinator(COORDINATOR_HOST, this.coordinatorPort);
|
|
308
324
|
this.peerInfo.clear();
|
|
309
325
|
for (const peer of peerList) {
|
|
310
326
|
this.peerInfo.set(peer.id, peer);
|
|
311
|
-
void this.
|
|
327
|
+
void this.requireTransport().connectToPeer(peer, this.peerId);
|
|
312
328
|
}
|
|
313
329
|
this.startStaleCheck();
|
|
314
330
|
}
|
|
@@ -348,7 +364,7 @@ export class MeshStore {
|
|
|
348
364
|
}
|
|
349
365
|
this.pendingInboundConnections.delete(connectionId);
|
|
350
366
|
const handle = { id: connectionId };
|
|
351
|
-
await this.
|
|
367
|
+
await this.requireTransport().acceptConnection(handle);
|
|
352
368
|
}
|
|
353
369
|
/** Reject a pending inbound connection. */
|
|
354
370
|
async rejectConnection(connectionId, reason) {
|
|
@@ -358,7 +374,7 @@ export class MeshStore {
|
|
|
358
374
|
}
|
|
359
375
|
this.pendingInboundConnections.delete(connectionId);
|
|
360
376
|
const handle = { id: connectionId };
|
|
361
|
-
await this.
|
|
377
|
+
await this.requireTransport().rejectConnection(handle, reason);
|
|
362
378
|
}
|
|
363
379
|
/** List all pending inbound connections awaiting approval. */
|
|
364
380
|
listPendingConnections() {
|
|
@@ -375,8 +391,8 @@ export class MeshStore {
|
|
|
375
391
|
// Fire-and-forget: don't await the full approval handshake.
|
|
376
392
|
// The coordinator will either accept (triggering normal introduction flow)
|
|
377
393
|
// or reject (closing the socket). Handle rejection to avoid unhandled rejection.
|
|
378
|
-
this.
|
|
379
|
-
.connectToRemote(host, port, this.peerId, this.
|
|
394
|
+
this.requireTransport()
|
|
395
|
+
.connectToRemote(host, port, this.peerId, this.requireTransport().dataPort, agent?.name ?? "", "")
|
|
380
396
|
.catch(() => {
|
|
381
397
|
// Rejection is expected when the coordinator denies the connection.
|
|
382
398
|
// Log silently — the calling tool already returned success.
|
|
@@ -386,13 +402,13 @@ export class MeshStore {
|
|
|
386
402
|
/** Start only the data server without connecting to a coordinator.
|
|
387
403
|
* Used for testing scenarios where the peer connects via connectToRemote. */
|
|
388
404
|
async startDataServerOnly() {
|
|
389
|
-
await this.
|
|
405
|
+
await this.requireTransport().startDataServer();
|
|
390
406
|
this.peerInfo.set(this.peerId, {
|
|
391
407
|
id: this.peerId,
|
|
392
|
-
port: this.
|
|
408
|
+
port: this.requireTransport().dataPort,
|
|
393
409
|
startedAt: this.startedAt,
|
|
394
410
|
});
|
|
395
|
-
this.
|
|
411
|
+
this.requireTransport().unref();
|
|
396
412
|
}
|
|
397
413
|
// -----------------------------------------------------------------------
|
|
398
414
|
// Transport events accessor (for bridges to wire up)
|
|
@@ -424,6 +440,9 @@ export class MeshStore {
|
|
|
424
440
|
onConnectionRequest: (handle, request) => {
|
|
425
441
|
this.handleConnectionRequest(handle, request);
|
|
426
442
|
},
|
|
443
|
+
onError: (error) => {
|
|
444
|
+
this.onError?.(error);
|
|
445
|
+
},
|
|
427
446
|
};
|
|
428
447
|
}
|
|
429
448
|
/** Append to a target agent's delivery queue, bounded oldest-first (#28). */
|
|
@@ -603,7 +622,7 @@ export class MeshStore {
|
|
|
603
622
|
// Broadcast
|
|
604
623
|
// -----------------------------------------------------------------------
|
|
605
624
|
async broadcastPatch(patch) {
|
|
606
|
-
await this.
|
|
625
|
+
await this.requireTransport().broadcast({ method: "state_update", patch });
|
|
607
626
|
if (this.onPatch) {
|
|
608
627
|
await this.onPatch(patch);
|
|
609
628
|
}
|
|
@@ -1267,13 +1286,13 @@ export class MeshStore {
|
|
|
1267
1286
|
if (!isListenerPolicy(policy)) {
|
|
1268
1287
|
throw new CommsError(`Invalid policy "${policy}"`, "INVALID_POLICY");
|
|
1269
1288
|
}
|
|
1270
|
-
return this.
|
|
1289
|
+
return this.requireTransport().addListener(host, port, policy);
|
|
1271
1290
|
}
|
|
1272
1291
|
async removeListener(id) {
|
|
1273
|
-
return this.
|
|
1292
|
+
return this.requireTransport().removeListener(id);
|
|
1274
1293
|
}
|
|
1275
1294
|
listListeners() {
|
|
1276
|
-
return this.
|
|
1295
|
+
return this.requireTransport().listListeners();
|
|
1277
1296
|
}
|
|
1278
1297
|
getNetworkInterfaces() {
|
|
1279
1298
|
const interfaces = os.networkInterfaces();
|
|
@@ -1446,7 +1465,7 @@ export class MeshStore {
|
|
|
1446
1465
|
}
|
|
1447
1466
|
this.stopStaleCheck();
|
|
1448
1467
|
await this.federation.shutdown();
|
|
1449
|
-
await this.
|
|
1468
|
+
await this.requireTransport().shutdown();
|
|
1450
1469
|
}
|
|
1451
1470
|
}
|
|
1452
1471
|
//# sourceMappingURL=mesh-store.js.map
|