@openclaw/matrix 2026.3.13 → 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 (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-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 -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,22 @@
1
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
2
+ //#region extensions/matrix/src/cli-metadata.ts
3
+ function registerMatrixCliMetadata(api) {
4
+ api.registerCli(async ({ program }) => {
5
+ const { registerMatrixCli } = await import("./cli-BmfTmg7x.js");
6
+ registerMatrixCli({ program });
7
+ }, { descriptors: [{
8
+ name: "matrix",
9
+ description: "Manage Matrix accounts, verification, devices, and profile state",
10
+ hasSubcommands: true
11
+ }] });
12
+ }
13
+ //#endregion
14
+ //#region extensions/matrix/cli-metadata.ts
15
+ var cli_metadata_default = definePluginEntry({
16
+ id: "matrix",
17
+ name: "Matrix",
18
+ description: "Matrix channel plugin (matrix-js-sdk)",
19
+ register: registerMatrixCliMetadata
20
+ });
21
+ //#endregion
22
+ export { registerMatrixCliMetadata as n, cli_metadata_default as t };
@@ -0,0 +1,2 @@
1
+ import { n as registerMatrixCliMetadata, t as cli_metadata_default } from "./cli-metadata-B-PCEzrA.js";
2
+ export { cli_metadata_default as default, registerMatrixCliMetadata };
@@ -0,0 +1,25 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { u as resolveMatrixRoomId } from "./send-Bo0DU1ca.js";
3
+ import { n as withResolvedRuntimeMatrixClient } from "./client-bootstrap-Rb8oHvhH.js";
4
+ //#region extensions/matrix/src/matrix/actions/client.ts
5
+ var client_exports = /* @__PURE__ */ __exportAll({
6
+ withResolvedActionClient: () => withResolvedActionClient,
7
+ withResolvedRoomAction: () => withResolvedRoomAction,
8
+ withStartedActionClient: () => withStartedActionClient
9
+ });
10
+ async function withResolvedActionClient(opts, run, mode = "stop") {
11
+ return await withResolvedRuntimeMatrixClient(opts, run, mode);
12
+ }
13
+ async function withStartedActionClient(opts, run) {
14
+ return await withResolvedActionClient({
15
+ ...opts,
16
+ readiness: "started"
17
+ }, run, "persist");
18
+ }
19
+ async function withResolvedRoomAction(roomId, opts, run) {
20
+ return await withResolvedActionClient(opts, async (client) => {
21
+ return await run(client, await resolveMatrixRoomId(client, roomId));
22
+ });
23
+ }
24
+ //#endregion
25
+ export { withStartedActionClient as i, withResolvedActionClient as n, withResolvedRoomAction as r, client_exports as t };
@@ -0,0 +1,31 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { t as getMatrixScopedEnvVarNames } from "./env-vars-C7uQCTKn.js";
3
+ import { i as resolveScopedMatrixEnvConfig, r as resolveMatrixEnvAuthReadiness, t as hasReadyMatrixEnvAuth } from "./env-auth-BJqGI8M6.js";
4
+ import { n as validateMatrixHomeserverUrl, t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DiK9j7jz.js";
5
+ import { t as isBunRuntime } from "./runtime-C6X4h_SJ.js";
6
+ import { i as resolveMatrixConfigForAccount, n as resolveMatrixAuth, r as resolveMatrixAuthContext, t as backfillMatrixAuthDeviceIdAfterStartup } from "./config--5-S2Akv.js";
7
+ import { t as createMatrixClient } from "./create-client-DCnqDaqd.js";
8
+ import { i as resolveSharedMatrixClient, n as releaseSharedClientInstance, o as stopSharedClientForAccount, r as removeSharedClientInstance, s as stopSharedClientInstance, t as acquireSharedMatrixClient } from "./shared-CpMoYKm1.js";
9
+ //#region extensions/matrix/src/matrix/client.ts
10
+ var client_exports = /* @__PURE__ */ __exportAll({
11
+ acquireSharedMatrixClient: () => acquireSharedMatrixClient,
12
+ backfillMatrixAuthDeviceIdAfterStartup: () => backfillMatrixAuthDeviceIdAfterStartup,
13
+ createMatrixClient: () => createMatrixClient,
14
+ getMatrixScopedEnvVarNames: () => getMatrixScopedEnvVarNames,
15
+ hasReadyMatrixEnvAuth: () => hasReadyMatrixEnvAuth,
16
+ isBunRuntime: () => isBunRuntime,
17
+ releaseSharedClientInstance: () => releaseSharedClientInstance,
18
+ removeSharedClientInstance: () => removeSharedClientInstance,
19
+ resolveMatrixAuth: () => resolveMatrixAuth,
20
+ resolveMatrixAuthContext: () => resolveMatrixAuthContext,
21
+ resolveMatrixConfigForAccount: () => resolveMatrixConfigForAccount,
22
+ resolveMatrixEnvAuthReadiness: () => resolveMatrixEnvAuthReadiness,
23
+ resolveScopedMatrixEnvConfig: () => resolveScopedMatrixEnvConfig,
24
+ resolveSharedMatrixClient: () => resolveSharedMatrixClient,
25
+ resolveValidatedMatrixHomeserverUrl: () => resolveValidatedMatrixHomeserverUrl,
26
+ stopSharedClientForAccount: () => stopSharedClientForAccount,
27
+ stopSharedClientInstance: () => stopSharedClientInstance,
28
+ validateMatrixHomeserverUrl: () => validateMatrixHomeserverUrl
29
+ });
30
+ //#endregion
31
+ export { client_exports as t };
@@ -0,0 +1,114 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { t as getActiveMatrixClient } from "./active-client-uhlxdhEy.js";
3
+ import { t as isBunRuntime } from "./runtime-C6X4h_SJ.js";
4
+ import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
5
+ //#region extensions/matrix/src/matrix/client-bootstrap.ts
6
+ var client_bootstrap_exports = /* @__PURE__ */ __exportAll({
7
+ resolveRuntimeMatrixClientWithReadiness: () => resolveRuntimeMatrixClientWithReadiness,
8
+ stopResolvedRuntimeMatrixClient: () => stopResolvedRuntimeMatrixClient,
9
+ withResolvedRuntimeMatrixClient: () => withResolvedRuntimeMatrixClient
10
+ });
11
+ let matrixSharedClientRuntimeDepsPromise;
12
+ async function loadMatrixSharedClientRuntimeDeps() {
13
+ matrixSharedClientRuntimeDepsPromise ??= Promise.all([import("./client-_hckQNGW.js").then((n) => n.t), import("./shared-CpMoYKm1.js").then((n) => n.a)]).then(([clientModule, sharedModule]) => ({
14
+ acquireSharedMatrixClient: clientModule.acquireSharedMatrixClient,
15
+ resolveMatrixAuthContext: clientModule.resolveMatrixAuthContext,
16
+ releaseSharedClientInstance: sharedModule.releaseSharedClientInstance
17
+ }));
18
+ return await matrixSharedClientRuntimeDepsPromise;
19
+ }
20
+ async function ensureResolvedClientReadiness(params) {
21
+ if (params.readiness === "started") {
22
+ await params.client.start();
23
+ return;
24
+ }
25
+ if (params.readiness === "prepared" || !params.readiness && params.preparedByDefault) await params.client.prepareForOneOff();
26
+ }
27
+ function ensureMatrixNodeRuntime() {
28
+ if (isBunRuntime()) throw new Error("Matrix support requires Node (bun runtime not supported)");
29
+ }
30
+ async function resolveRuntimeMatrixClient(opts) {
31
+ ensureMatrixNodeRuntime();
32
+ if (opts.client) {
33
+ await opts.onResolved?.(opts.client, { preparedByDefault: false });
34
+ return {
35
+ client: opts.client,
36
+ stopOnDone: false
37
+ };
38
+ }
39
+ if (!opts.cfg) throw new Error("Matrix runtime client requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.");
40
+ const cfg = requireRuntimeConfig(opts.cfg, "Matrix runtime client");
41
+ const { acquireSharedMatrixClient, releaseSharedClientInstance, resolveMatrixAuthContext } = await loadMatrixSharedClientRuntimeDeps();
42
+ const authContext = resolveMatrixAuthContext({
43
+ cfg,
44
+ accountId: opts.accountId
45
+ });
46
+ const active = getActiveMatrixClient(authContext.accountId);
47
+ if (active) {
48
+ await opts.onResolved?.(active, { preparedByDefault: false });
49
+ return {
50
+ client: active,
51
+ stopOnDone: false
52
+ };
53
+ }
54
+ const client = await acquireSharedMatrixClient({
55
+ cfg,
56
+ timeoutMs: opts.timeoutMs,
57
+ accountId: authContext.accountId,
58
+ startClient: false
59
+ });
60
+ try {
61
+ await opts.onResolved?.(client, { preparedByDefault: true });
62
+ } catch (err) {
63
+ await releaseSharedClientInstance(client, "stop");
64
+ throw err;
65
+ }
66
+ return {
67
+ client,
68
+ stopOnDone: true,
69
+ cleanup: async (mode) => {
70
+ await releaseSharedClientInstance(client, mode);
71
+ }
72
+ };
73
+ }
74
+ async function resolveRuntimeMatrixClientWithReadiness(opts) {
75
+ return await resolveRuntimeMatrixClient({
76
+ client: opts.client,
77
+ cfg: opts.cfg,
78
+ timeoutMs: opts.timeoutMs,
79
+ accountId: opts.accountId,
80
+ onResolved: async (client, context) => {
81
+ await ensureResolvedClientReadiness({
82
+ client,
83
+ readiness: opts.readiness,
84
+ preparedByDefault: context.preparedByDefault
85
+ });
86
+ }
87
+ });
88
+ }
89
+ async function stopResolvedRuntimeMatrixClient(resolved, mode = "stop") {
90
+ if (!resolved.stopOnDone) return;
91
+ if (resolved.cleanup) {
92
+ await resolved.cleanup(mode);
93
+ return;
94
+ }
95
+ if (mode === "persist") {
96
+ await resolved.client.stopAndPersist();
97
+ return;
98
+ }
99
+ if (mode === "discard") {
100
+ resolved.client.stopWithoutPersist();
101
+ return;
102
+ }
103
+ resolved.client.stop();
104
+ }
105
+ async function withResolvedRuntimeMatrixClient(opts, run, stopMode = "stop") {
106
+ const resolved = await resolveRuntimeMatrixClientWithReadiness(opts);
107
+ try {
108
+ return await run(resolved.client);
109
+ } finally {
110
+ await stopResolvedRuntimeMatrixClient(resolved, stopMode);
111
+ }
112
+ }
113
+ //#endregion
114
+ export { withResolvedRuntimeMatrixClient as n, client_bootstrap_exports as t };
@@ -0,0 +1,452 @@
1
+ import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount, o as resolveMatrixAccountStringValues } from "./account-selection-BWwIruri.js";
2
+ import { t as getMatrixScopedEnvVarNames } from "./env-vars-C7uQCTKn.js";
3
+ import { o as resolveMatrixBaseConfig, r as listNormalizedMatrixAccountIds, t as findMatrixAccountConfig } from "./account-config-D2W-V1eQ.js";
4
+ import { i as resolveScopedMatrixEnvConfig, n as resolveGlobalMatrixEnvConfig } from "./env-auth-BJqGI8M6.js";
5
+ import { t as resolveMatrixConfigFieldPath } from "./config-paths-nsVaysCu.js";
6
+ import { t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DiK9j7jz.js";
7
+ import { r as repairCurrentTokenStorageMetaDeviceId } from "./storage-tC3ujLiW.js";
8
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, normalizeAccountId as normalizeAccountId$1, normalizeOptionalAccountId as normalizeOptionalAccountId$1 } from "openclaw/plugin-sdk/account-id";
9
+ import { coerceSecretRef, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
10
+ import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
11
+ import { isPrivateNetworkOptInEnabled, ssrfPolicyFromDangerouslyAllowPrivateNetwork as ssrfPolicyFromDangerouslyAllowPrivateNetwork$1 } from "openclaw/plugin-sdk/ssrf-runtime";
12
+ import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
13
+ import { retryAsync } from "openclaw/plugin-sdk/retry-runtime";
14
+ //#region extensions/matrix/src/matrix/client/config.ts
15
+ let matrixAuthClientDepsPromise;
16
+ let matrixCredentialsReadDepsPromise;
17
+ let matrixCredentialsWriteRuntimePromise;
18
+ let matrixSecretInputDepsPromise;
19
+ let matrixAuthClientDepsForTest;
20
+ const MATRIX_AUTH_REQUEST_RETRY_RE = /\b(fetch failed|econnreset|econnrefused|enotfound|etimedout|ehostunreach|enetunreach|eai_again|und_err_|socket hang up|network|headers timeout|body timeout|connect timeout)\b/i;
21
+ async function loadMatrixAuthClientDeps() {
22
+ matrixAuthClientDepsPromise ??= Promise.all([import("./sdk-B2vZA27-.js").then((n) => n.n), import("./logging-DZHSPP5N.js").then((n) => n.n)]).then(([sdkModule, loggingModule]) => ({
23
+ MatrixClient: sdkModule.MatrixClient,
24
+ ensureMatrixSdkLoggingConfigured: loggingModule.ensureMatrixSdkLoggingConfigured
25
+ }));
26
+ return await matrixAuthClientDepsPromise;
27
+ }
28
+ async function loadMatrixCredentialsReadDeps() {
29
+ matrixCredentialsReadDepsPromise ??= import("./credentials-read-cmHgousK.js").then((n) => n.r).then((credentialsReadModule) => ({
30
+ loadMatrixCredentials: credentialsReadModule.loadMatrixCredentials,
31
+ credentialsMatchConfig: credentialsReadModule.credentialsMatchConfig
32
+ }));
33
+ return await matrixCredentialsReadDepsPromise;
34
+ }
35
+ async function loadMatrixCredentialsWriteRuntime() {
36
+ matrixCredentialsWriteRuntimePromise ??= import("./credentials-write.runtime-zniTq-Gr.js");
37
+ return await matrixCredentialsWriteRuntimePromise;
38
+ }
39
+ async function loadMatrixSecretInputDeps() {
40
+ matrixSecretInputDepsPromise ??= import("./config-secret-input.runtime-DiKFehsE.js").then((runtime) => ({ resolveConfiguredSecretInputString: runtime.resolveConfiguredSecretInputString }));
41
+ return await matrixSecretInputDepsPromise;
42
+ }
43
+ function shouldRetryMatrixAuthRequest(err) {
44
+ return MATRIX_AUTH_REQUEST_RETRY_RE.test(formatErrorMessage(err));
45
+ }
46
+ function isAbortSignalTriggered(signal) {
47
+ return signal?.aborted === true;
48
+ }
49
+ function credentialsMatchBackfillAuthLineage(params) {
50
+ if (!params.stored) return true;
51
+ return params.stored.homeserver === params.auth.homeserver && params.stored.userId === params.auth.userId && params.stored.accessToken === params.auth.accessToken;
52
+ }
53
+ async function retryMatrixAuthRequest(label, run) {
54
+ return await retryAsync(run, {
55
+ attempts: 3,
56
+ minDelayMs: matrixAuthClientDepsForTest?.retryMinDelayMs ?? 250,
57
+ maxDelayMs: 1500,
58
+ jitter: .1,
59
+ label,
60
+ shouldRetry: (err) => shouldRetryMatrixAuthRequest(err)
61
+ });
62
+ }
63
+ async function fetchMatrixWhoamiIdentity(params) {
64
+ const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixAuthClientDeps();
65
+ ensureMatrixSdkLoggingConfigured();
66
+ const tempClient = new MatrixClient(params.homeserver, params.accessToken, {
67
+ userId: params.userId,
68
+ ssrfPolicy: params.ssrfPolicy,
69
+ dispatcherPolicy: params.dispatcherPolicy
70
+ });
71
+ return await retryMatrixAuthRequest("matrix auth whoami", async () => {
72
+ return await tempClient.doRequest("GET", "/_matrix/client/v3/account/whoami");
73
+ });
74
+ }
75
+ function readEnvSecretRefFallback(params) {
76
+ const ref = coerceSecretRef(params.value, params.config?.secrets?.defaults);
77
+ if (!ref || ref.source !== "env" || !params.env) return;
78
+ const providerConfig = params.config?.secrets?.providers?.[ref.provider];
79
+ if (providerConfig) {
80
+ if (providerConfig.source !== "env") throw new Error(`Secret provider "${ref.provider}" has source "${providerConfig.source}" but ref requests "env".`);
81
+ if (providerConfig.allowlist && !providerConfig.allowlist.includes(ref.id)) throw new Error(`Environment variable "${ref.id}" is not allowlisted in secrets.providers.${ref.provider}.allowlist.`);
82
+ } else if (ref.provider !== (params.config?.secrets?.defaults?.env?.trim() || "default")) throw new Error(`Secret provider "${ref.provider}" is not configured (ref: ${ref.source}:${ref.provider}:${ref.id}).`);
83
+ const resolved = params.env[ref.id];
84
+ if (typeof resolved !== "string") return;
85
+ const trimmed = resolved.trim();
86
+ return trimmed.length > 0 ? trimmed : void 0;
87
+ }
88
+ function clean(value, path, opts) {
89
+ const ref = coerceSecretRef(value, opts?.config?.secrets?.defaults);
90
+ if (opts?.suppressSecretRef && ref) return "";
91
+ return normalizeResolvedSecretInputString({
92
+ value: opts?.allowEnvSecretRefFallback ? ref?.source === "env" ? readEnvSecretRefFallback({
93
+ value,
94
+ env: opts.env,
95
+ config: opts.config
96
+ }) ?? value : ref ? "" : value : value,
97
+ path,
98
+ defaults: opts?.config?.secrets?.defaults
99
+ }) ?? "";
100
+ }
101
+ function resolveMatrixBaseConfigFieldPath(field) {
102
+ return `channels.matrix.${field}`;
103
+ }
104
+ function shouldAllowEnvSecretRefFallback(field) {
105
+ return field === "accessToken" || field === "password";
106
+ }
107
+ function hasConfiguredSecretInputValue(value, cfg) {
108
+ return typeof value === "string" && value.trim().length > 0 || Boolean(coerceSecretRef(value, cfg.secrets?.defaults));
109
+ }
110
+ function hasConfiguredMatrixAccessTokenSource(params) {
111
+ const normalizedAccountId = normalizeAccountId$1(params.accountId);
112
+ const account = findMatrixAccountConfig(params.cfg, normalizedAccountId) ?? {};
113
+ const scopedAccessTokenVar = getMatrixScopedEnvVarNames(normalizedAccountId).accessToken;
114
+ if (hasConfiguredSecretInputValue(account.accessToken, params.cfg) || clean(params.env[scopedAccessTokenVar], scopedAccessTokenVar).length > 0) return true;
115
+ if (normalizedAccountId !== DEFAULT_ACCOUNT_ID$1) return false;
116
+ return hasConfiguredSecretInputValue(resolveMatrixBaseConfig(params.cfg).accessToken, params.cfg) || clean(params.env.MATRIX_ACCESS_TOKEN, "MATRIX_ACCESS_TOKEN").length > 0;
117
+ }
118
+ function resolveConfiguredMatrixAuthInput(params) {
119
+ const normalizedAccountId = normalizeAccountId$1(params.accountId);
120
+ const accountValue = (findMatrixAccountConfig(params.cfg, normalizedAccountId) ?? {})[params.field];
121
+ if (accountValue !== void 0) return {
122
+ value: accountValue,
123
+ path: resolveMatrixConfigFieldPath(params.cfg, normalizedAccountId, params.field)
124
+ };
125
+ const scopedKeys = getMatrixScopedEnvVarNames(normalizedAccountId);
126
+ const scopedValue = resolveScopedMatrixEnvConfig(normalizedAccountId, params.env)[params.field];
127
+ if (scopedValue !== void 0) return {
128
+ value: scopedValue,
129
+ path: params.field === "accessToken" ? scopedKeys.accessToken : scopedKeys.password
130
+ };
131
+ if (normalizedAccountId !== DEFAULT_ACCOUNT_ID$1) return;
132
+ const baseValue = resolveMatrixBaseConfig(params.cfg)[params.field];
133
+ if (baseValue !== void 0) return {
134
+ value: baseValue,
135
+ path: resolveMatrixBaseConfigFieldPath(params.field)
136
+ };
137
+ const globalValue = params.field === "accessToken" ? params.env.MATRIX_ACCESS_TOKEN : params.env.MATRIX_PASSWORD;
138
+ if (globalValue !== void 0) return {
139
+ value: globalValue,
140
+ path: params.field === "accessToken" ? "MATRIX_ACCESS_TOKEN" : "MATRIX_PASSWORD"
141
+ };
142
+ }
143
+ async function resolveConfiguredMatrixAuthSecretInput(params) {
144
+ const configured = resolveConfiguredMatrixAuthInput(params);
145
+ if (!configured) return;
146
+ if (!coerceSecretRef(configured.value, params.cfg.secrets?.defaults)) return normalizeResolvedSecretInputString({
147
+ value: configured.value,
148
+ path: configured.path,
149
+ defaults: params.cfg.secrets?.defaults
150
+ });
151
+ const { resolveConfiguredSecretInputString } = await loadMatrixSecretInputDeps();
152
+ const resolved = await resolveConfiguredSecretInputString({
153
+ config: params.cfg,
154
+ env: params.env,
155
+ value: configured.value,
156
+ path: configured.path,
157
+ unresolvedReasonStyle: "detailed"
158
+ });
159
+ if (resolved.value !== void 0) return resolved.value;
160
+ throw new Error(resolved.unresolvedRefReason ?? `${configured.path} SecretRef could not be resolved.`);
161
+ }
162
+ function readMatrixBaseConfigField(matrix, field, opts) {
163
+ return clean(matrix[field], resolveMatrixBaseConfigFieldPath(field), {
164
+ env: opts?.env,
165
+ config: opts?.config,
166
+ allowEnvSecretRefFallback: shouldAllowEnvSecretRefFallback(field),
167
+ suppressSecretRef: opts?.suppressSecretRef
168
+ });
169
+ }
170
+ function readMatrixAccountConfigField(cfg, accountId, account, field, opts) {
171
+ return clean(account[field], resolveMatrixConfigFieldPath(cfg, accountId, field), {
172
+ env: opts?.env,
173
+ config: opts?.config,
174
+ allowEnvSecretRefFallback: shouldAllowEnvSecretRefFallback(field),
175
+ suppressSecretRef: opts?.suppressSecretRef
176
+ });
177
+ }
178
+ function clampMatrixInitialSyncLimit(value) {
179
+ return typeof value === "number" ? Math.max(0, Math.floor(value)) : void 0;
180
+ }
181
+ function buildMatrixNetworkFields(params) {
182
+ const dispatcherPolicy = params.dispatcherPolicy ?? (params.proxy ? {
183
+ mode: "explicit-proxy",
184
+ proxyUrl: params.proxy
185
+ } : void 0);
186
+ if (!params.allowPrivateNetwork && !dispatcherPolicy) return {};
187
+ return {
188
+ ...params.allowPrivateNetwork ? {
189
+ allowPrivateNetwork: true,
190
+ ssrfPolicy: ssrfPolicyFromDangerouslyAllowPrivateNetwork$1(true)
191
+ } : {},
192
+ ...dispatcherPolicy ? { dispatcherPolicy } : {}
193
+ };
194
+ }
195
+ function hasScopedMatrixEnvConfig(accountId, env) {
196
+ const scoped = resolveScopedMatrixEnvConfig(accountId, env);
197
+ return Boolean(scoped.homeserver || scoped.userId || scoped.accessToken || scoped.password || scoped.deviceId || scoped.deviceName);
198
+ }
199
+ function resolveMatrixConfigForAccount(cfg, accountId, env = process.env) {
200
+ const matrix = resolveMatrixBaseConfig(cfg);
201
+ const account = findMatrixAccountConfig(cfg, accountId) ?? {};
202
+ const normalizedAccountId = normalizeAccountId$1(accountId);
203
+ const suppressInactivePasswordSecretRef = hasConfiguredMatrixAccessTokenSource({
204
+ cfg,
205
+ env,
206
+ accountId: normalizedAccountId
207
+ });
208
+ const fieldReadOptions = {
209
+ env,
210
+ config: cfg
211
+ };
212
+ const scopedEnv = resolveScopedMatrixEnvConfig(normalizedAccountId, env);
213
+ const globalEnv = resolveGlobalMatrixEnvConfig(env);
214
+ const accountField = (field) => readMatrixAccountConfigField(cfg, normalizedAccountId, account, field, {
215
+ ...fieldReadOptions,
216
+ suppressSecretRef: field === "password" ? suppressInactivePasswordSecretRef : void 0
217
+ });
218
+ const resolvedStrings = resolveMatrixAccountStringValues({
219
+ accountId: normalizedAccountId,
220
+ account: {
221
+ homeserver: accountField("homeserver"),
222
+ userId: accountField("userId"),
223
+ accessToken: accountField("accessToken"),
224
+ password: accountField("password"),
225
+ deviceId: accountField("deviceId"),
226
+ deviceName: accountField("deviceName")
227
+ },
228
+ scopedEnv,
229
+ channel: {
230
+ homeserver: readMatrixBaseConfigField(matrix, "homeserver", fieldReadOptions),
231
+ userId: readMatrixBaseConfigField(matrix, "userId", fieldReadOptions),
232
+ accessToken: readMatrixBaseConfigField(matrix, "accessToken", fieldReadOptions),
233
+ password: readMatrixBaseConfigField(matrix, "password", {
234
+ ...fieldReadOptions,
235
+ suppressSecretRef: suppressInactivePasswordSecretRef
236
+ }),
237
+ deviceId: readMatrixBaseConfigField(matrix, "deviceId", fieldReadOptions),
238
+ deviceName: readMatrixBaseConfigField(matrix, "deviceName", fieldReadOptions)
239
+ },
240
+ globalEnv
241
+ });
242
+ const initialSyncLimit = clampMatrixInitialSyncLimit(account.initialSyncLimit) ?? clampMatrixInitialSyncLimit(matrix.initialSyncLimit);
243
+ const encryption = typeof account.encryption === "boolean" ? account.encryption : matrix.encryption ?? false;
244
+ const allowPrivateNetwork = isPrivateNetworkOptInEnabled(account) || isPrivateNetworkOptInEnabled(matrix) ? true : void 0;
245
+ return {
246
+ homeserver: resolvedStrings.homeserver,
247
+ userId: resolvedStrings.userId,
248
+ accessToken: resolvedStrings.accessToken || void 0,
249
+ password: resolvedStrings.password || void 0,
250
+ deviceId: resolvedStrings.deviceId || void 0,
251
+ deviceName: resolvedStrings.deviceName || void 0,
252
+ initialSyncLimit,
253
+ encryption,
254
+ ...buildMatrixNetworkFields({
255
+ allowPrivateNetwork,
256
+ proxy: account.proxy ?? matrix.proxy
257
+ })
258
+ };
259
+ }
260
+ function resolveImplicitMatrixAccountId(cfg, env = process.env) {
261
+ if (requiresExplicitMatrixDefaultAccount(cfg, env)) return null;
262
+ return normalizeAccountId$1(resolveMatrixDefaultOrOnlyAccountId(cfg, env));
263
+ }
264
+ function resolveMatrixAuthContext(params) {
265
+ const cfg = requireRuntimeConfig(params.cfg, "Matrix auth context");
266
+ const env = params?.env ?? process.env;
267
+ const explicitAccountId = normalizeOptionalAccountId$1(params?.accountId);
268
+ const effectiveAccountId = explicitAccountId ?? resolveImplicitMatrixAccountId(cfg, env);
269
+ if (!effectiveAccountId) throw new Error("Multiple Matrix accounts are configured and channels.matrix.defaultAccount is not set. Set \"channels.matrix.defaultAccount\" to the intended account or pass --account <id>.");
270
+ if (explicitAccountId && explicitAccountId !== DEFAULT_ACCOUNT_ID$1 && !listNormalizedMatrixAccountIds(cfg).includes(explicitAccountId) && !hasScopedMatrixEnvConfig(explicitAccountId, env)) throw new Error(`Matrix account "${explicitAccountId}" is not configured. Add channels.matrix.accounts.${explicitAccountId} or define scoped ${getMatrixScopedEnvVarNames(explicitAccountId).accessToken.replace(/_ACCESS_TOKEN$/, "")}_* variables.`);
271
+ return {
272
+ cfg,
273
+ env,
274
+ accountId: effectiveAccountId,
275
+ resolved: resolveMatrixConfigForAccount(cfg, effectiveAccountId, env)
276
+ };
277
+ }
278
+ async function resolveMatrixAuth(params) {
279
+ if (!params?.cfg) throw new Error("Matrix auth requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.");
280
+ const { cfg, env, accountId, resolved } = resolveMatrixAuthContext({
281
+ cfg: params.cfg,
282
+ env: params.env,
283
+ accountId: params.accountId
284
+ });
285
+ const accessToken = await resolveConfiguredMatrixAuthSecretInput({
286
+ cfg,
287
+ env,
288
+ accountId,
289
+ field: "accessToken"
290
+ }) ?? resolved.accessToken;
291
+ const tokenAuthPassword = resolved.password;
292
+ const homeserver = await resolveValidatedMatrixHomeserverUrl(resolved.homeserver, { dangerouslyAllowPrivateNetwork: resolved.allowPrivateNetwork });
293
+ const { loadMatrixCredentials, credentialsMatchConfig } = await loadMatrixCredentialsReadDeps();
294
+ const cached = loadMatrixCredentials(env, accountId);
295
+ const cachedCredentials = cached && credentialsMatchConfig(cached, {
296
+ homeserver,
297
+ userId: resolved.userId || "",
298
+ accessToken
299
+ }) ? cached : null;
300
+ if (accessToken) {
301
+ let userId = resolved.userId;
302
+ const hasMatchingCachedToken = cachedCredentials?.accessToken === accessToken;
303
+ let knownDeviceId = hasMatchingCachedToken ? cachedCredentials?.deviceId || resolved.deviceId : resolved.deviceId;
304
+ if (!userId) {
305
+ const whoami = await fetchMatrixWhoamiIdentity({
306
+ homeserver,
307
+ accessToken,
308
+ userId,
309
+ ssrfPolicy: resolved.ssrfPolicy,
310
+ dispatcherPolicy: resolved.dispatcherPolicy
311
+ });
312
+ const fetchedUserId = whoami.user_id?.trim();
313
+ if (!fetchedUserId) throw new Error("Matrix whoami did not return user_id");
314
+ userId = fetchedUserId;
315
+ knownDeviceId = knownDeviceId || whoami.device_id?.trim() || resolved.deviceId;
316
+ }
317
+ if (!cachedCredentials || !hasMatchingCachedToken || cachedCredentials.userId !== userId || (cachedCredentials.deviceId || void 0) !== knownDeviceId) {
318
+ const { saveMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
319
+ await saveMatrixCredentials({
320
+ homeserver,
321
+ userId,
322
+ accessToken,
323
+ deviceId: knownDeviceId
324
+ }, env, accountId);
325
+ } else if (hasMatchingCachedToken) {
326
+ const { touchMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
327
+ await touchMatrixCredentials(env, accountId);
328
+ }
329
+ return {
330
+ accountId,
331
+ homeserver,
332
+ userId,
333
+ accessToken,
334
+ password: tokenAuthPassword,
335
+ deviceId: knownDeviceId,
336
+ deviceName: resolved.deviceName,
337
+ initialSyncLimit: resolved.initialSyncLimit,
338
+ encryption: resolved.encryption,
339
+ ...buildMatrixNetworkFields({
340
+ allowPrivateNetwork: resolved.allowPrivateNetwork,
341
+ dispatcherPolicy: resolved.dispatcherPolicy
342
+ })
343
+ };
344
+ }
345
+ if (cachedCredentials) {
346
+ const { touchMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
347
+ await touchMatrixCredentials(env, accountId);
348
+ return {
349
+ accountId,
350
+ homeserver: cachedCredentials.homeserver,
351
+ userId: cachedCredentials.userId,
352
+ accessToken: cachedCredentials.accessToken,
353
+ password: tokenAuthPassword,
354
+ deviceId: cachedCredentials.deviceId || resolved.deviceId,
355
+ deviceName: resolved.deviceName,
356
+ initialSyncLimit: resolved.initialSyncLimit,
357
+ encryption: resolved.encryption,
358
+ ...buildMatrixNetworkFields({
359
+ allowPrivateNetwork: resolved.allowPrivateNetwork,
360
+ dispatcherPolicy: resolved.dispatcherPolicy
361
+ })
362
+ };
363
+ }
364
+ if (!resolved.userId) throw new Error("Matrix userId is required when no access token is configured (matrix.userId)");
365
+ const password = await resolveConfiguredMatrixAuthSecretInput({
366
+ cfg,
367
+ env,
368
+ accountId,
369
+ field: "password"
370
+ }) ?? resolved.password;
371
+ if (!password) throw new Error("Matrix password is required when no access token is configured (matrix.password)");
372
+ const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixAuthClientDeps();
373
+ ensureMatrixSdkLoggingConfigured();
374
+ const loginClient = new MatrixClient(homeserver, "", {
375
+ ssrfPolicy: resolved.ssrfPolicy,
376
+ dispatcherPolicy: resolved.dispatcherPolicy
377
+ });
378
+ const login = await retryMatrixAuthRequest("matrix auth login", async () => {
379
+ return await loginClient.doRequest("POST", "/_matrix/client/v3/login", void 0, {
380
+ type: "m.login.password",
381
+ identifier: {
382
+ type: "m.id.user",
383
+ user: resolved.userId
384
+ },
385
+ password,
386
+ device_id: resolved.deviceId,
387
+ initial_device_display_name: resolved.deviceName ?? "OpenClaw Gateway"
388
+ });
389
+ });
390
+ const loginAccessToken = login.access_token?.trim();
391
+ if (!loginAccessToken) throw new Error("Matrix login did not return an access token");
392
+ const auth = {
393
+ accountId,
394
+ homeserver,
395
+ userId: login.user_id ?? resolved.userId,
396
+ accessToken: loginAccessToken,
397
+ password,
398
+ deviceId: login.device_id ?? resolved.deviceId,
399
+ deviceName: resolved.deviceName,
400
+ initialSyncLimit: resolved.initialSyncLimit,
401
+ encryption: resolved.encryption,
402
+ ...buildMatrixNetworkFields({
403
+ allowPrivateNetwork: resolved.allowPrivateNetwork,
404
+ dispatcherPolicy: resolved.dispatcherPolicy
405
+ })
406
+ };
407
+ const { saveMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
408
+ await saveMatrixCredentials({
409
+ homeserver: auth.homeserver,
410
+ userId: auth.userId,
411
+ accessToken: auth.accessToken,
412
+ deviceId: auth.deviceId
413
+ }, env, accountId);
414
+ return auth;
415
+ }
416
+ async function backfillMatrixAuthDeviceIdAfterStartup(params) {
417
+ const knownDeviceId = params.auth.deviceId?.trim();
418
+ if (knownDeviceId) return knownDeviceId;
419
+ if (isAbortSignalTriggered(params.abortSignal)) return;
420
+ const deviceId = (await fetchMatrixWhoamiIdentity({
421
+ homeserver: params.auth.homeserver,
422
+ accessToken: params.auth.accessToken,
423
+ userId: params.auth.userId,
424
+ ssrfPolicy: params.auth.ssrfPolicy,
425
+ dispatcherPolicy: params.auth.dispatcherPolicy
426
+ })).device_id?.trim();
427
+ if (!deviceId) return;
428
+ if (isAbortSignalTriggered(params.abortSignal)) return;
429
+ const env = params.env ?? process.env;
430
+ const { loadMatrixCredentials } = await loadMatrixCredentialsReadDeps();
431
+ if (!credentialsMatchBackfillAuthLineage({
432
+ stored: loadMatrixCredentials(env, params.auth.accountId),
433
+ auth: params.auth
434
+ })) return;
435
+ if (!repairCurrentTokenStorageMetaDeviceId({
436
+ homeserver: params.auth.homeserver,
437
+ userId: params.auth.userId,
438
+ accessToken: params.auth.accessToken,
439
+ accountId: params.auth.accountId,
440
+ deviceId,
441
+ env: params.env
442
+ })) throw new Error("Matrix deviceId backfill failed to repair current-token storage metadata");
443
+ if (isAbortSignalTriggered(params.abortSignal)) return;
444
+ return await (await loadMatrixCredentialsWriteRuntime()).saveBackfilledMatrixDeviceId({
445
+ homeserver: params.auth.homeserver,
446
+ userId: params.auth.userId,
447
+ accessToken: params.auth.accessToken,
448
+ deviceId
449
+ }, env, params.auth.accountId) === "saved" ? deviceId : void 0;
450
+ }
451
+ //#endregion
452
+ export { resolveMatrixConfigForAccount as i, resolveMatrixAuth as n, resolveMatrixAuthContext as r, backfillMatrixAuthDeviceIdAfterStartup as t };
@@ -0,0 +1,19 @@
1
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
2
+ //#region extensions/matrix/src/matrix/config-paths.ts
3
+ function shouldStoreMatrixAccountAtTopLevel(cfg, accountId) {
4
+ if (normalizeAccountId(accountId) !== DEFAULT_ACCOUNT_ID) return false;
5
+ const accounts = cfg.channels?.matrix?.accounts;
6
+ return !accounts || Object.keys(accounts).length === 0;
7
+ }
8
+ function resolveMatrixConfigPath(cfg, accountId) {
9
+ const normalizedAccountId = normalizeAccountId(accountId);
10
+ if (shouldStoreMatrixAccountAtTopLevel(cfg, normalizedAccountId)) return "channels.matrix";
11
+ return `channels.matrix.accounts.${normalizedAccountId}`;
12
+ }
13
+ function resolveMatrixConfigFieldPath(cfg, accountId, fieldPath) {
14
+ const suffix = fieldPath.trim().replace(/^\.+/, "");
15
+ if (!suffix) return resolveMatrixConfigPath(cfg, accountId);
16
+ return `${resolveMatrixConfigPath(cfg, accountId)}.${suffix}`;
17
+ }
18
+ //#endregion
19
+ export { resolveMatrixConfigPath as n, shouldStoreMatrixAccountAtTopLevel as r, resolveMatrixConfigFieldPath as t };