@agentvault/agentvault 0.19.26 → 0.19.28
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/dist/channel.d.ts +9 -0
- package/dist/channel.d.ts.map +1 -1
- package/dist/cli.js +145 -91
- package/dist/cli.js.map +2 -2
- package/dist/index.js +145 -91
- package/dist/index.js.map +2 -2
- package/dist/openclaw-entry.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/dist/__tests__/crypto-helpers.test.d.ts +0 -2
- package/dist/__tests__/crypto-helpers.test.d.ts.map +0 -1
- package/dist/__tests__/functional.test.d.ts +0 -21
- package/dist/__tests__/functional.test.d.ts.map +0 -1
- package/dist/__tests__/multi-session.test.d.ts +0 -2
- package/dist/__tests__/multi-session.test.d.ts.map +0 -1
- package/dist/__tests__/state.test.d.ts +0 -2
- package/dist/__tests__/state.test.d.ts.map +0 -1
- package/dist/__tests__/transport.test.d.ts +0 -2
- package/dist/__tests__/transport.test.d.ts.map +0 -1
- package/dist/channel.js +0 -2257
- package/dist/channel.js.map +0 -1
- package/dist/crypto-helpers.js +0 -4
- package/dist/crypto-helpers.js.map +0 -1
- package/dist/openclaw-plugin.js +0 -222
- package/dist/openclaw-plugin.js.map +0 -1
- package/dist/setup.js +0 -329
- package/dist/setup.js.map +0 -1
- package/dist/state.js +0 -61
- package/dist/state.js.map +0 -1
- package/dist/transport.js +0 -43
- package/dist/transport.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/dist/channel.d.ts
CHANGED
|
@@ -46,6 +46,10 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
46
46
|
/** Dedup buffer for A2A message IDs (prevents double-delivery via direct + Redis) */
|
|
47
47
|
private _a2aSeenMessageIds;
|
|
48
48
|
private static readonly A2A_SEEN_MAX;
|
|
49
|
+
/** Whether A2A channel sync has completed after (re)connect */
|
|
50
|
+
private _a2aSyncComplete;
|
|
51
|
+
/** Messages buffered while A2A sync is in progress */
|
|
52
|
+
private _a2aBufferedMessages;
|
|
49
53
|
/** Dedup buffer for regular message IDs (prevents double-decrypt via direct WS + Redis pub/sub) */
|
|
50
54
|
private _seenMessageIds;
|
|
51
55
|
private static readonly SEEN_MSG_MAX;
|
|
@@ -364,6 +368,11 @@ export declare class SecureChannel extends EventEmitter {
|
|
|
364
368
|
* Sync missed messages across ALL sessions.
|
|
365
369
|
* For each conversation, fetches messages since last sync and decrypts.
|
|
366
370
|
*/
|
|
371
|
+
/**
|
|
372
|
+
* Handle an incoming A2A message (extracted from WS handler for reuse during buffer replay).
|
|
373
|
+
* Includes dedup, encrypted path (with on-demand key exchange), and legacy plaintext path.
|
|
374
|
+
*/
|
|
375
|
+
private _handleA2AMessage;
|
|
367
376
|
/**
|
|
368
377
|
* Paginated sync: fetch missed messages in pages of 200, up to 5 pages (1000 messages).
|
|
369
378
|
* Tracks message IDs in _syncMessageIds to prevent duplicate processing from concurrent WS messages.
|
package/dist/channel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,OAAO,EAWL,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,mBAAmB,EACnB,YAAY,EAKZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,cAAc,EACd,oBAAoB,EACpB,QAAQ,EAER,UAAU,EAEV,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,EAGX,MAAM,YAAY,CAAC;AAmEpB,qBAAa,aAAc,SAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;A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1B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,kBAAkB;IA2H1B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,YAAY;IAKpB;;;OAGG;YACW,aAAa;IAyB3B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAqB9B"}
|
package/dist/cli.js
CHANGED
|
@@ -47084,6 +47084,10 @@ var init_channel = __esm({
|
|
|
47084
47084
|
/** Dedup buffer for A2A message IDs (prevents double-delivery via direct + Redis) */
|
|
47085
47085
|
_a2aSeenMessageIds = /* @__PURE__ */ new Set();
|
|
47086
47086
|
static A2A_SEEN_MAX = 500;
|
|
47087
|
+
/** Whether A2A channel sync has completed after (re)connect */
|
|
47088
|
+
_a2aSyncComplete = false;
|
|
47089
|
+
/** Messages buffered while A2A sync is in progress */
|
|
47090
|
+
_a2aBufferedMessages = [];
|
|
47087
47091
|
/** Dedup buffer for regular message IDs (prevents double-decrypt via direct WS + Redis pub/sub) */
|
|
47088
47092
|
_seenMessageIds = /* @__PURE__ */ new Set();
|
|
47089
47093
|
static SEEN_MSG_MAX = 500;
|
|
@@ -48735,6 +48739,8 @@ var init_channel = __esm({
|
|
|
48735
48739
|
ws.on("open", async () => {
|
|
48736
48740
|
try {
|
|
48737
48741
|
this._reconnectAttempt = 0;
|
|
48742
|
+
this._a2aSyncComplete = false;
|
|
48743
|
+
this._a2aBufferedMessages = [];
|
|
48738
48744
|
this._lastWsOpenTime = Date.now();
|
|
48739
48745
|
this._startPing(ws);
|
|
48740
48746
|
this._startWakeDetector();
|
|
@@ -48780,8 +48786,21 @@ var init_channel = __esm({
|
|
|
48780
48786
|
}, 3e3);
|
|
48781
48787
|
}
|
|
48782
48788
|
}
|
|
48789
|
+
this._a2aSyncComplete = true;
|
|
48790
|
+
if (this._a2aBufferedMessages.length > 0) {
|
|
48791
|
+
console.log(`[SecureChannel] Replaying ${this._a2aBufferedMessages.length} buffered A2A message(s)`);
|
|
48792
|
+
const buffered = this._a2aBufferedMessages.splice(0);
|
|
48793
|
+
for (const msg of buffered) {
|
|
48794
|
+
try {
|
|
48795
|
+
await this._handleA2AMessage(msg.data);
|
|
48796
|
+
} catch (err) {
|
|
48797
|
+
console.warn("[SecureChannel] Failed to replay buffered A2A message:", err);
|
|
48798
|
+
}
|
|
48799
|
+
}
|
|
48800
|
+
}
|
|
48783
48801
|
} catch (err) {
|
|
48784
48802
|
console.warn("[SecureChannel] A2A channel sync failed (non-fatal):", err);
|
|
48803
|
+
this._a2aSyncComplete = true;
|
|
48785
48804
|
}
|
|
48786
48805
|
if (!this._telemetryReporter && this._persisted?.deviceJwt && this._persisted?.hubId) {
|
|
48787
48806
|
this._telemetryReporter = new TelemetryReporter({
|
|
@@ -49272,99 +49291,14 @@ var init_channel = __esm({
|
|
|
49272
49291
|
this.emit("error", new Error(`Server: ${detail}`));
|
|
49273
49292
|
}
|
|
49274
49293
|
if (data.event === "a2a_message") {
|
|
49275
|
-
|
|
49276
|
-
|
|
49277
|
-
|
|
49294
|
+
console.log(`[SecureChannel] WS received a2a_message: syncComplete=${this._a2aSyncComplete} msgId=${(data.data || data).message_id?.slice(0, 8)}`);
|
|
49295
|
+
if (!this._a2aSyncComplete) {
|
|
49296
|
+
const msgId = (data.data || data).message_id;
|
|
49297
|
+
console.log(`[SecureChannel] Buffering A2A message (sync not complete): ${msgId?.slice(0, 8)}`);
|
|
49298
|
+
this._a2aBufferedMessages.push({ data });
|
|
49278
49299
|
return;
|
|
49279
49300
|
}
|
|
49280
|
-
|
|
49281
|
-
this._a2aSeenMessageIds.add(a2aMsgId);
|
|
49282
|
-
if (this._a2aSeenMessageIds.size > _SecureChannel.A2A_SEEN_MAX) {
|
|
49283
|
-
const first = this._a2aSeenMessageIds.values().next().value;
|
|
49284
|
-
if (first) this._a2aSeenMessageIds.delete(first);
|
|
49285
|
-
}
|
|
49286
|
-
}
|
|
49287
|
-
if (msgData.ciphertext && msgData.header_blob) {
|
|
49288
|
-
const channelId = msgData.channel_id || "";
|
|
49289
|
-
const channelEntry = this._persisted?.a2aChannels?.[channelId];
|
|
49290
|
-
if (channelEntry?.session?.ratchetState) {
|
|
49291
|
-
try {
|
|
49292
|
-
const headerJson = Buffer.from(msgData.header_blob, "hex").toString("utf-8");
|
|
49293
|
-
const headerObj = JSON.parse(headerJson);
|
|
49294
|
-
const encryptedMessage = {
|
|
49295
|
-
header: {
|
|
49296
|
-
dhPublicKey: hexToBytes(headerObj.dhPublicKey),
|
|
49297
|
-
previousChainLength: headerObj.previousChainLength,
|
|
49298
|
-
messageNumber: headerObj.messageNumber
|
|
49299
|
-
},
|
|
49300
|
-
headerSignature: msgData.header_signature ? hexToBytes(msgData.header_signature) : new Uint8Array(64),
|
|
49301
|
-
ciphertext: hexToBytes(msgData.ciphertext),
|
|
49302
|
-
nonce: hexToBytes(msgData.nonce)
|
|
49303
|
-
};
|
|
49304
|
-
const ratchet = DoubleRatchet.deserialize(channelEntry.session.ratchetState);
|
|
49305
|
-
const ratchetSnapshot = channelEntry.session.ratchetState;
|
|
49306
|
-
let a2aPlaintext;
|
|
49307
|
-
try {
|
|
49308
|
-
a2aPlaintext = ratchet.decrypt(encryptedMessage);
|
|
49309
|
-
} catch (decryptErr) {
|
|
49310
|
-
console.error(`[SecureChannel] A2A decrypt failed \u2014 restoring ratchet state:`, decryptErr);
|
|
49311
|
-
channelEntry.session.ratchetState = ratchetSnapshot;
|
|
49312
|
-
return;
|
|
49313
|
-
}
|
|
49314
|
-
channelEntry.session.ratchetState = ratchet.serialize();
|
|
49315
|
-
if (channelEntry.role === "responder" && !channelEntry.session.activated) {
|
|
49316
|
-
channelEntry.session.activated = true;
|
|
49317
|
-
console.log(
|
|
49318
|
-
`[SecureChannel] A2A responder ratchet activated for ${channelId.slice(0, 8)}...`
|
|
49319
|
-
);
|
|
49320
|
-
const queued = this._a2aPendingQueue[channelId];
|
|
49321
|
-
if (queued && queued.length > 0) {
|
|
49322
|
-
delete this._a2aPendingQueue[channelId];
|
|
49323
|
-
console.log(`[SecureChannel] Flushing ${queued.length} queued A2A message(s)`);
|
|
49324
|
-
await this._persistState();
|
|
49325
|
-
for (const pending of queued) {
|
|
49326
|
-
try {
|
|
49327
|
-
await this.sendToAgent(channelEntry.hubAddress, pending.text, pending.opts);
|
|
49328
|
-
} catch (flushErr) {
|
|
49329
|
-
console.error("[SecureChannel] Failed to flush queued A2A message:", flushErr);
|
|
49330
|
-
}
|
|
49331
|
-
}
|
|
49332
|
-
}
|
|
49333
|
-
}
|
|
49334
|
-
await this._persistState();
|
|
49335
|
-
const a2aMsg = {
|
|
49336
|
-
text: a2aPlaintext,
|
|
49337
|
-
fromHubAddress: msgData.from_hub_address || msgData.hub_address || "",
|
|
49338
|
-
channelId,
|
|
49339
|
-
conversationId: msgData.conversation_id || "",
|
|
49340
|
-
parentSpanId: msgData.parent_span_id,
|
|
49341
|
-
timestamp: msgData.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
49342
|
-
};
|
|
49343
|
-
this.emit("a2a_message", a2aMsg);
|
|
49344
|
-
if (this.config.onA2AMessage) {
|
|
49345
|
-
this.config.onA2AMessage(a2aMsg);
|
|
49346
|
-
}
|
|
49347
|
-
} catch (decryptErr) {
|
|
49348
|
-
console.error(`[SecureChannel] A2A decrypt failed for channel ${channelId.slice(0, 8)}...:`, decryptErr);
|
|
49349
|
-
this.emit("error", decryptErr);
|
|
49350
|
-
}
|
|
49351
|
-
} else {
|
|
49352
|
-
console.warn(`[SecureChannel] Received encrypted A2A message but no session for channel ${channelId}`);
|
|
49353
|
-
}
|
|
49354
|
-
} else {
|
|
49355
|
-
const a2aMsg = {
|
|
49356
|
-
text: msgData.plaintext || msgData.text,
|
|
49357
|
-
fromHubAddress: msgData.from_hub_address || msgData.hub_address || "",
|
|
49358
|
-
channelId: msgData.channel_id || "",
|
|
49359
|
-
conversationId: msgData.conversation_id || "",
|
|
49360
|
-
parentSpanId: msgData.parent_span_id,
|
|
49361
|
-
timestamp: msgData.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
49362
|
-
};
|
|
49363
|
-
this.emit("a2a_message", a2aMsg);
|
|
49364
|
-
if (this.config.onA2AMessage) {
|
|
49365
|
-
this.config.onA2AMessage(a2aMsg);
|
|
49366
|
-
}
|
|
49367
|
-
}
|
|
49301
|
+
await this._handleA2AMessage(data);
|
|
49368
49302
|
}
|
|
49369
49303
|
} catch (err) {
|
|
49370
49304
|
this.emit("error", err);
|
|
@@ -50443,6 +50377,126 @@ ${messageText}`;
|
|
|
50443
50377
|
* Sync missed messages across ALL sessions.
|
|
50444
50378
|
* For each conversation, fetches messages since last sync and decrypts.
|
|
50445
50379
|
*/
|
|
50380
|
+
/**
|
|
50381
|
+
* Handle an incoming A2A message (extracted from WS handler for reuse during buffer replay).
|
|
50382
|
+
* Includes dedup, encrypted path (with on-demand key exchange), and legacy plaintext path.
|
|
50383
|
+
*/
|
|
50384
|
+
async _handleA2AMessage(data) {
|
|
50385
|
+
const msgData = data.data || data;
|
|
50386
|
+
const a2aMsgId = msgData.message_id;
|
|
50387
|
+
console.log(`[SecureChannel] _handleA2AMessage: msgId=${a2aMsgId?.slice(0, 8)} channelId=${(msgData.channel_id || "").slice(0, 8)} hasCipher=${!!msgData.ciphertext} hasHeader=${!!msgData.header_blob}`);
|
|
50388
|
+
if (a2aMsgId && this._a2aSeenMessageIds.has(a2aMsgId)) {
|
|
50389
|
+
console.log(`[SecureChannel] A2A dedup: skipping ${a2aMsgId.slice(0, 8)}`);
|
|
50390
|
+
return;
|
|
50391
|
+
}
|
|
50392
|
+
if (a2aMsgId) {
|
|
50393
|
+
this._a2aSeenMessageIds.add(a2aMsgId);
|
|
50394
|
+
if (this._a2aSeenMessageIds.size > _SecureChannel.A2A_SEEN_MAX) {
|
|
50395
|
+
const first = this._a2aSeenMessageIds.values().next().value;
|
|
50396
|
+
if (first) this._a2aSeenMessageIds.delete(first);
|
|
50397
|
+
}
|
|
50398
|
+
}
|
|
50399
|
+
if (msgData.ciphertext && msgData.header_blob) {
|
|
50400
|
+
const channelId = msgData.channel_id || "";
|
|
50401
|
+
const channelEntry = this._persisted?.a2aChannels?.[channelId];
|
|
50402
|
+
console.log(`[SecureChannel] A2A encrypted: channel=${channelId.slice(0, 8)} found=${!!channelEntry} hasSession=${!!channelEntry?.session} hasRatchet=${!!channelEntry?.session?.ratchetState} role=${channelEntry?.role}`);
|
|
50403
|
+
if (channelEntry?.session?.ratchetState) {
|
|
50404
|
+
try {
|
|
50405
|
+
const headerJson = Buffer.from(msgData.header_blob, "hex").toString("utf-8");
|
|
50406
|
+
const headerObj = JSON.parse(headerJson);
|
|
50407
|
+
const encryptedMessage = {
|
|
50408
|
+
header: {
|
|
50409
|
+
dhPublicKey: hexToBytes(headerObj.dhPublicKey),
|
|
50410
|
+
previousChainLength: headerObj.previousChainLength,
|
|
50411
|
+
messageNumber: headerObj.messageNumber
|
|
50412
|
+
},
|
|
50413
|
+
headerSignature: msgData.header_signature ? hexToBytes(msgData.header_signature) : new Uint8Array(64),
|
|
50414
|
+
ciphertext: hexToBytes(msgData.ciphertext),
|
|
50415
|
+
nonce: hexToBytes(msgData.nonce)
|
|
50416
|
+
};
|
|
50417
|
+
const ratchet = DoubleRatchet.deserialize(channelEntry.session.ratchetState);
|
|
50418
|
+
const ratchetSnapshot = channelEntry.session.ratchetState;
|
|
50419
|
+
let a2aPlaintext;
|
|
50420
|
+
try {
|
|
50421
|
+
a2aPlaintext = ratchet.decrypt(encryptedMessage);
|
|
50422
|
+
} catch (decryptErr) {
|
|
50423
|
+
console.error(`[SecureChannel] A2A decrypt failed \u2014 restoring ratchet state:`, decryptErr);
|
|
50424
|
+
channelEntry.session.ratchetState = ratchetSnapshot;
|
|
50425
|
+
return;
|
|
50426
|
+
}
|
|
50427
|
+
channelEntry.session.ratchetState = ratchet.serialize();
|
|
50428
|
+
if (channelEntry.role === "responder" && !channelEntry.session.activated) {
|
|
50429
|
+
channelEntry.session.activated = true;
|
|
50430
|
+
console.log(
|
|
50431
|
+
`[SecureChannel] A2A responder ratchet activated for ${channelId.slice(0, 8)}...`
|
|
50432
|
+
);
|
|
50433
|
+
const queued = this._a2aPendingQueue[channelId];
|
|
50434
|
+
if (queued && queued.length > 0) {
|
|
50435
|
+
delete this._a2aPendingQueue[channelId];
|
|
50436
|
+
console.log(`[SecureChannel] Flushing ${queued.length} queued A2A message(s)`);
|
|
50437
|
+
await this._persistState();
|
|
50438
|
+
for (const pending of queued) {
|
|
50439
|
+
try {
|
|
50440
|
+
await this.sendToAgent(channelEntry.hubAddress, pending.text, pending.opts);
|
|
50441
|
+
} catch (flushErr) {
|
|
50442
|
+
console.error("[SecureChannel] Failed to flush queued A2A message:", flushErr);
|
|
50443
|
+
}
|
|
50444
|
+
}
|
|
50445
|
+
}
|
|
50446
|
+
}
|
|
50447
|
+
await this._persistState();
|
|
50448
|
+
const a2aMsg = {
|
|
50449
|
+
text: a2aPlaintext,
|
|
50450
|
+
fromHubAddress: msgData.from_hub_address || msgData.hub_address || "",
|
|
50451
|
+
channelId,
|
|
50452
|
+
conversationId: msgData.conversation_id || "",
|
|
50453
|
+
parentSpanId: msgData.parent_span_id,
|
|
50454
|
+
timestamp: msgData.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
50455
|
+
};
|
|
50456
|
+
this.emit("a2a_message", a2aMsg);
|
|
50457
|
+
if (this.config.onA2AMessage) {
|
|
50458
|
+
this.config.onA2AMessage(a2aMsg);
|
|
50459
|
+
}
|
|
50460
|
+
} catch (decryptErr) {
|
|
50461
|
+
console.error(`[SecureChannel] A2A decrypt failed for channel ${channelId.slice(0, 8)}...:`, decryptErr);
|
|
50462
|
+
this.emit("error", decryptErr);
|
|
50463
|
+
}
|
|
50464
|
+
} else {
|
|
50465
|
+
console.warn(
|
|
50466
|
+
`[SecureChannel] Received encrypted A2A but no session for ${channelId.slice(0, 8)} \u2014 triggering key exchange`
|
|
50467
|
+
);
|
|
50468
|
+
const entry = this._persisted?.a2aChannels?.[channelId];
|
|
50469
|
+
if (entry && !entry.pendingEphemeralPrivateKey && !entry.session) {
|
|
50470
|
+
try {
|
|
50471
|
+
const a2aEphemeral = await generateEphemeralKeypair();
|
|
50472
|
+
const ephPubHex = bytesToHex(a2aEphemeral.publicKey);
|
|
50473
|
+
entry.pendingEphemeralPrivateKey = bytesToHex(a2aEphemeral.privateKey);
|
|
50474
|
+
this._ws?.send(JSON.stringify({
|
|
50475
|
+
event: "a2a_key_exchange",
|
|
50476
|
+
data: { channel_id: channelId, ephemeral_key: ephPubHex }
|
|
50477
|
+
}));
|
|
50478
|
+
await this._persistState();
|
|
50479
|
+
console.log(`[SecureChannel] On-demand A2A key exchange for ${channelId.slice(0, 8)}`);
|
|
50480
|
+
} catch (kxErr) {
|
|
50481
|
+
console.warn(`[SecureChannel] On-demand key exchange failed:`, kxErr);
|
|
50482
|
+
}
|
|
50483
|
+
}
|
|
50484
|
+
}
|
|
50485
|
+
} else {
|
|
50486
|
+
const a2aMsg = {
|
|
50487
|
+
text: msgData.plaintext || msgData.text,
|
|
50488
|
+
fromHubAddress: msgData.from_hub_address || msgData.hub_address || "",
|
|
50489
|
+
channelId: msgData.channel_id || "",
|
|
50490
|
+
conversationId: msgData.conversation_id || "",
|
|
50491
|
+
parentSpanId: msgData.parent_span_id,
|
|
50492
|
+
timestamp: msgData.timestamp || (/* @__PURE__ */ new Date()).toISOString()
|
|
50493
|
+
};
|
|
50494
|
+
this.emit("a2a_message", a2aMsg);
|
|
50495
|
+
if (this.config.onA2AMessage) {
|
|
50496
|
+
this.config.onA2AMessage(a2aMsg);
|
|
50497
|
+
}
|
|
50498
|
+
}
|
|
50499
|
+
}
|
|
50446
50500
|
/**
|
|
50447
50501
|
* Paginated sync: fetch missed messages in pages of 200, up to 5 pages (1000 messages).
|
|
50448
50502
|
* Tracks message IDs in _syncMessageIds to prevent duplicate processing from concurrent WS messages.
|