@openclaw/matrix 2026.8.1 → 2026.8.33
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-C8nnBTxi.js → .setup/account-selection-DZMazUgX.mjs} +12 -10
- package/dist/{accounts-fC57n-Jo.js → .setup/accounts-BJ6ECCac.mjs} +3 -3
- package/dist/{approval-handler.runtime-BBjFZw1t.js → .setup/approval-handler.runtime-CdT1wQve.mjs} +6 -6
- package/dist/{approval-ids-DTIdXV-m.js → .setup/approval-ids-CU_nMQy9.mjs} +1 -1
- package/dist/{approval-reaction-auth-BDONXxnF.js → .setup/approval-reaction-auth-CpxhvOOT.mjs} +2 -2
- package/dist/{approval-reactions-tXh9KYrW.js → .setup/approval-reactions-D5eegob9.mjs} +2 -2
- package/dist/{channel-BkEcVUs_.js → .setup/channel-Q_N83Wwa.mjs} +57 -59
- package/dist/{channel.runtime-CTLSBFsP.js → .setup/channel.runtime-BFXlZFP1.mjs} +17 -13
- package/dist/{channel.setup-CSacbORr.js → .setup/channel.setup-2A6HBRbA.mjs} +22 -20
- package/dist/{cli-DRVtgrq5.js → .setup/cli-CyuDGiIr.mjs} +43 -34
- package/dist/{cli-metadata-Ddx_y4Os.js → .setup/cli-metadata-B_y2Z5Np.mjs} +1 -1
- package/dist/{client-CZ_JvrO0.js → .setup/client-CpHMD-C2.mjs} +3 -3
- package/dist/{client-kSi51NKp.js → .setup/client-DvcYcTSy.mjs} +76 -23
- package/dist/{client-bootstrap-D8irSL2i.js → .setup/client-bootstrap-Cb1tHsT4.mjs} +3 -3
- package/dist/{client-support-DLj4vDeu.js → .setup/client-support-Bn9Bk0-H.mjs} +1 -1
- package/dist/{config-update-DC0fWBxc.js → .setup/config-update-B_4qZ5bV.mjs} +49 -31
- package/dist/{credentials-BdAaWuiR.js → .setup/credentials-B2roKThT.mjs} +6 -10
- package/dist/{credentials-read-B37cQknZ.js → .setup/credentials-read-DaemdXHy.mjs} +11 -9
- package/dist/{credentials-write.runtime-nAV2-5uR.js → .setup/credentials-write.runtime-D83HEGcL.mjs} +1 -1
- package/dist/{crypto-runtime-C4WDYxlP.js → .setup/crypto-runtime-Ch4WOG1y.mjs} +8 -8
- package/dist/{deps-CcVJfvRM.js → .setup/deps-mtxF2mHI.mjs} +1 -1
- package/dist/{device-health-B4-YXtJR.js → .setup/device-health-CWOuIirq.mjs} +1 -1
- package/dist/{direct-room-RinHjtqX.js → .setup/direct-room-CKyU8upP.mjs} +1 -1
- package/dist/{directory-live-DKr0w35b.js → .setup/directory-live-DggLE-28.mjs} +10 -8
- package/dist/{doctor-EWf9CDso.js → .setup/doctor-BLCvdOFo.mjs} +1 -1
- package/dist/{doctor-contract-DEt4O4Zt.js → .setup/doctor-contract-HyWFZQVG.mjs} +5 -4
- package/dist/{draft-stream-0CEpNrBk.js → .setup/draft-stream-DfUFwKfN.mjs} +1 -1
- package/dist/{encryption-guidance-D4ZdAqzM.js → .setup/encryption-guidance-CvN_NQUJ.mjs} +4 -3
- package/dist/{http-client-D8o8b9u6.js → .setup/http-client-Bv6a2OfI.mjs} +11 -8
- package/dist/{idb-persistence-DfgW720p.js → .setup/idb-persistence-BiscLSq4.mjs} +3 -3
- package/dist/{idb-persistence-lock-DAJ49nZX.js → .setup/idb-persistence-lock-B3fZXyF_.mjs} +1 -1
- package/dist/{inbound-dedupe-RvSLqdsz.js → .setup/inbound-dedupe-BOsuMiaj.mjs} +2 -2
- package/dist/{logger-B_71hN6W.js → .setup/logger-B3tfcB-m.mjs} +1 -1
- package/dist/{logging-DRjvUOIh.js → .setup/logging-CkohOZwO.mjs} +2 -2
- package/dist/{messages-DaGRt-tu.js → .setup/messages-C3v-jkaN.mjs} +4 -4
- package/dist/{monitor-CLPbPcR9.js → .setup/monitor-CQ6pGvZh.mjs} +56 -81
- package/dist/.setup/probe.runtime-ni46ImsO.mjs +2 -0
- package/dist/{profile-D-Wubo0A.js → .setup/profile-ClrB3IgR.mjs} +2 -2
- package/dist/{profile-update-zXVCMg7y.js → .setup/profile-update-B9Q6Ox2O.mjs} +6 -5
- package/dist/{reaction-events-CjVUiqcY.js → .setup/reaction-events-Dtd3W-rj.mjs} +10 -8
- package/dist/{resolve-targets-qG6gceps.js → .setup/resolve-targets-Bke5jHKS.mjs} +3 -3
- package/dist/{resolver.runtime-zX3TR3TN.js → .setup/resolver.runtime-BtrbC025.mjs} +1 -1
- package/dist/{room-info-yheP1mod.js → .setup/room-info-B0VNxsF8.mjs} +4 -4
- package/dist/.setup/runtime-setter-api-DGMubGUq.mjs +3 -0
- package/dist/{sdk-TZYyo0XQ.js → .setup/sdk-DoObvds0.mjs} +528 -30
- package/dist/{secret-contract-CufozuyJ.js → .setup/secret-contract-JlB6VmI3.mjs} +1 -1
- package/dist/.setup/secret-contract-api-B-iJoQEv.mjs +3 -0
- package/dist/{send-BL_iH5Ox.js → .setup/send-SmBzUhD-.mjs} +19 -15
- package/dist/{setup-bootstrap-D8M7FmcO.js → .setup/setup-bootstrap-CUKhebeX.mjs} +3 -3
- package/dist/{setup-core-r6L0nno-.js → .setup/setup-core-BnqoLunq.mjs} +9 -8
- package/dist/.setup/setup-plugin-api-Dg95tydH.mjs +3 -0
- package/dist/{setup-surface-g174ElFO.js → .setup/setup-surface-sWwADrZ8.mjs} +87 -81
- package/dist/{startup-verification-Cs08ca8u.js → .setup/startup-verification-E46yu4fh.mjs} +3 -3
- package/dist/{storage-BsGuHngK.js → .setup/storage-B-nf2ReN.mjs} +7 -6
- package/dist/{subagent-hooks-CMoZaARG.js → .setup/subagent-hooks-jFgft_Mr.mjs} +6 -2
- package/dist/.setup/sync-cache-state-6Hjn1K-v.mjs +234 -0
- package/dist/{thread-binding-api-CzkeLZCU.js → .setup/thread-binding-api-DRMC62cs.mjs} +1 -1
- package/dist/{thread-bindings-ERWNousC.js → .setup/thread-bindings-_WJ8RYWJ.mjs} +4 -4
- package/dist/{tool-actions.runtime-DcBCSwY4.js → .setup/tool-actions.runtime-DLICojA3.mjs} +230 -168
- package/dist/{verification-4vsW_WSn.js → .setup/verification-DOT16noD.mjs} +4 -3
- package/dist/api.js +8 -8
- package/dist/auth-presence.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/contract-api.js +2 -2
- package/dist/doctor-contract-api.js +9 -9
- package/dist/helper-api.js +3 -3
- package/dist/index.js +1 -1
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- package/dist/runtime-api.js +6 -6
- package/dist/runtime-setter-api.js +1 -1
- package/dist/secret-contract-api.js +1 -1
- package/dist/session-binding-contract-api.js +2 -2
- package/dist/setup-entry.js +4 -3
- package/dist/setup-plugin-api.js +1 -1
- package/dist/subagent-hooks-api.js +1 -1
- package/dist/thread-binding-api.js +1 -1
- package/dist/thread-bindings-runtime.js +1 -1
- package/node_modules/markdown-it/dist/browser/markdown-it.esm.min.mjs +525 -484
- 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 +129 -121
- 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 +129 -121
- package/node_modules/markdown-it/dist/markdown-it.mjs.map +1 -1
- package/node_modules/markdown-it/package.json +1 -2
- package/node_modules/matrix-js-sdk/lib/client.d.ts +2 -1
- package/node_modules/matrix-js-sdk/lib/client.js +6 -2
- package/node_modules/matrix-js-sdk/lib/sync.js +8 -8
- package/node_modules/matrix-js-sdk/src/client.ts +7 -3
- package/node_modules/matrix-js-sdk/src/sync.ts +8 -8
- package/node_modules/typebox/build/format/email.mjs +1 -1
- package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
- package/node_modules/typebox/package.json +1 -1
- package/package.json +6 -6
- package/dist/file-sync-store-DjskBX2o.js +0 -436
- package/dist/probe.runtime-Bxpr1FFy.js +0 -2
- package/dist/recovery-key-store-CognuDys.js +0 -276
- /package/dist/{account-config-CRsKoMqJ.js → .setup/account-config-CRsKoMqJ.mjs} +0 -0
- /package/dist/{backup-health-Dm_YMVFT.js → .setup/backup-health-Dm_YMVFT.mjs} +0 -0
- /package/dist/{config-paths-CnREYb1Y.js → .setup/config-paths-CnREYb1Y.mjs} +0 -0
- /package/dist/{config-secret-input.runtime-CwsP3--c.js → .setup/config-secret-input.runtime-CwsP3--c.mjs} +0 -0
- /package/dist/{credentials-state-B3cuUFwZ.js → .setup/credentials-state-B3cuUFwZ.mjs} +0 -0
- /package/dist/{crypto-node.runtime-6Aj_ltHQ.js → .setup/crypto-node.runtime-6Aj_ltHQ.mjs} +0 -0
- /package/dist/{env-vars-dGqak9dN.js → .setup/env-vars-dGqak9dN.mjs} +0 -0
- /package/dist/{errors-DKVS3_DO.js → .setup/errors-DKVS3_DO.mjs} +0 -0
- /package/dist/{event-helpers-XRfAbOIh.js → .setup/event-helpers-XRfAbOIh.mjs} +0 -0
- /package/dist/{reaction-common-DkrQdBSZ.js → .setup/reaction-common-DkrQdBSZ.mjs} +0 -0
- /package/dist/{rolldown-runtime-8H4AJuhK.js → .setup/rolldown-runtime-8H4AJuhK.mjs} +0 -0
- /package/dist/{runtime-6S3DNFNv.js → .setup/runtime-6S3DNFNv.mjs} +0 -0
- /package/dist/{runtime-BefyhPWv.js → .setup/runtime-BefyhPWv.mjs} +0 -0
- /package/dist/{storage-paths-gUmSydsW.js → .setup/storage-paths-gUmSydsW.mjs} +0 -0
- /package/dist/{target-ids-Nwx7cMVE.js → .setup/target-ids-Nwx7cMVE.mjs} +0 -0
- /package/dist/{thread-bindings-shared-oNPiyMWY.js → .setup/thread-bindings-shared-oNPiyMWY.mjs} +0 -0
- /package/dist/{url-validation-GRHde6lq.js → .setup/url-validation-GRHde6lq.mjs} +0 -0
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
-
import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
|
|
3
|
-
import { M as resolveMatrixSqliteStateEnv, t as claimCurrentTokenStorageState } from "./storage-BsGuHngK.js";
|
|
4
|
-
import { n as LogService } from "./logger-B_71hN6W.js";
|
|
5
|
-
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
6
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import fs from "node:fs/promises";
|
|
9
|
-
import { Category, MemoryStore, SyncAccumulator } from "matrix-js-sdk/lib/matrix.js";
|
|
10
|
-
//#region extensions/matrix/src/matrix/async-lock.ts
|
|
11
|
-
function createAsyncLock() {
|
|
12
|
-
let lock = Promise.resolve();
|
|
13
|
-
return async function withLock(fn) {
|
|
14
|
-
const previous = lock;
|
|
15
|
-
let release;
|
|
16
|
-
lock = new Promise((resolve) => {
|
|
17
|
-
release = resolve;
|
|
18
|
-
});
|
|
19
|
-
await previous;
|
|
20
|
-
try {
|
|
21
|
-
return await fn();
|
|
22
|
-
} finally {
|
|
23
|
-
release?.();
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region extensions/matrix/src/matrix/client/file-sync-store.ts
|
|
29
|
-
var file_sync_store_exports = /* @__PURE__ */ __exportAll({
|
|
30
|
-
SqliteBackedMatrixSyncStore: () => SqliteBackedMatrixSyncStore,
|
|
31
|
-
hasMatrixSyncCacheStateInStore: () => hasMatrixSyncCacheStateInStore,
|
|
32
|
-
openMatrixSyncCacheStoreOptions: () => openMatrixSyncCacheStoreOptions,
|
|
33
|
-
readLegacyMatrixSyncCacheState: () => readLegacyMatrixSyncCacheState,
|
|
34
|
-
writeMatrixSyncCacheStateToStore: () => writeMatrixSyncCacheStateToStore
|
|
35
|
-
});
|
|
36
|
-
const STORE_VERSION = 1;
|
|
37
|
-
const PERSIST_DEBOUNCE_MS = 250;
|
|
38
|
-
const SYNC_CACHE_NAMESPACE = "sync-cache";
|
|
39
|
-
const SYNC_CACHE_MAX_ENTRIES = 2e4;
|
|
40
|
-
const SYNC_CACHE_MAX_CHUNKS = Math.floor((SYNC_CACHE_MAX_ENTRIES - 1) / 2);
|
|
41
|
-
const SYNC_CACHE_STATE_KEY = "current";
|
|
42
|
-
const SYNC_CACHE_CHUNK_BYTES = 24e3;
|
|
43
|
-
function normalizeRoomsData(value) {
|
|
44
|
-
if (!isRecord(value)) return null;
|
|
45
|
-
return {
|
|
46
|
-
[Category.Join]: isRecord(value[Category.Join]) ? value[Category.Join] : {},
|
|
47
|
-
[Category.Invite]: isRecord(value[Category.Invite]) ? value[Category.Invite] : {},
|
|
48
|
-
[Category.Leave]: isRecord(value[Category.Leave]) ? value[Category.Leave] : {},
|
|
49
|
-
[Category.Knock]: isRecord(value[Category.Knock]) ? value[Category.Knock] : {}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function toPersistedSyncData(value) {
|
|
53
|
-
if (!isRecord(value)) return null;
|
|
54
|
-
if (typeof value.nextBatch === "string" && value.nextBatch.trim()) {
|
|
55
|
-
const roomsData = normalizeRoomsData(value.roomsData);
|
|
56
|
-
if (!Array.isArray(value.accountData) || !roomsData) return null;
|
|
57
|
-
return {
|
|
58
|
-
nextBatch: value.nextBatch,
|
|
59
|
-
accountData: value.accountData,
|
|
60
|
-
roomsData
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (typeof value.next_batch === "string" && value.next_batch.trim()) {
|
|
64
|
-
const roomsData = normalizeRoomsData(value.rooms);
|
|
65
|
-
if (!roomsData) return null;
|
|
66
|
-
return {
|
|
67
|
-
nextBatch: value.next_batch,
|
|
68
|
-
accountData: isRecord(value.account_data) && Array.isArray(value.account_data.events) ? value.account_data.events : [],
|
|
69
|
-
roomsData
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
function normalizePersistedStore(value) {
|
|
75
|
-
if (!isRecord(value) || value.version !== STORE_VERSION) return null;
|
|
76
|
-
return {
|
|
77
|
-
version: STORE_VERSION,
|
|
78
|
-
savedSync: toPersistedSyncData(value.savedSync),
|
|
79
|
-
clientOptions: isRecord(value.clientOptions) ? value.clientOptions : void 0,
|
|
80
|
-
cleanShutdown: value.cleanShutdown === true
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function normalizeLegacyPersistedStore(value) {
|
|
84
|
-
const persisted = normalizePersistedStore(value);
|
|
85
|
-
if (persisted) return persisted;
|
|
86
|
-
return {
|
|
87
|
-
version: STORE_VERSION,
|
|
88
|
-
savedSync: toPersistedSyncData(value),
|
|
89
|
-
cleanShutdown: false
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function cloneJson(value) {
|
|
93
|
-
return structuredClone(value);
|
|
94
|
-
}
|
|
95
|
-
function syncDataToSyncResponse(syncData) {
|
|
96
|
-
return {
|
|
97
|
-
next_batch: syncData.nextBatch,
|
|
98
|
-
rooms: syncData.roomsData,
|
|
99
|
-
account_data: { events: syncData.accountData }
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
var SqliteBackedMatrixSyncStore = class extends MemoryStore {
|
|
103
|
-
constructor(storageRootDir) {
|
|
104
|
-
super();
|
|
105
|
-
this.storageRootDir = storageRootDir;
|
|
106
|
-
this.persistLock = createAsyncLock();
|
|
107
|
-
this.accumulator = new SyncAccumulator();
|
|
108
|
-
this.savedSync = null;
|
|
109
|
-
this.cleanShutdown = false;
|
|
110
|
-
this.dirty = false;
|
|
111
|
-
this.frozen = false;
|
|
112
|
-
this.persistTimer = null;
|
|
113
|
-
this.persistPromise = null;
|
|
114
|
-
this.stateKey = SYNC_CACHE_STATE_KEY;
|
|
115
|
-
let restoredSavedSync = null;
|
|
116
|
-
let restoredClientOptions;
|
|
117
|
-
let restoredCleanShutdown = false;
|
|
118
|
-
let syncCacheStore = createNoopMatrixSyncCacheStore();
|
|
119
|
-
let syncCacheStoreUnavailableError;
|
|
120
|
-
try {
|
|
121
|
-
syncCacheStore = openMatrixSyncCacheStore(storageRootDir);
|
|
122
|
-
const persisted = readPersistedStoreFromSyncStore(syncCacheStore, this.stateKey);
|
|
123
|
-
if (persisted) {
|
|
124
|
-
restoredSavedSync = persisted.savedSync;
|
|
125
|
-
restoredClientOptions = persisted.clientOptions;
|
|
126
|
-
restoredCleanShutdown = persisted.cleanShutdown === true;
|
|
127
|
-
}
|
|
128
|
-
} catch (err) {
|
|
129
|
-
syncCacheStoreUnavailableError = err;
|
|
130
|
-
LogService.warn("MatrixSyncCacheStore", "Failed to load Matrix sync cache:", err);
|
|
131
|
-
}
|
|
132
|
-
this.store = syncCacheStore;
|
|
133
|
-
this.storeUnavailableError = syncCacheStoreUnavailableError;
|
|
134
|
-
this.savedSync = restoredSavedSync;
|
|
135
|
-
this.savedClientOptions = restoredClientOptions;
|
|
136
|
-
this.hadSavedSyncOnLoad = restoredSavedSync !== null;
|
|
137
|
-
this.hadCleanShutdownOnLoad = this.hadSavedSyncOnLoad && restoredCleanShutdown;
|
|
138
|
-
this.cleanShutdown = this.hadCleanShutdownOnLoad;
|
|
139
|
-
if (this.savedSync) {
|
|
140
|
-
this.accumulator.accumulate(syncDataToSyncResponse(this.savedSync), true);
|
|
141
|
-
super.setSyncToken(this.savedSync.nextBatch);
|
|
142
|
-
}
|
|
143
|
-
if (this.savedClientOptions) super.storeClientOptions(this.savedClientOptions);
|
|
144
|
-
}
|
|
145
|
-
hasSavedSync() {
|
|
146
|
-
return this.hadSavedSyncOnLoad;
|
|
147
|
-
}
|
|
148
|
-
hasSavedSyncFromCleanShutdown() {
|
|
149
|
-
return this.hadCleanShutdownOnLoad;
|
|
150
|
-
}
|
|
151
|
-
getSavedSync() {
|
|
152
|
-
return Promise.resolve(this.savedSync ? cloneJson(this.savedSync) : null);
|
|
153
|
-
}
|
|
154
|
-
getSavedSyncToken() {
|
|
155
|
-
return Promise.resolve(this.savedSync?.nextBatch ?? null);
|
|
156
|
-
}
|
|
157
|
-
setSyncData(syncData) {
|
|
158
|
-
if (this.frozen) return Promise.resolve();
|
|
159
|
-
this.accumulator.accumulate(syncData);
|
|
160
|
-
this.savedSync = this.accumulator.getJSON();
|
|
161
|
-
this.markDirtyAndSchedulePersist();
|
|
162
|
-
return Promise.resolve();
|
|
163
|
-
}
|
|
164
|
-
getClientOptions() {
|
|
165
|
-
return Promise.resolve(this.savedClientOptions ? cloneJson(this.savedClientOptions) : void 0);
|
|
166
|
-
}
|
|
167
|
-
storeClientOptions(options) {
|
|
168
|
-
if (this.frozen) return Promise.resolve();
|
|
169
|
-
this.savedClientOptions = cloneJson(options);
|
|
170
|
-
super.storeClientOptions(options);
|
|
171
|
-
this.markDirtyAndSchedulePersist();
|
|
172
|
-
return Promise.resolve();
|
|
173
|
-
}
|
|
174
|
-
save(force = false) {
|
|
175
|
-
if (force) return this.flush();
|
|
176
|
-
return Promise.resolve();
|
|
177
|
-
}
|
|
178
|
-
wantsSave() {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
async deleteAllData() {
|
|
182
|
-
this.assertStoreAvailable();
|
|
183
|
-
if (this.persistTimer) {
|
|
184
|
-
clearTimeout(this.persistTimer);
|
|
185
|
-
this.persistTimer = null;
|
|
186
|
-
}
|
|
187
|
-
this.dirty = false;
|
|
188
|
-
await this.persistPromise?.catch(() => void 0);
|
|
189
|
-
await super.deleteAllData();
|
|
190
|
-
this.savedSync = null;
|
|
191
|
-
this.savedClientOptions = void 0;
|
|
192
|
-
this.cleanShutdown = false;
|
|
193
|
-
this.store.delete(metaKey(this.stateKey));
|
|
194
|
-
for (const row of this.store.entries()) if (row.key.startsWith(chunkKeyPrefix(this.stateKey))) this.store.delete(row.key);
|
|
195
|
-
await fs.rm(resolveLegacySyncCachePath(this.storageRootDir), { force: true }).catch(() => void 0);
|
|
196
|
-
}
|
|
197
|
-
markCleanShutdown() {
|
|
198
|
-
this.cleanShutdown = true;
|
|
199
|
-
this.dirty = true;
|
|
200
|
-
}
|
|
201
|
-
async freezeSyncCursorPersistence() {
|
|
202
|
-
this.frozen = true;
|
|
203
|
-
if (this.persistTimer) {
|
|
204
|
-
clearTimeout(this.persistTimer);
|
|
205
|
-
this.persistTimer = null;
|
|
206
|
-
}
|
|
207
|
-
await this.persistPromise;
|
|
208
|
-
}
|
|
209
|
-
discardPendingSyncCursorPersistence() {
|
|
210
|
-
this.frozen = true;
|
|
211
|
-
if (this.persistTimer) {
|
|
212
|
-
clearTimeout(this.persistTimer);
|
|
213
|
-
this.persistTimer = null;
|
|
214
|
-
}
|
|
215
|
-
this.cleanShutdown = false;
|
|
216
|
-
this.dirty = false;
|
|
217
|
-
}
|
|
218
|
-
async flush() {
|
|
219
|
-
if (this.persistTimer) {
|
|
220
|
-
clearTimeout(this.persistTimer);
|
|
221
|
-
this.persistTimer = null;
|
|
222
|
-
}
|
|
223
|
-
while (this.dirty || this.persistPromise) {
|
|
224
|
-
if (this.dirty && !this.persistPromise) this.persistPromise = this.persist().finally(() => {
|
|
225
|
-
this.persistPromise = null;
|
|
226
|
-
});
|
|
227
|
-
await this.persistPromise;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
markDirtyAndSchedulePersist() {
|
|
231
|
-
if (this.frozen) return;
|
|
232
|
-
this.cleanShutdown = false;
|
|
233
|
-
this.dirty = true;
|
|
234
|
-
if (this.persistTimer) return;
|
|
235
|
-
this.persistTimer = setTimeout(() => {
|
|
236
|
-
this.persistTimer = null;
|
|
237
|
-
this.flush().catch((err) => {
|
|
238
|
-
LogService.warn("MatrixSyncCacheStore", "Failed to persist Matrix sync store:", err);
|
|
239
|
-
});
|
|
240
|
-
}, PERSIST_DEBOUNCE_MS);
|
|
241
|
-
this.persistTimer.unref?.();
|
|
242
|
-
}
|
|
243
|
-
async persist() {
|
|
244
|
-
this.assertStoreAvailable();
|
|
245
|
-
this.dirty = false;
|
|
246
|
-
const payload = {
|
|
247
|
-
version: STORE_VERSION,
|
|
248
|
-
savedSync: this.savedSync ? cloneJson(this.savedSync) : null,
|
|
249
|
-
cleanShutdown: this.cleanShutdown,
|
|
250
|
-
...this.savedClientOptions ? { clientOptions: cloneJson(this.savedClientOptions) } : {}
|
|
251
|
-
};
|
|
252
|
-
try {
|
|
253
|
-
await this.persistLock(async () => {
|
|
254
|
-
this.writePersistedStore(payload);
|
|
255
|
-
claimCurrentTokenStorageState({ rootDir: this.storageRootDir });
|
|
256
|
-
});
|
|
257
|
-
} catch (err) {
|
|
258
|
-
this.dirty = true;
|
|
259
|
-
throw err;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
writePersistedStore(payload) {
|
|
263
|
-
const rows = buildSyncCacheRows(this.stateKey, payload);
|
|
264
|
-
for (const row of rows.chunks) this.store.register(row.key, row.value);
|
|
265
|
-
this.store.register(rows.meta.key, rows.meta.value);
|
|
266
|
-
for (const row of this.store.entries()) if (row.key.startsWith(chunkKeyPrefix(this.stateKey)) && !rows.nextChunkKeys.has(row.key)) this.store.delete(row.key);
|
|
267
|
-
}
|
|
268
|
-
assertStoreAvailable() {
|
|
269
|
-
if (this.storeUnavailableError == null) return;
|
|
270
|
-
throw new Error("Matrix sync cache SQLite store is unavailable; cannot persist sync state", { cause: this.storeUnavailableError });
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
function createNoopMatrixSyncCacheStore() {
|
|
274
|
-
return {
|
|
275
|
-
register: () => {},
|
|
276
|
-
registerIfAbsent: () => false,
|
|
277
|
-
lookup: () => void 0,
|
|
278
|
-
consume: () => void 0,
|
|
279
|
-
delete: () => false,
|
|
280
|
-
entries: () => [],
|
|
281
|
-
clear: () => {}
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
function readPersistedStoreFromSyncStore(store, stateKey) {
|
|
285
|
-
const meta = store.lookup(metaKey(stateKey));
|
|
286
|
-
if (!isSyncCacheMeta(meta)) return null;
|
|
287
|
-
const chunks = [];
|
|
288
|
-
for (let index = 0; index < meta.chunkCount; index += 1) {
|
|
289
|
-
const chunk = store.lookup(chunkKey(stateKey, meta.generation, index));
|
|
290
|
-
if (!isSyncCacheChunk(chunk) || chunk.index !== index) return normalizePersistedStore({
|
|
291
|
-
version: STORE_VERSION,
|
|
292
|
-
savedSync: null,
|
|
293
|
-
clientOptions: meta.clientOptions,
|
|
294
|
-
cleanShutdown: false
|
|
295
|
-
});
|
|
296
|
-
chunks.push(chunk.data);
|
|
297
|
-
}
|
|
298
|
-
let savedSync = null;
|
|
299
|
-
if (chunks.length > 0) {
|
|
300
|
-
const syncJson = chunks.join("");
|
|
301
|
-
if (meta.syncDigest !== digestText(syncJson)) return normalizePersistedStore({
|
|
302
|
-
version: STORE_VERSION,
|
|
303
|
-
savedSync: null,
|
|
304
|
-
clientOptions: meta.clientOptions,
|
|
305
|
-
cleanShutdown: false
|
|
306
|
-
});
|
|
307
|
-
try {
|
|
308
|
-
savedSync = toPersistedSyncData(JSON.parse(syncJson));
|
|
309
|
-
} catch {
|
|
310
|
-
savedSync = null;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return normalizePersistedStore({
|
|
314
|
-
version: STORE_VERSION,
|
|
315
|
-
savedSync,
|
|
316
|
-
clientOptions: meta.clientOptions,
|
|
317
|
-
cleanShutdown: meta.cleanShutdown
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
function openMatrixSyncCacheStore(storageRootDir) {
|
|
321
|
-
return getMatrixRuntime().state.openSyncKeyedStore(openMatrixSyncCacheStoreOptions(storageRootDir));
|
|
322
|
-
}
|
|
323
|
-
function metaKey(stateKey) {
|
|
324
|
-
return `${stateKey}:meta`;
|
|
325
|
-
}
|
|
326
|
-
function chunkKeyPrefix(stateKey) {
|
|
327
|
-
return `${stateKey}:sync:`;
|
|
328
|
-
}
|
|
329
|
-
function chunkKey(stateKey, generation, index) {
|
|
330
|
-
return `${chunkKeyPrefix(stateKey)}${generation}:${index}`;
|
|
331
|
-
}
|
|
332
|
-
function resolveLegacySyncCachePath(storageRootDir) {
|
|
333
|
-
return path.join(storageRootDir, "bot-storage.json");
|
|
334
|
-
}
|
|
335
|
-
function digestText(value) {
|
|
336
|
-
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
337
|
-
}
|
|
338
|
-
function isSyncCacheMeta(value) {
|
|
339
|
-
return isRecord(value) && value.kind === "meta" && value.version === STORE_VERSION && typeof value.generation === "string" && value.generation.trim() !== "" && typeof value.chunkCount === "number" && Number.isSafeInteger(value.chunkCount) && value.chunkCount >= 0 && value.chunkCount <= SYNC_CACHE_MAX_CHUNKS;
|
|
340
|
-
}
|
|
341
|
-
function isSyncCacheChunk(value) {
|
|
342
|
-
return isRecord(value) && value.kind === "sync-chunk" && typeof value.index === "number" && Number.isSafeInteger(value.index) && value.index >= 0 && typeof value.data === "string";
|
|
343
|
-
}
|
|
344
|
-
function chunkSyncCacheJson(value) {
|
|
345
|
-
const chunks = [];
|
|
346
|
-
const pushChunk = (chunk) => {
|
|
347
|
-
if (chunks.length >= SYNC_CACHE_MAX_CHUNKS) throw new Error("Matrix sync cache exceeds SQLite chunk limit");
|
|
348
|
-
chunks.push(chunk);
|
|
349
|
-
};
|
|
350
|
-
let current = "";
|
|
351
|
-
let currentBytes = 0;
|
|
352
|
-
for (const char of value) {
|
|
353
|
-
const charBytes = Buffer.byteLength(char, "utf8");
|
|
354
|
-
if (current && currentBytes + charBytes > SYNC_CACHE_CHUNK_BYTES) {
|
|
355
|
-
pushChunk(current);
|
|
356
|
-
current = "";
|
|
357
|
-
currentBytes = 0;
|
|
358
|
-
}
|
|
359
|
-
current += char;
|
|
360
|
-
currentBytes += charBytes;
|
|
361
|
-
}
|
|
362
|
-
if (current) pushChunk(current);
|
|
363
|
-
return chunks;
|
|
364
|
-
}
|
|
365
|
-
function buildSyncCacheRows(stateKey, payload) {
|
|
366
|
-
const generation = randomUUID().replaceAll("-", "");
|
|
367
|
-
const syncJson = payload.savedSync ? JSON.stringify(payload.savedSync) : "";
|
|
368
|
-
const chunks = (syncJson ? chunkSyncCacheJson(syncJson) : []).map((data, index) => ({
|
|
369
|
-
key: chunkKey(stateKey, generation, index),
|
|
370
|
-
value: {
|
|
371
|
-
kind: "sync-chunk",
|
|
372
|
-
index,
|
|
373
|
-
data
|
|
374
|
-
}
|
|
375
|
-
}));
|
|
376
|
-
return {
|
|
377
|
-
chunks,
|
|
378
|
-
nextChunkKeys: new Set(chunks.map((chunk) => chunk.key)),
|
|
379
|
-
meta: {
|
|
380
|
-
key: metaKey(stateKey),
|
|
381
|
-
value: {
|
|
382
|
-
kind: "meta",
|
|
383
|
-
version: STORE_VERSION,
|
|
384
|
-
generation,
|
|
385
|
-
chunkCount: chunks.length,
|
|
386
|
-
...syncJson ? { syncDigest: digestText(syncJson) } : {},
|
|
387
|
-
...payload.clientOptions ? { clientOptions: payload.clientOptions } : {},
|
|
388
|
-
cleanShutdown: payload.cleanShutdown === true
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
async function readLegacyMatrixSyncCacheState(storageRootDir) {
|
|
394
|
-
try {
|
|
395
|
-
const raw = await fs.readFile(resolveLegacySyncCachePath(storageRootDir), "utf8");
|
|
396
|
-
const persisted = normalizeLegacyPersistedStore(JSON.parse(raw));
|
|
397
|
-
if (!persisted?.savedSync && !persisted?.clientOptions) return null;
|
|
398
|
-
return persisted;
|
|
399
|
-
} catch {
|
|
400
|
-
return null;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
async function hasMatrixSyncCacheStateInStore(params) {
|
|
404
|
-
const stateKey = SYNC_CACHE_STATE_KEY;
|
|
405
|
-
const meta = await params.store.lookup(metaKey(stateKey));
|
|
406
|
-
if (!isSyncCacheMeta(meta) || meta.chunkCount <= 0) return false;
|
|
407
|
-
const chunks = [];
|
|
408
|
-
for (let index = 0; index < meta.chunkCount; index += 1) {
|
|
409
|
-
const chunk = await params.store.lookup(chunkKey(stateKey, meta.generation, index));
|
|
410
|
-
if (!isSyncCacheChunk(chunk) || chunk.index !== index) return false;
|
|
411
|
-
chunks.push(chunk.data);
|
|
412
|
-
}
|
|
413
|
-
const syncJson = chunks.join("");
|
|
414
|
-
if (meta.syncDigest !== digestText(syncJson)) return false;
|
|
415
|
-
try {
|
|
416
|
-
return toPersistedSyncData(JSON.parse(syncJson)) !== null;
|
|
417
|
-
} catch {
|
|
418
|
-
return false;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
async function writeMatrixSyncCacheStateToStore(params) {
|
|
422
|
-
const stateKey = SYNC_CACHE_STATE_KEY;
|
|
423
|
-
const rows = buildSyncCacheRows(stateKey, params.payload);
|
|
424
|
-
for (const row of rows.chunks) await params.store.register(row.key, row.value);
|
|
425
|
-
await params.store.register(rows.meta.key, rows.meta.value);
|
|
426
|
-
for (const row of await params.store.entries()) if (row.key.startsWith(chunkKeyPrefix(stateKey)) && !rows.nextChunkKeys.has(row.key)) await params.store.delete(row.key);
|
|
427
|
-
}
|
|
428
|
-
function openMatrixSyncCacheStoreOptions(storageRootDir) {
|
|
429
|
-
return {
|
|
430
|
-
namespace: SYNC_CACHE_NAMESPACE,
|
|
431
|
-
maxEntries: SYNC_CACHE_MAX_ENTRIES,
|
|
432
|
-
env: resolveMatrixSqliteStateEnv({ stateDir: storageRootDir })
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
//#endregion
|
|
436
|
-
export { readLegacyMatrixSyncCacheState as a, openMatrixSyncCacheStoreOptions as i, file_sync_store_exports as n, writeMatrixSyncCacheStateToStore as o, hasMatrixSyncCacheStateInStore as r, SqliteBackedMatrixSyncStore as t };
|