@openclaw/matrix 2026.3.13 → 2026.5.10-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/account-config-D2W-V1eQ.js +96 -0
  2. package/dist/account-selection-BWwIruri.js +158 -0
  3. package/dist/accounts-Bm90Rzvp.js +130 -0
  4. package/dist/active-client-uhlxdhEy.js +20 -0
  5. package/dist/allowlist-sTzpCn5d.js +68 -0
  6. package/dist/api.js +12 -0
  7. package/dist/approval-handler.runtime-DWTQfd4m.js +370 -0
  8. package/dist/approval-ids-DoC2z7tR.js +7 -0
  9. package/dist/approval-reaction-auth-DbcA1gGd.js +27 -0
  10. package/dist/approval-reactions-o2_tuH8D.js +162 -0
  11. package/dist/async-lock-uQfhfQIY.js +19 -0
  12. package/dist/auth-presence.js +26 -0
  13. package/dist/backup-health-Cabu_WQC.js +60 -0
  14. package/dist/channel-H_6lMgwf.js +1116 -0
  15. package/dist/channel-plugin-api.js +2 -0
  16. package/dist/channel.runtime-BnO9f0pR.js +246 -0
  17. package/dist/cli-CYZ9yVcB.js +1340 -0
  18. package/dist/cli-metadata-DPIHnoa6.js +22 -0
  19. package/dist/cli-metadata.js +2 -0
  20. package/dist/client-DkcXnm0X.js +25 -0
  21. package/dist/client-_hckQNGW.js +31 -0
  22. package/dist/client-bootstrap-Rb8oHvhH.js +114 -0
  23. package/dist/config--5-S2Akv.js +452 -0
  24. package/dist/config-paths-nsVaysCu.js +19 -0
  25. package/dist/config-schema-nPLpEgHl.js +200 -0
  26. package/dist/config-secret-input.runtime-DiKFehsE.js +2 -0
  27. package/dist/config-update-wZX-HLMn.js +143 -0
  28. package/dist/contract-api.js +9 -0
  29. package/dist/create-client-DCnqDaqd.js +64 -0
  30. package/dist/credentials-DV6fWXhC.js +56 -0
  31. package/dist/credentials-read-cmHgousK.js +112 -0
  32. package/dist/credentials-write.runtime-zniTq-Gr.js +17 -0
  33. package/dist/crypto-node.runtime-pihzdpY7.js +12 -0
  34. package/dist/crypto-runtime-ZI0zAtn3.js +1214 -0
  35. package/dist/deps-C6WqKY7m.js +235 -0
  36. package/dist/device-health-UVYpbA_W.js +16 -0
  37. package/dist/direct-management-DMMMgtTB.js +249 -0
  38. package/dist/direct-room-XkutHjES.js +76 -0
  39. package/dist/directory-live-DmOtMhyr.js +150 -0
  40. package/dist/doctor-C4__7c-U.js +153 -0
  41. package/dist/doctor-contract-D4-64QuJ.js +246 -0
  42. package/dist/doctor-contract-api.js +2 -0
  43. package/dist/draft-stream-BE2QevQQ.js +144 -0
  44. package/dist/encryption-guidance-BPi3A_m3.js +15 -0
  45. package/dist/env-auth-BJqGI8M6.js +63 -0
  46. package/dist/env-vars-C7uQCTKn.js +63 -0
  47. package/dist/errors-CTcpEDq-.js +17 -0
  48. package/dist/exec-approval-resolver-Bza9Dhlm.js +15 -0
  49. package/dist/exec-approvals-Crnh543m.js +196 -0
  50. package/dist/helper-api.js +4 -0
  51. package/dist/http-client-C7AeVJay.js +319 -0
  52. package/dist/index.js +46 -0
  53. package/dist/legacy-crypto-inspector-poDWldgy.js +41 -0
  54. package/dist/legacy-crypto-restore-Biw-w2ng.js +85 -0
  55. package/dist/logger-CnZRVrux.js +78 -0
  56. package/dist/logging-DZHSPP5N.js +99 -0
  57. package/dist/matrix-migration.runtime-WY6ffcrf.js +525 -0
  58. package/dist/media-text-DU6nWZuj.js +146 -0
  59. package/dist/messages-BpihMh82.js +140 -0
  60. package/dist/migration-snapshot-backup-DaCHTp8C.js +69 -0
  61. package/dist/migration-snapshot.runtime-CKHE3xF9.js +2 -0
  62. package/dist/monitor-BaRCKyLd.js +4175 -0
  63. package/dist/plugin-entry.handlers.runtime.js +51 -0
  64. package/dist/probe.runtime-BvAzYAIe.js +3 -0
  65. package/dist/profile-BlHu0wDX.js +111 -0
  66. package/dist/profile-update-DjeBNgIV.js +69 -0
  67. package/dist/reaction-common-ejrL19w-.js +71 -0
  68. package/dist/reaction-events-CiARZfjk.js +121 -0
  69. package/dist/record-shared-CHWJCTWf.js +2 -0
  70. package/dist/recovery-key-store-BTJ6jz5v.js +294 -0
  71. package/dist/resolve-targets-YtJnw1Tb.js +140 -0
  72. package/dist/resolver.runtime-D9piiGEl.js +5 -0
  73. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  74. package/dist/route-D6rg-iXN.js +161 -0
  75. package/dist/runtime-C6X4h_SJ.js +6 -0
  76. package/dist/runtime-Dog86njy.js +8 -0
  77. package/dist/runtime-api-DTKcXOhp.js +24 -0
  78. package/dist/runtime-api.js +25 -0
  79. package/dist/runtime-heavy-api.js +3 -0
  80. package/dist/runtime-setter-api.js +2 -0
  81. package/dist/sdk-B2vZA27-.js +1416 -0
  82. package/dist/secret-contract-DcrJWCQI.js +120 -0
  83. package/dist/secret-contract-api.js +2 -0
  84. package/dist/send-Bo0DU1ca.js +1200 -0
  85. package/dist/session-store-metadata-DQXjgNLt.js +77 -0
  86. package/dist/setup-bootstrap-ImenBsMt.js +62 -0
  87. package/dist/setup-core-CfZy05oW.js +116 -0
  88. package/dist/setup-dm-policy-2-r1FrQh.js +194 -0
  89. package/dist/setup-entry.js +19 -0
  90. package/dist/setup-plugin-api.js +44 -0
  91. package/dist/setup-surface-CqT_o61M.js +540 -0
  92. package/dist/shared-CpMoYKm1.js +195 -0
  93. package/dist/startup-abort-56edvmbM.js +32 -0
  94. package/dist/startup-verification-Demyp0bP.js +132 -0
  95. package/dist/storage-paths-BJLdnCjV.js +52 -0
  96. package/dist/storage-tC3ujLiW.js +281 -0
  97. package/dist/subagent-hooks-DQbyqq9V.js +149 -0
  98. package/dist/subagent-hooks-api.js +23 -0
  99. package/dist/sync-state-C_beeevA.js +12 -0
  100. package/dist/target-ids-80nQ2gql.js +77 -0
  101. package/dist/test-api.js +4 -0
  102. package/dist/thread-binding-api-Cq_E-E1K.js +17 -0
  103. package/dist/thread-binding-api.js +2 -0
  104. package/dist/thread-bindings-B9mesxXk.js +352 -0
  105. package/dist/thread-bindings-runtime.js +2 -0
  106. package/dist/thread-bindings-shared-DK-d-oYX.js +97 -0
  107. package/dist/timeout-abort-signal-CtaIaP1v.js +2 -0
  108. package/dist/tool-actions.runtime-ThYhfHtZ.js +532 -0
  109. package/dist/url-validation-DiK9j7jz.js +36 -0
  110. package/dist/verification-CZ2rDeHL.js +345 -0
  111. package/openclaw.plugin.json +796 -1
  112. package/package.json +82 -16
  113. package/CHANGELOG.md +0 -104
  114. package/index.ts +0 -22
  115. package/src/actions.ts +0 -195
  116. package/src/channel.directory.test.ts +0 -135
  117. package/src/channel.ts +0 -461
  118. package/src/config-schema.test.ts +0 -26
  119. package/src/config-schema.ts +0 -62
  120. package/src/directory-live.test.ts +0 -85
  121. package/src/directory-live.ts +0 -209
  122. package/src/group-mentions.ts +0 -52
  123. package/src/matrix/accounts.test.ts +0 -131
  124. package/src/matrix/accounts.ts +0 -114
  125. package/src/matrix/actions/client.ts +0 -47
  126. package/src/matrix/actions/limits.test.ts +0 -15
  127. package/src/matrix/actions/limits.ts +0 -6
  128. package/src/matrix/actions/messages.ts +0 -126
  129. package/src/matrix/actions/pins.test.ts +0 -74
  130. package/src/matrix/actions/pins.ts +0 -84
  131. package/src/matrix/actions/reactions.test.ts +0 -109
  132. package/src/matrix/actions/reactions.ts +0 -102
  133. package/src/matrix/actions/room.ts +0 -85
  134. package/src/matrix/actions/summary.ts +0 -75
  135. package/src/matrix/actions/types.ts +0 -85
  136. package/src/matrix/actions.ts +0 -15
  137. package/src/matrix/active-client.ts +0 -32
  138. package/src/matrix/client/config.ts +0 -245
  139. package/src/matrix/client/create-client.ts +0 -125
  140. package/src/matrix/client/logging.ts +0 -46
  141. package/src/matrix/client/runtime.ts +0 -4
  142. package/src/matrix/client/shared.test.ts +0 -85
  143. package/src/matrix/client/shared.ts +0 -210
  144. package/src/matrix/client/startup.test.ts +0 -49
  145. package/src/matrix/client/startup.ts +0 -29
  146. package/src/matrix/client/storage.ts +0 -131
  147. package/src/matrix/client/types.ts +0 -34
  148. package/src/matrix/client-bootstrap.ts +0 -47
  149. package/src/matrix/client.test.ts +0 -56
  150. package/src/matrix/client.ts +0 -14
  151. package/src/matrix/credentials.ts +0 -125
  152. package/src/matrix/deps.test.ts +0 -74
  153. package/src/matrix/deps.ts +0 -126
  154. package/src/matrix/format.test.ts +0 -33
  155. package/src/matrix/format.ts +0 -22
  156. package/src/matrix/index.ts +0 -11
  157. package/src/matrix/monitor/access-policy.ts +0 -126
  158. package/src/matrix/monitor/allowlist.test.ts +0 -45
  159. package/src/matrix/monitor/allowlist.ts +0 -94
  160. package/src/matrix/monitor/auto-join.ts +0 -72
  161. package/src/matrix/monitor/direct.test.ts +0 -396
  162. package/src/matrix/monitor/direct.ts +0 -152
  163. package/src/matrix/monitor/events.test.ts +0 -186
  164. package/src/matrix/monitor/events.ts +0 -168
  165. package/src/matrix/monitor/handler.body-for-agent.test.ts +0 -196
  166. package/src/matrix/monitor/handler.ts +0 -768
  167. package/src/matrix/monitor/inbound-body.test.ts +0 -73
  168. package/src/matrix/monitor/inbound-body.ts +0 -28
  169. package/src/matrix/monitor/index.test.ts +0 -18
  170. package/src/matrix/monitor/index.ts +0 -414
  171. package/src/matrix/monitor/location.ts +0 -100
  172. package/src/matrix/monitor/media.test.ts +0 -86
  173. package/src/matrix/monitor/media.ts +0 -118
  174. package/src/matrix/monitor/mentions.test.ts +0 -154
  175. package/src/matrix/monitor/mentions.ts +0 -62
  176. package/src/matrix/monitor/replies.test.ts +0 -184
  177. package/src/matrix/monitor/replies.ts +0 -124
  178. package/src/matrix/monitor/room-info.ts +0 -55
  179. package/src/matrix/monitor/rooms.test.ts +0 -124
  180. package/src/matrix/monitor/rooms.ts +0 -47
  181. package/src/matrix/monitor/threads.ts +0 -68
  182. package/src/matrix/monitor/types.ts +0 -39
  183. package/src/matrix/poll-types.test.ts +0 -21
  184. package/src/matrix/poll-types.ts +0 -167
  185. package/src/matrix/probe.ts +0 -69
  186. package/src/matrix/sdk-runtime.ts +0 -18
  187. package/src/matrix/send/client.ts +0 -99
  188. package/src/matrix/send/formatting.ts +0 -93
  189. package/src/matrix/send/media.ts +0 -230
  190. package/src/matrix/send/targets.test.ts +0 -98
  191. package/src/matrix/send/targets.ts +0 -150
  192. package/src/matrix/send/types.ts +0 -110
  193. package/src/matrix/send-queue.test.ts +0 -145
  194. package/src/matrix/send-queue.ts +0 -28
  195. package/src/matrix/send.test.ts +0 -319
  196. package/src/matrix/send.ts +0 -267
  197. package/src/onboarding.ts +0 -462
  198. package/src/outbound.test.ts +0 -159
  199. package/src/outbound.ts +0 -58
  200. package/src/resolve-targets.test.ts +0 -68
  201. package/src/resolve-targets.ts +0 -125
  202. package/src/runtime.ts +0 -6
  203. package/src/secret-input.ts +0 -13
  204. package/src/test-mocks.ts +0 -53
  205. package/src/tool-actions.ts +0 -164
  206. package/src/types.ts +0 -118
