@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,540 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { n as requiresExplicitMatrixDefaultAccount } from "./account-selection-BWwIruri.js";
3
+ import { a as resolveMatrixAccountConfig } from "./account-config-D2W-V1eQ.js";
4
+ import { r as resolveMatrixEnvAuthReadiness } from "./env-auth-BJqGI8M6.js";
5
+ import { i as resolveMatrixAccount, r as resolveDefaultMatrixAccountId, t as listMatrixAccountIds } from "./accounts-Bm90Rzvp.js";
6
+ import { r as moveSingleMatrixAccountConfigToNamedAccount, t as resolveMatrixSetupDmAllowFrom } from "./setup-dm-policy-2-r1FrQh.js";
7
+ import { t as resolveMatrixConfigFieldPath } from "./config-paths-nsVaysCu.js";
8
+ import { r as updateMatrixAccountConfig } from "./config-update-wZX-HLMn.js";
9
+ import { n as validateMatrixHomeserverUrl, r as isPrivateOrLoopbackHost, t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DiK9j7jz.js";
10
+ import { n as ensureMatrixSdkInstalled, r as isMatrixSdkAvailable } from "./deps-C6WqKY7m.js";
11
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
12
+ import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
13
+ import { formatDocsLink, hasConfiguredSecretInput, mergeAllowFromEntries, normalizeAccountId as normalizeAccountId$1, promptAccountId, promptChannelAccessConfig, splitSetupEntries } from "openclaw/plugin-sdk/setup";
14
+ import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-policy";
15
+ //#region extensions/matrix/src/onboarding.ts
16
+ const channel = "matrix";
17
+ const matrixInviteAutoJoinOptions = [
18
+ {
19
+ value: "allowlist",
20
+ label: "Allowlist (recommended)"
21
+ },
22
+ {
23
+ value: "always",
24
+ label: "Always (join every invite)"
25
+ },
26
+ {
27
+ value: "off",
28
+ label: "Off (do not auto-join invites)"
29
+ }
30
+ ];
31
+ function isMatrixInviteAutoJoinPolicy(value) {
32
+ return value === "allowlist" || value === "always" || value === "off";
33
+ }
34
+ function isMatrixInviteAutoJoinTarget(entry) {
35
+ return entry === "*" || entry.startsWith("!") && entry.includes(":") || entry.startsWith("#") && entry.includes(":");
36
+ }
37
+ function normalizeMatrixInviteAutoJoinTargets(entries) {
38
+ return [...new Set(entries.map((entry) => normalizeOptionalString(entry)).filter((entry) => Boolean(entry)))];
39
+ }
40
+ function resolveMatrixOnboardingAccountId(cfg, accountId) {
41
+ return normalizeAccountId$1(normalizeOptionalString(accountId) || resolveDefaultMatrixAccountId(cfg) || DEFAULT_ACCOUNT_ID);
42
+ }
43
+ function setMatrixDmPolicy(cfg, policy, accountId) {
44
+ const resolvedAccountId = resolveMatrixOnboardingAccountId(cfg, accountId);
45
+ const existing = resolveMatrixAccountConfig({
46
+ cfg,
47
+ accountId: resolvedAccountId
48
+ });
49
+ const allowFrom = resolveMatrixSetupDmAllowFrom(policy, existing.dm?.allowFrom);
50
+ return updateMatrixAccountConfig(cfg, resolvedAccountId, { dm: {
51
+ ...existing.dm,
52
+ policy,
53
+ allowFrom
54
+ } });
55
+ }
56
+ async function noteMatrixAuthHelp(prompter) {
57
+ await prompter.note([
58
+ "Matrix requires a homeserver URL.",
59
+ "Use an access token (recommended) or password login to an existing account.",
60
+ "With access token: user ID is fetched automatically.",
61
+ "Env vars supported: MATRIX_HOMESERVER, MATRIX_USER_ID, MATRIX_ACCESS_TOKEN, MATRIX_PASSWORD, MATRIX_DEVICE_ID, MATRIX_DEVICE_NAME.",
62
+ "Per-account env vars: MATRIX_<ACCOUNT_ID>_HOMESERVER, MATRIX_<ACCOUNT_ID>_USER_ID, MATRIX_<ACCOUNT_ID>_ACCESS_TOKEN, MATRIX_<ACCOUNT_ID>_PASSWORD, MATRIX_<ACCOUNT_ID>_DEVICE_ID, MATRIX_<ACCOUNT_ID>_DEVICE_NAME.",
63
+ `Docs: ${formatDocsLink("/channels/matrix", "channels/matrix")}`
64
+ ].join("\n"), "Matrix setup");
65
+ }
66
+ function requiresMatrixPrivateNetworkOptIn(homeserver) {
67
+ try {
68
+ const parsed = new URL(homeserver);
69
+ return parsed.protocol === "http:" && !isPrivateOrLoopbackHost(parsed.hostname);
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+ async function promptMatrixAllowFrom(params) {
75
+ const { cfg, prompter } = params;
76
+ const accountId = resolveMatrixOnboardingAccountId(cfg, params.accountId);
77
+ const existingConfig = resolveMatrixAccountConfig({
78
+ cfg,
79
+ accountId
80
+ });
81
+ const existingAllowFrom = existingConfig.dm?.allowFrom ?? [];
82
+ const canResolve = resolveMatrixAccount({
83
+ cfg,
84
+ accountId
85
+ }).configured;
86
+ const isFullUserId = (value) => value.startsWith("@") && value.includes(":");
87
+ while (true) {
88
+ const parts = splitSetupEntries(await prompter.text({
89
+ message: "Matrix allowFrom (full @user:server; display name only if unique)",
90
+ placeholder: "@user:server",
91
+ initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : void 0,
92
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
93
+ }));
94
+ const resolvedIds = [];
95
+ const pending = [];
96
+ const unresolved = [];
97
+ const unresolvedNotes = [];
98
+ for (const part of parts) {
99
+ if (isFullUserId(part)) {
100
+ resolvedIds.push(part);
101
+ continue;
102
+ }
103
+ if (!canResolve) {
104
+ unresolved.push(part);
105
+ continue;
106
+ }
107
+ pending.push(part);
108
+ }
109
+ if (pending.length > 0) {
110
+ const { resolveMatrixTargets } = await import("./resolve-targets-YtJnw1Tb.js").then((n) => n.n);
111
+ const results = await resolveMatrixTargets({
112
+ cfg,
113
+ accountId,
114
+ inputs: pending,
115
+ kind: "user"
116
+ }).catch(() => []);
117
+ for (const result of results) {
118
+ if (result?.resolved && result.id) {
119
+ resolvedIds.push(result.id);
120
+ continue;
121
+ }
122
+ if (result?.input) {
123
+ unresolved.push(result.input);
124
+ if (result.note) unresolvedNotes.push(`${result.input}: ${result.note}`);
125
+ }
126
+ }
127
+ }
128
+ if (unresolved.length > 0) {
129
+ const details = unresolvedNotes.length > 0 ? unresolvedNotes : unresolved;
130
+ await prompter.note(`Could not resolve:\n${details.join("\n")}\nUse full @user:server IDs.`, "Matrix allowlist");
131
+ continue;
132
+ }
133
+ const unique = mergeAllowFromEntries(existingAllowFrom, resolvedIds);
134
+ return updateMatrixAccountConfig(cfg, accountId, { dm: {
135
+ ...existingConfig.dm,
136
+ policy: "allowlist",
137
+ allowFrom: unique
138
+ } });
139
+ }
140
+ }
141
+ function setMatrixGroupPolicy(cfg, groupPolicy, accountId) {
142
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), { groupPolicy });
143
+ }
144
+ function setMatrixGroupRooms(cfg, roomKeys, accountId) {
145
+ const groups = Object.fromEntries(roomKeys.map((key) => [key, { enabled: true }]));
146
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), {
147
+ groups,
148
+ rooms: null
149
+ });
150
+ }
151
+ function setMatrixAutoJoin(cfg, autoJoin, autoJoinAllowlist, accountId) {
152
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), {
153
+ autoJoin,
154
+ autoJoinAllowlist: autoJoin === "allowlist" ? autoJoinAllowlist : null
155
+ });
156
+ }
157
+ async function configureMatrixInviteAutoJoin(params) {
158
+ const accountId = resolveMatrixOnboardingAccountId(params.cfg, params.accountId);
159
+ const existingConfig = resolveMatrixAccountConfig({
160
+ cfg: params.cfg,
161
+ accountId
162
+ });
163
+ const currentPolicy = existingConfig.autoJoin ?? "off";
164
+ const currentAllowlist = (existingConfig.autoJoinAllowlist ?? []).map((entry) => String(entry));
165
+ const hasExistingConfig = existingConfig.autoJoin !== void 0 || currentAllowlist.length > 0;
166
+ await params.prompter.note([
167
+ "WARNING: Matrix invite auto-join defaults to off.",
168
+ "OpenClaw agents will not join invited rooms or fresh DM-style invites unless you set autoJoin.",
169
+ "Choose \"allowlist\" to restrict joins or \"always\" to join every invite."
170
+ ].join("\n"), "Matrix invite auto-join");
171
+ if (!await params.prompter.confirm({
172
+ message: hasExistingConfig ? "Update Matrix invite auto-join?" : "Configure Matrix invite auto-join?",
173
+ initialValue: hasExistingConfig ? currentPolicy !== "off" : true
174
+ })) return params.cfg;
175
+ const selectedPolicy = await params.prompter.select({
176
+ message: "Matrix invite auto-join",
177
+ options: matrixInviteAutoJoinOptions,
178
+ initialValue: currentPolicy
179
+ });
180
+ if (!isMatrixInviteAutoJoinPolicy(selectedPolicy)) throw new Error(`Unsupported Matrix invite auto-join policy: ${String(selectedPolicy)}`);
181
+ const policy = selectedPolicy;
182
+ if (policy === "off") {
183
+ await params.prompter.note(["Matrix invite auto-join remains off.", "Agents will not join invited rooms or fresh DM-style invites until you change autoJoin."].join("\n"), "Matrix invite auto-join");
184
+ return setMatrixAutoJoin(params.cfg, policy, [], accountId);
185
+ }
186
+ if (policy === "always") return setMatrixAutoJoin(params.cfg, policy, [], accountId);
187
+ while (true) {
188
+ const allowlist = normalizeMatrixInviteAutoJoinTargets(splitSetupEntries(await params.prompter.text({
189
+ message: "Matrix invite auto-join allowlist (comma-separated)",
190
+ placeholder: "!roomId:server, #alias:server, *",
191
+ initialValue: currentAllowlist[0] ? currentAllowlist.join(", ") : void 0,
192
+ validate: (value) => {
193
+ return splitSetupEntries(value).length > 0 ? void 0 : "Required";
194
+ }
195
+ })));
196
+ const invalidEntries = allowlist.filter((entry) => !isMatrixInviteAutoJoinTarget(entry));
197
+ if (allowlist.length === 0 || invalidEntries.length > 0) {
198
+ await params.prompter.note(["Use only stable Matrix invite targets for auto-join: !roomId:server, #alias:server, or *.", invalidEntries.length > 0 ? `Invalid: ${invalidEntries.join(", ")}` : void 0].filter(Boolean).join("\n"), "Matrix invite auto-join");
199
+ continue;
200
+ }
201
+ return setMatrixAutoJoin(params.cfg, "allowlist", allowlist, accountId);
202
+ }
203
+ }
204
+ async function configureMatrixAccessPrompts(params) {
205
+ let next = params.cfg;
206
+ if (params.forceAllowFrom) next = await promptMatrixAllowFrom({
207
+ cfg: next,
208
+ prompter: params.prompter,
209
+ accountId: params.accountId
210
+ });
211
+ const existingAccountConfig = resolveMatrixAccountConfig({
212
+ cfg: next,
213
+ accountId: params.accountId
214
+ });
215
+ const existingGroups = existingAccountConfig.groups ?? existingAccountConfig.rooms;
216
+ const accessConfig = await promptChannelAccessConfig({
217
+ prompter: params.prompter,
218
+ label: "Matrix rooms",
219
+ currentPolicy: existingAccountConfig.groupPolicy ?? "allowlist",
220
+ currentEntries: Object.keys(existingGroups ?? {}),
221
+ placeholder: "!roomId:server, #alias:server, Project Room",
222
+ updatePrompt: Boolean(existingGroups)
223
+ });
224
+ if (accessConfig) if (accessConfig.policy !== "allowlist") next = setMatrixGroupPolicy(next, accessConfig.policy, params.accountId);
225
+ else {
226
+ let roomKeys = accessConfig.entries;
227
+ if (accessConfig.entries.length > 0) try {
228
+ const resolvedIds = [];
229
+ const unresolved = [];
230
+ for (const entry of accessConfig.entries) {
231
+ const trimmed = normalizeOptionalString(entry) ?? "";
232
+ if (!trimmed) continue;
233
+ const cleaned = trimmed.replace(/^(room|channel):/i, "").trim();
234
+ if (cleaned.startsWith("!") && cleaned.includes(":")) {
235
+ resolvedIds.push(cleaned);
236
+ continue;
237
+ }
238
+ const { listMatrixDirectoryGroupsLive } = await import("./directory-live-DmOtMhyr.js").then((n) => n.t);
239
+ const matches = await listMatrixDirectoryGroupsLive({
240
+ cfg: next,
241
+ accountId: params.accountId,
242
+ query: trimmed,
243
+ limit: 10
244
+ });
245
+ const best = matches.find((match) => normalizeLowercaseStringOrEmpty(match.name) === normalizeLowercaseStringOrEmpty(trimmed)) ?? matches[0];
246
+ if (best?.id) resolvedIds.push(best.id);
247
+ else unresolved.push(entry);
248
+ }
249
+ roomKeys = [...resolvedIds, ...unresolved.map((entry) => normalizeOptionalString(entry)).filter((entry) => Boolean(entry))];
250
+ if (resolvedIds.length > 0 || unresolved.length > 0) await params.prompter.note([resolvedIds.length > 0 ? `Resolved: ${resolvedIds.join(", ")}` : void 0, unresolved.length > 0 ? `Unresolved (kept as typed): ${unresolved.join(", ")}` : void 0].filter(Boolean).join("\n"), "Matrix rooms");
251
+ } catch (err) {
252
+ await params.prompter.note(`Room lookup failed; keeping entries as typed. ${String(err)}`, "Matrix rooms");
253
+ }
254
+ next = setMatrixGroupPolicy(next, "allowlist", params.accountId);
255
+ next = setMatrixGroupRooms(next, roomKeys, params.accountId);
256
+ }
257
+ return await configureMatrixInviteAutoJoin({
258
+ cfg: next,
259
+ prompter: params.prompter,
260
+ accountId: params.accountId
261
+ });
262
+ }
263
+ const dmPolicy = {
264
+ label: "Matrix",
265
+ channel,
266
+ policyKey: "channels.matrix.dm.policy",
267
+ allowFromKey: "channels.matrix.dm.allowFrom",
268
+ resolveConfigKeys: (cfg, accountId) => {
269
+ const effectiveAccountId = resolveMatrixOnboardingAccountId(cfg, accountId);
270
+ return {
271
+ policyKey: resolveMatrixConfigFieldPath(cfg, effectiveAccountId, "dm.policy"),
272
+ allowFromKey: resolveMatrixConfigFieldPath(cfg, effectiveAccountId, "dm.allowFrom")
273
+ };
274
+ },
275
+ getCurrent: (cfg, accountId) => resolveMatrixAccountConfig({
276
+ cfg,
277
+ accountId: resolveMatrixOnboardingAccountId(cfg, accountId)
278
+ }).dm?.policy ?? "pairing",
279
+ setPolicy: (cfg, policy, accountId) => setMatrixDmPolicy(cfg, policy, accountId),
280
+ promptAllowFrom: promptMatrixAllowFrom
281
+ };
282
+ async function runMatrixConfigure(params) {
283
+ let next = params.cfg;
284
+ await ensureMatrixSdkInstalled({
285
+ runtime: params.runtime,
286
+ confirm: async (message) => await params.prompter.confirm({
287
+ message,
288
+ initialValue: true
289
+ })
290
+ });
291
+ const defaultAccountId = resolveDefaultMatrixAccountId(next);
292
+ let accountId = defaultAccountId || DEFAULT_ACCOUNT_ID;
293
+ if (params.intent === "add-account") {
294
+ const enteredName = normalizeStringifiedOptionalString(await params.prompter.text({
295
+ message: "Matrix account name",
296
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
297
+ })) ?? "";
298
+ accountId = normalizeAccountId$1(enteredName);
299
+ if (enteredName !== accountId) await params.prompter.note(`Account id will be "${accountId}".`, "Matrix account");
300
+ if (accountId !== DEFAULT_ACCOUNT_ID) next = moveSingleMatrixAccountConfigToNamedAccount(next);
301
+ next = updateMatrixAccountConfig(next, accountId, {
302
+ name: enteredName,
303
+ enabled: true
304
+ });
305
+ } else {
306
+ const override = normalizeOptionalString(params.accountOverrides?.[channel]);
307
+ if (override) accountId = normalizeAccountId$1(override);
308
+ else if (params.shouldPromptAccountIds) accountId = await promptAccountId({
309
+ cfg: next,
310
+ prompter: params.prompter,
311
+ label: "Matrix",
312
+ currentId: accountId,
313
+ listAccountIds: (inputCfg) => listMatrixAccountIds(inputCfg),
314
+ defaultAccountId
315
+ });
316
+ }
317
+ const existing = resolveMatrixAccountConfig({
318
+ cfg: next,
319
+ accountId
320
+ });
321
+ if (!resolveMatrixAccount({
322
+ cfg: next,
323
+ accountId
324
+ }).configured) await noteMatrixAuthHelp(params.prompter);
325
+ const envReadiness = resolveMatrixEnvAuthReadiness(accountId, process.env);
326
+ const envReady = envReadiness.ready;
327
+ const envHomeserver = envReadiness.homeserver;
328
+ const envUserId = envReadiness.userId;
329
+ if (envReady && !existing.homeserver && !existing.userId && !existing.accessToken && !existing.password) {
330
+ if (await params.prompter.confirm({
331
+ message: `Matrix env vars detected (${envReadiness.sourceHint}). Use env values?`,
332
+ initialValue: true
333
+ })) {
334
+ next = updateMatrixAccountConfig(next, accountId, { enabled: true });
335
+ next = await configureMatrixAccessPrompts({
336
+ cfg: next,
337
+ prompter: params.prompter,
338
+ forceAllowFrom: params.forceAllowFrom,
339
+ accountId
340
+ });
341
+ return {
342
+ cfg: next,
343
+ accountId
344
+ };
345
+ }
346
+ }
347
+ const homeserver = normalizeStringifiedOptionalString(await params.prompter.text({
348
+ message: "Matrix homeserver URL",
349
+ initialValue: existing.homeserver ?? envHomeserver,
350
+ validate: (value) => {
351
+ try {
352
+ validateMatrixHomeserverUrl(value, { allowPrivateNetwork: true });
353
+ return;
354
+ } catch (error) {
355
+ return error instanceof Error ? error.message : "Invalid Matrix homeserver URL";
356
+ }
357
+ }
358
+ })) ?? "";
359
+ const requiresAllowPrivateNetwork = requiresMatrixPrivateNetworkOptIn(homeserver);
360
+ const shouldPromptAllowPrivateNetwork = requiresAllowPrivateNetwork || isPrivateNetworkOptInEnabled(existing);
361
+ const allowPrivateNetwork = shouldPromptAllowPrivateNetwork ? await params.prompter.confirm({
362
+ message: "Allow private/internal Matrix homeserver traffic for this account?",
363
+ initialValue: isPrivateNetworkOptInEnabled(existing) || requiresAllowPrivateNetwork
364
+ }) : false;
365
+ if (requiresAllowPrivateNetwork && !allowPrivateNetwork) throw new Error("Matrix homeserver requires explicit private-network opt-in");
366
+ await resolveValidatedMatrixHomeserverUrl(homeserver, { dangerouslyAllowPrivateNetwork: allowPrivateNetwork });
367
+ let accessToken = existing.accessToken;
368
+ let password = existing.password;
369
+ let userId = existing.userId ?? "";
370
+ if (hasConfiguredSecretInput(accessToken) || hasConfiguredSecretInput(password)) {
371
+ if (!await params.prompter.confirm({
372
+ message: "Matrix credentials already configured. Keep them?",
373
+ initialValue: true
374
+ })) {
375
+ accessToken = void 0;
376
+ password = void 0;
377
+ userId = "";
378
+ }
379
+ }
380
+ if (!hasConfiguredSecretInput(accessToken) && !hasConfiguredSecretInput(password)) if (await params.prompter.select({
381
+ message: "Matrix auth method",
382
+ options: [{
383
+ value: "token",
384
+ label: "Access token (user ID fetched automatically)"
385
+ }, {
386
+ value: "password",
387
+ label: "Password (requires user ID)"
388
+ }]
389
+ }) === "token") {
390
+ accessToken = normalizeStringifiedOptionalString(await params.prompter.text({
391
+ message: "Matrix access token",
392
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
393
+ })) ?? "";
394
+ password = void 0;
395
+ userId = "";
396
+ } else {
397
+ userId = normalizeStringifiedOptionalString(await params.prompter.text({
398
+ message: "Matrix user ID",
399
+ initialValue: existing.userId ?? envUserId,
400
+ validate: (value) => {
401
+ const raw = normalizeOptionalString(value) ?? "";
402
+ if (!raw) return "Required";
403
+ if (!raw.startsWith("@")) return "Matrix user IDs should start with @";
404
+ if (!raw.includes(":")) return "Matrix user IDs should include a server (:server)";
405
+ }
406
+ })) ?? "";
407
+ password = normalizeStringifiedOptionalString(await params.prompter.text({
408
+ message: "Matrix password",
409
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
410
+ })) ?? "";
411
+ accessToken = void 0;
412
+ }
413
+ const deviceName = normalizeStringifiedOptionalString(await params.prompter.text({
414
+ message: "Matrix device name (optional)",
415
+ initialValue: existing.deviceName ?? "OpenClaw Gateway"
416
+ })) ?? "";
417
+ const enableEncryption = await params.prompter.confirm({
418
+ message: "Enable end-to-end encryption (E2EE)?",
419
+ initialValue: existing.encryption ?? false
420
+ });
421
+ next = updateMatrixAccountConfig(next, accountId, {
422
+ enabled: true,
423
+ homeserver,
424
+ ...shouldPromptAllowPrivateNetwork ? { allowPrivateNetwork: allowPrivateNetwork ? true : null } : {},
425
+ userId: userId || null,
426
+ accessToken: accessToken ?? null,
427
+ password: password ?? null,
428
+ deviceName: deviceName || null,
429
+ encryption: enableEncryption
430
+ });
431
+ next = await configureMatrixAccessPrompts({
432
+ cfg: next,
433
+ prompter: params.prompter,
434
+ forceAllowFrom: params.forceAllowFrom,
435
+ accountId
436
+ });
437
+ return {
438
+ cfg: next,
439
+ accountId
440
+ };
441
+ }
442
+ const matrixOnboardingAdapter = {
443
+ channel,
444
+ getStatus: async ({ cfg, accountOverrides }) => {
445
+ const resolvedCfg = cfg;
446
+ const sdkReady = isMatrixSdkAvailable();
447
+ if (!accountOverrides[channel] && requiresExplicitMatrixDefaultAccount(resolvedCfg)) return {
448
+ channel,
449
+ configured: false,
450
+ statusLines: ["Matrix: set \"channels.matrix.defaultAccount\" to select a named account"],
451
+ selectionHint: !sdkReady ? "install Matrix deps" : "set defaultAccount"
452
+ };
453
+ const configured = resolveMatrixAccount({
454
+ cfg: resolvedCfg,
455
+ accountId: resolveMatrixOnboardingAccountId(resolvedCfg, accountOverrides[channel])
456
+ }).configured;
457
+ return {
458
+ channel,
459
+ configured,
460
+ statusLines: [`Matrix: ${configured ? "configured" : "needs homeserver + access token or password"}`],
461
+ selectionHint: !sdkReady ? "install Matrix deps" : configured ? "configured" : "needs auth"
462
+ };
463
+ },
464
+ configure: async ({ cfg, runtime, prompter, forceAllowFrom, accountOverrides, shouldPromptAccountIds }) => await runMatrixConfigure({
465
+ cfg,
466
+ runtime,
467
+ prompter,
468
+ forceAllowFrom,
469
+ accountOverrides,
470
+ shouldPromptAccountIds,
471
+ intent: "update"
472
+ }),
473
+ configureInteractive: async ({ cfg, runtime, prompter, forceAllowFrom, accountOverrides, shouldPromptAccountIds, configured }) => {
474
+ if (!configured) return await runMatrixConfigure({
475
+ cfg,
476
+ runtime,
477
+ prompter,
478
+ forceAllowFrom,
479
+ accountOverrides,
480
+ shouldPromptAccountIds,
481
+ intent: "update"
482
+ });
483
+ const action = await prompter.select({
484
+ message: "Matrix already configured. What do you want to do?",
485
+ options: [
486
+ {
487
+ value: "update",
488
+ label: "Modify settings"
489
+ },
490
+ {
491
+ value: "add-account",
492
+ label: "Add account"
493
+ },
494
+ {
495
+ value: "skip",
496
+ label: "Skip (leave as-is)"
497
+ }
498
+ ],
499
+ initialValue: "update"
500
+ });
501
+ if (action === "skip") return "skip";
502
+ return await runMatrixConfigure({
503
+ cfg,
504
+ runtime,
505
+ prompter,
506
+ forceAllowFrom,
507
+ accountOverrides,
508
+ shouldPromptAccountIds,
509
+ intent: action === "add-account" ? "add-account" : "update"
510
+ });
511
+ },
512
+ afterConfigWritten: async ({ previousCfg, cfg, accountId, runtime }) => {
513
+ const { runMatrixSetupBootstrapAfterConfigWrite } = await import("./setup-bootstrap-ImenBsMt.js");
514
+ await runMatrixSetupBootstrapAfterConfigWrite({
515
+ previousCfg,
516
+ cfg,
517
+ accountId,
518
+ runtime
519
+ });
520
+ },
521
+ dmPolicy,
522
+ disable: (cfg) => ({
523
+ ...cfg,
524
+ channels: {
525
+ ...cfg.channels,
526
+ matrix: {
527
+ ...cfg.channels?.["matrix"],
528
+ enabled: false
529
+ }
530
+ }
531
+ })
532
+ };
533
+ //#endregion
534
+ //#region extensions/matrix/src/setup-surface.ts
535
+ var setup_surface_exports = /* @__PURE__ */ __exportAll({
536
+ matrixOnboardingAdapter: () => matrixOnboardingAdapter,
537
+ matrixSetupWizard: () => matrixOnboardingAdapter
538
+ });
539
+ //#endregion
540
+ export { matrixOnboardingAdapter as n, setup_surface_exports as t };