@openclaw/matrix 2026.8.1 → 2026.8.2

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.
Files changed (74) hide show
  1. package/dist/{account-selection-C8nnBTxi.js → account-selection-DA-jfx22.js} +11 -9
  2. package/dist/{accounts-fC57n-Jo.js → accounts-DR1c4xF_.js} +2 -2
  3. package/dist/api.js +5 -5
  4. package/dist/{approval-handler.runtime-BBjFZw1t.js → approval-handler.runtime-xcVrZw9o.js} +5 -5
  5. package/dist/{approval-ids-DTIdXV-m.js → approval-ids-hmvhDNBj.js} +1 -1
  6. package/dist/{approval-reaction-auth-BDONXxnF.js → approval-reaction-auth-DziFGHSk.js} +2 -2
  7. package/dist/{approval-reactions-tXh9KYrW.js → approval-reactions-1fwEhoK9.js} +1 -1
  8. package/dist/{channel-BkEcVUs_.js → channel-D6-ajB_u.js} +51 -53
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/{channel.runtime-CTLSBFsP.js → channel.runtime-BMA0dG2k.js} +16 -12
  11. package/dist/{channel.setup-CSacbORr.js → channel.setup-OIEzCzSs.js} +21 -19
  12. package/dist/{cli-DRVtgrq5.js → cli-B6HF7Hmn.js} +38 -29
  13. package/dist/{cli-metadata-Ddx_y4Os.js → cli-metadata-Mtzu5-AY.js} +1 -1
  14. package/dist/cli-metadata.js +1 -1
  15. package/dist/{client-CZ_JvrO0.js → client-B0yMDho1.js} +2 -2
  16. package/dist/{client-kSi51NKp.js → client-DFsRJEgB.js} +69 -16
  17. package/dist/{client-bootstrap-D8irSL2i.js → client-bootstrap-DjXCKEtg.js} +1 -1
  18. package/dist/{config-update-DC0fWBxc.js → config-update-BnX26jCO.js} +46 -28
  19. package/dist/contract-api.js +2 -2
  20. package/dist/{credentials-BdAaWuiR.js → credentials-DJj2xs3q.js} +4 -8
  21. package/dist/{credentials-read-B37cQknZ.js → credentials-read-mexhw-Ur.js} +7 -5
  22. package/dist/{credentials-write.runtime-nAV2-5uR.js → credentials-write.runtime-DQt-kgJq.js} +1 -1
  23. package/dist/{crypto-runtime-C4WDYxlP.js → crypto-runtime-QvlgyCkj.js} +6 -6
  24. package/dist/{deps-CcVJfvRM.js → deps-mtxF2mHI.js} +1 -1
  25. package/dist/{directory-live-DKr0w35b.js → directory-live-Drh343TW.js} +8 -6
  26. package/dist/{doctor-EWf9CDso.js → doctor-CJE8wO6y.js} +1 -1
  27. package/dist/{doctor-contract-DEt4O4Zt.js → doctor-contract-HyWFZQVG.js} +5 -4
  28. package/dist/doctor-contract-api.js +7 -7
  29. package/dist/{draft-stream-0CEpNrBk.js → draft-stream-DhGHVdO4.js} +1 -1
  30. package/dist/{encryption-guidance-D4ZdAqzM.js → encryption-guidance-BNcZNQZI.js} +3 -2
  31. package/dist/helper-api.js +1 -1
  32. package/dist/{http-client-D8o8b9u6.js → http-client-DOmFvKvB.js} +10 -7
  33. package/dist/{idb-persistence-DfgW720p.js → idb-persistence-D4NGNQxt.js} +2 -2
  34. package/dist/{idb-persistence-lock-DAJ49nZX.js → idb-persistence-lock-B3fZXyF_.js} +1 -1
  35. package/dist/{inbound-dedupe-RvSLqdsz.js → inbound-dedupe-Ch33GU06.js} +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/{messages-DaGRt-tu.js → messages-DlMQaC02.js} +2 -2
  38. package/dist/{monitor-CLPbPcR9.js → monitor-U2LcVtHt.js} +49 -74
  39. package/dist/plugin-entry.handlers.runtime.js +1 -1
  40. package/dist/probe.runtime-CNo-5_iz.js +2 -0
  41. package/dist/{profile-update-zXVCMg7y.js → profile-update-CsyKA9jI.js} +5 -4
  42. package/dist/{profile-D-Wubo0A.js → profile-vmjsmhh4.js} +1 -1
  43. package/dist/{reaction-events-CjVUiqcY.js → reaction-events-lwNc5I1X.js} +8 -6
  44. package/dist/{resolve-targets-qG6gceps.js → resolve-targets-D3Eakgzs.js} +1 -1
  45. package/dist/{resolver.runtime-zX3TR3TN.js → resolver.runtime-DJQxR35r.js} +1 -1
  46. package/dist/{room-info-yheP1mod.js → room-info-DIU67XLP.js} +3 -3
  47. package/dist/runtime-api.js +2 -2
  48. package/dist/{sdk-TZYyo0XQ.js → sdk-Jl2CgAbJ.js} +518 -23
  49. package/dist/{send-BL_iH5Ox.js → send-DfS5ciUL.js} +13 -9
  50. package/dist/session-binding-contract-api.js +1 -1
  51. package/dist/{setup-bootstrap-D8M7FmcO.js → setup-bootstrap-CWoIWudw.js} +2 -2
  52. package/dist/{setup-core-r6L0nno-.js → setup-core-CZM496H-.js} +7 -6
  53. package/dist/setup-plugin-api.js +1 -1
  54. package/dist/{setup-surface-g174ElFO.js → setup-surface-DSZtOsWK.js} +83 -77
  55. package/dist/{startup-verification-Cs08ca8u.js → startup-verification-1Ney1mmI.js} +2 -2
  56. package/dist/{storage-BsGuHngK.js → storage-BVf4uucD.js} +5 -4
  57. package/dist/{subagent-hooks-CMoZaARG.js → subagent-hooks-DeICLbU5.js} +5 -1
  58. package/dist/subagent-hooks-api.js +1 -1
  59. package/dist/sync-cache-state-d-A_OhbU.js +234 -0
  60. package/dist/{thread-bindings-ERWNousC.js → thread-bindings-2HN2AyLu.js} +2 -2
  61. package/dist/{tool-actions.runtime-DcBCSwY4.js → tool-actions.runtime-CFZZPG5g.js} +225 -163
  62. package/dist/{verification-4vsW_WSn.js → verification-CD7k5vE9.js} +2 -2
  63. package/node_modules/matrix-js-sdk/lib/client.d.ts +2 -1
  64. package/node_modules/matrix-js-sdk/lib/client.js +6 -2
  65. package/node_modules/matrix-js-sdk/lib/sync.js +8 -8
  66. package/node_modules/matrix-js-sdk/src/client.ts +7 -3
  67. package/node_modules/matrix-js-sdk/src/sync.ts +8 -8
  68. package/node_modules/typebox/build/format/email.mjs +1 -1
  69. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
  70. package/node_modules/typebox/package.json +1 -1
  71. package/package.json +5 -5
  72. package/dist/file-sync-store-DjskBX2o.js +0 -436
  73. package/dist/probe.runtime-Bxpr1FFy.js +0 -2
  74. package/dist/recovery-key-store-CognuDys.js +0 -276
