@openclaw/matrix 2026.7.1 → 2026.7.2-beta.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 (83) hide show
  1. package/dist/{account-selection-5e4mHR1m.js → account-selection-Bz00QTmQ.js} +4 -3
  2. package/dist/api.js +8 -8
  3. package/dist/{approval-handler.runtime-DI5x9r8I.js → approval-handler.runtime-BQZdg_dJ.js} +27 -17
  4. package/dist/{approval-ids-ZgqbspmS.js → approval-ids-De4IhOSN.js} +1 -1
  5. package/dist/{approval-reaction-auth-D9LijQhr.js → approval-reaction-auth-BLJKPLku.js} +2 -2
  6. package/dist/approval-reactions-D-BxBK_L.js +202 -0
  7. package/dist/auth-presence.js +1 -1
  8. package/dist/{channel-jUTBsjHU.js → channel-B1woOUgk.js} +103 -143
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/{channel.runtime-DO1Nv9ed.js → channel.runtime-BvJm9z0w.js} +7 -7
  11. package/dist/{cli-CEfWwCKx.js → cli-CLWOkMvw.js} +15 -12
  12. package/dist/{cli-metadata-CfiEO-CE.js → cli-metadata-9Naf7in0.js} +1 -1
  13. package/dist/cli-metadata.js +1 -1
  14. package/dist/{client-FRuyCNju.js → client-BUai6s29.js} +2 -2
  15. package/dist/{client-tgnlQJk4.js → client-CPuYbNL8.js} +4 -4
  16. package/dist/{client-bootstrap-DjFJ7e0N.js → client-bootstrap-CNVF73sF.js} +1 -1
  17. package/dist/{config-schema-DtnhNYd-.js → config-schema-BTSatSY3.js} +27 -63
  18. package/dist/contract-api.js +2 -2
  19. package/dist/{create-client-CNakT7zF.js → create-client-85ttAWDP.js} +3 -3
  20. package/dist/{credentials-Ds9V1mn2.js → credentials-CncWUieb.js} +1 -1
  21. package/dist/{credentials-read-BlkvsNFg.js → credentials-read-CwNJrmwu.js} +2 -2
  22. package/dist/{credentials-write.runtime-CTqqxcut.js → credentials-write.runtime-BDtpqvj0.js} +1 -1
  23. package/dist/{crypto-runtime-B74cTS6A.js → crypto-runtime-DoEB5RpM.js} +74 -44
  24. package/dist/{deps-CdjHvnmh.js → deps-DDbghaZH.js} +23 -90
  25. package/dist/{directory-live-Ufd4qSpX.js → directory-live-0TyS9xep.js} +3 -3
  26. package/dist/doctor-BGTs609f.js +64 -0
  27. package/dist/{doctor-contract-BAja_fmb.js → doctor-contract-D2qTLe-C.js} +72 -6
  28. package/dist/doctor-contract-api.js +323 -45
  29. package/dist/{draft-stream-D4EH25gv.js → draft-stream-GOdPZMBm.js} +1 -1
  30. package/dist/{encryption-guidance-D8walY04.js → encryption-guidance-BFfgq7c7.js} +1 -1
  31. package/dist/{env-auth-DIzOApj0.js → env-auth-CQsYbz-p.js} +1 -1
  32. package/dist/{env-vars-KzaYveuy.js → env-vars-B0NxQnPk.js} +3 -1
  33. package/dist/{exec-approval-resolver-f9j6staN.js → exec-approval-resolver-BCgqRtZS.js} +2 -1
  34. package/dist/{file-sync-store-DVm0ACml.js → file-sync-store-CUE9WwD2.js} +2 -3
  35. package/dist/helper-api.js +4 -4
  36. package/dist/{http-client-nSmFiVgk.js → http-client-Jw5_bwQo.js} +18 -34
  37. package/dist/{idb-persistence-BHm97th-.js → idb-persistence-BiHEEzD7.js} +1 -1
  38. package/dist/inbound-dedupe-CaBLblef.js +48 -0
  39. package/dist/index.js +1 -1
  40. package/dist/{media-text-p-LP21qs.js → media-text-DPCtdFjk.js} +1 -1
  41. package/dist/{messages-DRKkiEY-.js → messages-DCRbGLMh.js} +3 -3
  42. package/dist/{monitor-CsGOGdwu.js → monitor-C5EOF9et.js} +90 -427
  43. package/dist/plugin-entry.handlers.runtime.js +1 -1
  44. package/dist/probe.runtime-BBvciVfo.js +3 -0
  45. package/dist/{profile-update-Ucc8RrJL.js → profile-update-DompcDyu.js} +2 -2
  46. package/dist/{reaction-events-DentrVii.js → reaction-events-QUgxkQKQ.js} +60 -10
  47. package/dist/record-shared-CvzjvHRn.js +2 -0
  48. package/dist/{recovery-key-store-DSeLFvNx.js → recovery-key-store-B2RglalK.js} +1 -1
  49. package/dist/{resolve-targets-DcV_KfgX.js → resolve-targets-Cx1VVArA.js} +1 -1
  50. package/dist/{resolver.runtime-Hr6bO5zl.js → resolver.runtime-PPrv3ZHu.js} +1 -1
  51. package/dist/room-info-B6vKD5DF.js +86 -0
  52. package/dist/{runtime-api-CsBoesCU.js → runtime-api-D1xI_cvh.js} +3 -3
  53. package/dist/runtime-api.js +6 -6
  54. package/dist/{sdk-AZYVl34z.js → sdk-1TXuSiXZ.js} +10 -15
  55. package/dist/{secret-contract-DTgQyQxc.js → secret-contract-OZoQf0kI.js} +7 -48
  56. package/dist/secret-contract-api.js +1 -1
  57. package/dist/{send-D92v6Yy0.js → send-yre1krm8.js} +9 -3
  58. package/dist/session-binding-contract-api.js +1 -1
  59. package/dist/{setup-bootstrap-Da564w5f.js → setup-bootstrap-DXVRCd4G.js} +2 -2
  60. package/dist/{setup-core-BGgbrdaJ.js → setup-core-CYQRY2oG.js} +9 -7
  61. package/dist/setup-plugin-api.js +3 -3
  62. package/dist/{setup-surface-iJ6pd-t5.js → setup-surface-BjvRQzK6.js} +7 -7
  63. package/dist/{shared-DkFfq7mH.js → shared-BfW4lxGu.js} +13 -8
  64. package/dist/{startup-verification-BKMAXvcV.js → startup-verification-DSiyDKM5.js} +2 -3
  65. package/dist/storage-DD-EnNJE.js +718 -0
  66. package/dist/{storage-paths-BWo_ZEMC.js → storage-paths-B4_I9iqO.js} +1 -12
  67. package/dist/{thread-bindings-BX5nmWpw.js → thread-bindings-U5ZroBeZ.js} +3 -4
  68. package/dist/{tool-actions.runtime-C1d5fxE_.js → tool-actions.runtime-BlfTr9b0.js} +246 -53
  69. package/dist/{verification-BGCMiO1p.js → verification-CGnI9k1O.js} +2 -2
  70. package/npm-shrinkwrap.json +3 -3
  71. package/openclaw.plugin.json +136 -125
  72. package/package.json +4 -4
  73. package/dist/approval-reactions-BdUaUXVw.js +0 -113
  74. package/dist/crypto-state-store-Jy3qwhdy.js +0 -352
  75. package/dist/doctor-DfaOqFtr.js +0 -167
  76. package/dist/legacy-crypto-inspector-vzXSkm18.js +0 -42
  77. package/dist/legacy-crypto-restore-CIBfOmLn.js +0 -93
  78. package/dist/matrix-migration.runtime-BMCyrANT.js +0 -524
  79. package/dist/migration-snapshot-backup-YcCrSjbE.js +0 -69
  80. package/dist/migration-snapshot.runtime-VGD4QfeS.js +0 -2
  81. package/dist/probe.runtime-2MZLc6ng.js +0 -3
  82. package/dist/runtime-heavy-api.js +0 -3
  83. package/dist/storage-CQdyKcGg.js +0 -430
