@openclaw/matrix 2026.3.12 → 2026.5.9-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 (205) 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-DJNir3Rb.js +1116 -0
  15. package/dist/channel-plugin-api.js +2 -0
  16. package/dist/channel.runtime-BQu0hTih.js +246 -0
  17. package/dist/cli-BmfTmg7x.js +1340 -0
  18. package/dist/cli-metadata-B-PCEzrA.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-C_81r_Ck.js +4125 -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-BXWBFIqm.js +25 -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-DI5SCofx.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-BIH49vRr.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 +788 -1
  112. package/package.json +82 -16
  113. package/CHANGELOG.md +0 -98
  114. package/index.ts +0 -22
  115. package/src/actions.ts +0 -195
  116. package/src/channel.directory.test.ts +0 -154
  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 -100
  160. package/src/matrix/monitor/auto-join.ts +0 -72
  161. package/src/matrix/monitor/direct.test.ts +0 -400
  162. package/src/matrix/monitor/direct.ts +0 -152
  163. package/src/matrix/monitor/events.test.ts +0 -172
  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 -767
  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 -154
  194. package/src/matrix/send-queue.ts +0 -28
  195. package/src/matrix/send.test.ts +0 -326
  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 -67
  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/tool-actions.ts +0 -164
  205. package/src/types.ts +0 -118
