@openclaw/matrix 2026.7.2-beta.3 → 2026.7.2-beta.5

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 (77) hide show
  1. package/README.md +1 -1
  2. package/dist/api.js +4 -4
  3. package/dist/{approval-handler.runtime-BEa98wwG.js → approval-handler.runtime-D1ibJgSk.js} +4 -4
  4. package/dist/{approval-ids-Dfn7oQAm.js → approval-ids-2OQj32-K.js} +1 -1
  5. package/dist/{approval-reaction-auth-kXkCJBGi.js → approval-reaction-auth-CCAWWkbu.js} +2 -2
  6. package/dist/{channel-j331Xd7b.js → channel-Cmi248PA.js} +34 -32
  7. package/dist/channel-plugin-api.js +1 -1
  8. package/dist/{channel.runtime-BIwlVfQw.js → channel.runtime-BaPXFRgT.js} +34 -40
  9. package/dist/{cli-0EcKfqFw.js → cli-0CNHkps5.js} +868 -852
  10. package/dist/{cli-metadata-Xq1Xb15R.js → cli-metadata-DnXxNCoj.js} +1 -1
  11. package/dist/cli-metadata.js +1 -1
  12. package/dist/{client-CA0PULls.js → client-BFRg0kd4.js} +2 -2
  13. package/dist/{client-BtG4quUl.js → client-CitERujx.js} +2 -2
  14. package/dist/{client-bootstrap-Dk5EAn3n.js → client-bootstrap-CkAnkzB6.js} +1 -1
  15. package/dist/{config-schema-B5GRV8wL.js → config-schema-BShrVROw.js} +19 -6
  16. package/dist/contract-api.js +2 -2
  17. package/dist/{create-client-WQExaby_.js → create-client-f-CkRllE.js} +3 -3
  18. package/dist/{crypto-runtime-CAff-n15.js → crypto-runtime-D9_6J5tZ.js} +2 -2
  19. package/dist/{device-health-D4LBxuPq.js → device-health-B4-YXtJR.js} +6 -1
  20. package/dist/{directory-live-DiC-0XBC.js → directory-live-YRgYDx2w.js} +3 -3
  21. package/dist/{doctor-DwUVm5Lw.js → doctor-CM8ijNpW.js} +1 -1
  22. package/dist/doctor-contract-BMSJkkAE.js +167 -0
  23. package/dist/doctor-contract-api.js +112 -71
  24. package/dist/{draft-stream-CTLKtJJ0.js → draft-stream-CIjafRr0.js} +1 -1
  25. package/dist/{file-sync-store-CPkgnSXp.js → file-sync-store-DiiFsayX.js} +1 -1
  26. package/dist/{http-client-BmrgOZTL.js → http-client-CycYxU9-.js} +2 -2
  27. package/dist/{idb-persistence-Dyy6ipgU.js → idb-persistence-B6x7dMsF.js} +75 -72
  28. package/dist/index.js +1 -1
  29. package/dist/{logging-QH-48Gr6.js → logging-DV-p52N0.js} +8 -1
  30. package/dist/{media-text-BMXEXb1j.js → media-text-DlQC_k_K.js} +1 -1
  31. package/dist/{messages-3UBHfZrN.js → messages-Bf_s--M9.js} +3 -3
  32. package/dist/{monitor-BtUIds8T.js → monitor-s--XqoxF.js} +2041 -1804
  33. package/dist/plugin-entry.handlers.runtime.js +1 -1
  34. package/dist/probe.runtime-BJOvCHnZ.js +3 -0
  35. package/dist/{profile-update-Bh2XtJwN.js → profile-update-z3aM46KS.js} +2 -2
  36. package/dist/{reaction-events-BwAKtUyQ.js → reaction-events-DrK9Zua7.js} +2 -2
  37. package/dist/{recovery-key-store-CW6eePfp.js → recovery-key-store-BNnHvXdk.js} +1 -1
  38. package/dist/{resolve-targets-DVoj-YxB.js → resolve-targets-nNMcrV3W.js} +1 -1
  39. package/dist/{resolver.runtime-CC0VVsAt.js → resolver.runtime-BvaFlVLg.js} +1 -1
  40. package/dist/{room-info-B6vKD5DF.js → room-info-CAFZ3Z9J.js} +13 -12
  41. package/dist/{sdk-CIDZXWpZ.js → sdk-UzPd8tst.js} +227 -181
  42. package/dist/{send-BJbrdmNm.js → send-C9Ssx-iV.js} +624 -109
  43. package/dist/session-binding-contract-api.js +1 -1
  44. package/dist/{setup-bootstrap-DGPOOdz-.js → setup-bootstrap-BBGpPKgy.js} +2 -2
  45. package/dist/{setup-core-XCdAx1nY.js → setup-core-a542Ernq.js} +135 -45
  46. package/dist/setup-plugin-api.js +4 -3
  47. package/dist/{setup-surface-CzUiTe_k.js → setup-surface-BJrCI6KT.js} +34 -30
  48. package/dist/{shared-DquM1oz6.js → shared-CUH5otj8.js} +5 -12
  49. package/dist/{startup-verification-CA00kebL.js → startup-verification-wm3_i88s.js} +1 -1
  50. package/dist/{storage-CzHxeF5E.js → storage-BvAkgzvT.js} +24 -57
  51. package/dist/{thread-bindings-Cw194yEn.js → thread-bindings-D3RfVgAF.js} +4 -3
  52. package/dist/{tool-actions.runtime-C0jgWYhX.js → tool-actions.runtime-Dh5ow2EK.js} +8 -8
  53. package/dist/{verification-DjxyWTNP.js → verification-ZdAXdmuh.js} +1 -1
  54. package/node_modules/music-metadata/lib/common/Util.d.ts +1 -1
  55. package/node_modules/music-metadata/lib/common/Util.js +7 -1
  56. package/node_modules/music-metadata/lib/id3v2/FrameHeader.js +23 -3
  57. package/node_modules/music-metadata/lib/id3v2/FrameParser.js +2 -2
  58. package/node_modules/music-metadata/lib/id3v2/ID3v2Token.js +1 -1
  59. package/node_modules/music-metadata/lib/mp4/AtomToken.js +38 -13
  60. package/node_modules/music-metadata/lib/mpeg/MpegParser.js +1 -1
  61. package/node_modules/music-metadata/package.json +6 -6
  62. package/node_modules/typebox/build/compile/validator.d.mts +1 -4
  63. package/node_modules/typebox/build/guard/guard.d.mts +1 -1
  64. package/node_modules/typebox/build/guard/guard.mjs +5 -2
  65. package/node_modules/typebox/build/guard/string.mjs +16 -4
  66. package/node_modules/typebox/build/schema/engine/_functions.mjs +34 -15
  67. package/node_modules/typebox/build/type/action/readonly_object.d.mts +5 -0
  68. package/node_modules/typebox/build/type/action/readonly_object.mjs +8 -0
  69. package/node_modules/typebox/build/typebox.d.mts +1 -1
  70. package/node_modules/typebox/build/typebox.mjs +1 -1
  71. package/node_modules/typebox/package.json +1 -1
  72. package/node_modules/typebox/readme.md +29 -32
  73. package/openclaw.plugin.json +7 -20
  74. package/package.json +111 -29
  75. package/dist/doctor-contract-BA2Y6Crx.js +0 -312
  76. package/dist/probe.runtime-sBV-Govx.js +0 -3
  77. package/npm-shrinkwrap.json +0 -557
