@openclaw/matrix 2026.7.1-beta.6 → 2026.7.2-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.
- package/dist/{account-selection-5e4mHR1m.js → account-selection-Bz00QTmQ.js} +4 -3
- package/dist/api.js +8 -8
- package/dist/{approval-handler.runtime-DI5x9r8I.js → approval-handler.runtime--Ei44Vo2.js} +27 -17
- package/dist/{approval-ids-ZgqbspmS.js → approval-ids-C_2kSMdJ.js} +1 -1
- package/dist/{approval-reaction-auth-D9LijQhr.js → approval-reaction-auth-TdVPcgxP.js} +2 -2
- package/dist/approval-reactions-BgU51JGd.js +202 -0
- package/dist/auth-presence.js +1 -1
- package/dist/{channel-jUTBsjHU.js → channel-CxqDh7mS.js} +102 -143
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.runtime-DO1Nv9ed.js → channel.runtime-wNfJc57I.js} +7 -7
- package/dist/{cli-metadata-CfiEO-CE.js → cli-metadata-Gf3HSJ2c.js} +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{cli-CEfWwCKx.js → cli-o00oTJhx.js} +12 -12
- package/dist/{client-FRuyCNju.js → client-ClHisZbf.js} +2 -2
- package/dist/{client-tgnlQJk4.js → client-DP0nmFxK.js} +4 -4
- package/dist/{client-bootstrap-DjFJ7e0N.js → client-bootstrap-PqYOS-mO.js} +1 -1
- package/dist/{config-schema-DtnhNYd-.js → config-schema-CG9goLWp.js} +21 -55
- package/dist/contract-api.js +2 -2
- package/dist/{create-client-CNakT7zF.js → create-client-D9z9RjCM.js} +3 -3
- package/dist/{credentials-Ds9V1mn2.js → credentials-DnhsLAuR.js} +1 -1
- package/dist/{credentials-read-BlkvsNFg.js → credentials-read-BtS-HRT5.js} +3 -3
- package/dist/{credentials-write.runtime-CTqqxcut.js → credentials-write.runtime-J_EUt5WP.js} +1 -1
- package/dist/{crypto-runtime-B74cTS6A.js → crypto-runtime-BHcxauC4.js} +75 -45
- package/dist/{deps-CdjHvnmh.js → deps-DDbghaZH.js} +23 -90
- package/dist/{directory-live-Ufd4qSpX.js → directory-live-DPy2aaPF.js} +3 -3
- package/dist/doctor-BGTs609f.js +64 -0
- package/dist/{doctor-contract-BAja_fmb.js → doctor-contract-D2qTLe-C.js} +72 -6
- package/dist/doctor-contract-api.js +323 -45
- package/dist/{draft-stream-D4EH25gv.js → draft-stream-De7uikGn.js} +1 -1
- package/dist/{encryption-guidance-D8walY04.js → encryption-guidance-BFfgq7c7.js} +1 -1
- package/dist/{env-auth-DIzOApj0.js → env-auth-CQsYbz-p.js} +1 -1
- package/dist/{env-vars-KzaYveuy.js → env-vars-B0NxQnPk.js} +3 -1
- package/dist/{exec-approval-resolver-f9j6staN.js → exec-approval-resolver-BCgqRtZS.js} +2 -1
- package/dist/{file-sync-store-DVm0ACml.js → file-sync-store-Cxb0ckyX.js} +4 -5
- package/dist/helper-api.js +4 -4
- package/dist/{http-client-nSmFiVgk.js → http-client-W4TJQM6r.js} +17 -33
- package/dist/{idb-persistence-BHm97th-.js → idb-persistence-iUZoHZkp.js} +2 -2
- package/dist/inbound-dedupe-DcMs0YXL.js +67 -0
- package/dist/index.js +1 -1
- package/dist/{logger-D0GCSDQq.js → logger-BMClpI5b.js} +1 -1
- package/dist/{logging-QH-48Gr6.js → logging-CFJrbDAN.js} +1 -1
- package/dist/{media-text-p-LP21qs.js → media-text-DWaotsZB.js} +1 -1
- package/dist/{messages-DRKkiEY-.js → messages-Dm3K4ZvM.js} +3 -3
- package/dist/{monitor-CsGOGdwu.js → monitor-C_kgPPeV.js} +44 -382
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- package/dist/probe.runtime-Dry8PTWC.js +3 -0
- package/dist/{profile-update-Ucc8RrJL.js → profile-update-iUHCoks3.js} +3 -3
- package/dist/{reaction-events-DentrVii.js → reaction-events-0tubdHRM.js} +60 -10
- package/dist/record-shared-CvzjvHRn.js +2 -0
- package/dist/{recovery-key-store-DSeLFvNx.js → recovery-key-store-Bx0zTJcB.js} +2 -2
- package/dist/{resolve-targets-DcV_KfgX.js → resolve-targets-DlLrfWDy.js} +1 -1
- package/dist/{resolver.runtime-Hr6bO5zl.js → resolver.runtime-MeaT1zXx.js} +1 -1
- package/dist/room-info-B6vKD5DF.js +86 -0
- package/dist/{runtime-6S3DNFNv.js → runtime-CveSqMOP.js} +1 -1
- package/dist/{runtime-api-CsBoesCU.js → runtime-api-D1xI_cvh.js} +3 -3
- package/dist/runtime-api.js +6 -6
- package/dist/runtime-setter-api.js +1 -1
- package/dist/{sdk-AZYVl34z.js → sdk-CI8E2TKg.js} +12 -17
- package/dist/{secret-contract-DTgQyQxc.js → secret-contract-OZoQf0kI.js} +7 -48
- package/dist/secret-contract-api.js +1 -1
- package/dist/{send-D92v6Yy0.js → send-C7xuGWpv.js} +10 -4
- package/dist/session-binding-contract-api.js +2 -2
- package/dist/{setup-bootstrap-Da564w5f.js → setup-bootstrap-CCsexWTZ.js} +2 -2
- package/dist/{setup-core-BGgbrdaJ.js → setup-core-DlmTyIP0.js} +9 -7
- package/dist/setup-plugin-api.js +3 -3
- package/dist/{setup-surface-iJ6pd-t5.js → setup-surface-2SS94JV0.js} +7 -7
- package/dist/{shared-DkFfq7mH.js → shared-DgvN5rBx.js} +14 -9
- package/dist/{startup-verification-BKMAXvcV.js → startup-verification-CbIyF7z1.js} +3 -4
- package/dist/storage-BtSOar8T.js +718 -0
- package/dist/{storage-paths-BWo_ZEMC.js → storage-paths-B4_I9iqO.js} +1 -12
- package/dist/{thread-bindings-BX5nmWpw.js → thread-bindings-BI8MHWp9.js} +4 -5
- package/dist/{tool-actions.runtime-C1d5fxE_.js → tool-actions.runtime-CnyhVPoY.js} +242 -53
- package/dist/{verification-BGCMiO1p.js → verification-DLSe3sP7.js} +2 -2
- package/npm-shrinkwrap.json +3 -3
- package/openclaw.plugin.json +66 -55
- package/package.json +4 -4
- package/dist/approval-reactions-BdUaUXVw.js +0 -113
- package/dist/crypto-state-store-Jy3qwhdy.js +0 -352
- package/dist/doctor-DfaOqFtr.js +0 -167
- package/dist/legacy-crypto-inspector-vzXSkm18.js +0 -42
- package/dist/legacy-crypto-restore-CIBfOmLn.js +0 -93
- package/dist/matrix-migration.runtime-BMCyrANT.js +0 -524
- package/dist/migration-snapshot-backup-YcCrSjbE.js +0 -69
- package/dist/migration-snapshot.runtime-VGD4QfeS.js +0 -2
- package/dist/probe.runtime-2MZLc6ng.js +0 -3
- package/dist/runtime-heavy-api.js +0 -3
- package/dist/storage-CQdyKcGg.js +0 -430
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { t as ensureMatrixCryptoRuntime } from "./deps-CdjHvnmh.js";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import crypto from "node:crypto";
|
|
6
|
-
//#region extensions/matrix/src/matrix/legacy-crypto-inspector.ts
|
|
7
|
-
const MATRIX_CRYPTO_STORE_SQLITE = 0;
|
|
8
|
-
function resolveLegacyMachineStorePath(params) {
|
|
9
|
-
const hashedDir = path.join(params.cryptoRootDir, crypto.createHash("sha256").update(params.deviceId).digest("hex"));
|
|
10
|
-
if (fs.existsSync(path.join(hashedDir, "matrix-sdk-crypto.sqlite3"))) return hashedDir;
|
|
11
|
-
if (fs.existsSync(path.join(params.cryptoRootDir, "matrix-sdk-crypto.sqlite3"))) return params.cryptoRootDir;
|
|
12
|
-
const match = fs.readdirSync(params.cryptoRootDir, { withFileTypes: true }).find((entry) => entry.isDirectory() && fs.existsSync(path.join(params.cryptoRootDir, entry.name, "matrix-sdk-crypto.sqlite3")));
|
|
13
|
-
return match ? path.join(params.cryptoRootDir, match.name) : null;
|
|
14
|
-
}
|
|
15
|
-
async function inspectLegacyMatrixCryptoStore(params) {
|
|
16
|
-
const machineStorePath = resolveLegacyMachineStorePath(params);
|
|
17
|
-
if (!machineStorePath) throw new Error(`Matrix legacy crypto store not found for device ${params.deviceId}`);
|
|
18
|
-
const requireFn = createRequire(import.meta.url);
|
|
19
|
-
await ensureMatrixCryptoRuntime({
|
|
20
|
-
requireFn,
|
|
21
|
-
resolveFn: requireFn.resolve.bind(requireFn),
|
|
22
|
-
log: params.log
|
|
23
|
-
});
|
|
24
|
-
const { DeviceId, OlmMachine, UserId } = requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
25
|
-
const machine = await OlmMachine.initialize(new UserId(params.userId), new DeviceId(params.deviceId), machineStorePath, "", MATRIX_CRYPTO_STORE_SQLITE);
|
|
26
|
-
try {
|
|
27
|
-
const [backupKeys, roomKeyCounts] = await Promise.all([machine.getBackupKeys(), machine.roomKeyCounts()]);
|
|
28
|
-
return {
|
|
29
|
-
deviceId: params.deviceId,
|
|
30
|
-
roomKeyCounts: roomKeyCounts ? {
|
|
31
|
-
total: typeof roomKeyCounts.total === "number" ? roomKeyCounts.total : 0,
|
|
32
|
-
backedUp: typeof roomKeyCounts.backedUp === "number" ? roomKeyCounts.backedUp : 0
|
|
33
|
-
} : null,
|
|
34
|
-
backupVersion: typeof backupKeys?.backupVersion === "string" && backupKeys.backupVersion.trim() ? backupKeys.backupVersion : null,
|
|
35
|
-
decryptionKeyBase64: typeof backupKeys?.decryptionKeyBase64 === "string" && backupKeys.decryptionKeyBase64.trim() ? backupKeys.decryptionKeyBase64 : null
|
|
36
|
-
};
|
|
37
|
-
} finally {
|
|
38
|
-
machine.close();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
export { inspectLegacyMatrixCryptoStore };
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
|
|
2
|
-
import { C as writeMatrixLegacyCryptoMigrationState, _ as readMatrixLegacyCryptoMigrationState, s as migrateLegacyMatrixLegacyCryptoMigrationFileToStore } from "./crypto-state-store-Jy3qwhdy.js";
|
|
3
|
-
import { l as resolveMatrixStoragePaths } from "./storage-CQdyKcGg.js";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import fs from "node:fs/promises";
|
|
7
|
-
//#region extensions/matrix/src/matrix/monitor/legacy-crypto-restore.ts
|
|
8
|
-
async function resolvePendingMigrationStateRoot(params) {
|
|
9
|
-
const { rootDir } = resolveMatrixStoragePaths({
|
|
10
|
-
homeserver: params.auth.homeserver,
|
|
11
|
-
userId: params.auth.userId,
|
|
12
|
-
accessToken: params.auth.accessToken,
|
|
13
|
-
accountId: params.auth.accountId,
|
|
14
|
-
deviceId: params.auth.deviceId,
|
|
15
|
-
stateDir: params.stateDir
|
|
16
|
-
});
|
|
17
|
-
try {
|
|
18
|
-
migrateLegacyMatrixLegacyCryptoMigrationFileToStore(rootDir);
|
|
19
|
-
} catch {}
|
|
20
|
-
const directValue = readMatrixLegacyCryptoMigrationState(rootDir);
|
|
21
|
-
if (directValue?.restoreStatus === "pending") return {
|
|
22
|
-
storageRootDir: rootDir,
|
|
23
|
-
value: directValue
|
|
24
|
-
};
|
|
25
|
-
const accountStorageDir = path.dirname(rootDir);
|
|
26
|
-
let siblingEntries;
|
|
27
|
-
try {
|
|
28
|
-
siblingEntries = (await fs.readdir(accountStorageDir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).filter((entry) => path.join(accountStorageDir, entry) !== rootDir).toSorted((left, right) => left.localeCompare(right));
|
|
29
|
-
} catch {
|
|
30
|
-
return {
|
|
31
|
-
storageRootDir: rootDir,
|
|
32
|
-
value: directValue
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
for (const sibling of siblingEntries) {
|
|
36
|
-
const siblingRootDir = path.join(accountStorageDir, sibling);
|
|
37
|
-
try {
|
|
38
|
-
migrateLegacyMatrixLegacyCryptoMigrationFileToStore(siblingRootDir);
|
|
39
|
-
} catch {}
|
|
40
|
-
const value = readMatrixLegacyCryptoMigrationState(siblingRootDir);
|
|
41
|
-
if (value?.restoreStatus === "pending") return {
|
|
42
|
-
storageRootDir: siblingRootDir,
|
|
43
|
-
value
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
storageRootDir: rootDir,
|
|
48
|
-
value: directValue
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
async function maybeRestoreLegacyMatrixBackup(params) {
|
|
52
|
-
const env = params.env ?? process.env;
|
|
53
|
-
const { storageRootDir, value } = await resolvePendingMigrationStateRoot({
|
|
54
|
-
stateDir: params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir),
|
|
55
|
-
auth: params.auth
|
|
56
|
-
});
|
|
57
|
-
if (value?.restoreStatus !== "pending") return { kind: "skipped" };
|
|
58
|
-
const restore = await params.client.restoreRoomKeyBackup();
|
|
59
|
-
const localOnlyKeys = value.roomKeyCounts && value.roomKeyCounts.total > value.roomKeyCounts.backedUp ? value.roomKeyCounts.total - value.roomKeyCounts.backedUp : 0;
|
|
60
|
-
if (restore.success) {
|
|
61
|
-
writeMatrixLegacyCryptoMigrationState({
|
|
62
|
-
storageRootDir,
|
|
63
|
-
state: {
|
|
64
|
-
...value,
|
|
65
|
-
restoreStatus: "completed",
|
|
66
|
-
restoredAt: restore.restoredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
67
|
-
importedCount: restore.imported,
|
|
68
|
-
totalCount: restore.total,
|
|
69
|
-
lastError: null
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
kind: "restored",
|
|
74
|
-
imported: restore.imported,
|
|
75
|
-
total: restore.total,
|
|
76
|
-
localOnlyKeys
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
writeMatrixLegacyCryptoMigrationState({
|
|
80
|
-
storageRootDir,
|
|
81
|
-
state: {
|
|
82
|
-
...value,
|
|
83
|
-
lastError: restore.error ?? "unknown"
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return {
|
|
87
|
-
kind: "failed",
|
|
88
|
-
error: restore.error ?? "unknown",
|
|
89
|
-
localOnlyKeys
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
export { maybeRestoreLegacyMatrixBackup };
|
|
@@ -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 };
|