@@ -0,0 +1,281 @@
1
+ import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount } from "./account-selection-BWwIruri.js";
2
+ import { t as getMatrixRuntime } from "./runtime-Dog86njy.js";
3
+ import { n as resolveMatrixAccountStorageRoot, s as resolveMatrixLegacyFlatStoragePaths } from "./storage-paths-BJLdnCjV.js";
4
+ import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
5
+ import fs from "node:fs";
6
+ import os from "node:os";
7
+ import path from "node:path";
8
+ import { loadJsonFile, saveJsonFile } from "openclaw/plugin-sdk/json-store";
9
+ //#region extensions/matrix/src/matrix/client/storage.ts
10
+ const DEFAULT_ACCOUNT_KEY = "default";
11
+ const STORAGE_META_FILENAME = "storage-meta.json";
12
+ const THREAD_BINDINGS_FILENAME = "thread-bindings.json";
13
+ const LEGACY_CRYPTO_MIGRATION_FILENAME = "legacy-crypto-migration.json";
14
+ const RECOVERY_KEY_FILENAME = "recovery-key.json";
15
+ const IDB_SNAPSHOT_FILENAME = "crypto-idb-snapshot.json";
16
+ const STARTUP_VERIFICATION_FILENAME = "startup-verification.json";
17
+ function resolveLegacyStoragePaths(env = process.env) {
18
+ const legacy = resolveMatrixLegacyFlatStoragePaths(getMatrixRuntime().state.resolveStateDir(env, os.homedir));
19
+ return {
20
+ storagePath: legacy.storagePath,
21
+ cryptoPath: legacy.cryptoPath
22
+ };
23
+ }
24
+ function assertLegacyMigrationAccountSelection(params) {
25
+ const cfg = getMatrixRuntime().config.current();
26
+ if (!cfg.channels?.matrix || typeof cfg.channels.matrix !== "object") return;
27
+ if (requiresExplicitMatrixDefaultAccount(cfg)) throw new Error("Legacy Matrix client storage cannot be migrated automatically because multiple Matrix accounts are configured and channels.matrix.defaultAccount is not set.");
28
+ const selectedAccountId = normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(cfg));
29
+ const currentAccountId = normalizeAccountId(params.accountKey);
30
+ if (selectedAccountId !== currentAccountId) throw new Error(`Legacy Matrix client storage targets account "${selectedAccountId}", but the current client is starting account "${currentAccountId}". Start the selected account first so flat legacy storage is not migrated into the wrong account directory.`);
31
+ }
32
+ function scoreStorageRoot(rootDir) {
33
+ let score = 0;
34
+ if (fs.existsSync(path.join(rootDir, "bot-storage.json"))) score += 8;
35
+ if (fs.existsSync(path.join(rootDir, "crypto"))) score += 8;
36
+ if (fs.existsSync(path.join(rootDir, THREAD_BINDINGS_FILENAME))) score += 4;
37
+ if (fs.existsSync(path.join(rootDir, LEGACY_CRYPTO_MIGRATION_FILENAME))) score += 3;
38
+ if (fs.existsSync(path.join(rootDir, RECOVERY_KEY_FILENAME))) score += 2;
39
+ if (fs.existsSync(path.join(rootDir, IDB_SNAPSHOT_FILENAME))) score += 2;
40
+ if (fs.existsSync(path.join(rootDir, STORAGE_META_FILENAME))) score += 1;
41
+ return score;
42
+ }
43
+ function resolveStorageRootMtimeMs(rootDir) {
44
+ try {
45
+ return fs.statSync(rootDir).mtimeMs;
46
+ } catch {
47
+ return 0;
48
+ }
49
+ }
50
+ function readStoredRootMetadata(rootDir) {
51
+ const metadata = {};
52
+ const parsed = loadJsonFile(path.join(rootDir, STORAGE_META_FILENAME));
53
+ if (parsed) {
54
+ if (typeof parsed.homeserver === "string" && parsed.homeserver.trim()) metadata.homeserver = parsed.homeserver.trim();
55
+ if (typeof parsed.userId === "string" && parsed.userId.trim()) metadata.userId = parsed.userId.trim();
56
+ if (typeof parsed.accountId === "string" && parsed.accountId.trim()) metadata.accountId = parsed.accountId.trim();
57
+ if (typeof parsed.accessTokenHash === "string" && parsed.accessTokenHash.trim()) metadata.accessTokenHash = parsed.accessTokenHash.trim();
58
+ if (typeof parsed.deviceId === "string" && parsed.deviceId.trim()) metadata.deviceId = parsed.deviceId.trim();
59
+ if (parsed.currentTokenStateClaimed === true) metadata.currentTokenStateClaimed = true;
60
+ if (typeof parsed.createdAt === "string" && parsed.createdAt.trim()) metadata.createdAt = parsed.createdAt.trim();
61
+ }
62
+ const verification = loadJsonFile(path.join(rootDir, STARTUP_VERIFICATION_FILENAME));
63
+ if (!metadata.deviceId && typeof verification?.deviceId === "string" && verification.deviceId.trim()) metadata.deviceId = verification.deviceId.trim();
64
+ return metadata;
65
+ }
66
+ function isCompatibleStorageRoot(params) {
67
+ const metadata = readStoredRootMetadata(params.candidateRootDir);
68
+ if (metadata.homeserver && metadata.homeserver !== params.homeserver) return false;
69
+ if (metadata.userId && metadata.userId !== params.userId) return false;
70
+ if (metadata.accountId && normalizeAccountId(metadata.accountId) !== normalizeAccountId(params.accountKey)) return false;
71
+ if (params.deviceId && metadata.deviceId && metadata.deviceId.trim() && metadata.deviceId.trim() !== params.deviceId.trim()) return false;
72
+ if (params.requireExplicitDeviceMatch && params.deviceId && (!metadata.deviceId || metadata.deviceId.trim() !== params.deviceId.trim())) return false;
73
+ return true;
74
+ }
75
+ function resolvePreferredMatrixStorageRoot(params) {
76
+ const parentDir = path.dirname(params.canonicalRootDir);
77
+ const bestCurrentScore = scoreStorageRoot(params.canonicalRootDir);
78
+ let best = {
79
+ rootDir: params.canonicalRootDir,
80
+ tokenHash: params.canonicalTokenHash,
81
+ score: bestCurrentScore,
82
+ mtimeMs: resolveStorageRootMtimeMs(params.canonicalRootDir)
83
+ };
84
+ if (!params.deviceId?.trim()) return {
85
+ rootDir: best.rootDir,
86
+ tokenHash: best.tokenHash
87
+ };
88
+ const canonicalMetadata = readStoredRootMetadata(params.canonicalRootDir);
89
+ if (canonicalMetadata.accessTokenHash === params.canonicalTokenHash && canonicalMetadata.deviceId?.trim() === params.deviceId.trim() && canonicalMetadata.currentTokenStateClaimed === true) return {
90
+ rootDir: best.rootDir,
91
+ tokenHash: best.tokenHash
92
+ };
93
+ let siblingEntries = [];
94
+ try {
95
+ siblingEntries = fs.readdirSync(parentDir, { withFileTypes: true });
96
+ } catch {
97
+ return {
98
+ rootDir: best.rootDir,
99
+ tokenHash: best.tokenHash
100
+ };
101
+ }
102
+ for (const entry of siblingEntries) {
103
+ if (!entry.isDirectory()) continue;
104
+ if (entry.name === params.canonicalTokenHash) continue;
105
+ const candidateRootDir = path.join(parentDir, entry.name);
106
+ if (!isCompatibleStorageRoot({
107
+ candidateRootDir,
108
+ homeserver: params.homeserver,
109
+ userId: params.userId,
110
+ accountKey: params.accountKey,
111
+ deviceId: params.deviceId,
112
+ requireExplicitDeviceMatch: Boolean(params.deviceId)
113
+ })) continue;
114
+ const candidateScore = scoreStorageRoot(candidateRootDir);
115
+ if (candidateScore <= 0) continue;
116
+ const candidateMtimeMs = resolveStorageRootMtimeMs(candidateRootDir);
117
+ if (candidateScore > best.score || best.rootDir !== params.canonicalRootDir && candidateScore === best.score && candidateMtimeMs > best.mtimeMs) best = {
118
+ rootDir: candidateRootDir,
119
+ tokenHash: entry.name,
120
+ score: candidateScore,
121
+ mtimeMs: candidateMtimeMs
122
+ };
123
+ }
124
+ return {
125
+ rootDir: best.rootDir,
126
+ tokenHash: best.tokenHash
127
+ };
128
+ }
129
+ function resolveMatrixStoragePaths(params) {
130
+ const env = params.env ?? process.env;
131
+ const canonical = resolveMatrixAccountStorageRoot({
132
+ stateDir: params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir),
133
+ homeserver: params.homeserver,
134
+ userId: params.userId,
135
+ accessToken: params.accessToken,
136
+ accountId: params.accountId
137
+ });
138
+ const { rootDir, tokenHash } = resolvePreferredMatrixStorageRoot({
139
+ canonicalRootDir: canonical.rootDir,
140
+ canonicalTokenHash: canonical.tokenHash,
141
+ homeserver: params.homeserver,
142
+ userId: params.userId,
143
+ accountKey: canonical.accountKey,
144
+ deviceId: params.deviceId
145
+ });
146
+ return {
147
+ rootDir,
148
+ storagePath: path.join(rootDir, "bot-storage.json"),
149
+ cryptoPath: path.join(rootDir, "crypto"),
150
+ metaPath: path.join(rootDir, STORAGE_META_FILENAME),
151
+ recoveryKeyPath: path.join(rootDir, "recovery-key.json"),
152
+ idbSnapshotPath: path.join(rootDir, IDB_SNAPSHOT_FILENAME),
153
+ accountKey: canonical.accountKey,
154
+ tokenHash
155
+ };
156
+ }
157
+ function resolveMatrixStateFilePath(params) {
158
+ const storagePaths = resolveMatrixStoragePaths({
159
+ homeserver: params.auth.homeserver,
160
+ userId: params.auth.userId,
161
+ accessToken: params.auth.accessToken,
162
+ accountId: params.accountId ?? params.auth.accountId,
163
+ deviceId: params.auth.deviceId,
164
+ env: params.env,
165
+ stateDir: params.stateDir
166
+ });
167
+ return path.join(storagePaths.rootDir, params.filename);
168
+ }
169
+ async function maybeMigrateLegacyStorage(params) {
170
+ const legacy = resolveLegacyStoragePaths(params.env);
171
+ const hasLegacyStorage = fs.existsSync(legacy.storagePath);
172
+ const hasLegacyCrypto = fs.existsSync(legacy.cryptoPath);
173
+ if (!hasLegacyStorage && !hasLegacyCrypto) return;
174
+ const hasTargetStorage = fs.existsSync(params.storagePaths.storagePath);
175
+ const hasTargetCrypto = fs.existsSync(params.storagePaths.cryptoPath);
176
+ const shouldMigrateStorage = hasLegacyStorage && !hasTargetStorage;
177
+ const shouldMigrateCrypto = hasLegacyCrypto && !hasTargetCrypto;
178
+ if (!shouldMigrateStorage && !shouldMigrateCrypto) return;
179
+ assertLegacyMigrationAccountSelection({ accountKey: params.storagePaths.accountKey });
180
+ const logger = getMatrixRuntime().logging.getChildLogger({ module: "matrix-storage" });
181
+ const { maybeCreateMatrixMigrationSnapshot } = await import("./migration-snapshot.runtime-CKHE3xF9.js");
182
+ await maybeCreateMatrixMigrationSnapshot({
183
+ trigger: "matrix-client-fallback",
184
+ env: params.env,
185
+ log: logger
186
+ });
187
+ fs.mkdirSync(params.storagePaths.rootDir, { recursive: true });
188
+ const moved = [];
189
+ const skippedExistingTargets = [];
190
+ try {
191
+ if (shouldMigrateStorage) moveLegacyStoragePathOrThrow({
192
+ sourcePath: legacy.storagePath,
193
+ targetPath: params.storagePaths.storagePath,
194
+ label: "sync store",
195
+ moved
196
+ });
197
+ else if (hasLegacyStorage) skippedExistingTargets.push(`- sync store remains at ${legacy.storagePath} because ${params.storagePaths.storagePath} already exists`);
198
+ if (shouldMigrateCrypto) moveLegacyStoragePathOrThrow({
199
+ sourcePath: legacy.cryptoPath,
200
+ targetPath: params.storagePaths.cryptoPath,
201
+ label: "crypto store",
202
+ moved
203
+ });
204
+ else if (hasLegacyCrypto) skippedExistingTargets.push(`- crypto store remains at ${legacy.cryptoPath} because ${params.storagePaths.cryptoPath} already exists`);
205
+ } catch (err) {
206
+ const rollbackError = rollbackLegacyMoves(moved);
207
+ throw new Error(rollbackError ? `Failed migrating legacy Matrix client storage: ${String(err)}. Rollback also failed: ${rollbackError}` : `Failed migrating legacy Matrix client storage: ${String(err)}`, { cause: err });
208
+ }
209
+ if (moved.length > 0) logger.info(`matrix: migrated legacy client storage into ${params.storagePaths.rootDir}\n${moved.map((entry) => `- ${entry.label}: ${entry.sourcePath} -> ${entry.targetPath}`).join("\n")}`);
210
+ if (skippedExistingTargets.length > 0) logger.warn?.(`matrix: legacy client storage still exists in the flat path because some account-scoped targets already existed.\n${skippedExistingTargets.join("\n")}`);
211
+ }
212
+ function moveLegacyStoragePathOrThrow(params) {
213
+ if (!fs.existsSync(params.sourcePath)) return;
214
+ if (fs.existsSync(params.targetPath)) throw new Error(`legacy Matrix ${params.label} target already exists (${params.targetPath}); refusing to overwrite it automatically`);
215
+ fs.renameSync(params.sourcePath, params.targetPath);
216
+ params.moved.push({
217
+ sourcePath: params.sourcePath,
218
+ targetPath: params.targetPath,
219
+ label: params.label
220
+ });
221
+ }
222
+ function rollbackLegacyMoves(moved) {
223
+ for (const entry of moved.toReversed()) try {
224
+ if (!fs.existsSync(entry.targetPath) || fs.existsSync(entry.sourcePath)) continue;
225
+ fs.renameSync(entry.targetPath, entry.sourcePath);
226
+ } catch (err) {
227
+ return `${entry.label} (${entry.targetPath} -> ${entry.sourcePath}): ${String(err)}`;
228
+ }
229
+ return null;
230
+ }
231
+ function writeStoredRootMetadata(metaPath, payload) {
232
+ try {
233
+ saveJsonFile(metaPath, payload);
234
+ return true;
235
+ } catch {
236
+ return false;
237
+ }
238
+ }
239
+ function writeStorageMeta(params) {
240
+ const existing = readStoredRootMetadata(params.storagePaths.rootDir);
241
+ return writeStoredRootMetadata(params.storagePaths.metaPath, {
242
+ homeserver: params.homeserver,
243
+ userId: params.userId,
244
+ accountId: params.accountId ?? DEFAULT_ACCOUNT_KEY,
245
+ accessTokenHash: params.storagePaths.tokenHash,
246
+ deviceId: params.deviceId ?? null,
247
+ currentTokenStateClaimed: params.currentTokenStateClaimed ?? existing.currentTokenStateClaimed === true,
248
+ createdAt: existing.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
249
+ });
250
+ }
251
+ function claimCurrentTokenStorageState(params) {
252
+ const metadata = readStoredRootMetadata(params.rootDir);
253
+ if (!metadata.accessTokenHash?.trim()) return false;
254
+ return writeStoredRootMetadata(path.join(params.rootDir, STORAGE_META_FILENAME), {
255
+ homeserver: metadata.homeserver,
256
+ userId: metadata.userId,
257
+ accountId: metadata.accountId ?? DEFAULT_ACCOUNT_KEY,
258
+ accessTokenHash: metadata.accessTokenHash,
259
+ deviceId: metadata.deviceId ?? null,
260
+ currentTokenStateClaimed: true,
261
+ createdAt: metadata.createdAt ?? (/* @__PURE__ */ new Date()).toISOString()
262
+ });
263
+ }
264
+ function repairCurrentTokenStorageMetaDeviceId(params) {
265
+ return writeStorageMeta({
266
+ storagePaths: resolveMatrixStoragePaths({
267
+ homeserver: params.homeserver,
268
+ userId: params.userId,
269
+ accessToken: params.accessToken,
270
+ accountId: params.accountId,
271
+ env: params.env,
272
+ stateDir: params.stateDir
273
+ }),
274
+ homeserver: params.homeserver,
275
+ userId: params.userId,
276
+ accountId: params.accountId,
277
+ deviceId: params.deviceId
278
+ });
279
+ }
280
+ //#endregion
281
+ export { resolveMatrixStoragePaths as a, resolveMatrixStateFilePath as i, maybeMigrateLegacyStorage as n, writeStorageMeta as o, repairCurrentTokenStorageMetaDeviceId as r, claimCurrentTokenStorageState as t };
@@ -0,0 +1,149 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { a as resolveMatrixTargetIdentity } from "./target-ids-80nQ2gql.js";
3
+ import { a as listBindingsForAccount, c as resolveBindingKey, i as listAllBindings, n as getMatrixThreadBindingManager, o as removeBindingRecord } from "./thread-bindings-shared-DK-d-oYX.js";
4
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
5
+ import { getSessionBindingService } from "openclaw/plugin-sdk/conversation-binding-runtime";
6
+ import { formatThreadBindingDisabledError, formatThreadBindingSpawnDisabledError, resolveThreadBindingSpawnPolicy } from "openclaw/plugin-sdk/conversation-runtime";
7
+ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ //#region extensions/matrix/src/matrix/subagent-hooks.ts
9
+ var subagent_hooks_exports = /* @__PURE__ */ __exportAll({
10
+ handleMatrixSubagentDeliveryTarget: () => handleMatrixSubagentDeliveryTarget,
11
+ handleMatrixSubagentEnded: () => handleMatrixSubagentEnded,
12
+ handleMatrixSubagentSpawning: () => handleMatrixSubagentSpawning
13
+ });
14
+ function summarizeError(err) {
15
+ if (err instanceof Error) return err.message;
16
+ if (typeof err === "string") return err;
17
+ return "error";
18
+ }
19
+ function resolveMatrixBindingThreadId(binding) {
20
+ const { conversationId, parentConversationId } = binding.conversation;
21
+ return parentConversationId && parentConversationId !== conversationId ? conversationId : void 0;
22
+ }
23
+ function resolveMatrixBindingDeliveryOrigin(binding, fallbackAccountId) {
24
+ const boundRoomId = binding.conversation.parentConversationId ?? binding.conversation.conversationId;
25
+ const threadId = resolveMatrixBindingThreadId(binding);
26
+ return {
27
+ channel: "matrix",
28
+ accountId: binding.conversation.accountId ?? fallbackAccountId,
29
+ to: `room:${boundRoomId}`,
30
+ ...threadId ? { threadId } : {}
31
+ };
32
+ }
33
+ async function handleMatrixSubagentSpawning(api, event) {
34
+ if (!event.threadRequested) return;
35
+ if (event.requester?.channel?.trim().toLowerCase() !== "matrix") return;
36
+ const accountId = normalizeOptionalString(event.requester?.accountId) || DEFAULT_ACCOUNT_ID;
37
+ const policy = resolveThreadBindingSpawnPolicy({
38
+ cfg: api.config,
39
+ channel: "matrix",
40
+ accountId,
41
+ kind: "subagent"
42
+ });
43
+ if (!policy.enabled) return {
44
+ status: "error",
45
+ error: formatThreadBindingDisabledError({
46
+ channel: policy.channel,
47
+ accountId: policy.accountId,
48
+ kind: "subagent"
49
+ })
50
+ };
51
+ if (!policy.spawnEnabled) return {
52
+ status: "error",
53
+ error: formatThreadBindingSpawnDisabledError({
54
+ channel: policy.channel,
55
+ accountId: policy.accountId,
56
+ kind: "subagent"
57
+ })
58
+ };
59
+ const rawTo = normalizeOptionalString(event.requester?.to) ?? "";
60
+ const matrixTarget = rawTo ? resolveMatrixTargetIdentity(rawTo) : null;
61
+ const roomId = matrixTarget?.kind === "room" ? matrixTarget.id : "";
62
+ if (!roomId) return {
63
+ status: "error",
64
+ error: "Cannot create Matrix thread binding: no room target in spawn request (requester.to must be a Matrix room ID)."
65
+ };
66
+ const bindingService = getSessionBindingService();
67
+ const capabilities = bindingService.getCapabilities({
68
+ channel: "matrix",
69
+ accountId
70
+ });
71
+ if (!capabilities.adapterAvailable || !capabilities.bindSupported) return {
72
+ status: "error",
73
+ error: `No Matrix session binding adapter available for account "${accountId}". Is the Matrix channel running?`
74
+ };
75
+ if (!capabilities.placements.includes("child")) return {
76
+ status: "error",
77
+ error: `Matrix session binding adapter for account "${accountId}" does not support child thread bindings.`
78
+ };
79
+ try {
80
+ return {
81
+ status: "ok",
82
+ threadBindingReady: true,
83
+ deliveryOrigin: resolveMatrixBindingDeliveryOrigin(await bindingService.bind({
84
+ targetSessionKey: event.childSessionKey,
85
+ targetKind: "subagent",
86
+ conversation: {
87
+ channel: "matrix",
88
+ accountId,
89
+ conversationId: roomId
90
+ },
91
+ placement: "child",
92
+ metadata: {
93
+ agentId: event.agentId?.trim() || void 0,
94
+ label: normalizeOptionalString(event.label) || void 0,
95
+ boundBy: "system"
96
+ }
97
+ }), accountId)
98
+ };
99
+ } catch (err) {
100
+ return {
101
+ status: "error",
102
+ error: `Matrix thread bind failed: ${summarizeError(err)}`
103
+ };
104
+ }
105
+ }
106
+ async function handleMatrixSubagentEnded(event) {
107
+ const accountId = normalizeOptionalString(event.accountId) || void 0;
108
+ const matching = (accountId ? listBindingsForAccount(accountId) : listAllBindings()).filter((entry) => entry.targetSessionKey === event.targetSessionKey && entry.targetKind === "subagent");
109
+ const removedBindingKeys = /* @__PURE__ */ new Set();
110
+ if (event.sendFarewell) {
111
+ const bindingService = getSessionBindingService();
112
+ const reason = normalizeOptionalString(event.reason) || "subagent-ended";
113
+ for (const binding of matching) {
114
+ const bindingId = resolveBindingKey(binding);
115
+ if ((await bindingService.unbind({
116
+ bindingId,
117
+ reason
118
+ })).some((entry) => entry.bindingId === bindingId)) removedBindingKeys.add(bindingId);
119
+ }
120
+ }
121
+ const affectedAccountIds = /* @__PURE__ */ new Set();
122
+ for (const binding of matching) {
123
+ if (removedBindingKeys.has(resolveBindingKey(binding))) continue;
124
+ if (removeBindingRecord(binding)) affectedAccountIds.add(binding.accountId);
125
+ }
126
+ for (const acctId of affectedAccountIds) await getMatrixThreadBindingManager(acctId)?.persist();
127
+ }
128
+ function handleMatrixSubagentDeliveryTarget(event) {
129
+ if (!event.expectsCompletionMessage) return;
130
+ if (event.requesterOrigin?.channel?.trim().toLowerCase() !== "matrix") return;
131
+ const requesterAccountId = normalizeOptionalString(event.requesterOrigin?.accountId);
132
+ const requesterThreadId = event.requesterOrigin?.threadId != null && event.requesterOrigin.threadId !== "" ? String(event.requesterOrigin.threadId).trim() : "";
133
+ const bindings = (requesterAccountId ? listBindingsForAccount(requesterAccountId) : listAllBindings()).filter((entry) => entry.targetSessionKey === event.childSessionKey && entry.targetKind === "subagent");
134
+ if (bindings.length === 0) return;
135
+ let binding;
136
+ if (requesterThreadId) binding = bindings.find((entry) => entry.conversationId === requesterThreadId && (!requesterAccountId || entry.accountId === requesterAccountId));
137
+ if (!binding && bindings.length === 1) binding = bindings[0];
138
+ if (!binding) return;
139
+ const roomId = binding.parentConversationId ?? binding.conversationId;
140
+ const threadId = binding.parentConversationId && binding.parentConversationId !== binding.conversationId ? binding.conversationId : void 0;
141
+ return { origin: {
142
+ channel: "matrix",
143
+ accountId: binding.accountId,
144
+ to: `room:${roomId}`,
145
+ ...threadId ? { threadId } : {}
146
+ } };
147
+ }
148
+ //#endregion
149
+ export { subagent_hooks_exports as i, handleMatrixSubagentEnded as n, handleMatrixSubagentSpawning as r, handleMatrixSubagentDeliveryTarget as t };
@@ -0,0 +1,23 @@
1
+ import { n as handleMatrixSubagentEnded, r as handleMatrixSubagentSpawning, t as handleMatrixSubagentDeliveryTarget } from "./subagent-hooks-DQbyqq9V.js";
2
+ //#region extensions/matrix/subagent-hooks-api.ts
3
+ let matrixSubagentHooksPromise = null;
4
+ function loadMatrixSubagentHooksModule() {
5
+ matrixSubagentHooksPromise ??= import("./subagent-hooks-DQbyqq9V.js").then((n) => n.i);
6
+ return matrixSubagentHooksPromise;
7
+ }
8
+ function registerMatrixSubagentHooks(api) {
9
+ api.on("subagent_spawning", async (event) => {
10
+ const { handleMatrixSubagentSpawning } = await loadMatrixSubagentHooksModule();
11
+ return await handleMatrixSubagentSpawning(api, event);
12
+ });
13
+ api.on("subagent_ended", async (event) => {
14
+ const { handleMatrixSubagentEnded } = await loadMatrixSubagentHooksModule();
15
+ await handleMatrixSubagentEnded(event);
16
+ });
17
+ api.on("subagent_delivery_target", async (event) => {
18
+ const { handleMatrixSubagentDeliveryTarget } = await loadMatrixSubagentHooksModule();
19
+ return handleMatrixSubagentDeliveryTarget(event);
20
+ });
21
+ }
22
+ //#endregion
23
+ export { handleMatrixSubagentDeliveryTarget, handleMatrixSubagentEnded, handleMatrixSubagentSpawning, registerMatrixSubagentHooks };
@@ -0,0 +1,12 @@
1
+ //#region extensions/matrix/src/matrix/sync-state.ts
2
+ function isMatrixReadySyncState(state) {
3
+ return state === "PREPARED" || state === "SYNCING" || state === "CATCHUP";
4
+ }
5
+ function isMatrixDisconnectedSyncState(state) {
6
+ return state === "RECONNECTING" || state === "ERROR" || state === "STOPPED";
7
+ }
8
+ function isMatrixTerminalSyncState(state) {
9
+ return state === "STOPPED";
10
+ }
11
+ //#endregion
12
+ export { isMatrixReadySyncState as n, isMatrixTerminalSyncState as r, isMatrixDisconnectedSyncState as t };
@@ -0,0 +1,77 @@
1
+ import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ //#region extensions/matrix/src/matrix/target-ids.ts
3
+ const MATRIX_PREFIX = "matrix:";
4
+ const ROOM_PREFIX = "room:";
5
+ const CHANNEL_PREFIX = "channel:";
6
+ const USER_PREFIX = "user:";
7
+ function stripKnownPrefixes(raw, prefixes) {
8
+ let normalized = raw.trim();
9
+ while (normalized) {
10
+ const lowered = normalizeLowercaseStringOrEmpty(normalized);
11
+ const matched = prefixes.find((prefix) => lowered.startsWith(prefix));
12
+ if (!matched) return normalized;
13
+ normalized = normalized.slice(matched.length).trim();
14
+ }
15
+ return normalized;
16
+ }
17
+ function resolveMatrixTargetIdentity(raw) {
18
+ const normalized = stripKnownPrefixes(raw, [MATRIX_PREFIX]);
19
+ if (!normalized) return null;
20
+ const lowered = normalizeLowercaseStringOrEmpty(normalized);
21
+ if (lowered.startsWith(USER_PREFIX)) {
22
+ const id = normalized.slice(5).trim();
23
+ return id ? {
24
+ kind: "user",
25
+ id
26
+ } : null;
27
+ }
28
+ if (lowered.startsWith(ROOM_PREFIX)) {
29
+ const id = normalized.slice(5).trim();
30
+ return id ? {
31
+ kind: "room",
32
+ id
33
+ } : null;
34
+ }
35
+ if (lowered.startsWith(CHANNEL_PREFIX)) {
36
+ const id = normalized.slice(8).trim();
37
+ return id ? {
38
+ kind: "room",
39
+ id
40
+ } : null;
41
+ }
42
+ if (isMatrixQualifiedUserId(normalized)) return {
43
+ kind: "user",
44
+ id: normalized
45
+ };
46
+ return {
47
+ kind: "room",
48
+ id: normalized
49
+ };
50
+ }
51
+ function isMatrixQualifiedUserId(raw) {
52
+ const trimmed = raw.trim();
53
+ return trimmed.startsWith("@") && trimmed.includes(":");
54
+ }
55
+ function normalizeMatrixResolvableTarget(raw) {
56
+ return stripKnownPrefixes(raw, [
57
+ MATRIX_PREFIX,
58
+ ROOM_PREFIX,
59
+ CHANNEL_PREFIX
60
+ ]);
61
+ }
62
+ function normalizeMatrixMessagingTarget(raw) {
63
+ return stripKnownPrefixes(raw, [
64
+ MATRIX_PREFIX,
65
+ ROOM_PREFIX,
66
+ CHANNEL_PREFIX,
67
+ USER_PREFIX
68
+ ]) || void 0;
69
+ }
70
+ function resolveMatrixDirectUserId(params) {
71
+ if (params.chatType !== "direct") return;
72
+ if (!normalizeMatrixResolvableTarget(params.to ?? "").startsWith("!")) return;
73
+ const userId = stripKnownPrefixes(params.from ?? "", [MATRIX_PREFIX, USER_PREFIX]);
74
+ return isMatrixQualifiedUserId(userId) ? userId : void 0;
75
+ }
76
+ //#endregion
77
+ export { resolveMatrixTargetIdentity as a, resolveMatrixDirectUserId as i, normalizeMatrixMessagingTarget as n, normalizeMatrixResolvableTarget as r, isMatrixQualifiedUserId as t };
@@ -0,0 +1,4 @@
1
+ import { r as setMatrixRuntime } from "./runtime-Dog86njy.js";
2
+ import { t as matrixPlugin } from "./channel-H_6lMgwf.js";
3
+ import { t as MatrixClient } from "./sdk-B2vZA27-.js";
4
+ export { MatrixClient, matrixPlugin, setMatrixRuntime };
@@ -0,0 +1,17 @@
1
+ import { a as resolveMatrixTargetIdentity } from "./target-ids-80nQ2gql.js";
2
+ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ //#region extensions/matrix/src/thread-binding-api.ts
4
+ const defaultTopLevelPlacement = "child";
5
+ function resolveMatrixInboundConversation(params) {
6
+ const rawTarget = params.to?.trim() || params.conversationId?.trim() || "";
7
+ const target = rawTarget ? resolveMatrixTargetIdentity(rawTarget) : null;
8
+ const parentConversationId = target?.kind === "room" ? target.id : void 0;
9
+ const threadId = params.threadId != null ? normalizeOptionalString(String(params.threadId)) : void 0;
10
+ if (threadId) return {
11
+ conversationId: threadId,
12
+ ...parentConversationId ? { parentConversationId } : {}
13
+ };
14
+ return parentConversationId ? { conversationId: parentConversationId } : null;
15
+ }
16
+ //#endregion
17
+ export { resolveMatrixInboundConversation as n, defaultTopLevelPlacement as t };
@@ -0,0 +1,2 @@
1
+ import { n as resolveMatrixInboundConversation, t as defaultTopLevelPlacement } from "./thread-binding-api-Cq_E-E1K.js";
2
+ export { defaultTopLevelPlacement, resolveMatrixInboundConversation as resolveInboundConversation };