@@ -2,7 +2,7 @@ import { t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
2
2
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
3
3
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  //#region extensions/matrix/src/plugin-entry.runtime.ts
5
- const loadMatrixVerificationRuntime = createLazyRuntimeModule(() => import("./verification-DjxyWTNP.js").then((n) => n.y));
5
+ const loadMatrixVerificationRuntime = createLazyRuntimeModule(() => import("./verification-ZdAXdmuh.js").then((n) => n.y));
6
6
  function sendError(respond, err) {
7
7
  respond(false, { error: formatMatrixErrorMessage(err) });
8
8
  }
@@ -0,0 +1,3 @@
1
+ import { t as createMatrixClient } from "./create-client-f-CkRllE.js";
2
+ import "./client-BFRg0kd4.js";
3
+ export { createMatrixClient };
@@ -1,6 +1,6 @@
1
1
  import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
2
- import { c as resolveMatrixConfigPath, l as updateMatrixAccountConfig, o as syncMatrixOwnProfile } from "./setup-core-XCdAx1nY.js";
3
- import { n as withResolvedActionClient } from "./client-BtG4quUl.js";
2
+ import { l as resolveMatrixConfigPath, s as syncMatrixOwnProfile, u as updateMatrixAccountConfig } from "./setup-core-a542Ernq.js";
3
+ import { n as withResolvedActionClient } from "./client-CitERujx.js";
4
4
  import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
5
5
  //#region extensions/matrix/src/matrix/actions/profile.ts
6
6
  async function updateMatrixOwnProfile(opts = {}) {
@@ -6,9 +6,9 @@ import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
6
6
  import { normalizeAccountId } from "openclaw/plugin-sdk/routing";
7
7
  import { getSessionBindingService } from "openclaw/plugin-sdk/session-binding-runtime";
8
8
  //#region extensions/matrix/src/matrix/monitor/reaction-events.ts
9
- const loadApprovalReactionAuth = createLazyRuntimeModule(() => import("./approval-reaction-auth-kXkCJBGi.js"));
9
+ const loadApprovalReactionAuth = createLazyRuntimeModule(() => import("./approval-reaction-auth-CCAWWkbu.js"));
10
10
  const loadExecApprovalResolver = createLazyRuntimeModule(() => import("./exec-approval-resolver-BCgqRtZS.js"));
11
- const loadMatrixSend = createLazyRuntimeModule(() => import("./send-BJbrdmNm.js").then((n) => n.l));
11
+ const loadMatrixSend = createLazyRuntimeModule(() => import("./send-C9Ssx-iV.js").then((n) => n.s));
12
12
  function buildMatrixApprovalTerminalText(result) {
13
13
  const approval = result.approval;
14
14
  const terminalLabel = approval.status === "allowed" ? approval.decision === "allow-always" ? "Allowed always" : "Allowed once" : approval.status === "denied" ? "Denied" : approval.status === "expired" ? "Expired" : "Cancelled";
@@ -1,5 +1,5 @@
1
1
  import { n as formatMatrixErrorReason, t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
2
- import { A as writeMatrixRecoveryKeyStateForPath, C as readLegacyMatrixRecoveryKeyFile, E as readMatrixRecoveryKeyStateForPath, v as migrateLegacyMatrixRecoveryKeyFilePathToStore } from "./storage-CzHxeF5E.js";
2
+ import { A as writeMatrixRecoveryKeyStateForPath, E as readMatrixRecoveryKeyStateForPath, S as readLegacyMatrixRecoveryKeyFile, _ as migrateLegacyMatrixRecoveryKeyFilePathToStore } from "./storage-BvAkgzvT.js";
3
3
  import { n as LogService } from "./logger-D0GCSDQq.js";
4
4
  import path from "node:path";
5
5
  import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js";
@@ -1,6 +1,6 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
2
  import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-B-5aQxwn.js";
3
- import { n as listMatrixDirectoryGroupsLive, r as listMatrixDirectoryPeersLive } from "./directory-live-DiC-0XBC.js";
3
+ import { n as listMatrixDirectoryGroupsLive, r as listMatrixDirectoryPeersLive } from "./directory-live-YRgYDx2w.js";
4
4
  import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
5
  //#region extensions/matrix/src/resolve-targets.ts
6
6
  var resolve_targets_exports = /* @__PURE__ */ __exportAll({ resolveMatrixTargets: () => resolveMatrixTargets });
@@ -1,4 +1,4 @@
1
- import { t as resolveMatrixTargets } from "./resolve-targets-DVoj-YxB.js";
1
+ import { t as resolveMatrixTargets } from "./resolve-targets-nNMcrV3W.js";
2
2
  //#region extensions/matrix/src/resolver.runtime.ts
3
3
  const matrixResolverRuntime = { resolveMatrixTargets };
4
4
  //#endregion
@@ -1,14 +1,15 @@
1
1
  import { r as isMatrixNotFoundError } from "./errors-C47hvAF8.js";
2
- //#region extensions/matrix/src/matrix/monitor/room-info.ts
3
- const MAX_TRACKED_ROOM_INFO = 1024;
4
- const MAX_TRACKED_MEMBER_DISPLAY_NAMES = 4096;
5
- function rememberBounded(map, key, value, maxEntries) {
2
+ //#region extensions/matrix/src/matrix/monitor/bounded-cache.ts
3
+ function setBoundedMap(map, key, value, maxEntries) {
6
4
  map.set(key, value);
7
- if (map.size > maxEntries) {
8
- const oldest = map.keys().next().value;
9
- if (typeof oldest === "string") map.delete(oldest);
10
- }
5
+ if (map.size <= maxEntries) return;
6
+ const oldest = map.keys().next();
7
+ if (!oldest.done) map.delete(oldest.value);
11
8
  }
9
+ //#endregion
10
+ //#region extensions/matrix/src/matrix/monitor/room-info.ts
11
+ const MAX_ROOM_INFO = 1024;
12
+ const MAX_MEMBER_DISPLAY_NAMES = 4096;
12
13
  function createMatrixRoomInfoResolver(client) {
13
14
  const roomNameCache = /* @__PURE__ */ new Map();
14
15
  const roomAliasCache = /* @__PURE__ */ new Map();
@@ -28,7 +29,7 @@ function createMatrixRoomInfoResolver(client) {
28
29
  name,
29
30
  nameResolved
30
31
  };
31
- if (nameResolved) rememberBounded(roomNameCache, roomId, info, MAX_TRACKED_ROOM_INFO);
32
+ if (nameResolved) setBoundedMap(roomNameCache, roomId, info, MAX_ROOM_INFO);
32
33
  return info;
33
34
  };
34
35
  const getRoomAliases = async (roomId) => {
@@ -51,7 +52,7 @@ function createMatrixRoomInfoResolver(client) {
51
52
  altAliases,
52
53
  aliasesResolved
53
54
  };
54
- if (aliasesResolved) rememberBounded(roomAliasCache, roomId, info, MAX_TRACKED_ROOM_INFO);
55
+ if (aliasesResolved) setBoundedMap(roomAliasCache, roomId, info, MAX_ROOM_INFO);
55
56
  return info;
56
57
  };
57
58
  const getRoomInfo = async (roomId, opts = {}) => {
@@ -73,7 +74,7 @@ function createMatrixRoomInfoResolver(client) {
73
74
  if (memberDisplayNameCache.has(cacheKey)) return memberDisplayNameCache.get(cacheKey) ?? userId;
74
75
  const memberState = await client.getRoomStateEvent(roomId, "m.room.member", userId).catch(() => null);
75
76
  const displayName = memberState && typeof memberState.displayname === "string" ? memberState.displayname : userId;
76
- rememberBounded(memberDisplayNameCache, cacheKey, displayName, MAX_TRACKED_MEMBER_DISPLAY_NAMES);
77
+ setBoundedMap(memberDisplayNameCache, cacheKey, displayName, MAX_MEMBER_DISPLAY_NAMES);
77
78
  return displayName;
78
79
  };
79
80
  return {
@@ -83,4 +84,4 @@ function createMatrixRoomInfoResolver(client) {
83
84
  };
84
85
  }
85
86
  //#endregion
86
- export { createMatrixRoomInfoResolver as t };
87
+ export { setBoundedMap as n, createMatrixRoomInfoResolver as t };
@@ -1,20 +1,121 @@
1
1
  import { n as formatMatrixErrorReason, r as isMatrixNotFoundError, t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
2
- import { t as SqliteBackedMatrixSyncStore } from "./file-sync-store-CPkgnSXp.js";
2
+ import { t as SqliteBackedMatrixSyncStore } from "./file-sync-store-DiiFsayX.js";
3
3
  import { n as LogService, r as noop, t as ConsoleLogger } from "./logger-D0GCSDQq.js";
4
4
  import { t as MATRIX_IDB_PERSIST_INTERVAL_MS } from "./idb-persistence-lock-DAJ49nZX.js";
5
- import { c as createMatrixStartupAbortError, u as throwIfMatrixStartupAborted } from "./shared-DquM1oz6.js";
6
- import { a as matrixEventToRaw, n as createMatrixGuardedFetch, o as parseMxc, t as MatrixAuthedHttpClient } from "./http-client-BmrgOZTL.js";
5
+ import { c as createMatrixStartupAbortError, u as throwIfMatrixStartupAborted } from "./shared-CUH5otj8.js";
6
+ import { a as matrixEventToRaw, n as createMatrixGuardedFetch, o as parseMxc, t as MatrixAuthedHttpClient } from "./http-client-CycYxU9-.js";
7
7
  import { n as resolveMatrixRoomKeyBackupReadinessError } from "./backup-health-Dm_YMVFT.js";
8
- import { createMatrixJsSdkClientLogger } from "./logging-QH-48Gr6.js";
8
+ import { t as createMatrixJsSdkClientLogger } from "./logging-DV-p52N0.js";
9
9
  import { n as isMatrixReadySyncState, r as isMatrixTerminalSyncState } from "./sync-state-CWbp0QSY.js";
10
- import { n as isRepairableSecretStorageAccessError, t as MatrixRecoveryKeyStore } from "./recovery-key-store-CW6eePfp.js";
10
+ import { n as isRepairableSecretStorageAccessError, t as MatrixRecoveryKeyStore } from "./recovery-key-store-BNnHvXdk.js";
11
11
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
12
12
  import { normalizeNullableString, normalizeStringEntries, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
13
13
  import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
14
14
  import { ClientEvent, Filter, MatrixEventEvent, Preset, createClient } from "matrix-js-sdk/lib/matrix.js";
15
15
  import { EventEmitter } from "node:events";
16
16
  import { VerificationMethod } from "matrix-js-sdk/lib/types.js";
17
- //#region extensions/matrix/src/matrix/sdk.ts
17
+ //#region extensions/matrix/src/matrix/sdk/client-device-info.ts
18
+ async function resolveMatrixCrossSigningPublicationStatus(params) {
19
+ if (!params.userId) return {
20
+ userId: null,
21
+ masterKeyPublished: false,
22
+ selfSigningKeyPublished: false,
23
+ userSigningKeyPublished: false,
24
+ published: false
25
+ };
26
+ try {
27
+ const response = await params.query();
28
+ const masterKeyPublished = Boolean(response.master_keys?.[params.userId]);
29
+ const selfSigningKeyPublished = Boolean(response.self_signing_keys?.[params.userId]);
30
+ const userSigningKeyPublished = Boolean(response.user_signing_keys?.[params.userId]);
31
+ return {
32
+ userId: params.userId,
33
+ masterKeyPublished,
34
+ selfSigningKeyPublished,
35
+ userSigningKeyPublished,
36
+ published: masterKeyPublished && selfSigningKeyPublished && userSigningKeyPublished
37
+ };
38
+ } catch {
39
+ return {
40
+ userId: params.userId,
41
+ masterKeyPublished: false,
42
+ selfSigningKeyPublished: false,
43
+ userSigningKeyPublished: false,
44
+ published: false
45
+ };
46
+ }
47
+ }
48
+ async function listMatrixOwnDevices(client) {
49
+ const currentDeviceId = client.getDeviceId()?.trim() || null;
50
+ const devices = await client.getDevices();
51
+ return (Array.isArray(devices?.devices) ? devices.devices : []).map((device) => ({
52
+ deviceId: device.device_id,
53
+ displayName: device.display_name?.trim() || null,
54
+ lastSeenIp: device.last_seen_ip?.trim() || null,
55
+ lastSeenTs: typeof device.last_seen_ts === "number" && Number.isFinite(device.last_seen_ts) ? device.last_seen_ts : null,
56
+ current: currentDeviceId !== null && device.device_id === currentDeviceId
57
+ }));
58
+ }
59
+ //#endregion
60
+ //#region extensions/matrix/src/matrix/sdk/client-event-bridge.ts
61
+ function registerMatrixClientBridge(params) {
62
+ params.client.on(ClientEvent.Event, (event) => {
63
+ const roomId = event.getRoomId();
64
+ if (!roomId) return;
65
+ const raw = matrixEventToRaw(event, { contentMode: "original" });
66
+ const isEncryptedEvent = raw.type === "m.room.encrypted";
67
+ params.emitter.emit("room.event", roomId, raw);
68
+ if (isEncryptedEvent) params.emitter.emit("room.encrypted_event", roomId, raw);
69
+ else if (params.decryptBridge.shouldEmitUnencryptedMessage(roomId, raw.event_id)) params.emitter.emit("room.message", roomId, raw);
70
+ const stateKey = raw.state_key ?? "";
71
+ const selfUserId = params.getSelfUserId();
72
+ const membership = raw.type === "m.room.member" ? raw.content.membership : void 0;
73
+ if (stateKey && selfUserId && stateKey === selfUserId) {
74
+ if (membership === "invite") params.emitter.emit("room.invite", roomId, raw);
75
+ else if (membership === "join") params.emitter.emit("room.join", roomId, raw);
76
+ }
77
+ if (isEncryptedEvent) params.decryptBridge.attachEncryptedEvent(event, roomId);
78
+ });
79
+ params.client.on(ClientEvent.Room, params.emitMembershipForRoom);
80
+ params.client.on(ClientEvent.Sync, (state, prevState, data) => {
81
+ params.setCurrentSyncState(state);
82
+ const error = data && typeof data === "object" && "error" in data ? data.error : void 0;
83
+ params.emitter.emit("sync.state", state, prevState, error);
84
+ });
85
+ params.client.on(ClientEvent.SyncUnexpectedError, (error) => {
86
+ params.emitter.emit("sync.unexpected_error", error);
87
+ });
88
+ }
89
+ function emitMatrixMembershipForRoom(params) {
90
+ const roomId = params.room.roomId.trim();
91
+ if (!roomId || !params.selfUserId) return;
92
+ const membership = params.room.getMyMembership();
93
+ const raw = {
94
+ event_id: `$membership-${roomId}-${Date.now()}`,
95
+ type: "m.room.member",
96
+ sender: params.selfUserId,
97
+ state_key: params.selfUserId,
98
+ content: { membership },
99
+ origin_server_ts: Date.now(),
100
+ unsigned: { age: 0 }
101
+ };
102
+ if (membership === "invite") {
103
+ params.emitter.emit("room.invite", roomId, raw);
104
+ return;
105
+ }
106
+ if (membership === "join") params.emitter.emit("room.join", roomId, raw);
107
+ }
108
+ function refreshMatrixDmRoomIds(direct, dmRoomIds) {
109
+ dmRoomIds.clear();
110
+ if (!direct || typeof direct !== "object") return false;
111
+ for (const value of Object.values(direct)) {
112
+ if (!Array.isArray(value)) continue;
113
+ for (const roomId of value) if (typeof roomId === "string" && roomId.trim()) dmRoomIds.add(roomId);
114
+ }
115
+ return true;
116
+ }
117
+ //#endregion
118
+ //#region extensions/matrix/src/matrix/sdk/client-support.ts
18
119
  const MATRIX_STATUS_DIAGNOSTIC_TIMEOUT_MS = 1e4;
19
120
  const DEFAULT_MATRIX_LOCAL_TIMEOUT_MS = 6e4;
20
121
  function resolveMatrixLocalTimeoutMs(raw) {
@@ -93,19 +194,14 @@ function createMatrixExplicitBootstrapOptions(params) {
93
194
  strict: params?.strict !== false
94
195
  };
95
196
  }
197
+ //#endregion
198
+ //#region extensions/matrix/src/matrix/sdk/client-base.ts
96
199
  let loadedMatrixCryptoRuntime = null;
97
- const loadMatrixCryptoRuntime = createLazyRuntimeModule(() => import("./crypto-runtime-CAff-n15.js").then((runtime) => {
200
+ const loadMatrixCryptoRuntime = createLazyRuntimeModule(() => import("./crypto-runtime-D9_6J5tZ.js").then((runtime) => {
98
201
  loadedMatrixCryptoRuntime = runtime;
99
202
  return runtime;
100
203
  }));
101
- const normalizeOptionalString$1 = normalizeNullableString;
102
- function isUnsupportedAuthenticatedMediaEndpointError(err) {
103
- const statusCode = err?.statusCode;
104
- if (statusCode === 404 || statusCode === 405 || statusCode === 501) return true;
105
- const message = formatMatrixErrorReason(err);
106
- return message.includes("m_unrecognized") || message.includes("unrecognized request") || message.includes("method not allowed") || message.includes("not implemented");
107
- }
108
- var MatrixClient = class {
204
+ var MatrixClientBase = class {
109
205
  constructor(homeserver, accessToken, opts = {}) {
110
206
  this.emitter = new EventEmitter();
111
207
  this.bridgeRegistered = false;
@@ -134,7 +230,8 @@ var MatrixClient = class {
134
230
  this.initialSyncLimit = opts.initialSyncLimit;
135
231
  this.syncFilter = opts.syncFilter;
136
232
  this.encryptionEnabled = opts.encryption === true;
137
- this.password = opts.password;
233
+ const { password: loginPassword } = opts;
234
+ this.password = loginPassword;
138
235
  this.syncStore = opts.storageRootDir ? new SqliteBackedMatrixSyncStore(opts.storageRootDir) : void 0;
139
236
  this.idbSnapshotPath = opts.idbSnapshotPath;
140
237
  this.cryptoDatabasePrefix = opts.cryptoDatabasePrefix;
@@ -414,6 +511,16 @@ var MatrixClient = class {
414
511
  LogService.warn("MatrixClientLite", "Failed to initialize rust crypto:", err);
415
512
  }
416
513
  }
514
+ };
515
+ //#endregion
516
+ //#region extensions/matrix/src/matrix/sdk/client-core.ts
517
+ function isUnsupportedAuthenticatedMediaEndpointError(err) {
518
+ const statusCode = err?.statusCode;
519
+ if (statusCode === 404 || statusCode === 405 || statusCode === 501) return true;
520
+ const message = formatMatrixErrorReason(err);
521
+ return message.includes("m_unrecognized") || message.includes("unrecognized request") || message.includes("method not allowed") || message.includes("not implemented");
522
+ }
523
+ var MatrixClientCore = class extends MatrixClientBase {
417
524
  async getUserId() {
418
525
  const fromClient = this.client.getUserId();
419
526
  if (fromClient) {
@@ -588,6 +695,11 @@ var MatrixClient = class {
588
695
  timeoutMs: this.localTimeoutMs
589
696
  });
590
697
  }
698
+ };
699
+ //#endregion
700
+ //#region extensions/matrix/src/matrix/sdk/client-verification.ts
701
+ const normalizeOptionalString$1 = normalizeNullableString;
702
+ var MatrixClientVerification = class extends MatrixClientCore {
591
703
  async getRoomKeyBackupStatus() {
592
704
  if (!this.encryptionEnabled) return {
593
705
  serverVersion: null,
@@ -715,6 +827,83 @@ var MatrixClient = class {
715
827
  ownIdentity.free?.();
716
828
  }
717
829
  }
830
+ async resolveActiveRoomKeyBackupVersion(crypto) {
831
+ if (typeof crypto.getActiveSessionBackupVersion !== "function") return null;
832
+ const version = await crypto.getActiveSessionBackupVersion().catch(() => null);
833
+ return normalizeOptionalString$1(version);
834
+ }
835
+ async resolveCachedRoomKeyBackupDecryptionKey(crypto) {
836
+ const read = Reflect.get(crypto, "getSessionBackupPrivateKey");
837
+ if (typeof read !== "function") return null;
838
+ const key = await read.call(crypto).catch(() => null);
839
+ return key ? key.length > 0 : false;
840
+ }
841
+ async resolveRoomKeyBackupLocalState(crypto) {
842
+ const [activeVersion, decryptionKeyCached] = await Promise.all([this.resolveActiveRoomKeyBackupVersion(crypto), this.resolveCachedRoomKeyBackupDecryptionKey(crypto)]);
843
+ return {
844
+ activeVersion,
845
+ decryptionKeyCached
846
+ };
847
+ }
848
+ async shouldForceSecretStorageRecreationForBackupReset(crypto) {
849
+ if (await this.resolveCachedRoomKeyBackupDecryptionKey(crypto) !== false) return false;
850
+ const loadSessionBackupPrivateKeyFromSecretStorage = crypto.loadSessionBackupPrivateKeyFromSecretStorage;
851
+ if (typeof loadSessionBackupPrivateKeyFromSecretStorage !== "function") return false;
852
+ try {
853
+ await loadSessionBackupPrivateKeyFromSecretStorage.call(crypto);
854
+ return false;
855
+ } catch (err) {
856
+ return isRepairableSecretStorageAccessError(err);
857
+ }
858
+ }
859
+ async resolveRoomKeyBackupTrustState(crypto, fallbackVersion) {
860
+ let serverVersion = fallbackVersion;
861
+ let trusted = null;
862
+ let matchesDecryptionKey = null;
863
+ if (typeof crypto.getKeyBackupInfo === "function") {
864
+ const info = await crypto.getKeyBackupInfo().catch(() => null);
865
+ serverVersion = normalizeOptionalString$1(info?.version) ?? serverVersion;
866
+ if (info && typeof crypto.isKeyBackupTrusted === "function") {
867
+ const trustInfo = await crypto.isKeyBackupTrusted(info).catch(() => null);
868
+ trusted = typeof trustInfo?.trusted === "boolean" ? trustInfo.trusted : null;
869
+ matchesDecryptionKey = typeof trustInfo?.matchesDecryptionKey === "boolean" ? trustInfo.matchesDecryptionKey : null;
870
+ }
871
+ }
872
+ return {
873
+ serverVersion,
874
+ trusted,
875
+ matchesDecryptionKey
876
+ };
877
+ }
878
+ async resolveDefaultSecretStorageKeyId(crypto) {
879
+ const getSecretStorageStatus = crypto?.getSecretStorageStatus;
880
+ if (typeof getSecretStorageStatus !== "function") return;
881
+ return (await getSecretStorageStatus.call(crypto).catch(() => null))?.defaultKeyId;
882
+ }
883
+ async resolveRoomKeyBackupVersion() {
884
+ try {
885
+ const response = await this.doRequest("GET", "/_matrix/client/v3/room_keys/version");
886
+ return normalizeOptionalString$1(response.version);
887
+ } catch {
888
+ return null;
889
+ }
890
+ }
891
+ async enableTrustedRoomKeyBackupIfPossible(crypto) {
892
+ if (typeof crypto.checkKeyBackupAndEnable !== "function") return;
893
+ await crypto.checkKeyBackupAndEnable();
894
+ }
895
+ async ensureRoomKeyBackupEnabled(crypto) {
896
+ if (await this.resolveRoomKeyBackupVersion()) return;
897
+ LogService.info("MatrixClientLite", "No room key backup version found on server, creating one via secret storage bootstrap");
898
+ await this.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey(crypto, { setupNewKeyBackup: true });
899
+ const createdVersion = await this.resolveRoomKeyBackupVersion();
900
+ if (!createdVersion) throw new Error("Matrix room key backup is still missing after bootstrap");
901
+ LogService.info("MatrixClientLite", `Room key backup enabled (version ${createdVersion})`);
902
+ }
903
+ };
904
+ //#endregion
905
+ //#region extensions/matrix/src/matrix/sdk.ts
906
+ var MatrixClient = class extends MatrixClientVerification {
718
907
  async verifyWithRecoveryKey(rawRecoveryKey) {
719
908
  const fail = async (error, fields = {}) => {
720
909
  const status = await this.getOwnDeviceVerificationStatus();
@@ -959,34 +1148,10 @@ var MatrixClient = class {
959
1148
  }
960
1149
  async getOwnCrossSigningPublicationStatus() {
961
1150
  const userId = this.client.getUserId() ?? this.selfUserId ?? null;
962
- if (!userId) return {
963
- userId: null,
964
- masterKeyPublished: false,
965
- selfSigningKeyPublished: false,
966
- userSigningKeyPublished: false,
967
- published: false
968
- };
969
- try {
970
- const response = await this.doRequest("POST", "/_matrix/client/v3/keys/query", void 0, { device_keys: { [userId]: [] } });
971
- const masterKeyPublished = Boolean(response.master_keys?.[userId]);
972
- const selfSigningKeyPublished = Boolean(response.self_signing_keys?.[userId]);
973
- const userSigningKeyPublished = Boolean(response.user_signing_keys?.[userId]);
974
- return {
975
- userId,
976
- masterKeyPublished,
977
- selfSigningKeyPublished,
978
- userSigningKeyPublished,
979
- published: masterKeyPublished && selfSigningKeyPublished && userSigningKeyPublished
980
- };
981
- } catch {
982
- return {
983
- userId,
984
- masterKeyPublished: false,
985
- selfSigningKeyPublished: false,
986
- userSigningKeyPublished: false,
987
- published: false
988
- };
989
- }
1151
+ return await resolveMatrixCrossSigningPublicationStatus({
1152
+ userId,
1153
+ query: async () => await this.doRequest("POST", "/_matrix/client/v3/keys/query", void 0, { device_keys: userId ? { [userId]: [] } : {} })
1154
+ });
990
1155
  }
991
1156
  async bootstrapOwnDeviceVerification(params) {
992
1157
  const pendingVerifications = async () => this.crypto ? (await this.crypto.listVerifications()).length : 0;
@@ -1042,15 +1207,7 @@ var MatrixClient = class {
1042
1207
  };
1043
1208
  }
1044
1209
  async listOwnDevices() {
1045
- const currentDeviceId = this.client.getDeviceId()?.trim() || null;
1046
- const devices = await this.client.getDevices();
1047
- return (Array.isArray(devices?.devices) ? devices.devices : []).map((device) => ({
1048
- deviceId: device.device_id,
1049
- displayName: device.display_name?.trim() || null,
1050
- lastSeenIp: device.last_seen_ip?.trim() || null,
1051
- lastSeenTs: typeof device.last_seen_ts === "number" && Number.isFinite(device.last_seen_ts) ? device.last_seen_ts : null,
1052
- current: currentDeviceId !== null && device.device_id === currentDeviceId
1053
- }));
1210
+ return await listMatrixOwnDevices(this.client);
1054
1211
  }
1055
1212
  async deleteOwnDevices(deviceIds) {
1056
1213
  const uniqueDeviceIds = uniqueStrings(normalizeStringEntries(deviceIds));
@@ -1082,145 +1239,34 @@ var MatrixClient = class {
1082
1239
  remainingDevices: await this.listOwnDevices()
1083
1240
  };
1084
1241
  }
1085
- async resolveActiveRoomKeyBackupVersion(crypto) {
1086
- if (typeof crypto.getActiveSessionBackupVersion !== "function") return null;
1087
- const version = await crypto.getActiveSessionBackupVersion().catch(() => null);
1088
- return normalizeOptionalString$1(version);
1089
- }
1090
- async resolveCachedRoomKeyBackupDecryptionKey(crypto) {
1091
- const getSessionBackupPrivateKey = crypto.getSessionBackupPrivateKey;
1092
- if (typeof getSessionBackupPrivateKey !== "function") return null;
1093
- const key = await getSessionBackupPrivateKey.call(crypto).catch(() => null);
1094
- return key ? key.length > 0 : false;
1095
- }
1096
- async resolveRoomKeyBackupLocalState(crypto) {
1097
- const [activeVersion, decryptionKeyCached] = await Promise.all([this.resolveActiveRoomKeyBackupVersion(crypto), this.resolveCachedRoomKeyBackupDecryptionKey(crypto)]);
1098
- return {
1099
- activeVersion,
1100
- decryptionKeyCached
1101
- };
1102
- }
1103
- async shouldForceSecretStorageRecreationForBackupReset(crypto) {
1104
- if (await this.resolveCachedRoomKeyBackupDecryptionKey(crypto) !== false) return false;
1105
- const loadSessionBackupPrivateKeyFromSecretStorage = crypto.loadSessionBackupPrivateKeyFromSecretStorage;
1106
- if (typeof loadSessionBackupPrivateKeyFromSecretStorage !== "function") return false;
1107
- try {
1108
- await loadSessionBackupPrivateKeyFromSecretStorage.call(crypto);
1109
- return false;
1110
- } catch (err) {
1111
- return isRepairableSecretStorageAccessError(err);
1112
- }
1113
- }
1114
- async resolveRoomKeyBackupTrustState(crypto, fallbackVersion) {
1115
- let serverVersion = fallbackVersion;
1116
- let trusted = null;
1117
- let matchesDecryptionKey = null;
1118
- if (typeof crypto.getKeyBackupInfo === "function") {
1119
- const info = await crypto.getKeyBackupInfo().catch(() => null);
1120
- serverVersion = normalizeOptionalString$1(info?.version) ?? serverVersion;
1121
- if (info && typeof crypto.isKeyBackupTrusted === "function") {
1122
- const trustInfo = await crypto.isKeyBackupTrusted(info).catch(() => null);
1123
- trusted = typeof trustInfo?.trusted === "boolean" ? trustInfo.trusted : null;
1124
- matchesDecryptionKey = typeof trustInfo?.matchesDecryptionKey === "boolean" ? trustInfo.matchesDecryptionKey : null;
1125
- }
1126
- }
1127
- return {
1128
- serverVersion,
1129
- trusted,
1130
- matchesDecryptionKey
1131
- };
1132
- }
1133
- async resolveDefaultSecretStorageKeyId(crypto) {
1134
- const getSecretStorageStatus = crypto?.getSecretStorageStatus;
1135
- if (typeof getSecretStorageStatus !== "function") return;
1136
- return (await getSecretStorageStatus.call(crypto).catch(() => null))?.defaultKeyId;
1137
- }
1138
- async resolveRoomKeyBackupVersion() {
1139
- try {
1140
- const response = await this.doRequest("GET", "/_matrix/client/v3/room_keys/version");
1141
- return normalizeOptionalString$1(response.version);
1142
- } catch {
1143
- return null;
1144
- }
1145
- }
1146
- async enableTrustedRoomKeyBackupIfPossible(crypto) {
1147
- if (typeof crypto.checkKeyBackupAndEnable !== "function") return;
1148
- await crypto.checkKeyBackupAndEnable();
1149
- }
1150
- async ensureRoomKeyBackupEnabled(crypto) {
1151
- if (await this.resolveRoomKeyBackupVersion()) return;
1152
- LogService.info("MatrixClientLite", "No room key backup version found on server, creating one via secret storage bootstrap");
1153
- await this.recoveryKeyStore.bootstrapSecretStorageWithRecoveryKey(crypto, { setupNewKeyBackup: true });
1154
- const createdVersion = await this.resolveRoomKeyBackupVersion();
1155
- if (!createdVersion) throw new Error("Matrix room key backup is still missing after bootstrap");
1156
- LogService.info("MatrixClientLite", `Room key backup enabled (version ${createdVersion})`);
1157
- }
1158
1242
  registerBridge() {
1159
- if (this.bridgeRegistered || !this.decryptBridge) return;
1160
- this.bridgeRegistered = true;
1161
1243
  const decryptBridge = this.decryptBridge;
1162
- this.client.on(ClientEvent.Event, (event) => {
1163
- const roomId = event.getRoomId();
1164
- if (!roomId) return;
1165
- const raw = matrixEventToRaw(event, { contentMode: "original" });
1166
- const isEncryptedEvent = raw.type === "m.room.encrypted";
1167
- this.emitter.emit("room.event", roomId, raw);
1168
- if (isEncryptedEvent) this.emitter.emit("room.encrypted_event", roomId, raw);
1169
- else if (decryptBridge.shouldEmitUnencryptedMessage(roomId, raw.event_id)) this.emitter.emit("room.message", roomId, raw);
1170
- const stateKey = raw.state_key ?? "";
1171
- const selfUserId = this.client.getUserId() ?? this.selfUserId ?? "";
1172
- const membership = raw.type === "m.room.member" ? raw.content.membership : void 0;
1173
- if (stateKey && selfUserId && stateKey === selfUserId) {
1174
- if (membership === "invite") this.emitter.emit("room.invite", roomId, raw);
1175
- else if (membership === "join") this.emitter.emit("room.join", roomId, raw);
1244
+ if (this.bridgeRegistered || !decryptBridge) return;
1245
+ this.bridgeRegistered = true;
1246
+ registerMatrixClientBridge({
1247
+ client: this.client,
1248
+ decryptBridge,
1249
+ emitter: this.emitter,
1250
+ emitMembershipForRoom: (room) => this.emitMembershipForRoom(room),
1251
+ getSelfUserId: () => this.client.getUserId() ?? this.selfUserId ?? "",
1252
+ setCurrentSyncState: (state) => {
1253
+ this.currentSyncState = state;
1176
1254
  }
1177
- if (isEncryptedEvent) decryptBridge.attachEncryptedEvent(event, roomId);
1178
- });
1179
- this.client.on(ClientEvent.Room, (room) => {
1180
- this.emitMembershipForRoom(room);
1181
- });
1182
- this.client.on(ClientEvent.Sync, (state, prevState, data) => {
1183
- this.currentSyncState = state;
1184
- const error = data && typeof data === "object" && "error" in data ? data.error : void 0;
1185
- this.emitter.emit("sync.state", state, prevState, error);
1186
- });
1187
- this.client.on(ClientEvent.SyncUnexpectedError, (error) => {
1188
- this.emitter.emit("sync.unexpected_error", error);
1189
1255
  });
1190
1256
  }
1191
1257
  emitMembershipForRoom(room) {
1192
- const roomId = room.roomId.trim();
1193
- if (!roomId) return;
1194
- const membership = room.getMyMembership();
1195
- const selfUserId = this.client.getUserId() ?? this.selfUserId ?? "";
1196
- if (!selfUserId) return;
1197
- const raw = {
1198
- event_id: `$membership-${roomId}-${Date.now()}`,
1199
- type: "m.room.member",
1200
- sender: selfUserId,
1201
- state_key: selfUserId,
1202
- content: { membership },
1203
- origin_server_ts: Date.now(),
1204
- unsigned: { age: 0 }
1205
- };
1206
- if (membership === "invite") {
1207
- this.emitter.emit("room.invite", roomId, raw);
1208
- return;
1209
- }
1210
- if (membership === "join") this.emitter.emit("room.join", roomId, raw);
1258
+ emitMatrixMembershipForRoom({
1259
+ client: this.client,
1260
+ emitter: this.emitter,
1261
+ room,
1262
+ selfUserId: this.client.getUserId() ?? this.selfUserId ?? ""
1263
+ });
1211
1264
  }
1212
1265
  emitOutstandingInviteEvents() {
1213
1266
  for (const room of this.client.getRooms()) this.emitMembershipForRoom(room);
1214
1267
  }
1215
1268
  async refreshDmCache() {
1216
- const direct = await this.getAccountData("m.direct");
1217
- this.dmRoomIds.clear();
1218
- if (!direct || typeof direct !== "object") return false;
1219
- for (const value of Object.values(direct)) {
1220
- if (!Array.isArray(value)) continue;
1221
- for (const roomId of value) if (typeof roomId === "string" && roomId.trim()) this.dmRoomIds.add(roomId);
1222
- }
1223
- return true;
1269
+ return refreshMatrixDmRoomIds(await this.getAccountData("m.direct"), this.dmRoomIds);
1224
1270
  }
1225
1271
  };
1226
1272
  //#endregion