@@ -1,26 +1,30 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
1
3
  import "./reaction-common-DkrQdBSZ.js";
2
- import { t as SqliteBackedMatrixSyncStore } from "./file-sync-store-DjskBX2o.js";
4
+ import { A as writeMatrixRecoveryKeyStateForPath, E as readMatrixRecoveryKeyStateForPath, S as readLegacyMatrixRecoveryKeyFile, _ as migrateLegacyMatrixRecoveryKeyFilePathToStore, t as claimCurrentTokenStorageState } from "./storage-BVf4uucD.js";
5
+ import { i as openMatrixSyncCacheStoreOptions, l as writeMatrixSyncCacheStateToSyncStore, n as deleteMatrixSyncCacheStateFromSyncStore, o as readPersistedStoreFromSyncStore } from "./sync-cache-state-d-A_OhbU.js";
6
+ import { t as MATRIX_IDB_PERSIST_INTERVAL_MS } from "./idb-persistence-lock-B3fZXyF_.js";
3
7
  import { n as LogService, r as noop, t as ConsoleLogger } from "./logger-B_71hN6W.js";
4
- import { t as MATRIX_IDB_PERSIST_INTERVAL_MS } from "./idb-persistence-lock-DAJ49nZX.js";
5
8
  import { n as isMatrixNotFoundError, t as formatMatrixErrorReason } from "./errors-DKVS3_DO.js";
6
- import { a as throwIfMatrixStartupAborted, r as createMatrixStartupAbortError } from "./client-kSi51NKp.js";
9
+ import { a as throwIfMatrixStartupAborted, r as createMatrixStartupAbortError } from "./client-DFsRJEgB.js";
7
10
  import { n as matrixEventToRaw, r as parseMxc } from "./event-helpers-XRfAbOIh.js";
8
- import { n as createMatrixGuardedFetch, t as MatrixAuthedHttpClient } from "./http-client-D8o8b9u6.js";
11
+ import { n as createMatrixGuardedFetch, t as MatrixAuthedHttpClient } from "./http-client-DOmFvKvB.js";
9
12
  import { n as resolveMatrixRoomKeyBackupReadinessError } from "./backup-health-Dm_YMVFT.js";
10
13
  import { t as createMatrixJsSdkClientLogger } from "./logging-DRjvUOIh.js";
11
14
  import { a as isMatrixAccessTokenInvalidatedError, c as resolveMatrixLocalTimeoutMs, f as isMatrixReadySyncState, i as createMatrixExplicitBootstrapOptions, l as unresolvedMatrixDeviceVerificationStatus, n as MATRIX_INITIAL_CRYPTO_BOOTSTRAP_OPTIONS, o as resolveMatrixDiagnostic, p as isMatrixTerminalSyncState, r as MATRIX_STATUS_DIAGNOSTIC_TIMEOUT_MS, s as resolveMatrixDiagnosticResult, t as MATRIX_AUTOMATIC_REPAIR_BOOTSTRAP_OPTIONS, u as unresolvedMatrixRoomKeyBackupStatus } from "./client-support-DLj4vDeu.js";
12
- import { n as isRepairableSecretStorageAccessError, t as MatrixRecoveryKeyStore } from "./recovery-key-store-CognuDys.js";
13
15
  import { createRequire } from "node:module";
