@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,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,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 };
|
package/dist/storage-CQdyKcGg.js
DELETED
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount, o as isRecord } from "./account-selection-5e4mHR1m.js";
|
|
2
|
-
import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
|
|
3
|
-
import { n as resolveMatrixAccountStorageRoot, s as resolveMatrixLegacyFlatStoragePaths } from "./storage-paths-BWo_ZEMC.js";
|
|
4
|
-
import { O as resolveMatrixSqliteStateEnv, b as scoreMatrixCryptoStateInStore, g as readMatrixIdbSnapshotJson, l as migrateLegacyMatrixRecoveryKeyFileToStore, n as MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, r as MATRIX_RECOVERY_KEY_FILENAME, s as migrateLegacyMatrixLegacyCryptoMigrationFileToStore, t as MATRIX_IDB_SNAPSHOT_FILENAME, x as writeMatrixIdbSnapshotJson } from "./crypto-state-store-Jy3qwhdy.js";
|
|
5
|
-
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import os from "node:os";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
|
|
10
|
-
//#region extensions/matrix/src/matrix/client/storage.ts
|
|
11
|
-
const DEFAULT_ACCOUNT_KEY = "default";
|
|
12
|
-
const STORAGE_META_FILENAME = "storage-meta.json";
|
|
13
|
-
const THREAD_BINDINGS_FILENAME = "thread-bindings.json";
|
|
14
|
-
const STORAGE_META_NAMESPACE = "storage-meta";
|
|
15
|
-
const STORAGE_META_STATE_KEY = "current";
|
|
16
|
-
const STORAGE_META_MAX_ENTRIES = 10;
|
|
17
|
-
function openMatrixStorageMetaStoreOptions(storageRootDir) {
|
|
18
|
-
return {
|
|
19
|
-
namespace: STORAGE_META_NAMESPACE,
|
|
20
|
-
maxEntries: STORAGE_META_MAX_ENTRIES,
|
|
21
|
-
env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function openStorageMetaStore(rootDir) {
|
|
25
|
-
return getMatrixRuntime().state.openSyncKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
|
|
26
|
-
}
|
|
27
|
-
function resolveLegacyStoragePaths(env = process.env) {
|
|
28
|
-
return resolveMatrixLegacyFlatStoragePaths(getMatrixRuntime().state.resolveStateDir(env, os.homedir));
|
|
29
|
-
}
|
|
30
|
-
function assertLegacyMigrationAccountSelection(params) {
|
|
31
|
-
const cfg = getMatrixRuntime().config.current();
|
|
32
|
-
if (!cfg.channels?.matrix || typeof cfg.channels.matrix !== "object") return;
|
|
33
|
-
if (requiresExplicitMatrixDefaultAccount(cfg)) throw new Error("Legacy Matrix client storage cannot be migrated automatically because multiple Matrix accounts are configured and channels.matrix.defaultAccount is not set.");
|
|
34
|
-
const selectedAccountId = normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(cfg));
|
|
35
|
-
const currentAccountId = normalizeAccountId(params.accountKey);
|
|
36
|
-
if (selectedAccountId !== currentAccountId) throw new Error(`Legacy Matrix client storage targets account "${selectedAccountId}", but the current client is starting account "${currentAccountId}". Start the selected account first so flat legacy storage is not migrated into the wrong account directory.`);
|
|
37
|
-
}
|
|
38
|
-
function scoreStorageRoot(rootDir) {
|
|
39
|
-
let score = 0;
|
|
40
|
-
const metadata = readStoredRootMetadata(rootDir);
|
|
41
|
-
if (Object.keys(metadata).length > 0) score += 1;
|
|
42
|
-
if (metadata.currentTokenStateClaimed === true) score += 8;
|
|
43
|
-
if (fs.existsSync(path.join(rootDir, "crypto"))) score += 8;
|
|
44
|
-
if (fs.existsSync(path.join(rootDir, THREAD_BINDINGS_FILENAME))) score += 4;
|
|
45
|
-
if (fs.existsSync(path.join(rootDir, "legacy-crypto-migration.json"))) score += 3;
|
|
46
|
-
if (fs.existsSync(path.join(rootDir, "recovery-key.json"))) score += 2;
|
|
47
|
-
if (fs.existsSync(path.join(rootDir, "crypto-idb-snapshot.json"))) score += 2;
|
|
48
|
-
score += scoreMatrixCryptoStateInStore(rootDir);
|
|
49
|
-
return score;
|
|
50
|
-
}
|
|
51
|
-
function resolveStorageRootMtimeMs(rootDir) {
|
|
52
|
-
try {
|
|
53
|
-
return fs.statSync(rootDir).mtimeMs;
|
|
54
|
-
} catch {
|
|
55
|
-
return 0;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function normalizeMatrixStorageMetadata(value) {
|
|
59
|
-
if (!isRecord(value)) return null;
|
|
60
|
-
const metadata = {};
|
|
61
|
-
if (typeof value.homeserver === "string" && value.homeserver.trim()) metadata.homeserver = value.homeserver.trim();
|
|
62
|
-
if (typeof value.userId === "string" && value.userId.trim()) metadata.userId = value.userId.trim();
|
|
63
|
-
if (typeof value.accountId === "string" && value.accountId.trim()) metadata.accountId = value.accountId.trim();
|
|
64
|
-
if (typeof value.accessTokenHash === "string" && value.accessTokenHash.trim()) metadata.accessTokenHash = value.accessTokenHash.trim();
|
|
65
|
-
if (typeof value.deviceId === "string" && value.deviceId.trim()) metadata.deviceId = value.deviceId.trim();
|
|
66
|
-
if (value.currentTokenStateClaimed === true) metadata.currentTokenStateClaimed = true;
|
|
67
|
-
if (typeof value.createdAt === "string" && value.createdAt.trim()) metadata.createdAt = value.createdAt.trim();
|
|
68
|
-
return Object.keys(metadata).length > 0 ? metadata : null;
|
|
69
|
-
}
|
|
70
|
-
async function hasMatrixStorageMetaStateInStore(params) {
|
|
71
|
-
return normalizeMatrixStorageMetadata(await params.store.lookup(STORAGE_META_STATE_KEY)) !== null;
|
|
72
|
-
}
|
|
73
|
-
async function writeMatrixStorageMetaStateToStore(params) {
|
|
74
|
-
await params.store.register(STORAGE_META_STATE_KEY, params.payload);
|
|
75
|
-
}
|
|
76
|
-
function readStoredRootMetadata(rootDir) {
|
|
77
|
-
if (fs.existsSync(path.join(rootDir, "state", "openclaw.sqlite"))) try {
|
|
78
|
-
const stored = normalizeMatrixStorageMetadata(openStorageMetaStore(rootDir).lookup(STORAGE_META_STATE_KEY));
|
|
79
|
-
if (stored) return stored;
|
|
80
|
-
} catch {}
|
|
81
|
-
return normalizeMatrixStorageMetadata(loadJsonFile(path.join(rootDir, STORAGE_META_FILENAME))) ?? {};
|
|
82
|
-
}
|
|
83
|
-
function isCompatibleStorageRoot(params) {
|
|
84
|
-
const metadata = readStoredRootMetadata(params.candidateRootDir);
|
|
85
|
-
if (metadata.homeserver && metadata.homeserver !== params.homeserver) return false;
|
|
86
|
-
if (metadata.userId && metadata.userId !== params.userId) return false;
|
|
87
|
-
if (metadata.accountId && normalizeAccountId(metadata.accountId) !== normalizeAccountId(params.accountKey)) return false;
|
|
88
|
-
if (params.deviceId && metadata.deviceId && metadata.deviceId.trim() && metadata.deviceId.trim() !== params.deviceId.trim()) return false;
|
|
89
|
-
if (params.requireExplicitDeviceMatch && params.deviceId && (!metadata.deviceId || metadata.deviceId.trim() !== params.deviceId.trim())) return false;
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
function resolvePreferredMatrixStorageRoot(params) {
|
|
93
|
-
const parentDir = path.dirname(params.canonicalRootDir);
|
|
94
|
-
const bestCurrentScore = scoreStorageRoot(params.canonicalRootDir);
|
|
95
|
-
const bestCurrentMtimeMs = resolveStorageRootMtimeMs(params.canonicalRootDir);
|
|
96
|
-
let best = {
|
|
97
|
-
rootDir: params.canonicalRootDir,
|
|
98
|
-
tokenHash: params.canonicalTokenHash,
|
|
99
|
-
score: bestCurrentScore,
|
|
100
|
-
mtimeMs: bestCurrentMtimeMs
|
|
101
|
-
};
|
|
102
|
-
if (!params.deviceId?.trim()) return {
|
|
103
|
-
rootDir: best.rootDir,
|
|
104
|
-
tokenHash: best.tokenHash
|
|
105
|
-
};
|
|
106
|
-
let siblingEntries;
|
|
107
|
-
try {
|
|
108
|
-
siblingEntries = fs.readdirSync(parentDir, { withFileTypes: true });
|
|
109
|
-
} catch {
|
|
110
|
-
return {
|
|
111
|
-
rootDir: best.rootDir,
|
|
112
|
-
tokenHash: best.tokenHash
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
const compatiblePopulatedSiblings = [];
|
|
116
|
-
const populatedTokenHashes = bestCurrentScore > 0 ? [params.canonicalTokenHash] : [];
|
|
117
|
-
for (const entry of siblingEntries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
118
|
-
if (!entry.isDirectory()) continue;
|
|
119
|
-
if (entry.name === params.canonicalTokenHash) continue;
|
|
120
|
-
const candidateRootDir = path.join(parentDir, entry.name);
|
|
121
|
-
if (!isCompatibleStorageRoot({
|
|
122
|
-
candidateRootDir,
|
|
123
|
-
homeserver: params.homeserver,
|
|
124
|
-
userId: params.userId,
|
|
125
|
-
accountKey: params.accountKey,
|
|
126
|
-
deviceId: params.deviceId,
|
|
127
|
-
requireExplicitDeviceMatch: Boolean(params.deviceId)
|
|
128
|
-
})) continue;
|
|
129
|
-
const candidateScore = scoreStorageRoot(candidateRootDir);
|
|
130
|
-
if (candidateScore <= 0) continue;
|
|
131
|
-
populatedTokenHashes.push(entry.name);
|
|
132
|
-
compatiblePopulatedSiblings.push({
|
|
133
|
-
rootDir: candidateRootDir,
|
|
134
|
-
tokenHash: entry.name,
|
|
135
|
-
score: candidateScore,
|
|
136
|
-
mtimeMs: resolveStorageRootMtimeMs(candidateRootDir)
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
const canonicalMetadata = readStoredRootMetadata(params.canonicalRootDir);
|
|
140
|
-
if (!(canonicalMetadata.accessTokenHash === params.canonicalTokenHash && canonicalMetadata.deviceId?.trim() === params.deviceId.trim() && canonicalMetadata.currentTokenStateClaimed === true)) {
|
|
141
|
-
for (const candidate of compatiblePopulatedSiblings) if (candidate.score > best.score || best.rootDir !== params.canonicalRootDir && candidate.score === best.score && candidate.mtimeMs > best.mtimeMs) best = {
|
|
142
|
-
rootDir: candidate.rootDir,
|
|
143
|
-
tokenHash: candidate.tokenHash,
|
|
144
|
-
score: candidate.score,
|
|
145
|
-
mtimeMs: candidate.mtimeMs
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
if (populatedTokenHashes.length > 1) getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" }).warn("matrix: multiple populated token-hash storage roots detected", {
|
|
149
|
-
parentDir,
|
|
150
|
-
canonicalTokenHash: params.canonicalTokenHash,
|
|
151
|
-
selectedTokenHash: best.tokenHash,
|
|
152
|
-
populatedTokenHashes,
|
|
153
|
-
populatedSiblingTokenHashes: compatiblePopulatedSiblings.map((root) => root.tokenHash),
|
|
154
|
-
populatedRootCount: populatedTokenHashes.length
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
rootDir: best.rootDir,
|
|
158
|
-
tokenHash: best.tokenHash
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function resolveMatrixStoragePaths(params) {
|
|
162
|
-
const env = params.env ?? process.env;
|
|
163
|
-
const canonical = resolveMatrixAccountStorageRoot({
|
|
164
|
-
stateDir: params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir),
|
|
165
|
-
homeserver: params.homeserver,
|
|
166
|
-
userId: params.userId,
|
|
167
|
-
accessToken: params.accessToken,
|
|
168
|
-
accountId: params.accountId
|
|
169
|
-
});
|
|
170
|
-
const { rootDir, tokenHash } = resolvePreferredMatrixStorageRoot({
|
|
171
|
-
canonicalRootDir: canonical.rootDir,
|
|
172
|
-
canonicalTokenHash: canonical.tokenHash,
|
|
173
|
-
homeserver: params.homeserver,
|
|
174
|
-
userId: params.userId,
|
|
175
|
-
accountKey: canonical.accountKey,
|
|
176
|
-
deviceId: params.deviceId
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
rootDir,
|
|
180
|
-
storagePath: path.join(rootDir, "bot-storage.json"),
|
|
181
|
-
cryptoPath: path.join(rootDir, "crypto"),
|
|
182
|
-
recoveryKeyPath: path.join(rootDir, MATRIX_RECOVERY_KEY_FILENAME),
|
|
183
|
-
idbSnapshotPath: path.join(rootDir, MATRIX_IDB_SNAPSHOT_FILENAME),
|
|
184
|
-
accountKey: canonical.accountKey,
|
|
185
|
-
tokenHash
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function resolveMatrixStateFilePath(params) {
|
|
189
|
-
const storagePaths = resolveMatrixStoragePaths({
|
|
190
|
-
homeserver: params.auth.homeserver,
|
|
191
|
-
userId: params.auth.userId,
|
|
192
|
-
accessToken: params.auth.accessToken,
|
|
193
|
-
accountId: params.accountId ?? params.auth.accountId,
|
|
194
|
-
deviceId: params.auth.deviceId,
|
|
195
|
-
env: params.env,
|
|
196
|
-
stateDir: params.stateDir
|
|
197
|
-
});
|
|
198
|
-
return path.join(storagePaths.rootDir, params.filename);
|
|
199
|
-
}
|
|
200
|
-
async function maybeMigrateLegacyStorage(params) {
|
|
201
|
-
const legacy = resolveLegacyStoragePaths(params.env);
|
|
202
|
-
const hasFlatLegacyStorageFile = fs.existsSync(legacy.storagePath);
|
|
203
|
-
const hasAccountScopedLegacyStorageFile = fs.existsSync(params.storagePaths.storagePath);
|
|
204
|
-
const syncCache = hasFlatLegacyStorageFile || hasAccountScopedLegacyStorageFile ? await import("./file-sync-store-DVm0ACml.js").then((n) => n.n) : null;
|
|
205
|
-
const hasFlatLegacyStorage = hasFlatLegacyStorageFile && await syncCache?.readLegacyMatrixSyncCacheState(legacy.rootDir) !== null;
|
|
206
|
-
const hasAccountScopedLegacyStorage = hasAccountScopedLegacyStorageFile && await syncCache?.readLegacyMatrixSyncCacheState(params.storagePaths.rootDir) !== null;
|
|
207
|
-
const hasLegacyCrypto = fs.existsSync(legacy.cryptoPath);
|
|
208
|
-
const hasAccountScopedRecoveryKey = fs.existsSync(params.storagePaths.recoveryKeyPath);
|
|
209
|
-
const hasAccountScopedIdbSnapshot = fs.existsSync(params.storagePaths.idbSnapshotPath);
|
|
210
|
-
const hasAccountScopedLegacyCryptoMigration = fs.existsSync(path.join(params.storagePaths.rootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME));
|
|
211
|
-
if (!hasFlatLegacyStorage && !hasAccountScopedLegacyStorage && !hasLegacyCrypto && !hasAccountScopedRecoveryKey && !hasAccountScopedIdbSnapshot && !hasAccountScopedLegacyCryptoMigration) return;
|
|
212
|
-
const hasTargetCrypto = fs.existsSync(params.storagePaths.cryptoPath);
|
|
213
|
-
const shouldMigrateCrypto = hasLegacyCrypto && !hasTargetCrypto;
|
|
214
|
-
if (!hasFlatLegacyStorage && !hasAccountScopedLegacyStorage && !shouldMigrateCrypto && !hasAccountScopedRecoveryKey && !hasAccountScopedIdbSnapshot && !hasAccountScopedLegacyCryptoMigration) return;
|
|
215
|
-
if (hasFlatLegacyStorage || hasLegacyCrypto) assertLegacyMigrationAccountSelection({ accountKey: params.storagePaths.accountKey });
|
|
216
|
-
const logger = getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" });
|
|
217
|
-
const { maybeCreateMatrixMigrationSnapshot } = await import("./migration-snapshot.runtime-VGD4QfeS.js");
|
|
218
|
-
await maybeCreateMatrixMigrationSnapshot({
|
|
219
|
-
trigger: "matrix-client-fallback",
|
|
220
|
-
env: params.env,
|
|
221
|
-
log: logger
|
|
222
|
-
});
|
|
223
|
-
fs.mkdirSync(params.storagePaths.rootDir, { recursive: true });
|
|
224
|
-
const moved = [];
|
|
225
|
-
const pendingArchives = [];
|
|
226
|
-
const skippedExistingTargets = [];
|
|
227
|
-
try {
|
|
228
|
-
if (hasAccountScopedLegacyStorage) await migrateLegacySyncCacheToSqlite({
|
|
229
|
-
sourceRootDir: params.storagePaths.rootDir,
|
|
230
|
-
sourcePath: params.storagePaths.storagePath,
|
|
231
|
-
targetRootDir: params.storagePaths.rootDir,
|
|
232
|
-
label: "account sync cache",
|
|
233
|
-
moved,
|
|
234
|
-
pendingArchives
|
|
235
|
-
});
|
|
236
|
-
if (hasFlatLegacyStorage) await migrateLegacySyncCacheToSqlite({
|
|
237
|
-
sourceRootDir: legacy.rootDir,
|
|
238
|
-
sourcePath: legacy.storagePath,
|
|
239
|
-
targetRootDir: params.storagePaths.rootDir,
|
|
240
|
-
label: "flat sync cache",
|
|
241
|
-
moved,
|
|
242
|
-
pendingArchives
|
|
243
|
-
});
|
|
244
|
-
if (shouldMigrateCrypto) moveLegacyStoragePathOrThrow({
|
|
245
|
-
sourcePath: legacy.cryptoPath,
|
|
246
|
-
targetPath: params.storagePaths.cryptoPath,
|
|
247
|
-
label: "crypto store",
|
|
248
|
-
moved
|
|
249
|
-
});
|
|
250
|
-
else if (hasLegacyCrypto) skippedExistingTargets.push(`- crypto store remains at ${legacy.cryptoPath} because ${params.storagePaths.cryptoPath} already exists`);
|
|
251
|
-
if (hasAccountScopedRecoveryKey) {
|
|
252
|
-
migrateLegacyMatrixRecoveryKeyFileToStore(params.storagePaths.rootDir);
|
|
253
|
-
moved.push({
|
|
254
|
-
sourcePath: params.storagePaths.recoveryKeyPath,
|
|
255
|
-
targetPath: `${params.storagePaths.rootDir} SQLite recovery key state`,
|
|
256
|
-
label: "recovery key"
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
if (hasAccountScopedLegacyCryptoMigration) {
|
|
260
|
-
migrateLegacyMatrixLegacyCryptoMigrationFileToStore(params.storagePaths.rootDir);
|
|
261
|
-
moved.push({
|
|
262
|
-
sourcePath: path.join(params.storagePaths.rootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME),
|
|
263
|
-
targetPath: `${params.storagePaths.rootDir} SQLite legacy crypto migration state`,
|
|
264
|
-
label: "legacy crypto migration"
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
if (hasAccountScopedIdbSnapshot) await migrateLegacyIdbSnapshotToSqlite({
|
|
268
|
-
storageRootDir: params.storagePaths.rootDir,
|
|
269
|
-
snapshotPath: params.storagePaths.idbSnapshotPath,
|
|
270
|
-
moved,
|
|
271
|
-
pendingArchives
|
|
272
|
-
});
|
|
273
|
-
} catch (err) {
|
|
274
|
-
const rollbackError = rollbackLegacyMoves(moved);
|
|
275
|
-
throw new Error(rollbackError ? `Failed migrating legacy Matrix client storage: ${String(err)}. Rollback also failed: ${rollbackError}` : `Failed migrating legacy Matrix client storage: ${String(err)}`, { cause: err });
|
|
276
|
-
}
|
|
277
|
-
for (const archive of pendingArchives) archiveLegacyStoragePath({
|
|
278
|
-
...archive,
|
|
279
|
-
skippedExistingTargets
|
|
280
|
-
});
|
|
281
|
-
if (moved.length > 0) logger.info(`matrix: migrated legacy client storage into ${params.storagePaths.rootDir}\n${moved.map((entry) => `- ${entry.label}: ${entry.sourcePath} -> ${entry.targetPath}`).join("\n")}`);
|
|
282
|
-
if (skippedExistingTargets.length > 0) logger.warn?.(`matrix: legacy client storage still exists in the flat path because some account-scoped targets already existed.\n${skippedExistingTargets.join("\n")}`);
|
|
283
|
-
}
|
|
284
|
-
async function migrateLegacyIdbSnapshotToSqlite(params) {
|
|
285
|
-
if (readMatrixIdbSnapshotJson(params.storageRootDir)) {
|
|
286
|
-
params.pendingArchives.push({
|
|
287
|
-
sourcePath: params.snapshotPath,
|
|
288
|
-
label: "IndexedDB snapshot"
|
|
289
|
-
});
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const { readLegacyMatrixIdbSnapshotState } = await import("./idb-persistence-BHm97th-.js").then((n) => n.t);
|
|
293
|
-
const snapshot = await readLegacyMatrixIdbSnapshotState(params.storageRootDir);
|
|
294
|
-
if (!snapshot) return;
|
|
295
|
-
writeMatrixIdbSnapshotJson({
|
|
296
|
-
storageRootDir: params.storageRootDir,
|
|
297
|
-
snapshotJson: JSON.stringify(snapshot),
|
|
298
|
-
databaseCount: snapshot.length
|
|
299
|
-
});
|
|
300
|
-
params.moved.push({
|
|
301
|
-
sourcePath: params.snapshotPath,
|
|
302
|
-
targetPath: `${params.storageRootDir} SQLite IndexedDB snapshot state`,
|
|
303
|
-
label: "IndexedDB snapshot"
|
|
304
|
-
});
|
|
305
|
-
params.pendingArchives.push({
|
|
306
|
-
sourcePath: params.snapshotPath,
|
|
307
|
-
label: "IndexedDB snapshot"
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
async function migrateLegacySyncCacheToSqlite(params) {
|
|
311
|
-
const syncCache = await import("./file-sync-store-DVm0ACml.js").then((n) => n.n);
|
|
312
|
-
const persisted = await syncCache.readLegacyMatrixSyncCacheState(params.sourceRootDir);
|
|
313
|
-
if (!persisted) return;
|
|
314
|
-
const store = getMatrixRuntime().state.openKeyedStore(syncCache.openMatrixSyncCacheStoreOptions(params.targetRootDir));
|
|
315
|
-
if (!await syncCache.hasMatrixSyncCacheStateInStore({
|
|
316
|
-
storageRootDir: params.targetRootDir,
|
|
317
|
-
store
|
|
318
|
-
})) {
|
|
319
|
-
await syncCache.writeMatrixSyncCacheStateToStore({
|
|
320
|
-
storageRootDir: params.targetRootDir,
|
|
321
|
-
payload: persisted,
|
|
322
|
-
store
|
|
323
|
-
});
|
|
324
|
-
claimCurrentTokenStorageState({ rootDir: params.targetRootDir });
|
|
325
|
-
params.moved.push({
|
|
326
|
-
sourcePath: params.sourcePath,
|
|
327
|
-
targetPath: `${params.targetRootDir} SQLite sync cache`,
|
|
328
|
-
label: params.label
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
params.pendingArchives.push({
|
|
332
|
-
sourcePath: params.sourcePath,
|
|
333
|
-
label: params.label
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
function archiveLegacyStoragePath(params) {
|
|
337
|
-
const archivedLegacyStoragePath = `${params.sourcePath}.migrated`;
|
|
338
|
-
if (fs.existsSync(archivedLegacyStoragePath)) {
|
|
339
|
-
params.skippedExistingTargets.push(`- ${params.label} remains at ${params.sourcePath} because ${archivedLegacyStoragePath} already exists`);
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
fs.renameSync(params.sourcePath, archivedLegacyStoragePath);
|
|
343
|
-
}
|
|
344
|
-
function moveLegacyStoragePathOrThrow(params) {
|
|
345
|
-
if (!fs.existsSync(params.sourcePath)) return;
|
|
346
|
-
if (fs.existsSync(params.targetPath)) throw new Error(`legacy Matrix ${params.label} target already exists (${params.targetPath}); refusing to overwrite it automatically`);
|
|
347
|
-
fs.renameSync(params.sourcePath, params.targetPath);
|
|
348
|
-
params.moved.push({
|
|
349
|
-
sourcePath: params.sourcePath,
|
|
350
|
-
targetPath: params.targetPath,
|
|
351
|
-
label: params.label
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
function rollbackLegacyMoves(moved) {
|
|
355
|
-
for (const entry of moved.toReversed()) try {
|
|
356
|
-
if (!fs.existsSync(entry.targetPath) || fs.existsSync(entry.sourcePath)) continue;
|
|
357
|
-
fs.renameSync(entry.targetPath, entry.sourcePath);
|
|
358
|
-
} catch (err) {
|
|
359
|
-
return `${entry.label} (${entry.targetPath} -> ${entry.sourcePath}): ${String(err)}`;
|
|
360
|
-
}
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
function writeStoredRootMetadata(rootDir, payload) {
|
|
364
|
-
try {
|
|
365
|
-
const normalized = normalizeMatrixStorageMetadata(payload);
|
|
366
|
-
if (!normalized) return false;
|
|
367
|
-
openStorageMetaStore(rootDir).register(STORAGE_META_STATE_KEY, normalized);
|
|
368
|
-
return true;
|
|
369
|
-
} catch {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function writeStorageMeta(params) {
|
|
374
|
-
const existing = readStoredRootMetadata(params.storagePaths.rootDir);
|
|
375
|
-
return writeStoredRootMetadata(params.storagePaths.rootDir, {
|
|
376
|
-
homeserver: params.homeserver,
|
|
377
|
-
userId: params.userId,
|
|
378
|
-
accountId: params.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
379
|
-
accessTokenHash: params.storagePaths.tokenHash,
|
|
380
|
-
deviceId: params.deviceId ?? null,
|
|
381
|
-
currentTokenStateClaimed: params.currentTokenStateClaimed ?? existing.currentTokenStateClaimed === true,
|
|
382
|
-
createdAt: existing.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
function claimCurrentTokenStorageState(params) {
|
|
386
|
-
const metadata = readStoredRootMetadata(params.rootDir);
|
|
387
|
-
if (!metadata.accessTokenHash?.trim()) return false;
|
|
388
|
-
return writeStoredRootMetadata(params.rootDir, {
|
|
389
|
-
homeserver: metadata.homeserver,
|
|
390
|
-
userId: metadata.userId,
|
|
391
|
-
accountId: metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
392
|
-
accessTokenHash: metadata.accessTokenHash,
|
|
393
|
-
deviceId: metadata.deviceId ?? null,
|
|
394
|
-
currentTokenStateClaimed: true,
|
|
395
|
-
createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
function recordCurrentStorageMetaDeviceId(params) {
|
|
399
|
-
const deviceId = params.deviceId.trim();
|
|
400
|
-
if (!deviceId) return false;
|
|
401
|
-
const metadata = readStoredRootMetadata(params.rootDir);
|
|
402
|
-
if (!metadata.accessTokenHash?.trim()) return false;
|
|
403
|
-
return writeStoredRootMetadata(params.rootDir, {
|
|
404
|
-
homeserver: metadata.homeserver,
|
|
405
|
-
userId: metadata.userId,
|
|
406
|
-
accountId: metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
407
|
-
accessTokenHash: metadata.accessTokenHash,
|
|
408
|
-
deviceId,
|
|
409
|
-
currentTokenStateClaimed: metadata.currentTokenStateClaimed === true,
|
|
410
|
-
createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
function repairCurrentTokenStorageMetaDeviceId(params) {
|
|
414
|
-
return writeStorageMeta({
|
|
415
|
-
storagePaths: resolveMatrixStoragePaths({
|
|
416
|
-
homeserver: params.homeserver,
|
|
417
|
-
userId: params.userId,
|
|
418
|
-
accessToken: params.accessToken,
|
|
419
|
-
accountId: params.accountId,
|
|
420
|
-
env: params.env,
|
|
421
|
-
stateDir: params.stateDir
|
|
422
|
-
}),
|
|
423
|
-
homeserver: params.homeserver,
|
|
424
|
-
userId: params.userId,
|
|
425
|
-
accountId: params.accountId,
|
|
426
|
-
deviceId: params.deviceId
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
//#endregion
|
|
430
|
-
export { openMatrixStorageMetaStoreOptions as a, resolveMatrixStateFilePath as c, writeStorageMeta as d, normalizeMatrixStorageMetadata as i, resolveMatrixStoragePaths as l, hasMatrixStorageMetaStateInStore as n, recordCurrentStorageMetaDeviceId as o, maybeMigrateLegacyStorage as r, repairCurrentTokenStorageMetaDeviceId as s, claimCurrentTokenStorageState as t, writeMatrixStorageMetaStateToStore as u };
|