@openclaw/matrix 2026.3.13 → 2026.5.9-beta.1

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 (206) hide show
  1. package/dist/account-config-D2W-V1eQ.js +96 -0
  2. package/dist/account-selection-BWwIruri.js +158 -0
  3. package/dist/accounts-Bm90Rzvp.js +130 -0
  4. package/dist/active-client-uhlxdhEy.js +20 -0
  5. package/dist/allowlist-sTzpCn5d.js +68 -0
  6. package/dist/api.js +12 -0
  7. package/dist/approval-handler.runtime-DWTQfd4m.js +370 -0
  8. package/dist/approval-ids-DoC2z7tR.js +7 -0
  9. package/dist/approval-reaction-auth-DbcA1gGd.js +27 -0
  10. package/dist/approval-reactions-o2_tuH8D.js +162 -0
  11. package/dist/async-lock-uQfhfQIY.js +19 -0
  12. package/dist/auth-presence.js +26 -0
  13. package/dist/backup-health-Cabu_WQC.js +60 -0
  14. package/dist/channel-DJNir3Rb.js +1116 -0
  15. package/dist/channel-plugin-api.js +2 -0
  16. package/dist/channel.runtime-BQu0hTih.js +246 -0
  17. package/dist/cli-BmfTmg7x.js +1340 -0
  18. package/dist/cli-metadata-B-PCEzrA.js +22 -0
  19. package/dist/cli-metadata.js +2 -0
  20. package/dist/client-DkcXnm0X.js +25 -0
  21. package/dist/client-_hckQNGW.js +31 -0
  22. package/dist/client-bootstrap-Rb8oHvhH.js +114 -0
  23. package/dist/config--5-S2Akv.js +452 -0
  24. package/dist/config-paths-nsVaysCu.js +19 -0
  25. package/dist/config-schema-nPLpEgHl.js +200 -0
  26. package/dist/config-secret-input.runtime-DiKFehsE.js +2 -0
  27. package/dist/config-update-wZX-HLMn.js +143 -0
  28. package/dist/contract-api.js +9 -0
  29. package/dist/create-client-DCnqDaqd.js +64 -0
  30. package/dist/credentials-DV6fWXhC.js +56 -0
  31. package/dist/credentials-read-cmHgousK.js +112 -0
  32. package/dist/credentials-write.runtime-zniTq-Gr.js +17 -0
  33. package/dist/crypto-node.runtime-pihzdpY7.js +12 -0
  34. package/dist/crypto-runtime-ZI0zAtn3.js +1214 -0
  35. package/dist/deps-C6WqKY7m.js +235 -0
  36. package/dist/device-health-UVYpbA_W.js +16 -0
  37. package/dist/direct-management-DMMMgtTB.js +249 -0
  38. package/dist/direct-room-XkutHjES.js +76 -0
  39. package/dist/directory-live-DmOtMhyr.js +150 -0
  40. package/dist/doctor-C4__7c-U.js +153 -0
  41. package/dist/doctor-contract-D4-64QuJ.js +246 -0
  42. package/dist/doctor-contract-api.js +2 -0
  43. package/dist/draft-stream-BE2QevQQ.js +144 -0
  44. package/dist/encryption-guidance-BPi3A_m3.js +15 -0
  45. package/dist/env-auth-BJqGI8M6.js +63 -0
  46. package/dist/env-vars-C7uQCTKn.js +63 -0
  47. package/dist/errors-CTcpEDq-.js +17 -0
  48. package/dist/exec-approval-resolver-Bza9Dhlm.js +15 -0
  49. package/dist/exec-approvals-Crnh543m.js +196 -0
  50. package/dist/helper-api.js +4 -0
  51. package/dist/http-client-C7AeVJay.js +319 -0
  52. package/dist/index.js +46 -0
  53. package/dist/legacy-crypto-inspector-poDWldgy.js +41 -0
  54. package/dist/legacy-crypto-restore-Biw-w2ng.js +85 -0
  55. package/dist/logger-CnZRVrux.js +78 -0
  56. package/dist/logging-DZHSPP5N.js +99 -0
  57. package/dist/matrix-migration.runtime-WY6ffcrf.js +525 -0
  58. package/dist/media-text-DU6nWZuj.js +146 -0
  59. package/dist/messages-BpihMh82.js +140 -0
  60. package/dist/migration-snapshot-backup-DaCHTp8C.js +69 -0
  61. package/dist/migration-snapshot.runtime-CKHE3xF9.js +2 -0
  62. package/dist/monitor-C_81r_Ck.js +4125 -0
  63. package/dist/plugin-entry.handlers.runtime.js +51 -0
  64. package/dist/probe.runtime-BvAzYAIe.js +3 -0
  65. package/dist/profile-BlHu0wDX.js +111 -0
  66. package/dist/profile-update-DjeBNgIV.js +69 -0
  67. package/dist/reaction-common-ejrL19w-.js +71 -0
  68. package/dist/reaction-events-CiARZfjk.js +121 -0
  69. package/dist/record-shared-CHWJCTWf.js +2 -0
  70. package/dist/recovery-key-store-BTJ6jz5v.js +294 -0
  71. package/dist/resolve-targets-YtJnw1Tb.js +140 -0
  72. package/dist/resolver.runtime-D9piiGEl.js +5 -0
  73. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  74. package/dist/route-D6rg-iXN.js +161 -0
  75. package/dist/runtime-C6X4h_SJ.js +6 -0
  76. package/dist/runtime-Dog86njy.js +8 -0
  77. package/dist/runtime-api-BXWBFIqm.js +25 -0
  78. package/dist/runtime-api.js +25 -0
  79. package/dist/runtime-heavy-api.js +3 -0
  80. package/dist/runtime-setter-api.js +2 -0
  81. package/dist/sdk-B2vZA27-.js +1416 -0
  82. package/dist/secret-contract-DcrJWCQI.js +120 -0
  83. package/dist/secret-contract-api.js +2 -0
  84. package/dist/send-Bo0DU1ca.js +1200 -0
  85. package/dist/session-store-metadata-DI5SCofx.js +77 -0
  86. package/dist/setup-bootstrap-ImenBsMt.js +62 -0
  87. package/dist/setup-core-CfZy05oW.js +116 -0
  88. package/dist/setup-dm-policy-2-r1FrQh.js +194 -0
  89. package/dist/setup-entry.js +19 -0
  90. package/dist/setup-plugin-api.js +44 -0
  91. package/dist/setup-surface-CqT_o61M.js +540 -0
  92. package/dist/shared-CpMoYKm1.js +195 -0
  93. package/dist/startup-abort-56edvmbM.js +32 -0
  94. package/dist/startup-verification-Demyp0bP.js +132 -0
  95. package/dist/storage-paths-BJLdnCjV.js +52 -0
  96. package/dist/storage-tC3ujLiW.js +281 -0
  97. package/dist/subagent-hooks-DQbyqq9V.js +149 -0
  98. package/dist/subagent-hooks-api.js +23 -0
  99. package/dist/sync-state-C_beeevA.js +12 -0
  100. package/dist/target-ids-80nQ2gql.js +77 -0
  101. package/dist/test-api.js +4 -0
  102. package/dist/thread-binding-api-Cq_E-E1K.js +17 -0
  103. package/dist/thread-binding-api.js +2 -0
  104. package/dist/thread-bindings-B9mesxXk.js +352 -0
  105. package/dist/thread-bindings-runtime.js +2 -0
  106. package/dist/thread-bindings-shared-DK-d-oYX.js +97 -0
  107. package/dist/timeout-abort-signal-CtaIaP1v.js +2 -0
  108. package/dist/tool-actions.runtime-BIH49vRr.js +532 -0
  109. package/dist/url-validation-DiK9j7jz.js +36 -0
  110. package/dist/verification-CZ2rDeHL.js +345 -0
  111. package/openclaw.plugin.json +788 -1
  112. package/package.json +82 -16
  113. package/CHANGELOG.md +0 -104
  114. package/index.ts +0 -22
  115. package/src/actions.ts +0 -195
  116. package/src/channel.directory.test.ts +0 -135
  117. package/src/channel.ts +0 -461
  118. package/src/config-schema.test.ts +0 -26
  119. package/src/config-schema.ts +0 -62
  120. package/src/directory-live.test.ts +0 -85
  121. package/src/directory-live.ts +0 -209
  122. package/src/group-mentions.ts +0 -52
  123. package/src/matrix/accounts.test.ts +0 -131
  124. package/src/matrix/accounts.ts +0 -114
  125. package/src/matrix/actions/client.ts +0 -47
  126. package/src/matrix/actions/limits.test.ts +0 -15
  127. package/src/matrix/actions/limits.ts +0 -6
  128. package/src/matrix/actions/messages.ts +0 -126
  129. package/src/matrix/actions/pins.test.ts +0 -74
  130. package/src/matrix/actions/pins.ts +0 -84
  131. package/src/matrix/actions/reactions.test.ts +0 -109
  132. package/src/matrix/actions/reactions.ts +0 -102
  133. package/src/matrix/actions/room.ts +0 -85
  134. package/src/matrix/actions/summary.ts +0 -75
  135. package/src/matrix/actions/types.ts +0 -85
  136. package/src/matrix/actions.ts +0 -15
  137. package/src/matrix/active-client.ts +0 -32
  138. package/src/matrix/client/config.ts +0 -245
  139. package/src/matrix/client/create-client.ts +0 -125
  140. package/src/matrix/client/logging.ts +0 -46
  141. package/src/matrix/client/runtime.ts +0 -4
  142. package/src/matrix/client/shared.test.ts +0 -85
  143. package/src/matrix/client/shared.ts +0 -210
  144. package/src/matrix/client/startup.test.ts +0 -49
  145. package/src/matrix/client/startup.ts +0 -29
  146. package/src/matrix/client/storage.ts +0 -131
  147. package/src/matrix/client/types.ts +0 -34
  148. package/src/matrix/client-bootstrap.ts +0 -47
  149. package/src/matrix/client.test.ts +0 -56
  150. package/src/matrix/client.ts +0 -14
  151. package/src/matrix/credentials.ts +0 -125
  152. package/src/matrix/deps.test.ts +0 -74
  153. package/src/matrix/deps.ts +0 -126
  154. package/src/matrix/format.test.ts +0 -33
  155. package/src/matrix/format.ts +0 -22
  156. package/src/matrix/index.ts +0 -11
  157. package/src/matrix/monitor/access-policy.ts +0 -126
  158. package/src/matrix/monitor/allowlist.test.ts +0 -45
  159. package/src/matrix/monitor/allowlist.ts +0 -94
  160. package/src/matrix/monitor/auto-join.ts +0 -72
  161. package/src/matrix/monitor/direct.test.ts +0 -396
  162. package/src/matrix/monitor/direct.ts +0 -152
  163. package/src/matrix/monitor/events.test.ts +0 -186
  164. package/src/matrix/monitor/events.ts +0 -168
  165. package/src/matrix/monitor/handler.body-for-agent.test.ts +0 -196
  166. package/src/matrix/monitor/handler.ts +0 -768
  167. package/src/matrix/monitor/inbound-body.test.ts +0 -73
  168. package/src/matrix/monitor/inbound-body.ts +0 -28
  169. package/src/matrix/monitor/index.test.ts +0 -18
  170. package/src/matrix/monitor/index.ts +0 -414
  171. package/src/matrix/monitor/location.ts +0 -100
  172. package/src/matrix/monitor/media.test.ts +0 -86
  173. package/src/matrix/monitor/media.ts +0 -118
  174. package/src/matrix/monitor/mentions.test.ts +0 -154
  175. package/src/matrix/monitor/mentions.ts +0 -62
  176. package/src/matrix/monitor/replies.test.ts +0 -184
  177. package/src/matrix/monitor/replies.ts +0 -124
  178. package/src/matrix/monitor/room-info.ts +0 -55
  179. package/src/matrix/monitor/rooms.test.ts +0 -124
  180. package/src/matrix/monitor/rooms.ts +0 -47
  181. package/src/matrix/monitor/threads.ts +0 -68
  182. package/src/matrix/monitor/types.ts +0 -39
  183. package/src/matrix/poll-types.test.ts +0 -21
  184. package/src/matrix/poll-types.ts +0 -167
  185. package/src/matrix/probe.ts +0 -69
  186. package/src/matrix/sdk-runtime.ts +0 -18
  187. package/src/matrix/send/client.ts +0 -99
  188. package/src/matrix/send/formatting.ts +0 -93
  189. package/src/matrix/send/media.ts +0 -230
  190. package/src/matrix/send/targets.test.ts +0 -98
  191. package/src/matrix/send/targets.ts +0 -150
  192. package/src/matrix/send/types.ts +0 -110
  193. package/src/matrix/send-queue.test.ts +0 -145
  194. package/src/matrix/send-queue.ts +0 -28
  195. package/src/matrix/send.test.ts +0 -319
  196. package/src/matrix/send.ts +0 -267
  197. package/src/onboarding.ts +0 -462
  198. package/src/outbound.test.ts +0 -159
  199. package/src/outbound.ts +0 -58
  200. package/src/resolve-targets.test.ts +0 -68
  201. package/src/resolve-targets.ts +0 -125
  202. package/src/runtime.ts +0 -6
  203. package/src/secret-input.ts +0 -13
  204. package/src/test-mocks.ts +0 -53
  205. package/src/tool-actions.ts +0 -164
  206. package/src/types.ts +0 -118