14
16
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
15
17
  import { normalizeNullableString, normalizeStringEntries, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
16
18
  import { createHash } from "node:crypto";
19
+ import path from "node:path";
17
20
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
18
21
  import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
19
- import { ClientEvent, EventType, Filter, MatrixError, MatrixEventEvent, MsgType, Preset, createClient } from "matrix-js-sdk/lib/matrix.js";
20
22
  import { EventEmitter } from "node:events";
23
+ import { ClientEvent, EventType, Filter, MatrixError, MatrixEventEvent, MemoryStore, MsgType, Preset, SyncAccumulator, createClient } from "matrix-js-sdk/lib/matrix.js";
21
24
  import { RoomEvent } from "matrix-js-sdk/lib/models/room.js";
22
25
  import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
23
26
  import { SyncApi, SyncState } from "matrix-js-sdk/lib/sync.js";
27
+ import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js";
24
28
  import { EventStatus } from "matrix-js-sdk/lib/models/event-status.js";
25
29
  //#region extensions/matrix/src/matrix/sdk/client-device-info.ts
26
30
  async function resolveMatrixCrossSigningPublicationStatus(params) {
@@ -135,6 +139,219 @@ function refreshMatrixDmRoomIds(direct, dmRoomIds) {
135
139
  return true;
136
140
  }
137
141
  //#endregion
142
+ //#region extensions/matrix/src/matrix/async-lock.ts
143
+ function createAsyncLock() {
144
+ let lock = Promise.resolve();
145
+ return async function withLock(fn) {
146
+ const previous = lock;
147
+ let release;
148
+ lock = new Promise((resolve) => {
149
+ release = resolve;
150
+ });
151
+ await previous;
152
+ try {
153
+ return await fn();
154
+ } finally {
155
+ release?.();
156
+ }
157
+ };
158
+ }
159
+ //#endregion
160
+ //#region extensions/matrix/src/matrix/client/file-sync-store.ts
161
+ const PERSIST_DEBOUNCE_MS = 250;
162
+ function cloneJson(value) {
163
+ return structuredClone(value);
164
+ }
165
+ function syncDataToSyncResponse(syncData) {
166
+ return {
167
+ next_batch: syncData.nextBatch,
168
+ rooms: syncData.roomsData,
169
+ account_data: { events: syncData.accountData }
170
+ };
171
+ }
172
+ var SqliteBackedMatrixSyncStore = class extends MemoryStore {
173
+ constructor(storageRootDir) {
174
+ super();
175
+ this.storageRootDir = storageRootDir;
176
+ this.persistLock = createAsyncLock();
177
+ this.accumulator = new SyncAccumulator();
178
+ this.savedSync = null;
179
+ this.cleanShutdown = false;
180
+ this.dirty = false;
181
+ this.frozen = false;
182
+ this.persistTimer = null;
183
+ this.persistPromise = null;
184
+ let restoredSavedSync = null;
185
+ let restoredClientOptions;
186
+ let restoredCleanShutdown = false;
187
+ let syncCacheStore = createNoopMatrixSyncCacheStore();
188
+ let syncCacheStoreUnavailableError;
189
+ try {
190
+ syncCacheStore = openMatrixSyncCacheStore(storageRootDir);
191
+ const persisted = readPersistedStoreFromSyncStore(syncCacheStore);
192
+ if (persisted) {
193
+ restoredSavedSync = persisted.savedSync;
194
+ restoredClientOptions = persisted.clientOptions;
195
+ restoredCleanShutdown = persisted.cleanShutdown === true;
196
+ }
197
+ } catch (err) {
198
+ syncCacheStoreUnavailableError = err;
199
+ LogService.warn("MatrixSyncCacheStore", "Failed to load Matrix sync cache:", err);
200
+ }
201
+ this.store = syncCacheStore;
202
+ this.storeUnavailableError = syncCacheStoreUnavailableError;
203
+ this.savedSync = restoredSavedSync;
204
+ this.savedClientOptions = restoredClientOptions;
205
+ this.hadSavedSyncOnLoad = restoredSavedSync !== null;
206
+ this.hadCleanShutdownOnLoad = this.hadSavedSyncOnLoad && restoredCleanShutdown;
207
+ this.cleanShutdown = this.hadCleanShutdownOnLoad;
208
+ if (this.savedSync) {
209
+ this.accumulator.accumulate(syncDataToSyncResponse(this.savedSync), true);
210
+ super.setSyncToken(this.savedSync.nextBatch);
211
+ }
212
+ if (this.savedClientOptions) super.storeClientOptions(this.savedClientOptions);
213
+ }
214
+ hasSavedSync() {
215
+ return this.hadSavedSyncOnLoad;
216
+ }
217
+ hasSavedSyncFromCleanShutdown() {
218
+ return this.hadCleanShutdownOnLoad;
219
+ }
220
+ getSavedSync() {
221
+ return Promise.resolve(this.savedSync ? cloneJson(this.savedSync) : null);
222
+ }
223
+ getSavedSyncToken() {
224
+ return Promise.resolve(this.savedSync?.nextBatch ?? null);
225
+ }
226
+ setSyncData(syncData) {
227
+ if (this.frozen) return Promise.resolve();
228
+ this.accumulator.accumulate(syncData);
229
+ this.savedSync = this.accumulator.getJSON();
230
+ this.markDirtyAndSchedulePersist();
231
+ return Promise.resolve();
232
+ }
233
+ getClientOptions() {
234
+ return Promise.resolve(this.savedClientOptions ? cloneJson(this.savedClientOptions) : void 0);
235
+ }
236
+ storeClientOptions(options) {
237
+ if (this.frozen) return Promise.resolve();
238
+ this.savedClientOptions = cloneJson(options);
239
+ super.storeClientOptions(options);
240
+ this.markDirtyAndSchedulePersist();
241
+ return Promise.resolve();
242
+ }
243
+ save(force = false) {
244
+ if (force) return this.flush();
245
+ return Promise.resolve();
246
+ }
247
+ wantsSave() {
248
+ return false;
249
+ }
250
+ async deleteAllData() {
251
+ this.assertStoreAvailable();
252
+ if (this.persistTimer) {
253
+ clearTimeout(this.persistTimer);
254
+ this.persistTimer = null;
255
+ }
256
+ this.dirty = false;
257
+ await this.persistPromise?.catch(() => void 0);
258
+ await super.deleteAllData();
259
+ this.savedSync = null;
260
+ this.savedClientOptions = void 0;
261
+ this.cleanShutdown = false;
262
+ await deleteMatrixSyncCacheStateFromSyncStore({
263
+ storageRootDir: this.storageRootDir,
264
+ store: this.store
265
+ });
266
+ }
267
+ markCleanShutdown() {
268
+ this.cleanShutdown = true;
269
+ this.dirty = true;
270
+ }
271
+ async freezeSyncCursorPersistence() {
272
+ this.frozen = true;
273
+ if (this.persistTimer) {
274
+ clearTimeout(this.persistTimer);
275
+ this.persistTimer = null;
276
+ }
277
+ await this.persistPromise;
278
+ }
279
+ discardPendingSyncCursorPersistence() {
280
+ this.frozen = true;
281
+ if (this.persistTimer) {
282
+ clearTimeout(this.persistTimer);
283
+ this.persistTimer = null;
284
+ }
285
+ this.cleanShutdown = false;
286
+ this.dirty = false;
287
+ }
288
+ async flush() {
289
+ if (this.persistTimer) {
290
+ clearTimeout(this.persistTimer);
291
+ this.persistTimer = null;
292
+ }
293
+ while (this.dirty || this.persistPromise) {
294
+ if (this.dirty && !this.persistPromise) this.persistPromise = this.persist().finally(() => {
295
+ this.persistPromise = null;
296
+ });
297
+ await this.persistPromise;
298
+ }
299
+ }
300
+ markDirtyAndSchedulePersist() {
301
+ if (this.frozen) return;
302
+ this.cleanShutdown = false;
303
+ this.dirty = true;
304
+ if (this.persistTimer) return;
305
+ this.persistTimer = setTimeout(() => {
306
+ this.persistTimer = null;
307
+ this.flush().catch((err) => {
308
+ LogService.warn("MatrixSyncCacheStore", "Failed to persist Matrix sync store:", err);
309
+ });
310
+ }, PERSIST_DEBOUNCE_MS);
311
+ this.persistTimer.unref?.();
312
+ }
313
+ async persist() {
314
+ this.assertStoreAvailable();
315
+ this.dirty = false;
316
+ const payload = {
317
+ version: 1,
318
+ savedSync: this.savedSync ? cloneJson(this.savedSync) : null,
319
+ cleanShutdown: this.cleanShutdown,
320
+ ...this.savedClientOptions ? { clientOptions: cloneJson(this.savedClientOptions) } : {}
321
+ };
322
+ try {
323
+ await this.persistLock(async () => {
324
+ writeMatrixSyncCacheStateToSyncStore({
325
+ payload,
326
+ store: this.store
327
+ });
328
+ claimCurrentTokenStorageState({ rootDir: this.storageRootDir });
329
+ });
330
+ } catch (err) {
331
+ this.dirty = true;
332
+ throw err;
333
+ }
334
+ }
335
+ assertStoreAvailable() {
336
+ if (this.storeUnavailableError == null) return;
337
+ throw new Error("Matrix sync cache SQLite store is unavailable; cannot persist sync state", { cause: this.storeUnavailableError });
338
+ }
339
+ };
340
+ function createNoopMatrixSyncCacheStore() {
341
+ return {
342
+ register: () => {},
343
+ registerIfAbsent: () => false,
344
+ lookup: () => void 0,
345
+ consume: () => void 0,
346
+ delete: () => false,
347
+ entries: () => [],
348
+ clear: () => {}
349
+ };
350
+ }
351
+ function openMatrixSyncCacheStore(storageRootDir) {
352
+ return getMatrixRuntime().state.openSyncKeyedStore(openMatrixSyncCacheStoreOptions(storageRootDir));
353
+ }
354
+ //#endregion
138
355
  //#region extensions/matrix/src/matrix/sdk/client-sync-quiesce.ts
139
356
  const MATRIX_SYNC_QUIESCE_TIMEOUT_MS = 5e3;
140
357
  const MATRIX_JS_SDK_SYNC_VERSION = "42.2.0";
@@ -204,6 +421,275 @@ async function quiesceMatrixClientSync(params) {
204
421
  });
205
422
  }
