@gakr-gakr/matrix 0.1.0 → 0.1.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.
- package/autobot.plugin.json +891 -3
- package/dist/account-selection-D4xDzY_1.js +158 -0
- package/dist/active-client-BXz0W1fG.js +20 -0
- package/dist/api.js +12 -0
- package/dist/approval-handler.runtime-XgtgHryy.js +377 -0
- package/dist/approval-ids-Bj1MSuK0.js +7 -0
- package/dist/approval-reaction-auth-CP8yUUiI.js +27 -0
- package/dist/approval-reactions-C7FrzFhD.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-CVtvS1kS.js +1380 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BCl9atvS.js +250 -0
- package/dist/cli-D1Fxo6zb.js +1338 -0
- package/dist/cli-metadata-lo35g_nH.js +22 -0
- package/dist/cli-metadata.js +2 -0
- package/dist/client-4JU3adE6.js +30 -0
- package/dist/client-DVbkO1fr.js +25 -0
- package/dist/client-bootstrap-mLJmDCv8.js +114 -0
- package/dist/config-paths-BRIwec9o.js +114 -0
- package/dist/config-schema-ON2KZjSH.js +308 -0
- package/dist/config-secret-input.runtime-BcE98Tab.js +2 -0
- package/dist/contract-api.js +8 -0
- package/dist/create-client-nSnXsRe0.js +64 -0
- package/dist/credentials-CLaeORZB.js +56 -0
- package/dist/credentials-read-lnekFDSy.js +112 -0
- package/dist/credentials-write.runtime-AcuXkIly.js +17 -0
- package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
- package/dist/crypto-runtime-D577JLjP.js +1214 -0
- package/dist/deps-CcgU6fF9.js +208 -0
- package/dist/device-health-BDJoK0GP.js +16 -0
- package/dist/directory-live-D5osmyPM.js +150 -0
- package/dist/doctor-contract-CRTZe22J.js +246 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/doctor-k53ce7TR.js +153 -0
- package/dist/draft-stream-B81ki3aq.js +143 -0
- package/dist/encryption-guidance-C4UZO9P_.js +15 -0
- package/dist/env-auth-ZPNhil6w.js +63 -0
- package/dist/env-vars-Ch51id3Y.js +63 -0
- package/dist/errors-D8exgH7Z.js +17 -0
- package/dist/exec-approval-resolver-NR6hHp1P.js +15 -0
- package/dist/helper-api.js +4 -0
- package/dist/http-client-CLvnNzJZ.js +331 -0
- package/dist/index.js +46 -0
- package/dist/legacy-crypto-inspector-BXa-K6Qb.js +41 -0
- package/dist/legacy-crypto-restore-DmSdbVyW.js +85 -0
- package/dist/logging-BWx5aV5G.js +99 -0
- package/dist/matrix-migration.runtime-C5EAzuSF.js +525 -0
- package/dist/media-text-H2gCWr7p.js +146 -0
- package/dist/messages-BM8v2OhM.js +140 -0
- package/dist/migration-snapshot-backup-B4qRjmn2.js +69 -0
- package/dist/migration-snapshot.runtime-CEaEL8JK.js +2 -0
- package/dist/monitor-9_MYVUk0.js +4331 -0
- package/dist/plugin-entry.handlers.runtime.js +51 -0
- package/dist/probe.runtime-ARO_q_Zl.js +3 -0
- package/dist/profile-update-DgBXphvR.js +68 -0
- package/dist/reaction-common-Bx8mZPc9.js +71 -0
- package/dist/reaction-events-B2GhGktu.js +121 -0
- package/{src/record-shared.ts → dist/record-shared-D-PbvaZ7.js} +1 -2
- package/dist/resolve-targets-CFr6_x9K.js +140 -0
- package/dist/resolver.runtime-fPzzTZVJ.js +5 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/route-m49kMiHx.js +161 -0
- package/dist/runtime-BfjP-NST.js +8 -0
- package/dist/runtime-api-D7plmCoC.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-CK0ON6Js.js +1704 -0
- package/dist/secret-contract-BKkC-9fa.js +120 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/send-CWOxcUMq.js +1517 -0
- package/dist/setup-bootstrap-VShXhiBJ.js +62 -0
- package/dist/setup-core-CmXNGvQt.js +677 -0
- package/dist/setup-entry.js +19 -0
- package/dist/setup-plugin-api.js +43 -0
- package/dist/setup-surface-zTLHNBns.js +537 -0
- package/dist/shared-BrKJkpx_.js +642 -0
- package/dist/startup-abort-D79WSeUh.js +109 -0
- package/dist/startup-verification-Dj34oWgb.js +132 -0
- package/dist/storage-DxbroIe0.js +281 -0
- package/dist/storage-paths-BcLg30GH.js +52 -0
- package/dist/subagent-hooks-api-CjHBfEoY.js +170 -0
- package/dist/subagent-hooks-api.js +2 -0
- package/dist/sync-state-Bx0gPaGA.js +12 -0
- package/dist/target-ids-iZwjCUZa.js +77 -0
- package/dist/test-api.js +4 -0
- package/dist/thread-binding-api-BWT96Ttd.js +17 -0
- package/dist/thread-binding-api.js +2 -0
- package/dist/thread-bindings-owbheXoV.js +352 -0
- package/dist/thread-bindings-runtime.js +2 -0
- package/dist/thread-bindings-shared-4nkBBftw.js +97 -0
- package/dist/timeout-abort-signal-CPD0PPNy.js +2 -0
- package/dist/tool-actions.runtime-DDh2EP6z.js +532 -0
- package/dist/url-validation-fQvf_pW_.js +36 -0
- package/dist/verification-BhMWyuAf.js +345 -0
- package/package.json +16 -4
- package/CHANGELOG.md +0 -285
- package/SPEC-SUPPORT.md +0 -116
- package/api.ts +0 -38
- package/auth-presence.ts +0 -56
- package/channel-plugin-api.ts +0 -3
- package/cli-metadata.ts +0 -11
- package/contract-api.ts +0 -17
- package/doctor-contract-api.ts +0 -1
- package/helper-api.ts +0 -3
- package/index.ts +0 -55
- package/plugin-entry.handlers.runtime.ts +0 -1
- package/runtime-api.ts +0 -72
- package/runtime-heavy-api.ts +0 -1
- package/runtime-setter-api.ts +0 -3
- package/secret-contract-api.ts +0 -5
- package/setup-entry.ts +0 -17
- package/setup-plugin-api.ts +0 -3
- package/src/account-selection.ts +0 -223
- package/src/actions.ts +0 -346
- package/src/approval-auth.ts +0 -25
- package/src/approval-handler.runtime.ts +0 -595
- package/src/approval-ids.ts +0 -6
- package/src/approval-native.ts +0 -348
- package/src/approval-reaction-auth.ts +0 -45
- package/src/approval-reactions.ts +0 -313
- package/src/auth-precedence.ts +0 -61
- package/src/channel-account-paths.ts +0 -97
- package/src/channel.runtime.ts +0 -17
- package/src/channel.setup.ts +0 -48
- package/src/channel.ts +0 -667
- package/src/cli-metadata.ts +0 -19
- package/src/cli.ts +0 -2298
- package/src/config-adapter.ts +0 -41
- package/src/config-schema.ts +0 -159
- package/src/config-ui-hints.ts +0 -56
- package/src/directory-live.ts +0 -238
- package/src/doctor-contract.ts +0 -287
- package/src/doctor.ts +0 -262
- package/src/env-vars.ts +0 -92
- package/src/exec-approval-resolver.ts +0 -23
- package/src/exec-approvals.ts +0 -293
- package/src/group-mentions.ts +0 -41
- package/src/legacy-crypto-inspector-availability.ts +0 -60
- package/src/legacy-crypto.ts +0 -531
- package/src/legacy-state.ts +0 -156
- package/src/matrix/account-config.ts +0 -175
- package/src/matrix/accounts.ts +0 -194
- package/src/matrix/actions/client.ts +0 -31
- package/src/matrix/actions/devices.ts +0 -34
- package/src/matrix/actions/limits.ts +0 -6
- package/src/matrix/actions/messages.ts +0 -129
- package/src/matrix/actions/pins.ts +0 -63
- package/src/matrix/actions/polls.ts +0 -109
- package/src/matrix/actions/profile.ts +0 -37
- package/src/matrix/actions/reactions.ts +0 -59
- package/src/matrix/actions/room.ts +0 -71
- package/src/matrix/actions/summary.ts +0 -88
- package/src/matrix/actions/types.ts +0 -63
- package/src/matrix/actions/verification.ts +0 -589
- package/src/matrix/actions.ts +0 -37
- package/src/matrix/active-client.ts +0 -26
- package/src/matrix/async-lock.ts +0 -18
- package/src/matrix/backup-health.ts +0 -124
- package/src/matrix/client/config-runtime-api.ts +0 -9
- package/src/matrix/client/config-secret-input.runtime.ts +0 -1
- package/src/matrix/client/config.ts +0 -853
- package/src/matrix/client/create-client.ts +0 -105
- package/src/matrix/client/env-auth.ts +0 -95
- package/src/matrix/client/file-sync-store.ts +0 -289
- package/src/matrix/client/logging.ts +0 -140
- package/src/matrix/client/migration-snapshot.runtime.ts +0 -1
- package/src/matrix/client/private-network-host.ts +0 -1
- package/src/matrix/client/runtime.ts +0 -4
- package/src/matrix/client/shared.ts +0 -316
- package/src/matrix/client/storage.ts +0 -543
- package/src/matrix/client/types.ts +0 -50
- package/src/matrix/client/url-validation.ts +0 -76
- package/src/matrix/client-bootstrap.ts +0 -173
- package/src/matrix/client.ts +0 -23
- package/src/matrix/config-paths.ts +0 -31
- package/src/matrix/config-update.ts +0 -292
- package/src/matrix/credentials-read.ts +0 -207
- package/src/matrix/credentials-write.runtime.ts +0 -35
- package/src/matrix/credentials.ts +0 -95
- package/src/matrix/deps.ts +0 -309
- package/src/matrix/device-health.ts +0 -31
- package/src/matrix/direct-management.ts +0 -349
- package/src/matrix/direct-room.ts +0 -128
- package/src/matrix/draft-stream.ts +0 -225
- package/src/matrix/encryption-guidance.ts +0 -24
- package/src/matrix/errors.ts +0 -21
- package/src/matrix/format.ts +0 -426
- package/src/matrix/legacy-crypto-inspector.ts +0 -95
- package/src/matrix/media-errors.ts +0 -20
- package/src/matrix/media-text.ts +0 -162
- package/src/matrix/monitor/access-state.ts +0 -145
- package/src/matrix/monitor/ack-config.ts +0 -27
- package/src/matrix/monitor/allowlist.ts +0 -92
- package/src/matrix/monitor/auto-join.ts +0 -86
- package/src/matrix/monitor/config.ts +0 -569
- package/src/matrix/monitor/context-summary.ts +0 -43
- package/src/matrix/monitor/direct.ts +0 -296
- package/src/matrix/monitor/events.ts +0 -397
- package/src/matrix/monitor/handler.ts +0 -2271
- package/src/matrix/monitor/inbound-dedupe.ts +0 -267
- package/src/matrix/monitor/index.ts +0 -540
- package/src/matrix/monitor/legacy-crypto-restore.ts +0 -139
- package/src/matrix/monitor/location.ts +0 -108
- package/src/matrix/monitor/media.ts +0 -119
- package/src/matrix/monitor/mentions.ts +0 -256
- package/src/matrix/monitor/reaction-events.ts +0 -197
- package/src/matrix/monitor/recent-invite.ts +0 -30
- package/src/matrix/monitor/replies.ts +0 -136
- package/src/matrix/monitor/reply-context.ts +0 -92
- package/src/matrix/monitor/room-history.ts +0 -301
- package/src/matrix/monitor/room-info.ts +0 -126
- package/src/matrix/monitor/rooms.ts +0 -52
- package/src/matrix/monitor/route.ts +0 -179
- package/src/matrix/monitor/runtime-api.ts +0 -28
- package/src/matrix/monitor/startup-verification.ts +0 -237
- package/src/matrix/monitor/startup.ts +0 -218
- package/src/matrix/monitor/status.ts +0 -120
- package/src/matrix/monitor/sync-lifecycle.ts +0 -91
- package/src/matrix/monitor/task-runner.ts +0 -38
- package/src/matrix/monitor/test-events.ts +0 -21
- package/src/matrix/monitor/thread-context.ts +0 -108
- package/src/matrix/monitor/threads.ts +0 -85
- package/src/matrix/monitor/types.ts +0 -30
- package/src/matrix/monitor/verification-events.ts +0 -643
- package/src/matrix/monitor/verification-utils.ts +0 -46
- package/src/matrix/outbound-media-runtime.ts +0 -1
- package/src/matrix/poll-summary.ts +0 -110
- package/src/matrix/poll-types.ts +0 -429
- package/src/matrix/probe.runtime.ts +0 -4
- package/src/matrix/probe.ts +0 -97
- package/src/matrix/profile.ts +0 -184
- package/src/matrix/reaction-common.ts +0 -147
- package/src/matrix/sdk/crypto-bootstrap.ts +0 -438
- package/src/matrix/sdk/crypto-facade.ts +0 -242
- package/src/matrix/sdk/crypto-node.runtime.ts +0 -17
- package/src/matrix/sdk/crypto-runtime.ts +0 -14
- package/src/matrix/sdk/decrypt-bridge.ts +0 -410
- package/src/matrix/sdk/event-helpers.ts +0 -83
- package/src/matrix/sdk/http-client.ts +0 -87
- package/src/matrix/sdk/idb-persistence-lock.ts +0 -51
- package/src/matrix/sdk/idb-persistence.ts +0 -286
- package/src/matrix/sdk/logger.ts +0 -108
- package/src/matrix/sdk/read-response-with-limit.ts +0 -19
- package/src/matrix/sdk/recovery-key-store.ts +0 -453
- package/src/matrix/sdk/timeout-abort-signal.ts +0 -1
- package/src/matrix/sdk/transport-runtime-api.ts +0 -18
- package/src/matrix/sdk/transport.ts +0 -352
- package/src/matrix/sdk/types.ts +0 -245
- package/src/matrix/sdk/verification-manager.ts +0 -795
- package/src/matrix/sdk/verification-status.ts +0 -23
- package/src/matrix/sdk.ts +0 -2152
- package/src/matrix/send/client.ts +0 -93
- package/src/matrix/send/formatting.ts +0 -189
- package/src/matrix/send/media.ts +0 -244
- package/src/matrix/send/targets.ts +0 -104
- package/src/matrix/send/types.ts +0 -131
- package/src/matrix/send.ts +0 -660
- package/src/matrix/session-store-metadata.ts +0 -108
- package/src/matrix/startup-abort.ts +0 -44
- package/src/matrix/subagent-hooks.ts +0 -308
- package/src/matrix/sync-state.ts +0 -27
- package/src/matrix/target-ids.ts +0 -79
- package/src/matrix/thread-bindings-shared.ts +0 -206
- package/src/matrix/thread-bindings.ts +0 -580
- package/src/matrix-migration.runtime.ts +0 -9
- package/src/migration-config.ts +0 -243
- package/src/migration-snapshot-backup.ts +0 -116
- package/src/migration-snapshot.ts +0 -53
- package/src/onboarding.ts +0 -775
- package/src/outbound.ts +0 -248
- package/src/plugin-entry.runtime.js +0 -115
- package/src/plugin-entry.runtime.ts +0 -70
- package/src/profile-update.ts +0 -71
- package/src/resolve-targets.ts +0 -175
- package/src/resolver.runtime.ts +0 -5
- package/src/resolver.ts +0 -21
- package/src/runtime-api.ts +0 -106
- package/src/runtime.ts +0 -13
- package/src/secret-contract.ts +0 -174
- package/src/session-route.ts +0 -126
- package/src/setup-bootstrap.ts +0 -102
- package/src/setup-config.ts +0 -222
- package/src/setup-contract.ts +0 -90
- package/src/setup-core.ts +0 -146
- package/src/setup-dm-policy.ts +0 -15
- package/src/setup-surface.ts +0 -4
- package/src/startup-maintenance.ts +0 -114
- package/src/storage-paths.ts +0 -92
- package/src/thread-binding-api.ts +0 -23
- package/src/tool-actions.runtime.ts +0 -1
- package/src/tool-actions.ts +0 -498
- package/src/types.ts +0 -257
- package/subagent-hooks-api.ts +0 -31
- package/test-api.ts +0 -21
- package/thread-binding-api.ts +0 -4
- package/thread-bindings-runtime.ts +0 -4
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { n as listMatrixEnvAccountIds, t as getMatrixScopedEnvVarNames } from "./env-vars-Ch51id3Y.js";
|
|
2
|
+
import { t as isRecord } from "./record-shared-D-PbvaZ7.js";
|
|
3
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId, normalizeOptionalAccountId } from "autobot/plugin-sdk/account-id";
|
|
4
|
+
import { normalizeOptionalString } from "autobot/plugin-sdk/string-coerce-runtime";
|
|
5
|
+
import { listCombinedAccountIds, listConfiguredAccountIds, resolveListedDefaultAccountId, resolveNormalizedAccountEntry } from "autobot/plugin-sdk/account-core";
|
|
6
|
+
import { hasConfiguredSecretInput } from "autobot/plugin-sdk/secret-input-runtime";
|
|
7
|
+
//#region extensions/matrix/src/auth-precedence.ts
|
|
8
|
+
const MATRIX_DEFAULT_ACCOUNT_AUTH_ONLY_FIELDS = new Set([
|
|
9
|
+
"userId",
|
|
10
|
+
"accessToken",
|
|
11
|
+
"password",
|
|
12
|
+
"deviceId"
|
|
13
|
+
]);
|
|
14
|
+
function resolveMatrixStringSourceValue(value) {
|
|
15
|
+
return typeof value === "string" ? value : "";
|
|
16
|
+
}
|
|
17
|
+
function shouldAllowBaseAuthFallback(accountId, field) {
|
|
18
|
+
return normalizeAccountId(accountId) === DEFAULT_ACCOUNT_ID || !MATRIX_DEFAULT_ACCOUNT_AUTH_ONLY_FIELDS.has(field);
|
|
19
|
+
}
|
|
20
|
+
function resolveMatrixAccountStringValues(params) {
|
|
21
|
+
const fields = [
|
|
22
|
+
"homeserver",
|
|
23
|
+
"userId",
|
|
24
|
+
"accessToken",
|
|
25
|
+
"password",
|
|
26
|
+
"deviceId",
|
|
27
|
+
"deviceName"
|
|
28
|
+
];
|
|
29
|
+
const resolved = {};
|
|
30
|
+
for (const field of fields) resolved[field] = resolveMatrixStringSourceValue(params.account?.[field]) || resolveMatrixStringSourceValue(params.scopedEnv?.[field]) || (shouldAllowBaseAuthFallback(params.accountId, field) ? resolveMatrixStringSourceValue(params.channel?.[field]) || resolveMatrixStringSourceValue(params.globalEnv?.[field]) : "");
|
|
31
|
+
return resolved;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region extensions/matrix/src/account-selection.ts
|
|
35
|
+
function readConfiguredMatrixString(value) {
|
|
36
|
+
return normalizeOptionalString(value) ?? "";
|
|
37
|
+
}
|
|
38
|
+
function readConfiguredMatrixSecretSource(value) {
|
|
39
|
+
return hasConfiguredSecretInput(value) ? "configured" : "";
|
|
40
|
+
}
|
|
41
|
+
function resolveMatrixChannelStringSources(entry) {
|
|
42
|
+
if (!entry) return {};
|
|
43
|
+
return {
|
|
44
|
+
homeserver: readConfiguredMatrixString(entry.homeserver),
|
|
45
|
+
userId: readConfiguredMatrixString(entry.userId),
|
|
46
|
+
accessToken: readConfiguredMatrixSecretSource(entry.accessToken),
|
|
47
|
+
password: readConfiguredMatrixSecretSource(entry.password),
|
|
48
|
+
deviceId: readConfiguredMatrixString(entry.deviceId),
|
|
49
|
+
deviceName: readConfiguredMatrixString(entry.deviceName)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function readEnvMatrixString(env, key) {
|
|
53
|
+
return normalizeOptionalString(env[key]) ?? "";
|
|
54
|
+
}
|
|
55
|
+
function resolveScopedMatrixEnvStringSources(accountId, env) {
|
|
56
|
+
const keys = getMatrixScopedEnvVarNames(accountId);
|
|
57
|
+
return {
|
|
58
|
+
homeserver: readEnvMatrixString(env, keys.homeserver),
|
|
59
|
+
userId: readEnvMatrixString(env, keys.userId),
|
|
60
|
+
accessToken: readEnvMatrixString(env, keys.accessToken),
|
|
61
|
+
password: readEnvMatrixString(env, keys.password),
|
|
62
|
+
deviceId: readEnvMatrixString(env, keys.deviceId),
|
|
63
|
+
deviceName: readEnvMatrixString(env, keys.deviceName)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function resolveGlobalMatrixEnvStringSources(env) {
|
|
67
|
+
return {
|
|
68
|
+
homeserver: readEnvMatrixString(env, "MATRIX_HOMESERVER"),
|
|
69
|
+
userId: readEnvMatrixString(env, "MATRIX_USER_ID"),
|
|
70
|
+
accessToken: readEnvMatrixString(env, "MATRIX_ACCESS_TOKEN"),
|
|
71
|
+
password: readEnvMatrixString(env, "MATRIX_PASSWORD"),
|
|
72
|
+
deviceId: readEnvMatrixString(env, "MATRIX_DEVICE_ID"),
|
|
73
|
+
deviceName: readEnvMatrixString(env, "MATRIX_DEVICE_NAME")
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function hasUsableResolvedMatrixAuth(values) {
|
|
77
|
+
return Boolean(values.homeserver && (values.accessToken || values.userId));
|
|
78
|
+
}
|
|
79
|
+
function hasFreshResolvedMatrixAuth(values) {
|
|
80
|
+
return Boolean(values.homeserver && (values.accessToken || values.userId && values.password));
|
|
81
|
+
}
|
|
82
|
+
function resolveEffectiveMatrixAccountSources(params) {
|
|
83
|
+
const normalizedAccountId = normalizeAccountId(params.accountId);
|
|
84
|
+
return resolveMatrixAccountStringValues({
|
|
85
|
+
accountId: normalizedAccountId,
|
|
86
|
+
scopedEnv: resolveScopedMatrixEnvStringSources(normalizedAccountId, params.env),
|
|
87
|
+
channel: resolveMatrixChannelStringSources(params.channel),
|
|
88
|
+
globalEnv: resolveGlobalMatrixEnvStringSources(params.env)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function hasUsableEffectiveMatrixAccountSource(params) {
|
|
92
|
+
return hasUsableResolvedMatrixAuth(resolveEffectiveMatrixAccountSources(params));
|
|
93
|
+
}
|
|
94
|
+
function hasFreshEffectiveMatrixAccountSource(params) {
|
|
95
|
+
return hasFreshResolvedMatrixAuth(resolveEffectiveMatrixAccountSources(params));
|
|
96
|
+
}
|
|
97
|
+
function hasConfiguredDefaultMatrixAccountSource(params) {
|
|
98
|
+
return hasFreshEffectiveMatrixAccountSource({
|
|
99
|
+
channel: params.channel,
|
|
100
|
+
accountId: DEFAULT_ACCOUNT_ID,
|
|
101
|
+
env: params.env
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function resolveMatrixChannelConfig(cfg) {
|
|
105
|
+
return isRecord(cfg.channels?.matrix) ? cfg.channels.matrix : null;
|
|
106
|
+
}
|
|
107
|
+
function findMatrixAccountEntry(cfg, accountId) {
|
|
108
|
+
const channel = resolveMatrixChannelConfig(cfg);
|
|
109
|
+
if (!channel) return null;
|
|
110
|
+
const accounts = isRecord(channel.accounts) ? channel.accounts : null;
|
|
111
|
+
if (!accounts) return null;
|
|
112
|
+
const entry = resolveNormalizedAccountEntry(accounts, accountId, normalizeAccountId);
|
|
113
|
+
return isRecord(entry) ? entry : null;
|
|
114
|
+
}
|
|
115
|
+
function resolveConfiguredMatrixAccountIds(cfg, env = process.env) {
|
|
116
|
+
const channel = resolveMatrixChannelConfig(cfg);
|
|
117
|
+
const configuredAccountIds = listConfiguredAccountIds({
|
|
118
|
+
accounts: channel && isRecord(channel.accounts) ? channel.accounts : void 0,
|
|
119
|
+
normalizeAccountId
|
|
120
|
+
});
|
|
121
|
+
if (hasConfiguredDefaultMatrixAccountSource({
|
|
122
|
+
channel,
|
|
123
|
+
env
|
|
124
|
+
})) configuredAccountIds.push(DEFAULT_ACCOUNT_ID);
|
|
125
|
+
return listCombinedAccountIds({
|
|
126
|
+
configuredAccountIds,
|
|
127
|
+
additionalAccountIds: listMatrixEnvAccountIds(env).filter((accountId) => normalizeAccountId(accountId) === DEFAULT_ACCOUNT_ID ? hasConfiguredDefaultMatrixAccountSource({
|
|
128
|
+
channel,
|
|
129
|
+
env
|
|
130
|
+
}) : hasUsableEffectiveMatrixAccountSource({
|
|
131
|
+
channel,
|
|
132
|
+
accountId,
|
|
133
|
+
env
|
|
134
|
+
})),
|
|
135
|
+
fallbackAccountIdWhenEmpty: channel ? DEFAULT_ACCOUNT_ID : void 0
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function resolveMatrixDefaultOrOnlyAccountId(cfg, env = process.env) {
|
|
139
|
+
const channel = resolveMatrixChannelConfig(cfg);
|
|
140
|
+
if (!channel) return DEFAULT_ACCOUNT_ID;
|
|
141
|
+
const configuredDefault = normalizeOptionalAccountId(typeof channel.defaultAccount === "string" ? channel.defaultAccount : void 0);
|
|
142
|
+
return resolveListedDefaultAccountId({
|
|
143
|
+
accountIds: resolveConfiguredMatrixAccountIds(cfg, env),
|
|
144
|
+
configuredDefaultAccountId: configuredDefault,
|
|
145
|
+
ambiguousFallbackAccountId: DEFAULT_ACCOUNT_ID
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function requiresExplicitMatrixDefaultAccount(cfg, env = process.env) {
|
|
149
|
+
const channel = resolveMatrixChannelConfig(cfg);
|
|
150
|
+
if (!channel) return false;
|
|
151
|
+
const configuredAccountIds = resolveConfiguredMatrixAccountIds(cfg, env);
|
|
152
|
+
if (configuredAccountIds.length <= 1) return false;
|
|
153
|
+
if (configuredAccountIds.includes(DEFAULT_ACCOUNT_ID)) return false;
|
|
154
|
+
const configuredDefault = normalizeOptionalAccountId(typeof channel.defaultAccount === "string" ? channel.defaultAccount : void 0);
|
|
155
|
+
return !(configuredDefault && configuredAccountIds.includes(configuredDefault));
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { resolveMatrixDefaultOrOnlyAccountId as a, resolveMatrixChannelConfig as i, requiresExplicitMatrixDefaultAccount as n, resolveMatrixAccountStringValues as o, resolveConfiguredMatrixAccountIds as r, findMatrixAccountEntry as t };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "autobot/plugin-sdk/account-id";
|
|
2
|
+
//#region extensions/matrix/src/matrix/active-client.ts
|
|
3
|
+
const activeClients = /* @__PURE__ */ new Map();
|
|
4
|
+
function resolveAccountKey(accountId) {
|
|
5
|
+
return normalizeAccountId(accountId) || DEFAULT_ACCOUNT_ID;
|
|
6
|
+
}
|
|
7
|
+
function setActiveMatrixClient(client, accountId) {
|
|
8
|
+
const key = resolveAccountKey(accountId);
|
|
9
|
+
if (!client) {
|
|
10
|
+
activeClients.delete(key);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
activeClients.set(key, client);
|
|
14
|
+
}
|
|
15
|
+
function getActiveMatrixClient(accountId) {
|
|
16
|
+
const key = resolveAccountKey(accountId);
|
|
17
|
+
return activeClients.get(key) ?? null;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { setActiveMatrixClient as n, getActiveMatrixClient as t };
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { d as setMatrixThreadBindingIdleTimeoutBySessionKey, n as getMatrixThreadBindingManager, p as setMatrixThreadBindingMaxAgeBySessionKey, s as resetMatrixThreadBindingsForTests } from "./thread-bindings-shared-4nkBBftw.js";
|
|
2
|
+
import { a as resolveMatrixDefaultOrOnlyAccountId, i as resolveMatrixChannelConfig, n as requiresExplicitMatrixDefaultAccount, r as resolveConfiguredMatrixAccountIds, t as findMatrixAccountEntry } from "./account-selection-D4xDzY_1.js";
|
|
3
|
+
import { n as listMatrixEnvAccountIds, r as resolveMatrixEnvAccountToken, t as getMatrixScopedEnvVarNames } from "./env-vars-Ch51id3Y.js";
|
|
4
|
+
import { a as resolveMatrixCredentialsPath, c as resolveMatrixLegacyFlatStoreRoot, i as resolveMatrixCredentialsFilename, l as sanitizeMatrixPathSegment, n as resolveMatrixAccountStorageRoot, o as resolveMatrixHomeserverKey, r as resolveMatrixCredentialsDir, s as resolveMatrixLegacyFlatStoragePaths, t as hashMatrixAccessToken } from "./storage-paths-BcLg30GH.js";
|
|
5
|
+
import { n as matrixSetupAdapter, t as createMatrixSetupWizardProxy } from "./setup-core-CmXNGvQt.js";
|
|
6
|
+
import { t as matrixPlugin } from "./channel-CVtvS1kS.js";
|
|
7
|
+
import { n as matrixOnboardingAdapter } from "./setup-surface-zTLHNBns.js";
|
|
8
|
+
import { t as createMatrixThreadBindingManager } from "./thread-bindings-owbheXoV.js";
|
|
9
|
+
//#region extensions/matrix/api.ts
|
|
10
|
+
const matrixSessionBindingAdapterChannels = ["matrix"];
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createMatrixSetupWizardProxy, createMatrixThreadBindingManager, findMatrixAccountEntry, getMatrixScopedEnvVarNames, getMatrixThreadBindingManager, hashMatrixAccessToken, listMatrixEnvAccountIds, matrixOnboardingAdapter, matrixOnboardingAdapter as matrixSetupWizard, matrixPlugin, matrixSessionBindingAdapterChannels, matrixSetupAdapter, requiresExplicitMatrixDefaultAccount, resetMatrixThreadBindingsForTests, resolveConfiguredMatrixAccountIds, resolveMatrixAccountStorageRoot, resolveMatrixChannelConfig, resolveMatrixCredentialsDir, resolveMatrixCredentialsFilename, resolveMatrixCredentialsPath, resolveMatrixDefaultOrOnlyAccountId, resolveMatrixEnvAccountToken, resolveMatrixHomeserverKey, resolveMatrixLegacyFlatStoragePaths, resolveMatrixLegacyFlatStoreRoot, sanitizeMatrixPathSegment, setMatrixThreadBindingIdleTimeoutBySessionKey, setMatrixThreadBindingMaxAgeBySessionKey };
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { a as resolveMatrixTargetIdentity } from "./target-ids-iZwjCUZa.js";
|
|
2
|
+
import { g as resolveMatrixAccount } from "./setup-core-CmXNGvQt.js";
|
|
3
|
+
import { _ as shouldHandleMatrixApprovalRequest, g as isMatrixAnyApprovalClientEnabled } from "./channel-CVtvS1kS.js";
|
|
4
|
+
import { a as sendMessageMatrix, i as reactMatrixMessage, p as repairMatrixDirectRooms, s as sendSingleTextMessageMatrix } from "./send-CWOxcUMq.js";
|
|
5
|
+
import { a as unregisterMatrixApprovalReactionTarget, n as listMatrixApprovalReactionBindings, r as registerMatrixApprovalReactionTarget, t as buildMatrixApprovalReactionHint } from "./approval-reactions-C7FrzFhD.js";
|
|
6
|
+
import { n as editMatrixMessage, t as deleteMatrixMessage } from "./messages-BM8v2OhM.js";
|
|
7
|
+
import { listMessageReceiptPlatformIds, resolveMessageReceiptPrimaryId } from "autobot/plugin-sdk/channel-message";
|
|
8
|
+
import { buildChannelApprovalNativeTargetKey } from "autobot/plugin-sdk/approval-native-runtime";
|
|
9
|
+
import { setTimeout } from "node:timers/promises";
|
|
10
|
+
import { createChannelApprovalNativeRuntimeAdapter } from "autobot/plugin-sdk/approval-handler-runtime";
|
|
11
|
+
import { buildExecApprovalPendingReplyPayload, buildPluginApprovalPendingReplyPayload } from "autobot/plugin-sdk/approval-reply-runtime";
|
|
12
|
+
import { buildPluginApprovalResolvedReplyPayload } from "autobot/plugin-sdk/approval-runtime";
|
|
13
|
+
//#region extensions/matrix/src/approval-handler.runtime.ts
|
|
14
|
+
const MATRIX_APPROVAL_METADATA_KEY = "com.autobot.approval";
|
|
15
|
+
const MATRIX_APPROVAL_DELIVERY_ATTEMPTS = 3;
|
|
16
|
+
const MATRIX_APPROVAL_DELIVERY_RETRY_DELAY_MS = 250;
|
|
17
|
+
function resolveHandlerContext(params) {
|
|
18
|
+
const context = params.context;
|
|
19
|
+
const accountId = params.accountId?.trim() || "";
|
|
20
|
+
if (!context?.client || !accountId) return null;
|
|
21
|
+
return {
|
|
22
|
+
accountId,
|
|
23
|
+
context
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function normalizePendingMessageIds(entry) {
|
|
27
|
+
return Array.from(new Set(entry.platformMessageIds.map((messageId) => messageId.trim()).filter(Boolean)));
|
|
28
|
+
}
|
|
29
|
+
function normalizeReactionTargetRef(params) {
|
|
30
|
+
const roomId = params.roomId.trim();
|
|
31
|
+
const eventId = params.eventId.trim();
|
|
32
|
+
if (!roomId || !eventId) return null;
|
|
33
|
+
return {
|
|
34
|
+
roomId,
|
|
35
|
+
eventId
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function normalizeThreadId(value) {
|
|
39
|
+
return (value == null ? "" : String(value).trim()) || void 0;
|
|
40
|
+
}
|
|
41
|
+
function isSingleMatrixMessageLimitError(error) {
|
|
42
|
+
return error instanceof Error && error.message.includes("Matrix single-message text exceeds limit");
|
|
43
|
+
}
|
|
44
|
+
async function retryMatrixApprovalDelivery(operation, params = {}) {
|
|
45
|
+
let lastError;
|
|
46
|
+
for (let attempt = 1; attempt <= MATRIX_APPROVAL_DELIVERY_ATTEMPTS; attempt += 1) try {
|
|
47
|
+
return await operation();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
lastError = error;
|
|
50
|
+
if (attempt === MATRIX_APPROVAL_DELIVERY_ATTEMPTS || params.shouldRetry?.(error) === false) break;
|
|
51
|
+
await setTimeout(MATRIX_APPROVAL_DELIVERY_RETRY_DELAY_MS * attempt);
|
|
52
|
+
}
|
|
53
|
+
throw lastError;
|
|
54
|
+
}
|
|
55
|
+
async function prepareTarget(params) {
|
|
56
|
+
const resolved = resolveHandlerContext(params);
|
|
57
|
+
if (!resolved) return null;
|
|
58
|
+
const target = resolveMatrixTargetIdentity(params.rawTarget.to);
|
|
59
|
+
if (!target) return null;
|
|
60
|
+
const threadId = normalizeThreadId(params.rawTarget.threadId);
|
|
61
|
+
if (target.kind === "user") {
|
|
62
|
+
const account = resolveMatrixAccount({
|
|
63
|
+
cfg: params.cfg,
|
|
64
|
+
accountId: resolved.accountId
|
|
65
|
+
});
|
|
66
|
+
const repairDirectRooms = resolved.context.deps?.repairDirectRooms ?? repairMatrixDirectRooms;
|
|
67
|
+
const repaired = await retryMatrixApprovalDelivery(async () => await repairDirectRooms({
|
|
68
|
+
client: resolved.context.client,
|
|
69
|
+
remoteUserId: target.id,
|
|
70
|
+
encrypted: account.config.encryption === true
|
|
71
|
+
}));
|
|
72
|
+
if (!repaired.activeRoomId) return null;
|
|
73
|
+
return {
|
|
74
|
+
to: `room:${repaired.activeRoomId}`,
|
|
75
|
+
roomId: repaired.activeRoomId,
|
|
76
|
+
threadId
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
to: `room:${target.id}`,
|
|
81
|
+
roomId: target.id,
|
|
82
|
+
threadId
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function buildMatrixApprovalMetadata(params) {
|
|
86
|
+
const base = {
|
|
87
|
+
version: 1,
|
|
88
|
+
type: "approval.request",
|
|
89
|
+
id: params.view.approvalId,
|
|
90
|
+
state: "pending",
|
|
91
|
+
kind: params.view.approvalKind,
|
|
92
|
+
phase: params.view.phase,
|
|
93
|
+
title: params.view.title,
|
|
94
|
+
expiresAtMs: params.view.expiresAtMs,
|
|
95
|
+
metadata: params.view.metadata,
|
|
96
|
+
allowedDecisions: Array.from(params.allowedDecisions),
|
|
97
|
+
actions: params.view.actions.map((action) => ({
|
|
98
|
+
decision: action.decision,
|
|
99
|
+
label: action.label,
|
|
100
|
+
style: action.style,
|
|
101
|
+
command: action.command
|
|
102
|
+
})),
|
|
103
|
+
...params.view.description != null ? { description: params.view.description } : {}
|
|
104
|
+
};
|
|
105
|
+
if (params.view.approvalKind === "plugin") return {
|
|
106
|
+
...base,
|
|
107
|
+
kind: "plugin",
|
|
108
|
+
severity: params.view.severity,
|
|
109
|
+
...params.view.agentId != null ? { agentId: params.view.agentId } : {},
|
|
110
|
+
...params.view.pluginId != null ? { pluginId: params.view.pluginId } : {},
|
|
111
|
+
...params.view.toolName != null ? { toolName: params.view.toolName } : {}
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
...base,
|
|
115
|
+
kind: "exec",
|
|
116
|
+
commandText: params.view.commandText,
|
|
117
|
+
...params.view.ask != null ? { ask: params.view.ask } : {},
|
|
118
|
+
...params.view.agentId != null ? { agentId: params.view.agentId } : {},
|
|
119
|
+
...params.view.commandPreview != null ? { commandPreview: params.view.commandPreview } : {},
|
|
120
|
+
...params.view.cwd != null ? { cwd: params.view.cwd } : {},
|
|
121
|
+
...params.view.envKeys != null ? { envKeys: params.view.envKeys } : {},
|
|
122
|
+
...params.view.host != null ? { host: params.view.host } : {},
|
|
123
|
+
...params.view.nodeId != null ? { nodeId: params.view.nodeId } : {},
|
|
124
|
+
...params.view.sessionKey != null ? { sessionKey: params.view.sessionKey } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function buildPendingApprovalContent(params) {
|
|
128
|
+
const allowedDecisions = params.view.actions.map((action) => action.decision);
|
|
129
|
+
const payload = params.view.approvalKind === "plugin" ? buildPluginApprovalPendingReplyPayload({
|
|
130
|
+
request: {
|
|
131
|
+
id: params.view.approvalId,
|
|
132
|
+
request: {
|
|
133
|
+
title: params.view.title,
|
|
134
|
+
description: params.view.description ?? "",
|
|
135
|
+
severity: params.view.severity,
|
|
136
|
+
toolName: params.view.toolName ?? void 0,
|
|
137
|
+
pluginId: params.view.pluginId ?? void 0,
|
|
138
|
+
agentId: params.view.agentId ?? void 0
|
|
139
|
+
},
|
|
140
|
+
createdAtMs: 0,
|
|
141
|
+
expiresAtMs: params.view.expiresAtMs
|
|
142
|
+
},
|
|
143
|
+
nowMs: params.nowMs,
|
|
144
|
+
allowedDecisions
|
|
145
|
+
}) : buildExecApprovalPendingReplyPayload({
|
|
146
|
+
approvalId: params.view.approvalId,
|
|
147
|
+
approvalSlug: params.view.approvalId.slice(0, 8),
|
|
148
|
+
approvalCommandId: params.view.approvalId,
|
|
149
|
+
ask: params.view.ask ?? void 0,
|
|
150
|
+
agentId: params.view.agentId ?? void 0,
|
|
151
|
+
allowedDecisions,
|
|
152
|
+
command: params.view.commandText,
|
|
153
|
+
cwd: params.view.cwd ?? void 0,
|
|
154
|
+
host: params.view.host === "node" ? "node" : "gateway",
|
|
155
|
+
nodeId: params.view.nodeId ?? void 0,
|
|
156
|
+
sessionKey: params.view.sessionKey ?? void 0,
|
|
157
|
+
expiresAtMs: params.view.expiresAtMs,
|
|
158
|
+
nowMs: params.nowMs
|
|
159
|
+
});
|
|
160
|
+
const hint = buildMatrixApprovalReactionHint(allowedDecisions);
|
|
161
|
+
const text = payload.text ?? "";
|
|
162
|
+
return {
|
|
163
|
+
approvalId: params.view.approvalId,
|
|
164
|
+
text: hint ? text ? `${hint}\n\n${text}` : hint : text,
|
|
165
|
+
allowedDecisions,
|
|
166
|
+
extraContent: { [MATRIX_APPROVAL_METADATA_KEY]: buildMatrixApprovalMetadata({
|
|
167
|
+
view: params.view,
|
|
168
|
+
allowedDecisions
|
|
169
|
+
}) }
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function buildResolvedApprovalText(view) {
|
|
173
|
+
if (view.approvalKind === "plugin") return buildPluginApprovalResolvedReplyPayload({ resolved: {
|
|
174
|
+
id: view.approvalId,
|
|
175
|
+
decision: view.decision,
|
|
176
|
+
resolvedBy: view.resolvedBy ?? void 0,
|
|
177
|
+
ts: 0
|
|
178
|
+
} }).text ?? "";
|
|
179
|
+
return [
|
|
180
|
+
`Exec approval: ${view.decision === "allow-once" ? "Allowed once" : view.decision === "allow-always" ? "Allowed always" : "Denied"}`,
|
|
181
|
+
"",
|
|
182
|
+
"Command",
|
|
183
|
+
buildMarkdownCodeBlock(view.commandText)
|
|
184
|
+
].join("\n");
|
|
185
|
+
}
|
|
186
|
+
function buildMarkdownCodeBlock(text) {
|
|
187
|
+
const longestFence = Math.max(...Array.from(text.matchAll(/`+/g), (match) => match[0].length), 0);
|
|
188
|
+
const fence = "`".repeat(Math.max(3, longestFence + 1));
|
|
189
|
+
return [
|
|
190
|
+
fence,
|
|
191
|
+
text,
|
|
192
|
+
fence
|
|
193
|
+
].join("\n");
|
|
194
|
+
}
|
|
195
|
+
const matrixApprovalNativeRuntime = createChannelApprovalNativeRuntimeAdapter({
|
|
196
|
+
eventKinds: ["exec", "plugin"],
|
|
197
|
+
availability: {
|
|
198
|
+
isConfigured: ({ cfg, accountId, context }) => {
|
|
199
|
+
const resolved = resolveHandlerContext({
|
|
200
|
+
cfg,
|
|
201
|
+
accountId,
|
|
202
|
+
context
|
|
203
|
+
});
|
|
204
|
+
if (!resolved) return false;
|
|
205
|
+
return isMatrixAnyApprovalClientEnabled({
|
|
206
|
+
cfg,
|
|
207
|
+
accountId: resolved.accountId
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
shouldHandle: ({ cfg, accountId, request, context }) => {
|
|
211
|
+
const resolved = resolveHandlerContext({
|
|
212
|
+
cfg,
|
|
213
|
+
accountId,
|
|
214
|
+
context
|
|
215
|
+
});
|
|
216
|
+
if (!resolved) return false;
|
|
217
|
+
return shouldHandleMatrixApprovalRequest({
|
|
218
|
+
cfg,
|
|
219
|
+
accountId: resolved.accountId,
|
|
220
|
+
request
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
presentation: {
|
|
225
|
+
buildPendingPayload: ({ view, nowMs }) => buildPendingApprovalContent({
|
|
226
|
+
view,
|
|
227
|
+
nowMs
|
|
228
|
+
}),
|
|
229
|
+
buildResolvedResult: ({ view }) => ({
|
|
230
|
+
kind: "update",
|
|
231
|
+
payload: buildResolvedApprovalText(view)
|
|
232
|
+
}),
|
|
233
|
+
buildExpiredResult: () => ({ kind: "delete" })
|
|
234
|
+
},
|
|
235
|
+
transport: {
|
|
236
|
+
prepareTarget: ({ cfg, accountId, context, plannedTarget }) => {
|
|
237
|
+
return prepareTarget({
|
|
238
|
+
cfg,
|
|
239
|
+
accountId,
|
|
240
|
+
context,
|
|
241
|
+
rawTarget: plannedTarget.target
|
|
242
|
+
}).then((preparedTarget) => preparedTarget ? {
|
|
243
|
+
dedupeKey: buildChannelApprovalNativeTargetKey({
|
|
244
|
+
to: preparedTarget.roomId,
|
|
245
|
+
threadId: preparedTarget.threadId
|
|
246
|
+
}),
|
|
247
|
+
target: preparedTarget
|
|
248
|
+
} : null);
|
|
249
|
+
},
|
|
250
|
+
deliverPending: async ({ cfg, accountId, context, preparedTarget, pendingPayload, view }) => {
|
|
251
|
+
const resolved = resolveHandlerContext({
|
|
252
|
+
cfg,
|
|
253
|
+
accountId,
|
|
254
|
+
context
|
|
255
|
+
});
|
|
256
|
+
if (!resolved) return null;
|
|
257
|
+
const sendSingleTextMessage = resolved.context.deps?.sendSingleTextMessage ?? sendSingleTextMessageMatrix;
|
|
258
|
+
const reactMessage = resolved.context.deps?.reactMessage ?? reactMatrixMessage;
|
|
259
|
+
let result;
|
|
260
|
+
try {
|
|
261
|
+
result = await retryMatrixApprovalDelivery(async () => await sendSingleTextMessage(preparedTarget.to, pendingPayload.text, {
|
|
262
|
+
cfg,
|
|
263
|
+
accountId: resolved.accountId,
|
|
264
|
+
client: resolved.context.client,
|
|
265
|
+
threadId: preparedTarget.threadId,
|
|
266
|
+
extraContent: pendingPayload.extraContent
|
|
267
|
+
}), { shouldRetry: (error) => !isSingleMatrixMessageLimitError(error) });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (!isSingleMatrixMessageLimitError(error)) throw error;
|
|
270
|
+
const sendMessage = resolved.context.deps?.sendMessage ?? sendMessageMatrix;
|
|
271
|
+
result = await retryMatrixApprovalDelivery(async () => await sendMessage(preparedTarget.to, pendingPayload.text, {
|
|
272
|
+
cfg,
|
|
273
|
+
accountId: resolved.accountId,
|
|
274
|
+
client: resolved.context.client,
|
|
275
|
+
threadId: preparedTarget.threadId,
|
|
276
|
+
extraContent: pendingPayload.extraContent
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
const receiptMessageIds = listMessageReceiptPlatformIds(result.receipt);
|
|
280
|
+
const platformMessageIds = receiptMessageIds.length ? receiptMessageIds : [result.messageId.trim()].filter(Boolean);
|
|
281
|
+
const reactionEventId = resolveMessageReceiptPrimaryId(result.receipt) || result.primaryMessageId?.trim() || platformMessageIds[0] || result.messageId.trim();
|
|
282
|
+
registerMatrixApprovalReactionTarget({
|
|
283
|
+
roomId: result.roomId,
|
|
284
|
+
eventId: reactionEventId,
|
|
285
|
+
approvalId: pendingPayload.approvalId,
|
|
286
|
+
allowedDecisions: pendingPayload.allowedDecisions,
|
|
287
|
+
ttlMs: view.expiresAtMs - Date.now()
|
|
288
|
+
});
|
|
289
|
+
await Promise.allSettled(listMatrixApprovalReactionBindings(pendingPayload.allowedDecisions).map(async ({ emoji }) => {
|
|
290
|
+
await reactMessage(result.roomId, reactionEventId, emoji, {
|
|
291
|
+
cfg,
|
|
292
|
+
accountId: resolved.accountId,
|
|
293
|
+
client: resolved.context.client
|
|
294
|
+
});
|
|
295
|
+
}));
|
|
296
|
+
return {
|
|
297
|
+
roomId: result.roomId,
|
|
298
|
+
platformMessageIds,
|
|
299
|
+
reactionEventId
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
updateEntry: async ({ cfg, accountId, context, entry, payload }) => {
|
|
303
|
+
const resolved = resolveHandlerContext({
|
|
304
|
+
cfg,
|
|
305
|
+
accountId,
|
|
306
|
+
context
|
|
307
|
+
});
|
|
308
|
+
if (!resolved) return;
|
|
309
|
+
const editMessage = resolved.context.deps?.editMessage ?? editMatrixMessage;
|
|
310
|
+
const deleteMessage = resolved.context.deps?.deleteMessage ?? deleteMatrixMessage;
|
|
311
|
+
const [primaryMessageId, ...staleMessageIds] = normalizePendingMessageIds(entry);
|
|
312
|
+
if (!primaryMessageId) return;
|
|
313
|
+
const text = payload;
|
|
314
|
+
await Promise.allSettled([editMessage(entry.roomId, primaryMessageId, text, {
|
|
315
|
+
cfg,
|
|
316
|
+
accountId: resolved.accountId,
|
|
317
|
+
client: resolved.context.client
|
|
318
|
+
}), ...staleMessageIds.map(async (messageId) => {
|
|
319
|
+
await deleteMessage(entry.roomId, messageId, {
|
|
320
|
+
cfg,
|
|
321
|
+
accountId: resolved.accountId,
|
|
322
|
+
client: resolved.context.client,
|
|
323
|
+
reason: "approval resolved"
|
|
324
|
+
});
|
|
325
|
+
})]);
|
|
326
|
+
},
|
|
327
|
+
deleteEntry: async ({ cfg, accountId, context, entry, phase }) => {
|
|
328
|
+
const resolved = resolveHandlerContext({
|
|
329
|
+
cfg,
|
|
330
|
+
accountId,
|
|
331
|
+
context
|
|
332
|
+
});
|
|
333
|
+
if (!resolved) return;
|
|
334
|
+
const deleteMessage = resolved.context.deps?.deleteMessage ?? deleteMatrixMessage;
|
|
335
|
+
await Promise.allSettled(normalizePendingMessageIds(entry).map(async (messageId) => {
|
|
336
|
+
await deleteMessage(entry.roomId, messageId, {
|
|
337
|
+
cfg,
|
|
338
|
+
accountId: resolved.accountId,
|
|
339
|
+
client: resolved.context.client,
|
|
340
|
+
reason: phase === "expired" ? "approval expired" : "approval resolved"
|
|
341
|
+
});
|
|
342
|
+
}));
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
interactions: {
|
|
346
|
+
bindPending: (params) => {
|
|
347
|
+
const target = normalizeReactionTargetRef({
|
|
348
|
+
roomId: params.entry.roomId,
|
|
349
|
+
eventId: params.entry.reactionEventId
|
|
350
|
+
});
|
|
351
|
+
if (!target) return null;
|
|
352
|
+
registerMatrixApprovalReactionTarget({
|
|
353
|
+
roomId: target.roomId,
|
|
354
|
+
eventId: target.eventId,
|
|
355
|
+
approvalId: params.pendingPayload.approvalId,
|
|
356
|
+
allowedDecisions: params.pendingPayload.allowedDecisions,
|
|
357
|
+
ttlMs: params.view.expiresAtMs - Date.now()
|
|
358
|
+
});
|
|
359
|
+
return target;
|
|
360
|
+
},
|
|
361
|
+
unbindPending: (params) => {
|
|
362
|
+
const target = normalizeReactionTargetRef(params.binding);
|
|
363
|
+
if (!target) return;
|
|
364
|
+
unregisterMatrixApprovalReactionTarget(target);
|
|
365
|
+
},
|
|
366
|
+
cancelDelivered: (params) => {
|
|
367
|
+
const target = normalizeReactionTargetRef({
|
|
368
|
+
roomId: params.entry.roomId,
|
|
369
|
+
eventId: params.entry.reactionEventId
|
|
370
|
+
});
|
|
371
|
+
if (!target) return;
|
|
372
|
+
unregisterMatrixApprovalReactionTarget(target);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
//#endregion
|
|
377
|
+
export { matrixApprovalNativeRuntime };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { a as normalizeMatrixUserId } from "./config-schema-ON2KZjSH.js";
|
|
2
|
+
//#region extensions/matrix/src/approval-ids.ts
|
|
3
|
+
function normalizeMatrixApproverId(value) {
|
|
4
|
+
return normalizeMatrixUserId(String(value)) || void 0;
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { normalizeMatrixApproverId as t };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { g as resolveMatrixAccount } from "./setup-core-CmXNGvQt.js";
|
|
2
|
+
import { t as normalizeMatrixApproverId } from "./approval-ids-Bj1MSuK0.js";
|
|
3
|
+
import { resolveApprovalApprovers } from "autobot/plugin-sdk/approval-auth-runtime";
|
|
4
|
+
//#region extensions/matrix/src/approval-reaction-auth.ts
|
|
5
|
+
function normalizeMatrixExecApproverId(value) {
|
|
6
|
+
const normalized = normalizeMatrixApproverId(value);
|
|
7
|
+
return normalized === "*" ? void 0 : normalized;
|
|
8
|
+
}
|
|
9
|
+
function getMatrixApprovalReactionApprovers(params) {
|
|
10
|
+
const account = resolveMatrixAccount(params).config;
|
|
11
|
+
if (params.approvalKind === "plugin") return resolveApprovalApprovers({
|
|
12
|
+
allowFrom: account.dm?.allowFrom,
|
|
13
|
+
normalizeApprover: normalizeMatrixApproverId
|
|
14
|
+
});
|
|
15
|
+
return resolveApprovalApprovers({
|
|
16
|
+
explicit: account.execApprovals?.approvers,
|
|
17
|
+
allowFrom: account.dm?.allowFrom,
|
|
18
|
+
normalizeApprover: normalizeMatrixExecApproverId
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function isMatrixApprovalReactionAuthorizedSender(params) {
|
|
22
|
+
const normalizedSenderId = params.senderId ? normalizeMatrixApproverId(params.senderId) : void 0;
|
|
23
|
+
if (!normalizedSenderId) return false;
|
|
24
|
+
return getMatrixApprovalReactionApprovers(params).includes(normalizedSenderId);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isMatrixApprovalReactionAuthorizedSender };
|