@openclaw/matrix 2026.7.2-beta.1 → 2026.7.2-beta.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.
Files changed (76) hide show
  1. package/dist/{account-selection-Bz00QTmQ.js → account-selection-kqquRzCf.js} +5 -5
  2. package/dist/api.js +6 -6
  3. package/dist/{approval-handler.runtime--Ei44Vo2.js → approval-handler.runtime-BEa98wwG.js} +5 -5
  4. package/dist/{approval-ids-C_2kSMdJ.js → approval-ids-Dfn7oQAm.js} +1 -1
  5. package/dist/{approval-reaction-auth-TdVPcgxP.js → approval-reaction-auth-kXkCJBGi.js} +2 -2
  6. package/dist/{approval-reactions-BgU51JGd.js → approval-reactions-D-BxBK_L.js} +1 -1
  7. package/dist/auth-presence.js +13 -21
  8. package/dist/{channel-CxqDh7mS.js → channel-j331Xd7b.js} +14 -13
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/{channel.runtime-wNfJc57I.js → channel.runtime-BIwlVfQw.js} +15 -16
  11. package/dist/{cli-o00oTJhx.js → cli-0EcKfqFw.js} +25 -15
  12. package/dist/{cli-metadata-Gf3HSJ2c.js → cli-metadata-Xq1Xb15R.js} +1 -1
  13. package/dist/cli-metadata.js +1 -1
  14. package/dist/{client-ClHisZbf.js → client-BtG4quUl.js} +2 -2
  15. package/dist/{client-DP0nmFxK.js → client-CA0PULls.js} +2 -2
  16. package/dist/{client-bootstrap-PqYOS-mO.js → client-bootstrap-Dk5EAn3n.js} +1 -1
  17. package/dist/{config-schema-CG9goLWp.js → config-schema-B5GRV8wL.js} +8 -10
  18. package/dist/contract-api.js +2 -2
  19. package/dist/{create-client-D9z9RjCM.js → create-client-WQExaby_.js} +4 -4
  20. package/dist/credentials-W2EmwRhu.js +65 -0
  21. package/dist/credentials-read-DVmFCm7X.js +77 -0
  22. package/dist/{credentials-write.runtime-J_EUt5WP.js → credentials-write.runtime-Be9zNSUw.js} +1 -1
  23. package/dist/{crypto-runtime-BHcxauC4.js → crypto-runtime-CAff-n15.js} +4 -4
  24. package/dist/{directory-live-DPy2aaPF.js → directory-live-DiC-0XBC.js} +3 -3
  25. package/dist/{doctor-BGTs609f.js → doctor-DwUVm5Lw.js} +1 -1
  26. package/dist/{doctor-contract-D2qTLe-C.js → doctor-contract-BA2Y6Crx.js} +1 -1
  27. package/dist/doctor-contract-api.js +117 -11
  28. package/dist/{draft-stream-De7uikGn.js → draft-stream-CTLKtJJ0.js} +1 -1
  29. package/dist/{encryption-guidance-BFfgq7c7.js → encryption-guidance-CbEFe38F.js} +1 -1
  30. package/dist/{file-sync-store-Cxb0ckyX.js → file-sync-store-CPkgnSXp.js} +23 -6
  31. package/dist/helper-api.js +2 -2
  32. package/dist/{http-client-W4TJQM6r.js → http-client-BmrgOZTL.js} +2 -2
  33. package/dist/{idb-persistence-iUZoHZkp.js → idb-persistence-Dyy6ipgU.js} +3 -3
  34. package/dist/{inbound-dedupe-DcMs0YXL.js → inbound-dedupe-CaBLblef.js} +19 -38
  35. package/dist/index.js +1 -1
  36. package/dist/{logger-BMClpI5b.js → logger-D0GCSDQq.js} +1 -1
  37. package/dist/{logging-CFJrbDAN.js → logging-QH-48Gr6.js} +1 -1
  38. package/dist/{media-text-DWaotsZB.js → media-text-BMXEXb1j.js} +1 -1
  39. package/dist/{messages-Dm3K4ZvM.js → messages-3UBHfZrN.js} +3 -3
  40. package/dist/{monitor-C_kgPPeV.js → monitor-BtUIds8T.js} +135 -136
  41. package/dist/plugin-entry.handlers.runtime.js +1 -1
  42. package/dist/probe.runtime-sBV-Govx.js +3 -0
  43. package/dist/{profile-update-iUHCoks3.js → profile-update-Bh2XtJwN.js} +3 -3
  44. package/dist/{reaction-events-0tubdHRM.js → reaction-events-BwAKtUyQ.js} +3 -3
  45. package/dist/record-shared-CWWx6fvI.js +2 -0
  46. package/dist/{recovery-key-store-Bx0zTJcB.js → recovery-key-store-CW6eePfp.js} +2 -2
  47. package/dist/{resolve-targets-DlLrfWDy.js → resolve-targets-DVoj-YxB.js} +1 -1
  48. package/dist/{resolver.runtime-MeaT1zXx.js → resolver.runtime-CC0VVsAt.js} +1 -1
  49. package/dist/{runtime-CveSqMOP.js → runtime-6S3DNFNv.js} +1 -1
  50. package/dist/runtime-api.js +6 -6
  51. package/dist/runtime-setter-api.js +1 -1
  52. package/dist/{sdk-CI8E2TKg.js → sdk-CIDZXWpZ.js} +7 -7
  53. package/dist/{secret-contract-OZoQf0kI.js → secret-contract-M3hRmGO-.js} +21 -5
  54. package/dist/secret-contract-api.js +1 -1
  55. package/dist/{send-C7xuGWpv.js → send-BJbrdmNm.js} +4 -3
  56. package/dist/session-binding-contract-api.js +2 -2
  57. package/dist/{setup-bootstrap-CCsexWTZ.js → setup-bootstrap-DGPOOdz-.js} +2 -2
  58. package/dist/{setup-core-DlmTyIP0.js → setup-core-XCdAx1nY.js} +3 -3
  59. package/dist/setup-plugin-api.js +3 -3
  60. package/dist/{setup-surface-2SS94JV0.js → setup-surface-CzUiTe_k.js} +6 -6
  61. package/dist/{shared-DgvN5rBx.js → shared-DquM1oz6.js} +7 -7
  62. package/dist/{startup-verification-CbIyF7z1.js → startup-verification-CA00kebL.js} +3 -3
  63. package/dist/{storage-BtSOar8T.js → storage-CzHxeF5E.js} +9 -9
  64. package/dist/{thread-bindings-BI8MHWp9.js → thread-bindings-Cw194yEn.js} +4 -4
  65. package/dist/{tool-actions.runtime-CnyhVPoY.js → tool-actions.runtime-C0jgWYhX.js} +19 -15
  66. package/dist/{verification-DLSe3sP7.js → verification-DjxyWTNP.js} +2 -2
  67. package/npm-shrinkwrap.json +3 -3
  68. package/openclaw.plugin.json +70 -70
  69. package/package.json +4 -4
  70. package/dist/async-lock-BcLS4KOc.js +0 -19
  71. package/dist/credentials-DnhsLAuR.js +0 -56
  72. package/dist/credentials-read-BtS-HRT5.js +0 -112
  73. package/dist/probe.runtime-Dry8PTWC.js +0 -3
  74. package/dist/record-shared-CvzjvHRn.js +0 -2
  75. package/dist/{deps-DDbghaZH.js → deps-CcVJfvRM.js} +1 -1
  76. package/dist/{storage-paths-B4_I9iqO.js → storage-paths-gUmSydsW.js} +1 -1
