@kodelyth/matrix 2026.5.39 → 2026.6.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 (117) hide show
  1. package/dist/account-selection-Y50DNJ2l.js +158 -0
  2. package/dist/active-client-CmFdvPdO.js +20 -0
  3. package/dist/api.js +12 -0
  4. package/dist/approval-handler.runtime-BIi4fL0R.js +377 -0
  5. package/dist/approval-ids-BGHK7PnZ.js +7 -0
  6. package/dist/approval-reaction-auth-CL0-nCNV.js +27 -0
  7. package/dist/approval-reactions-nDm2x-K5.js +162 -0
  8. package/dist/async-lock-SsmtFXtt.js +19 -0
  9. package/dist/auth-presence.js +26 -0
  10. package/dist/backup-health-3BHbHxyd.js +60 -0
  11. package/dist/channel-C0kCyTNB.js +1380 -0
  12. package/dist/channel-plugin-api.js +2 -0
  13. package/dist/channel.runtime-CdrdEN-0.js +250 -0
  14. package/dist/cli-FtY6Nuzw.js +1338 -0
  15. package/dist/cli-metadata-Dkwua7CB.js +22 -0
  16. package/dist/cli-metadata.js +2 -0
  17. package/dist/client-BnohYygh.js +25 -0
  18. package/dist/client-PhrTwuC4.js +30 -0
  19. package/dist/client-bootstrap-Mcj8ChJ5.js +114 -0
  20. package/dist/config-paths-DVvt6vM3.js +114 -0
  21. package/dist/config-schema-BMGOlhdI.js +308 -0
  22. package/dist/config-secret-input.runtime-Dv_4Br_f.js +2 -0
  23. package/dist/contract-api.js +8 -0
  24. package/dist/create-client-J0htTaRj.js +64 -0
  25. package/dist/credentials-B7GsBbgQ.js +56 -0
  26. package/dist/credentials-read-8fE4qoWs.js +112 -0
  27. package/dist/credentials-write.runtime-BibplB4Y.js +17 -0
  28. package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
  29. package/dist/crypto-runtime-1pKW4O2F.js +1214 -0
  30. package/dist/deps-DVpDS81G.js +208 -0
  31. package/dist/device-health-Ct2wDSPG.js +16 -0
  32. package/dist/directory-live-i3T8uORc.js +150 -0
  33. package/dist/doctor-contract-BLzYHl_9.js +246 -0
  34. package/dist/doctor-contract-api.js +2 -0
  35. package/dist/doctor-diR5gE7D.js +153 -0
  36. package/dist/draft-stream-HpPJ_VJt.js +143 -0
  37. package/dist/encryption-guidance-BNEgckrZ.js +15 -0
  38. package/dist/env-auth-UFiTGkDM.js +63 -0
  39. package/dist/env-vars-EQKQv-FE.js +63 -0
  40. package/dist/errors-BETj3zr9.js +17 -0
  41. package/dist/exec-approval-resolver-BxPorU_t.js +15 -0
  42. package/dist/helper-api.js +4 -0
  43. package/dist/http-client-DoQgbQsU.js +331 -0
  44. package/dist/index.js +46 -0
  45. package/dist/legacy-crypto-inspector-zK0hDCbt.js +41 -0
  46. package/dist/legacy-crypto-restore-DSFIXuDo.js +85 -0
  47. package/dist/logging-Df7aPD1z.js +99 -0
  48. package/dist/matrix-migration.runtime-BNoT1Prt.js +525 -0
  49. package/dist/media-text-ZhGA8Pcs.js +146 -0
  50. package/dist/messages-CRA9WGg0.js +140 -0
  51. package/dist/migration-snapshot-backup-BR-xD7Ew.js +69 -0
  52. package/dist/migration-snapshot.runtime-BLcy_Nvw.js +2 -0
  53. package/dist/monitor-DQm7_13y.js +4331 -0
  54. package/dist/plugin-entry.handlers.runtime.js +51 -0
  55. package/dist/probe.runtime-CjJS53Kz.js +3 -0
  56. package/dist/profile-update-DqkPgZ1P.js +68 -0
  57. package/dist/reaction-common-CmVLzP-u.js +71 -0
  58. package/dist/reaction-events-D0nUJuZV.js +121 -0
  59. package/dist/record-shared-DGvSFn5M.js +2 -0
  60. package/dist/resolve-targets-ChECUzD2.js +140 -0
  61. package/dist/resolver.runtime-hdY3n0GO.js +5 -0
  62. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  63. package/dist/route-xRKj_ESW.js +161 -0
  64. package/dist/runtime-B-Fyrmxo.js +8 -0
  65. package/dist/runtime-api-BYXXkxq2.js +24 -0
  66. package/dist/runtime-api.js +25 -0
  67. package/dist/runtime-heavy-api.js +3 -0
  68. package/dist/runtime-lwTSy9Yt.js +6 -0
  69. package/dist/runtime-setter-api.js +2 -0
  70. package/dist/sdk-Jhq7mLtD.js +1704 -0
  71. package/dist/secret-contract-DEMcDsjl.js +120 -0
  72. package/dist/secret-contract-api.js +2 -0
  73. package/dist/send-CJunc6QM.js +1517 -0
  74. package/dist/setup-bootstrap-rJ0qZWPe.js +62 -0
  75. package/dist/setup-core-BEYoXF3J.js +677 -0
  76. package/dist/setup-entry.js +19 -0
  77. package/dist/setup-plugin-api.js +43 -0
  78. package/dist/setup-surface-c28ON6jq.js +537 -0
  79. package/dist/shared-D6MFMnpG.js +642 -0
  80. package/dist/startup-abort-B2J3MU_h.js +109 -0
  81. package/dist/startup-verification-CkD4Cwce.js +132 -0
  82. package/dist/storage-nyO0DOFE.js +281 -0
  83. package/dist/storage-paths-BTAketfg.js +52 -0
  84. package/dist/subagent-hooks-api-Dr_xnMRG.js +170 -0
  85. package/dist/subagent-hooks-api.js +2 -0
  86. package/dist/sync-state-Bx0gPaGA.js +12 -0
  87. package/dist/target-ids-Bsazo8si.js +77 -0
  88. package/dist/test-api.js +4 -0
  89. package/dist/thread-binding-api-IGU0-L70.js +17 -0
  90. package/dist/thread-binding-api.js +2 -0
  91. package/dist/thread-bindings-FjAZmDUP.js +352 -0
  92. package/dist/thread-bindings-runtime.js +2 -0
  93. package/dist/thread-bindings-shared-fvfP7jVs.js +97 -0
  94. package/dist/timeout-abort-signal-DpSHDHhR.js +2 -0
  95. package/dist/tool-actions.runtime-Cbo7YcYZ.js +532 -0
  96. package/dist/url-validation-DlrXNjAE.js +36 -0
  97. package/dist/verification-7tDPRpJU.js +345 -0
  98. package/package.json +19 -7
  99. package/api.js +0 -7
  100. package/auth-presence.js +0 -7
  101. package/channel-plugin-api.js +0 -7
  102. package/cli-metadata.js +0 -7
  103. package/contract-api.js +0 -7
  104. package/doctor-contract-api.js +0 -7
  105. package/helper-api.js +0 -7
  106. package/index.js +0 -7
  107. package/plugin-entry.handlers.runtime.js +0 -7
  108. package/runtime-api.js +0 -7
  109. package/runtime-heavy-api.js +0 -7
  110. package/runtime-setter-api.js +0 -7
  111. package/secret-contract-api.js +0 -7
  112. package/setup-entry.js +0 -7
  113. package/setup-plugin-api.js +0 -7
  114. package/subagent-hooks-api.js +0 -7
  115. package/test-api.js +0 -7
  116. package/thread-binding-api.js +0 -7
  117. package/thread-bindings-runtime.js +0 -7