@@ -0,0 +1,319 @@
1
+ import { t as buildTimeoutAbortSignal } from "./timeout-abort-signal-CtaIaP1v.js";
2
+ import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
3
+ import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
4
+ import { closeDispatcher, createPinnedDispatcher, resolvePinnedHostnameWithPolicy } from "openclaw/plugin-sdk/ssrf-dispatcher";
5
+ //#region extensions/matrix/src/matrix/sdk/event-helpers.ts
6
+ function matrixEventToRaw(event, opts = {}) {
7
+ const unsigned = event.getUnsigned?.() ?? {};
8
+ const eventWithOriginalContent = event;
9
+ const content = opts.contentMode === "original" ? eventWithOriginalContent.getOriginalContent?.() ?? event.getContent?.() ?? {} : event.getContent?.() ?? eventWithOriginalContent.getOriginalContent?.() ?? {};
10
+ const raw = {
11
+ event_id: event.getId() ?? "",
12
+ sender: event.getSender() ?? "",
13
+ type: event.getType() ?? "",
14
+ origin_server_ts: event.getTs() ?? 0,
15
+ content: content || {},
16
+ unsigned
17
+ };
18
+ const stateKey = resolveMatrixStateKey(event);
19
+ if (typeof stateKey === "string") raw.state_key = stateKey;
20
+ return raw;
21
+ }
22
+ function parseMxc(url) {
23
+ const match = /^mxc:\/\/([^/]+)\/(.+)$/.exec(url.trim());
24
+ if (!match) return null;
25
+ return {
26
+ server: match[1],
27
+ mediaId: match[2]
28
+ };
29
+ }
30
+ function buildHttpError(statusCode, bodyText) {
31
+ let message = `Matrix HTTP ${statusCode}`;
32
+ if (bodyText.trim()) try {
33
+ const parsed = JSON.parse(bodyText);
34
+ if (typeof parsed.error === "string" && parsed.error.trim()) message = parsed.error.trim();
35
+ else message = bodyText.slice(0, 500);
36
+ } catch {
37
+ message = bodyText.slice(0, 500);
38
+ }
39
+ return Object.assign(new Error(message), { statusCode });
40
+ }
41
+ function resolveMatrixStateKey(event) {
42
+ const direct = event.getStateKey?.();
43
+ if (typeof direct === "string") return direct;
44
+ const wireContent = event.getWireContent?.();
45
+ if (wireContent && typeof wireContent.state_key === "string") return wireContent.state_key;
46
+ const rawEvent = event.event;
47
+ if (rawEvent && typeof rawEvent.state_key === "string") return rawEvent.state_key;
48
+ }
49
+ //#endregion
50
+ //#region extensions/matrix/src/matrix/media-errors.ts
51
+ const MATRIX_MEDIA_SIZE_LIMIT_ERROR_MESSAGE = "Matrix media exceeds configured size limit";
52
+ var MatrixMediaSizeLimitError = class extends Error {
53
+ constructor(message = MATRIX_MEDIA_SIZE_LIMIT_ERROR_MESSAGE, options) {
54
+ super(message, options);
55
+ this.code = "MATRIX_MEDIA_SIZE_LIMIT";
56
+ this.name = "MatrixMediaSizeLimitError";
57
+ }
58
+ };
59
+ function isMatrixMediaSizeLimitError(err) {
60
+ if (err instanceof MatrixMediaSizeLimitError) return true;
61
+ if (!(err instanceof Error) || err.cause === void 0) return false;
62
+ return isMatrixMediaSizeLimitError(err.cause);
63
+ }
64
+ //#endregion
65
+ //#region extensions/matrix/src/matrix/sdk/read-response-with-limit.ts
66
+ async function readResponseWithLimit$1(res, maxBytes, opts) {
67
+ return await readResponseWithLimit(res, maxBytes, {
68
+ ...opts,
69
+ onIdleTimeout: opts?.onIdleTimeout ?? (({ chunkTimeoutMs }) => /* @__PURE__ */ new Error(`Matrix media download stalled: no data received for ${chunkTimeoutMs}ms`))
70
+ });
71
+ }
72
+ //#endregion
73
+ //#region extensions/matrix/src/matrix/sdk/transport.ts
74
+ function normalizeEndpoint(endpoint) {
75
+ if (!endpoint) return "/";
76
+ return endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
77
+ }
78
+ function applyQuery(url, qs) {
79
+ if (!qs) return;
80
+ for (const [key, rawValue] of Object.entries(qs)) {
81
+ if (rawValue === void 0 || rawValue === null) continue;
82
+ if (Array.isArray(rawValue)) {
83
+ for (const item of rawValue) {
84
+ if (item === void 0 || item === null) continue;
85
+ url.searchParams.append(key, String(item));
86
+ }
87
+ continue;
88
+ }
89
+ url.searchParams.set(key, String(rawValue));
90
+ }
91
+ }
92
+ function isRedirectStatus(statusCode) {
93
+ return statusCode >= 300 && statusCode < 400;
94
+ }
95
+ function toFetchUrl(resource) {
96
+ if (resource instanceof URL) return resource.toString();
97
+ if (typeof resource === "string") return resource;
98
+ return resource.url;
99
+ }
100
+ function buildBufferedResponse(params) {
101
+ const response = new Response(params.body, {
102
+ status: params.source.status,
103
+ statusText: params.source.statusText,
104
+ headers: new Headers(params.source.headers)
105
+ });
106
+ try {
107
+ Object.defineProperty(response, "url", {
108
+ value: params.source.url || params.url,
109
+ configurable: true
110
+ });
111
+ } catch {}
112
+ return response;
113
+ }
114
+ async function fetchWithMatrixDispatcher(params) {
115
+ return await fetchWithRuntimeDispatcherOrMockedGlobal(params.url, params.init);
116
+ }
117
+ async function fetchWithMatrixGuardedRedirects(params) {
118
+ let currentUrl = new URL(params.url);
119
+ let method = (params.init?.method ?? "GET").toUpperCase();
120
+ let body = params.init?.body;
121
+ let headers = new Headers(params.init?.headers ?? {});
122
+ const maxRedirects = 5;
123
+ const visited = /* @__PURE__ */ new Set();
124
+ const { signal, cleanup } = buildTimeoutAbortSignal({
125
+ timeoutMs: params.timeoutMs,
126
+ signal: params.signal,
127
+ operation: "matrix.guarded-redirect-fetch",
128
+ url: params.url
129
+ });
130
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount += 1) {
131
+ let dispatcher;
132
+ try {
133
+ dispatcher = createPinnedDispatcher(await resolvePinnedHostnameWithPolicy(currentUrl.hostname, { policy: params.ssrfPolicy }), params.dispatcherPolicy, params.ssrfPolicy);
134
+ const response = await fetchWithMatrixDispatcher({
135
+ url: currentUrl.toString(),
136
+ init: {
137
+ ...params.init,
138
+ method,
139
+ body,
140
+ headers,
141
+ redirect: "manual",
142
+ signal,
143
+ dispatcher
144
+ }
145
+ });
146
+ if (!isRedirectStatus(response.status)) return {
147
+ response,
148
+ release: async () => {
149
+ cleanup();
150
+ await closeDispatcher(dispatcher);
151
+ },
152
+ finalUrl: currentUrl.toString()
153
+ };
154
+ const location = response.headers.get("location");
155
+ if (!location) {
156
+ cleanup();
157
+ await closeDispatcher(dispatcher);
158
+ throw new Error(`Matrix redirect missing location header (${currentUrl.toString()})`);
159
+ }
160
+ const nextUrl = new URL(location, currentUrl);
161
+ if (nextUrl.protocol !== currentUrl.protocol) {
162
+ cleanup();
163
+ await closeDispatcher(dispatcher);
164
+ throw new Error(`Blocked cross-protocol redirect (${currentUrl.protocol} -> ${nextUrl.protocol})`);
165
+ }
166
+ const nextUrlString = nextUrl.toString();
167
+ if (visited.has(nextUrlString)) {
168
+ cleanup();
169
+ await closeDispatcher(dispatcher);
170
+ throw new Error("Redirect loop detected");
171
+ }
172
+ visited.add(nextUrlString);
173
+ if (nextUrl.origin !== currentUrl.origin) {
174
+ headers = new Headers(headers);
175
+ headers.delete("authorization");
176
+ }
177
+ if (response.status === 303 || (response.status === 301 || response.status === 302) && method !== "GET" && method !== "HEAD") {
178
+ method = "GET";
179
+ body = void 0;
180
+ headers = new Headers(headers);
181
+ headers.delete("content-type");
182
+ headers.delete("content-length");
183
+ }
184
+ response.body?.cancel();
185
+ await closeDispatcher(dispatcher);
186
+ currentUrl = nextUrl;
187
+ } catch (error) {
188
+ cleanup();
189
+ await closeDispatcher(dispatcher);
190
+ throw error;
191
+ }
192
+ }
193
+ cleanup();
194
+ throw new Error(`Too many redirects while requesting ${params.url}`);
195
+ }
196
+ function createMatrixGuardedFetch(params) {
197
+ return (async (resource, init) => {
198
+ const url = toFetchUrl(resource);
199
+ const { signal, ...requestInit } = init ?? {};
200
+ const { response, release } = await fetchWithMatrixGuardedRedirects({
201
+ url,
202
+ init: requestInit,
203
+ signal: signal ?? void 0,
204
+ ssrfPolicy: params.ssrfPolicy,
205
+ dispatcherPolicy: params.dispatcherPolicy
206
+ });
207
+ try {
208
+ return buildBufferedResponse({
209
+ source: response,
210
+ body: await response.arrayBuffer(),
211
+ url
212
+ });
213
+ } finally {
214
+ await release();
215
+ }
216
+ });
217
+ }
218
+ async function performMatrixRequest(params) {
219
+ const isAbsoluteEndpoint = params.endpoint.startsWith("http://") || params.endpoint.startsWith("https://");
220
+ if (isAbsoluteEndpoint && params.allowAbsoluteEndpoint !== true) throw new Error(`Absolute Matrix endpoint is blocked by default: ${params.endpoint}. Set allowAbsoluteEndpoint=true to opt in.`);
221
+ const baseUrl = isAbsoluteEndpoint ? new URL(params.endpoint) : new URL(normalizeEndpoint(params.endpoint), params.homeserver);
222
+ applyQuery(baseUrl, params.qs);
223
+ const headers = new Headers();
224
+ headers.set("Accept", params.raw ? "*/*" : "application/json");
225
+ if (params.accessToken) headers.set("Authorization", `Bearer ${params.accessToken}`);
226
+ let body;
227
+ if (params.body !== void 0) if (params.body instanceof Uint8Array || params.body instanceof ArrayBuffer || typeof params.body === "string") body = params.body;
228
+ else {
229
+ headers.set("Content-Type", "application/json");
230
+ body = JSON.stringify(params.body);
231
+ }
232
+ const { response, release } = await fetchWithMatrixGuardedRedirects({
233
+ url: baseUrl.toString(),
234
+ init: {
235
+ method: params.method,
236
+ headers,
237
+ body
238
+ },
239
+ timeoutMs: params.timeoutMs,
240
+ ssrfPolicy: params.ssrfPolicy,
241
+ dispatcherPolicy: params.dispatcherPolicy
242
+ });
243
+ try {
244
+ if (params.raw) {
245
+ const contentLength = response.headers.get("content-length");
246
+ if (params.maxBytes && contentLength) {
247
+ const length = Number(contentLength);
248
+ if (Number.isFinite(length) && length > params.maxBytes) throw new MatrixMediaSizeLimitError(`Matrix media exceeds configured size limit (${length} bytes > ${params.maxBytes} bytes)`);
249
+ }
250
+ const bytes = params.maxBytes ? await readResponseWithLimit$1(response, params.maxBytes, {
251
+ onOverflow: ({ maxBytes, size }) => new MatrixMediaSizeLimitError(`Matrix media exceeds configured size limit (${size} bytes > ${maxBytes} bytes)`),
252
+ chunkTimeoutMs: params.readIdleTimeoutMs
253
+ }) : Buffer.from(await response.arrayBuffer());
254
+ return {
255
+ response,
256
+ text: bytes.toString("utf8"),
257
+ buffer: bytes
258
+ };
259
+ }
260
+ const text = await response.text();
261
+ return {
262
+ response,
263
+ text,
264
+ buffer: Buffer.from(text, "utf8")
265
+ };
266
+ } finally {
267
+ await release();
268
+ }
269
+ }
270
+ //#endregion
271
+ //#region extensions/matrix/src/matrix/sdk/http-client.ts
272
+ var MatrixAuthedHttpClient = class {
273
+ constructor(params) {
274
+ this.homeserver = params.homeserver;
275
+ this.accessToken = params.accessToken;
276
+ this.ssrfPolicy = params.ssrfPolicy;
277
+ this.dispatcherPolicy = params.dispatcherPolicy;
278
+ }
279
+ async requestJson(params) {
280
+ const { response, text } = await performMatrixRequest({
281
+ homeserver: this.homeserver,
282
+ accessToken: this.accessToken,
283
+ method: params.method,
284
+ endpoint: params.endpoint,
285
+ qs: params.qs,
286
+ body: params.body,
287
+ timeoutMs: params.timeoutMs,
288
+ ssrfPolicy: this.ssrfPolicy,
289
+ dispatcherPolicy: this.dispatcherPolicy,
290
+ allowAbsoluteEndpoint: params.allowAbsoluteEndpoint
291
+ });
292
+ if (!response.ok) throw buildHttpError(response.status, text);
293
+ if ((response.headers.get("content-type") ?? "").includes("application/json")) {
294
+ if (!text.trim()) return {};
295
+ return JSON.parse(text);
296
+ }
297
+ return text;
298
+ }
299
+ async requestRaw(params) {
300
+ const { response, buffer } = await performMatrixRequest({
301
+ homeserver: this.homeserver,
302
+ accessToken: this.accessToken,
303
+ method: params.method,
304
+ endpoint: params.endpoint,
305
+ qs: params.qs,
306
+ timeoutMs: params.timeoutMs,
307
+ raw: true,
308
+ maxBytes: params.maxBytes,
309
+ readIdleTimeoutMs: params.readIdleTimeoutMs,
310
+ ssrfPolicy: this.ssrfPolicy,
311
+ dispatcherPolicy: this.dispatcherPolicy,
312
+ allowAbsoluteEndpoint: params.allowAbsoluteEndpoint
313
+ });
314
+ if (!response.ok) throw buildHttpError(response.status, buffer.toString("utf8"));
315
+ return buffer;
316
+ }
317
+ };
318
+ //#endregion
319
+ export { matrixEventToRaw as a, isMatrixMediaSizeLimitError as i, createMatrixGuardedFetch as n, parseMxc as o, MatrixMediaSizeLimitError as r, MatrixAuthedHttpClient as t };
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { n as registerMatrixCliMetadata } from "./cli-metadata-B-PCEzrA.js";
2
+ import { registerMatrixSubagentHooks } from "./subagent-hooks-api.js";
3
+ import { defineBundledChannelEntry } from "openclaw/plugin-sdk/channel-entry-contract";
4
+ //#region extensions/matrix/index.ts
5
+ let matrixHandlersRuntimePromise = null;
6
+ function loadMatrixHandlersRuntimeModule() {
7
+ matrixHandlersRuntimePromise ??= import("./plugin-entry.handlers.runtime.js");
8
+ return matrixHandlersRuntimePromise;
9
+ }
10
+ function registerMatrixFullRuntime(api) {
11
+ api.registerGatewayMethod("matrix.verify.recoveryKey", async (ctx) => {
12
+ const { handleVerifyRecoveryKey } = await loadMatrixHandlersRuntimeModule();
13
+ await handleVerifyRecoveryKey(ctx);
14
+ });
15
+ api.registerGatewayMethod("matrix.verify.bootstrap", async (ctx) => {
16
+ const { handleVerificationBootstrap } = await loadMatrixHandlersRuntimeModule();
17
+ await handleVerificationBootstrap(ctx);
18
+ });
19
+ api.registerGatewayMethod("matrix.verify.status", async (ctx) => {
20
+ const { handleVerificationStatus } = await loadMatrixHandlersRuntimeModule();
21
+ await handleVerificationStatus(ctx);
22
+ });
23
+ registerMatrixSubagentHooks(api);
24
+ }
25
+ var matrix_default = defineBundledChannelEntry({
26
+ id: "matrix",
27
+ name: "Matrix",
28
+ description: "Matrix channel plugin (matrix-js-sdk)",
29
+ importMetaUrl: import.meta.url,
30
+ plugin: {
31
+ specifier: "./channel-plugin-api.js",
32
+ exportName: "matrixPlugin"
33
+ },
34
+ secrets: {
35
+ specifier: "./secret-contract-api.js",
36
+ exportName: "channelSecrets"
37
+ },
38
+ runtime: {
39
+ specifier: "./runtime-setter-api.js",
40
+ exportName: "setMatrixRuntime"
41
+ },
42
+ registerCliMetadata: registerMatrixCliMetadata,
43
+ registerFull: registerMatrixFullRuntime
44
+ });
45
+ //#endregion
46
+ export { matrix_default as default, registerMatrixFullRuntime };
@@ -0,0 +1,41 @@
1
+ import { t as ensureMatrixCryptoRuntime } from "./deps-C6WqKY7m.js";
2
+ import { createRequire } from "node:module";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import crypto from "node:crypto";
6
+ //#region extensions/matrix/src/matrix/legacy-crypto-inspector.ts
7
+ function resolveLegacyMachineStorePath(params) {
8
+ const hashedDir = path.join(params.cryptoRootDir, crypto.createHash("sha256").update(params.deviceId).digest("hex"));
9
+ if (fs.existsSync(path.join(hashedDir, "matrix-sdk-crypto.sqlite3"))) return hashedDir;
10
+ if (fs.existsSync(path.join(params.cryptoRootDir, "matrix-sdk-crypto.sqlite3"))) return params.cryptoRootDir;
11
+ const match = fs.readdirSync(params.cryptoRootDir, { withFileTypes: true }).find((entry) => entry.isDirectory() && fs.existsSync(path.join(params.cryptoRootDir, entry.name, "matrix-sdk-crypto.sqlite3")));
12
+ return match ? path.join(params.cryptoRootDir, match.name) : null;
13
+ }
14
+ async function inspectLegacyMatrixCryptoStore(params) {
15
+ const machineStorePath = resolveLegacyMachineStorePath(params);
16
+ if (!machineStorePath) throw new Error(`Matrix legacy crypto store not found for device ${params.deviceId}`);
17
+ const requireFn = createRequire(import.meta.url);
18
+ await ensureMatrixCryptoRuntime({
19
+ requireFn,
20
+ resolveFn: requireFn.resolve.bind(requireFn),
21
+ log: params.log
22
+ });
23
+ const { DeviceId, OlmMachine, StoreType, UserId } = requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
24
+ const machine = await OlmMachine.initialize(new UserId(params.userId), new DeviceId(params.deviceId), machineStorePath, "", StoreType.Sqlite);
25
+ try {
26
+ const [backupKeys, roomKeyCounts] = await Promise.all([machine.getBackupKeys(), machine.roomKeyCounts()]);
27
+ return {
28
+ deviceId: params.deviceId,
29
+ roomKeyCounts: roomKeyCounts ? {
30
+ total: typeof roomKeyCounts.total === "number" ? roomKeyCounts.total : 0,
31
+ backedUp: typeof roomKeyCounts.backedUp === "number" ? roomKeyCounts.backedUp : 0
32
+ } : null,
33
+ backupVersion: typeof backupKeys?.backupVersion === "string" && backupKeys.backupVersion.trim() ? backupKeys.backupVersion : null,
34
+ decryptionKeyBase64: typeof backupKeys?.decryptionKeyBase64 === "string" && backupKeys.decryptionKeyBase64.trim() ? backupKeys.decryptionKeyBase64 : null
35
+ };
36
+ } finally {
37
+ machine.close();
38
+ }
39
+ }
40
+ //#endregion
41
+ export { inspectLegacyMatrixCryptoStore };
@@ -0,0 +1,85 @@
1
+ import { t as getMatrixRuntime } from "./runtime-Dog86njy.js";
2
+ import { a as resolveMatrixStoragePaths } from "./storage-tC3ujLiW.js";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { readJsonFileWithFallback, writeJsonFileAtomically } from "openclaw/plugin-sdk/json-store";
6
+ import fs from "node:fs/promises";
7
+ //#region extensions/matrix/src/matrix/monitor/legacy-crypto-restore.ts
8
+ function isMigrationState(value) {
9
+ return Boolean(value) && typeof value === "object" && value.version === 1;
10
+ }
11
+ async function resolvePendingMigrationStatePath(params) {
12
+ const { rootDir } = resolveMatrixStoragePaths({
13
+ homeserver: params.auth.homeserver,
14
+ userId: params.auth.userId,
15
+ accessToken: params.auth.accessToken,
16
+ accountId: params.auth.accountId,
17
+ deviceId: params.auth.deviceId,
18
+ stateDir: params.stateDir
19
+ });
20
+ const directStatePath = path.join(rootDir, "legacy-crypto-migration.json");
21
+ const { value: directValue } = await readJsonFileWithFallback(directStatePath, null);
22
+ if (isMigrationState(directValue) && directValue.restoreStatus === "pending") return {
23
+ statePath: directStatePath,
24
+ value: directValue
25
+ };
26
+ const accountStorageDir = path.dirname(rootDir);
27
+ let siblingEntries = [];
28
+ try {
29
+ siblingEntries = (await fs.readdir(accountStorageDir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).filter((entry) => path.join(accountStorageDir, entry) !== rootDir).toSorted((left, right) => left.localeCompare(right));
30
+ } catch {
31
+ return {
32
+ statePath: directStatePath,
33
+ value: directValue
34
+ };
35
+ }
36
+ for (const sibling of siblingEntries) {
37
+ const siblingStatePath = path.join(accountStorageDir, sibling, "legacy-crypto-migration.json");
38
+ const { value } = await readJsonFileWithFallback(siblingStatePath, null);
39
+ if (isMigrationState(value) && value.restoreStatus === "pending") return {
40
+ statePath: siblingStatePath,
41
+ value
42
+ };
43
+ }
44
+ return {
45
+ statePath: directStatePath,
46
+ value: directValue
47
+ };
48
+ }
49
+ async function maybeRestoreLegacyMatrixBackup(params) {
50
+ const env = params.env ?? process.env;
51
+ const { statePath, value } = await resolvePendingMigrationStatePath({
52
+ stateDir: params.stateDir ?? getMatrixRuntime().state.resolveStateDir(env, os.homedir),
53
+ auth: params.auth
54
+ });
55
+ if (!isMigrationState(value) || value.restoreStatus !== "pending") return { kind: "skipped" };
56
+ const restore = await params.client.restoreRoomKeyBackup();
57
+ const localOnlyKeys = value.roomKeyCounts && value.roomKeyCounts.total > value.roomKeyCounts.backedUp ? value.roomKeyCounts.total - value.roomKeyCounts.backedUp : 0;
58
+ if (restore.success) {
59
+ await writeJsonFileAtomically(statePath, {
60
+ ...value,
61
+ restoreStatus: "completed",
62
+ restoredAt: restore.restoredAt ?? (/* @__PURE__ */ new Date()).toISOString(),
63
+ importedCount: restore.imported,
64
+ totalCount: restore.total,
65
+ lastError: null
66
+ });
67
+ return {
68
+ kind: "restored",
69
+ imported: restore.imported,
70
+ total: restore.total,
71
+ localOnlyKeys
72
+ };
73
+ }
74
+ await writeJsonFileAtomically(statePath, {
75
+ ...value,
76
+ lastError: restore.error ?? "unknown"
77
+ });
78
+ return {
79
+ kind: "failed",
80
+ error: restore.error ?? "unknown",
81
+ localOnlyKeys
82
+ };
83
+ }
84
+ //#endregion
85
+ export { maybeRestoreLegacyMatrixBackup };
@@ -0,0 +1,78 @@
1
+ import { t as getMatrixRuntime } from "./runtime-Dog86njy.js";
2
+ import { format } from "node:util";
3
+ import { redactSensitiveText } from "openclaw/plugin-sdk/logging-core";
4
+ //#region extensions/matrix/src/matrix/sdk/logger.ts
5
+ function noop() {}
6
+ let forceConsoleLogging = false;
7
+ function setMatrixConsoleLogging(enabled) {
8
+ forceConsoleLogging = enabled;
9
+ }
10
+ function resolveRuntimeLogger(module) {
11
+ if (forceConsoleLogging) return null;
12
+ try {
13
+ return getMatrixRuntime().logging.getChildLogger({ module: `matrix:${module}` });
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+ function formatMessage(module, messageOrObject) {
19
+ if (messageOrObject.length === 0) return `[${module}]`;
20
+ return redactSensitiveText(`[${module}] ${format(...messageOrObject)}`);
21
+ }
22
+ var ConsoleLogger = class {
23
+ emit(level, module, ...messageOrObject) {
24
+ const runtimeLogger = resolveRuntimeLogger(module);
25
+ const message = formatMessage(module, messageOrObject);
26
+ if (runtimeLogger) {
27
+ if (level === "debug") {
28
+ runtimeLogger.debug?.(message);
29
+ return;
30
+ }
31
+ runtimeLogger[level](message);
32
+ return;
33
+ }
34
+ if (level === "debug") {
35
+ console.debug(message);
36
+ return;
37
+ }
38
+ console[level](message);
39
+ }
40
+ trace(module, ...messageOrObject) {
41
+ this.emit("debug", module, ...messageOrObject);
42
+ }
43
+ debug(module, ...messageOrObject) {
44
+ this.emit("debug", module, ...messageOrObject);
45
+ }
46
+ info(module, ...messageOrObject) {
47
+ this.emit("info", module, ...messageOrObject);
48
+ }
49
+ warn(module, ...messageOrObject) {
50
+ this.emit("warn", module, ...messageOrObject);
51
+ }
52
+ error(module, ...messageOrObject) {
53
+ this.emit("error", module, ...messageOrObject);
54
+ }
55
+ };
56
+ let activeLogger = new ConsoleLogger();
57
+ const LogService = {
58
+ setLogger(logger) {
59
+ activeLogger = logger;
60
+ },
61
+ trace(module, ...messageOrObject) {
62
+ activeLogger.trace(module, ...messageOrObject);
63
+ },
64
+ debug(module, ...messageOrObject) {
65
+ activeLogger.debug(module, ...messageOrObject);
66
+ },
67
+ info(module, ...messageOrObject) {
68
+ activeLogger.info(module, ...messageOrObject);
69
+ },
70
+ warn(module, ...messageOrObject) {
71
+ activeLogger.warn(module, ...messageOrObject);
72
+ },
73
+ error(module, ...messageOrObject) {
74
+ activeLogger.error(module, ...messageOrObject);
75
+ }
76
+ };
77
+ //#endregion
78
+ export { setMatrixConsoleLogging as i, LogService as n, noop as r, ConsoleLogger as t };
@@ -0,0 +1,99 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { i as setMatrixConsoleLogging, n as LogService, t as ConsoleLogger } from "./logger-CnZRVrux.js";
3
+ import { logger } from "matrix-js-sdk/lib/logger.js";
4
+ //#region extensions/matrix/src/matrix/client/logging.ts
5
+ var logging_exports = /* @__PURE__ */ __exportAll({
6
+ createMatrixJsSdkClientLogger: () => createMatrixJsSdkClientLogger,
7
+ ensureMatrixSdkLoggingConfigured: () => ensureMatrixSdkLoggingConfigured,
8
+ setMatrixSdkConsoleLogging: () => setMatrixSdkConsoleLogging,
9
+ setMatrixSdkLogMode: () => setMatrixSdkLogMode
10
+ });
11
+ let matrixSdkLoggingConfigured = false;
12
+ let matrixSdkLogMode = "default";
13
+ const matrixSdkBaseLogger = new ConsoleLogger();
14
+ let matrixJsSdkRootLoggerSnapshot = null;
15
+ function shouldSuppressMatrixHttpNotFound(module, messageOrObject) {
16
+ if (!module.includes("MatrixHttpClient")) return false;
17
+ return messageOrObject.some((entry) => {
18
+ if (!entry || typeof entry !== "object") return false;
19
+ return entry.errcode === "M_NOT_FOUND";
20
+ });
21
+ }
22
+ function ensureMatrixSdkLoggingConfigured() {
23
+ if (!matrixSdkLoggingConfigured) matrixSdkLoggingConfigured = true;
24
+ applyMatrixSdkLogger();
25
+ }
26
+ function setMatrixSdkLogMode(mode) {
27
+ matrixSdkLogMode = mode;
28
+ if (!matrixSdkLoggingConfigured) return;
29
+ applyMatrixSdkLogger();
30
+ }
31
+ function setMatrixSdkConsoleLogging(enabled) {
32
+ setMatrixConsoleLogging(enabled);
33
+ }
34
+ function createMatrixJsSdkClientLogger(prefix = "matrix") {
35
+ return createMatrixJsSdkLoggerInstance(prefix);
36
+ }
37
+ function applyMatrixSdkLogger() {
38
+ if (matrixSdkLogMode === "quiet") {
39
+ setMatrixJsSdkRootLoggerLevel("silent");
40
+ LogService.setLogger({
41
+ trace: () => {},
42
+ debug: () => {},
43
+ info: () => {},
44
+ warn: () => {},
45
+ error: () => {}
46
+ });
47
+ return;
48
+ }
49
+ setMatrixJsSdkRootLoggerLevel("debug");
50
+ LogService.setLogger({
51
+ trace: (module, ...messageOrObject) => matrixSdkBaseLogger.trace(module, ...messageOrObject),
52
+ debug: (module, ...messageOrObject) => matrixSdkBaseLogger.debug(module, ...messageOrObject),
53
+ info: (module, ...messageOrObject) => matrixSdkBaseLogger.info(module, ...messageOrObject),
54
+ warn: (module, ...messageOrObject) => matrixSdkBaseLogger.warn(module, ...messageOrObject),
55
+ error: (module, ...messageOrObject) => {
56
+ if (shouldSuppressMatrixHttpNotFound(module, messageOrObject)) return;
57
+ matrixSdkBaseLogger.error(module, ...messageOrObject);
58
+ }
59
+ });
60
+ }
61
+ function setMatrixJsSdkRootLoggerLevel(level) {
62
+ const logger$1 = logger;
63
+ matrixJsSdkRootLoggerSnapshot ??= {
64
+ level: logger$1.getLevel?.(),
65
+ methodFactory: logger$1.methodFactory
66
+ };
67
+ if (level === "silent") {
68
+ logger$1.methodFactory = () => () => void 0;
69
+ logger$1.setLevel?.("silent", false);
70
+ logger$1.rebuild?.();
71
+ return;
72
+ }
73
+ logger$1.methodFactory = matrixJsSdkRootLoggerSnapshot.methodFactory;
74
+ const previousLevel = matrixJsSdkRootLoggerSnapshot.level;
75
+ if (typeof previousLevel === "string" || typeof previousLevel === "number") logger$1.setLevel?.(previousLevel, false);
76
+ logger$1.rebuild?.();
77
+ }
78
+ function createMatrixJsSdkLoggerInstance(prefix) {
79
+ const log = (method, ...messageOrObject) => {
80
+ if (matrixSdkLogMode === "quiet") return;
81
+ matrixSdkBaseLogger[method](prefix, ...messageOrObject);
82
+ };
83
+ return {
84
+ trace: (...messageOrObject) => log("trace", ...messageOrObject),
85
+ debug: (...messageOrObject) => log("debug", ...messageOrObject),
86
+ info: (...messageOrObject) => log("info", ...messageOrObject),
87
+ warn: (...messageOrObject) => log("warn", ...messageOrObject),
88
+ error: (...messageOrObject) => {
89
+ if (shouldSuppressMatrixHttpNotFound(prefix, messageOrObject)) return;
90
+ log("error", ...messageOrObject);
91
+ },
92
+ getChild: (namespace) => {
93
+ const nextNamespace = namespace.trim();
94
+ return createMatrixJsSdkLoggerInstance(nextNamespace ? `${prefix}.${nextNamespace}` : prefix);
95
+ }
96
+ };
97
+ }
98
+ //#endregion
99
+ export { setMatrixSdkLogMode as i, logging_exports as n, setMatrixSdkConsoleLogging as r, createMatrixJsSdkClientLogger as t };