@@ -0,0 +1,77 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { n as getOptionalMatrixRuntime } from "./runtime-6S3DNFNv.js";
3
+ import "./storage-paths-gUmSydsW.js";
4
+ import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
5
+ import { createPluginStateSyncKeyedStore } from "openclaw/plugin-sdk/runtime-doctor";
6
+ //#region extensions/matrix/src/matrix/credentials-read.ts
7
+ var credentials_read_exports = /* @__PURE__ */ __exportAll({
8
+ MATRIX_CREDENTIALS_MAX_ENTRIES: () => 256,
9
+ MATRIX_CREDENTIALS_NAMESPACE: () => MATRIX_CREDENTIALS_NAMESPACE,
10
+ clearMatrixCredentials: () => clearMatrixCredentials,
11
+ credentialsMatchConfig: () => credentialsMatchConfig,
12
+ isMatrixCredentialRevocation: () => isMatrixCredentialRevocation,
13
+ loadMatrixCredentials: () => loadMatrixCredentials,
14
+ matrixCredentialsStoreKey: () => matrixCredentialsStoreKey,
15
+ normalizeMatrixStoredCredentials: () => normalizeMatrixStoredCredentials,
16
+ openMatrixCredentialsStore: () => openMatrixCredentialsStore
17
+ });
18
+ const MATRIX_CREDENTIALS_NAMESPACE = "credentials";
19
+ function matrixCredentialsStoreKey(accountId) {
20
+ return `account:${normalizeAccountId(accountId)}`;
21
+ }
22
+ function normalizeMatrixStoredCredentials(value, accountId) {
23
+ if (!value || typeof value !== "object") return null;
24
+ const parsed = value;
25
+ if (typeof parsed.homeserver !== "string" || !parsed.homeserver || typeof parsed.userId !== "string" || !parsed.userId || typeof parsed.accessToken !== "string" || !parsed.accessToken || typeof parsed.createdAt !== "string" || !parsed.createdAt) return null;
26
+ return {
27
+ accountId: normalizeAccountId(accountId ?? parsed.accountId),
28
+ homeserver: parsed.homeserver,
29
+ userId: parsed.userId,
30
+ accessToken: parsed.accessToken,
31
+ ...typeof parsed.deviceId === "string" ? { deviceId: parsed.deviceId } : {},
32
+ createdAt: parsed.createdAt,
33
+ ...typeof parsed.lastUsedAt === "string" ? { lastUsedAt: parsed.lastUsedAt } : {}
34
+ };
35
+ }
36
+ function isMatrixCredentialRevocation(value, accountId) {
37
+ if (!value || typeof value !== "object") return false;
38
+ const parsed = value;
39
+ return parsed.kind === "revoked" && typeof parsed.revokedAt === "string" && parsed.revokedAt.length > 0 && normalizeAccountId(parsed.accountId) === normalizeAccountId(accountId ?? parsed.accountId);
40
+ }
41
+ function openMatrixCredentialsStore(env = process.env) {
42
+ const runtime = getOptionalMatrixRuntime();
43
+ const resolvedEnv = env.OPENCLAW_STATE_DIR?.trim() || !runtime ? env : {
44
+ ...env,
45
+ OPENCLAW_STATE_DIR: runtime.state.resolveStateDir(env)
46
+ };
47
+ return createPluginStateSyncKeyedStore("matrix", {
48
+ namespace: MATRIX_CREDENTIALS_NAMESPACE,
49
+ maxEntries: 256,
50
+ overflowPolicy: "reject-new",
51
+ env: resolvedEnv
52
+ });
53
+ }
54
+ function loadMatrixCredentials(env = process.env, accountId) {
55
+ const normalizedAccountId = normalizeAccountId(accountId);
56
+ const parsed = normalizeMatrixStoredCredentials(openMatrixCredentialsStore(env).lookup(matrixCredentialsStoreKey(accountId)), normalizedAccountId);
57
+ if (!parsed || parsed.accountId !== normalizedAccountId) return null;
58
+ const { accountId: _accountId, ...credentials } = parsed;
59
+ return credentials;
60
+ }
61
+ function clearMatrixCredentials(env = process.env, accountId) {
62
+ const normalizedAccountId = normalizeAccountId(accountId);
63
+ openMatrixCredentialsStore(env).register(matrixCredentialsStoreKey(normalizedAccountId), {
64
+ accountId: normalizedAccountId,
65
+ kind: "revoked",
66
+ revokedAt: (/* @__PURE__ */ new Date()).toISOString()
67
+ });
68
+ }
69
+ function credentialsMatchConfig(stored, config) {
70
+ if (!config.userId) {
71
+ if (!config.accessToken) return false;
72
+ return stored.homeserver === config.homeserver && stored.accessToken === config.accessToken;
73
+ }
74
+ return stored.homeserver === config.homeserver && stored.userId === config.userId;
75
+ }
76
+ //#endregion
77
+ export { isMatrixCredentialRevocation as a, normalizeMatrixStoredCredentials as c, credentials_read_exports as i, openMatrixCredentialsStore as l, clearMatrixCredentials as n, loadMatrixCredentials as o, credentialsMatchConfig as r, matrixCredentialsStoreKey as s, MATRIX_CREDENTIALS_NAMESPACE as t };
@@ -1,6 +1,6 @@
1
1
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
2
2
  //#region extensions/matrix/src/matrix/credentials-write.runtime.ts
