@openclaw/matrix 2026.9.1 → 2026.9.3
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-DA-jfx22.js → account-selection-Bbtc483D.js} +9 -1
- package/dist/{accounts-DR1c4xF_.js → accounts-GwSAk9vY.js} +2 -2
- package/dist/api.js +6 -6
- package/dist/{approval-handler.runtime-B_6ytY5I.js → approval-handler.runtime-tJLn5JFB.js} +6 -6
- package/dist/{approval-ids-CfHtZ9d1.js → approval-ids-DJZ9ZTuS.js} +1 -1
- package/dist/{approval-reaction-auth-BpDvJqfy.js → approval-reaction-auth-Cd0sKHFc.js} +2 -2
- package/dist/{channel-b-jES-oi.js → channel-BpYiqmx-.js} +10 -39
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.runtime-BkqjwEDU.js → channel.runtime-dfEvRdLQ.js} +6 -11
- package/dist/{channel.setup-BY42QaL7.js → channel.setup-oxd8RsIr.js} +7 -4
- package/dist/{cli-CtYeU7ol.js → cli-_49Vsqs4.js} +149 -115
- package/dist/{cli-metadata-B7MQjR5S.js → cli-metadata-D19lmKmz.js} +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{client-D2utPQ1E.js → client-BXQCQDfY.js} +2 -2
- package/dist/{client-Dj4mcf-s.js → client-COLiUdWe.js} +6 -6
- package/dist/{client-bootstrap-n1Rqc8Go.js → client-bootstrap-CQwf9qrm.js} +1 -6
- package/dist/contract-api.js +2 -2
- package/dist/{credentials-DJj2xs3q.js → credentials-DysXbkv2.js} +2 -2
- package/dist/{credentials-read-mexhw-Ur.js → credentials-read-WWpqi88V.js} +1 -1
- package/dist/{credentials-write.runtime-DQt-kgJq.js → credentials-write.runtime-D22lPwRO.js} +1 -1
- package/dist/{crypto-runtime-m1eplj3b.js → crypto-runtime-BvunIYVn.js} +2 -2
- package/dist/{crypto-snapshot-doctor.runtime-D0v841D_.js → crypto-snapshot-doctor.runtime-DxgUMXUy.js} +2 -2
- package/dist/{directory-live-DLUgWBhA.js → directory-live-DABCxf8j.js} +2 -2
- package/dist/doctor-contract-api.js +43 -23
- package/dist/{draft-stream-DPYdv4fE.js → draft-stream-DSwgyyBi.js} +16 -5
- package/dist/{encryption-guidance-BNcZNQZI.js → encryption-guidance-mDyxJV9U.js} +1 -1
- package/dist/{event-helpers-XRfAbOIh.js → event-helpers-CspuhE9k.js} +9 -1
- package/dist/helper-api.js +3 -3
- package/dist/{http-client-DOmFvKvB.js → http-client-BfPeF4CE.js} +1 -1
- package/dist/{idb-persistence-CU7CNLlX.js → idb-persistence-DBdwHSWg.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{messages-C1U3b1oN.js → messages-H4mi9Cap.js} +6 -99
- package/dist/{monitor-SNnu-0bp.js → monitor-3Fw96uiE.js} +84 -118
- package/dist/{outbound-CeCEtF_q.js → outbound-UPI45TD_.js} +1 -1
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- package/dist/probe.runtime-DdXTrrmo.js +2 -0
- package/dist/{profile-update-Cd1p8ABr.js → profile-update-DWEg8Ylt.js} +1 -1
- package/dist/{reaction-events-DveJRUaX.js → reaction-events-D-iSW0iM.js} +5 -7
- package/dist/{resolve-targets-B64O69Nd.js → resolve-targets-BpnALDzR.js} +1 -1
- package/dist/{resolver.runtime-TRmePJDV.js → resolver.runtime-B83WkznZ.js} +1 -1
- package/dist/{room-info-DVkKDscD.js → room-info-CjnbX52D.js} +7 -4
- package/dist/runtime-api.js +2 -2
- package/dist/{sdk-C1yfda1L.js → sdk-CX9b0N8Q.js} +13 -6
- package/dist/{send-DG7Bnj7_.js → send-B9l1lKau.js} +201 -97
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/{setup-bootstrap-Co985F63.js → setup-bootstrap-CSI1L1lm.js} +2 -2
- package/dist/{setup-core-CEF6exLW.js → setup-core-DuTlyqRz.js} +3 -3
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-BSlj1vnL.js → setup-surface-fZing1WZ.js} +6 -6
- package/dist/{startup-verification-1Ney1mmI.js → startup-verification-BTSf31hS.js} +2 -1
- package/dist/storage-CV-pfV_2.js +320 -0
- package/dist/{storage-BVf4uucD.js → storage-metadata-DYArLcq1.js} +14 -319
- package/dist/{storage-paths-gUmSydsW.js → storage-paths-DVCANXTc.js} +13 -1
- package/dist/{sync-cache-state-d-A_OhbU.js → sync-cache-state-C-mhj3xb.js} +9 -3
- package/dist/{thread-bindings-DgxQEB99.js → thread-bindings-CRyf5on_.js} +3 -2
- package/dist/{tool-actions.runtime-vbkQgU7D.js → tool-actions.runtime-D5-hTkDu.js} +10 -10
- package/dist/types-DzSc7Sqm.js +32 -0
- package/dist/{verification-D-iOebn4.js → verification-B_aqtbx-.js} +2 -2
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/package.json +1 -1
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm.d.ts +69 -4
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.cjs +526 -432
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.js +358 -265
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm +0 -0
- package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts +8 -7
- package/node_modules/markdown-it/dist/browser/markdown-it.esm.min.mjs +216 -183
- package/node_modules/markdown-it/dist/browser/markdown-it.esm.min.mjs.map +1 -1
- package/node_modules/markdown-it/dist/browser/markdown-it.umd.min.js +7 -7
- package/node_modules/markdown-it/dist/browser/markdown-it.umd.min.js.map +1 -1
- package/node_modules/markdown-it/dist/markdown-it.cjs.js +98 -106
- package/node_modules/markdown-it/dist/markdown-it.cjs.js.map +1 -1
- package/node_modules/markdown-it/dist/markdown-it.d.mts +42 -71
- package/node_modules/markdown-it/dist/markdown-it.mjs +98 -106
- package/node_modules/markdown-it/dist/markdown-it.mjs.map +1 -1
- package/node_modules/markdown-it/package.json +1 -2
- package/node_modules/typebox/build/format/json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/json_pointer.mjs +2 -2
- package/node_modules/typebox/build/format/json_pointer_uri_fragment.d.mts +2 -2
- package/node_modules/typebox/build/format/json_pointer_uri_fragment.mjs +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
- package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
- package/node_modules/typebox/build/system/memory/assign.mjs +2 -1
- package/node_modules/typebox/build/system/memory/create.mjs +3 -4
- package/node_modules/typebox/build/system/memory/discard.mjs +2 -2
- package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
- package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
- package/node_modules/typebox/build/system/memory/update.mjs +3 -2
- package/node_modules/typebox/package.json +1 -1
- package/openclaw.plugin.json +24 -3
- package/package.json +7 -7
- package/dist/probe.runtime-B1YPxG9x.js +0 -2
- package/dist/runtime-BefyhPWv.js +0 -6
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
|
|
2
|
+
import { n as isMatrixActiveTokenRootDirectory, r as resolveMatrixAccountStorageRoot } from "./storage-paths-DVCANXTc.js";
|
|
3
|
+
import { C as scoreMatrixCryptoStateInStore, c as MATRIX_RECOVERY_KEY_FILENAME, d as migrateLegacyMatrixLegacyCryptoMigrationFileToStore, i as openMatrixStorageMetaStoreOptions, o as MATRIX_IDB_SNAPSHOT_FILENAME, p as migrateLegacyMatrixRecoveryKeyFileToStore, r as normalizeMatrixStorageMetadata, s as MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, t as STORAGE_META_STATE_KEY } from "./storage-metadata-DYArLcq1.js";
|
|
4
|
+
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { loadJsonFile } from "openclaw/plugin-sdk/json-store";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
//#region extensions/matrix/src/matrix/client/storage.ts
|
|
10
|
+
const DEFAULT_ACCOUNT_KEY = "default";
|
|
11
|
+
const STORAGE_META_FILENAME = "storage-meta.json";
|
|
12
|
+
const THREAD_BINDINGS_FILENAME = "thread-bindings.json";
|
|
13
|
+
function openStorageMetaStore(rootDir) {
|
|
14
|
+
return getMatrixRuntime().state.openSyncKeyedStore(openMatrixStorageMetaStoreOptions(rootDir));
|
|
15
|
+
}
|
|
16
|
+
function scoreStorageRoot(rootDir, metadata = readStoredRootMetadata(rootDir)) {
|
|
17
|
+
let score = 0;
|
|
18
|
+
if (Object.keys(metadata).length > 0) score += 1;
|
|
19
|
+
if (metadata.currentTokenStateClaimed === true) score += 8;
|
|
20
|
+
if (fs.existsSync(path.join(rootDir, "crypto"))) score += 8;
|
|
21
|
+
if (fs.existsSync(path.join(rootDir, THREAD_BINDINGS_FILENAME))) score += 4;
|
|
22
|
+
if (fs.existsSync(path.join(rootDir, "legacy-crypto-migration.json"))) score += 3;
|
|
23
|
+
if (fs.existsSync(path.join(rootDir, "recovery-key.json"))) score += 2;
|
|
24
|
+
if (fs.existsSync(path.join(rootDir, "crypto-idb-snapshot.json"))) score += 2;
|
|
25
|
+
score += scoreMatrixCryptoStateInStore(rootDir);
|
|
26
|
+
return score;
|
|
27
|
+
}
|
|
28
|
+
function resolveStorageRootMtimeMs(rootDir) {
|
|
29
|
+
try {
|
|
30
|
+
return fs.statSync(rootDir).mtimeMs;
|
|
31
|
+
} catch {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function readStoredRootMetadata(rootDir) {
|
|
36
|
+
if (fs.existsSync(path.join(rootDir, "state", "openclaw.sqlite"))) try {
|
|
37
|
+
const stored = normalizeMatrixStorageMetadata(openStorageMetaStore(rootDir).lookup(STORAGE_META_STATE_KEY));
|
|
38
|
+
if (stored) return stored;
|
|
39
|
+
} catch {}
|
|
40
|
+
return normalizeMatrixStorageMetadata(loadJsonFile(path.join(rootDir, STORAGE_META_FILENAME))) ?? {};
|
|
41
|
+
}
|
|
42
|
+
function isCompatibleStorageRoot(params) {
|
|
43
|
+
const metadata = readStoredRootMetadata(params.candidateRootDir);
|
|
44
|
+
if (metadata.homeserver && metadata.homeserver !== params.homeserver) return false;
|
|
45
|
+
if (metadata.userId && metadata.userId !== params.userId) return false;
|
|
46
|
+
if (metadata.accountId && normalizeAccountId(metadata.accountId) !== normalizeAccountId(params.accountKey)) return false;
|
|
47
|
+
if (params.deviceId && metadata.deviceId && metadata.deviceId.trim() && metadata.deviceId.trim() !== params.deviceId.trim()) return false;
|
|
48
|
+
if (params.requireExplicitDeviceMatch && params.deviceId && (!metadata.deviceId || metadata.deviceId.trim() !== params.deviceId.trim())) return false;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function resolvePreferredMatrixStorageRoot(params) {
|
|
52
|
+
const canonical = {
|
|
53
|
+
rootDir: params.canonicalRootDir,
|
|
54
|
+
tokenHash: params.canonicalTokenHash
|
|
55
|
+
};
|
|
56
|
+
const deviceId = params.deviceId?.trim();
|
|
57
|
+
if (!deviceId) return canonical;
|
|
58
|
+
const canonicalMetadata = readStoredRootMetadata(params.canonicalRootDir);
|
|
59
|
+
if (canonicalMetadata.accessTokenHash === params.canonicalTokenHash && canonicalMetadata.deviceId?.trim() === deviceId && canonicalMetadata.currentTokenStateClaimed === true) return canonical;
|
|
60
|
+
const parentDir = path.dirname(params.canonicalRootDir);
|
|
61
|
+
const bestCurrentScore = scoreStorageRoot(params.canonicalRootDir, canonicalMetadata);
|
|
62
|
+
const bestCurrentMtimeMs = resolveStorageRootMtimeMs(params.canonicalRootDir);
|
|
63
|
+
let best = {
|
|
64
|
+
rootDir: params.canonicalRootDir,
|
|
65
|
+
tokenHash: params.canonicalTokenHash,
|
|
66
|
+
score: bestCurrentScore,
|
|
67
|
+
mtimeMs: bestCurrentMtimeMs
|
|
68
|
+
};
|
|
69
|
+
let siblingEntries;
|
|
70
|
+
try {
|
|
71
|
+
siblingEntries = fs.readdirSync(parentDir, { withFileTypes: true });
|
|
72
|
+
} catch {
|
|
73
|
+
return {
|
|
74
|
+
rootDir: best.rootDir,
|
|
75
|
+
tokenHash: best.tokenHash
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const compatiblePopulatedSiblings = [];
|
|
79
|
+
const populatedTokenHashes = bestCurrentScore > 0 ? [params.canonicalTokenHash] : [];
|
|
80
|
+
for (const entry of siblingEntries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
81
|
+
if (!entry.isDirectory()) continue;
|
|
82
|
+
if (entry.name === params.canonicalTokenHash) continue;
|
|
83
|
+
if (!isMatrixActiveTokenRootDirectory(entry.name)) continue;
|
|
84
|
+
const candidateRootDir = path.join(parentDir, entry.name);
|
|
85
|
+
if (!isCompatibleStorageRoot({
|
|
86
|
+
candidateRootDir,
|
|
87
|
+
homeserver: params.homeserver,
|
|
88
|
+
userId: params.userId,
|
|
89
|
+
accountKey: params.accountKey,
|
|
90
|
+
deviceId,
|
|
91
|
+
requireExplicitDeviceMatch: true
|
|
92
|
+
})) continue;
|
|
93
|
+
const candidateScore = scoreStorageRoot(candidateRootDir);
|
|
94
|
+
if (candidateScore <= 0) continue;
|
|
95
|
+
populatedTokenHashes.push(entry.name);
|
|
96
|
+
compatiblePopulatedSiblings.push({
|
|
97
|
+
rootDir: candidateRootDir,
|
|
98
|
+
tokenHash: entry.name,
|
|
99
|
+
score: candidateScore,
|
|
100
|
+
mtimeMs: resolveStorageRootMtimeMs(candidateRootDir)
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
for (const candidate of compatiblePopulatedSiblings) if (candidate.score > best.score || best.rootDir !== params.canonicalRootDir && candidate.score === best.score && candidate.mtimeMs > best.mtimeMs) best = {
|
|
104
|
+
rootDir: candidate.rootDir,
|
|
105
|
+
tokenHash: candidate.tokenHash,
|
|
106
|
+
score: candidate.score,
|
|
107
|
+
mtimeMs: candidate.mtimeMs
|
|
108
|
+
};
|
|
109
|
+
if (populatedTokenHashes.length > 1) getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" }).warn("matrix: multiple populated token-hash storage roots detected", {
|
|
110
|
+
parentDir,
|
|
111
|
+
canonicalTokenHash: params.canonicalTokenHash,
|
|
112
|
+
selectedTokenHash: best.tokenHash,
|
|
113
|
+
populatedTokenHashes,
|
|
114
|
+
populatedSiblingTokenHashes: compatiblePopulatedSiblings.map((root) => root.tokenHash),
|
|
115
|
+
populatedRootCount: populatedTokenHashes.length
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
rootDir: best.rootDir,
|
|
119
|
+
tokenHash: best.tokenHash
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function resolveMatrixStoragePaths(params) {
|
|
123
|
+
const env = params.env ?? process.env;
|
|
124
|
+
const stateDir = params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir);
|
|
125
|
+
const canonical = resolveMatrixAccountStorageRoot({
|
|
126
|
+
stateDir,
|
|
127
|
+
homeserver: params.homeserver,
|
|
128
|
+
userId: params.userId,
|
|
129
|
+
accessToken: params.accessToken,
|
|
130
|
+
accountId: params.accountId
|
|
131
|
+
});
|
|
132
|
+
const { rootDir, tokenHash } = resolvePreferredMatrixStorageRoot({
|
|
133
|
+
canonicalRootDir: canonical.rootDir,
|
|
134
|
+
canonicalTokenHash: canonical.tokenHash,
|
|
135
|
+
homeserver: params.homeserver,
|
|
136
|
+
userId: params.userId,
|
|
137
|
+
accountKey: canonical.accountKey,
|
|
138
|
+
deviceId: params.deviceId
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
rootDir,
|
|
142
|
+
storagePath: path.join(rootDir, "bot-storage.json"),
|
|
143
|
+
cryptoPath: path.join(rootDir, "crypto"),
|
|
144
|
+
recoveryKeyPath: path.join(rootDir, MATRIX_RECOVERY_KEY_FILENAME),
|
|
145
|
+
idbSnapshotPath: path.join(rootDir, MATRIX_IDB_SNAPSHOT_FILENAME),
|
|
146
|
+
accountKey: canonical.accountKey,
|
|
147
|
+
tokenHash
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function resolveMatrixStateFilePath(params) {
|
|
151
|
+
const storagePaths = resolveMatrixStoragePaths({
|
|
152
|
+
homeserver: params.auth.homeserver,
|
|
153
|
+
userId: params.auth.userId,
|
|
154
|
+
accessToken: params.auth.accessToken,
|
|
155
|
+
accountId: params.accountId ?? params.auth.accountId,
|
|
156
|
+
deviceId: params.auth.deviceId,
|
|
157
|
+
env: params.env,
|
|
158
|
+
stateDir: params.stateDir
|
|
159
|
+
});
|
|
160
|
+
return path.join(storagePaths.rootDir, params.filename);
|
|
161
|
+
}
|
|
162
|
+
async function maybeMigrateLegacyStorage(params) {
|
|
163
|
+
const hasAccountScopedLegacyStorageFile = fs.existsSync(params.storagePaths.storagePath);
|
|
164
|
+
const syncCache = hasAccountScopedLegacyStorageFile ? await import("./sync-cache-state-C-mhj3xb.js").then((n) => n.s) : null;
|
|
165
|
+
const hasAccountScopedLegacyStorage = hasAccountScopedLegacyStorageFile && await syncCache?.readLegacyMatrixSyncCacheState(params.storagePaths.rootDir) !== null;
|
|
166
|
+
const hasAccountScopedRecoveryKey = fs.existsSync(params.storagePaths.recoveryKeyPath);
|
|
167
|
+
const hasAccountScopedLegacyCryptoMigration = fs.existsSync(path.join(params.storagePaths.rootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME));
|
|
168
|
+
if (!hasAccountScopedLegacyStorage && !hasAccountScopedRecoveryKey && !hasAccountScopedLegacyCryptoMigration) return;
|
|
169
|
+
const logger = getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" });
|
|
170
|
+
fs.mkdirSync(params.storagePaths.rootDir, { recursive: true });
|
|
171
|
+
const moved = [];
|
|
172
|
+
const pendingArchives = [];
|
|
173
|
+
const skippedExistingTargets = [];
|
|
174
|
+
try {
|
|
175
|
+
if (hasAccountScopedLegacyStorage) await migrateLegacySyncCacheToSqlite({
|
|
176
|
+
sourceRootDir: params.storagePaths.rootDir,
|
|
177
|
+
sourcePath: params.storagePaths.storagePath,
|
|
178
|
+
targetRootDir: params.storagePaths.rootDir,
|
|
179
|
+
label: "account sync cache",
|
|
180
|
+
moved,
|
|
181
|
+
pendingArchives
|
|
182
|
+
});
|
|
183
|
+
if (hasAccountScopedRecoveryKey) {
|
|
184
|
+
migrateLegacyMatrixRecoveryKeyFileToStore(params.storagePaths.rootDir);
|
|
185
|
+
moved.push({
|
|
186
|
+
sourcePath: params.storagePaths.recoveryKeyPath,
|
|
187
|
+
targetPath: `${params.storagePaths.rootDir} SQLite recovery key state`,
|
|
188
|
+
label: "recovery key"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (hasAccountScopedLegacyCryptoMigration) {
|
|
192
|
+
migrateLegacyMatrixLegacyCryptoMigrationFileToStore(params.storagePaths.rootDir);
|
|
193
|
+
moved.push({
|
|
194
|
+
sourcePath: path.join(params.storagePaths.rootDir, MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME),
|
|
195
|
+
targetPath: `${params.storagePaths.rootDir} SQLite legacy crypto migration state`,
|
|
196
|
+
label: "legacy crypto migration"
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
const rollbackError = rollbackLegacyMoves(moved);
|
|
201
|
+
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 });
|
|
202
|
+
}
|
|
203
|
+
for (const archive of pendingArchives) archiveLegacyStoragePath({
|
|
204
|
+
...archive,
|
|
205
|
+
skippedExistingTargets
|
|
206
|
+
});
|
|
207
|
+
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")}`);
|
|
208
|
+
if (skippedExistingTargets.length > 0) logger.warn?.(`matrix: legacy client storage files were left in place because their migrated targets already existed.\n${skippedExistingTargets.join("\n")}`);
|
|
209
|
+
}
|
|
210
|
+
async function migrateLegacySyncCacheToSqlite(params) {
|
|
211
|
+
const syncCache = await import("./sync-cache-state-C-mhj3xb.js").then((n) => n.s);
|
|
212
|
+
const persisted = await syncCache.readLegacyMatrixSyncCacheState(params.sourceRootDir);
|
|
213
|
+
if (!persisted) return;
|
|
214
|
+
const store = getMatrixRuntime().state.openKeyedStore(syncCache.openMatrixSyncCacheStoreOptions(params.targetRootDir));
|
|
215
|
+
if (!await syncCache.hasMatrixSyncCacheStateInStore({
|
|
216
|
+
storageRootDir: params.targetRootDir,
|
|
217
|
+
store
|
|
218
|
+
})) {
|
|
219
|
+
await syncCache.writeMatrixSyncCacheStateToStore({
|
|
220
|
+
storageRootDir: params.targetRootDir,
|
|
221
|
+
payload: persisted,
|
|
222
|
+
store
|
|
223
|
+
});
|
|
224
|
+
claimCurrentTokenStorageState({ rootDir: params.targetRootDir });
|
|
225
|
+
params.moved.push({
|
|
226
|
+
sourcePath: params.sourcePath,
|
|
227
|
+
targetPath: `${params.targetRootDir} SQLite sync cache`,
|
|
228
|
+
label: params.label
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
params.pendingArchives.push({
|
|
232
|
+
sourcePath: params.sourcePath,
|
|
233
|
+
label: params.label
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
function archiveLegacyStoragePath(params) {
|
|
237
|
+
const archivedLegacyStoragePath = `${params.sourcePath}.migrated`;
|
|
238
|
+
if (fs.existsSync(archivedLegacyStoragePath)) {
|
|
239
|
+
params.skippedExistingTargets.push(`- ${params.label} remains at ${params.sourcePath} because ${archivedLegacyStoragePath} already exists`);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
fs.renameSync(params.sourcePath, archivedLegacyStoragePath);
|
|
243
|
+
}
|
|
244
|
+
function rollbackLegacyMoves(moved) {
|
|
245
|
+
for (const entry of moved.toReversed()) try {
|
|
246
|
+
if (!fs.existsSync(entry.targetPath) || fs.existsSync(entry.sourcePath)) continue;
|
|
247
|
+
fs.renameSync(entry.targetPath, entry.sourcePath);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
return `${entry.label} (${entry.targetPath} -> ${entry.sourcePath}): ${String(err)}`;
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
function writeStoredRootMetadata(rootDir, payload) {
|
|
254
|
+
try {
|
|
255
|
+
const normalized = normalizeMatrixStorageMetadata(payload);
|
|
256
|
+
if (!normalized) return false;
|
|
257
|
+
openStorageMetaStore(rootDir).register(STORAGE_META_STATE_KEY, normalized);
|
|
258
|
+
return true;
|
|
259
|
+
} catch {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function writeStorageMeta(params) {
|
|
264
|
+
const existing = readStoredRootMetadata(params.storagePaths.rootDir);
|
|
265
|
+
return writeStoredRootMetadata(params.storagePaths.rootDir, {
|
|
266
|
+
homeserver: params.homeserver,
|
|
267
|
+
userId: params.userId,
|
|
268
|
+
accountId: params.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
269
|
+
accessTokenHash: params.storagePaths.tokenHash,
|
|
270
|
+
deviceId: params.deviceId ?? null,
|
|
271
|
+
currentTokenStateClaimed: params.currentTokenStateClaimed ?? existing.currentTokenStateClaimed === true,
|
|
272
|
+
createdAt: existing.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function claimCurrentTokenStorageState(params) {
|
|
276
|
+
const metadata = readStoredRootMetadata(params.rootDir);
|
|
277
|
+
if (!metadata.accessTokenHash?.trim()) return false;
|
|
278
|
+
return writeStoredRootMetadata(params.rootDir, {
|
|
279
|
+
homeserver: metadata.homeserver,
|
|
280
|
+
userId: metadata.userId,
|
|
281
|
+
accountId: metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
282
|
+
accessTokenHash: metadata.accessTokenHash,
|
|
283
|
+
deviceId: metadata.deviceId ?? null,
|
|
284
|
+
currentTokenStateClaimed: true,
|
|
285
|
+
createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function recordCurrentStorageMetaDeviceId(params) {
|
|
289
|
+
const deviceId = params.deviceId.trim();
|
|
290
|
+
if (!deviceId) return false;
|
|
291
|
+
const metadata = readStoredRootMetadata(params.rootDir);
|
|
292
|
+
if (!metadata.accessTokenHash?.trim()) return false;
|
|
293
|
+
return writeStoredRootMetadata(params.rootDir, {
|
|
294
|
+
homeserver: metadata.homeserver,
|
|
295
|
+
userId: metadata.userId,
|
|
296
|
+
accountId: metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
|
|
297
|
+
accessTokenHash: metadata.accessTokenHash,
|
|
298
|
+
deviceId,
|
|
299
|
+
currentTokenStateClaimed: metadata.currentTokenStateClaimed === true,
|
|
300
|
+
createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function repairCurrentTokenStorageMetaDeviceId(params) {
|
|
304
|
+
return writeStorageMeta({
|
|
305
|
+
storagePaths: resolveMatrixStoragePaths({
|
|
306
|
+
homeserver: params.homeserver,
|
|
307
|
+
userId: params.userId,
|
|
308
|
+
accessToken: params.accessToken,
|
|
309
|
+
accountId: params.accountId,
|
|
310
|
+
env: params.env,
|
|
311
|
+
stateDir: params.stateDir
|
|
312
|
+
}),
|
|
313
|
+
homeserver: params.homeserver,
|
|
314
|
+
userId: params.userId,
|
|
315
|
+
accountId: params.accountId,
|
|
316
|
+
deviceId: params.deviceId
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
//#endregion
|
|
320
|
+
export { resolveMatrixStateFilePath as a, repairCurrentTokenStorageMetaDeviceId as i, maybeMigrateLegacyStorage as n, resolveMatrixStoragePaths as o, recordCurrentStorageMetaDeviceId as r, writeStorageMeta as s, claimCurrentTokenStorageState as t };
|