206
423
  //#endregion
424
+ //#region extensions/matrix/src/matrix/sdk/recovery-key-store.ts
425
+ function isRepairableSecretStorageAccessError(err) {
426
+ const message = formatMatrixErrorReason(err);
427
+ if (!message) return false;
428
+ if (message.includes("getsecretstoragekey callback returned falsey")) return true;
429
+ if (message.includes("decrypting secret") && message.includes("bad mac")) return true;
430
+ return false;
431
+ }
432
+ var MatrixRecoveryKeyStore = class {
433
+ constructor(recoveryKeyPath) {
434
+ this.secretStorageKeyCache = /* @__PURE__ */ new Map();
435
+ this.stagedRecoveryKey = null;
436
+ this.stagedRecoveryKeyUsed = false;
437
+ this.stagedCacheKeyIds = /* @__PURE__ */ new Set();
438
+ this.recoveryKeyPath = recoveryKeyPath;
439
+ this.storageRootDir = recoveryKeyPath ? path.dirname(recoveryKeyPath) : void 0;
440
+ if (this.recoveryKeyPath) try {
441
+ migrateLegacyMatrixRecoveryKeyFilePathToStore(this.recoveryKeyPath);
442
+ } catch (err) {
443
+ this.legacyRecoveryKeyPathOnMigrationFailure = this.recoveryKeyPath;
444
+ LogService.warn("MatrixClientLite", "Failed to migrate Matrix recovery key state:", err);
445
+ }
446
+ }
447
+ buildCryptoCallbacks() {
448
+ return {
449
+ getSecretStorageKey: async ({ keys }) => {
450
+ const requestedKeyIds = Object.keys(keys ?? {});
451
+ if (requestedKeyIds.length === 0) return null;
452
+ const staged = this.resolveStagedSecretStorageKey(requestedKeyIds);
453
+ if (staged) return staged;
454
+ for (const keyId of requestedKeyIds) {
455
+ const cached = this.secretStorageKeyCache.get(keyId);
456
+ if (cached) return [keyId, new Uint8Array(cached.key)];
457
+ }
458
+ const stored = this.loadStoredRecoveryKey();
459
+ if (!stored?.privateKeyBase64) return null;
460
+ const privateKey = new Uint8Array(Buffer.from(stored.privateKeyBase64, "base64"));
461
+ if (privateKey.length === 0) return null;
462
+ if (stored.keyId && requestedKeyIds.includes(stored.keyId)) {
463
+ this.rememberSecretStorageKey(stored.keyId, privateKey, stored.keyInfo);
464
+ return [stored.keyId, privateKey];
465
+ }
466
+ const firstRequestedKeyId = requestedKeyIds[0];
467
+ if (!firstRequestedKeyId) return null;
468
+ this.rememberSecretStorageKey(firstRequestedKeyId, privateKey, stored.keyInfo);
469
+ return [firstRequestedKeyId, privateKey];
470
+ },
471
+ cacheSecretStorageKey: (keyId, keyInfo, key) => {
472
+ const privateKey = new Uint8Array(key);
473
+ const normalizedKeyInfo = {
474
+ passphrase: keyInfo?.passphrase,
475
+ name: typeof keyInfo?.name === "string" ? keyInfo.name : void 0
476
+ };
477
+ this.rememberSecretStorageKey(keyId, privateKey, normalizedKeyInfo);
478
+ const stored = this.loadStoredRecoveryKey();
479
+ this.saveRecoveryKeyToDisk({
480
+ keyId,
481
+ keyInfo: normalizedKeyInfo,
482
+ privateKey,
483
+ encodedPrivateKey: stored?.encodedPrivateKey
484
+ });
485
+ }
486
+ };
487
+ }
488
+ getRecoveryKeySummary() {
489
+ const stored = this.loadStoredRecoveryKey();
490
+ if (!stored) return null;
491
+ return {
492
+ encodedPrivateKey: stored.encodedPrivateKey,
493
+ keyId: stored.keyId,
494
+ createdAt: stored.createdAt
495
+ };
496
+ }
497
+ getSecretStorageKeyCandidate(keyId) {
498
+ const normalizedKeyId = keyId.trim();
499
+ if (!normalizedKeyId) return null;
500
+ const staged = this.resolveStagedSecretStorageKey([normalizedKeyId]);
501
+ if (staged) return staged[1];
502
+ const stored = this.loadStoredRecoveryKey();
503
+ if (!stored?.privateKeyBase64) return null;
504
+ const privateKey = new Uint8Array(Buffer.from(stored.privateKeyBase64, "base64"));
505
+ if (privateKey.length === 0) return null;
506
+ this.rememberSecretStorageKey(normalizedKeyId, privateKey, stored.keyInfo);
507
+ return privateKey;
508
+ }
509
+ resolveEncodedRecoveryKeyInput(params) {
510
+ const encodedPrivateKey = params.encodedPrivateKey.trim();
511
+ if (!encodedPrivateKey) throw new Error("Matrix recovery key is required");
512
+ let privateKey;
513
+ try {
514
+ privateKey = decodeRecoveryKey(encodedPrivateKey);
515
+ } catch (err) {
516
+ throw new Error(`Invalid Matrix recovery key: ${formatErrorMessage(err)}`, { cause: err });
517
+ }
518
+ const keyId = typeof params.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : null;
519
+ return {
520
+ encodedPrivateKey,
521
+ privateKey,
522
+ keyId,
523
+ keyInfo: params.keyInfo ?? this.loadStoredRecoveryKey()?.keyInfo
524
+ };
525
+ }
526
+ storeEncodedRecoveryKey(params) {
527
+ const prepared = this.resolveEncodedRecoveryKeyInput(params);
528
+ this.saveRecoveryKeyToDisk({
529
+ keyId: prepared.keyId,
530
+ keyInfo: prepared.keyInfo,
531
+ privateKey: prepared.privateKey,
532
+ encodedPrivateKey: prepared.encodedPrivateKey
533
+ });
534
+ if (prepared.keyId) this.rememberSecretStorageKey(prepared.keyId, prepared.privateKey, prepared.keyInfo);
535
+ return this.getRecoveryKeySummary() ?? {};
536
+ }
537
+ stageEncodedRecoveryKey(params) {
538
+ const prepared = this.resolveEncodedRecoveryKeyInput(params);
539
+ this.discardStagedRecoveryKey();
540
+ this.stagedRecoveryKey = {
541
+ version: 1,
542
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
543
+ keyId: prepared.keyId,
544
+ encodedPrivateKey: prepared.encodedPrivateKey,
545
+ privateKeyBase64: Buffer.from(prepared.privateKey).toString("base64"),
546
+ keyInfo: prepared.keyInfo
547
+ };
548
+ }
549
+ hasStagedRecoveryKeyBeenUsed() {
550
+ return this.stagedRecoveryKeyUsed;
551
+ }
552
+ commitStagedRecoveryKey(params) {
553
+ if (!this.stagedRecoveryKey) return this.getRecoveryKeySummary();
554
+ const staged = this.stagedRecoveryKey;
555
+ const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
556
+ const keyId = typeof params?.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : staged.keyId;
557
+ this.saveRecoveryKeyToDisk({
558
+ keyId,
559
+ keyInfo: params?.keyInfo ?? staged.keyInfo,
560
+ privateKey,
561
+ encodedPrivateKey: staged.encodedPrivateKey
562
+ });
563
+ this.clearStagedRecoveryKeyTracking();
564
+ return this.getRecoveryKeySummary();
565
+ }
566
+ discardStagedRecoveryKey() {
567
+ for (const keyId of this.stagedCacheKeyIds) this.secretStorageKeyCache.delete(keyId);
568
+ this.clearStagedRecoveryKeyTracking();
569
+ }
570
+ async bootstrapSecretStorageWithRecoveryKey(crypto, options = {}) {
571
+ let status = null;
572
+ const getSecretStorageStatus = crypto.getSecretStorageStatus;
573
+ if (typeof getSecretStorageStatus === "function") try {
574
+ status = await getSecretStorageStatus.call(crypto);
575
+ } catch (err) {
576
+ LogService.warn("MatrixClientLite", "Failed to read secret storage status:", err);
577
+ }
578
+ const hasDefaultSecretStorageKey = Boolean(status?.defaultKeyId);
579
+ const hasKnownInvalidSecrets = Object.values(status?.secretStorageKeyValidityMap ?? {}).some((valid) => !valid);
580
+ let generatedRecoveryKey = false;
581
+ const storedRecovery = this.loadStoredRecoveryKey();
582
+ const stagedRecovery = this.stagedRecoveryKey;
583
+ const sourceRecovery = options.forceNewRecoveryKey === true ? null : stagedRecovery ?? storedRecovery;
584
+ let recoveryKey = sourceRecovery ? {
585
+ keyInfo: sourceRecovery.keyInfo,
586
+ privateKey: new Uint8Array(Buffer.from(sourceRecovery.privateKeyBase64, "base64")),
587
+ encodedPrivateKey: sourceRecovery.encodedPrivateKey
588
+ } : null;
589
+ if (recoveryKey && status?.defaultKeyId) {
590
+ const defaultKeyId = status.defaultKeyId;
591
+ if (!stagedRecovery) {
592
+ this.rememberSecretStorageKey(defaultKeyId, recoveryKey.privateKey, recoveryKey.keyInfo);
593
+ if (storedRecovery && storedRecovery.keyId !== defaultKeyId) this.saveRecoveryKeyToDisk({
594
+ keyId: defaultKeyId,
595
+ keyInfo: recoveryKey.keyInfo,
596
+ privateKey: recoveryKey.privateKey,
597
+ encodedPrivateKey: recoveryKey.encodedPrivateKey
598
+ });
599
+ }
600
+ }
601
+ const ensureRecoveryKey = async () => {
602
+ if (recoveryKey) {
603
+ if (stagedRecovery) this.stagedRecoveryKeyUsed = true;
604
+ return recoveryKey;
605
+ }
606
+ if (typeof crypto.createRecoveryKeyFromPassphrase !== "function") throw new Error("Matrix crypto backend does not support recovery key generation (createRecoveryKeyFromPassphrase missing)");
607
+ recoveryKey = await crypto.createRecoveryKeyFromPassphrase();
608
+ this.saveRecoveryKeyToDisk(recoveryKey);
609
+ generatedRecoveryKey = true;
610
+ return recoveryKey;
611
+ };
612
+ const shouldRecreateSecretStorage = options.forceNewSecretStorage === true || !hasDefaultSecretStorageKey || !recoveryKey && status?.ready === false || hasKnownInvalidSecrets;
613
+ if (hasKnownInvalidSecrets) recoveryKey = null;
614
+ const secretStorageOptions = { setupNewKeyBackup: options.setupNewKeyBackup === true };
615
+ if (shouldRecreateSecretStorage) {
616
+ secretStorageOptions.setupNewSecretStorage = true;
617
+ secretStorageOptions.createSecretStorageKey = ensureRecoveryKey;
618
+ }
619
+ try {
620
+ await crypto.bootstrapSecretStorage(secretStorageOptions);
621
+ } catch (err) {
622
+ if (!(options.allowSecretStorageRecreateWithoutRecoveryKey === true && hasDefaultSecretStorageKey && isRepairableSecretStorageAccessError(err))) throw err;
623
+ recoveryKey = null;
624
+ LogService.warn("MatrixClientLite", "Secret storage exists on the server but local recovery material cannot unlock it; recreating secret storage during explicit bootstrap.");
625
+ await crypto.bootstrapSecretStorage({
626
+ setupNewSecretStorage: true,
627
+ setupNewKeyBackup: options.setupNewKeyBackup === true,
628
+ createSecretStorageKey: ensureRecoveryKey
629
+ });
630
+ }
631
+ if (generatedRecoveryKey && this.storageRootDir) LogService.warn("MatrixClientLite", "Generated Matrix recovery key and saved it to Matrix SQLite state. Keep the displayed recovery key secure.");
632
+ }
633
+ clearStagedRecoveryKeyTracking() {
634
+ this.stagedRecoveryKey = null;
635
+ this.stagedRecoveryKeyUsed = false;
636
+ this.stagedCacheKeyIds.clear();
637
+ }
638
+ resolveStagedSecretStorageKey(requestedKeyIds) {
639
+ const staged = this.stagedRecoveryKey;
640
+ if (!staged?.privateKeyBase64) return null;
641
+ const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
642
+ if (privateKey.length === 0) return null;
643
+ const keyId = staged.keyId && requestedKeyIds.includes(staged.keyId) ? staged.keyId : requestedKeyIds[0];
644
+ if (!keyId) return null;
645
+ this.rememberStagedSecretStorageKey(keyId, privateKey, staged.keyInfo);
646
+ this.stagedCacheKeyIds.add(keyId);
647
+ return [keyId, privateKey];
648
+ }
649
+ rememberStagedSecretStorageKey(keyId, key, keyInfo) {
650
+ this.stagedRecoveryKeyUsed = true;
651
+ this.rememberSecretStorageKey(keyId, key, keyInfo);
652
+ }
653
+ rememberSecretStorageKey(keyId, key, keyInfo) {
654
+ if (!keyId.trim()) return;
655
+ this.secretStorageKeyCache.set(keyId, {
656
+ key: new Uint8Array(key),
657
+ keyInfo
658
+ });
659
+ }
660
+ loadStoredRecoveryKey() {
661
+ if (!this.recoveryKeyPath) return null;
662
+ try {
663
+ const stored = readMatrixRecoveryKeyStateForPath(this.recoveryKeyPath);
664
+ if (stored) return stored;
665
+ } catch {}
666
+ if (this.legacyRecoveryKeyPathOnMigrationFailure) return readLegacyMatrixRecoveryKeyFile(this.legacyRecoveryKeyPathOnMigrationFailure);
667
+ return null;
668
+ }
669
+ saveRecoveryKeyToDisk(params) {
670
+ if (!this.recoveryKeyPath) return;
671
+ try {
672
+ const payload = {
673
+ version: 1,
674
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
675
+ keyId: typeof params.keyId === "string" ? params.keyId : null,
676
+ encodedPrivateKey: params.encodedPrivateKey,
677
+ privateKeyBase64: Buffer.from(params.privateKey).toString("base64"),
678
+ keyInfo: params.keyInfo ? {
679
+ passphrase: params.keyInfo.passphrase,
680
+ name: params.keyInfo.name
681
+ } : void 0
682
+ };
683
+ writeMatrixRecoveryKeyStateForPath({
684
+ recoveryKeyPath: this.recoveryKeyPath,
685
+ payload
686
+ });
687
+ } catch (err) {
688
+ LogService.warn("MatrixClientLite", "Failed to persist recovery key:", err);
689
+ }
690
+ }
691
+ };
692
+ //#endregion
207
693
  //#region extensions/matrix/src/matrix/sdk/client-base.ts