@@ -0,0 +1,294 @@
1
+ import { n as formatMatrixErrorReason, t as formatMatrixErrorMessage } from "./errors-CTcpEDq-.js";
2
+ import { n as LogService } from "./logger-CnZRVrux.js";
3
+ import { loadJsonFile, saveJsonFile } from "openclaw/plugin-sdk/json-store";
4
+ import { decodeRecoveryKey } from "matrix-js-sdk/lib/crypto-api/recovery-key.js";
5
+ //#region extensions/matrix/src/matrix/sdk/idb-persistence-lock.ts
6
+ const MATRIX_IDB_PERSIST_INTERVAL_MS = 6e4;
7
+ const IDB_SNAPSHOT_LOCK_STALE_MS = 5 * 6e4;
8
+ const IDB_SNAPSHOT_LOCK_RETRY_BASE = {
9
+ factor: 2,
10
+ minTimeout: 50,
11
+ maxTimeout: 5e3,
12
+ randomize: true
13
+ };
14
+ function computeRetryDelayMs(retries, attempt) {
15
+ return Math.min(retries.maxTimeout, Math.max(retries.minTimeout, retries.minTimeout * retries.factor ** attempt));
16
+ }
17
+ function computeMinimumRetryWindowMs(retries) {
18
+ let total = 0;
19
+ const attempts = Math.max(1, retries.retries + 1);
20
+ for (let attempt = 0; attempt < attempts - 1; attempt += 1) total += computeRetryDelayMs(retries, attempt);
21
+ return total;
22
+ }
23
+ function resolveRetriesForMinimumWindowMs(retries, minimumWindowMs) {
24
+ const resolved = {
25
+ ...retries,
26
+ retries: 0
27
+ };
28
+ while (computeMinimumRetryWindowMs(resolved) < minimumWindowMs) resolved.retries += 1;
29
+ return resolved;
30
+ }
31
+ const MATRIX_IDB_SNAPSHOT_LOCK_OPTIONS = {
32
+ retries: resolveRetriesForMinimumWindowMs(IDB_SNAPSHOT_LOCK_RETRY_BASE, MATRIX_IDB_PERSIST_INTERVAL_MS),
33
+ stale: IDB_SNAPSHOT_LOCK_STALE_MS
34
+ };
35
+ //#endregion
36
+ //#region extensions/matrix/src/matrix/sdk/recovery-key-store.ts
37
+ function isRepairableSecretStorageAccessError(err) {
38
+ const message = formatMatrixErrorReason(err);
39
+ if (!message) return false;
40
+ if (message.includes("getsecretstoragekey callback returned falsey")) return true;
41
+ if (message.includes("decrypting secret") && message.includes("bad mac")) return true;
42
+ return false;
43
+ }
44
+ var MatrixRecoveryKeyStore = class {
45
+ constructor(recoveryKeyPath) {
46
+ this.recoveryKeyPath = recoveryKeyPath;
47
+ this.secretStorageKeyCache = /* @__PURE__ */ new Map();
48
+ this.stagedRecoveryKey = null;
49
+ this.stagedRecoveryKeyUsed = false;
50
+ this.stagedCacheKeyIds = /* @__PURE__ */ new Set();
51
+ }
52
+ buildCryptoCallbacks() {
53
+ return {
54
+ getSecretStorageKey: async ({ keys }) => {
55
+ const requestedKeyIds = Object.keys(keys ?? {});
56
+ if (requestedKeyIds.length === 0) return null;
57
+ const staged = this.resolveStagedSecretStorageKey(requestedKeyIds);
58
+ if (staged) return staged;
59
+ for (const keyId of requestedKeyIds) {
60
+ const cached = this.secretStorageKeyCache.get(keyId);
61
+ if (cached) return [keyId, new Uint8Array(cached.key)];
62
+ }
63
+ const stored = this.loadStoredRecoveryKey();
64
+ if (!stored?.privateKeyBase64) return null;
65
+ const privateKey = new Uint8Array(Buffer.from(stored.privateKeyBase64, "base64"));
66
+ if (privateKey.length === 0) return null;
67
+ if (stored.keyId && requestedKeyIds.includes(stored.keyId)) {
68
+ this.rememberSecretStorageKey(stored.keyId, privateKey, stored.keyInfo);
69
+ return [stored.keyId, privateKey];
70
+ }
71
+ const firstRequestedKeyId = requestedKeyIds[0];
72
+ if (!firstRequestedKeyId) return null;
73
+ this.rememberSecretStorageKey(firstRequestedKeyId, privateKey, stored.keyInfo);
74
+ return [firstRequestedKeyId, privateKey];
75
+ },
76
+ cacheSecretStorageKey: (keyId, keyInfo, key) => {
77
+ const privateKey = new Uint8Array(key);
78
+ const normalizedKeyInfo = {
79
+ passphrase: keyInfo?.passphrase,
80
+ name: typeof keyInfo?.name === "string" ? keyInfo.name : void 0
81
+ };
82
+ this.rememberSecretStorageKey(keyId, privateKey, normalizedKeyInfo);
83
+ const stored = this.loadStoredRecoveryKey();
84
+ this.saveRecoveryKeyToDisk({
85
+ keyId,
86
+ keyInfo: normalizedKeyInfo,
87
+ privateKey,
88
+ encodedPrivateKey: stored?.encodedPrivateKey
89
+ });
90
+ }
91
+ };
92
+ }
93
+ getRecoveryKeySummary() {
94
+ const stored = this.loadStoredRecoveryKey();
95
+ if (!stored) return null;
96
+ return {
97
+ encodedPrivateKey: stored.encodedPrivateKey,
98
+ keyId: stored.keyId,
99
+ createdAt: stored.createdAt
100
+ };
101
+ }
102
+ resolveEncodedRecoveryKeyInput(params) {
103
+ const encodedPrivateKey = params.encodedPrivateKey.trim();
104
+ if (!encodedPrivateKey) throw new Error("Matrix recovery key is required");
105
+ let privateKey;
106
+ try {
107
+ privateKey = decodeRecoveryKey(encodedPrivateKey);
108
+ } catch (err) {
109
+ throw new Error(`Invalid Matrix recovery key: ${formatMatrixErrorMessage(err)}`, { cause: err });
110
+ }
111
+ const keyId = typeof params.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : null;
112
+ return {
113
+ encodedPrivateKey,
114
+ privateKey,
115
+ keyId,
116
+ keyInfo: params.keyInfo ?? this.loadStoredRecoveryKey()?.keyInfo
117
+ };
118
+ }
119
+ storeEncodedRecoveryKey(params) {
120
+ const prepared = this.resolveEncodedRecoveryKeyInput(params);
121
+ this.saveRecoveryKeyToDisk({
122
+ keyId: prepared.keyId,
123
+ keyInfo: prepared.keyInfo,
124
+ privateKey: prepared.privateKey,
125
+ encodedPrivateKey: prepared.encodedPrivateKey
126
+ });
127
+ if (prepared.keyId) this.rememberSecretStorageKey(prepared.keyId, prepared.privateKey, prepared.keyInfo);
128
+ return this.getRecoveryKeySummary() ?? {};
129
+ }
130
+ stageEncodedRecoveryKey(params) {
131
+ const prepared = this.resolveEncodedRecoveryKeyInput(params);
132
+ this.discardStagedRecoveryKey();
133
+ this.stagedRecoveryKey = {
134
+ version: 1,
135
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
136
+ keyId: prepared.keyId,
137
+ encodedPrivateKey: prepared.encodedPrivateKey,
138
+ privateKeyBase64: Buffer.from(prepared.privateKey).toString("base64"),
139
+ keyInfo: prepared.keyInfo
140
+ };
141
+ }
142
+ hasStagedRecoveryKeyBeenUsed() {
143
+ return this.stagedRecoveryKeyUsed;
144
+ }
145
+ commitStagedRecoveryKey(params) {
146
+ if (!this.stagedRecoveryKey) return this.getRecoveryKeySummary();
147
+ const staged = this.stagedRecoveryKey;
148
+ const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
149
+ const keyId = typeof params?.keyId === "string" && params.keyId.trim() ? params.keyId.trim() : staged.keyId;
150
+ this.saveRecoveryKeyToDisk({
151
+ keyId,
152
+ keyInfo: params?.keyInfo ?? staged.keyInfo,
153
+ privateKey,
154
+ encodedPrivateKey: staged.encodedPrivateKey
155
+ });
156
+ this.clearStagedRecoveryKeyTracking();
157
+ return this.getRecoveryKeySummary();
158
+ }
159
+ discardStagedRecoveryKey() {
160
+ for (const keyId of this.stagedCacheKeyIds) this.secretStorageKeyCache.delete(keyId);
161
+ this.clearStagedRecoveryKeyTracking();
162
+ }
163
+ async bootstrapSecretStorageWithRecoveryKey(crypto, options = {}) {
164
+ let status = null;
165
+ const getSecretStorageStatus = crypto.getSecretStorageStatus;
166
+ if (typeof getSecretStorageStatus === "function") try {
167
+ status = await getSecretStorageStatus.call(crypto);
168
+ } catch (err) {
169
+ LogService.warn("MatrixClientLite", "Failed to read secret storage status:", err);
170
+ }
171
+ const hasDefaultSecretStorageKey = Boolean(status?.defaultKeyId);
172
+ const hasKnownInvalidSecrets = Object.values(status?.secretStorageKeyValidityMap ?? {}).some((valid) => !valid);
173
+ let generatedRecoveryKey = false;
174
+ const storedRecovery = this.loadStoredRecoveryKey();
175
+ const stagedRecovery = this.stagedRecoveryKey;
176
+ const sourceRecovery = options.forceNewRecoveryKey === true ? null : stagedRecovery ?? storedRecovery;
177
+ let recoveryKey = sourceRecovery ? {
178
+ keyInfo: sourceRecovery.keyInfo,
179
+ privateKey: new Uint8Array(Buffer.from(sourceRecovery.privateKeyBase64, "base64")),
180
+ encodedPrivateKey: sourceRecovery.encodedPrivateKey
181
+ } : null;
182
+ if (recoveryKey && status?.defaultKeyId) {
183
+ const defaultKeyId = status.defaultKeyId;
184
+ if (!stagedRecovery) {
185
+ this.rememberSecretStorageKey(defaultKeyId, recoveryKey.privateKey, recoveryKey.keyInfo);
186
+ if (storedRecovery && storedRecovery.keyId !== defaultKeyId) this.saveRecoveryKeyToDisk({
187
+ keyId: defaultKeyId,
188
+ keyInfo: recoveryKey.keyInfo,
189
+ privateKey: recoveryKey.privateKey,
190
+ encodedPrivateKey: recoveryKey.encodedPrivateKey
191
+ });
192
+ }
193
+ }
194
+ const ensureRecoveryKey = async () => {
195
+ if (recoveryKey) {
196
+ if (stagedRecovery) this.stagedRecoveryKeyUsed = true;
197
+ return recoveryKey;
198
+ }
199
+ if (typeof crypto.createRecoveryKeyFromPassphrase !== "function") throw new Error("Matrix crypto backend does not support recovery key generation (createRecoveryKeyFromPassphrase missing)");
200
+ recoveryKey = await crypto.createRecoveryKeyFromPassphrase();
201
+ this.saveRecoveryKeyToDisk(recoveryKey);
202
+ generatedRecoveryKey = true;
203
+ return recoveryKey;
204
+ };
205
+ const shouldRecreateSecretStorage = options.forceNewSecretStorage === true || !hasDefaultSecretStorageKey || !recoveryKey && status?.ready === false || hasKnownInvalidSecrets;
206
+ if (hasKnownInvalidSecrets) recoveryKey = null;
207
+ const secretStorageOptions = { setupNewKeyBackup: options.setupNewKeyBackup === true };
208
+ if (shouldRecreateSecretStorage) {
209
+ secretStorageOptions.setupNewSecretStorage = true;
210
+ secretStorageOptions.createSecretStorageKey = ensureRecoveryKey;
211
+ }
212
+ try {
213
+ await crypto.bootstrapSecretStorage(secretStorageOptions);
214
+ } catch (err) {
215
+ if (!(options.allowSecretStorageRecreateWithoutRecoveryKey === true && hasDefaultSecretStorageKey && isRepairableSecretStorageAccessError(err))) throw err;
216
+ recoveryKey = null;
217
+ LogService.warn("MatrixClientLite", "Secret storage exists on the server but local recovery material cannot unlock it; recreating secret storage during explicit bootstrap.");
218
+ await crypto.bootstrapSecretStorage({
219
+ setupNewSecretStorage: true,
220
+ setupNewKeyBackup: options.setupNewKeyBackup === true,
221
+ createSecretStorageKey: ensureRecoveryKey
222
+ });
223
+ }
224
+ if (generatedRecoveryKey && this.recoveryKeyPath) LogService.warn("MatrixClientLite", `Generated Matrix recovery key and saved it to ${this.recoveryKeyPath}. Keep this file secure.`);
225
+ }
226
+ clearStagedRecoveryKeyTracking() {
227
+ this.stagedRecoveryKey = null;
228
+ this.stagedRecoveryKeyUsed = false;
229
+ this.stagedCacheKeyIds.clear();
230
+ }
231
+ resolveStagedSecretStorageKey(requestedKeyIds) {
232
+ const staged = this.stagedRecoveryKey;
233
+ if (!staged?.privateKeyBase64) return null;
234
+ const privateKey = new Uint8Array(Buffer.from(staged.privateKeyBase64, "base64"));
235
+ if (privateKey.length === 0) return null;
236
+ const keyId = staged.keyId && requestedKeyIds.includes(staged.keyId) ? staged.keyId : requestedKeyIds[0];
237
+ if (!keyId) return null;
238
+ this.rememberStagedSecretStorageKey(keyId, privateKey, staged.keyInfo);
239
+ this.stagedCacheKeyIds.add(keyId);
240
+ return [keyId, privateKey];
241
+ }
242
+ rememberStagedSecretStorageKey(keyId, key, keyInfo) {
243
+ this.stagedRecoveryKeyUsed = true;
244
+ this.rememberSecretStorageKey(keyId, key, keyInfo);
245
+ }
246
+ rememberSecretStorageKey(keyId, key, keyInfo) {
247
+ if (!keyId.trim()) return;
248
+ this.secretStorageKeyCache.set(keyId, {
249
+ key: new Uint8Array(key),
250
+ keyInfo
251
+ });
252
+ }
253
+ loadStoredRecoveryKey() {
254
+ if (!this.recoveryKeyPath) return null;
255
+ try {
256
+ const parsed = loadJsonFile(this.recoveryKeyPath);
257
+ if (parsed?.version !== 1 || typeof parsed.createdAt !== "string" || typeof parsed.privateKeyBase64 !== "string" || !parsed.privateKeyBase64.trim()) return null;
258
+ return {
259
+ version: 1,
260
+ createdAt: parsed.createdAt,
261
+ keyId: typeof parsed.keyId === "string" ? parsed.keyId : null,
262
+ encodedPrivateKey: typeof parsed.encodedPrivateKey === "string" ? parsed.encodedPrivateKey : void 0,
263
+ privateKeyBase64: parsed.privateKeyBase64,
264
+ keyInfo: parsed.keyInfo && typeof parsed.keyInfo === "object" ? {
265
+ passphrase: parsed.keyInfo.passphrase,
266
+ name: typeof parsed.keyInfo.name === "string" ? parsed.keyInfo.name : void 0
267
+ } : void 0
268
+ };
269
+ } catch {
270
+ return null;
271
+ }
272
+ }
273
+ saveRecoveryKeyToDisk(params) {
274
+ if (!this.recoveryKeyPath) return;
275
+ try {
276
+ const payload = {
277
+ version: 1,
278
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
279
+ keyId: typeof params.keyId === "string" ? params.keyId : null,
280
+ encodedPrivateKey: params.encodedPrivateKey,
281
+ privateKeyBase64: Buffer.from(params.privateKey).toString("base64"),
282
+ keyInfo: params.keyInfo ? {
283
+ passphrase: params.keyInfo.passphrase,
284
+ name: params.keyInfo.name
285
+ } : void 0
286
+ };
287
+ saveJsonFile(this.recoveryKeyPath, payload);
288
+ } catch (err) {
289
+ LogService.warn("MatrixClientLite", "Failed to persist recovery key:", err);
290
+ }
291
+ }
292
+ };
293
+ //#endregion
294
+ export { MATRIX_IDB_SNAPSHOT_LOCK_OPTIONS as i, isRepairableSecretStorageAccessError as n, MATRIX_IDB_PERSIST_INTERVAL_MS as r, MatrixRecoveryKeyStore as t };
@@ -0,0 +1,140 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-80nQ2gql.js";
3
+ import { n as listMatrixDirectoryGroupsLive, r as listMatrixDirectoryPeersLive } from "./directory-live-DmOtMhyr.js";
4
+ import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
+ //#region extensions/matrix/src/resolve-targets.ts
6
+ var resolve_targets_exports = /* @__PURE__ */ __exportAll({ resolveMatrixTargets: () => resolveMatrixTargets });
7
+ function normalizeLookupQuery(query) {
8
+ return normalizeOptionalLowercaseString(query) ?? "";
9
+ }
10
+ function findExactDirectoryMatches(matches, query) {
11
+ const normalized = normalizeLookupQuery(query);
12
+ if (!normalized) return [];
13
+ return matches.filter((match) => {
14
+ const id = normalizeOptionalLowercaseString(match.id);
15
+ const name = normalizeOptionalLowercaseString(match.name);
16
+ const handle = normalizeOptionalLowercaseString(match.handle);
17
+ return normalized === id || normalized === name || normalized === handle;
18
+ });
19
+ }
20
+ function pickBestGroupMatch(matches, query) {
21
+ if (matches.length === 0) return {};
22
+ const exact = findExactDirectoryMatches(matches, query);
23
+ if (exact.length > 1) return {
24
+ best: exact[0],
25
+ note: "multiple exact matches; chose first"
26
+ };
27
+ if (exact.length === 1) return { best: exact[0] };
28
+ return {
29
+ best: matches[0],
30
+ note: matches.length > 1 ? "multiple matches; chose first" : void 0
31
+ };
32
+ }
33
+ function pickBestUserMatch(matches, query) {
34
+ if (matches.length === 0) return;
35
+ const exact = findExactDirectoryMatches(matches, query);
36
+ if (exact.length === 1) return exact[0];
37
+ }
38
+ function describeUserMatchFailure(matches, query) {
39
+ if (matches.length === 0) return "no matches";
40
+ const normalized = normalizeLookupQuery(query);
41
+ if (!normalized) return "empty input";
42
+ const exact = findExactDirectoryMatches(matches, normalized);
43
+ if (exact.length === 0) return "no exact match; use full Matrix ID";
44
+ if (exact.length > 1) return "multiple exact matches; use full Matrix ID";
45
+ return "no exact match; use full Matrix ID";
46
+ }
47
+ async function readCachedMatches(cache, query, lookup) {
48
+ const key = normalizeLookupQuery(query);
49
+ if (!key) return [];
50
+ const cached = cache.get(key);
51
+ if (cached) return cached;
52
+ const matches = await lookup(query.trim());
53
+ cache.set(key, matches);
54
+ return matches;
55
+ }
56
+ async function resolveMatrixTargets(params) {
57
+ const results = [];
58
+ const userLookupCache = /* @__PURE__ */ new Map();
59
+ const groupLookupCache = /* @__PURE__ */ new Map();
60
+ for (const input of params.inputs) {
61
+ const trimmed = input.trim();
62
+ if (!trimmed) {
63
+ results.push({
64
+ input,
65
+ resolved: false,
66
+ note: "empty input"
67
+ });
68
+ continue;
69
+ }
70
+ if (params.kind === "user") {
71
+ const normalizedTarget = normalizeMatrixMessagingTarget(trimmed);
72
+ if (normalizedTarget && isMatrixQualifiedUserId(normalizedTarget)) {
73
+ results.push({
74
+ input,
75
+ resolved: true,
76
+ id: normalizedTarget
77
+ });
78
+ continue;
79
+ }
80
+ try {
81
+ const matches = await readCachedMatches(userLookupCache, trimmed, (query) => listMatrixDirectoryPeersLive({
82
+ cfg: params.cfg,
83
+ accountId: params.accountId,
84
+ query,
85
+ limit: 5
86
+ }));
87
+ const best = pickBestUserMatch(matches, trimmed);
88
+ results.push({
89
+ input,
90
+ resolved: Boolean(best?.id),
91
+ id: best?.id,
92
+ name: best?.name,
93
+ note: best ? void 0 : describeUserMatchFailure(matches, trimmed)
94
+ });
95
+ } catch (err) {
96
+ params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
97
+ results.push({
98
+ input,
99
+ resolved: false,
100
+ note: "lookup failed"
101
+ });
102
+ }
103
+ continue;
104
+ }
105
+ const normalizedTarget = normalizeMatrixMessagingTarget(trimmed);
106
+ if (normalizedTarget?.startsWith("!")) {
107
+ results.push({
108
+ input,
109
+ resolved: true,
110
+ id: normalizedTarget
111
+ });
112
+ continue;
113
+ }
114
+ try {
115
+ const { best, note } = pickBestGroupMatch(await readCachedMatches(groupLookupCache, trimmed, (query) => listMatrixDirectoryGroupsLive({
116
+ cfg: params.cfg,
117
+ accountId: params.accountId,
118
+ query,
119
+ limit: 5
120
+ })), trimmed);
121
+ results.push({
122
+ input,
123
+ resolved: Boolean(best?.id),
124
+ id: best?.id,
125
+ name: best?.name,
126
+ note
127
+ });
128
+ } catch (err) {
129
+ params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
130
+ results.push({
131
+ input,
132
+ resolved: false,
133
+ note: "lookup failed"
134
+ });
135
+ }
136
+ }
137
+ return results;
138
+ }
139
+ //#endregion
140
+ export { resolve_targets_exports as n, resolveMatrixTargets as t };
@@ -0,0 +1,5 @@
1
+ import { t as resolveMatrixTargets } from "./resolve-targets-YtJnw1Tb.js";
2
+ //#region extensions/matrix/src/resolver.runtime.ts
3
+ const matrixResolverRuntime = { resolveMatrixTargets };
4
+ //#endregion
5
+ export { matrixResolverRuntime };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __defProp = Object.defineProperty;
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
12
+ };
13
+ //#endregion
14
+ export { __exportAll as t };
@@ -0,0 +1,161 @@
1
+ import { n as MATRIX_REACTION_EVENT_TYPE } from "./reaction-common-ejrL19w-.js";
2
+ import { buildAgentSessionKey, deriveLastRoutePolicy, resolveAgentIdFromSessionKey, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
3
+ import { resolveConfiguredAcpBindingRecord } from "openclaw/plugin-sdk/acp-binding-resolve-runtime";
4
+ import { getSessionBindingService } from "openclaw/plugin-sdk/session-binding-runtime";
5
+ //#region extensions/matrix/src/matrix/monitor/types.ts
6
+ const EventType = {
7
+ RoomMessage: "m.room.message",
8
+ RoomMessageEncrypted: "m.room.encrypted",
9
+ RoomMember: "m.room.member",
10
+ Location: "m.location",
11
+ Reaction: MATRIX_REACTION_EVENT_TYPE
12
+ };
13
+ const RelationType = {
14
+ Replace: "m.replace",
15
+ Thread: "m.thread"
16
+ };
17
+ //#endregion
18
+ //#region extensions/matrix/src/matrix/monitor/threads.ts
19
+ function resolveMatrixThreadSessionKeys(params) {
20
+ return resolveThreadSessionKeys({
21
+ ...params,
22
+ normalizeThreadId: (threadId) => threadId
23
+ });
24
+ }
25
+ function resolveMatrixRelatedReplyToEventId(relates) {
26
+ if (!relates || typeof relates !== "object") return;
27
+ if ("m.in_reply_to" in relates && typeof relates["m.in_reply_to"] === "object" && relates["m.in_reply_to"] && "event_id" in relates["m.in_reply_to"] && typeof relates["m.in_reply_to"].event_id === "string") return relates["m.in_reply_to"].event_id;
28
+ }
29
+ function resolveMatrixThreadRouting(params) {
30
+ const effectiveThreadReplies = params.isDirectMessage && params.dmThreadReplies !== void 0 ? params.dmThreadReplies : params.threadReplies;
31
+ const messageId = params.messageId.trim();
32
+ const threadRootId = params.threadRootId?.trim();
33
+ const inboundThreadId = threadRootId && threadRootId !== messageId ? threadRootId : void 0;
34
+ return { threadId: effectiveThreadReplies === "off" ? void 0 : effectiveThreadReplies === "inbound" ? inboundThreadId : inboundThreadId ?? (messageId || void 0) };
35
+ }
36
+ function resolveMatrixThreadRootId(params) {
37
+ const relates = params.content["m.relates_to"];
38
+ if (!relates || typeof relates !== "object") return;
39
+ if ("rel_type" in relates && relates.rel_type === RelationType.Thread) {
40
+ if ("event_id" in relates && typeof relates.event_id === "string") return relates.event_id;
41
+ return resolveMatrixRelatedReplyToEventId(relates);
42
+ }
43
+ }
44
+ function resolveMatrixReplyToEventId(content) {
45
+ return resolveMatrixRelatedReplyToEventId(content["m.relates_to"]);
46
+ }
47
+ //#endregion
48
+ //#region extensions/matrix/src/matrix/monitor/route.ts
49
+ function resolveMatrixDmSessionKey(params) {
50
+ if (params.dmSessionScope !== "per-room") return params.fallbackSessionKey;
51
+ return buildAgentSessionKey({
52
+ agentId: params.agentId,
53
+ channel: "matrix",
54
+ accountId: params.accountId,
55
+ peer: {
56
+ kind: "channel",
57
+ id: params.roomId
58
+ }
59
+ });
60
+ }
61
+ function shouldApplyMatrixPerRoomDmSessionScope(params) {
62
+ return params.isDirectMessage && !params.configuredSessionKey;
63
+ }
64
+ function resolveMatrixInboundRoute(params) {
65
+ const baseRoute = params.resolveAgentRoute({
66
+ cfg: params.cfg,
67
+ channel: "matrix",
68
+ accountId: params.accountId,
69
+ peer: {
70
+ kind: params.isDirectMessage ? "direct" : "channel",
71
+ id: params.isDirectMessage ? params.senderId : params.roomId
72
+ },
73
+ parentPeer: params.isDirectMessage ? {
74
+ kind: "channel",
75
+ id: params.roomId
76
+ } : void 0
77
+ });
78
+ const bindingConversationId = params.threadId ?? params.roomId;
79
+ const bindingParentConversationId = params.threadId ? params.roomId : void 0;
80
+ const runtimeBinding = getSessionBindingService().resolveByConversation({
81
+ channel: "matrix",
82
+ accountId: params.accountId,
83
+ conversationId: bindingConversationId,
84
+ parentConversationId: bindingParentConversationId
85
+ });
86
+ const boundSessionKey = runtimeBinding?.targetSessionKey?.trim();
87
+ if (runtimeBinding && boundSessionKey) return {
88
+ route: {
89
+ ...baseRoute,
90
+ sessionKey: boundSessionKey,
91
+ agentId: resolveAgentIdFromSessionKey(boundSessionKey) || baseRoute.agentId,
92
+ lastRoutePolicy: deriveLastRoutePolicy({
93
+ sessionKey: boundSessionKey,
94
+ mainSessionKey: baseRoute.mainSessionKey
95
+ }),
96
+ matchedBy: "binding.channel"
97
+ },
98
+ configuredBinding: null,
99
+ runtimeBindingId: runtimeBinding.bindingId
100
+ };
101
+ const configuredBinding = runtimeBinding == null ? resolveConfiguredAcpBindingRecord({
102
+ cfg: params.cfg,
103
+ channel: "matrix",
104
+ accountId: params.accountId,
105
+ conversationId: bindingConversationId,
106
+ parentConversationId: bindingParentConversationId
107
+ }) : null;
108
+ const configuredSessionKey = configuredBinding?.record.targetSessionKey?.trim();
109
+ const effectiveRoute = configuredBinding && configuredSessionKey ? {
110
+ ...baseRoute,
111
+ sessionKey: configuredSessionKey,
112
+ agentId: resolveAgentIdFromSessionKey(configuredSessionKey) || configuredBinding.spec.agentId || baseRoute.agentId,
113
+ lastRoutePolicy: deriveLastRoutePolicy({
114
+ sessionKey: configuredSessionKey,
115
+ mainSessionKey: baseRoute.mainSessionKey
116
+ }),
117
+ matchedBy: "binding.channel"
118
+ } : baseRoute;
119
+ const dmSessionKey = shouldApplyMatrixPerRoomDmSessionScope({
120
+ isDirectMessage: params.isDirectMessage,
121
+ configuredSessionKey
122
+ }) ? resolveMatrixDmSessionKey({
123
+ accountId: params.accountId,
124
+ agentId: effectiveRoute.agentId,
125
+ roomId: params.roomId,
126
+ dmSessionScope: params.dmSessionScope,
127
+ fallbackSessionKey: effectiveRoute.sessionKey
128
+ }) : effectiveRoute.sessionKey;
129
+ const routeWithDmScope = dmSessionKey === effectiveRoute.sessionKey ? effectiveRoute : {
130
+ ...effectiveRoute,
131
+ sessionKey: dmSessionKey,
132
+ lastRoutePolicy: "session"
133
+ };
134
+ if (!configuredBinding && !configuredSessionKey && params.threadId) {
135
+ const threadKeys = resolveMatrixThreadSessionKeys({
136
+ baseSessionKey: routeWithDmScope.sessionKey,
137
+ threadId: params.threadId,
138
+ parentSessionKey: routeWithDmScope.sessionKey
139
+ });
140
+ return {
141
+ route: {
142
+ ...routeWithDmScope,
143
+ sessionKey: threadKeys.sessionKey,
144
+ mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey,
145
+ lastRoutePolicy: deriveLastRoutePolicy({
146
+ sessionKey: threadKeys.sessionKey,
147
+ mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey
148
+ })
149
+ },
150
+ configuredBinding,
151
+ runtimeBindingId: null
152
+ };
153
+ }
154
+ return {
155
+ route: routeWithDmScope,
156
+ configuredBinding,
157
+ runtimeBindingId: null
158
+ };
159
+ }
160
+ //#endregion
161
+ export { EventType as a, resolveMatrixThreadRouting as i, resolveMatrixReplyToEventId as n, RelationType as o, resolveMatrixThreadRootId as r, resolveMatrixInboundRoute as t };
@@ -0,0 +1,6 @@
1
+ //#region extensions/matrix/src/matrix/client/runtime.ts
2
+ function isBunRuntime() {
3
+ return typeof process.versions.bun === "string";
4
+ }
5
+ //#endregion
6
+ export { isBunRuntime as t };
@@ -0,0 +1,8 @@
1
+ import { createPluginRuntimeStore } from "openclaw/plugin-sdk/runtime-store";
2
+ //#region extensions/matrix/src/runtime.ts
3
+ const { setRuntime: setMatrixRuntime, getRuntime: getMatrixRuntime, tryGetRuntime: getOptionalMatrixRuntime } = createPluginRuntimeStore({
4
+ pluginId: "matrix",
5
+ errorMessage: "Matrix runtime not initialized"
6
+ });
7
+ //#endregion
8
+ export { getOptionalMatrixRuntime as n, setMatrixRuntime as r, getMatrixRuntime as t };
@@ -0,0 +1,25 @@
1
+ import "./timeout-abort-signal-CtaIaP1v.js";
2
+ import "openclaw/plugin-sdk/account-id";
3
+ import { resolveThreadBindingIdleTimeoutMsForChannel, resolveThreadBindingMaxAgeMsForChannel } from "openclaw/plugin-sdk/conversation-runtime";
4
+ import "openclaw/plugin-sdk/channel-message";
5
+ import "openclaw/plugin-sdk/channel-policy";
6
+ import { chunkTextForOutbound as chunkTextForOutbound$1 } from "openclaw/plugin-sdk/text-chunking";
7
+ import { createActionGate as createActionGate$1, jsonResult, readNumberParam as readNumberParam$1, readReactionParams, readStringArrayParam, readStringParam as readStringParam$1 } from "openclaw/plugin-sdk/channel-actions";
8
+ import "openclaw/plugin-sdk/routing";
9
+ import "openclaw/plugin-sdk/channel-status";
10
+ import "openclaw/plugin-sdk/channel-config-primitives";
11
+ import "openclaw/plugin-sdk/ssrf-runtime";
12
+ import "openclaw/plugin-sdk/channel-location";
13
+ import "openclaw/plugin-sdk/channel-logging";
14
+ import "openclaw/plugin-sdk/channel-targets";
15
+ import "openclaw/plugin-sdk/setup";
16
+ import "openclaw/plugin-sdk/json-store";
17
+ import "openclaw/plugin-sdk/outbound-media";
18
+ import "openclaw/plugin-sdk/poll-runtime";
19
+ import { formatZonedTimestamp } from "openclaw/plugin-sdk/time-runtime";
20
+ import "openclaw/plugin-sdk/channel-feedback";
21
+ import { GROUP_POLICY_BLOCKED_LABEL, resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
22
+ import "openclaw/plugin-sdk/inbound-reply-dispatch";
23
+ import "openclaw/plugin-sdk/acp-binding-runtime";
24
+ import { resolveOutboundSendDep } from "openclaw/plugin-sdk/outbound-send-deps";
25
+ export { jsonResult as a, readStringArrayParam as c, resolveDefaultGroupPolicy as d, resolveOutboundSendDep as f, warnMissingProviderGroupPolicyFallbackOnce as h, formatZonedTimestamp as i, readStringParam$1 as l, resolveThreadBindingMaxAgeMsForChannel as m, chunkTextForOutbound$1 as n, readNumberParam$1 as o, resolveThreadBindingIdleTimeoutMsForChannel as p, createActionGate$1 as r, readReactionParams as s, GROUP_POLICY_BLOCKED_LABEL as t, resolveAllowlistProviderRuntimeGroupPolicy as u };