@openclaw/matrix 2026.9.1-beta.1 → 2026.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{account-config-BZWN9tGS.js → account-config-CRsKoMqJ.js} +1 -1
- package/dist/{account-selection-CWuhuFn1.js → account-selection-DA-jfx22.js} +74 -36
- package/dist/{accounts-BCzyubQt.js → accounts-DR1c4xF_.js} +4 -5
- package/dist/api.js +5 -5
- package/dist/{approval-handler.runtime-G9fLHUWe.js → approval-handler.runtime-BJCD4dLf.js} +34 -11
- package/dist/{approval-ids-C6FD3pVY.js → approval-ids-Bst7HM_o.js} +1 -1
- package/dist/{approval-reaction-auth-60xHiDtQ.js → approval-reaction-auth-DhH8QOSe.js} +2 -2
- package/dist/{approval-reactions-tXh9KYrW.js → approval-reactions-1fwEhoK9.js} +1 -1
- package/dist/{channel-CBEvelTE.js → channel-Bs8VLb6q.js} +63 -58
- package/dist/channel-plugin-api.js +1 -1
- package/dist/channel.runtime-CCJRhdH5.js +76 -0
- package/dist/{channel.setup-sWPOGyQG.js → channel.setup-DhmDXwPp.js} +32 -22
- package/dist/{cli-DrTD2a_q.js → cli-IvDUuiDH.js} +179 -135
- package/dist/{cli-metadata-DrYVwQ_r.js → cli-metadata-BGryAl2e.js} +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/{client-hs1ePy2O.js → client-Dj4mcf-s.js} +73 -22
- package/dist/{client-bootstrap-BxdxjCwA.js → client-bootstrap-n1Rqc8Go.js} +1 -1
- package/dist/{client-BUtHbzib.js → client-oNOlldJI.js} +2 -2
- package/dist/{config-update-Bor_Pjsv.js → config-update-BnX26jCO.js} +48 -31
- package/dist/contract-api.js +2 -2
- package/dist/{credentials-BdAaWuiR.js → credentials-DJj2xs3q.js} +4 -8
- package/dist/{credentials-read-B37cQknZ.js → credentials-read-mexhw-Ur.js} +7 -5
- package/dist/{credentials-write.runtime-nAV2-5uR.js → credentials-write.runtime-DQt-kgJq.js} +1 -1
- package/dist/{crypto-runtime-C4WDYxlP.js → crypto-runtime-m1eplj3b.js} +7 -7
- package/dist/crypto-snapshot-doctor.runtime-D0v841D_.js +91 -0
- package/dist/{deps-CcVJfvRM.js → deps-mtxF2mHI.js} +1 -1
- package/dist/{directory-live-D0KfJlby.js → directory-live-DLUgWBhA.js} +8 -6
- package/dist/{doctor-EWf9CDso.js → doctor-CJE8wO6y.js} +1 -1
- package/dist/{doctor-contract-DEt4O4Zt.js → doctor-contract-HyWFZQVG.js} +5 -4
- package/dist/doctor-contract-api.js +89 -109
- package/dist/{draft-stream-B_m79Ynb.js → draft-stream-DglwxWzJ.js} +1 -1
- package/dist/{encryption-guidance-DmLY8NiO.js → encryption-guidance-BNcZNQZI.js} +3 -2
- package/dist/helper-api.js +1 -1
- package/dist/{http-client-D8o8b9u6.js → http-client-DOmFvKvB.js} +10 -7
- package/dist/{idb-persistence-DfgW720p.js → idb-persistence-CU7CNLlX.js} +2 -2
- package/dist/{idb-persistence-lock-DAJ49nZX.js → idb-persistence-lock-B3fZXyF_.js} +1 -1
- package/dist/{inbound-dedupe-RvSLqdsz.js → inbound-dedupe-Ch33GU06.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/{messages-Dow9EOoJ.js → messages-Czn8lNEh.js} +154 -5
- package/dist/{monitor-DBB47wTy.js → monitor-DouG43FJ.js} +200 -156
- package/dist/outbound-Co_tJyE6.js +220 -0
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- package/dist/probe.runtime-B1YPxG9x.js +2 -0
- package/dist/{profile-update-C61NR24_.js → profile-update-CAl8nZNG.js} +5 -4
- package/dist/{profile-D-Wubo0A.js → profile-vmjsmhh4.js} +1 -1
- package/dist/{reaction-events-BZUgLIZI.js → reaction-events-C_7G7bvI.js} +9 -7
- package/dist/{resolve-targets-DXzZwsIY.js → resolve-targets-B64O69Nd.js} +1 -1
- package/dist/{resolver.runtime-p5qJ3Kst.js → resolver.runtime-TRmePJDV.js} +1 -1
- package/dist/{room-info-BXQA7y10.js → room-info-6viLR3NH.js} +55 -1
- package/dist/runtime-api.js +2 -2
- package/dist/{sdk-CljOKEvc.js → sdk-C1yfda1L.js} +534 -26
- package/dist/{send-BKu9Ghi4.js → send-B5XChnvB.js} +31 -33
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/{setup-bootstrap-CpE6C3qV.js → setup-bootstrap-S_loyUyM.js} +3 -3
- package/dist/{setup-core-CyvaCOOr.js → setup-core-XkIfQ65J.js} +8 -7
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-DtRvRcCT.js → setup-surface-B2yZ8KGc.js} +84 -79
- package/dist/{startup-verification-Cs08ca8u.js → startup-verification-1Ney1mmI.js} +2 -2
- package/dist/{storage-BsGuHngK.js → storage-BVf4uucD.js} +5 -4
- package/dist/{subagent-hooks-CMoZaARG.js → subagent-hooks-DeICLbU5.js} +5 -1
- package/dist/subagent-hooks-api.js +1 -1
- package/dist/sync-cache-state-d-A_OhbU.js +234 -0
- package/dist/{thread-bindings-BvyU66kE.js → thread-bindings-BkBnn4te.js} +4 -4
- package/dist/{tool-actions.runtime-DD6jUxFK.js → tool-actions.runtime-a5L5xGSP.js} +226 -215
- package/dist/{verification-BP-3-XYn.js → verification-XJtTc5DI.js} +2 -2
- 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/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/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 +17 -3
- package/package.json +8 -7
- package/dist/channel.runtime-CiDl9deX.js +0 -276
- package/dist/env-auth-MVS-Vv41.js +0 -64
- package/dist/file-sync-store-DjskBX2o.js +0 -436
- package/dist/media-text-OR9uoC4W.js +0 -153
- package/dist/probe.runtime-CRM7RIrB.js +0 -2
- package/dist/recovery-key-store-CognuDys.js +0 -276
|
@@ -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 };
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { _ as parsePollStartContent, d as buildPollResultsSummary, f as formatPollAsText, h as isPollStartType, m as isPollEventType, p as formatPollResultsAsText, v as resolvePollReferenceEventId } from "./send-BKu9Ghi4.js";
|
|
2
|
-
import { asNullableObjectRecord, asNullableRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
//#region extensions/matrix/src/matrix/poll-summary.ts
|
|
5
|
-
function resolveMatrixPollRootEventId(event) {
|
|
6
|
-
if (isPollStartType(event.type)) {
|
|
7
|
-
const eventId = event.event_id?.trim();
|
|
8
|
-
return eventId ? eventId : null;
|
|
9
|
-
}
|
|
10
|
-
return resolvePollReferenceEventId(event.content);
|
|
11
|
-
}
|
|
12
|
-
async function readAllPollRelations(client, roomId, pollEventId) {
|
|
13
|
-
const relationEvents = [];
|
|
14
|
-
const seenCursors = /* @__PURE__ */ new Set();
|
|
15
|
-
let nextBatch;
|
|
16
|
-
do {
|
|
17
|
-
const page = await client.getRelations(roomId, pollEventId, "m.reference", void 0, { from: nextBatch });
|
|
18
|
-
relationEvents.push(...page.events);
|
|
19
|
-
nextBatch = page.nextBatch ?? void 0;
|
|
20
|
-
if (nextBatch && seenCursors.has(nextBatch)) throw new Error("Matrix poll pagination returned a repeated cursor");
|
|
21
|
-
if (nextBatch) seenCursors.add(nextBatch);
|
|
22
|
-
} while (nextBatch);
|
|
23
|
-
return relationEvents;
|
|
24
|
-
}
|
|
25
|
-
async function fetchMatrixPollSnapshot(client, roomId, event) {
|
|
26
|
-
if (!isPollEventType(event.type)) return null;
|
|
27
|
-
const pollEventId = resolveMatrixPollRootEventId(event);
|
|
28
|
-
if (!pollEventId) return null;
|
|
29
|
-
const rootEvent = isPollStartType(event.type) ? event : await client.getEvent(roomId, pollEventId);
|
|
30
|
-
if (!isPollStartType(rootEvent.type)) return null;
|
|
31
|
-
const pollStartContent = rootEvent.content;
|
|
32
|
-
const pollSummary = parsePollStartContent(pollStartContent);
|
|
33
|
-
if (!pollSummary) return null;
|
|
34
|
-
const relationEvents = await readAllPollRelations(client, roomId, pollEventId);
|
|
35
|
-
const pollResults = buildPollResultsSummary({
|
|
36
|
-
pollEventId,
|
|
37
|
-
roomId,
|
|
38
|
-
sender: rootEvent.sender,
|
|
39
|
-
senderName: rootEvent.sender,
|
|
40
|
-
content: pollStartContent,
|
|
41
|
-
relationEvents
|
|
42
|
-
});
|
|
43
|
-
return {
|
|
44
|
-
pollEventId,
|
|
45
|
-
triggerEvent: event,
|
|
46
|
-
rootEvent,
|
|
47
|
-
text: pollResults ? formatPollResultsAsText(pollResults) : formatPollAsText(pollSummary)
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
async function fetchMatrixPollMessageSummary(client, roomId, event) {
|
|
51
|
-
const snapshot = await fetchMatrixPollSnapshot(client, roomId, event);
|
|
52
|
-
if (!snapshot) return null;
|
|
53
|
-
return {
|
|
54
|
-
eventId: snapshot.pollEventId,
|
|
55
|
-
sender: snapshot.rootEvent.sender,
|
|
56
|
-
body: snapshot.text,
|
|
57
|
-
msgtype: "m.text",
|
|
58
|
-
timestamp: snapshot.triggerEvent.origin_server_ts || snapshot.rootEvent.origin_server_ts
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region extensions/matrix/src/matrix/media-text.ts
|
|
63
|
-
const MATRIX_MEDIA_KINDS = {
|
|
64
|
-
"m.audio": "audio",
|
|
65
|
-
"m.file": "file",
|
|
66
|
-
"m.image": "image",
|
|
67
|
-
"m.sticker": "sticker",
|
|
68
|
-
"m.video": "video"
|
|
69
|
-
};
|
|
70
|
-
function resolveMatrixMediaKind(msgtype) {
|
|
71
|
-
return MATRIX_MEDIA_KINDS[msgtype ?? ""] ?? null;
|
|
72
|
-
}
|
|
73
|
-
function resolveMatrixMediaLabel(kind, fallback = "media") {
|
|
74
|
-
return `${kind ?? fallback} attachment`;
|
|
75
|
-
}
|
|
76
|
-
function formatMatrixAttachmentMarker(params) {
|
|
77
|
-
const label = resolveMatrixMediaLabel(params.kind);
|
|
78
|
-
if (params.tooLarge) return `[matrix ${label} too large]`;
|
|
79
|
-
return params.unavailable ? `[matrix ${label} unavailable]` : `[matrix ${label}]`;
|
|
80
|
-
}
|
|
81
|
-
function isLikelyBareFilename(text) {
|
|
82
|
-
const trimmed = text.trim();
|
|
83
|
-
if (!trimmed || trimmed.includes("\n") || /\s/.test(trimmed)) return false;
|
|
84
|
-
if (path.basename(trimmed) !== trimmed) return false;
|
|
85
|
-
return path.extname(trimmed).length > 1;
|
|
86
|
-
}
|
|
87
|
-
function resolveCaptionOrFilename(params) {
|
|
88
|
-
const body = params.body?.trim() ?? "";
|
|
89
|
-
const filename = params.filename?.trim() ?? "";
|
|
90
|
-
if (filename) {
|
|
91
|
-
if (!body || body === filename) return { filename };
|
|
92
|
-
return {
|
|
93
|
-
caption: body,
|
|
94
|
-
filename
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
if (!body) return {};
|
|
98
|
-
if (isLikelyBareFilename(body)) return { filename: body };
|
|
99
|
-
return { caption: body };
|
|
100
|
-
}
|
|
101
|
-
function resolveBundledMatrixReplacementContent(event) {
|
|
102
|
-
const replacement = asNullableObjectRecord(event.unsigned?.["m.relations"]?.["m.replace"]);
|
|
103
|
-
if (!replacement || event.state_key !== void 0) return;
|
|
104
|
-
const content = asNullableObjectRecord(replacement.content);
|
|
105
|
-
const relation = asNullableObjectRecord(content?.["m.relates_to"]);
|
|
106
|
-
const newContent = content?.["m.new_content"];
|
|
107
|
-
if (replacement.sender !== event.sender || replacement.type !== event.type || replacement.state_key !== void 0 || asNullableObjectRecord(replacement.unsigned)?.redacted_because || !relation || relation.rel_type !== "m.replace" || relation.event_id !== event.event_id) return;
|
|
108
|
-
return asNullableRecord(newContent) ?? void 0;
|
|
109
|
-
}
|
|
110
|
-
function resolveMatrixMessageAttachment(params) {
|
|
111
|
-
const kind = resolveMatrixMediaKind(params.msgtype);
|
|
112
|
-
if (!kind) return;
|
|
113
|
-
const resolved = resolveCaptionOrFilename(params);
|
|
114
|
-
return {
|
|
115
|
-
kind,
|
|
116
|
-
caption: resolved.caption,
|
|
117
|
-
filename: resolved.filename
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function formatMatrixAttachmentText(params) {
|
|
121
|
-
if (!params.attachment) return;
|
|
122
|
-
return formatMatrixAttachmentMarker({
|
|
123
|
-
kind: params.attachment.kind,
|
|
124
|
-
tooLarge: params.tooLarge,
|
|
125
|
-
unavailable: params.unavailable
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function formatMatrixMessageText(params) {
|
|
129
|
-
const attachment = resolveMatrixMessageAttachment(params);
|
|
130
|
-
const body = attachment ? attachment.caption ?? "" : params.body?.trim() ?? "";
|
|
131
|
-
const marker = formatMatrixAttachmentText({
|
|
132
|
-
attachment,
|
|
133
|
-
tooLarge: params.tooLarge,
|
|
134
|
-
unavailable: params.unavailable
|
|
135
|
-
});
|
|
136
|
-
if (!marker) return body || void 0;
|
|
137
|
-
if (!body) return marker;
|
|
138
|
-
return `${body}\n\n${marker}`;
|
|
139
|
-
}
|
|
140
|
-
function formatMatrixMediaUnavailableText(params) {
|
|
141
|
-
return formatMatrixMessageText({
|
|
142
|
-
...params,
|
|
143
|
-
unavailable: true
|
|
144
|
-
}) ?? "";
|
|
145
|
-
}
|
|
146
|
-
function formatMatrixMediaTooLargeText(params) {
|
|
147
|
-
return formatMatrixMessageText({
|
|
148
|
-
...params,
|
|
149
|
-
tooLarge: true
|
|
150
|
-
}) ?? "";
|
|
151
|
-
}
|
|
152
|
-
//#endregion
|
|
153
|
-
export { resolveBundledMatrixReplacementContent as a, fetchMatrixPollSnapshot as c, isLikelyBareFilename as i, resolveMatrixPollRootEventId as l, formatMatrixMediaUnavailableText as n, resolveMatrixMessageAttachment as o, formatMatrixMessageText as r, fetchMatrixPollMessageSummary as s, formatMatrixMediaTooLargeText as t };
|