@kodelyth/matrix 2026.5.39 → 2026.5.42
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.
- package/CHANGELOG.md +321 -0
- package/SPEC-SUPPORT.md +116 -0
- package/api.ts +38 -0
- package/auth-presence.ts +56 -0
- package/channel-plugin-api.ts +3 -0
- package/cli-metadata.ts +11 -0
- package/contract-api.ts +17 -0
- package/dist/account-selection-Y50DNJ2l.js +158 -0
- package/dist/active-client-CmFdvPdO.js +20 -0
- package/dist/api.js +12 -0
- package/dist/approval-handler.runtime-BIi4fL0R.js +377 -0
- package/dist/approval-ids-BGHK7PnZ.js +7 -0
- package/dist/approval-reaction-auth-CL0-nCNV.js +27 -0
- package/dist/approval-reactions-nDm2x-K5.js +162 -0
- package/dist/async-lock-SsmtFXtt.js +19 -0
- package/dist/auth-presence.js +26 -0
- package/dist/backup-health-3BHbHxyd.js +60 -0
- package/dist/channel-C0kCyTNB.js +1380 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-CdrdEN-0.js +250 -0
- package/dist/cli-FtY6Nuzw.js +1338 -0
- package/dist/cli-metadata-Dkwua7CB.js +22 -0
- package/dist/cli-metadata.js +2 -0
- package/dist/client-BnohYygh.js +25 -0
- package/dist/client-PhrTwuC4.js +30 -0
- package/dist/client-bootstrap-Mcj8ChJ5.js +114 -0
- package/dist/config-paths-DVvt6vM3.js +114 -0
- package/dist/config-schema-BMGOlhdI.js +308 -0
- package/dist/config-secret-input.runtime-Dv_4Br_f.js +2 -0
- package/dist/contract-api.js +8 -0
- package/dist/create-client-J0htTaRj.js +64 -0
- package/dist/credentials-B7GsBbgQ.js +56 -0
- package/dist/credentials-read-8fE4qoWs.js +112 -0
- package/dist/credentials-write.runtime-BibplB4Y.js +17 -0
- package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
- package/dist/crypto-runtime-1pKW4O2F.js +1214 -0
- package/dist/deps-DVpDS81G.js +208 -0
- package/dist/device-health-Ct2wDSPG.js +16 -0
- package/dist/directory-live-i3T8uORc.js +150 -0
- package/dist/doctor-contract-BLzYHl_9.js +246 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/doctor-diR5gE7D.js +153 -0
- package/dist/draft-stream-HpPJ_VJt.js +143 -0
- package/dist/encryption-guidance-BNEgckrZ.js +15 -0
- package/dist/env-auth-UFiTGkDM.js +63 -0
- package/dist/env-vars-EQKQv-FE.js +63 -0
- package/dist/errors-BETj3zr9.js +17 -0
- package/dist/exec-approval-resolver-BxPorU_t.js +15 -0
- package/dist/helper-api.js +4 -0
- package/dist/http-client-DoQgbQsU.js +331 -0
- package/dist/index.js +46 -0
- package/dist/legacy-crypto-inspector-zK0hDCbt.js +41 -0
- package/dist/legacy-crypto-restore-DSFIXuDo.js +85 -0
- package/dist/logging-Df7aPD1z.js +99 -0
- package/dist/matrix-migration.runtime-BNoT1Prt.js +525 -0
- package/dist/media-text-ZhGA8Pcs.js +146 -0
- package/dist/messages-CRA9WGg0.js +140 -0
- package/dist/migration-snapshot-backup-BR-xD7Ew.js +69 -0
- package/dist/migration-snapshot.runtime-BLcy_Nvw.js +2 -0
- package/dist/monitor-DQm7_13y.js +4331 -0
- package/dist/plugin-entry.handlers.runtime.js +51 -0
- package/dist/probe.runtime-CjJS53Kz.js +3 -0
- package/dist/profile-update-DqkPgZ1P.js +68 -0
- package/dist/reaction-common-CmVLzP-u.js +71 -0
- package/dist/reaction-events-D0nUJuZV.js +121 -0
- package/dist/record-shared-DGvSFn5M.js +2 -0
- package/dist/resolve-targets-ChECUzD2.js +140 -0
- package/dist/resolver.runtime-hdY3n0GO.js +5 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/route-xRKj_ESW.js +161 -0
- package/dist/runtime-B-Fyrmxo.js +8 -0
- package/dist/runtime-api-BYXXkxq2.js +24 -0
- package/dist/runtime-api.js +25 -0
- package/dist/runtime-heavy-api.js +3 -0
- package/dist/runtime-lwTSy9Yt.js +6 -0
- package/dist/runtime-setter-api.js +2 -0
- package/dist/sdk-Jhq7mLtD.js +1704 -0
- package/dist/secret-contract-DEMcDsjl.js +120 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/send-CJunc6QM.js +1517 -0
- package/dist/setup-bootstrap-rJ0qZWPe.js +62 -0
- package/dist/setup-core-BEYoXF3J.js +677 -0
- package/dist/setup-entry.js +19 -0
- package/dist/setup-plugin-api.js +43 -0
- package/dist/setup-surface-c28ON6jq.js +537 -0
- package/dist/shared-D6MFMnpG.js +642 -0
- package/dist/startup-abort-B2J3MU_h.js +109 -0
- package/dist/startup-verification-CkD4Cwce.js +132 -0
- package/dist/storage-nyO0DOFE.js +281 -0
- package/dist/storage-paths-BTAketfg.js +52 -0
- package/dist/subagent-hooks-api-Dr_xnMRG.js +170 -0
- package/dist/subagent-hooks-api.js +2 -0
- package/dist/sync-state-Bx0gPaGA.js +12 -0
- package/dist/target-ids-Bsazo8si.js +77 -0
- package/dist/test-api.js +4 -0
- package/dist/thread-binding-api-IGU0-L70.js +17 -0
- package/dist/thread-binding-api.js +2 -0
- package/dist/thread-bindings-FjAZmDUP.js +352 -0
- package/dist/thread-bindings-runtime.js +2 -0
- package/dist/thread-bindings-shared-fvfP7jVs.js +97 -0
- package/dist/timeout-abort-signal-DpSHDHhR.js +2 -0
- package/dist/tool-actions.runtime-Cbo7YcYZ.js +532 -0
- package/dist/url-validation-DlrXNjAE.js +36 -0
- package/dist/verification-7tDPRpJU.js +345 -0
- package/doctor-contract-api.ts +1 -0
- package/helper-api.ts +3 -0
- package/index.ts +55 -0
- package/klaw.plugin.json +3 -891
- package/package.json +4 -4
- package/plugin-entry.handlers.runtime.ts +1 -0
- package/runtime-api.ts +72 -0
- package/runtime-heavy-api.ts +1 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +5 -0
- package/setup-entry.ts +17 -0
- package/setup-plugin-api.ts +3 -0
- package/src/account-selection.ts +223 -0
- package/src/actions.ts +346 -0
- package/src/approval-auth.ts +25 -0
- package/src/approval-handler.runtime.ts +592 -0
- package/src/approval-ids.ts +6 -0
- package/src/approval-native.ts +345 -0
- package/src/approval-reaction-auth.ts +45 -0
- package/src/approval-reactions.ts +313 -0
- package/src/auth-precedence.ts +61 -0
- package/src/channel-account-paths.ts +97 -0
- package/src/channel.runtime.ts +17 -0
- package/src/channel.setup.ts +48 -0
- package/src/channel.ts +667 -0
- package/src/cli-metadata.ts +19 -0
- package/src/cli.ts +2298 -0
- package/src/config-adapter.ts +41 -0
- package/src/config-schema.ts +159 -0
- package/src/config-ui-hints.ts +56 -0
- package/src/directory-live.ts +238 -0
- package/src/doctor-contract.ts +287 -0
- package/src/doctor.ts +262 -0
- package/src/env-vars.ts +92 -0
- package/src/exec-approval-resolver.ts +23 -0
- package/src/exec-approvals.ts +287 -0
- package/src/group-mentions.ts +41 -0
- package/src/legacy-crypto-inspector-availability.ts +60 -0
- package/src/legacy-crypto.ts +531 -0
- package/src/legacy-state.ts +156 -0
- package/src/matrix/account-config.ts +175 -0
- package/src/matrix/accounts.ts +194 -0
- package/src/matrix/actions/client.ts +31 -0
- package/src/matrix/actions/devices.ts +34 -0
- package/src/matrix/actions/limits.ts +6 -0
- package/src/matrix/actions/messages.ts +129 -0
- package/src/matrix/actions/pins.ts +63 -0
- package/src/matrix/actions/polls.ts +109 -0
- package/src/matrix/actions/profile.ts +37 -0
- package/src/matrix/actions/reactions.ts +59 -0
- package/src/matrix/actions/room.ts +71 -0
- package/src/matrix/actions/summary.ts +88 -0
- package/src/matrix/actions/types.ts +63 -0
- package/src/matrix/actions/verification.ts +589 -0
- package/src/matrix/actions.ts +37 -0
- package/src/matrix/active-client.ts +26 -0
- package/src/matrix/async-lock.ts +18 -0
- package/src/matrix/backup-health.ts +124 -0
- package/src/matrix/client/config-runtime-api.ts +9 -0
- package/src/matrix/client/config-secret-input.runtime.ts +1 -0
- package/src/matrix/client/config.ts +853 -0
- package/src/matrix/client/create-client.ts +105 -0
- package/src/matrix/client/env-auth.ts +95 -0
- package/src/matrix/client/file-sync-store.ts +289 -0
- package/src/matrix/client/logging.ts +140 -0
- package/src/matrix/client/migration-snapshot.runtime.ts +1 -0
- package/src/matrix/client/private-network-host.ts +1 -0
- package/src/matrix/client/runtime.ts +4 -0
- package/src/matrix/client/shared.ts +316 -0
- package/src/matrix/client/storage.ts +543 -0
- package/src/matrix/client/types.ts +50 -0
- package/src/matrix/client/url-validation.ts +73 -0
- package/src/matrix/client-bootstrap.ts +173 -0
- package/src/matrix/client.ts +23 -0
- package/src/matrix/config-paths.ts +31 -0
- package/src/matrix/config-update.ts +292 -0
- package/src/matrix/credentials-read.ts +208 -0
- package/src/matrix/credentials-write.runtime.ts +35 -0
- package/src/matrix/credentials.ts +95 -0
- package/src/matrix/deps.ts +309 -0
- package/src/matrix/device-health.ts +29 -0
- package/src/matrix/direct-management.ts +349 -0
- package/src/matrix/direct-room.ts +128 -0
- package/src/matrix/draft-stream.ts +225 -0
- package/src/matrix/encryption-guidance.ts +24 -0
- package/src/matrix/errors.ts +21 -0
- package/src/matrix/format.ts +426 -0
- package/src/matrix/legacy-crypto-inspector.ts +95 -0
- package/src/matrix/media-errors.ts +20 -0
- package/src/matrix/media-text.ts +162 -0
- package/src/matrix/monitor/access-state.ts +145 -0
- package/src/matrix/monitor/ack-config.ts +27 -0
- package/src/matrix/monitor/allowlist.ts +89 -0
- package/src/matrix/monitor/auto-join.ts +86 -0
- package/src/matrix/monitor/config.ts +569 -0
- package/src/matrix/monitor/context-summary.ts +43 -0
- package/src/matrix/monitor/direct.ts +296 -0
- package/src/matrix/monitor/events.ts +397 -0
- package/src/matrix/monitor/handler.ts +2266 -0
- package/src/matrix/monitor/inbound-dedupe.ts +267 -0
- package/src/matrix/monitor/index.ts +540 -0
- package/src/matrix/monitor/legacy-crypto-restore.ts +139 -0
- package/src/matrix/monitor/location.ts +108 -0
- package/src/matrix/monitor/media.ts +119 -0
- package/src/matrix/monitor/mentions.ts +256 -0
- package/src/matrix/monitor/reaction-events.ts +197 -0
- package/src/matrix/monitor/recent-invite.ts +30 -0
- package/src/matrix/monitor/replies.ts +136 -0
- package/src/matrix/monitor/reply-context.ts +92 -0
- package/src/matrix/monitor/room-history.ts +301 -0
- package/src/matrix/monitor/room-info.ts +126 -0
- package/src/matrix/monitor/rooms.ts +52 -0
- package/src/matrix/monitor/route.ts +179 -0
- package/src/matrix/monitor/runtime-api.ts +28 -0
- package/src/matrix/monitor/startup-verification.ts +237 -0
- package/src/matrix/monitor/startup.ts +218 -0
- package/src/matrix/monitor/status.ts +120 -0
- package/src/matrix/monitor/sync-lifecycle.ts +91 -0
- package/src/matrix/monitor/task-runner.ts +38 -0
- package/src/matrix/monitor/test-events.ts +21 -0
- package/src/matrix/monitor/thread-context.ts +108 -0
- package/src/matrix/monitor/threads.ts +85 -0
- package/src/matrix/monitor/types.ts +30 -0
- package/src/matrix/monitor/verification-events.ts +643 -0
- package/src/matrix/monitor/verification-utils.ts +46 -0
- package/src/matrix/outbound-media-runtime.ts +1 -0
- package/src/matrix/poll-summary.ts +110 -0
- package/src/matrix/poll-types.ts +429 -0
- package/src/matrix/probe.runtime.ts +4 -0
- package/src/matrix/probe.ts +97 -0
- package/src/matrix/profile.ts +184 -0
- package/src/matrix/reaction-common.ts +147 -0
- package/src/matrix/sdk/crypto-bootstrap.ts +438 -0
- package/src/matrix/sdk/crypto-facade.ts +242 -0
- package/src/matrix/sdk/crypto-node.runtime.ts +17 -0
- package/src/matrix/sdk/crypto-runtime.ts +14 -0
- package/src/matrix/sdk/decrypt-bridge.ts +410 -0
- package/src/matrix/sdk/event-helpers.ts +83 -0
- package/src/matrix/sdk/http-client.ts +87 -0
- package/src/matrix/sdk/idb-persistence-lock.ts +51 -0
- package/src/matrix/sdk/idb-persistence.ts +288 -0
- package/src/matrix/sdk/logger.ts +108 -0
- package/src/matrix/sdk/read-response-with-limit.ts +19 -0
- package/src/matrix/sdk/recovery-key-store.ts +453 -0
- package/src/matrix/sdk/timeout-abort-signal.ts +1 -0
- package/src/matrix/sdk/transport-runtime-api.ts +18 -0
- package/src/matrix/sdk/transport.ts +352 -0
- package/src/matrix/sdk/types.ts +245 -0
- package/src/matrix/sdk/verification-manager.ts +795 -0
- package/src/matrix/sdk/verification-status.ts +23 -0
- package/src/matrix/sdk.ts +2152 -0
- package/src/matrix/send/client.ts +93 -0
- package/src/matrix/send/formatting.ts +189 -0
- package/src/matrix/send/media.ts +244 -0
- package/src/matrix/send/targets.ts +104 -0
- package/src/matrix/send/types.ts +131 -0
- package/src/matrix/send.ts +660 -0
- package/src/matrix/session-store-metadata.ts +108 -0
- package/src/matrix/startup-abort.ts +44 -0
- package/src/matrix/subagent-hooks.ts +308 -0
- package/src/matrix/sync-state.ts +27 -0
- package/src/matrix/target-ids.ts +79 -0
- package/src/matrix/thread-bindings-shared.ts +206 -0
- package/src/matrix/thread-bindings.ts +580 -0
- package/src/matrix-migration.runtime.ts +9 -0
- package/src/migration-config.ts +243 -0
- package/src/migration-snapshot-backup.ts +116 -0
- package/src/migration-snapshot.ts +53 -0
- package/src/onboarding.ts +775 -0
- package/src/outbound.ts +248 -0
- package/src/plugin-entry.runtime.js +115 -0
- package/src/plugin-entry.runtime.ts +70 -0
- package/src/profile-update.ts +71 -0
- package/src/record-shared.ts +3 -0
- package/src/resolve-targets.ts +175 -0
- package/src/resolver.runtime.ts +5 -0
- package/src/resolver.ts +21 -0
- package/src/runtime-api.ts +106 -0
- package/src/runtime.ts +13 -0
- package/src/secret-contract.ts +174 -0
- package/src/session-route.ts +126 -0
- package/src/setup-bootstrap.ts +102 -0
- package/src/setup-config.ts +222 -0
- package/src/setup-contract.ts +90 -0
- package/src/setup-core.ts +146 -0
- package/src/setup-dm-policy.ts +15 -0
- package/src/setup-surface.ts +4 -0
- package/src/startup-maintenance.ts +114 -0
- package/src/storage-paths.ts +92 -0
- package/src/thread-binding-api.ts +23 -0
- package/src/tool-actions.runtime.ts +1 -0
- package/src/tool-actions.ts +498 -0
- package/src/types.ts +257 -0
- package/subagent-hooks-api.ts +31 -0
- package/test-api.ts +21 -0
- package/thread-binding-api.ts +4 -0
- package/thread-bindings-runtime.ts +4 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/auth-presence.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/cli-metadata.js +0 -7
- package/contract-api.js +0 -7
- package/doctor-contract-api.js +0 -7
- package/helper-api.js +0 -7
- package/index.js +0 -7
- package/plugin-entry.handlers.runtime.js +0 -7
- package/runtime-api.js +0 -7
- package/runtime-heavy-api.js +0 -7
- package/runtime-setter-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-entry.js +0 -7
- package/setup-plugin-api.js +0 -7
- package/subagent-hooks-api.js +0 -7
- package/test-api.js +0 -7
- package/thread-binding-api.js +0 -7
- package/thread-bindings-runtime.js +0 -7
|
@@ -0,0 +1,677 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { a as resolveMatrixDefaultOrOnlyAccountId, o as resolveMatrixAccountStringValues, r as resolveConfiguredMatrixAccountIds } from "./account-selection-Y50DNJ2l.js";
|
|
3
|
+
import { c as resolveMatrixAccountConfig, i as findMatrixAccountConfig, l as resolveMatrixBaseConfig, n as resolveMatrixConfigPath$1, r as shouldStoreMatrixAccountAtTopLevel, t as resolveMatrixConfigFieldPath } from "./config-paths-DVvt6vM3.js";
|
|
4
|
+
import { i as resolveScopedMatrixEnvConfig, n as resolveGlobalMatrixEnvConfig, r as resolveMatrixEnvAuthReadiness } from "./env-auth-UFiTGkDM.js";
|
|
5
|
+
import { i as loadMatrixCredentials, n as credentialsMatchConfig } from "./credentials-read-8fE4qoWs.js";
|
|
6
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "klaw/plugin-sdk/account-id";
|
|
7
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
import { hasConfiguredSecretInput } from "klaw/plugin-sdk/secret-input-runtime";
|
|
9
|
+
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, normalizeAccountId as normalizeAccountId$1 } from "klaw/plugin-sdk/routing";
|
|
10
|
+
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$2, addWildcardAllowFrom, applyAccountNameToChannelSection, normalizeAccountId as normalizeAccountId$2, normalizeAllowFromEntries, normalizeSecretInputString, prepareScopedSetupConfig } from "klaw/plugin-sdk/setup";
|
|
11
|
+
import { coerceSecretRef as coerceSecretRef$1 } from "klaw/plugin-sdk/secret-ref-runtime";
|
|
12
|
+
//#region extensions/matrix/src/matrix/accounts.ts
|
|
13
|
+
function clean(value) {
|
|
14
|
+
return normalizeOptionalString(value) ?? "";
|
|
15
|
+
}
|
|
16
|
+
function resolveMatrixAccountAuthView(params) {
|
|
17
|
+
const normalizedAccountId = normalizeAccountId(params.accountId);
|
|
18
|
+
const matrix = resolveMatrixBaseConfig(params.cfg);
|
|
19
|
+
const account = findMatrixAccountConfig(params.cfg, normalizedAccountId) ?? {};
|
|
20
|
+
const resolvedStrings = resolveMatrixAccountStringValues({
|
|
21
|
+
accountId: normalizedAccountId,
|
|
22
|
+
account: {
|
|
23
|
+
homeserver: clean(account.homeserver),
|
|
24
|
+
userId: clean(account.userId),
|
|
25
|
+
accessToken: typeof account.accessToken === "string" ? clean(account.accessToken) : "",
|
|
26
|
+
password: typeof account.password === "string" ? clean(account.password) : "",
|
|
27
|
+
deviceId: clean(account.deviceId),
|
|
28
|
+
deviceName: clean(account.deviceName)
|
|
29
|
+
},
|
|
30
|
+
scopedEnv: resolveScopedMatrixEnvConfig(normalizedAccountId, params.env),
|
|
31
|
+
channel: {
|
|
32
|
+
homeserver: clean(matrix.homeserver),
|
|
33
|
+
userId: clean(matrix.userId),
|
|
34
|
+
accessToken: typeof matrix.accessToken === "string" ? clean(matrix.accessToken) : "",
|
|
35
|
+
password: typeof matrix.password === "string" ? clean(matrix.password) : "",
|
|
36
|
+
deviceId: clean(matrix.deviceId),
|
|
37
|
+
deviceName: clean(matrix.deviceName)
|
|
38
|
+
},
|
|
39
|
+
globalEnv: resolveGlobalMatrixEnvConfig(params.env)
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
homeserver: resolvedStrings.homeserver,
|
|
43
|
+
userId: resolvedStrings.userId,
|
|
44
|
+
accessToken: resolvedStrings.accessToken || void 0,
|
|
45
|
+
password: resolvedStrings.password || void 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function resolveMatrixAccountUserId(params) {
|
|
49
|
+
const env = params.env ?? process.env;
|
|
50
|
+
const authView = resolveMatrixAccountAuthView({
|
|
51
|
+
cfg: params.cfg,
|
|
52
|
+
accountId: params.accountId,
|
|
53
|
+
env
|
|
54
|
+
});
|
|
55
|
+
const configuredUserId = authView.userId.trim();
|
|
56
|
+
if (configuredUserId) return configuredUserId;
|
|
57
|
+
const stored = loadMatrixCredentials(env, params.accountId);
|
|
58
|
+
if (!stored) return null;
|
|
59
|
+
if (authView.homeserver && stored.homeserver !== authView.homeserver) return null;
|
|
60
|
+
if (authView.accessToken && stored.accessToken !== authView.accessToken) return null;
|
|
61
|
+
return stored.userId.trim() || null;
|
|
62
|
+
}
|
|
63
|
+
function listMatrixAccountIds(cfg) {
|
|
64
|
+
const ids = resolveConfiguredMatrixAccountIds(cfg, process.env);
|
|
65
|
+
return ids.length > 0 ? ids : [DEFAULT_ACCOUNT_ID];
|
|
66
|
+
}
|
|
67
|
+
function resolveDefaultMatrixAccountId(cfg) {
|
|
68
|
+
return normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(cfg));
|
|
69
|
+
}
|
|
70
|
+
function resolveConfiguredMatrixBotUserIds(params) {
|
|
71
|
+
const env = params.env ?? process.env;
|
|
72
|
+
const currentAccountId = normalizeAccountId(params.accountId);
|
|
73
|
+
const accountIds = new Set(resolveConfiguredMatrixAccountIds(params.cfg, env));
|
|
74
|
+
if (resolveMatrixAccount({
|
|
75
|
+
cfg: params.cfg,
|
|
76
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
77
|
+
env
|
|
78
|
+
}).configured) accountIds.add(DEFAULT_ACCOUNT_ID);
|
|
79
|
+
const ids = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const accountId of accountIds) {
|
|
81
|
+
if (normalizeAccountId(accountId) === currentAccountId) continue;
|
|
82
|
+
if (!resolveMatrixAccount({
|
|
83
|
+
cfg: params.cfg,
|
|
84
|
+
accountId,
|
|
85
|
+
env
|
|
86
|
+
}).configured) continue;
|
|
87
|
+
const userId = resolveMatrixAccountUserId({
|
|
88
|
+
cfg: params.cfg,
|
|
89
|
+
accountId,
|
|
90
|
+
env
|
|
91
|
+
});
|
|
92
|
+
if (userId) ids.add(userId);
|
|
93
|
+
}
|
|
94
|
+
return ids;
|
|
95
|
+
}
|
|
96
|
+
function resolveMatrixAccount(params) {
|
|
97
|
+
const env = params.env ?? process.env;
|
|
98
|
+
const accountId = normalizeAccountId(params.accountId ?? resolveDefaultMatrixAccountId(params.cfg));
|
|
99
|
+
const matrixBase = resolveMatrixBaseConfig(params.cfg);
|
|
100
|
+
const base = resolveMatrixAccountConfig({
|
|
101
|
+
cfg: params.cfg,
|
|
102
|
+
accountId,
|
|
103
|
+
env
|
|
104
|
+
});
|
|
105
|
+
const explicitAuthConfig = accountId === DEFAULT_ACCOUNT_ID ? base : findMatrixAccountConfig(params.cfg, accountId) ?? {};
|
|
106
|
+
const enabled = base.enabled !== false && matrixBase.enabled !== false;
|
|
107
|
+
const authView = resolveMatrixAccountAuthView({
|
|
108
|
+
cfg: params.cfg,
|
|
109
|
+
accountId,
|
|
110
|
+
env
|
|
111
|
+
});
|
|
112
|
+
const hasHomeserver = Boolean(authView.homeserver);
|
|
113
|
+
const hasUserId = Boolean(authView.userId);
|
|
114
|
+
const hasAccessToken = Boolean(authView.accessToken) || hasConfiguredSecretInput(explicitAuthConfig.accessToken);
|
|
115
|
+
const hasPassword = Boolean(authView.password);
|
|
116
|
+
const hasPasswordAuth = hasUserId && (hasPassword || hasConfiguredSecretInput(explicitAuthConfig.password));
|
|
117
|
+
const stored = loadMatrixCredentials(env, accountId);
|
|
118
|
+
const hasStored = stored && authView.homeserver ? credentialsMatchConfig(stored, {
|
|
119
|
+
homeserver: authView.homeserver,
|
|
120
|
+
userId: authView.userId || ""
|
|
121
|
+
}) : false;
|
|
122
|
+
const configured = hasHomeserver && (hasAccessToken || hasPasswordAuth || hasStored);
|
|
123
|
+
return {
|
|
124
|
+
accountId,
|
|
125
|
+
enabled,
|
|
126
|
+
name: normalizeOptionalString(base.name),
|
|
127
|
+
configured,
|
|
128
|
+
homeserver: authView.homeserver || void 0,
|
|
129
|
+
userId: authView.userId || void 0,
|
|
130
|
+
config: base
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region extensions/matrix/src/setup-contract.ts
|
|
135
|
+
const matrixSingleAccountKeysToMove = [
|
|
136
|
+
"deviceId",
|
|
137
|
+
"avatarUrl",
|
|
138
|
+
"initialSyncLimit",
|
|
139
|
+
"encryption",
|
|
140
|
+
"allowlistOnly",
|
|
141
|
+
"dangerouslyAllowNameMatching",
|
|
142
|
+
"allowBots",
|
|
143
|
+
"blockStreaming",
|
|
144
|
+
"replyToMode",
|
|
145
|
+
"threadReplies",
|
|
146
|
+
"textChunkLimit",
|
|
147
|
+
"chunkMode",
|
|
148
|
+
"responsePrefix",
|
|
149
|
+
"ackReaction",
|
|
150
|
+
"ackReactionScope",
|
|
151
|
+
"reactionNotifications",
|
|
152
|
+
"threadBindings",
|
|
153
|
+
"startupVerification",
|
|
154
|
+
"startupVerificationCooldownHours",
|
|
155
|
+
"mediaMaxMb",
|
|
156
|
+
"autoJoin",
|
|
157
|
+
"autoJoinAllowlist",
|
|
158
|
+
"dm",
|
|
159
|
+
"groups",
|
|
160
|
+
"rooms",
|
|
161
|
+
"actions"
|
|
162
|
+
];
|
|
163
|
+
const matrixNamedAccountPromotionKeys = [
|
|
164
|
+
"name",
|
|
165
|
+
"homeserver",
|
|
166
|
+
"userId",
|
|
167
|
+
"accessToken",
|
|
168
|
+
"password",
|
|
169
|
+
"deviceId",
|
|
170
|
+
"deviceName",
|
|
171
|
+
"avatarUrl",
|
|
172
|
+
"initialSyncLimit",
|
|
173
|
+
"encryption"
|
|
174
|
+
];
|
|
175
|
+
const singleAccountKeysToMove = [...matrixSingleAccountKeysToMove];
|
|
176
|
+
const namedAccountPromotionKeys = [...matrixNamedAccountPromotionKeys];
|
|
177
|
+
function resolveSingleAccountPromotionTarget(params) {
|
|
178
|
+
const accounts = typeof params.channel.accounts === "object" && params.channel.accounts ? params.channel.accounts : {};
|
|
179
|
+
const normalizedDefaultAccount = typeof params.channel.defaultAccount === "string" && params.channel.defaultAccount.trim() ? normalizeAccountId$1(params.channel.defaultAccount) : void 0;
|
|
180
|
+
const matchedAccountId = normalizedDefaultAccount ? Object.entries(accounts).find(([accountId, value]) => accountId && value && typeof value === "object" && normalizeAccountId$1(accountId) === normalizedDefaultAccount)?.[0] : void 0;
|
|
181
|
+
if (matchedAccountId) return matchedAccountId;
|
|
182
|
+
if (normalizedDefaultAccount) return DEFAULT_ACCOUNT_ID$1;
|
|
183
|
+
const namedAccounts = Object.entries(accounts).filter(([accountId, value]) => accountId && typeof value === "object" && value);
|
|
184
|
+
if (namedAccounts.length === 1) return namedAccounts[0][0];
|
|
185
|
+
if (namedAccounts.length > 1 && accounts[DEFAULT_ACCOUNT_ID$1] && typeof accounts[DEFAULT_ACCOUNT_ID$1] === "object") return DEFAULT_ACCOUNT_ID$1;
|
|
186
|
+
return DEFAULT_ACCOUNT_ID$1;
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region extensions/matrix/src/matrix/config-update.ts
|
|
190
|
+
var config_update_exports = /* @__PURE__ */ __exportAll({
|
|
191
|
+
resolveMatrixConfigFieldPath: () => resolveMatrixConfigFieldPath,
|
|
192
|
+
resolveMatrixConfigPath: () => resolveMatrixConfigPath,
|
|
193
|
+
shouldStoreMatrixAccountAtTopLevel: () => shouldStoreMatrixAccountAtTopLevel,
|
|
194
|
+
updateMatrixAccountConfig: () => updateMatrixAccountConfig
|
|
195
|
+
});
|
|
196
|
+
const resolveMatrixConfigPath = resolveMatrixConfigPath$1;
|
|
197
|
+
function applyNullableStringField(target, key, value) {
|
|
198
|
+
if (value === void 0) return;
|
|
199
|
+
if (value === null) {
|
|
200
|
+
delete target[key];
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const trimmed = value.trim();
|
|
204
|
+
if (!trimmed) {
|
|
205
|
+
delete target[key];
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
target[key] = trimmed;
|
|
209
|
+
}
|
|
210
|
+
function applyNullableSecretInputField(target, key, value, defaults) {
|
|
211
|
+
if (value === void 0) return;
|
|
212
|
+
if (value === null) {
|
|
213
|
+
delete target[key];
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (typeof value === "string") {
|
|
217
|
+
const normalized = normalizeSecretInputString(value);
|
|
218
|
+
if (normalized) target[key] = normalized;
|
|
219
|
+
else delete target[key];
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const ref = coerceSecretRef$1(value, defaults);
|
|
223
|
+
if (!ref) throw new Error(`Invalid Matrix ${key} SecretInput.`);
|
|
224
|
+
target[key] = ref;
|
|
225
|
+
}
|
|
226
|
+
function cloneMatrixDmConfig(dm) {
|
|
227
|
+
if (!dm) return dm;
|
|
228
|
+
return {
|
|
229
|
+
...dm,
|
|
230
|
+
...dm.allowFrom ? { allowFrom: [...dm.allowFrom] } : {}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function cloneMatrixRoomMap(rooms) {
|
|
234
|
+
if (!rooms) return rooms;
|
|
235
|
+
const clonedRoomEntries = [];
|
|
236
|
+
for (const [roomId, roomCfg] of Object.entries(rooms)) clonedRoomEntries.push([roomId, roomCfg ? { ...roomCfg } : roomCfg]);
|
|
237
|
+
return Object.fromEntries(clonedRoomEntries);
|
|
238
|
+
}
|
|
239
|
+
function applyNullableArrayField(target, key, value) {
|
|
240
|
+
if (value === void 0) return;
|
|
241
|
+
if (value === null) {
|
|
242
|
+
delete target[key];
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
target[key] = [...value];
|
|
246
|
+
}
|
|
247
|
+
function updateMatrixAccountConfig(cfg, accountId, patch) {
|
|
248
|
+
const matrix = cfg.channels?.matrix ?? {};
|
|
249
|
+
const normalizedAccountId = normalizeAccountId(accountId);
|
|
250
|
+
const nextAccount = { ...findMatrixAccountConfig(cfg, normalizedAccountId) ?? (normalizedAccountId === DEFAULT_ACCOUNT_ID ? matrix : {}) };
|
|
251
|
+
if (patch.name !== void 0) if (patch.name === null) delete nextAccount.name;
|
|
252
|
+
else {
|
|
253
|
+
const trimmed = patch.name.trim();
|
|
254
|
+
if (trimmed) nextAccount.name = trimmed;
|
|
255
|
+
else delete nextAccount.name;
|
|
256
|
+
}
|
|
257
|
+
if (typeof patch.enabled === "boolean") nextAccount.enabled = patch.enabled;
|
|
258
|
+
else if (typeof nextAccount.enabled !== "boolean") nextAccount.enabled = true;
|
|
259
|
+
applyNullableStringField(nextAccount, "homeserver", patch.homeserver);
|
|
260
|
+
applyNullableStringField(nextAccount, "proxy", patch.proxy);
|
|
261
|
+
applyNullableStringField(nextAccount, "userId", patch.userId);
|
|
262
|
+
applyNullableSecretInputField(nextAccount, "accessToken", patch.accessToken, cfg.secrets?.defaults);
|
|
263
|
+
applyNullableSecretInputField(nextAccount, "password", patch.password, cfg.secrets?.defaults);
|
|
264
|
+
applyNullableStringField(nextAccount, "deviceId", patch.deviceId);
|
|
265
|
+
applyNullableStringField(nextAccount, "deviceName", patch.deviceName);
|
|
266
|
+
applyNullableStringField(nextAccount, "avatarUrl", patch.avatarUrl);
|
|
267
|
+
if (patch.allowPrivateNetwork !== void 0) {
|
|
268
|
+
const nextNetwork = nextAccount.network && typeof nextAccount.network === "object" ? { ...nextAccount.network } : {};
|
|
269
|
+
if (patch.allowPrivateNetwork === null) delete nextNetwork.dangerouslyAllowPrivateNetwork;
|
|
270
|
+
else nextNetwork.dangerouslyAllowPrivateNetwork = patch.allowPrivateNetwork;
|
|
271
|
+
if (Object.keys(nextNetwork).length > 0) nextAccount.network = nextNetwork;
|
|
272
|
+
else delete nextAccount.network;
|
|
273
|
+
}
|
|
274
|
+
if (patch.initialSyncLimit !== void 0) if (patch.initialSyncLimit === null) delete nextAccount.initialSyncLimit;
|
|
275
|
+
else nextAccount.initialSyncLimit = Math.max(0, Math.floor(patch.initialSyncLimit));
|
|
276
|
+
if (patch.encryption !== void 0) if (patch.encryption === null) delete nextAccount.encryption;
|
|
277
|
+
else nextAccount.encryption = patch.encryption;
|
|
278
|
+
if (patch.allowBots !== void 0) if (patch.allowBots === null) delete nextAccount.allowBots;
|
|
279
|
+
else nextAccount.allowBots = patch.allowBots;
|
|
280
|
+
if (patch.autoJoin !== void 0) if (patch.autoJoin === null) delete nextAccount.autoJoin;
|
|
281
|
+
else nextAccount.autoJoin = patch.autoJoin;
|
|
282
|
+
applyNullableArrayField(nextAccount, "autoJoinAllowlist", patch.autoJoinAllowlist);
|
|
283
|
+
if (patch.dm !== void 0) if (patch.dm === null) delete nextAccount.dm;
|
|
284
|
+
else nextAccount.dm = cloneMatrixDmConfig({
|
|
285
|
+
...nextAccount.dm,
|
|
286
|
+
...patch.dm
|
|
287
|
+
});
|
|
288
|
+
if (patch.groupPolicy !== void 0) if (patch.groupPolicy === null) delete nextAccount.groupPolicy;
|
|
289
|
+
else nextAccount.groupPolicy = patch.groupPolicy;
|
|
290
|
+
applyNullableArrayField(nextAccount, "groupAllowFrom", patch.groupAllowFrom);
|
|
291
|
+
if (patch.groups !== void 0) if (patch.groups === null) delete nextAccount.groups;
|
|
292
|
+
else nextAccount.groups = cloneMatrixRoomMap(patch.groups);
|
|
293
|
+
if (patch.rooms !== void 0) if (patch.rooms === null) delete nextAccount.rooms;
|
|
294
|
+
else nextAccount.rooms = cloneMatrixRoomMap(patch.rooms);
|
|
295
|
+
const nextAccounts = Object.fromEntries(Object.entries(matrix.accounts ?? {}).filter(([rawAccountId]) => rawAccountId === normalizedAccountId || normalizeAccountId(rawAccountId) !== normalizedAccountId));
|
|
296
|
+
if (shouldStoreMatrixAccountAtTopLevel(cfg, normalizedAccountId)) {
|
|
297
|
+
const { accounts: _ignoredAccounts, defaultAccount } = matrix;
|
|
298
|
+
const { accounts: _ignoredNextAccounts, defaultAccount: _ignoredNextDefaultAccount, ...topLevelAccount } = nextAccount;
|
|
299
|
+
return {
|
|
300
|
+
...cfg,
|
|
301
|
+
channels: {
|
|
302
|
+
...cfg.channels,
|
|
303
|
+
matrix: {
|
|
304
|
+
...defaultAccount ? { defaultAccount } : {},
|
|
305
|
+
enabled: true,
|
|
306
|
+
...topLevelAccount
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
...cfg,
|
|
313
|
+
channels: {
|
|
314
|
+
...cfg.channels,
|
|
315
|
+
matrix: {
|
|
316
|
+
...matrix,
|
|
317
|
+
enabled: true,
|
|
318
|
+
accounts: {
|
|
319
|
+
...nextAccounts,
|
|
320
|
+
[normalizedAccountId]: nextAccount
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region extensions/matrix/src/matrix/profile.ts
|
|
328
|
+
var profile_exports = /* @__PURE__ */ __exportAll({
|
|
329
|
+
MATRIX_PROFILE_AVATAR_MAX_BYTES: () => MATRIX_PROFILE_AVATAR_MAX_BYTES,
|
|
330
|
+
isMatrixHttpAvatarUri: () => isMatrixHttpAvatarUri,
|
|
331
|
+
isMatrixMxcUri: () => isMatrixMxcUri,
|
|
332
|
+
isSupportedMatrixAvatarSource: () => isSupportedMatrixAvatarSource,
|
|
333
|
+
syncMatrixOwnProfile: () => syncMatrixOwnProfile
|
|
334
|
+
});
|
|
335
|
+
const MATRIX_PROFILE_AVATAR_MAX_BYTES = 10 * 1024 * 1024;
|
|
336
|
+
function isMatrixMxcUri(value) {
|
|
337
|
+
return normalizeLowercaseStringOrEmpty(normalizeOptionalString(value)).startsWith("mxc://");
|
|
338
|
+
}
|
|
339
|
+
function isMatrixHttpAvatarUri(value) {
|
|
340
|
+
const normalized = normalizeLowercaseStringOrEmpty(normalizeOptionalString(value));
|
|
341
|
+
return normalized.startsWith("https://") || normalized.startsWith("http://");
|
|
342
|
+
}
|
|
343
|
+
function isSupportedMatrixAvatarSource(value) {
|
|
344
|
+
return isMatrixMxcUri(value) || isMatrixHttpAvatarUri(value);
|
|
345
|
+
}
|
|
346
|
+
async function uploadAvatarMedia(params) {
|
|
347
|
+
const media = await params.loadAvatar(params.avatarSource, params.avatarMaxBytes);
|
|
348
|
+
return await params.client.uploadContent(media.buffer, media.contentType, media.fileName || "avatar");
|
|
349
|
+
}
|
|
350
|
+
async function resolveAvatarUrl(params) {
|
|
351
|
+
const avatarPath = normalizeOptionalString(params.avatarPath) ?? null;
|
|
352
|
+
if (avatarPath) {
|
|
353
|
+
if (!params.loadAvatarFromPath) throw new Error("Matrix avatar path upload requires a media loader.");
|
|
354
|
+
return {
|
|
355
|
+
resolvedAvatarUrl: await uploadAvatarMedia({
|
|
356
|
+
client: params.client,
|
|
357
|
+
avatarSource: avatarPath,
|
|
358
|
+
avatarMaxBytes: params.avatarMaxBytes,
|
|
359
|
+
loadAvatar: params.loadAvatarFromPath
|
|
360
|
+
}),
|
|
361
|
+
uploadedAvatarSource: "path",
|
|
362
|
+
convertedAvatarFromHttp: false
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
const avatarUrl = normalizeOptionalString(params.avatarUrl) ?? null;
|
|
366
|
+
if (!avatarUrl) return {
|
|
367
|
+
resolvedAvatarUrl: null,
|
|
368
|
+
uploadedAvatarSource: null,
|
|
369
|
+
convertedAvatarFromHttp: false
|
|
370
|
+
};
|
|
371
|
+
if (isMatrixMxcUri(avatarUrl)) return {
|
|
372
|
+
resolvedAvatarUrl: avatarUrl,
|
|
373
|
+
uploadedAvatarSource: null,
|
|
374
|
+
convertedAvatarFromHttp: false
|
|
375
|
+
};
|
|
376
|
+
if (!isMatrixHttpAvatarUri(avatarUrl)) throw new Error("Matrix avatar URL must be an mxc:// URI or an http(s) URL.");
|
|
377
|
+
if (!params.loadAvatarFromUrl) throw new Error("Matrix avatar URL conversion requires a media loader.");
|
|
378
|
+
return {
|
|
379
|
+
resolvedAvatarUrl: await uploadAvatarMedia({
|
|
380
|
+
client: params.client,
|
|
381
|
+
avatarSource: avatarUrl,
|
|
382
|
+
avatarMaxBytes: params.avatarMaxBytes,
|
|
383
|
+
loadAvatar: params.loadAvatarFromUrl
|
|
384
|
+
}),
|
|
385
|
+
uploadedAvatarSource: "http",
|
|
386
|
+
convertedAvatarFromHttp: true
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
async function syncMatrixOwnProfile(params) {
|
|
390
|
+
const desiredDisplayName = normalizeOptionalString(params.displayName) ?? null;
|
|
391
|
+
const avatar = await resolveAvatarUrl({
|
|
392
|
+
client: params.client,
|
|
393
|
+
avatarUrl: params.avatarUrl ?? null,
|
|
394
|
+
avatarPath: params.avatarPath ?? null,
|
|
395
|
+
avatarMaxBytes: params.avatarMaxBytes ?? 10485760,
|
|
396
|
+
loadAvatarFromUrl: params.loadAvatarFromUrl,
|
|
397
|
+
loadAvatarFromPath: params.loadAvatarFromPath
|
|
398
|
+
});
|
|
399
|
+
const desiredAvatarUrl = avatar.resolvedAvatarUrl;
|
|
400
|
+
if (!desiredDisplayName && !desiredAvatarUrl) return {
|
|
401
|
+
skipped: true,
|
|
402
|
+
displayNameUpdated: false,
|
|
403
|
+
avatarUpdated: false,
|
|
404
|
+
resolvedAvatarUrl: null,
|
|
405
|
+
uploadedAvatarSource: avatar.uploadedAvatarSource,
|
|
406
|
+
convertedAvatarFromHttp: avatar.convertedAvatarFromHttp
|
|
407
|
+
};
|
|
408
|
+
let currentDisplayName;
|
|
409
|
+
let currentAvatarUrl;
|
|
410
|
+
try {
|
|
411
|
+
const currentProfile = await params.client.getUserProfile(params.userId);
|
|
412
|
+
currentDisplayName = normalizeOptionalString(currentProfile.displayname);
|
|
413
|
+
currentAvatarUrl = normalizeOptionalString(currentProfile.avatar_url);
|
|
414
|
+
} catch {}
|
|
415
|
+
let displayNameUpdated = false;
|
|
416
|
+
let avatarUpdated = false;
|
|
417
|
+
if (desiredDisplayName && currentDisplayName !== desiredDisplayName) {
|
|
418
|
+
await params.client.setDisplayName(desiredDisplayName);
|
|
419
|
+
displayNameUpdated = true;
|
|
420
|
+
}
|
|
421
|
+
if (desiredAvatarUrl && currentAvatarUrl !== desiredAvatarUrl) {
|
|
422
|
+
await params.client.setAvatarUrl(desiredAvatarUrl);
|
|
423
|
+
avatarUpdated = true;
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
skipped: false,
|
|
427
|
+
displayNameUpdated,
|
|
428
|
+
avatarUpdated,
|
|
429
|
+
resolvedAvatarUrl: desiredAvatarUrl,
|
|
430
|
+
uploadedAvatarSource: avatar.uploadedAvatarSource,
|
|
431
|
+
convertedAvatarFromHttp: avatar.convertedAvatarFromHttp
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region extensions/matrix/src/setup-config.ts
|
|
436
|
+
const channel$1 = "matrix";
|
|
437
|
+
const COMMON_SINGLE_ACCOUNT_KEYS_TO_MOVE = new Set([
|
|
438
|
+
"name",
|
|
439
|
+
"enabled",
|
|
440
|
+
"httpPort",
|
|
441
|
+
"webhookPath",
|
|
442
|
+
"webhookUrl",
|
|
443
|
+
"webhookSecret",
|
|
444
|
+
"service",
|
|
445
|
+
"region",
|
|
446
|
+
"homeserver",
|
|
447
|
+
"userId",
|
|
448
|
+
"accessToken",
|
|
449
|
+
"password",
|
|
450
|
+
"deviceName",
|
|
451
|
+
"url",
|
|
452
|
+
"code",
|
|
453
|
+
"dmPolicy",
|
|
454
|
+
"allowFrom",
|
|
455
|
+
"groupPolicy",
|
|
456
|
+
"groupAllowFrom",
|
|
457
|
+
"defaultTo"
|
|
458
|
+
]);
|
|
459
|
+
const MATRIX_SINGLE_ACCOUNT_KEYS_TO_MOVE = new Set(matrixSingleAccountKeysToMove);
|
|
460
|
+
const MATRIX_NAMED_ACCOUNT_PROMOTION_KEYS = new Set(matrixNamedAccountPromotionKeys);
|
|
461
|
+
function cloneIfObject(value) {
|
|
462
|
+
if (value && typeof value === "object") return structuredClone(value);
|
|
463
|
+
return value;
|
|
464
|
+
}
|
|
465
|
+
function resolveSetupAvatarUrl(input) {
|
|
466
|
+
const avatarUrl = input.avatarUrl;
|
|
467
|
+
if (typeof avatarUrl !== "string") return;
|
|
468
|
+
return avatarUrl.trim() || void 0;
|
|
469
|
+
}
|
|
470
|
+
function resolveExistingMatrixAccountKey(accounts, targetAccountId) {
|
|
471
|
+
const normalizedTargetAccountId = normalizeAccountId$2(targetAccountId);
|
|
472
|
+
return Object.keys(accounts).find((accountId) => normalizeAccountId$2(accountId) === normalizedTargetAccountId) ?? targetAccountId;
|
|
473
|
+
}
|
|
474
|
+
function moveSingleMatrixAccountConfigToNamedAccount(cfg) {
|
|
475
|
+
const baseConfig = cfg.channels?.[channel$1];
|
|
476
|
+
const base = typeof baseConfig === "object" && baseConfig ? baseConfig : void 0;
|
|
477
|
+
if (!base) return cfg;
|
|
478
|
+
const accounts = typeof base.accounts === "object" && base.accounts ? base.accounts : {};
|
|
479
|
+
const hasNamedAccounts = Object.keys(accounts).some(Boolean);
|
|
480
|
+
const keysToMove = Object.entries(base).filter(([key, value]) => {
|
|
481
|
+
if (key === "accounts" || key === "enabled" || value === void 0) return false;
|
|
482
|
+
if (!COMMON_SINGLE_ACCOUNT_KEYS_TO_MOVE.has(key) && !MATRIX_SINGLE_ACCOUNT_KEYS_TO_MOVE.has(key)) return false;
|
|
483
|
+
if (hasNamedAccounts && !MATRIX_NAMED_ACCOUNT_PROMOTION_KEYS.has(key)) return false;
|
|
484
|
+
return true;
|
|
485
|
+
}).map(([key]) => key);
|
|
486
|
+
if (keysToMove.length === 0) return cfg;
|
|
487
|
+
const resolvedTargetAccountId = resolveExistingMatrixAccountKey(accounts, resolveSingleAccountPromotionTarget({ channel: base }));
|
|
488
|
+
const nextAccount = { ...accounts[resolvedTargetAccountId] };
|
|
489
|
+
for (const key of keysToMove) nextAccount[key] = cloneIfObject(base[key]);
|
|
490
|
+
const nextChannel = { ...base };
|
|
491
|
+
for (const key of keysToMove) delete nextChannel[key];
|
|
492
|
+
return {
|
|
493
|
+
...cfg,
|
|
494
|
+
channels: {
|
|
495
|
+
...cfg.channels,
|
|
496
|
+
[channel$1]: {
|
|
497
|
+
...nextChannel,
|
|
498
|
+
accounts: {
|
|
499
|
+
...accounts,
|
|
500
|
+
[resolvedTargetAccountId]: nextAccount
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function validateMatrixSetupInput(params) {
|
|
507
|
+
const avatarUrl = resolveSetupAvatarUrl(params.input);
|
|
508
|
+
if (avatarUrl && !isSupportedMatrixAvatarSource(avatarUrl)) return "Matrix avatar URL must be an mxc:// URI or an http(s) URL.";
|
|
509
|
+
if (params.input.useEnv) {
|
|
510
|
+
const envReadiness = resolveMatrixEnvAuthReadiness(params.accountId, process.env);
|
|
511
|
+
return envReadiness.ready ? null : envReadiness.missingMessage;
|
|
512
|
+
}
|
|
513
|
+
if (!params.input.homeserver?.trim()) return "Matrix requires --homeserver";
|
|
514
|
+
const accessToken = params.input.accessToken?.trim();
|
|
515
|
+
const password = normalizeSecretInputString(params.input.password);
|
|
516
|
+
const userId = params.input.userId?.trim();
|
|
517
|
+
if (!accessToken && !password) return "Matrix requires --access-token or --password";
|
|
518
|
+
if (!accessToken) {
|
|
519
|
+
if (!userId) return "Matrix requires --user-id when using --password";
|
|
520
|
+
if (!password) return "Matrix requires --password when using --user-id";
|
|
521
|
+
}
|
|
522
|
+
return null;
|
|
523
|
+
}
|
|
524
|
+
function applyMatrixSetupAccountConfig(params) {
|
|
525
|
+
const normalizedAccountId = normalizeAccountId$2(params.accountId);
|
|
526
|
+
const next = applyAccountNameToChannelSection({
|
|
527
|
+
cfg: normalizedAccountId !== DEFAULT_ACCOUNT_ID$2 ? moveSingleMatrixAccountConfigToNamedAccount(params.cfg) : params.cfg,
|
|
528
|
+
channelKey: channel$1,
|
|
529
|
+
accountId: normalizedAccountId,
|
|
530
|
+
name: params.input.name
|
|
531
|
+
});
|
|
532
|
+
const avatarUrl = resolveSetupAvatarUrl(params.input);
|
|
533
|
+
if (params.input.useEnv) return updateMatrixAccountConfig(next, normalizedAccountId, {
|
|
534
|
+
enabled: true,
|
|
535
|
+
homeserver: null,
|
|
536
|
+
allowPrivateNetwork: null,
|
|
537
|
+
proxy: null,
|
|
538
|
+
userId: null,
|
|
539
|
+
accessToken: null,
|
|
540
|
+
password: null,
|
|
541
|
+
deviceId: null,
|
|
542
|
+
deviceName: null,
|
|
543
|
+
avatarUrl
|
|
544
|
+
});
|
|
545
|
+
const accessToken = params.input.accessToken?.trim();
|
|
546
|
+
const password = normalizeSecretInputString(params.input.password);
|
|
547
|
+
const userId = params.input.userId?.trim();
|
|
548
|
+
return updateMatrixAccountConfig(next, normalizedAccountId, {
|
|
549
|
+
enabled: true,
|
|
550
|
+
homeserver: params.input.homeserver?.trim(),
|
|
551
|
+
allowPrivateNetwork: typeof params.input.dangerouslyAllowPrivateNetwork === "boolean" ? params.input.dangerouslyAllowPrivateNetwork : typeof params.input.allowPrivateNetwork === "boolean" ? params.input.allowPrivateNetwork : void 0,
|
|
552
|
+
proxy: normalizeOptionalString(params.input.proxy),
|
|
553
|
+
userId: password && !userId ? null : userId,
|
|
554
|
+
accessToken: accessToken || (password ? null : void 0),
|
|
555
|
+
password: password || (accessToken ? null : void 0),
|
|
556
|
+
deviceName: params.input.deviceName?.trim(),
|
|
557
|
+
avatarUrl,
|
|
558
|
+
initialSyncLimit: params.input.initialSyncLimit
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region extensions/matrix/src/setup-dm-policy.ts
|
|
563
|
+
function resolveMatrixSetupDmAllowFrom(policy, allowFrom) {
|
|
564
|
+
if (policy === "open") return addWildcardAllowFrom(allowFrom);
|
|
565
|
+
return normalizeAllowFromEntries(allowFrom ?? []).filter((entry) => entry !== "*");
|
|
566
|
+
}
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region extensions/matrix/src/setup-core.ts
|
|
569
|
+
const channel = "matrix";
|
|
570
|
+
function resolveMatrixSetupAccountId(params) {
|
|
571
|
+
return normalizeAccountId$2(params.accountId?.trim() || params.name?.trim() || DEFAULT_ACCOUNT_ID$2);
|
|
572
|
+
}
|
|
573
|
+
function resolveMatrixSetupWizardAccountId(cfg, accountId) {
|
|
574
|
+
return normalizeAccountId$2(accountId?.trim() || resolveDefaultMatrixAccountId(cfg) || DEFAULT_ACCOUNT_ID$2);
|
|
575
|
+
}
|
|
576
|
+
function setMatrixDmPolicy(cfg, policy, accountId) {
|
|
577
|
+
const resolvedAccountId = resolveMatrixSetupWizardAccountId(cfg, accountId);
|
|
578
|
+
const existing = resolveMatrixAccountConfig({
|
|
579
|
+
cfg,
|
|
580
|
+
accountId: resolvedAccountId
|
|
581
|
+
});
|
|
582
|
+
const allowFrom = resolveMatrixSetupDmAllowFrom(policy, existing.dm?.allowFrom);
|
|
583
|
+
return updateMatrixAccountConfig(cfg, resolvedAccountId, { dm: {
|
|
584
|
+
...existing.dm,
|
|
585
|
+
policy,
|
|
586
|
+
allowFrom
|
|
587
|
+
} });
|
|
588
|
+
}
|
|
589
|
+
function createMatrixSetupWizardProxy(loadWizardModule) {
|
|
590
|
+
let wizardPromise = null;
|
|
591
|
+
const loadWizard = () => {
|
|
592
|
+
wizardPromise ??= loadWizardModule().then((module) => module.matrixSetupWizard);
|
|
593
|
+
return wizardPromise;
|
|
594
|
+
};
|
|
595
|
+
return {
|
|
596
|
+
channel,
|
|
597
|
+
getStatus: async (ctx) => await (await loadWizard()).getStatus(ctx),
|
|
598
|
+
configure: async (ctx) => await (await loadWizard()).configure(ctx),
|
|
599
|
+
configureInteractive: async (ctx) => {
|
|
600
|
+
const wizard = await loadWizard();
|
|
601
|
+
return await (wizard.configureInteractive ?? wizard.configure)(ctx);
|
|
602
|
+
},
|
|
603
|
+
configureWhenConfigured: async (ctx) => {
|
|
604
|
+
const wizard = await loadWizard();
|
|
605
|
+
return await (wizard.configureWhenConfigured ?? wizard.configureInteractive ?? wizard.configure)(ctx);
|
|
606
|
+
},
|
|
607
|
+
afterConfigWritten: async (ctx) => await (await loadWizard()).afterConfigWritten?.(ctx),
|
|
608
|
+
dmPolicy: {
|
|
609
|
+
label: "Matrix",
|
|
610
|
+
channel,
|
|
611
|
+
policyKey: "channels.matrix.dm.policy",
|
|
612
|
+
allowFromKey: "channels.matrix.dm.allowFrom",
|
|
613
|
+
resolveConfigKeys: (cfg, accountId) => {
|
|
614
|
+
const resolvedAccountId = resolveMatrixSetupWizardAccountId(cfg, accountId);
|
|
615
|
+
return {
|
|
616
|
+
policyKey: resolveMatrixConfigFieldPath(cfg, resolvedAccountId, "dm.policy"),
|
|
617
|
+
allowFromKey: resolveMatrixConfigFieldPath(cfg, resolvedAccountId, "dm.allowFrom")
|
|
618
|
+
};
|
|
619
|
+
},
|
|
620
|
+
getCurrent: (cfg, accountId) => resolveMatrixAccountConfig({
|
|
621
|
+
cfg,
|
|
622
|
+
accountId: resolveMatrixSetupWizardAccountId(cfg, accountId)
|
|
623
|
+
}).dm?.policy ?? "pairing",
|
|
624
|
+
setPolicy: (cfg, policy, accountId) => setMatrixDmPolicy(cfg, policy, accountId),
|
|
625
|
+
promptAllowFrom: async (params) => {
|
|
626
|
+
const promptAllowFrom = (await loadWizard()).dmPolicy?.promptAllowFrom;
|
|
627
|
+
return promptAllowFrom ? await promptAllowFrom(params) : params.cfg;
|
|
628
|
+
}
|
|
629
|
+
},
|
|
630
|
+
disable: (cfg) => ({
|
|
631
|
+
...cfg,
|
|
632
|
+
channels: {
|
|
633
|
+
...cfg.channels,
|
|
634
|
+
matrix: {
|
|
635
|
+
...cfg.channels?.matrix,
|
|
636
|
+
enabled: false
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
})
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
const matrixSetupAdapter = {
|
|
643
|
+
resolveAccountId: ({ accountId, input }) => resolveMatrixSetupAccountId({
|
|
644
|
+
accountId,
|
|
645
|
+
name: input?.name
|
|
646
|
+
}),
|
|
647
|
+
resolveBindingAccountId: ({ accountId, agentId }) => resolveMatrixSetupAccountId({
|
|
648
|
+
accountId,
|
|
649
|
+
name: agentId
|
|
650
|
+
}),
|
|
651
|
+
applyAccountName: ({ cfg, accountId, name }) => prepareScopedSetupConfig({
|
|
652
|
+
cfg,
|
|
653
|
+
channelKey: channel,
|
|
654
|
+
accountId,
|
|
655
|
+
name
|
|
656
|
+
}),
|
|
657
|
+
validateInput: ({ accountId, input }) => validateMatrixSetupInput({
|
|
658
|
+
accountId,
|
|
659
|
+
input
|
|
660
|
+
}),
|
|
661
|
+
applyAccountConfig: ({ cfg, accountId, input }) => applyMatrixSetupAccountConfig({
|
|
662
|
+
cfg,
|
|
663
|
+
accountId,
|
|
664
|
+
input
|
|
665
|
+
}),
|
|
666
|
+
afterAccountConfigWritten: async ({ previousCfg, cfg, accountId, runtime }) => {
|
|
667
|
+
const { runMatrixSetupBootstrapAfterConfigWrite } = await import("./setup-bootstrap-rJ0qZWPe.js");
|
|
668
|
+
await runMatrixSetupBootstrapAfterConfigWrite({
|
|
669
|
+
previousCfg,
|
|
670
|
+
cfg,
|
|
671
|
+
accountId,
|
|
672
|
+
runtime
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
//#endregion
|
|
677
|
+
export { profile_exports as a, resolveMatrixConfigPath as c, resolveSingleAccountPromotionTarget as d, singleAccountKeysToMove as f, resolveMatrixAccount as g, resolveDefaultMatrixAccountId as h, moveSingleMatrixAccountConfigToNamedAccount as i, updateMatrixAccountConfig as l, resolveConfiguredMatrixBotUserIds as m, matrixSetupAdapter as n, syncMatrixOwnProfile as o, listMatrixAccountIds as p, resolveMatrixSetupDmAllowFrom as r, config_update_exports as s, createMatrixSetupWizardProxy as t, namedAccountPromotionKeys as u };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineBundledChannelSetupEntry } from "klaw/plugin-sdk/channel-entry-contract";
|
|
2
|
+
//#region extensions/matrix/setup-entry.ts
|
|
3
|
+
var setup_entry_default = defineBundledChannelSetupEntry({
|
|
4
|
+
importMetaUrl: import.meta.url,
|
|
5
|
+
plugin: {
|
|
6
|
+
specifier: "./setup-plugin-api.js",
|
|
7
|
+
exportName: "matrixSetupPlugin"
|
|
8
|
+
},
|
|
9
|
+
secrets: {
|
|
10
|
+
specifier: "./secret-contract-api.js",
|
|
11
|
+
exportName: "channelSecrets"
|
|
12
|
+
},
|
|
13
|
+
runtime: {
|
|
14
|
+
specifier: "./runtime-setter-api.js",
|
|
15
|
+
exportName: "setMatrixRuntime"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
//#endregion
|
|
19
|
+
export { setup_entry_default as default };
|