3
- const loadMatrixCredentialsRuntime = createLazyRuntimeModule(() => import("./credentials-DnhsLAuR.js"));
3
+ const loadMatrixCredentialsRuntime = createLazyRuntimeModule(() => import("./credentials-W2EmwRhu.js"));
4
4
  async function saveMatrixCredentials(...args) {
5
5
  return (await loadMatrixCredentialsRuntime()).saveMatrixCredentials(...args);
6
6
  }
@@ -1,8 +1,8 @@
1
1
  import { t as formatMatrixErrorMessage } from "./errors-C47hvAF8.js";
2
- import { t as ensureMatrixCryptoRuntime } from "./deps-DDbghaZH.js";
3
- import { n as LogService, r as noop } from "./logger-BMClpI5b.js";
4
- import { i as restoreIdbFromDisk, n as persistIdbToDisk } from "./idb-persistence-iUZoHZkp.js";
5
- import { n as isRepairableSecretStorageAccessError } from "./recovery-key-store-Bx0zTJcB.js";
2
+ import { t as ensureMatrixCryptoRuntime } from "./deps-CcVJfvRM.js";
3
+ import { n as LogService, r as noop } from "./logger-D0GCSDQq.js";
4
+ import { i as restoreIdbFromDisk, n as persistIdbToDisk } from "./idb-persistence-Dyy6ipgU.js";
5
+ import { n as isRepairableSecretStorageAccessError } from "./recovery-key-store-CW6eePfp.js";
6
6
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
7
7
  import { resolveDateTimestampMs, resolveTimestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
8
8
  import { MatrixEventEvent } from "matrix-js-sdk/lib/matrix.js";
@@ -1,8 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
2
  import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-B-5aQxwn.js";
3
- import { f as resolveMatrixAuth } from "./shared-DgvN5rBx.js";
4
- import "./client-DP0nmFxK.js";
5
- import { t as MatrixAuthedHttpClient } from "./http-client-W4TJQM6r.js";
3
+ import { f as resolveMatrixAuth } from "./shared-DquM1oz6.js";
4
+ import "./client-CA0PULls.js";
5
+ import { t as MatrixAuthedHttpClient } from "./http-client-BmrgOZTL.js";
6
6
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
7
7
  //#region extensions/matrix/src/directory-live.ts
8
8
  var directory_live_exports = /* @__PURE__ */ __exportAll({
@@ -1,4 +1,4 @@
1
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-D2qTLe-C.js";
1
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BA2Y6Crx.js";
2
2
  import { detectPluginInstallPathIssue, formatPluginInstallPathIssue, removePluginFromConfig } from "openclaw/plugin-sdk/runtime-doctor";
3
3
  //#region extensions/matrix/src/doctor.ts
4
4
  async function collectMatrixInstallPathWarnings(cfg) {
@@ -1,4 +1,4 @@
1
- import { t as isRecord } from "./record-shared-CvzjvHRn.js";
1
+ import { t as isRecord } from "./record-shared-CWWx6fvI.js";
2
2
  import { defineChannelAliasMigration } from "openclaw/plugin-sdk/runtime-doctor";
3
3
  import { hasLegacyFlatAllowPrivateNetworkAlias, migrateLegacyFlatAllowPrivateNetworkAlias } from "openclaw/plugin-sdk/ssrf-runtime";
4
4
  //#region extensions/matrix/src/doctor-contract.ts
@@ -1,12 +1,17 @@
1
- import { t as isRecord } from "./record-shared-CvzjvHRn.js";
2
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-D2qTLe-C.js";
3
- import { O as writeMatrixIdbSnapshotJsonToStore, S as readLegacyMatrixLegacyCryptoMigrationState, _ as hasMatrixRecoveryKeyStateInStore, a as openMatrixStorageMetaStoreOptions, b as openMatrixLegacyCryptoMigrationStoreOptions, f as MATRIX_IDB_SNAPSHOT_FILENAME, g as hasMatrixLegacyCryptoMigrationStateInStore, h as hasMatrixIdbSnapshotStateInStore, i as normalizeMatrixStorageMetadata, j as writeMatrixRecoveryKeyStateToStore, k as writeMatrixLegacyCryptoMigrationStateToStore, m as MATRIX_RECOVERY_KEY_FILENAME, n as hasMatrixStorageMetaStateInStore, p as MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, u as writeMatrixStorageMetaStateToStore, w as readLegacyMatrixRecoveryKeyState, x as openMatrixRecoveryKeyStoreOptions, y as openMatrixIdbSnapshotStoreOptions } from "./storage-BtSOar8T.js";
4
- import { a as readLegacyMatrixSyncCacheState, i as openMatrixSyncCacheStoreOptions, o as writeMatrixSyncCacheStateToStore, r as hasMatrixSyncCacheStateInStore } from "./file-sync-store-Cxb0ckyX.js";
5
- import { a as resolveMatrixInboundDedupeStateNamespace, n as MATRIX_INBOUND_DEDUPE_TTL_MS, r as buildMatrixInboundDedupeEventKey } from "./inbound-dedupe-DcMs0YXL.js";
6
- import { r as readLegacyMatrixIdbSnapshotState } from "./idb-persistence-iUZoHZkp.js";
7
- import path from "node:path";
8
- import { createHash } from "node:crypto";
1
+ import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount } from "./account-selection-kqquRzCf.js";
2
+ import { t as isRecord$1 } from "./record-shared-CWWx6fvI.js";
3
+ import { r as resolveMatrixCredentialsDir } from "./storage-paths-gUmSydsW.js";
4
+ import { a as isMatrixCredentialRevocation, c as normalizeMatrixStoredCredentials, s as matrixCredentialsStoreKey, t as MATRIX_CREDENTIALS_NAMESPACE } from "./credentials-read-DVmFCm7X.js";
5
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BA2Y6Crx.js";
6
+ import { O as writeMatrixIdbSnapshotJsonToStore, S as readLegacyMatrixLegacyCryptoMigrationState, _ as hasMatrixRecoveryKeyStateInStore, a as openMatrixStorageMetaStoreOptions, b as openMatrixLegacyCryptoMigrationStoreOptions, f as MATRIX_IDB_SNAPSHOT_FILENAME, g as hasMatrixLegacyCryptoMigrationStateInStore, h as hasMatrixIdbSnapshotStateInStore, i as normalizeMatrixStorageMetadata, j as writeMatrixRecoveryKeyStateToStore, k as writeMatrixLegacyCryptoMigrationStateToStore, m as MATRIX_RECOVERY_KEY_FILENAME, n as hasMatrixStorageMetaStateInStore, p as MATRIX_LEGACY_CRYPTO_MIGRATION_FILENAME, u as writeMatrixStorageMetaStateToStore, w as readLegacyMatrixRecoveryKeyState, x as openMatrixRecoveryKeyStoreOptions, y as openMatrixIdbSnapshotStoreOptions } from "./storage-CzHxeF5E.js";
7
+ import { a as readLegacyMatrixSyncCacheState, i as openMatrixSyncCacheStoreOptions, o as writeMatrixSyncCacheStateToStore, r as hasMatrixSyncCacheStateInStore } from "./file-sync-store-CPkgnSXp.js";
8
+ import { a as resolveMatrixInboundDedupeStateNamespace, n as MATRIX_INBOUND_DEDUPE_TTL_MS, r as buildMatrixInboundDedupeEventKey } from "./inbound-dedupe-CaBLblef.js";
9
+ import { r as readLegacyMatrixIdbSnapshotState } from "./idb-persistence-Dyy6ipgU.js";
10
+ import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
11
+ import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
9
12
  import { archiveLegacyStateSource } from "openclaw/plugin-sdk/runtime-doctor";
13
+ import { createHash } from "node:crypto";
14
+ import path from "node:path";
10
15
  import fs from "node:fs/promises";
11
16
  import { createPersistentDedupeImportEntry } from "openclaw/plugin-sdk/persistent-dedupe";
12
17
  //#region extensions/matrix/src/matrix/monitor/inbound-dedupe-migration.ts
@@ -71,7 +76,7 @@ function normalizeLegacyTimestamp(raw) {
71
76
  return Math.max(0, Math.floor(raw));
72
77
  }
73
78
  function parseLegacySqliteRow(row) {
74
- const value = isRecord(row.value) ? row.value : {};
79
+ const value = isRecord$1(row.value) ? row.value : {};
75
80
  const roomId = typeof value.roomId === "string" ? value.roomId.trim() : "";
76
81
  const eventId = typeof value.eventId === "string" ? value.eventId.trim() : "";
77
82
  const ts = normalizeLegacyTimestamp(value.ts);
@@ -127,11 +132,11 @@ async function readLegacyInboundDedupeJsonSource(storageRootDir) {
127
132
  } catch {
128
133
  return null;
129
134
  }
130
- if (!isRecord(parsed) || parsed.version !== LEGACY_JSON_VERSION || !Array.isArray(parsed.entries)) return null;
135
+ if (!isRecord$1(parsed) || parsed.version !== LEGACY_JSON_VERSION || !Array.isArray(parsed.entries)) return null;
131
136
  const accountId = await resolveJsonRootAccountId(storageRootDir);
132
137
  const markers = [];
133
138
  for (const entry of parsed.entries) {
134
- if (!isRecord(entry) || typeof entry.key !== "string") continue;
139
+ if (!isRecord$1(entry) || typeof entry.key !== "string") continue;
135
140
  const separator = entry.key.indexOf("|");
136
141
  if (separator <= 0) continue;
137
142
  const roomId = entry.key.slice(0, separator).trim();
@@ -199,6 +204,39 @@ async function importNewestInboundDedupeMarkers(params) {
199
204
  //#region extensions/matrix/doctor-contract-api.ts
200
205
  const MATRIX_SYNC_CACHE_FILENAME = "bot-storage.json";
201
206
  const MATRIX_STORAGE_META_FILENAME = "storage-meta.json";
207
+ async function collectLegacyMatrixCredentialSources(params) {
208
+ const credentialsDir = resolveMatrixCredentialsDir(params.stateDir);
209
+ let entries;
210
+ try {
211
+ entries = await fs.readdir(credentialsDir, { withFileTypes: true });
212
+ } catch {
213
+ return [];
214
+ }
215
+ return entries.filter((entry) => entry.isFile() && /^credentials(?:-[a-z0-9._-]+)?\.json$/iu.test(entry.name)).toSorted((left, right) => {
216
+ if (left.name === "credentials.json") return 1;
217
+ if (right.name === "credentials.json") return -1;
218
+ return left.name.localeCompare(right.name);
219
+ }).map((entry) => {
220
+ const namedAccount = /^credentials(?:-([a-z0-9._-]+))?\.json$/iu.exec(entry.name)?.[1];
221
+ return {
222
+ accountId: namedAccount ? normalizeAccountId(namedAccount) : requiresExplicitMatrixDefaultAccount(params.config, params.env) ? null : normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(params.config, params.env)),
223
+ filePath: path.join(credentialsDir, entry.name)
224
+ };
225
+ });
226
+ }
227
+ async function readLegacyMatrixCredentials(source) {
228
+ if (!source.accountId) return null;
229
+ try {
230
+ const raw = JSON.parse(await fs.readFile(source.filePath, "utf8"));
231
+ const createdAt = isRecord(raw) && typeof raw.createdAt === "string" && raw.createdAt ? raw.createdAt : (await fs.stat(source.filePath)).mtime.toISOString();
232
+ return normalizeMatrixStoredCredentials(isRecord(raw) ? {
233
+ ...raw,
234
+ createdAt
235
+ } : raw, source.accountId);
236
+ } catch {
237
+ return null;
238
+ }
239
+ }
202
240
  async function collectLegacyMatrixStateRoots(stateDir, filename) {
203
241
  const matrixRoot = path.join(stateDir, "matrix");
204
242
  const roots = [];
@@ -249,6 +287,74 @@ async function archiveLegacyMatrixStateFile(params) {
249
287
  if (params.notice && params.warnings.length === warningCount) params.notices?.push(params.notice);
250
288
  }
251
289
  const stateMigrations = [
290
+ {
291
+ id: "matrix-credentials-json-to-plugin-state",
292
+ label: "Matrix credentials",
293
+ async detectLegacyState(params) {
294
+ const sources = await collectLegacyMatrixCredentialSources(params);
295
+ return sources.length > 0 ? { preview: [`Matrix credential JSON can migrate to SQLite (${sources.length} ${sources.length === 1 ? "file" : "files"})`] } : null;
296
+ },
297
+ async migrateLegacyState(params) {
298
+ const changes = [];
299
+ const warnings = [];
300
+ const sources = await collectLegacyMatrixCredentialSources(params);
301
+ const store = params.context.openPluginStateKeyedStore({
302
+ namespace: MATRIX_CREDENTIALS_NAMESPACE,
303
+ maxEntries: 256,
304
+ overflowPolicy: "reject-new"
305
+ });
306
+ for (const source of sources) {
307
+ if (!source.accountId) {
308
+ warnings.push(`Left ambiguous Matrix credential legacy source in place because no default account is selected: ${source.filePath}`);
309
+ continue;
310
+ }
311
+ const credentials = await readLegacyMatrixCredentials(source);
312
+ if (!credentials) {
313
+ warnings.push(`Left invalid Matrix credential legacy source in place: ${source.filePath}`);
314
+ continue;
315
+ }
316
+ const key = matrixCredentialsStoreKey(source.accountId);
317
+ const stored = await store.lookup(key);
318
+ if (isMatrixCredentialRevocation(stored, source.accountId)) {
319
+ changes.push(`Archived revoked Matrix credential legacy source for account ${source.accountId}`);
320
+ await archiveLegacyStateSource({
321
+ filePath: source.filePath,
322
+ label: "Matrix credentials",
323
+ changes,
324
+ warnings
325
+ });
326
+ continue;
327
+ }
328
+ const existing = normalizeMatrixStoredCredentials(stored, source.accountId);
329
+ if (existing && JSON.stringify(existing) !== JSON.stringify(credentials)) {
330
+ warnings.push(`Kept existing Matrix credentials for account ${source.accountId}; left differing legacy source in place`);
331
+ continue;
332
+ }
333
+ if (!existing) try {
334
+ await store.registerIfAbsent(key, credentials);
335
+ } catch (error) {
336
+ warnings.push(`Failed importing Matrix credentials for account ${source.accountId}: ${String(error)}; left legacy source in place`);
337
+ continue;
338
+ }
339
+ const persisted = normalizeMatrixStoredCredentials(await store.lookup(key), source.accountId);
340
+ if (!persisted || JSON.stringify(persisted) !== JSON.stringify(credentials)) {
341
+ warnings.push(`Failed verifying Matrix credentials for account ${source.accountId}; left legacy source in place`);
342
+ continue;
343
+ }
344
+ changes.push(`Migrated Matrix credentials for account ${source.accountId} to SQLite`);
345
+ await archiveLegacyStateSource({
346
+ filePath: source.filePath,
347
+ label: "Matrix credentials",
348
+ changes,
349
+ warnings
350
+ });
351
+ }
352
+ return {
353
+ changes,
354
+ warnings
355
+ };
356
+ }
357
+ },
252
358
  {
253
359
  id: "matrix-inbound-dedupe-to-claimable-dedupe",
254
360
  label: "Matrix inbound dedupe markers",
@@ -1,4 +1,4 @@
1
- import { n as editMessageMatrix, r as prepareMatrixSingleText, s as sendSingleTextMessageMatrix, y as MsgType } from "./send-C7xuGWpv.js";
1
+ import { n as editMessageMatrix, r as prepareMatrixSingleText, s as sendSingleTextMessageMatrix, y as MsgType } from "./send-BJbrdmNm.js";
2
2
  import { createDraftStreamLoop } from "openclaw/plugin-sdk/channel-outbound";
3
3
  //#region extensions/matrix/src/matrix/draft-stream.ts
4
4
  const DEFAULT_THROTTLE_MS = 1e3;
@@ -1,4 +1,4 @@
1
- import { a as resolveMatrixDefaultOrOnlyAccountId } from "./account-selection-Bz00QTmQ.js";
1
+ import { a as resolveMatrixDefaultOrOnlyAccountId } from "./account-selection-kqquRzCf.js";
2
2
  import { t as resolveMatrixConfigFieldPath } from "./config-paths-CnREYb1Y.js";
3
3
  import { normalizeOptionalAccountId } from "openclaw/plugin-sdk/account-id";
4
4
  //#region extensions/matrix/src/matrix/encryption-guidance.ts
@@ -1,13 +1,30 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { t as isRecord } from "./record-shared-CvzjvHRn.js";
3
- import { t as getMatrixRuntime } from "./runtime-CveSqMOP.js";
4
- import { M as resolveMatrixSqliteStateEnv, t as claimCurrentTokenStorageState } from "./storage-BtSOar8T.js";
5
- import { t as createAsyncLock } from "./async-lock-BcLS4KOc.js";
6
- import { n as LogService } from "./logger-BMClpI5b.js";
7
- import path from "node:path";
2
+ import { t as isRecord } from "./record-shared-CWWx6fvI.js";
3
+ import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
4
+ import { M as resolveMatrixSqliteStateEnv, t as claimCurrentTokenStorageState } from "./storage-CzHxeF5E.js";
5
+ import { n as LogService } from "./logger-D0GCSDQq.js";
8
6
  import { createHash, randomUUID } from "node:crypto";
7
+ import path from "node:path";
9
8
  import fs from "node:fs/promises";
10
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
11
28
  //#region extensions/matrix/src/matrix/client/file-sync-store.ts
12
29
  var file_sync_store_exports = /* @__PURE__ */ __exportAll({
13
30
  SqliteBackedMatrixSyncStore: () => SqliteBackedMatrixSyncStore,
@@ -1,4 +1,4 @@
1
- import { a as resolveMatrixDefaultOrOnlyAccountId, i as resolveMatrixChannelConfig, n as requiresExplicitMatrixDefaultAccount, r as resolveConfiguredMatrixAccountIds, t as findMatrixAccountEntry } from "./account-selection-Bz00QTmQ.js";
1
+ import { a as resolveMatrixDefaultOrOnlyAccountId, i as resolveMatrixChannelConfig, n as requiresExplicitMatrixDefaultAccount, r as resolveConfiguredMatrixAccountIds, t as findMatrixAccountEntry } from "./account-selection-kqquRzCf.js";
2
2
  import { n as listMatrixEnvAccountIds, r as resolveMatrixEnvAccountToken, t as getMatrixScopedEnvVarNames } from "./env-vars-B0NxQnPk.js";
3
- import { a as resolveMatrixCredentialsPath, i as resolveMatrixCredentialsFilename, n as resolveMatrixAccountStorageRoot, o as resolveMatrixHomeserverKey, r as resolveMatrixCredentialsDir, s as sanitizeMatrixPathSegment, t as hashMatrixAccessToken } from "./storage-paths-B4_I9iqO.js";
3
+ import { a as resolveMatrixCredentialsPath, i as resolveMatrixCredentialsFilename, n as resolveMatrixAccountStorageRoot, o as resolveMatrixHomeserverKey, r as resolveMatrixCredentialsDir, s as sanitizeMatrixPathSegment, t as hashMatrixAccessToken } from "./storage-paths-gUmSydsW.js";
4
4
  export { findMatrixAccountEntry, getMatrixScopedEnvVarNames, hashMatrixAccessToken, listMatrixEnvAccountIds, requiresExplicitMatrixDefaultAccount, resolveConfiguredMatrixAccountIds, resolveMatrixAccountStorageRoot, resolveMatrixChannelConfig, resolveMatrixCredentialsDir, resolveMatrixCredentialsFilename, resolveMatrixCredentialsPath, resolveMatrixDefaultOrOnlyAccountId, resolveMatrixEnvAccountToken, resolveMatrixHomeserverKey, sanitizeMatrixPathSegment };
@@ -1,6 +1,6 @@
1
1
  import { t as buildTimeoutAbortSignal } from "./timeout-abort-signal-DMrgRFIy.js";
2
- import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
3
2
  import { parseMediaContentLength } from "openclaw/plugin-sdk/media-runtime";
3
+ import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
4
4
  import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
5
5
  import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
6
6
  import { closeDispatcher, createPinnedDispatcher, resolvePinnedHostnameWithPolicy } from "openclaw/plugin-sdk/ssrf-dispatcher";
@@ -337,7 +337,7 @@ var MatrixAuthedHttpClient = class {
337
337
  allowAbsoluteEndpoint: params.allowAbsoluteEndpoint
338
338
  });
339
339
  if (!response.ok) throw buildHttpError(response.status, text);
340
- if ((response.headers.get("content-type") ?? "").includes("application/json")) {
340
+ if ((response.headers.get("content-type") ?? "").split(";", 1)[0]?.trim().toLowerCase() === "application/json") {
341
341
  if (!text.trim()) return {};
342
342
  try {
343
343
  return JSON.parse(text);
@@ -1,9 +1,9 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { D as writeMatrixIdbSnapshotJson, T as readMatrixIdbSnapshotJson, f as MATRIX_IDB_SNAPSHOT_FILENAME } from "./storage-BtSOar8T.js";
3
- import { n as LogService } from "./logger-BMClpI5b.js";
2
+ import { D as writeMatrixIdbSnapshotJson, T as readMatrixIdbSnapshotJson, f as MATRIX_IDB_SNAPSHOT_FILENAME } from "./storage-CzHxeF5E.js";
3
+ import { n as LogService } from "./logger-D0GCSDQq.js";
4
4
  import { n as MATRIX_IDB_SNAPSHOT_LOCK_OPTIONS } from "./idb-persistence-lock-DAJ49nZX.js";
5
- import fs from "node:fs";
6
5
  import path from "node:path";
6
+ import fs from "node:fs";
7
7
  import { indexedDB } from "fake-indexeddb";
8
8
  import { withFileLock } from "openclaw/plugin-sdk/file-lock";
9
9
  //#region extensions/matrix/src/matrix/sdk/idb-persistence.ts
@@ -1,5 +1,5 @@
1
- import { n as LogService } from "./logger-BMClpI5b.js";
2
- import { createClaimableDedupe, resolvePersistentDedupePluginStateNamespace } from "openclaw/plugin-sdk/persistent-dedupe";
1
+ import { n as LogService } from "./logger-D0GCSDQq.js";
2
+ import { createChannelReplayGuard, resolvePersistentDedupePluginStateNamespace } from "openclaw/plugin-sdk/persistent-dedupe";
3
3
  //#region extensions/matrix/src/matrix/monitor/inbound-dedupe.ts
4
4
  const MATRIX_INBOUND_DEDUPE_PLUGIN_ID = "matrix";
5
5
  const MATRIX_INBOUND_DEDUPE_NAMESPACE_PREFIX = "matrix.inbound-dedupe";
@@ -24,44 +24,25 @@ function resolveMatrixInboundDedupeStateNamespace() {
24
24
  });
25
25
  }
26
26
  function createMatrixInboundEventDeduper(params) {
27
- const guard = createClaimableDedupe({
28
- pluginId: MATRIX_INBOUND_DEDUPE_PLUGIN_ID,
29
- namespacePrefix: MATRIX_INBOUND_DEDUPE_NAMESPACE_PREFIX,
30
- ttlMs: MATRIX_INBOUND_DEDUPE_TTL_MS,
31
- memoryMaxSize: MATRIX_INBOUND_DEDUPE_MEMORY_MAX,
32
- stateMaxEntries: MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES,
33
- ...params.env ? { env: params.env } : {},
34
- onDiskError: (err) => {
35
- LogService.warn("MatrixInboundDedupe", "Matrix inbound dedupe persistence failed:", err);
36
- }
37
- });
38
27
  const accountId = params.auth.accountId;
39
- const namespace = MATRIX_INBOUND_DEDUPE_NAMESPACE;
40
- return {
41
- claimEvent: async (ids) => {
42
- const key = buildMatrixInboundDedupeEventKey({
43
- accountId,
44
- ...ids
45
- });
46
- if (!key) return true;
47
- return (await guard.claim(key, { namespace })).kind === "claimed";
48
- },
49
- commitEvent: async (ids) => {
50
- const key = buildMatrixInboundDedupeEventKey({
51
- accountId,
52
- ...ids
53
- });
54
- if (!key) return;
55
- await guard.commit(key, { namespace });
28
+ return createChannelReplayGuard({
29
+ dedupe: {
30
+ pluginId: MATRIX_INBOUND_DEDUPE_PLUGIN_ID,
31
+ namespacePrefix: MATRIX_INBOUND_DEDUPE_NAMESPACE_PREFIX,
32
+ ttlMs: MATRIX_INBOUND_DEDUPE_TTL_MS,
33
+ memoryMaxSize: MATRIX_INBOUND_DEDUPE_MEMORY_MAX,
34
+ stateMaxEntries: MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES,
35
+ ...params.env ? { env: params.env } : {},
36
+ onDiskError: (err) => {
37
+ LogService.warn("MatrixInboundDedupe", "Matrix inbound dedupe persistence failed:", err);
38
+ }
56
39
  },
57
- releaseEvent: (ids) => {
58
- const key = buildMatrixInboundDedupeEventKey({
59
- accountId,
60
- ...ids
61
- });
62
- if (key) guard.release(key, { namespace });
63
- }
64
- };
40
+ buildReplayKey: (event) => buildMatrixInboundDedupeEventKey({
41
+ accountId,
42
+ ...event
43
+ }),
44
+ namespace: () => MATRIX_INBOUND_DEDUPE_NAMESPACE
45
+ });
65
46
  }
66
47
  //#endregion
67
48
  export { resolveMatrixInboundDedupeStateNamespace as a, createMatrixInboundEventDeduper as i, MATRIX_INBOUND_DEDUPE_TTL_MS as n, buildMatrixInboundDedupeEventKey as r, MATRIX_INBOUND_DEDUPE_STATE_MAX_ENTRIES as t };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as registerMatrixCliMetadata } from "./cli-metadata-Gf3HSJ2c.js";
1
+ import { n as registerMatrixCliMetadata } from "./cli-metadata-Xq1Xb15R.js";
2
2
  import { registerMatrixSubagentHooks } from "./subagent-hooks-api.js";
3
3
  import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
4
4
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
@@ -1,4 +1,4 @@
1
- import { t as getMatrixRuntime } from "./runtime-CveSqMOP.js";
1
+ import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
2
2
  import { format } from "node:util";
3
3
  import { redactSensitiveText } from "openclaw/plugin-sdk/logging-core";
4
4
  //#region extensions/matrix/src/matrix/sdk/logger.ts
@@ -1,4 +1,4 @@
1
- import { i as setMatrixConsoleLogging, n as LogService, t as ConsoleLogger } from "./logger-BMClpI5b.js";
1
+ import { i as setMatrixConsoleLogging, n as LogService, t as ConsoleLogger } from "./logger-D0GCSDQq.js";
2
2
  import { logger } from "matrix-js-sdk/lib/logger.js";
3
3
  //#region extensions/matrix/src/matrix/client/logging.ts
4
4
  let matrixSdkLoggingConfigured = false;
@@ -1,4 +1,4 @@
1
- import { C as formatPollResultsAsText, D as parsePollStartContent, O as resolvePollReferenceEventId, S as formatPollAsText, T as isPollStartType, w as isPollEventType, x as buildPollResultsSummary } from "./send-C7xuGWpv.js";
1
+ import { C as formatPollResultsAsText, D as parsePollStartContent, O as resolvePollReferenceEventId, S as formatPollAsText, T as isPollStartType, w as isPollEventType, x as buildPollResultsSummary } from "./send-BJbrdmNm.js";
2
2
  import path from "node:path";
3
3
  //#region extensions/matrix/src/matrix/poll-summary.ts
4
4
  function resolveMatrixPollRootEventId(event) {
@@ -1,8 +1,8 @@
1
1
  import { r as isMatrixNotFoundError } from "./errors-C47hvAF8.js";
2
- import { T as isPollStartType, a as sendMessageMatrix, n as editMessageMatrix, w as isPollEventType } from "./send-C7xuGWpv.js";
2
+ import { T as isPollStartType, a as sendMessageMatrix, n as editMessageMatrix, w as isPollEventType } from "./send-BJbrdmNm.js";
3
3
  import { n as MATRIX_REACTION_EVENT_TYPE } from "./reaction-common-DkrQdBSZ.js";
4
- import { a as resolveMatrixMessageAttachment, l as resolveMatrixPollRootEventId, o as resolveMatrixMessageBody, s as fetchMatrixPollMessageSummary } from "./media-text-DWaotsZB.js";
5
- import { r as withResolvedRoomAction } from "./client-ClHisZbf.js";
4
+ import { a as resolveMatrixMessageAttachment, l as resolveMatrixPollRootEventId, o as resolveMatrixMessageBody, s as fetchMatrixPollMessageSummary } from "./media-text-BMXEXb1j.js";
5
+ import { r as withResolvedRoomAction } from "./client-BtG4quUl.js";
6
6
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
7
7
  import { resolveIntegerOption } from "openclaw/plugin-sdk/number-runtime";
8
8
  //#region extensions/matrix/src/matrix/actions/limits.ts