208
694
  function resolveMessageWireDispatch(resource, init) {
209
695
  if ((init?.method ?? (resource instanceof Request ? resource.method : "GET")).toUpperCase() !== "PUT") return null;
@@ -221,7 +707,7 @@ function resolveMessageWireDispatch(resource, init) {
221
707
  };
222
708
  }
223
709
  let loadedMatrixCryptoRuntime = null;
224
- const loadMatrixCryptoRuntime = createLazyRuntimeModule(() => import("./crypto-runtime-C4WDYxlP.js").then((runtime) => {
710
+ const loadMatrixCryptoRuntime = createLazyRuntimeModule(() => import("./crypto-runtime-QvlgyCkj.js").then((runtime) => {
225
711
  loadedMatrixCryptoRuntime = runtime;
226
712
  return runtime;
227
713
  }));
@@ -552,13 +1038,15 @@ var MatrixClientBase = class {
552
1038
  if (!cryptoBootstrapper) return;
553
1039
  const initial = await cryptoBootstrapper.bootstrap(crypto, MATRIX_INITIAL_CRYPTO_BOOTSTRAP_OPTIONS);
554
1040
  throwIfMatrixStartupAborted(abortSignal);
555
- if (!initial.crossSigningPublished || initial.ownDeviceVerified === false) if ((await this.getOwnDeviceVerificationStatus()).signedByOwner) LogService.warn("MatrixClientLite", "Cross-signing/bootstrap is incomplete for an already owner-signed device; skipping automatic reset and preserving the current identity. Restore the recovery key or run an explicit verification bootstrap if repair is needed.");
556
- else try {
557
- const repaired = await cryptoBootstrapper.bootstrap(crypto, MATRIX_AUTOMATIC_REPAIR_BOOTSTRAP_OPTIONS);
558
- throwIfMatrixStartupAborted(abortSignal);
559
- if (repaired.crossSigningPublished && repaired.ownDeviceVerified !== false) LogService.info("MatrixClientLite", "Cross-signing/bootstrap recovered after forced reset");
560
- } catch (err) {
561
- LogService.warn("MatrixClientLite", "Failed to recover cross-signing/bootstrap with forced reset:", err);
1041
+ if (!initial.crossSigningPublished || initial.ownDeviceVerified === false) {
1042
+ if ((await this.getOwnDeviceVerificationStatus()).signedByOwner) LogService.warn("MatrixClientLite", "Cross-signing/bootstrap is incomplete for an already owner-signed device; skipping automatic reset and preserving the current identity. Restore the recovery key or run an explicit verification bootstrap if repair is needed.");
1043
+ else try {
1044
+ const repaired = await cryptoBootstrapper.bootstrap(crypto, MATRIX_AUTOMATIC_REPAIR_BOOTSTRAP_OPTIONS);
1045
+ throwIfMatrixStartupAborted(abortSignal);
1046
+ if (repaired.crossSigningPublished && repaired.ownDeviceVerified !== false) LogService.info("MatrixClientLite", "Cross-signing/bootstrap recovered after forced reset");
1047
+ } catch (err) {
1048
+ LogService.warn("MatrixClientLite", "Failed to recover cross-signing/bootstrap with forced reset:", err);
1049
+ }
562
1050
  }
563
1051
  this.cryptoBootstrapped = true;
564
1052
  }
@@ -881,14 +1369,16 @@ var MatrixClientVerification = class extends MatrixClientCore {
881
1369
  let keyLoadAttempted = false;
882
1370
  let keyLoadError = null;
883
1371
  if (serverVersion && (shouldLoadBackupKey || shouldActivateBackup)) {
884
- if (shouldLoadBackupKey) if (typeof crypto.loadSessionBackupPrivateKeyFromSecretStorage === "function") {
885
- keyLoadAttempted = true;
886
- try {
887
- await crypto.loadSessionBackupPrivateKeyFromSecretStorage();
888
- } catch (err) {
889
- keyLoadError = formatErrorMessage(err);
890
- }
891
- } else keyLoadError = "Matrix crypto backend does not support loading backup keys from secret storage";
1372
+ if (shouldLoadBackupKey) {
1373
+ if (typeof crypto.loadSessionBackupPrivateKeyFromSecretStorage === "function") {
1374
+ keyLoadAttempted = true;
1375
+ try {
1376
+ await crypto.loadSessionBackupPrivateKeyFromSecretStorage();
1377
+ } catch (err) {
1378
+ keyLoadError = formatErrorMessage(err);
1379
+ }
1380
+ } else keyLoadError = "Matrix crypto backend does not support loading backup keys from secret storage";
1381
+ }
892
1382
  if (!keyLoadError) await this.enableTrustedRoomKeyBackupIfPossible(crypto);
893
1383
  ({activeVersion, decryptionKeyCached} = await this.resolveRoomKeyBackupLocalState(crypto));
894
1384
  ({serverVersion, trusted, matchesDecryptionKey} = await this.resolveRoomKeyBackupTrustState(crypto, serverVersion));
@@ -1056,6 +1546,11 @@ var MatrixClientVerification = class extends MatrixClientCore {
1056
1546
  };
1057
1547
  //#endregion
1058
1548
  //#region extensions/matrix/src/matrix/sdk.ts
1549
+ var sdk_exports = /* @__PURE__ */ __exportAll({
1550
+ ConsoleLogger: () => ConsoleLogger,
1551
+ LogService: () => LogService,
1552
+ MatrixClient: () => MatrixClient
1553
+ });
1059
1554
  var MatrixClient = class extends MatrixClientVerification {
1060
1555
  async verifyWithRecoveryKey(rawRecoveryKey) {
1061
1556
  const fail = async (error, fields = {}) => {
@@ -1424,4 +1919,4 @@ var MatrixClient = class extends MatrixClientVerification {
1424
1919
  }
1425
1920
  };
1426
1921
  //#endregion
1427
- export { ConsoleLogger, LogService, MatrixClient };
1922
+ export { ConsoleLogger, LogService, MatrixClient, isRepairableSecretStorageAccessError as n, sdk_exports as t };
@@ -19,11 +19,12 @@ import { isAutoLinkedFileRef } from "openclaw/plugin-sdk/text-autolink-runtime";
19
19
  import { isVoiceMessageCompatibleAudio } from "openclaw/plugin-sdk/media-runtime";
20
20
  import { parseBuffer } from "music-metadata";
21
21
  //#region extensions/matrix/src/matrix/send/client.ts
22
- const loadMatrixSendClientRuntime = createLazyRuntimeModule(() => import("./client-bootstrap-D8irSL2i.js").then((n) => n.t));
22
+ const loadMatrixSendClientRuntime = createLazyRuntimeModule(() => import("./client-bootstrap-DjXCKEtg.js").then((n) => n.t));
23
23
  function resolveMediaMaxBytes(accountId, cfg) {
24
24
  if (!cfg) throw new Error("Matrix media limits requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.");
25
+ const resolvedCfg = requireRuntimeConfig(cfg, "Matrix media limits");
25
26
  const mediaMaxMb = resolveMatrixAccountConfig({
26
- cfg: requireRuntimeConfig(cfg, "Matrix media limits"),
27
+ cfg: resolvedCfg,
27
28
  accountId
28
29
  }).mediaMaxMb;
29
30
  return typeof mediaMaxMb === "number" && mediaMaxMb > 0 ? mediaMaxMb * 1024 * 1024 : void 0;
@@ -359,7 +360,7 @@ async function resolveMatrixRoomId(client, raw) {
359
360
  //#region extensions/matrix/src/matrix/delivery-plan.ts
360
361
  const DELIVERY_PLAN_VERSION = 1;
361
362
  const DELIVERY_PLAN_NAMESPACE = "outbound-delivery-plans";
362
- const DELIVERY_PLAN_TTL_MS = 1440 * 60 * 1e3;
363
+ const DELIVERY_PLAN_TTL_MS = 864e5;
363
364
  var MatrixDeliveryPlanInvariantError = class extends Error {
364
365
  constructor(message) {
365
366
  super(message);
@@ -370,8 +371,8 @@ function createDeliveryPlanStore() {
370
371
  return getMatrixRuntime().state.openBlobStore({
371
372
  namespace: DELIVERY_PLAN_NAMESPACE,
372
373
  maxEntries: 1e4,
373
- maxBytesPerEntry: 8 * 1024 * 1024,
374
- maxBytesPerNamespace: 256 * 1024 * 1024,
374
+ maxBytesPerEntry: 8388608,
375
+ maxBytesPerNamespace: 268435456,
375
376
  overflowPolicy: "reject-new",
376
377
  defaultTtlMs: DELIVERY_PLAN_TTL_MS
377
378
  });
@@ -639,7 +640,8 @@ function isPollEventType(eventType) {
639
640
  }
640
641
  function getTextContent(text) {
641
642
  if (!isRecord(text)) return "";
642
- return normalizeOptionalString(text["m.text"] ?? text["org.matrix.msc1767.text"] ?? text.body) ?? "";
643
+ const value = text["m.text"] ?? text["org.matrix.msc1767.text"] ?? text.body;
644
+ return normalizeOptionalString(value) ?? "";
643
645
  }
644
646
  function parsePollStart(content) {
645
647
  const poll = content["m.poll.start"] ?? content[ORG_POLL_START] ?? content["m.poll"];
@@ -852,8 +854,9 @@ function isMarkdownEscaped(markdown, index) {
852
854
  return slashCount % 2 === 1;
853
855
  }
854
856
  function projectMatrixMarkdown(markdown) {
857
+ const normalized = (markdown ?? "").replace(/\r\n?/gu, "\n");
855
858
  return renderMarkdownWithMarkers({
856
- text: (markdown ?? "").replace(/\r\n?/gu, "\n"),
859
+ text: normalized,
857
860
  styles: [],
858
861
  links: []
859
862
  }, {
@@ -1427,11 +1430,12 @@ function markdownToMatrixBody(markdown) {
1427
1430
  const close = offsets[index + 1];
1428
1431
  if (open !== void 0 && close !== void 0) body = `${body.slice(0, open)}[Spoiler]${body.slice(close + 2)}`;
1429
1432
  }
1430
- return renderMarkdownWithMarkers(markdownToIR(body, {
1433
+ const ir = markdownToIR(body, {
1431
1434
  enableHtmlUnderline: true,
1432
1435
  headingStyle: "rich",
1433
1436
  linkify: true
1434
- }), {
1437
+ });
1438
+ return renderMarkdownWithMarkers(ir, {
1435
1439
  styleMarkers: {},
1436
1440
  escapeText: (text) => text
1437
1441
  }, MATRIX_FORMAT_PROFILE);
@@ -1,3 +1,3 @@
1
1
  import { r as setMatrixRuntime } from "./runtime-6S3DNFNv.js";
2
- import { t as createMatrixThreadBindingManager } from "./thread-bindings-ERWNousC.js";
2
+ import { t as createMatrixThreadBindingManager } from "./thread-bindings-2HN2AyLu.js";
3
3
  export { createMatrixThreadBindingManager, setMatrixRuntime };