@openclaw/matrix 2026.7.2-beta.7 → 2026.8.1-beta.3

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 (92) hide show
  1. package/dist/{account-selection-kqquRzCf.js → account-selection-CWuhuFn1.js} +7 -8
  2. package/dist/{accounts-DfngqebB.js → accounts-BCzyubQt.js} +3 -3
  3. package/dist/api.js +8 -11
  4. package/dist/{approval-handler.runtime-DSeaIsGa.js → approval-handler.runtime-CSvueU9P.js} +7 -6
  5. package/dist/{approval-ids-BdJGPAJT.js → approval-ids-CEcf-EiM.js} +1 -1
  6. package/dist/{approval-reaction-auth-BjOpELxu.js → approval-reaction-auth-CziKXatm.js} +2 -2
  7. package/dist/{approval-reactions-D-BxBK_L.js → approval-reactions-tXh9KYrW.js} +2 -8
  8. package/dist/auth-presence.js +2 -2
  9. package/dist/{channel-vj788dNZ.js → channel-CzQw5OZN.js} +376 -148
  10. package/dist/channel-plugin-api.js +1 -1
  11. package/dist/{channel.runtime-CLoF2S9T.js → channel.runtime-I9pBRQb3.js} +79 -55
  12. package/dist/{config-schema-Djxw3C6b.js → channel.setup-aNaa3Uyn.js} +51 -10
  13. package/dist/{cli-DMqfDE-q.js → cli-iR6QJ5U0.js} +16 -16
  14. package/dist/{cli-metadata-C7D53SND.js → cli-metadata-BmUYWjuM.js} +1 -1
  15. package/dist/cli-metadata.js +1 -1
  16. package/dist/client-BBQdBG7t.js +799 -0
  17. package/dist/{client-6eRENr7k.js → client-D8XghqmX.js} +4 -4
  18. package/dist/{client-bootstrap-XsIkHNt0.js → client-bootstrap-Co3RlItb.js} +25 -61
  19. package/dist/client-support-DLj4vDeu.js +93 -0
  20. package/dist/config-update-Bor_Pjsv.js +150 -0
  21. package/dist/contract-api.js +2 -2
  22. package/dist/{credentials-W2EmwRhu.js → credentials-BdAaWuiR.js} +2 -1
  23. package/dist/credentials-read-B37cQknZ.js +51 -0
  24. package/dist/credentials-state-B3cuUFwZ.js +27 -0
  25. package/dist/{credentials-write.runtime-Be9zNSUw.js → credentials-write.runtime-nAV2-5uR.js} +1 -1
  26. package/dist/{crypto-runtime-D9_6J5tZ.js → crypto-runtime-Bnz3zEcS.js} +55 -32
  27. package/dist/direct-room-RinHjtqX.js +71 -0
  28. package/dist/{directory-live-C8dVBiCc.js → directory-live-DLQzel12.js} +2 -3
  29. package/dist/{doctor-CM8ijNpW.js → doctor-EWf9CDso.js} +2 -2
  30. package/dist/{doctor-contract-BMSJkkAE.js → doctor-contract-DEt4O4Zt.js} +2 -3
  31. package/dist/doctor-contract-api.js +209 -91
  32. package/dist/{draft-stream-CtvOXq0Z.js → draft-stream-DQ7QNC-l.js} +20 -23
  33. package/dist/{encryption-guidance-CbEFe38F.js → encryption-guidance-DmLY8NiO.js} +1 -1
  34. package/dist/{env-auth-CQsYbz-p.js → env-auth-MVS-Vv41.js} +4 -3
  35. package/dist/{env-vars-B0NxQnPk.js → env-vars-dGqak9dN.js} +1 -1
  36. package/dist/{errors-C47hvAF8.js → errors-DKVS3_DO.js} +2 -5
  37. package/dist/{file-sync-store-DiiFsayX.js → file-sync-store-DjskBX2o.js} +24 -3
  38. package/dist/helper-api.js +2 -2
  39. package/dist/{idb-persistence-B6x7dMsF.js → idb-persistence-BM0P27Zg.js} +3 -2
  40. package/dist/{inbound-dedupe-CaBLblef.js → inbound-dedupe-RvSLqdsz.js} +2 -2
  41. package/dist/index.js +1 -1
  42. package/dist/{logger-D0GCSDQq.js → logger-B_71hN6W.js} +1 -1
  43. package/dist/{logging-DV-p52N0.js → logging-DRjvUOIh.js} +1 -1
  44. package/dist/{media-text-BTwzADS_.js → media-text-Dh-DpTc3.js} +4 -1
  45. package/dist/{messages-DxQJkhxs.js → messages-DEqg7HVy.js} +31 -11
  46. package/dist/{monitor-VyWlSLwo.js → monitor-FNrfkuWL.js} +413 -405
  47. package/dist/plugin-entry.handlers.runtime.js +3 -3
  48. package/dist/probe.runtime-NIJZYqc2.js +2 -0
  49. package/dist/profile-D-Wubo0A.js +108 -0
  50. package/dist/{profile-update-CffmyW_4.js → profile-update-BQlE5s2J.js} +3 -2
  51. package/dist/{reaction-events-B00WSi98.js → reaction-events-BKOLlnCo.js} +10 -7
  52. package/dist/{recovery-key-store-BNnHvXdk.js → recovery-key-store-CognuDys.js} +5 -4
  53. package/dist/{resolve-targets-nm2L48sh.js → resolve-targets-e7AI0P75.js} +2 -2
  54. package/dist/{resolver.runtime-DS6uPaEe.js → resolver.runtime-V8u0pHEb.js} +1 -1
  55. package/dist/{room-info-CAFZ3Z9J.js → room-info-BXQA7y10.js} +12 -3
  56. package/dist/runtime-api.js +7 -4
  57. package/dist/{sdk-bUytQHx7.js → sdk-NxK3vzMa.js} +242 -119
  58. package/dist/{secret-contract-M3hRmGO-.js → secret-contract-CufozuyJ.js} +1 -1
  59. package/dist/secret-contract-api.js +1 -1
  60. package/dist/{send-BldGYG8g.js → send-ClHgDZLT.js} +1477 -1210
  61. package/dist/session-binding-contract-api.js +2 -3
  62. package/dist/{setup-bootstrap-Deleiibz.js → setup-bootstrap-BGPjbA5N.js} +4 -4
  63. package/dist/{setup-core-BVfBv2ai.js → setup-core-DigrLebY.js} +17 -266
  64. package/dist/setup-plugin-api.js +1 -44
  65. package/dist/{setup-surface-BBq3WeqX.js → setup-surface-Dtn8sAWs.js} +15 -16
  66. package/dist/{startup-verification-wm3_i88s.js → startup-verification-Cs08ca8u.js} +3 -3
  67. package/dist/{storage-BvAkgzvT.js → storage-BsGuHngK.js} +3 -3
  68. package/dist/subagent-hooks-CMoZaARG.js +48 -0
  69. package/dist/subagent-hooks-api.js +1 -1
  70. package/dist/{target-ids-B-5aQxwn.js → target-ids-Nwx7cMVE.js} +11 -1
  71. package/dist/{thread-binding-api-DRbBZlhS.js → thread-binding-api-CzkeLZCU.js} +1 -1
  72. package/dist/thread-binding-api.js +1 -1
  73. package/dist/{thread-bindings-DGbl3vDW.js → thread-bindings-BYEGfw3h.js} +17 -10
  74. package/dist/thread-bindings-runtime.js +1 -1
  75. package/dist/{thread-bindings-shared-CKnY4LSd.js → thread-bindings-shared-oNPiyMWY.js} +1 -6
  76. package/dist/{tool-actions.runtime-uu9blSqO.js → tool-actions.runtime-ck6IJyP0.js} +36 -19
  77. package/dist/{verification-DYMQ1QpI.js → verification-CabtBTtB.js} +2 -2
  78. package/openclaw.plugin.json +61 -1
  79. package/package.json +4 -4
  80. package/dist/active-client-DXvz2gCo.js +0 -20
  81. package/dist/client-Dbso3-0V.js +0 -30
  82. package/dist/create-client-BmSU-q-D.js +0 -61
  83. package/dist/credentials-read-DVmFCm7X.js +0 -77
  84. package/dist/exec-approval-resolver-BCgqRtZS.js +0 -16
  85. package/dist/preflight-audio.runtime-BZxxQsxY.js +0 -11
  86. package/dist/probe.runtime-BuieqmS3.js +0 -3
  87. package/dist/record-shared-CWWx6fvI.js +0 -2
  88. package/dist/route-DY6at4qJ.js +0 -161
  89. package/dist/shared-CUMWxcMz.js +0 -673
  90. package/dist/subagent-hooks-dkPAF6Et.js +0 -143
  91. package/dist/sync-state-CWbp0QSY.js +0 -12
  92. package/dist/{runtime-api-D1xI_cvh.js → runtime-api-BGO16Fu8.js} +3 -3