@@ -0,0 +1,43 @@
1
+ import { g as resolveMatrixAccount, n as matrixSetupAdapter, t as createMatrixSetupWizardProxy } from "./setup-core-BEYoXF3J.js";
2
+ import { r as matrixConfigAdapter, t as MatrixChannelConfigSchema } from "./config-schema-BMGOlhdI.js";
3
+ import { describeAccountSnapshot } from "klaw/plugin-sdk/account-helpers";
4
+ const matrixSetupPlugin = {
5
+ id: "matrix",
6
+ meta: {
7
+ id: "matrix",
8
+ label: "Matrix",
9
+ selectionLabel: "Matrix (plugin)",
10
+ docsPath: "/channels/matrix",
11
+ docsLabel: "matrix",
12
+ blurb: "open protocol; configure a homeserver + access token.",
13
+ order: 70,
14
+ quickstartAllowFrom: true
15
+ },
16
+ setupWizard: createMatrixSetupWizardProxy(async () => ({ matrixSetupWizard: (await import("./setup-surface-c28ON6jq.js").then((n) => n.t)).matrixSetupWizard })),
17
+ setup: matrixSetupAdapter,
18
+ capabilities: {
19
+ chatTypes: [
20
+ "direct",
21
+ "group",
22
+ "thread"
23
+ ],
24
+ polls: true,
25
+ reactions: true,
26
+ threads: true,
27
+ media: true
28
+ },
29
+ reload: { configPrefixes: ["channels.matrix"] },
30
+ configSchema: MatrixChannelConfigSchema,
31
+ config: {
32
+ ...matrixConfigAdapter,
33
+ isConfigured: (account) => account.configured,
34
+ describeAccount: (account) => describeAccountSnapshot({
35
+ account,
36
+ configured: account.configured,
37
+ extra: { baseUrl: account.homeserver }
38
+ }),
39
+ hasConfiguredState: ({ cfg }) => resolveMatrixAccount({ cfg }).configured
40
+ }
41
+ };
42
+ //#endregion
43
+ export { matrixSetupPlugin };
@@ -0,0 +1,537 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { n as requiresExplicitMatrixDefaultAccount } from "./account-selection-Y50DNJ2l.js";
3
+ import { c as resolveMatrixAccountConfig, t as resolveMatrixConfigFieldPath } from "./config-paths-DVvt6vM3.js";
4
+ import { r as resolveMatrixEnvAuthReadiness } from "./env-auth-UFiTGkDM.js";
5
+ import { g as resolveMatrixAccount, h as resolveDefaultMatrixAccountId, i as moveSingleMatrixAccountConfigToNamedAccount, l as updateMatrixAccountConfig, p as listMatrixAccountIds, r as resolveMatrixSetupDmAllowFrom } from "./setup-core-BEYoXF3J.js";
6
+ import { n as validateMatrixHomeserverUrl, r as isPrivateOrLoopbackHost, t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DlrXNjAE.js";
7
+ import { n as ensureMatrixSdkInstalled, r as isMatrixSdkAvailable } from "./deps-DVpDS81G.js";
8
+ import { DEFAULT_ACCOUNT_ID } from "klaw/plugin-sdk/account-id";
9
+ import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
10
+ import { formatDocsLink, hasConfiguredSecretInput, mergeAllowFromEntries, normalizeAccountId as normalizeAccountId$1, promptAccountId, promptChannelAccessConfig, splitSetupEntries } from "klaw/plugin-sdk/setup";
11
+ import { isPrivateNetworkOptInEnabled } from "klaw/plugin-sdk/ssrf-policy";
12
+ //#region extensions/matrix/src/onboarding.ts
13
+ const channel = "matrix";
14
+ const matrixInviteAutoJoinOptions = [
15
+ {
16
+ value: "allowlist",
17
+ label: "Allowlist (recommended)"
18
+ },
19
+ {
20
+ value: "always",
21
+ label: "Always (join every invite)"
22
+ },
23
+ {
24
+ value: "off",
25
+ label: "Off (do not auto-join invites)"
26
+ }
27
+ ];
28
+ function isMatrixInviteAutoJoinPolicy(value) {
29
+ return value === "allowlist" || value === "always" || value === "off";
30
+ }
31
+ function isMatrixInviteAutoJoinTarget(entry) {
32
+ return entry === "*" || entry.startsWith("!") && entry.includes(":") || entry.startsWith("#") && entry.includes(":");
33
+ }
34
+ function normalizeMatrixInviteAutoJoinTargets(entries) {
35
+ return [...new Set(entries.map((entry) => normalizeOptionalString(entry)).filter((entry) => Boolean(entry)))];
36
+ }
37
+ function resolveMatrixOnboardingAccountId(cfg, accountId) {
38
+ return normalizeAccountId$1(normalizeOptionalString(accountId) || resolveDefaultMatrixAccountId(cfg) || DEFAULT_ACCOUNT_ID);
39
+ }
40
+ function setMatrixDmPolicy(cfg, policy, accountId) {
41
+ const resolvedAccountId = resolveMatrixOnboardingAccountId(cfg, accountId);
42
+ const existing = resolveMatrixAccountConfig({
43
+ cfg,
44
+ accountId: resolvedAccountId
45
+ });
46
+ const allowFrom = resolveMatrixSetupDmAllowFrom(policy, existing.dm?.allowFrom);
47
+ return updateMatrixAccountConfig(cfg, resolvedAccountId, { dm: {
48
+ ...existing.dm,
49
+ policy,
50
+ allowFrom
51
+ } });
52
+ }
53
+ async function noteMatrixAuthHelp(prompter) {
54
+ await prompter.note([
55
+ "Matrix requires a homeserver URL.",
56
+ "Use an access token (recommended) or password login to an existing account.",
57
+ "With access token: user ID is fetched automatically.",
58
+ "Env vars supported: MATRIX_HOMESERVER, MATRIX_USER_ID, MATRIX_ACCESS_TOKEN, MATRIX_PASSWORD, MATRIX_DEVICE_ID, MATRIX_DEVICE_NAME.",
59
+ "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.",
60
+ `Docs: ${formatDocsLink("/channels/matrix", "channels/matrix")}`
61
+ ].join("\n"), "Matrix setup");
62
+ }
63
+ function requiresMatrixPrivateNetworkOptIn(homeserver) {
64
+ try {
65
+ const parsed = new URL(homeserver);
66
+ return parsed.protocol === "http:" && !isPrivateOrLoopbackHost(parsed.hostname);
67
+ } catch {
68
+ return false;
69
+ }
70
+ }
71
+ async function promptMatrixAllowFrom(params) {
72
+ const { cfg, prompter } = params;
73
+ const accountId = resolveMatrixOnboardingAccountId(cfg, params.accountId);
74
+ const existingConfig = resolveMatrixAccountConfig({
75
+ cfg,
76
+ accountId
77
+ });
78
+ const existingAllowFrom = existingConfig.dm?.allowFrom ?? [];
79
+ const canResolve = resolveMatrixAccount({
80
+ cfg,
81
+ accountId
82
+ }).configured;
83
+ const isFullUserId = (value) => value.startsWith("@") && value.includes(":");
84
+ while (true) {
85
+ const parts = splitSetupEntries(await prompter.text({
86
+ message: "Matrix allowFrom (full @user:server; display name only if unique)",
87
+ placeholder: "@user:server",
88
+ initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : void 0,
89
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
90
+ }));
91
+ const resolvedIds = [];
92
+ const pending = [];
93
+ const unresolved = [];
94
+ const unresolvedNotes = [];
95
+ for (const part of parts) {
96
+ if (isFullUserId(part)) {
97
+ resolvedIds.push(part);
98
+ continue;
99
+ }
100
+ if (!canResolve) {
101
+ unresolved.push(part);
102
+ continue;
103
+ }
104
+ pending.push(part);
105
+ }
106
+ if (pending.length > 0) {
107
+ const { resolveMatrixTargets } = await import("./resolve-targets-ChECUzD2.js").then((n) => n.n);
108
+ const results = await resolveMatrixTargets({
109
+ cfg,
110
+ accountId,
111
+ inputs: pending,
112
+ kind: "user"
113
+ }).catch(() => []);
114
+ for (const result of results) {
115
+ if (result?.resolved && result.id) {
116
+ resolvedIds.push(result.id);
117
+ continue;
118
+ }
119
+ if (result?.input) {
120
+ unresolved.push(result.input);
121
+ if (result.note) unresolvedNotes.push(`${result.input}: ${result.note}`);
122
+ }
123
+ }
124
+ }
125
+ if (unresolved.length > 0) {
126
+ const details = unresolvedNotes.length > 0 ? unresolvedNotes : unresolved;
127
+ await prompter.note(`Could not resolve:\n${details.join("\n")}\nUse full @user:server IDs.`, "Matrix allowlist");
128
+ continue;
129
+ }
130
+ const unique = mergeAllowFromEntries(existingAllowFrom, resolvedIds);
131
+ return updateMatrixAccountConfig(cfg, accountId, { dm: {
132
+ ...existingConfig.dm,
133
+ policy: "allowlist",
134
+ allowFrom: unique
135
+ } });
136
+ }
137
+ }
138
+ function setMatrixGroupPolicy(cfg, groupPolicy, accountId) {
139
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), { groupPolicy });
140
+ }
141
+ function setMatrixGroupRooms(cfg, roomKeys, accountId) {
142
+ const groups = Object.fromEntries(roomKeys.map((key) => [key, { enabled: true }]));
143
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), {
144
+ groups,
145
+ rooms: null
146
+ });
147
+ }
148
+ function setMatrixAutoJoin(cfg, autoJoin, autoJoinAllowlist, accountId) {
149
+ return updateMatrixAccountConfig(cfg, resolveMatrixOnboardingAccountId(cfg, accountId), {
150
+ autoJoin,
151
+ autoJoinAllowlist: autoJoin === "allowlist" ? autoJoinAllowlist : null
152
+ });
153
+ }
154
+ async function configureMatrixInviteAutoJoin(params) {
155
+ const accountId = resolveMatrixOnboardingAccountId(params.cfg, params.accountId);
156
+ const existingConfig = resolveMatrixAccountConfig({
157
+ cfg: params.cfg,
158
+ accountId
159
+ });
160
+ const currentPolicy = existingConfig.autoJoin ?? "off";
161
+ const currentAllowlist = (existingConfig.autoJoinAllowlist ?? []).map((entry) => String(entry));
162
+ const hasExistingConfig = existingConfig.autoJoin !== void 0 || currentAllowlist.length > 0;
163
+ await params.prompter.note([
164
+ "WARNING: Matrix invite auto-join defaults to off.",
165
+ "Klaw agents will not join invited rooms or fresh DM-style invites unless you set autoJoin.",
166
+ "Choose \"allowlist\" to restrict joins or \"always\" to join every invite."
167
+ ].join("\n"), "Matrix invite auto-join");
168
+ if (!await params.prompter.confirm({
169
+ message: hasExistingConfig ? "Update Matrix invite auto-join?" : "Configure Matrix invite auto-join?",
170
+ initialValue: hasExistingConfig ? currentPolicy !== "off" : true
171
+ })) return params.cfg;
172
+ const selectedPolicy = await params.prompter.select({
173
+ message: "Matrix invite auto-join",
174
+ options: matrixInviteAutoJoinOptions,
175
+ initialValue: currentPolicy
176
+ });
177
+ if (!isMatrixInviteAutoJoinPolicy(selectedPolicy)) throw new Error(`Unsupported Matrix invite auto-join policy: ${String(selectedPolicy)}`);
178
+ const policy = selectedPolicy;
179
+ if (policy === "off") {
180
+ 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");
181
+ return setMatrixAutoJoin(params.cfg, policy, [], accountId);
182
+ }
183
+ if (policy === "always") return setMatrixAutoJoin(params.cfg, policy, [], accountId);
184
+ while (true) {
185
+ const allowlist = normalizeMatrixInviteAutoJoinTargets(splitSetupEntries(await params.prompter.text({
186
+ message: "Matrix invite auto-join allowlist (comma-separated)",
187
+ placeholder: "!roomId:server, #alias:server, *",
188
+ initialValue: currentAllowlist[0] ? currentAllowlist.join(", ") : void 0,
189
+ validate: (value) => {
190
+ return splitSetupEntries(value).length > 0 ? void 0 : "Required";
191
+ }
192
+ })));
193
+ const invalidEntries = allowlist.filter((entry) => !isMatrixInviteAutoJoinTarget(entry));
194
+ if (allowlist.length === 0 || invalidEntries.length > 0) {
195
+ 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");
196
+ continue;
197
+ }
198
+ return setMatrixAutoJoin(params.cfg, "allowlist", allowlist, accountId);
199
+ }
200
+ }
201
+ async function configureMatrixAccessPrompts(params) {
202
+ let next = params.cfg;
203
+ if (params.forceAllowFrom) next = await promptMatrixAllowFrom({
204
+ cfg: next,
205
+ prompter: params.prompter,
206
+ accountId: params.accountId
207
+ });
208
+ const existingAccountConfig = resolveMatrixAccountConfig({
209
+ cfg: next,
210
+ accountId: params.accountId
211
+ });
212
+ const existingGroups = existingAccountConfig.groups ?? existingAccountConfig.rooms;
213
+ const accessConfig = await promptChannelAccessConfig({
214
+ prompter: params.prompter,
215
+ label: "Matrix rooms",
216
+ currentPolicy: existingAccountConfig.groupPolicy ?? "allowlist",
217
+ currentEntries: Object.keys(existingGroups ?? {}),
218
+ placeholder: "!roomId:server, #alias:server, Project Room",
219
+ updatePrompt: Boolean(existingGroups)
220
+ });
221
+ if (accessConfig) if (accessConfig.policy !== "allowlist") next = setMatrixGroupPolicy(next, accessConfig.policy, params.accountId);
222
+ else {
223
+ let roomKeys = accessConfig.entries;
224
+ if (accessConfig.entries.length > 0) try {
225
+ const resolvedIds = [];
226
+ const unresolved = [];
227
+ for (const entry of accessConfig.entries) {
228
+ const trimmed = normalizeOptionalString(entry) ?? "";
229
+ if (!trimmed) continue;
230
+ const cleaned = trimmed.replace(/^(room|channel):/i, "").trim();
231
+ if (cleaned.startsWith("!") && cleaned.includes(":")) {
232
+ resolvedIds.push(cleaned);
233
+ continue;
234
+ }
235
+ const { listMatrixDirectoryGroupsLive } = await import("./directory-live-i3T8uORc.js").then((n) => n.t);
236
+ const matches = await listMatrixDirectoryGroupsLive({
237
+ cfg: next,
238
+ accountId: params.accountId,
239
+ query: trimmed,
240
+ limit: 10
241
+ });
242
+ const best = matches.find((match) => normalizeLowercaseStringOrEmpty(match.name) === normalizeLowercaseStringOrEmpty(trimmed)) ?? matches[0];
243
+ if (best?.id) resolvedIds.push(best.id);
244
+ else unresolved.push(entry);
245
+ }
246
+ roomKeys = [...resolvedIds, ...unresolved.map((entry) => normalizeOptionalString(entry)).filter((entry) => Boolean(entry))];
247
+ 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");
248
+ } catch (err) {
249
+ await params.prompter.note(`Room lookup failed; keeping entries as typed. ${String(err)}`, "Matrix rooms");
250
+ }
251
+ next = setMatrixGroupPolicy(next, "allowlist", params.accountId);
252
+ next = setMatrixGroupRooms(next, roomKeys, params.accountId);
253
+ }
254
+ return await configureMatrixInviteAutoJoin({
255
+ cfg: next,
256
+ prompter: params.prompter,
257
+ accountId: params.accountId
258
+ });
259
+ }
260
+ const dmPolicy = {
261
+ label: "Matrix",
262
+ channel,
263
+ policyKey: "channels.matrix.dm.policy",
264
+ allowFromKey: "channels.matrix.dm.allowFrom",
265
+ resolveConfigKeys: (cfg, accountId) => {
266
+ const effectiveAccountId = resolveMatrixOnboardingAccountId(cfg, accountId);
267
+ return {
268
+ policyKey: resolveMatrixConfigFieldPath(cfg, effectiveAccountId, "dm.policy"),
269
+ allowFromKey: resolveMatrixConfigFieldPath(cfg, effectiveAccountId, "dm.allowFrom")
270
+ };
271
+ },
272
+ getCurrent: (cfg, accountId) => resolveMatrixAccountConfig({
273
+ cfg,
274
+ accountId: resolveMatrixOnboardingAccountId(cfg, accountId)
275
+ }).dm?.policy ?? "pairing",
276
+ setPolicy: (cfg, policy, accountId) => setMatrixDmPolicy(cfg, policy, accountId),
277
+ promptAllowFrom: promptMatrixAllowFrom
278
+ };
279
+ async function runMatrixConfigure(params) {
280
+ let next = params.cfg;
281
+ await ensureMatrixSdkInstalled({
282
+ runtime: params.runtime,
283
+ confirm: async (message) => await params.prompter.confirm({
284
+ message,
285
+ initialValue: true
286
+ })
287
+ });
288
+ const defaultAccountId = resolveDefaultMatrixAccountId(next);
289
+ let accountId = defaultAccountId || DEFAULT_ACCOUNT_ID;
290
+ if (params.intent === "add-account") {
291
+ const enteredName = normalizeStringifiedOptionalString(await params.prompter.text({
292
+ message: "Matrix account name",
293
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
294
+ })) ?? "";
295
+ accountId = normalizeAccountId$1(enteredName);
296
+ if (enteredName !== accountId) await params.prompter.note(`Account id will be "${accountId}".`, "Matrix account");
297
+ if (accountId !== DEFAULT_ACCOUNT_ID) next = moveSingleMatrixAccountConfigToNamedAccount(next);
298
+ next = updateMatrixAccountConfig(next, accountId, {
299
+ name: enteredName,
300
+ enabled: true
301
+ });
302
+ } else {
303
+ const override = normalizeOptionalString(params.accountOverrides?.[channel]);
304
+ if (override) accountId = normalizeAccountId$1(override);
305
+ else if (params.shouldPromptAccountIds) accountId = await promptAccountId({
306
+ cfg: next,
307
+ prompter: params.prompter,
308
+ label: "Matrix",
309
+ currentId: accountId,
310
+ listAccountIds: (inputCfg) => listMatrixAccountIds(inputCfg),
311
+ defaultAccountId
312
+ });
313
+ }
314
+ const existing = resolveMatrixAccountConfig({
315
+ cfg: next,
316
+ accountId
317
+ });
318
+ if (!resolveMatrixAccount({
319
+ cfg: next,
320
+ accountId
321
+ }).configured) await noteMatrixAuthHelp(params.prompter);
322
+ const envReadiness = resolveMatrixEnvAuthReadiness(accountId, process.env);
323
+ const envReady = envReadiness.ready;
324
+ const envHomeserver = envReadiness.homeserver;
325
+ const envUserId = envReadiness.userId;
326
+ if (envReady && !existing.homeserver && !existing.userId && !existing.accessToken && !existing.password) {
327
+ if (await params.prompter.confirm({
328
+ message: `Matrix env vars detected (${envReadiness.sourceHint}). Use env values?`,
329
+ initialValue: true
330
+ })) {
331
+ next = updateMatrixAccountConfig(next, accountId, { enabled: true });
332
+ next = await configureMatrixAccessPrompts({
333
+ cfg: next,
334
+ prompter: params.prompter,
335
+ forceAllowFrom: params.forceAllowFrom,
336
+ accountId
337
+ });
338
+ return {
339
+ cfg: next,
340
+ accountId
341
+ };
342
+ }
343
+ }
344
+ const homeserver = normalizeStringifiedOptionalString(await params.prompter.text({
345
+ message: "Matrix homeserver URL",
346
+ initialValue: existing.homeserver ?? envHomeserver,
347
+ validate: (value) => {
348
+ try {
349
+ validateMatrixHomeserverUrl(value, { allowPrivateNetwork: true });
350
+ return;
351
+ } catch (error) {
352
+ return error instanceof Error ? error.message : "Invalid Matrix homeserver URL";
353
+ }
354
+ }
355
+ })) ?? "";
356
+ const requiresAllowPrivateNetwork = requiresMatrixPrivateNetworkOptIn(homeserver);
357
+ const shouldPromptAllowPrivateNetwork = requiresAllowPrivateNetwork || isPrivateNetworkOptInEnabled(existing);
358
+ const allowPrivateNetwork = shouldPromptAllowPrivateNetwork ? await params.prompter.confirm({
359
+ message: "Allow private/internal Matrix homeserver traffic for this account?",
360
+ initialValue: isPrivateNetworkOptInEnabled(existing) || requiresAllowPrivateNetwork
361
+ }) : false;
362
+ if (requiresAllowPrivateNetwork && !allowPrivateNetwork) throw new Error("Matrix homeserver requires explicit private-network opt-in");
363
+ await resolveValidatedMatrixHomeserverUrl(homeserver, { dangerouslyAllowPrivateNetwork: allowPrivateNetwork });
364
+ let accessToken = existing.accessToken;
365
+ let password = existing.password;
366
+ let userId = existing.userId ?? "";
367
+ if (hasConfiguredSecretInput(accessToken) || hasConfiguredSecretInput(password)) {
368
+ if (!await params.prompter.confirm({
369
+ message: "Matrix credentials already configured. Keep them?",
370
+ initialValue: true
371
+ })) {
372
+ accessToken = void 0;
373
+ password = void 0;
374
+ userId = "";
375
+ }
376
+ }
377
+ if (!hasConfiguredSecretInput(accessToken) && !hasConfiguredSecretInput(password)) if (await params.prompter.select({
378
+ message: "Matrix auth method",
379
+ options: [{
380
+ value: "token",
381
+ label: "Access token (user ID fetched automatically)"
382
+ }, {
383
+ value: "password",
384
+ label: "Password (requires user ID)"
385
+ }]
386
+ }) === "token") {
387
+ accessToken = normalizeStringifiedOptionalString(await params.prompter.text({
388
+ message: "Matrix access token",
389
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
390
+ })) ?? "";
391
+ password = void 0;
392
+ userId = "";
393
+ } else {
394
+ userId = normalizeStringifiedOptionalString(await params.prompter.text({
395
+ message: "Matrix user ID",
396
+ initialValue: existing.userId ?? envUserId,
397
+ validate: (value) => {
398
+ const raw = normalizeOptionalString(value) ?? "";
399
+ if (!raw) return "Required";
400
+ if (!raw.startsWith("@")) return "Matrix user IDs should start with @";
401
+ if (!raw.includes(":")) return "Matrix user IDs should include a server (:server)";
402
+ }
403
+ })) ?? "";
404
+ password = normalizeStringifiedOptionalString(await params.prompter.text({
405
+ message: "Matrix password",
406
+ validate: (value) => normalizeOptionalString(value) ? void 0 : "Required"
407
+ })) ?? "";
408
+ accessToken = void 0;
409
+ }
410
+ const deviceName = normalizeStringifiedOptionalString(await params.prompter.text({
411
+ message: "Matrix device name (optional)",
412
+ initialValue: existing.deviceName ?? "Klaw Gateway"
413
+ })) ?? "";
414
+ const enableEncryption = await params.prompter.confirm({
415
+ message: "Enable end-to-end encryption (E2EE)?",
416
+ initialValue: existing.encryption ?? false
417
+ });
418
+ next = updateMatrixAccountConfig(next, accountId, {
419
+ enabled: true,
420
+ homeserver,
421
+ ...shouldPromptAllowPrivateNetwork ? { allowPrivateNetwork: allowPrivateNetwork ? true : null } : {},
422
+ userId: userId || null,
423
+ accessToken: accessToken ?? null,
424
+ password: password ?? null,
425
+ deviceName: deviceName || null,
426
+ encryption: enableEncryption
427
+ });
428
+ next = await configureMatrixAccessPrompts({
429
+ cfg: next,
430
+ prompter: params.prompter,
431
+ forceAllowFrom: params.forceAllowFrom,
432
+ accountId
433
+ });
434
+ return {
435
+ cfg: next,
436
+ accountId
437
+ };
438
+ }
439
+ const matrixOnboardingAdapter = {
440
+ channel,
441
+ getStatus: async ({ cfg, accountOverrides }) => {
442
+ const resolvedCfg = cfg;
443
+ const sdkReady = isMatrixSdkAvailable();
444
+ if (!accountOverrides[channel] && requiresExplicitMatrixDefaultAccount(resolvedCfg)) return {
445
+ channel,
446
+ configured: false,
447
+ statusLines: ["Matrix: set \"channels.matrix.defaultAccount\" to select a named account"],
448
+ selectionHint: !sdkReady ? "install Matrix deps" : "set defaultAccount"
449
+ };
450
+ const configured = resolveMatrixAccount({
451
+ cfg: resolvedCfg,
452
+ accountId: resolveMatrixOnboardingAccountId(resolvedCfg, accountOverrides[channel])
453
+ }).configured;
454
+ return {
455
+ channel,
456
+ configured,
457
+ statusLines: [`Matrix: ${configured ? "configured" : "needs homeserver + access token or password"}`],
458
+ selectionHint: !sdkReady ? "install Matrix deps" : configured ? "configured" : "needs auth"
459
+ };
460
+ },
461
+ configure: async ({ cfg, runtime, prompter, forceAllowFrom, accountOverrides, shouldPromptAccountIds }) => await runMatrixConfigure({
462
+ cfg,
463
+ runtime,
464
+ prompter,
465
+ forceAllowFrom,
466
+ accountOverrides,
467
+ shouldPromptAccountIds,
468
+ intent: "update"
469
+ }),
470
+ configureInteractive: async ({ cfg, runtime, prompter, forceAllowFrom, accountOverrides, shouldPromptAccountIds, configured }) => {
471
+ if (!configured) return await runMatrixConfigure({
472
+ cfg,
473
+ runtime,
474
+ prompter,
475
+ forceAllowFrom,
476
+ accountOverrides,
477
+ shouldPromptAccountIds,
478
+ intent: "update"
479
+ });
480
+ const action = await prompter.select({
481
+ message: "Matrix already configured. What do you want to do?",
482
+ options: [
483
+ {
484
+ value: "update",
485
+ label: "Modify settings"
486
+ },
487
+ {
488
+ value: "add-account",
489
+ label: "Add account"
490
+ },
491
+ {
492
+ value: "skip",
493
+ label: "Skip (leave as-is)"
494
+ }
495
+ ],
496
+ initialValue: "update"
497
+ });
498
+ if (action === "skip") return "skip";
499
+ return await runMatrixConfigure({
500
+ cfg,
501
+ runtime,
502
+ prompter,
503
+ forceAllowFrom,
504
+ accountOverrides,
505
+ shouldPromptAccountIds,
506
+ intent: action === "add-account" ? "add-account" : "update"
507
+ });
508
+ },
509
+ afterConfigWritten: async ({ previousCfg, cfg, accountId, runtime }) => {
510
+ const { runMatrixSetupBootstrapAfterConfigWrite } = await import("./setup-bootstrap-rJ0qZWPe.js");
511
+ await runMatrixSetupBootstrapAfterConfigWrite({
512
+ previousCfg,
513
+ cfg,
514
+ accountId,
515
+ runtime
516
+ });
517
+ },
518
+ dmPolicy,
519
+ disable: (cfg) => ({
520
+ ...cfg,
521
+ channels: {
522
+ ...cfg.channels,
523
+ matrix: {
524
+ ...cfg.channels?.["matrix"],
525
+ enabled: false
526
+ }
527
+ }
528
+ })
529
+ };
530
+ //#endregion
531
+ //#region extensions/matrix/src/setup-surface.ts
532
+ var setup_surface_exports = /* @__PURE__ */ __exportAll({
533
+ matrixOnboardingAdapter: () => matrixOnboardingAdapter,
534
+ matrixSetupWizard: () => matrixOnboardingAdapter
535
+ });
536
+ //#endregion
537
+ export { matrixOnboardingAdapter as n, setup_surface_exports as t };