@@ -1,524 +0,0 @@
1
- import { a as resolveMatrixDefaultOrOnlyAccountId, i as resolveMatrixChannelConfig, n as requiresExplicitMatrixDefaultAccount, r as resolveConfiguredMatrixAccountIds, s as resolveMatrixAccountStringValues, t as findMatrixAccountEntry } from "./account-selection-5e4mHR1m.js";
2
- import { i as resolveScopedMatrixEnvConfig, n as resolveGlobalMatrixEnvConfig } from "./env-auth-DIzOApj0.js";
3
- import { a as resolveMatrixCredentialsPath, n as resolveMatrixAccountStorageRoot, s as resolveMatrixLegacyFlatStoragePaths } from "./storage-paths-BWo_ZEMC.js";
4
- import { t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
5
- import { C as writeMatrixLegacyCryptoMigrationState, T as writeMatrixRecoveryKeyState, _ as readMatrixLegacyCryptoMigrationState, l as migrateLegacyMatrixRecoveryKeyFileToStore, s as migrateLegacyMatrixLegacyCryptoMigrationFileToStore, v as readMatrixRecoveryKeyState } from "./crypto-state-store-Jy3qwhdy.js";
6
- import "./migration-snapshot-backup-YcCrSjbE.js";
7
- import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
- import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
9
- import fs from "node:fs";
10
- import os from "node:os";
11
- import path from "node:path";
12
- import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
13
- import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
14
- import { fileURLToPath } from "node:url";
15
- //#region extensions/matrix/src/migration-config.ts
16
- function clean(value) {
17
- return normalizeOptionalString(value) ?? "";
18
- }
19
- function resolveMatrixAccountConfigEntry(cfg, accountId) {
20
- return findMatrixAccountEntry(cfg, accountId);
21
- }
22
- function resolveMatrixFlatStoreSelectionNote(cfg, accountId) {
23
- if (resolveConfiguredMatrixAccountIds(cfg).length <= 1) return;
24
- return `Legacy Matrix flat store uses one shared on-disk state, so it will be migrated into account "${accountId}".`;
25
- }
26
- function resolveMatrixMigrationConfigFields(params) {
27
- const channel = resolveMatrixChannelConfig(params.cfg);
28
- const account = resolveMatrixAccountConfigEntry(params.cfg, params.accountId);
29
- const scopedEnv = resolveScopedMatrixEnvConfig(params.accountId, params.env);
30
- const globalEnv = resolveGlobalMatrixEnvConfig(params.env);
31
- const resolvedStrings = resolveMatrixAccountStringValues({
32
- accountId: normalizeAccountId(params.accountId),
33
- account: {
34
- homeserver: clean(account?.homeserver),
35
- userId: clean(account?.userId),
36
- accessToken: clean(account?.accessToken)
37
- },
38
- scopedEnv,
39
- channel: {
40
- homeserver: clean(channel?.homeserver),
41
- userId: clean(channel?.userId),
42
- accessToken: clean(channel?.accessToken)
43
- },
44
- globalEnv
45
- });
46
- return {
47
- homeserver: resolvedStrings.homeserver,
48
- userId: resolvedStrings.userId,
49
- accessToken: resolvedStrings.accessToken
50
- };
51
- }
52
- function loadStoredMatrixCredentials(env, accountId) {
53
- const credentialsPath = resolveMatrixCredentialsPath({
54
- stateDir: resolveStateDir(env, os.homedir),
55
- accountId: normalizeAccountId(accountId)
56
- });
57
- try {
58
- if (!fs.existsSync(credentialsPath)) return null;
59
- const parsed = JSON.parse(fs.readFileSync(credentialsPath, "utf8"));
60
- if (typeof parsed.homeserver !== "string" || typeof parsed.userId !== "string" || typeof parsed.accessToken !== "string") return null;
61
- return {
62
- homeserver: parsed.homeserver,
63
- userId: parsed.userId,
64
- accessToken: parsed.accessToken,
65
- deviceId: typeof parsed.deviceId === "string" ? parsed.deviceId : void 0
66
- };
67
- } catch {
68
- return null;
69
- }
70
- }
71
- function credentialsMatchResolvedIdentity(stored, identity) {
72
- if (!stored || !identity.homeserver) return false;
73
- if (!identity.userId) {
74
- if (!identity.accessToken) return false;
75
- return stored.homeserver === identity.homeserver && stored.accessToken === identity.accessToken;
76
- }
77
- return stored.homeserver === identity.homeserver && stored.userId === identity.userId;
78
- }
79
- function resolveMatrixMigrationAccountTarget(params) {
80
- const stored = loadStoredMatrixCredentials(params.env, params.accountId);
81
- const resolved = resolveMatrixMigrationConfigFields(params);
82
- const matchingStored = credentialsMatchResolvedIdentity(stored, {
83
- homeserver: resolved.homeserver,
84
- userId: resolved.userId,
85
- accessToken: resolved.accessToken
86
- }) ? stored : null;
87
- const homeserver = resolved.homeserver;
88
- const userId = resolved.userId || matchingStored?.userId || "";
89
- const accessToken = resolved.accessToken || matchingStored?.accessToken || "";
90
- if (!homeserver || !userId || !accessToken) return null;
91
- const { rootDir } = resolveMatrixAccountStorageRoot({
92
- stateDir: resolveStateDir(params.env, os.homedir),
93
- homeserver,
94
- userId,
95
- accessToken,
96
- accountId: params.accountId
97
- });
98
- return {
99
- accountId: params.accountId,
100
- homeserver,
101
- userId,
102
- accessToken,
103
- rootDir,
104
- storedDeviceId: matchingStored?.deviceId ?? null
105
- };
106
- }
107
- function resolveLegacyMatrixFlatStoreTarget(params) {
108
- if (!resolveMatrixChannelConfig(params.cfg)) return { warning: `Legacy Matrix ${params.detectedKind} detected at ${params.detectedPath}, but channels.matrix is not configured yet. Configure Matrix, then rerun "openclaw doctor --fix" or restart the gateway.` };
109
- if (requiresExplicitMatrixDefaultAccount(params.cfg)) return { warning: `Legacy Matrix ${params.detectedKind} detected at ${params.detectedPath}, but multiple Matrix accounts are configured and channels.matrix.defaultAccount is not set. Set "channels.matrix.defaultAccount" to the intended target account before rerunning "openclaw doctor --fix" or restarting the gateway.` };
110
- const accountId = resolveMatrixDefaultOrOnlyAccountId(params.cfg);
111
- const target = resolveMatrixMigrationAccountTarget({
112
- cfg: params.cfg,
113
- env: params.env,
114
- accountId
115
- });
116
- if (!target) {
117
- const targetDescription = params.detectedKind === "state" ? "the new account-scoped target" : "the account-scoped target";
118
- return { warning: `Legacy Matrix ${params.detectedKind} detected at ${params.detectedPath}, but ${targetDescription} could not be resolved yet (need homeserver, userId, and access token for channels.matrix${accountId === DEFAULT_ACCOUNT_ID ? "" : `.accounts.${accountId}`}). Start the gateway once with a working Matrix login, or rerun "openclaw doctor --fix" after cached credentials are available.` };
119
- }
120
- return {
121
- ...target,
122
- selectionNote: resolveMatrixFlatStoreSelectionNote(params.cfg, accountId)
123
- };
124
- }
125
- //#endregion
126
- //#region extensions/matrix/src/legacy-state.ts
127
- function resolveLegacyMatrixPaths(env) {
128
- return resolveMatrixLegacyFlatStoragePaths(resolveStateDir(env, os.homedir));
129
- }
130
- function resolveMatrixMigrationPlan(params) {
131
- const legacy = resolveLegacyMatrixPaths(params.env);
132
- if (!fs.existsSync(legacy.storagePath) && !fs.existsSync(legacy.cryptoPath)) return null;
133
- const target = resolveLegacyMatrixFlatStoreTarget({
134
- cfg: params.cfg,
135
- env: params.env,
136
- detectedPath: legacy.rootDir,
137
- detectedKind: "state"
138
- });
139
- if ("warning" in target) return target;
140
- return {
141
- accountId: target.accountId,
142
- legacyStoragePath: legacy.storagePath,
143
- legacyCryptoPath: legacy.cryptoPath,
144
- targetRootDir: target.rootDir,
145
- targetStoragePath: path.join(target.rootDir, "bot-storage.json"),
146
- targetCryptoPath: path.join(target.rootDir, "crypto"),
147
- selectionNote: target.selectionNote
148
- };
149
- }
150
- function detectLegacyMatrixState(params) {
151
- return resolveMatrixMigrationPlan({
152
- cfg: params.cfg,
153
- env: params.env ?? process.env
154
- });
155
- }
156
- function moveLegacyPath(params) {
157
- if (!fs.existsSync(params.sourcePath)) return;
158
- if (fs.existsSync(params.targetPath)) {
159
- params.warnings.push(`Matrix legacy ${params.label} not migrated because the target already exists (${params.targetPath}).`);
160
- return;
161
- }
162
- try {
163
- fs.mkdirSync(path.dirname(params.targetPath), { recursive: true });
164
- fs.renameSync(params.sourcePath, params.targetPath);
165
- params.changes.push(`Migrated Matrix legacy ${params.label}: ${params.sourcePath} -> ${params.targetPath}`);
166
- } catch (err) {
167
- params.warnings.push(`Failed migrating Matrix legacy ${params.label} (${params.sourcePath} -> ${params.targetPath}): ${String(err)}`);
168
- }
169
- }
170
- async function autoMigrateLegacyMatrixState(params) {
171
- const env = params.env ?? process.env;
172
- const detection = detectLegacyMatrixState({
173
- cfg: params.cfg,
174
- env
175
- });
176
- if (!detection) return {
177
- migrated: false,
178
- changes: [],
179
- warnings: []
180
- };
181
- if ("warning" in detection) {
182
- params.log?.warn?.(`matrix: ${detection.warning}`);
183
- return {
184
- migrated: false,
185
- changes: [],
186
- warnings: [detection.warning]
187
- };
188
- }
189
- const changes = [];
190
- const warnings = [];
191
- moveLegacyPath({
192
- sourcePath: detection.legacyStoragePath,
193
- targetPath: detection.targetStoragePath,
194
- label: "sync store",
195
- changes,
196
- warnings
197
- });
198
- moveLegacyPath({
199
- sourcePath: detection.legacyCryptoPath,
200
- targetPath: detection.targetCryptoPath,
201
- label: "crypto store",
202
- changes,
203
- warnings
204
- });
205
- if (changes.length > 0) {
206
- const details = [
207
- ...changes.map((entry) => `- ${entry}`),
208
- ...detection.selectionNote ? [`- ${detection.selectionNote}`] : [],
209
- "- No user action required."
210
- ];
211
- params.log?.info?.(`matrix: plugin upgraded in place for account "${detection.accountId}".\n${details.join("\n")}`);
212
- }
213
- if (warnings.length > 0) params.log?.warn?.(`matrix: legacy state migration warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`);
214
- return {
215
- migrated: changes.length > 0,
216
- changes,
217
- warnings
218
- };
219
- }
220
- //#endregion
221
- //#region extensions/matrix/src/legacy-crypto-inspector-availability.ts
222
- const LEGACY_CRYPTO_INSPECTOR_FILE = "legacy-crypto-inspector.js";
223
- const LEGACY_CRYPTO_INSPECTOR_CHUNK_PREFIX = "legacy-crypto-inspector-";
224
- const LEGACY_CRYPTO_INSPECTOR_HELPER_CHUNK_PREFIX = "availability-";
225
- const JAVASCRIPT_MODULE_SUFFIX = ".js";
226
- function isLegacyCryptoInspectorArtifactName(name) {
227
- if (name === LEGACY_CRYPTO_INSPECTOR_FILE) return true;
228
- if (!name.startsWith(LEGACY_CRYPTO_INSPECTOR_CHUNK_PREFIX) || !name.endsWith(JAVASCRIPT_MODULE_SUFFIX)) return false;
229
- const chunkSuffix = name.slice(24, -3);
230
- return chunkSuffix.length > 0 && chunkSuffix !== "availability" && !chunkSuffix.startsWith(LEGACY_CRYPTO_INSPECTOR_HELPER_CHUNK_PREFIX);
231
- }
232
- function hasSourceInspectorArtifact(currentDir) {
233
- return [path.resolve(currentDir, "matrix", "legacy-crypto-inspector.ts"), path.resolve(currentDir, "matrix", "legacy-crypto-inspector.js")].some((candidate) => fs.existsSync(candidate));
234
- }
235
- function hasBuiltInspectorArtifact(currentDir) {
236
- if (fs.existsSync(path.join(currentDir, "legacy-crypto-inspector.js"))) return true;
237
- if (fs.existsSync(path.join(currentDir, "extensions", "matrix", "legacy-crypto-inspector.js"))) return true;
238
- return fs.readdirSync(currentDir, { withFileTypes: true }).some((entry) => entry.isFile() && isLegacyCryptoInspectorArtifactName(entry.name));
239
- }
240
- function isMatrixLegacyCryptoInspectorAvailable() {
241
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
242
- if (hasSourceInspectorArtifact(currentDir)) return true;
243
- try {
244
- return hasBuiltInspectorArtifact(currentDir);
245
- } catch {
246
- return false;
247
- }
248
- }
249
- //#endregion
250
- //#region extensions/matrix/src/legacy-crypto.ts
251
- const MATRIX_LEGACY_CRYPTO_INSPECTOR_UNAVAILABLE_MESSAGE = "Legacy Matrix encrypted state was detected, but the Matrix crypto inspector is unavailable.";
252
- async function loadMatrixLegacyCryptoInspector() {
253
- return (await import("./legacy-crypto-inspector-vzXSkm18.js")).inspectLegacyMatrixCryptoStore;
254
- }
255
- function detectLegacyBotSdkCryptoStore(cryptoRootDir) {
256
- try {
257
- if (!fs.statSync(cryptoRootDir).isDirectory()) return {
258
- detected: false,
259
- warning: `Legacy Matrix encrypted state path exists but is not a directory: ${cryptoRootDir}. OpenClaw skipped automatic crypto migration for that path.`
260
- };
261
- } catch (err) {
262
- return {
263
- detected: false,
264
- warning: `Failed reading legacy Matrix encrypted state path (${cryptoRootDir}): ${String(err)}. OpenClaw skipped automatic crypto migration for that path.`
265
- };
266
- }
267
- try {
268
- return { detected: fs.existsSync(path.join(cryptoRootDir, "bot-sdk.json")) || fs.existsSync(path.join(cryptoRootDir, "matrix-sdk-crypto.sqlite3")) || fs.readdirSync(cryptoRootDir, { withFileTypes: true }).some((entry) => entry.isDirectory() && fs.existsSync(path.join(cryptoRootDir, entry.name, "matrix-sdk-crypto.sqlite3"))) };
269
- } catch (err) {
270
- return {
271
- detected: false,
272
- warning: `Failed scanning legacy Matrix encrypted state path (${cryptoRootDir}): ${String(err)}. OpenClaw skipped automatic crypto migration for that path.`
273
- };
274
- }
275
- }
276
- function resolveMatrixAccountIds(cfg) {
277
- return resolveConfiguredMatrixAccountIds(cfg);
278
- }
279
- function resolveLegacyMatrixFlatStorePlan(params) {
280
- const legacy = resolveMatrixLegacyFlatStoragePaths(resolveStateDir(params.env, os.homedir));
281
- if (!fs.existsSync(legacy.cryptoPath)) return null;
282
- const legacyStore = detectLegacyBotSdkCryptoStore(legacy.cryptoPath);
283
- if (legacyStore.warning) return { warning: legacyStore.warning };
284
- if (!legacyStore.detected) return null;
285
- const target = resolveLegacyMatrixFlatStoreTarget({
286
- cfg: params.cfg,
287
- env: params.env,
288
- detectedPath: legacy.cryptoPath,
289
- detectedKind: "encrypted state"
290
- });
291
- if ("warning" in target) return target;
292
- const metadata = loadLegacyBotSdkMetadata(legacy.cryptoPath);
293
- return {
294
- accountId: target.accountId,
295
- rootDir: target.rootDir,
296
- recoveryKeyPath: path.join(target.rootDir, "recovery-key.json"),
297
- statePath: path.join(target.rootDir, "legacy-crypto-migration.json"),
298
- legacyCryptoPath: legacy.cryptoPath,
299
- homeserver: target.homeserver,
300
- userId: target.userId,
301
- accessToken: target.accessToken,
302
- deviceId: metadata.deviceId ?? target.storedDeviceId
303
- };
304
- }
305
- function loadLegacyBotSdkMetadata(cryptoRootDir) {
306
- const metadataPath = path.join(cryptoRootDir, "bot-sdk.json");
307
- const fallback = { deviceId: null };
308
- const parsed = loadJsonFile(metadataPath);
309
- return { deviceId: typeof parsed?.deviceId === "string" && parsed.deviceId.trim() ? parsed.deviceId : fallback.deviceId };
310
- }
311
- function resolveMatrixLegacyCryptoPlans(params) {
312
- const warnings = [];
313
- const plans = [];
314
- const flatPlan = resolveLegacyMatrixFlatStorePlan(params);
315
- if (flatPlan) if ("warning" in flatPlan) warnings.push(flatPlan.warning);
316
- else plans.push(flatPlan);
317
- for (const accountId of resolveMatrixAccountIds(params.cfg)) {
318
- const target = resolveMatrixMigrationAccountTarget({
319
- cfg: params.cfg,
320
- env: params.env,
321
- accountId
322
- });
323
- if (!target) continue;
324
- const legacyCryptoPath = path.join(target.rootDir, "crypto");
325
- if (!fs.existsSync(legacyCryptoPath)) continue;
326
- const detectedStore = detectLegacyBotSdkCryptoStore(legacyCryptoPath);
327
- if (detectedStore.warning) {
328
- warnings.push(detectedStore.warning);
329
- continue;
330
- }
331
- if (!detectedStore.detected) continue;
332
- if (plans.some((plan) => plan.accountId === accountId && path.resolve(plan.legacyCryptoPath) === path.resolve(legacyCryptoPath))) continue;
333
- const metadata = loadLegacyBotSdkMetadata(legacyCryptoPath);
334
- plans.push({
335
- accountId: target.accountId,
336
- rootDir: target.rootDir,
337
- recoveryKeyPath: path.join(target.rootDir, "recovery-key.json"),
338
- statePath: path.join(target.rootDir, "legacy-crypto-migration.json"),
339
- legacyCryptoPath,
340
- homeserver: target.homeserver,
341
- userId: target.userId,
342
- accessToken: target.accessToken,
343
- deviceId: metadata.deviceId ?? target.storedDeviceId
344
- });
345
- }
346
- return {
347
- plans,
348
- warnings
349
- };
350
- }
351
- function detectLegacyMatrixCrypto(params) {
352
- const detection = resolveMatrixLegacyCryptoPlans({
353
- cfg: params.cfg,
354
- env: params.env ?? process.env
355
- });
356
- const inspectorAvailable = detection.plans.length === 0 || isMatrixLegacyCryptoInspectorAvailable();
357
- if (!inspectorAvailable && detection.plans.length > 0) return {
358
- inspectorAvailable,
359
- plans: detection.plans,
360
- warnings: [...detection.warnings, MATRIX_LEGACY_CRYPTO_INSPECTOR_UNAVAILABLE_MESSAGE]
361
- };
362
- return {
363
- inspectorAvailable,
364
- plans: detection.plans,
365
- warnings: detection.warnings
366
- };
367
- }
368
- async function autoPrepareLegacyMatrixCrypto(params) {
369
- const env = params.env ?? process.env;
370
- const detection = params.deps?.inspectLegacyStore ? resolveMatrixLegacyCryptoPlans({
371
- cfg: params.cfg,
372
- env
373
- }) : detectLegacyMatrixCrypto({
374
- cfg: params.cfg,
375
- env
376
- });
377
- const inspectorAvailable = "inspectorAvailable" in detection ? detection.inspectorAvailable : true;
378
- const warnings = [...detection.warnings];
379
- const changes = [];
380
- if (detection.plans.length === 0) {
381
- if (warnings.length > 0) params.log?.warn?.(`matrix: legacy encrypted-state warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`);
382
- return {
383
- migrated: false,
384
- changes,
385
- warnings
386
- };
387
- }
388
- if (!params.deps?.inspectLegacyStore && !inspectorAvailable) {
389
- if (warnings.length > 0) params.log?.warn?.(`matrix: legacy encrypted-state warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`);
390
- return {
391
- migrated: false,
392
- changes,
393
- warnings
394
- };
395
- }
396
- let inspectLegacyStore = params.deps?.inspectLegacyStore;
397
- if (!inspectLegacyStore) try {
398
- inspectLegacyStore = await loadMatrixLegacyCryptoInspector();
399
- } catch (err) {
400
- const message = formatMatrixErrorMessage(err);
401
- if (!warnings.includes(message)) warnings.push(message);
402
- if (warnings.length > 0) params.log?.warn?.(`matrix: legacy encrypted-state warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`);
403
- return {
404
- migrated: false,
405
- changes,
406
- warnings
407
- };
408
- }
409
- if (!inspectLegacyStore) return {
410
- migrated: false,
411
- changes,
412
- warnings
413
- };
414
- for (const plan of detection.plans) {
415
- try {
416
- migrateLegacyMatrixLegacyCryptoMigrationFileToStore(plan.rootDir);
417
- migrateLegacyMatrixRecoveryKeyFileToStore(plan.rootDir);
418
- } catch (err) {
419
- warnings.push(`Failed migrating Matrix crypto sidecar state for account "${plan.accountId}" (${plan.rootDir}): ${String(err)}`);
420
- }
421
- if (readMatrixLegacyCryptoMigrationState(plan.rootDir)?.version === 1) continue;
422
- if (!plan.deviceId) {
423
- warnings.push(`Legacy Matrix encrypted state detected at ${plan.legacyCryptoPath}, but no device ID was found for account "${plan.accountId}". OpenClaw will continue, but old encrypted history cannot be recovered automatically.`);
424
- continue;
425
- }
426
- let summary;
427
- try {
428
- summary = await inspectLegacyStore({
429
- cryptoRootDir: plan.legacyCryptoPath,
430
- userId: plan.userId,
431
- deviceId: plan.deviceId,
432
- log: params.log?.info
433
- });
434
- } catch (err) {
435
- warnings.push(`Failed inspecting legacy Matrix encrypted state for account "${plan.accountId}" (${plan.legacyCryptoPath}): ${String(err)}`);
436
- continue;
437
- }
438
- let decryptionKeyImported = false;
439
- if (summary.decryptionKeyBase64) {
440
- const existingRecoveryKey = readMatrixRecoveryKeyState(plan.rootDir);
441
- if (existingRecoveryKey?.privateKeyBase64 && existingRecoveryKey.privateKeyBase64 !== summary.decryptionKeyBase64) warnings.push(`Legacy Matrix backup key was found for account "${plan.accountId}", but Matrix SQLite state already contains a different recovery key. Leaving the existing state unchanged.`);
442
- else if (!existingRecoveryKey?.privateKeyBase64) {
443
- const payload = {
444
- version: 1,
445
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
446
- keyId: null,
447
- privateKeyBase64: summary.decryptionKeyBase64
448
- };
449
- try {
450
- writeMatrixRecoveryKeyState({
451
- storageRootDir: plan.rootDir,
452
- payload
453
- });
454
- changes.push(`Imported Matrix legacy backup key for account "${plan.accountId}" into SQLite`);
455
- decryptionKeyImported = true;
456
- } catch (err) {
457
- warnings.push(`Failed writing Matrix recovery key for account "${plan.accountId}" to SQLite: ${String(err)}`);
458
- }
459
- } else decryptionKeyImported = true;
460
- }
461
- const localOnlyKeys = summary.roomKeyCounts && summary.roomKeyCounts.total > summary.roomKeyCounts.backedUp ? summary.roomKeyCounts.total - summary.roomKeyCounts.backedUp : 0;
462
- if (localOnlyKeys > 0) warnings.push(`Legacy Matrix encrypted state for account "${plan.accountId}" contains ${localOnlyKeys} room key(s) that were never backed up. Backed-up keys can be restored automatically, but local-only encrypted history may remain unavailable after upgrade.`);
463
- if (!summary.decryptionKeyBase64 && (summary.roomKeyCounts?.backedUp ?? 0) > 0) warnings.push(`Legacy Matrix encrypted state for account "${plan.accountId}" has backed-up room keys, but no local backup decryption key was found. Ask the operator to run "openclaw matrix verify backup restore --recovery-key <key>" after upgrade if they have the recovery key.`);
464
- if (!summary.decryptionKeyBase64 && (summary.roomKeyCounts?.total ?? 0) > 0) warnings.push(`Legacy Matrix encrypted state for account "${plan.accountId}" cannot be fully converted automatically because the old rust crypto store does not expose all local room keys for export.`);
465
- if (summary.decryptionKeyBase64 && !decryptionKeyImported && !readMatrixRecoveryKeyState(plan.rootDir)) continue;
466
- const state = {
467
- version: 1,
468
- source: "matrix-bot-sdk-rust",
469
- accountId: plan.accountId,
470
- deviceId: summary.deviceId,
471
- roomKeyCounts: summary.roomKeyCounts,
472
- backupVersion: summary.backupVersion,
473
- decryptionKeyImported,
474
- restoreStatus: decryptionKeyImported ? "pending" : "manual-action-required",
475
- detectedAt: (/* @__PURE__ */ new Date()).toISOString(),
476
- lastError: null
477
- };
478
- try {
479
- writeMatrixLegacyCryptoMigrationState({
480
- storageRootDir: plan.rootDir,
481
- state
482
- });
483
- changes.push(`Prepared Matrix legacy encrypted-state migration for account "${plan.accountId}" in SQLite`);
484
- } catch (err) {
485
- warnings.push(`Failed writing Matrix legacy encrypted-state migration record for account "${plan.accountId}" to SQLite: ${String(err)}`);
486
- }
487
- }
488
- if (changes.length > 0) params.log?.info?.(`matrix: prepared encrypted-state upgrade.\n${changes.map((entry) => `- ${entry}`).join("\n")}`);
489
- if (warnings.length > 0) params.log?.warn?.(`matrix: legacy encrypted-state warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`);
490
- return {
491
- migrated: changes.length > 0,
492
- changes,
493
- warnings
494
- };
495
- }
496
- //#endregion
497
- //#region extensions/matrix/src/migration-snapshot.ts
498
- function resolveMatrixMigrationStatus(params) {
499
- const env = params.env ?? process.env;
500
- const legacyState = detectLegacyMatrixState({
501
- cfg: params.cfg,
502
- env
503
- });
504
- const legacyCrypto = detectLegacyMatrixCrypto({
505
- cfg: params.cfg,
506
- env
507
- });
508
- const actionableLegacyState = legacyState !== null && !("warning" in legacyState);
509
- const actionableLegacyCrypto = legacyCrypto.plans.length > 0 && legacyCrypto.inspectorAvailable;
510
- return {
511
- legacyState,
512
- legacyCrypto,
513
- pending: legacyState !== null || legacyCrypto.plans.length > 0 || legacyCrypto.warnings.length > 0,
514
- actionable: actionableLegacyState || actionableLegacyCrypto
515
- };
516
- }
517
- function hasPendingMatrixMigration(params) {
518
- return resolveMatrixMigrationStatus(params).pending;
519
- }
520
- function hasActionableMatrixMigration(params) {
521
- return resolveMatrixMigrationStatus(params).actionable;
522
- }
523
- //#endregion
524
- export { detectLegacyMatrixCrypto as a, autoPrepareLegacyMatrixCrypto as i, hasPendingMatrixMigration as n, autoMigrateLegacyMatrixState as o, resolveMatrixMigrationStatus as r, detectLegacyMatrixState as s, hasActionableMatrixMigration as t };
@@ -1,69 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { resolveRequiredHomeDir, resolveStateDir } from "openclaw/plugin-sdk/state-paths";
5
- import { writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
6
- //#region extensions/matrix/src/migration-snapshot-backup.ts
7
- const MATRIX_MIGRATION_SNAPSHOT_DIRNAME = "openclaw-migrations";
8
- function loadSnapshotMarker(filePath) {
9
- try {
10
- if (!fs.existsSync(filePath)) return null;
11
- const parsed = JSON.parse(fs.readFileSync(filePath, "utf8"));
12
- if (parsed.version !== 1 || typeof parsed.createdAt !== "string" || typeof parsed.archivePath !== "string" || typeof parsed.trigger !== "string") return null;
13
- return {
14
- version: 1,
15
- createdAt: parsed.createdAt,
16
- archivePath: parsed.archivePath,
17
- trigger: parsed.trigger,
18
- includeWorkspace: parsed.includeWorkspace === true
19
- };
20
- } catch {
21
- return null;
22
- }
23
- }
24
- function resolveMatrixMigrationSnapshotMarkerPath(env = process.env) {
25
- const stateDir = resolveStateDir(env, os.homedir);
26
- return path.join(stateDir, "matrix", "migration-snapshot.json");
27
- }
28
- function resolveMatrixMigrationSnapshotOutputDir(env = process.env) {
29
- const homeDir = resolveRequiredHomeDir(env, os.homedir);
30
- return path.join(homeDir, "Backups", MATRIX_MIGRATION_SNAPSHOT_DIRNAME);
31
- }
32
- async function maybeCreateMatrixMigrationSnapshot(params) {
33
- const env = params.env ?? process.env;
34
- const createBackupArchive = params.createBackupArchive ?? (await import("openclaw/plugin-sdk/runtime")).createBackupArchive;
35
- const markerPath = resolveMatrixMigrationSnapshotMarkerPath(env);
36
- const existingMarker = loadSnapshotMarker(markerPath);
37
- if (existingMarker?.archivePath && fs.existsSync(existingMarker.archivePath)) {
38
- params.log?.info?.(`matrix: reusing existing pre-migration backup snapshot: ${existingMarker.archivePath}`);
39
- return {
40
- created: false,
41
- archivePath: existingMarker.archivePath,
42
- markerPath
43
- };
44
- }
45
- if (existingMarker?.archivePath && !fs.existsSync(existingMarker.archivePath)) params.log?.warn?.(`matrix: previous migration snapshot is missing (${existingMarker.archivePath}); creating a replacement backup before continuing`);
46
- const snapshot = await createBackupArchive({
47
- output: (() => {
48
- const outputDir = params.outputDir ?? resolveMatrixMigrationSnapshotOutputDir(env);
49
- fs.mkdirSync(outputDir, { recursive: true });
50
- return outputDir;
51
- })(),
52
- includeWorkspace: false
53
- });
54
- await writeJsonFileAtomically(markerPath, {
55
- version: 1,
56
- createdAt: snapshot.createdAt,
57
- archivePath: snapshot.archivePath,
58
- trigger: params.trigger,
59
- includeWorkspace: snapshot.includeWorkspace
60
- });
61
- params.log?.info?.(`matrix: created pre-migration backup snapshot: ${snapshot.archivePath}`);
62
- return {
63
- created: true,
64
- archivePath: snapshot.archivePath,
65
- markerPath
66
- };
67
- }
68
- //#endregion
69
- export { maybeCreateMatrixMigrationSnapshot as t };
@@ -1,2 +0,0 @@
1
- import { t as maybeCreateMatrixMigrationSnapshot } from "./migration-snapshot-backup-YcCrSjbE.js";
2
- export { maybeCreateMatrixMigrationSnapshot };
@@ -1,3 +0,0 @@
1
- import { t as createMatrixClient } from "./create-client-CNakT7zF.js";
2
- import "./client-tgnlQJk4.js";
3
- export { createMatrixClient };
@@ -1,3 +0,0 @@
1
- import { a as detectLegacyMatrixCrypto, i as autoPrepareLegacyMatrixCrypto, n as hasPendingMatrixMigration, o as autoMigrateLegacyMatrixState, r as resolveMatrixMigrationStatus, s as detectLegacyMatrixState, t as hasActionableMatrixMigration } from "./matrix-migration.runtime-BMCyrANT.js";
2
- import { t as maybeCreateMatrixMigrationSnapshot } from "./migration-snapshot-backup-YcCrSjbE.js";
3
- export { autoMigrateLegacyMatrixState, autoPrepareLegacyMatrixCrypto, detectLegacyMatrixCrypto, detectLegacyMatrixState, hasActionableMatrixMigration, hasPendingMatrixMigration, maybeCreateMatrixMigrationSnapshot, resolveMatrixMigrationStatus };