@@ -1,673 +0,0 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount, o as resolveMatrixAccountStringValues } from "./account-selection-kqquRzCf.js";
3
- import { t as getMatrixScopedEnvVarNames } from "./env-vars-B0NxQnPk.js";
4
- import { o as resolveMatrixBaseConfig, r as listNormalizedMatrixAccountIds, t as findMatrixAccountConfig } from "./account-config-BZWN9tGS.js";
5
- import { i as resolveScopedMatrixEnvConfig, n as resolveGlobalMatrixEnvConfig } from "./env-auth-CQsYbz-p.js";
6
- import { t as resolveMatrixConfigFieldPath } from "./config-paths-CnREYb1Y.js";
7
- import { t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-GRHde6lq.js";
8
- import { s as repairCurrentTokenStorageMetaDeviceId } from "./storage-BvAkgzvT.js";
9
- import { n as LogService } from "./logger-D0GCSDQq.js";
10
- import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
11
- import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, normalizeAccountId as normalizeAccountId$1, normalizeOptionalAccountId, normalizeOptionalAccountId as normalizeOptionalAccountId$1 } from "openclaw/plugin-sdk/account-id";
12
- import { coerceSecretRef, normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
13
- import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
14
- import { isPrivateNetworkOptInEnabled, ssrfPolicyFromDangerouslyAllowPrivateNetwork as ssrfPolicyFromDangerouslyAllowPrivateNetwork$1 } from "openclaw/plugin-sdk/ssrf-runtime";
15
- import { resolveOptionalIntegerOption } from "openclaw/plugin-sdk/number-runtime";
16
- import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
17
- import { retryAsync } from "openclaw/plugin-sdk/retry-runtime";
18
- import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
19
- //#region extensions/matrix/src/matrix/client/config.ts
20
- const loadDefaultMatrixAuthClientDeps = createLazyRuntimeModule(() => Promise.all([import("./sdk-bUytQHx7.js"), import("./logging-DV-p52N0.js").then((n) => n.n)]).then(([sdkModule, loggingModule]) => ({
21
- MatrixClient: sdkModule.MatrixClient,
22
- ensureMatrixSdkLoggingConfigured: loggingModule.ensureMatrixSdkLoggingConfigured
23
- })));
24
- 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;
25
- async function loadMatrixAuthClientDeps() {
26
- return await loadDefaultMatrixAuthClientDeps();
27
- }
28
- const loadMatrixCredentialsReadDeps = createLazyRuntimeModule(() => import("./credentials-read-DVmFCm7X.js").then((n) => n.i).then((credentialsReadModule) => ({
29
- loadMatrixCredentials: credentialsReadModule.loadMatrixCredentials,
30
- credentialsMatchConfig: credentialsReadModule.credentialsMatchConfig
31
- })));
32
- const loadMatrixCredentialsWriteRuntime = createLazyRuntimeModule(() => import("./credentials-write.runtime-Be9zNSUw.js"));
33
- const loadMatrixSecretInputDeps = createLazyRuntimeModule(() => import("./config-secret-input.runtime-CwsP3--c.js").then((runtime) => ({ resolveConfiguredSecretInputString: runtime.resolveConfiguredSecretInputString })));
34
- function shouldRetryMatrixAuthRequest(err) {
35
- return MATRIX_AUTH_REQUEST_RETRY_RE.test(formatErrorMessage(err));
36
- }
37
- function isAbortSignalTriggered(signal) {
38
- return signal?.aborted === true;
39
- }
40
- function credentialsMatchBackfillAuthLineage(params) {
41
- if (!params.stored) return true;
42
- return params.stored.homeserver === params.auth.homeserver && params.stored.userId === params.auth.userId && params.stored.accessToken === params.auth.accessToken;
43
- }
44
- async function retryMatrixAuthRequest(label, run, signal) {
45
- return await retryAsync(run, {
46
- attempts: 3,
47
- minDelayMs: 250,
48
- maxDelayMs: 1500,
49
- jitter: .1,
50
- label,
51
- shouldRetry: (err) => shouldRetryMatrixAuthRequest(err),
52
- sleep: (ms) => sleepWithAbort(ms, signal)
53
- });
54
- }
55
- async function fetchMatrixWhoamiIdentity(params) {
56
- const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixAuthClientDeps();
57
- ensureMatrixSdkLoggingConfigured();
58
- const tempClient = new MatrixClient(params.homeserver, params.accessToken, {
59
- userId: params.userId,
60
- ssrfPolicy: params.ssrfPolicy,
61
- dispatcherPolicy: params.dispatcherPolicy
62
- });
63
- return await retryMatrixAuthRequest("matrix auth whoami", async () => {
64
- return await tempClient.doRequest("GET", "/_matrix/client/v3/account/whoami");
65
- }, params.signal);
66
- }
67
- function readEnvSecretRefFallback(params) {
68
- const ref = coerceSecretRef(params.value, params.config?.secrets?.defaults);
69
- if (!ref || ref.source !== "env" || !params.env) return;
70
- const providerConfig = params.config?.secrets?.providers?.[ref.provider];
71
- if (providerConfig) {
72
- if (providerConfig.source !== "env") throw new Error(`Secret provider "${ref.provider}" has source "${providerConfig.source}" but ref requests "env".`);
73
- if (providerConfig.allowlist && !providerConfig.allowlist.includes(ref.id)) throw new Error(`Environment variable "${ref.id}" is not allowlisted in secrets.providers.${ref.provider}.allowlist.`);
74
- } 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}).`);
75
- const resolved = params.env[ref.id];
76
- if (typeof resolved !== "string") return;
77
- const trimmed = resolved.trim();
78
- return trimmed.length > 0 ? trimmed : void 0;
79
- }
80
- function clean(value, path, opts) {
81
- const ref = coerceSecretRef(value, opts?.config?.secrets?.defaults);
82
- if (opts?.suppressSecretRef && ref) return "";
83
- return normalizeResolvedSecretInputString({
84
- value: opts?.allowEnvSecretRefFallback ? ref?.source === "env" ? readEnvSecretRefFallback({
85
- value,
86
- env: opts.env,
87
- config: opts.config
88
- }) ?? value : ref ? "" : value : value,
89
- path,
90
- defaults: opts?.config?.secrets?.defaults
91
- }) ?? "";
92
- }
93
- function resolveMatrixBaseConfigFieldPath(field) {
94
- return `channels.matrix.${field}`;
95
- }
96
- function shouldAllowEnvSecretRefFallback(field) {
97
- return field === "accessToken" || field === "password";
98
- }
99
- function hasConfiguredSecretInputValue(value, cfg) {
100
- return typeof value === "string" && value.trim().length > 0 || Boolean(coerceSecretRef(value, cfg.secrets?.defaults));
101
- }
102
- function hasConfiguredMatrixAccessTokenSource(params) {
103
- const normalizedAccountId = normalizeAccountId$1(params.accountId);
104
- const account = findMatrixAccountConfig(params.cfg, normalizedAccountId) ?? {};
105
- const scopedAccessTokenVar = getMatrixScopedEnvVarNames(normalizedAccountId).accessToken;
106
- if (hasConfiguredSecretInputValue(account.accessToken, params.cfg) || clean(params.env[scopedAccessTokenVar], scopedAccessTokenVar).length > 0) return true;
107
- if (normalizedAccountId !== DEFAULT_ACCOUNT_ID$1) return false;
108
- return hasConfiguredSecretInputValue(resolveMatrixBaseConfig(params.cfg).accessToken, params.cfg) || clean(params.env.MATRIX_ACCESS_TOKEN, "MATRIX_ACCESS_TOKEN").length > 0;
109
- }
110
- function resolveConfiguredMatrixAuthInput(params) {
111
- const normalizedAccountId = normalizeAccountId$1(params.accountId);
112
- const accountValue = (findMatrixAccountConfig(params.cfg, normalizedAccountId) ?? {})[params.field];
113
- if (accountValue !== void 0) return {
114
- value: accountValue,
115
- path: resolveMatrixConfigFieldPath(params.cfg, normalizedAccountId, params.field)
116
- };
117
- const scopedKeys = getMatrixScopedEnvVarNames(normalizedAccountId);
118
- const scopedValue = resolveScopedMatrixEnvConfig(normalizedAccountId, params.env)[params.field];
119
- if (scopedValue !== void 0) return {
120
- value: scopedValue,
121
- path: params.field === "accessToken" ? scopedKeys.accessToken : scopedKeys.password
122
- };
123
- if (normalizedAccountId !== DEFAULT_ACCOUNT_ID$1) return;
124
- const baseValue = resolveMatrixBaseConfig(params.cfg)[params.field];
125
- if (baseValue !== void 0) return {
126
- value: baseValue,
127
- path: resolveMatrixBaseConfigFieldPath(params.field)
128
- };
129
- const globalValue = params.field === "accessToken" ? params.env.MATRIX_ACCESS_TOKEN : params.env.MATRIX_PASSWORD;
130
- if (globalValue !== void 0) return {
131
- value: globalValue,
132
- path: params.field === "accessToken" ? "MATRIX_ACCESS_TOKEN" : "MATRIX_PASSWORD"
133
- };
134
- }
135
- async function resolveConfiguredMatrixAuthSecretInput(params) {
136
- const configured = resolveConfiguredMatrixAuthInput(params);
137
- if (!configured) return;
138
- if (!coerceSecretRef(configured.value, params.cfg.secrets?.defaults)) return normalizeResolvedSecretInputString({
139
- value: configured.value,
140
- path: configured.path,
141
- defaults: params.cfg.secrets?.defaults
142
- });
143
- const { resolveConfiguredSecretInputString } = await loadMatrixSecretInputDeps();
144
- const resolved = await resolveConfiguredSecretInputString({
145
- config: params.cfg,
146
- env: params.env,
147
- value: configured.value,
148
- path: configured.path,
149
- unresolvedReasonStyle: "detailed"
150
- });
151
- if (resolved.value !== void 0) return resolved.value;
152
- throw new Error(resolved.unresolvedRefReason ?? `${configured.path} SecretRef could not be resolved.`);
153
- }
154
- function readMatrixBaseConfigField(matrix, field, opts) {
155
- return clean(matrix[field], resolveMatrixBaseConfigFieldPath(field), {
156
- env: opts?.env,
157
- config: opts?.config,
158
- allowEnvSecretRefFallback: shouldAllowEnvSecretRefFallback(field),
159
- suppressSecretRef: opts?.suppressSecretRef
160
- });
161
- }
162
- function readMatrixAccountConfigField(cfg, accountId, account, field, opts) {
163
- return clean(account[field], resolveMatrixConfigFieldPath(cfg, accountId, field), {
164
- env: opts?.env,
165
- config: opts?.config,
166
- allowEnvSecretRefFallback: shouldAllowEnvSecretRefFallback(field),
167
- suppressSecretRef: opts?.suppressSecretRef
168
- });
169
- }
170
- function clampMatrixInitialSyncLimit(value) {
171
- return resolveOptionalIntegerOption(value, { min: 0 });
172
- }
173
- function buildMatrixNetworkFields(params) {
174
- const dispatcherPolicy = params.dispatcherPolicy ?? (params.proxy ? {
175
- mode: "explicit-proxy",
176
- proxyUrl: params.proxy
177
- } : void 0);
178
- if (!params.allowPrivateNetwork && !dispatcherPolicy) return {};
179
- return {
180
- ...params.allowPrivateNetwork ? {
181
- allowPrivateNetwork: true,
182
- ssrfPolicy: ssrfPolicyFromDangerouslyAllowPrivateNetwork$1(true)
183
- } : {},
184
- ...dispatcherPolicy ? { dispatcherPolicy } : {}
185
- };
186
- }
187
- function hasScopedMatrixEnvConfig(accountId, env) {
188
- const scoped = resolveScopedMatrixEnvConfig(accountId, env);
189
- return Boolean(scoped.homeserver || scoped.userId || scoped.accessToken || scoped.password || scoped.deviceId || scoped.deviceName);
190
- }
191
- function resolveMatrixConfigForAccount(cfg, accountId, env = process.env) {
192
- const matrix = resolveMatrixBaseConfig(cfg);
193
- const account = findMatrixAccountConfig(cfg, accountId) ?? {};
194
- const normalizedAccountId = normalizeAccountId$1(accountId);
195
- const suppressInactivePasswordSecretRef = hasConfiguredMatrixAccessTokenSource({
196
- cfg,
197
- env,
198
- accountId: normalizedAccountId
199
- });
200
- const fieldReadOptions = {
201
- env,
202
- config: cfg
203
- };
204
- const scopedEnv = resolveScopedMatrixEnvConfig(normalizedAccountId, env);
205
- const globalEnv = resolveGlobalMatrixEnvConfig(env);
206
- const accountField = (field) => readMatrixAccountConfigField(cfg, normalizedAccountId, account, field, {
207
- ...fieldReadOptions,
208
- suppressSecretRef: field === "password" ? suppressInactivePasswordSecretRef : void 0
209
- });
210
- const resolvedStrings = resolveMatrixAccountStringValues({
211
- accountId: normalizedAccountId,
212
- account: {
213
- homeserver: accountField("homeserver"),
214
- userId: accountField("userId"),
215
- accessToken: accountField("accessToken"),
216
- password: accountField("password"),
217
- deviceId: accountField("deviceId"),
218
- deviceName: accountField("deviceName")
219
- },
220
- scopedEnv,
221
- channel: {
222
- homeserver: readMatrixBaseConfigField(matrix, "homeserver", fieldReadOptions),
223
- userId: readMatrixBaseConfigField(matrix, "userId", fieldReadOptions),
224
- accessToken: readMatrixBaseConfigField(matrix, "accessToken", fieldReadOptions),
225
- password: readMatrixBaseConfigField(matrix, "password", {
226
- ...fieldReadOptions,
227
- suppressSecretRef: suppressInactivePasswordSecretRef
228
- }),
229
- deviceId: readMatrixBaseConfigField(matrix, "deviceId", fieldReadOptions),
230
- deviceName: readMatrixBaseConfigField(matrix, "deviceName", fieldReadOptions)
231
- },
232
- globalEnv
233
- });
234
- const initialSyncLimit = clampMatrixInitialSyncLimit(account.initialSyncLimit) ?? clampMatrixInitialSyncLimit(matrix.initialSyncLimit);
235
- const encryption = typeof account.encryption === "boolean" ? account.encryption : matrix.encryption ?? false;
236
- const allowPrivateNetwork = isPrivateNetworkOptInEnabled(account) || isPrivateNetworkOptInEnabled(matrix) ? true : void 0;
237
- return {
238
- homeserver: resolvedStrings.homeserver,
239
- userId: resolvedStrings.userId,
240
- accessToken: resolvedStrings.accessToken || void 0,
241
- password: resolvedStrings.password || void 0,
242
- deviceId: resolvedStrings.deviceId || void 0,
243
- deviceName: resolvedStrings.deviceName || void 0,
244
- initialSyncLimit,
245
- encryption,
246
- ...buildMatrixNetworkFields({
247
- allowPrivateNetwork,
248
- proxy: account.proxy ?? matrix.proxy
249
- })
250
- };
251
- }
252
- function resolveImplicitMatrixAccountId(cfg, env = process.env) {
253
- if (requiresExplicitMatrixDefaultAccount(cfg, env)) return null;
254
- return normalizeAccountId$1(resolveMatrixDefaultOrOnlyAccountId(cfg, env));
255
- }
256
- function resolveMatrixAuthContext(params) {
257
- const cfg = requireRuntimeConfig(params.cfg, "Matrix auth context");
258
- const env = params?.env ?? process.env;
259
- const requestedAccountId = params?.accountId?.trim();
260
- const explicitAccountId = normalizeOptionalAccountId$1(params?.accountId);
261
- if (requestedAccountId && !explicitAccountId) throw new Error(`Matrix account id "${requestedAccountId}" is invalid.`);
262
- const effectiveAccountId = explicitAccountId ?? resolveImplicitMatrixAccountId(cfg, env);
263
- 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>.");
264
- 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.`);
265
- const matrix = resolveMatrixBaseConfig(cfg);
266
- const account = findMatrixAccountConfig(cfg, effectiveAccountId);
267
- if (matrix.enabled === false || account?.enabled === false) throw new Error(`Matrix account "${effectiveAccountId}" is disabled.`);
268
- return {
269
- cfg,
270
- env,
271
- accountId: effectiveAccountId,
272
- resolved: resolveMatrixConfigForAccount(cfg, effectiveAccountId, env)
273
- };
274
- }
275
- async function resolveMatrixAuth(params) {
276
- 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.");
277
- const { cfg, env, accountId, resolved } = resolveMatrixAuthContext({
278
- cfg: params.cfg,
279
- env: params.env,
280
- accountId: params.accountId
281
- });
282
- const accessToken = await resolveConfiguredMatrixAuthSecretInput({
283
- cfg,
284
- env,
285
- accountId,
286
- field: "accessToken"
287
- }) ?? resolved.accessToken;
288
- const tokenAuthPassword = resolved.password;
289
- const homeserver = await resolveValidatedMatrixHomeserverUrl(resolved.homeserver, { dangerouslyAllowPrivateNetwork: resolved.allowPrivateNetwork });
290
- const { loadMatrixCredentials, credentialsMatchConfig } = await loadMatrixCredentialsReadDeps();
291
- const cached = loadMatrixCredentials(env, accountId);
292
- const cachedCredentials = cached && credentialsMatchConfig(cached, {
293
- homeserver,
294
- userId: resolved.userId || "",
295
- accessToken
296
- }) ? cached : null;
297
- if (accessToken) {
298
- let userId = resolved.userId;
299
- const hasMatchingCachedToken = cachedCredentials?.accessToken === accessToken;
300
- let knownDeviceId = hasMatchingCachedToken ? cachedCredentials?.deviceId || resolved.deviceId : resolved.deviceId;
301
- if (!userId) {
302
- const whoami = await fetchMatrixWhoamiIdentity({
303
- homeserver,
304
- accessToken,
305
- userId,
306
- ssrfPolicy: resolved.ssrfPolicy,
307
- dispatcherPolicy: resolved.dispatcherPolicy
308
- });
309
- const fetchedUserId = whoami.user_id?.trim();
310
- if (!fetchedUserId) throw new Error("Matrix whoami did not return user_id");
311
- userId = fetchedUserId;
312
- knownDeviceId = knownDeviceId || whoami.device_id?.trim() || resolved.deviceId;
313
- }
314
- if (!cachedCredentials || !hasMatchingCachedToken || cachedCredentials.userId !== userId || (cachedCredentials.deviceId || void 0) !== knownDeviceId) {
315
- const { saveMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
316
- await saveMatrixCredentials({
317
- homeserver,
318
- userId,
319
- accessToken,
320
- deviceId: knownDeviceId
321
- }, env, accountId);
322
- } else if (hasMatchingCachedToken) {
323
- const { touchMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
324
- await touchMatrixCredentials(env, accountId);
325
- }
326
- return {
327
- accountId,
328
- homeserver,
329
- userId,
330
- accessToken,
331
- password: tokenAuthPassword,
332
- deviceId: knownDeviceId,
333
- deviceName: resolved.deviceName,
334
- initialSyncLimit: resolved.initialSyncLimit,
335
- encryption: resolved.encryption,
336
- ...buildMatrixNetworkFields({
337
- allowPrivateNetwork: resolved.allowPrivateNetwork,
338
- dispatcherPolicy: resolved.dispatcherPolicy
339
- })
340
- };
341
- }
342
- if (cachedCredentials) {
343
- const { touchMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
344
- await touchMatrixCredentials(env, accountId);
345
- return {
346
- accountId,
347
- homeserver: cachedCredentials.homeserver,
348
- userId: cachedCredentials.userId,
349
- accessToken: cachedCredentials.accessToken,
350
- password: tokenAuthPassword,
351
- deviceId: cachedCredentials.deviceId || resolved.deviceId,
352
- deviceName: resolved.deviceName,
353
- initialSyncLimit: resolved.initialSyncLimit,
354
- encryption: resolved.encryption,
355
- ...buildMatrixNetworkFields({
356
- allowPrivateNetwork: resolved.allowPrivateNetwork,
357
- dispatcherPolicy: resolved.dispatcherPolicy
358
- })
359
- };
360
- }
361
- if (!resolved.userId) throw new Error("Matrix userId is required when no access token is configured (matrix.userId)");
362
- const password = await resolveConfiguredMatrixAuthSecretInput({
363
- cfg,
364
- env,
365
- accountId,
366
- field: "password"
367
- }) ?? resolved.password;
368
- if (!password) throw new Error("Matrix password is required when no access token is configured (matrix.password)");
369
- const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixAuthClientDeps();
370
- ensureMatrixSdkLoggingConfigured();
371
- const loginClient = new MatrixClient(homeserver, "", {
372
- ssrfPolicy: resolved.ssrfPolicy,
373
- dispatcherPolicy: resolved.dispatcherPolicy
374
- });
375
- const login = await retryMatrixAuthRequest("matrix auth login", async () => {
376
- return await loginClient.doRequest("POST", "/_matrix/client/v3/login", void 0, {
377
- type: "m.login.password",
378
- identifier: {
379
- type: "m.id.user",
380
- user: resolved.userId
381
- },
382
- password,
383
- device_id: resolved.deviceId,
384
- initial_device_display_name: resolved.deviceName ?? "OpenClaw Gateway"
385
- });
386
- });
387
- const loginAccessToken = login.access_token?.trim();
388
- if (!loginAccessToken) throw new Error("Matrix login did not return an access token");
389
- const auth = {
390
- accountId,
391
- homeserver,
392
- userId: login.user_id ?? resolved.userId,
393
- accessToken: loginAccessToken,
394
- password,
395
- deviceId: login.device_id ?? resolved.deviceId,
396
- deviceName: resolved.deviceName,
397
- initialSyncLimit: resolved.initialSyncLimit,
398
- encryption: resolved.encryption,
399
- ...buildMatrixNetworkFields({
400
- allowPrivateNetwork: resolved.allowPrivateNetwork,
401
- dispatcherPolicy: resolved.dispatcherPolicy
402
- })
403
- };
404
- const { saveMatrixCredentials } = await loadMatrixCredentialsWriteRuntime();
405
- await saveMatrixCredentials({
406
- homeserver: auth.homeserver,
407
- userId: auth.userId,
408
- accessToken: auth.accessToken,
409
- deviceId: auth.deviceId
410
- }, env, accountId);
411
- return auth;
412
- }
413
- async function backfillMatrixAuthDeviceIdAfterStartup(params) {
414
- const knownDeviceId = params.auth.deviceId?.trim();
415
- if (knownDeviceId) return knownDeviceId;
416
- if (isAbortSignalTriggered(params.abortSignal)) return;
417
- let whoami;
418
- try {
419
- whoami = await fetchMatrixWhoamiIdentity({
420
- homeserver: params.auth.homeserver,
421
- accessToken: params.auth.accessToken,
422
- userId: params.auth.userId,
423
- ssrfPolicy: params.auth.ssrfPolicy,
424
- dispatcherPolicy: params.auth.dispatcherPolicy,
425
- signal: params.abortSignal
426
- });
427
- } catch (err) {
428
- if (isAbortSignalTriggered(params.abortSignal)) return;
429
- throw err;
430
- }
431
- const deviceId = whoami.device_id?.trim();
432
- if (!deviceId) return;
433
- if (isAbortSignalTriggered(params.abortSignal)) return;
434
- const env = params.env ?? process.env;
435
- const { loadMatrixCredentials } = await loadMatrixCredentialsReadDeps();
436
- if (!credentialsMatchBackfillAuthLineage({
437
- stored: loadMatrixCredentials(env, params.auth.accountId),
438
- auth: params.auth
439
- })) return;
440
- if (!repairCurrentTokenStorageMetaDeviceId({
441
- homeserver: params.auth.homeserver,
442
- userId: params.auth.userId,
443
- accessToken: params.auth.accessToken,
444
- accountId: params.auth.accountId,
445
- deviceId,
446
- env: params.env
447
- })) throw new Error("Matrix deviceId backfill failed to repair current-token storage metadata");
448
- if (isAbortSignalTriggered(params.abortSignal)) return;
449
- return await (await loadMatrixCredentialsWriteRuntime()).saveBackfilledMatrixDeviceId({
450
- homeserver: params.auth.homeserver,
451
- userId: params.auth.userId,
452
- accessToken: params.auth.accessToken,
453
- deviceId
454
- }, env, params.auth.accountId) === "saved" ? deviceId : void 0;
455
- }
456
- //#endregion
457
- //#region extensions/matrix/src/matrix/startup-abort.ts
458
- function createMatrixStartupAbortError() {
459
- const error = /* @__PURE__ */ new Error("Matrix startup aborted");
460
- error.name = "AbortError";
461
- return error;
462
- }
463
- function throwIfMatrixStartupAborted(abortSignal) {
464
- if (abortSignal?.aborted === true) throw createMatrixStartupAbortError();
465
- }
466
- function isMatrixStartupAbortError(error) {
467
- return error instanceof Error && error.name === "AbortError";
468
- }
469
- async function awaitMatrixStartupWithAbort(promise, abortSignal) {
470
- if (!abortSignal) return await promise;
471
- if (abortSignal.aborted) throw createMatrixStartupAbortError();
472
- return await new Promise((resolve, reject) => {
473
- const onAbort = () => {
474
- abortSignal.removeEventListener("abort", onAbort);
475
- reject(createMatrixStartupAbortError());
476
- };
477
- abortSignal.addEventListener("abort", onAbort, { once: true });
478
- promise.then((value) => {
479
- abortSignal.removeEventListener("abort", onAbort);
480
- resolve(value);
481
- }, (error) => {
482
- abortSignal.removeEventListener("abort", onAbort);
483
- reject(toErrorObject(error, "Non-Error rejection"));
484
- });
485
- });
486
- }
487
- //#endregion
488
- //#region extensions/matrix/src/matrix/client/shared.ts
489
- var shared_exports = /* @__PURE__ */ __exportAll({
490
- acquireSharedMatrixClient: () => acquireSharedMatrixClient,
491
- releaseSharedClientInstance: () => releaseSharedClientInstance,
492
- removeSharedClientInstance: () => removeSharedClientInstance,
493
- resolveSharedMatrixClient: () => resolveSharedMatrixClient,
494
- stopSharedClient: () => stopSharedClient,
495
- stopSharedClientForAccount: () => stopSharedClientForAccount,
496
- stopSharedClientInstance: () => stopSharedClientInstance
497
- });
498
- const loadMatrixCreateClientDeps = createLazyRuntimeModule(() => import("./create-client-BmSU-q-D.js").then((n) => n.n).then((runtime) => ({ createMatrixClient: runtime.createMatrixClient })));
499
- const sharedClientStates = /* @__PURE__ */ new Map();
500
- const sharedClientPromises = /* @__PURE__ */ new Map();
501
- function serializeDispatcherPolicyKey(auth) {
502
- return JSON.stringify(auth.dispatcherPolicy ?? null);
503
- }
504
- function buildSharedClientKey(auth) {
505
- return [
506
- auth.homeserver,
507
- auth.userId,
508
- auth.accessToken,
509
- auth.encryption ? "e2ee" : "plain",
510
- auth.allowPrivateNetwork ? "private-net" : "strict-net",
511
- serializeDispatcherPolicyKey(auth),
512
- auth.accountId
513
- ].join("|");
514
- }
515
- async function createSharedMatrixClient(params) {
516
- const { createMatrixClient } = await loadMatrixCreateClientDeps();
517
- return {
518
- client: await createMatrixClient({
519
- homeserver: params.auth.homeserver,
520
- userId: params.auth.userId,
521
- accessToken: params.auth.accessToken,
522
- password: params.auth.password,
523
- deviceId: params.auth.deviceId,
524
- encryption: params.auth.encryption,
525
- localTimeoutMs: params.timeoutMs,
526
- initialSyncLimit: params.auth.initialSyncLimit,
527
- accountId: params.auth.accountId,
528
- allowPrivateNetwork: params.auth.allowPrivateNetwork,
529
- ssrfPolicy: params.auth.ssrfPolicy,
530
- dispatcherPolicy: params.auth.dispatcherPolicy
531
- }),
532
- key: buildSharedClientKey(params.auth),
533
- started: false,
534
- cryptoReady: false,
535
- startPromise: null,
536
- leases: 0
537
- };
538
- }
539
- function findSharedClientStateByInstance(client) {
540
- for (const state of sharedClientStates.values()) if (state.client === client) return state;
541
- return null;
542
- }
543
- function deleteSharedClientState(state) {
544
- sharedClientStates.delete(state.key);
545
- sharedClientPromises.delete(state.key);
546
- }
547
- async function ensureSharedClientStarted(params) {
548
- const waitForStart = async (startPromise) => {
549
- await awaitMatrixStartupWithAbort(startPromise, params.abortSignal);
550
- };
551
- if (params.state.started) return;
552
- if (params.state.startPromise) {
553
- await waitForStart(params.state.startPromise);
554
- return;
555
- }
556
- const guardedStart = (async () => {
557
- const client = params.state.client;
558
- if (params.encryption && !params.state.cryptoReady) try {
559
- const joinedRooms = await client.getJoinedRooms();
560
- if (client.crypto) {
561
- await client.crypto.prepare(joinedRooms);
562
- params.state.cryptoReady = true;
563
- }
564
- } catch (err) {
565
- LogService.warn("MatrixClientLite", "Failed to prepare crypto:", err);
566
- }
567
- await client.start({ abortSignal: params.abortSignal });
568
- params.state.started = true;
569
- })().finally(() => {
570
- if (params.state.startPromise === guardedStart) params.state.startPromise = null;
571
- });
572
- params.state.startPromise = guardedStart;
573
- await waitForStart(guardedStart);
574
- }
575
- async function resolveSharedMatrixClientState(params = {}) {
576
- const requestedAccountId = normalizeOptionalAccountId(params.accountId);
577
- if (params.auth && requestedAccountId && requestedAccountId !== params.auth.accountId) throw new Error(`Matrix shared client account mismatch: requested ${requestedAccountId}, auth resolved ${params.auth.accountId}`);
578
- const authContext = (() => {
579
- if (params.auth) return null;
580
- if (!params.cfg) throw new Error("Matrix shared client requires a resolved runtime config. Load and resolve config at the command or gateway boundary, then pass cfg through the runtime path.");
581
- return resolveMatrixAuthContext({
582
- cfg: params.cfg,
583
- env: params.env,
584
- accountId: params.accountId
585
- });
586
- })();
587
- const auth = params.auth ?? await resolveMatrixAuth({
588
- cfg: authContext?.cfg ?? params.cfg,
589
- env: authContext?.env ?? params.env,
590
- accountId: authContext?.accountId
591
- });
592
- const key = buildSharedClientKey(auth);
593
- const shouldStart = params.startClient !== false;
594
- const existingState = sharedClientStates.get(key);
595
- if (existingState) {
596
- if (shouldStart) await ensureSharedClientStarted({
597
- state: existingState,
598
- encryption: auth.encryption,
599
- abortSignal: params.abortSignal
600
- });
601
- return existingState;
602
- }
603
- const existingPromise = sharedClientPromises.get(key);
604
- if (existingPromise) {
605
- const pending = await existingPromise;
606
- if (shouldStart) await ensureSharedClientStarted({
607
- state: pending,
608
- encryption: auth.encryption,
609
- abortSignal: params.abortSignal
610
- });
611
- return pending;
612
- }
613
- const creationPromise = createSharedMatrixClient({
614
- auth,
615
- timeoutMs: params.timeoutMs
616
- });
617
- sharedClientPromises.set(key, creationPromise);
618
- try {
619
- const created = await creationPromise;
620
- sharedClientStates.set(key, created);
621
- if (shouldStart) await ensureSharedClientStarted({
622
- state: created,
623
- encryption: auth.encryption,
624
- abortSignal: params.abortSignal
625
- });
626
- return created;
627
- } finally {
628
- sharedClientPromises.delete(key);
629
- }
630
- }
631
- async function resolveSharedMatrixClient(params = {}) {
632
- return (await resolveSharedMatrixClientState(params)).client;
633
- }
634
- async function acquireSharedMatrixClient(params = {}) {
635
- const state = await resolveSharedMatrixClientState(params);
636
- state.leases += 1;
637
- return state.client;
638
- }
639
- function stopSharedClient() {
640
- for (const state of sharedClientStates.values()) state.client.stop();
641
- sharedClientStates.clear();
642
- sharedClientPromises.clear();
643
- }
644
- function stopSharedClientForAccount(auth) {
645
- const key = buildSharedClientKey(auth);
646
- const state = sharedClientStates.get(key);
647
- if (!state) return;
648
- state.client.stop();
649
- deleteSharedClientState(state);
650
- }
651
- function removeSharedClientInstance(client) {
652
- const state = findSharedClientStateByInstance(client);
653
- if (!state) return false;
654
- deleteSharedClientState(state);
655
- return true;
656
- }
657
- function stopSharedClientInstance(client) {
658
- if (!removeSharedClientInstance(client)) return;
659
- client.stop();
660
- }
661
- async function releaseSharedClientInstance(client, mode = "stop") {
662
- const state = findSharedClientStateByInstance(client);
663
- if (!state) return false;
664
- state.leases = Math.max(0, state.leases - 1);
665
- if (state.leases > 0) return false;
666
- deleteSharedClientState(state);
667
- if (mode === "persist") await client.stopAndPersist();
668
- else if (mode === "discard") client.stopWithoutPersist();
669
- else client.stop();
670
- return true;
671
- }
672
- //#endregion
673
- export { shared_exports as a, createMatrixStartupAbortError as c, backfillMatrixAuthDeviceIdAfterStartup as d, resolveMatrixAuth as f, resolveSharedMatrixClient as i, isMatrixStartupAbortError as l, resolveMatrixConfigForAccount as m, releaseSharedClientInstance as n, stopSharedClientForAccount as o, resolveMatrixAuthContext as p, removeSharedClientInstance as r, stopSharedClientInstance as s, acquireSharedMatrixClient as t, throwIfMatrixStartupAborted as u };