@openclaw/matrix 2026.3.12 → 2026.5.9-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-config-D2W-V1eQ.js +96 -0
- package/dist/account-selection-BWwIruri.js +158 -0
- package/dist/accounts-Bm90Rzvp.js +130 -0
- package/dist/active-client-uhlxdhEy.js +20 -0
- package/dist/allowlist-sTzpCn5d.js +68 -0
- package/dist/api.js +12 -0
- package/dist/approval-handler.runtime-DWTQfd4m.js +370 -0
- package/dist/approval-ids-DoC2z7tR.js +7 -0
- package/dist/approval-reaction-auth-DbcA1gGd.js +27 -0
- package/dist/approval-reactions-o2_tuH8D.js +162 -0
- package/dist/async-lock-uQfhfQIY.js +19 -0
- package/dist/auth-presence.js +26 -0
- package/dist/backup-health-Cabu_WQC.js +60 -0
- package/dist/channel-DJNir3Rb.js +1116 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BQu0hTih.js +246 -0
- package/dist/cli-BmfTmg7x.js +1340 -0
- package/dist/cli-metadata-B-PCEzrA.js +22 -0
- package/dist/cli-metadata.js +2 -0
- package/dist/client-DkcXnm0X.js +25 -0
- package/dist/client-_hckQNGW.js +31 -0
- package/dist/client-bootstrap-Rb8oHvhH.js +114 -0
- package/dist/config--5-S2Akv.js +452 -0
- package/dist/config-paths-nsVaysCu.js +19 -0
- package/dist/config-schema-nPLpEgHl.js +200 -0
- package/dist/config-secret-input.runtime-DiKFehsE.js +2 -0
- package/dist/config-update-wZX-HLMn.js +143 -0
- package/dist/contract-api.js +9 -0
- package/dist/create-client-DCnqDaqd.js +64 -0
- package/dist/credentials-DV6fWXhC.js +56 -0
- package/dist/credentials-read-cmHgousK.js +112 -0
- package/dist/credentials-write.runtime-zniTq-Gr.js +17 -0
- package/dist/crypto-node.runtime-pihzdpY7.js +12 -0
- package/dist/crypto-runtime-ZI0zAtn3.js +1214 -0
- package/dist/deps-C6WqKY7m.js +235 -0
- package/dist/device-health-UVYpbA_W.js +16 -0
- package/dist/direct-management-DMMMgtTB.js +249 -0
- package/dist/direct-room-XkutHjES.js +76 -0
- package/dist/directory-live-DmOtMhyr.js +150 -0
- package/dist/doctor-C4__7c-U.js +153 -0
- package/dist/doctor-contract-D4-64QuJ.js +246 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/draft-stream-BE2QevQQ.js +144 -0
- package/dist/encryption-guidance-BPi3A_m3.js +15 -0
- package/dist/env-auth-BJqGI8M6.js +63 -0
- package/dist/env-vars-C7uQCTKn.js +63 -0
- package/dist/errors-CTcpEDq-.js +17 -0
- package/dist/exec-approval-resolver-Bza9Dhlm.js +15 -0
- package/dist/exec-approvals-Crnh543m.js +196 -0
- package/dist/helper-api.js +4 -0
- package/dist/http-client-C7AeVJay.js +319 -0
- package/dist/index.js +46 -0
- package/dist/legacy-crypto-inspector-poDWldgy.js +41 -0
- package/dist/legacy-crypto-restore-Biw-w2ng.js +85 -0
- package/dist/logger-CnZRVrux.js +78 -0
- package/dist/logging-DZHSPP5N.js +99 -0
- package/dist/matrix-migration.runtime-WY6ffcrf.js +525 -0
- package/dist/media-text-DU6nWZuj.js +146 -0
- package/dist/messages-BpihMh82.js +140 -0
- package/dist/migration-snapshot-backup-DaCHTp8C.js +69 -0
- package/dist/migration-snapshot.runtime-CKHE3xF9.js +2 -0
- package/dist/monitor-C_81r_Ck.js +4125 -0
- package/dist/plugin-entry.handlers.runtime.js +51 -0
- package/dist/probe.runtime-BvAzYAIe.js +3 -0
- package/dist/profile-BlHu0wDX.js +111 -0
- package/dist/profile-update-DjeBNgIV.js +69 -0
- package/dist/reaction-common-ejrL19w-.js +71 -0
- package/dist/reaction-events-CiARZfjk.js +121 -0
- package/dist/record-shared-CHWJCTWf.js +2 -0
- package/dist/recovery-key-store-BTJ6jz5v.js +294 -0
- package/dist/resolve-targets-YtJnw1Tb.js +140 -0
- package/dist/resolver.runtime-D9piiGEl.js +5 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/route-D6rg-iXN.js +161 -0
- package/dist/runtime-C6X4h_SJ.js +6 -0
- package/dist/runtime-Dog86njy.js +8 -0
- package/dist/runtime-api-BXWBFIqm.js +25 -0
- package/dist/runtime-api.js +25 -0
- package/dist/runtime-heavy-api.js +3 -0
- package/dist/runtime-setter-api.js +2 -0
- package/dist/sdk-B2vZA27-.js +1416 -0
- package/dist/secret-contract-DcrJWCQI.js +120 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/send-Bo0DU1ca.js +1200 -0
- package/dist/session-store-metadata-DI5SCofx.js +77 -0
- package/dist/setup-bootstrap-ImenBsMt.js +62 -0
- package/dist/setup-core-CfZy05oW.js +116 -0
- package/dist/setup-dm-policy-2-r1FrQh.js +194 -0
- package/dist/setup-entry.js +19 -0
- package/dist/setup-plugin-api.js +44 -0
- package/dist/setup-surface-CqT_o61M.js +540 -0
- package/dist/shared-CpMoYKm1.js +195 -0
- package/dist/startup-abort-56edvmbM.js +32 -0
- package/dist/startup-verification-Demyp0bP.js +132 -0
- package/dist/storage-paths-BJLdnCjV.js +52 -0
- package/dist/storage-tC3ujLiW.js +281 -0
- package/dist/subagent-hooks-DQbyqq9V.js +149 -0
- package/dist/subagent-hooks-api.js +23 -0
- package/dist/sync-state-C_beeevA.js +12 -0
- package/dist/target-ids-80nQ2gql.js +77 -0
- package/dist/test-api.js +4 -0
- package/dist/thread-binding-api-Cq_E-E1K.js +17 -0
- package/dist/thread-binding-api.js +2 -0
- package/dist/thread-bindings-B9mesxXk.js +352 -0
- package/dist/thread-bindings-runtime.js +2 -0
- package/dist/thread-bindings-shared-DK-d-oYX.js +97 -0
- package/dist/timeout-abort-signal-CtaIaP1v.js +2 -0
- package/dist/tool-actions.runtime-BIH49vRr.js +532 -0
- package/dist/url-validation-DiK9j7jz.js +36 -0
- package/dist/verification-CZ2rDeHL.js +345 -0
- package/openclaw.plugin.json +788 -1
- package/package.json +82 -16
- package/CHANGELOG.md +0 -98
- package/index.ts +0 -22
- package/src/actions.ts +0 -195
- package/src/channel.directory.test.ts +0 -154
- package/src/channel.ts +0 -461
- package/src/config-schema.test.ts +0 -26
- package/src/config-schema.ts +0 -62
- package/src/directory-live.test.ts +0 -85
- package/src/directory-live.ts +0 -209
- package/src/group-mentions.ts +0 -52
- package/src/matrix/accounts.test.ts +0 -131
- package/src/matrix/accounts.ts +0 -114
- package/src/matrix/actions/client.ts +0 -47
- package/src/matrix/actions/limits.test.ts +0 -15
- package/src/matrix/actions/limits.ts +0 -6
- package/src/matrix/actions/messages.ts +0 -126
- package/src/matrix/actions/pins.test.ts +0 -74
- package/src/matrix/actions/pins.ts +0 -84
- package/src/matrix/actions/reactions.test.ts +0 -109
- package/src/matrix/actions/reactions.ts +0 -102
- package/src/matrix/actions/room.ts +0 -85
- package/src/matrix/actions/summary.ts +0 -75
- package/src/matrix/actions/types.ts +0 -85
- package/src/matrix/actions.ts +0 -15
- package/src/matrix/active-client.ts +0 -32
- package/src/matrix/client/config.ts +0 -245
- package/src/matrix/client/create-client.ts +0 -125
- package/src/matrix/client/logging.ts +0 -46
- package/src/matrix/client/runtime.ts +0 -4
- package/src/matrix/client/shared.test.ts +0 -85
- package/src/matrix/client/shared.ts +0 -210
- package/src/matrix/client/startup.test.ts +0 -49
- package/src/matrix/client/startup.ts +0 -29
- package/src/matrix/client/storage.ts +0 -131
- package/src/matrix/client/types.ts +0 -34
- package/src/matrix/client-bootstrap.ts +0 -47
- package/src/matrix/client.test.ts +0 -56
- package/src/matrix/client.ts +0 -14
- package/src/matrix/credentials.ts +0 -125
- package/src/matrix/deps.test.ts +0 -74
- package/src/matrix/deps.ts +0 -126
- package/src/matrix/format.test.ts +0 -33
- package/src/matrix/format.ts +0 -22
- package/src/matrix/index.ts +0 -11
- package/src/matrix/monitor/access-policy.ts +0 -126
- package/src/matrix/monitor/allowlist.test.ts +0 -45
- package/src/matrix/monitor/allowlist.ts +0 -100
- package/src/matrix/monitor/auto-join.ts +0 -72
- package/src/matrix/monitor/direct.test.ts +0 -400
- package/src/matrix/monitor/direct.ts +0 -152
- package/src/matrix/monitor/events.test.ts +0 -172
- package/src/matrix/monitor/events.ts +0 -168
- package/src/matrix/monitor/handler.body-for-agent.test.ts +0 -196
- package/src/matrix/monitor/handler.ts +0 -767
- package/src/matrix/monitor/inbound-body.test.ts +0 -73
- package/src/matrix/monitor/inbound-body.ts +0 -28
- package/src/matrix/monitor/index.test.ts +0 -18
- package/src/matrix/monitor/index.ts +0 -414
- package/src/matrix/monitor/location.ts +0 -100
- package/src/matrix/monitor/media.test.ts +0 -86
- package/src/matrix/monitor/media.ts +0 -118
- package/src/matrix/monitor/mentions.test.ts +0 -154
- package/src/matrix/monitor/mentions.ts +0 -62
- package/src/matrix/monitor/replies.test.ts +0 -184
- package/src/matrix/monitor/replies.ts +0 -124
- package/src/matrix/monitor/room-info.ts +0 -55
- package/src/matrix/monitor/rooms.test.ts +0 -124
- package/src/matrix/monitor/rooms.ts +0 -47
- package/src/matrix/monitor/threads.ts +0 -68
- package/src/matrix/monitor/types.ts +0 -39
- package/src/matrix/poll-types.test.ts +0 -21
- package/src/matrix/poll-types.ts +0 -167
- package/src/matrix/probe.ts +0 -69
- package/src/matrix/sdk-runtime.ts +0 -18
- package/src/matrix/send/client.ts +0 -99
- package/src/matrix/send/formatting.ts +0 -93
- package/src/matrix/send/media.ts +0 -230
- package/src/matrix/send/targets.test.ts +0 -98
- package/src/matrix/send/targets.ts +0 -150
- package/src/matrix/send/types.ts +0 -110
- package/src/matrix/send-queue.test.ts +0 -154
- package/src/matrix/send-queue.ts +0 -28
- package/src/matrix/send.test.ts +0 -326
- package/src/matrix/send.ts +0 -267
- package/src/onboarding.ts +0 -462
- package/src/outbound.test.ts +0 -159
- package/src/outbound.ts +0 -58
- package/src/resolve-targets.test.ts +0 -67
- package/src/resolve-targets.ts +0 -125
- package/src/runtime.ts +0 -6
- package/src/secret-input.ts +0 -13
- package/src/tool-actions.ts +0 -164
- package/src/types.ts +0 -118
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { a as resolveMatrixTargetIdentity } from "./target-ids-80nQ2gql.js";
|
|
2
|
+
import { i as resolveMatrixAccount } from "./accounts-Bm90Rzvp.js";
|
|
3
|
+
import { c as shouldHandleMatrixApprovalRequest, r as isMatrixAnyApprovalClientEnabled } from "./exec-approvals-Crnh543m.js";
|
|
4
|
+
import { a as sendMessageMatrix, i as reactMatrixMessage, s as sendSingleTextMessageMatrix } from "./send-Bo0DU1ca.js";
|
|
5
|
+
import { a as repairMatrixDirectRooms } from "./direct-management-DMMMgtTB.js";
|
|
6
|
+
import { a as unregisterMatrixApprovalReactionTarget, n as listMatrixApprovalReactionBindings, r as registerMatrixApprovalReactionTarget, t as buildMatrixApprovalReactionHint } from "./approval-reactions-o2_tuH8D.js";
|
|
7
|
+
import { n as editMatrixMessage, t as deleteMatrixMessage } from "./messages-BpihMh82.js";
|
|
8
|
+
import { listMessageReceiptPlatformIds, resolveMessageReceiptPrimaryId } from "openclaw/plugin-sdk/channel-message";
|
|
9
|
+
import { buildChannelApprovalNativeTargetKey } from "openclaw/plugin-sdk/approval-native-runtime";
|
|
10
|
+
import { setTimeout } from "node:timers/promises";
|
|
11
|
+
import { createChannelApprovalNativeRuntimeAdapter } from "openclaw/plugin-sdk/approval-handler-runtime";
|
|
12
|
+
import { buildExecApprovalPendingReplyPayload, buildPluginApprovalPendingReplyPayload } from "openclaw/plugin-sdk/approval-reply-runtime";
|
|
13
|
+
import { buildPluginApprovalResolvedReplyPayload } from "openclaw/plugin-sdk/approval-runtime";
|
|
14
|
+
//#region extensions/matrix/src/approval-handler.runtime.ts
|
|
15
|
+
const MATRIX_APPROVAL_METADATA_KEY = "com.openclaw.approval";
|
|
16
|
+
const MATRIX_APPROVAL_DELIVERY_ATTEMPTS = 3;
|
|
17
|
+
const MATRIX_APPROVAL_DELIVERY_RETRY_DELAY_MS = 250;
|
|
18
|
+
function resolveHandlerContext(params) {
|
|
19
|
+
const context = params.context;
|
|
20
|
+
const accountId = params.accountId?.trim() || "";
|
|
21
|
+
if (!context?.client || !accountId) return null;
|
|
22
|
+
return {
|
|
23
|
+
accountId,
|
|
24
|
+
context
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function normalizePendingMessageIds(entry) {
|
|
28
|
+
return Array.from(new Set(entry.platformMessageIds.map((messageId) => messageId.trim()).filter(Boolean)));
|
|
29
|
+
}
|
|
30
|
+
function normalizeReactionTargetRef(params) {
|
|
31
|
+
const roomId = params.roomId.trim();
|
|
32
|
+
const eventId = params.eventId.trim();
|
|
33
|
+
if (!roomId || !eventId) return null;
|
|
34
|
+
return {
|
|
35
|
+
roomId,
|
|
36
|
+
eventId
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function normalizeThreadId(value) {
|
|
40
|
+
return (value == null ? "" : String(value).trim()) || void 0;
|
|
41
|
+
}
|
|
42
|
+
function isSingleMatrixMessageLimitError(error) {
|
|
43
|
+
return error instanceof Error && error.message.includes("Matrix single-message text exceeds limit");
|
|
44
|
+
}
|
|
45
|
+
async function retryMatrixApprovalDelivery(operation, params = {}) {
|
|
46
|
+
let lastError;
|
|
47
|
+
for (let attempt = 1; attempt <= MATRIX_APPROVAL_DELIVERY_ATTEMPTS; attempt += 1) try {
|
|
48
|
+
return await operation();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
lastError = error;
|
|
51
|
+
if (attempt === MATRIX_APPROVAL_DELIVERY_ATTEMPTS || params.shouldRetry?.(error) === false) break;
|
|
52
|
+
await setTimeout(MATRIX_APPROVAL_DELIVERY_RETRY_DELAY_MS * attempt);
|
|
53
|
+
}
|
|
54
|
+
throw lastError;
|
|
55
|
+
}
|
|
56
|
+
async function prepareTarget(params) {
|
|
57
|
+
const resolved = resolveHandlerContext(params);
|
|
58
|
+
if (!resolved) return null;
|
|
59
|
+
const target = resolveMatrixTargetIdentity(params.rawTarget.to);
|
|
60
|
+
if (!target) return null;
|
|
61
|
+
const threadId = normalizeThreadId(params.rawTarget.threadId);
|
|
62
|
+
if (target.kind === "user") {
|
|
63
|
+
const account = resolveMatrixAccount({
|
|
64
|
+
cfg: params.cfg,
|
|
65
|
+
accountId: resolved.accountId
|
|
66
|
+
});
|
|
67
|
+
const repairDirectRooms = resolved.context.deps?.repairDirectRooms ?? repairMatrixDirectRooms;
|
|
68
|
+
const repaired = await retryMatrixApprovalDelivery(async () => await repairDirectRooms({
|
|
69
|
+
client: resolved.context.client,
|
|
70
|
+
remoteUserId: target.id,
|
|
71
|
+
encrypted: account.config.encryption === true
|
|
72
|
+
}));
|
|
73
|
+
if (!repaired.activeRoomId) return null;
|
|
74
|
+
return {
|
|
75
|
+
to: `room:${repaired.activeRoomId}`,
|
|
76
|
+
roomId: repaired.activeRoomId,
|
|
77
|
+
threadId
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
to: `room:${target.id}`,
|
|
82
|
+
roomId: target.id,
|
|
83
|
+
threadId
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function buildMatrixApprovalMetadata(params) {
|
|
87
|
+
const base = {
|
|
88
|
+
version: 1,
|
|
89
|
+
type: "approval.request",
|
|
90
|
+
id: params.view.approvalId,
|
|
91
|
+
state: "pending",
|
|
92
|
+
kind: params.view.approvalKind,
|
|
93
|
+
phase: params.view.phase,
|
|
94
|
+
title: params.view.title,
|
|
95
|
+
expiresAtMs: params.view.expiresAtMs,
|
|
96
|
+
metadata: params.view.metadata,
|
|
97
|
+
allowedDecisions: Array.from(params.allowedDecisions),
|
|
98
|
+
actions: params.view.actions.map((action) => ({
|
|
99
|
+
decision: action.decision,
|
|
100
|
+
label: action.label,
|
|
101
|
+
style: action.style,
|
|
102
|
+
command: action.command
|
|
103
|
+
})),
|
|
104
|
+
...params.view.description != null ? { description: params.view.description } : {}
|
|
105
|
+
};
|
|
106
|
+
if (params.view.approvalKind === "plugin") return {
|
|
107
|
+
...base,
|
|
108
|
+
kind: "plugin",
|
|
109
|
+
severity: params.view.severity,
|
|
110
|
+
...params.view.agentId != null ? { agentId: params.view.agentId } : {},
|
|
111
|
+
...params.view.pluginId != null ? { pluginId: params.view.pluginId } : {},
|
|
112
|
+
...params.view.toolName != null ? { toolName: params.view.toolName } : {}
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
...base,
|
|
116
|
+
kind: "exec",
|
|
117
|
+
commandText: params.view.commandText,
|
|
118
|
+
...params.view.ask != null ? { ask: params.view.ask } : {},
|
|
119
|
+
...params.view.agentId != null ? { agentId: params.view.agentId } : {},
|
|
120
|
+
...params.view.commandPreview != null ? { commandPreview: params.view.commandPreview } : {},
|
|
121
|
+
...params.view.cwd != null ? { cwd: params.view.cwd } : {},
|
|
122
|
+
...params.view.envKeys != null ? { envKeys: params.view.envKeys } : {},
|
|
123
|
+
...params.view.host != null ? { host: params.view.host } : {},
|
|
124
|
+
...params.view.nodeId != null ? { nodeId: params.view.nodeId } : {},
|
|
125
|
+
...params.view.sessionKey != null ? { sessionKey: params.view.sessionKey } : {}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function buildPendingApprovalContent(params) {
|
|
129
|
+
const allowedDecisions = params.view.actions.map((action) => action.decision);
|
|
130
|
+
const payload = params.view.approvalKind === "plugin" ? buildPluginApprovalPendingReplyPayload({
|
|
131
|
+
request: {
|
|
132
|
+
id: params.view.approvalId,
|
|
133
|
+
request: {
|
|
134
|
+
title: params.view.title,
|
|
135
|
+
description: params.view.description ?? "",
|
|
136
|
+
severity: params.view.severity,
|
|
137
|
+
toolName: params.view.toolName ?? void 0,
|
|
138
|
+
pluginId: params.view.pluginId ?? void 0,
|
|
139
|
+
agentId: params.view.agentId ?? void 0
|
|
140
|
+
},
|
|
141
|
+
createdAtMs: 0,
|
|
142
|
+
expiresAtMs: params.view.expiresAtMs
|
|
143
|
+
},
|
|
144
|
+
nowMs: params.nowMs,
|
|
145
|
+
allowedDecisions
|
|
146
|
+
}) : buildExecApprovalPendingReplyPayload({
|
|
147
|
+
approvalId: params.view.approvalId,
|
|
148
|
+
approvalSlug: params.view.approvalId.slice(0, 8),
|
|
149
|
+
approvalCommandId: params.view.approvalId,
|
|
150
|
+
ask: params.view.ask ?? void 0,
|
|
151
|
+
agentId: params.view.agentId ?? void 0,
|
|
152
|
+
allowedDecisions,
|
|
153
|
+
command: params.view.commandText,
|
|
154
|
+
cwd: params.view.cwd ?? void 0,
|
|
155
|
+
host: params.view.host === "node" ? "node" : "gateway",
|
|
156
|
+
nodeId: params.view.nodeId ?? void 0,
|
|
157
|
+
sessionKey: params.view.sessionKey ?? void 0,
|
|
158
|
+
expiresAtMs: params.view.expiresAtMs,
|
|
159
|
+
nowMs: params.nowMs
|
|
160
|
+
});
|
|
161
|
+
const hint = buildMatrixApprovalReactionHint(allowedDecisions);
|
|
162
|
+
const text = payload.text ?? "";
|
|
163
|
+
return {
|
|
164
|
+
approvalId: params.view.approvalId,
|
|
165
|
+
text: hint ? text ? `${hint}\n\n${text}` : hint : text,
|
|
166
|
+
allowedDecisions,
|
|
167
|
+
extraContent: { [MATRIX_APPROVAL_METADATA_KEY]: buildMatrixApprovalMetadata({
|
|
168
|
+
view: params.view,
|
|
169
|
+
allowedDecisions
|
|
170
|
+
}) }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function buildResolvedApprovalText(view) {
|
|
174
|
+
if (view.approvalKind === "plugin") return buildPluginApprovalResolvedReplyPayload({ resolved: {
|
|
175
|
+
id: view.approvalId,
|
|
176
|
+
decision: view.decision,
|
|
177
|
+
resolvedBy: view.resolvedBy ?? void 0,
|
|
178
|
+
ts: 0
|
|
179
|
+
} }).text ?? "";
|
|
180
|
+
return [
|
|
181
|
+
`Exec approval: ${view.decision === "allow-once" ? "Allowed once" : view.decision === "allow-always" ? "Allowed always" : "Denied"}`,
|
|
182
|
+
"",
|
|
183
|
+
"Command",
|
|
184
|
+
buildMarkdownCodeBlock(view.commandText)
|
|
185
|
+
].join("\n");
|
|
186
|
+
}
|
|
187
|
+
function buildMarkdownCodeBlock(text) {
|
|
188
|
+
const longestFence = Math.max(...Array.from(text.matchAll(/`+/g), (match) => match[0].length), 0);
|
|
189
|
+
const fence = "`".repeat(Math.max(3, longestFence + 1));
|
|
190
|
+
return [
|
|
191
|
+
fence,
|
|
192
|
+
text,
|
|
193
|
+
fence
|
|
194
|
+
].join("\n");
|
|
195
|
+
}
|
|
196
|
+
const matrixApprovalNativeRuntime = createChannelApprovalNativeRuntimeAdapter({
|
|
197
|
+
eventKinds: ["exec", "plugin"],
|
|
198
|
+
availability: {
|
|
199
|
+
isConfigured: ({ cfg, accountId, context }) => {
|
|
200
|
+
const resolved = resolveHandlerContext({
|
|
201
|
+
cfg,
|
|
202
|
+
accountId,
|
|
203
|
+
context
|
|
204
|
+
});
|
|
205
|
+
if (!resolved) return false;
|
|
206
|
+
return isMatrixAnyApprovalClientEnabled({
|
|
207
|
+
cfg,
|
|
208
|
+
accountId: resolved.accountId
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
shouldHandle: ({ cfg, accountId, request, context }) => {
|
|
212
|
+
const resolved = resolveHandlerContext({
|
|
213
|
+
cfg,
|
|
214
|
+
accountId,
|
|
215
|
+
context
|
|
216
|
+
});
|
|
217
|
+
if (!resolved) return false;
|
|
218
|
+
return shouldHandleMatrixApprovalRequest({
|
|
219
|
+
cfg,
|
|
220
|
+
accountId: resolved.accountId,
|
|
221
|
+
request
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
presentation: {
|
|
226
|
+
buildPendingPayload: ({ view, nowMs }) => buildPendingApprovalContent({
|
|
227
|
+
view,
|
|
228
|
+
nowMs
|
|
229
|
+
}),
|
|
230
|
+
buildResolvedResult: ({ view }) => ({
|
|
231
|
+
kind: "update",
|
|
232
|
+
payload: buildResolvedApprovalText(view)
|
|
233
|
+
}),
|
|
234
|
+
buildExpiredResult: () => ({ kind: "delete" })
|
|
235
|
+
},
|
|
236
|
+
transport: {
|
|
237
|
+
prepareTarget: ({ cfg, accountId, context, plannedTarget }) => {
|
|
238
|
+
return prepareTarget({
|
|
239
|
+
cfg,
|
|
240
|
+
accountId,
|
|
241
|
+
context,
|
|
242
|
+
rawTarget: plannedTarget.target
|
|
243
|
+
}).then((preparedTarget) => preparedTarget ? {
|
|
244
|
+
dedupeKey: buildChannelApprovalNativeTargetKey({
|
|
245
|
+
to: preparedTarget.roomId,
|
|
246
|
+
threadId: preparedTarget.threadId
|
|
247
|
+
}),
|
|
248
|
+
target: preparedTarget
|
|
249
|
+
} : null);
|
|
250
|
+
},
|
|
251
|
+
deliverPending: async ({ cfg, accountId, context, preparedTarget, pendingPayload, view }) => {
|
|
252
|
+
const resolved = resolveHandlerContext({
|
|
253
|
+
cfg,
|
|
254
|
+
accountId,
|
|
255
|
+
context
|
|
256
|
+
});
|
|
257
|
+
if (!resolved) return null;
|
|
258
|
+
const sendSingleTextMessage = resolved.context.deps?.sendSingleTextMessage ?? sendSingleTextMessageMatrix;
|
|
259
|
+
const reactMessage = resolved.context.deps?.reactMessage ?? reactMatrixMessage;
|
|
260
|
+
let result;
|
|
261
|
+
try {
|
|
262
|
+
result = await retryMatrixApprovalDelivery(async () => await sendSingleTextMessage(preparedTarget.to, pendingPayload.text, {
|
|
263
|
+
cfg,
|
|
264
|
+
accountId: resolved.accountId,
|
|
265
|
+
client: resolved.context.client,
|
|
266
|
+
threadId: preparedTarget.threadId,
|
|
267
|
+
extraContent: pendingPayload.extraContent
|
|
268
|
+
}), { shouldRetry: (error) => !isSingleMatrixMessageLimitError(error) });
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (!isSingleMatrixMessageLimitError(error)) throw error;
|
|
271
|
+
const sendMessage = resolved.context.deps?.sendMessage ?? sendMessageMatrix;
|
|
272
|
+
result = await retryMatrixApprovalDelivery(async () => await sendMessage(preparedTarget.to, pendingPayload.text, {
|
|
273
|
+
cfg,
|
|
274
|
+
accountId: resolved.accountId,
|
|
275
|
+
client: resolved.context.client,
|
|
276
|
+
threadId: preparedTarget.threadId,
|
|
277
|
+
extraContent: pendingPayload.extraContent
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
const receiptMessageIds = listMessageReceiptPlatformIds(result.receipt);
|
|
281
|
+
const platformMessageIds = receiptMessageIds.length ? receiptMessageIds : [result.messageId.trim()].filter(Boolean);
|
|
282
|
+
const reactionEventId = resolveMessageReceiptPrimaryId(result.receipt) || result.primaryMessageId?.trim() || platformMessageIds[0] || result.messageId.trim();
|
|
283
|
+
registerMatrixApprovalReactionTarget({
|
|
284
|
+
roomId: result.roomId,
|
|
285
|
+
eventId: reactionEventId,
|
|
286
|
+
approvalId: pendingPayload.approvalId,
|
|
287
|
+
allowedDecisions: pendingPayload.allowedDecisions,
|
|
288
|
+
ttlMs: view.expiresAtMs - Date.now()
|
|
289
|
+
});
|
|
290
|
+
await Promise.allSettled(listMatrixApprovalReactionBindings(pendingPayload.allowedDecisions).map(async ({ emoji }) => {
|
|
291
|
+
await reactMessage(result.roomId, reactionEventId, emoji, {
|
|
292
|
+
cfg,
|
|
293
|
+
accountId: resolved.accountId,
|
|
294
|
+
client: resolved.context.client
|
|
295
|
+
});
|
|
296
|
+
}));
|
|
297
|
+
return {
|
|
298
|
+
roomId: result.roomId,
|
|
299
|
+
platformMessageIds,
|
|
300
|
+
reactionEventId
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
updateEntry: async ({ cfg, accountId, context, entry, payload }) => {
|
|
304
|
+
const resolved = resolveHandlerContext({
|
|
305
|
+
cfg,
|
|
306
|
+
accountId,
|
|
307
|
+
context
|
|
308
|
+
});
|
|
309
|
+
if (!resolved) return;
|
|
310
|
+
const editMessage = resolved.context.deps?.editMessage ?? editMatrixMessage;
|
|
311
|
+
const deleteMessage = resolved.context.deps?.deleteMessage ?? deleteMatrixMessage;
|
|
312
|
+
const [primaryMessageId, ...staleMessageIds] = normalizePendingMessageIds(entry);
|
|
313
|
+
if (!primaryMessageId) return;
|
|
314
|
+
const text = payload;
|
|
315
|
+
await Promise.allSettled([editMessage(entry.roomId, primaryMessageId, text, {
|
|
316
|
+
cfg,
|
|
317
|
+
accountId: resolved.accountId,
|
|
318
|
+
client: resolved.context.client
|
|
319
|
+
}), ...staleMessageIds.map(async (messageId) => {
|
|
320
|
+
await deleteMessage(entry.roomId, messageId, {
|
|
321
|
+
cfg,
|
|
322
|
+
accountId: resolved.accountId,
|
|
323
|
+
client: resolved.context.client,
|
|
324
|
+
reason: "approval resolved"
|
|
325
|
+
});
|
|
326
|
+
})]);
|
|
327
|
+
},
|
|
328
|
+
deleteEntry: async ({ cfg, accountId, context, entry, phase }) => {
|
|
329
|
+
const resolved = resolveHandlerContext({
|
|
330
|
+
cfg,
|
|
331
|
+
accountId,
|
|
332
|
+
context
|
|
333
|
+
});
|
|
334
|
+
if (!resolved) return;
|
|
335
|
+
const deleteMessage = resolved.context.deps?.deleteMessage ?? deleteMatrixMessage;
|
|
336
|
+
await Promise.allSettled(normalizePendingMessageIds(entry).map(async (messageId) => {
|
|
337
|
+
await deleteMessage(entry.roomId, messageId, {
|
|
338
|
+
cfg,
|
|
339
|
+
accountId: resolved.accountId,
|
|
340
|
+
client: resolved.context.client,
|
|
341
|
+
reason: phase === "expired" ? "approval expired" : "approval resolved"
|
|
342
|
+
});
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
interactions: {
|
|
347
|
+
bindPending: (params) => {
|
|
348
|
+
const target = normalizeReactionTargetRef({
|
|
349
|
+
roomId: params.entry.roomId,
|
|
350
|
+
eventId: params.entry.reactionEventId
|
|
351
|
+
});
|
|
352
|
+
if (!target) return null;
|
|
353
|
+
registerMatrixApprovalReactionTarget({
|
|
354
|
+
roomId: target.roomId,
|
|
355
|
+
eventId: target.eventId,
|
|
356
|
+
approvalId: params.pendingPayload.approvalId,
|
|
357
|
+
allowedDecisions: params.pendingPayload.allowedDecisions,
|
|
358
|
+
ttlMs: params.view.expiresAtMs - Date.now()
|
|
359
|
+
});
|
|
360
|
+
return target;
|
|
361
|
+
},
|
|
362
|
+
unbindPending: (params) => {
|
|
363
|
+
const target = normalizeReactionTargetRef(params.binding);
|
|
364
|
+
if (!target) return;
|
|
365
|
+
unregisterMatrixApprovalReactionTarget(target);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
//#endregion
|
|
370
|
+
export { matrixApprovalNativeRuntime };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { n as normalizeMatrixUserId } from "./allowlist-sTzpCn5d.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 { i as resolveMatrixAccount } from "./accounts-Bm90Rzvp.js";
|
|
2
|
+
import { t as normalizeMatrixApproverId } from "./approval-ids-DoC2z7tR.js";
|
|
3
|
+
import { resolveApprovalApprovers } from "openclaw/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 };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { n as getOptionalMatrixRuntime } from "./runtime-Dog86njy.js";
|
|
2
|
+
//#region extensions/matrix/src/approval-reactions.ts
|
|
3
|
+
const MATRIX_APPROVAL_REACTION_META = {
|
|
4
|
+
"allow-once": {
|
|
5
|
+
emoji: "✅",
|
|
6
|
+
label: "Allow once"
|
|
7
|
+
},
|
|
8
|
+
"allow-always": {
|
|
9
|
+
emoji: "♾️",
|
|
10
|
+
label: "Allow always"
|
|
11
|
+
},
|
|
12
|
+
deny: {
|
|
13
|
+
emoji: "❌",
|
|
14
|
+
label: "Deny"
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const MATRIX_APPROVAL_REACTION_ORDER = [
|
|
18
|
+
"allow-once",
|
|
19
|
+
"allow-always",
|
|
20
|
+
"deny"
|
|
21
|
+
];
|
|
22
|
+
const PERSISTENT_NAMESPACE = "matrix.approval-reactions";
|
|
23
|
+
const PERSISTENT_MAX_ENTRIES = 1e3;
|
|
24
|
+
const DEFAULT_REACTION_TARGET_TTL_MS = 1440 * 60 * 1e3;
|
|
25
|
+
const matrixApprovalReactionTargets = /* @__PURE__ */ new Map();
|
|
26
|
+
let persistentStore;
|
|
27
|
+
let persistentStoreDisabled = false;
|
|
28
|
+
function buildReactionTargetKey(roomId, eventId) {
|
|
29
|
+
const normalizedRoomId = roomId.trim();
|
|
30
|
+
const normalizedEventId = eventId.trim();
|
|
31
|
+
if (!normalizedRoomId || !normalizedEventId) return null;
|
|
32
|
+
return `${normalizedRoomId}:${normalizedEventId}`;
|
|
33
|
+
}
|
|
34
|
+
function reportPersistentApprovalReactionError(error) {
|
|
35
|
+
try {
|
|
36
|
+
getOptionalMatrixRuntime()?.logging.getChildLogger({
|
|
37
|
+
plugin: "matrix",
|
|
38
|
+
feature: "approval-reaction-state"
|
|
39
|
+
}).warn("Matrix persistent approval reaction state failed", { error: String(error) });
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
function disablePersistentApprovalReactionStore(error) {
|
|
43
|
+
persistentStoreDisabled = true;
|
|
44
|
+
persistentStore = void 0;
|
|
45
|
+
reportPersistentApprovalReactionError(error);
|
|
46
|
+
}
|
|
47
|
+
function getPersistentApprovalReactionStore() {
|
|
48
|
+
if (persistentStoreDisabled) return;
|
|
49
|
+
if (persistentStore) return persistentStore;
|
|
50
|
+
const runtime = getOptionalMatrixRuntime();
|
|
51
|
+
if (!runtime) return;
|
|
52
|
+
try {
|
|
53
|
+
persistentStore = runtime.state.openKeyedStore({
|
|
54
|
+
namespace: PERSISTENT_NAMESPACE,
|
|
55
|
+
maxEntries: PERSISTENT_MAX_ENTRIES,
|
|
56
|
+
defaultTtlMs: DEFAULT_REACTION_TARGET_TTL_MS
|
|
57
|
+
});
|
|
58
|
+
return persistentStore;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
disablePersistentApprovalReactionStore(error);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function readPersistedTarget(value) {
|
|
65
|
+
const persisted = value;
|
|
66
|
+
if (persisted?.version !== 1 || !persisted.target || typeof persisted.target.approvalId !== "string" || !Array.isArray(persisted.target.allowedDecisions)) return null;
|
|
67
|
+
return persisted.target;
|
|
68
|
+
}
|
|
69
|
+
function rememberPersistentApprovalReactionTarget(params) {
|
|
70
|
+
const ttlMs = params.ttlMs == null ? DEFAULT_REACTION_TARGET_TTL_MS : Math.max(1, params.ttlMs);
|
|
71
|
+
const store = getPersistentApprovalReactionStore();
|
|
72
|
+
if (!store) return;
|
|
73
|
+
store.register(params.key, {
|
|
74
|
+
version: 1,
|
|
75
|
+
target: params.target
|
|
76
|
+
}, { ttlMs }).catch(disablePersistentApprovalReactionStore);
|
|
77
|
+
}
|
|
78
|
+
function forgetPersistentApprovalReactionTarget(key) {
|
|
79
|
+
const store = getPersistentApprovalReactionStore();
|
|
80
|
+
if (!store) return;
|
|
81
|
+
store.delete(key).catch(disablePersistentApprovalReactionStore);
|
|
82
|
+
}
|
|
83
|
+
async function lookupPersistentApprovalReactionTarget(key) {
|
|
84
|
+
const store = getPersistentApprovalReactionStore();
|
|
85
|
+
if (!store) return null;
|
|
86
|
+
try {
|
|
87
|
+
return readPersistedTarget(await store.lookup(key));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
disablePersistentApprovalReactionStore(error);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function listMatrixApprovalReactionBindings(allowedDecisions) {
|
|
94
|
+
const allowed = new Set(allowedDecisions);
|
|
95
|
+
return MATRIX_APPROVAL_REACTION_ORDER.filter((decision) => allowed.has(decision)).map((decision) => ({
|
|
96
|
+
decision,
|
|
97
|
+
emoji: MATRIX_APPROVAL_REACTION_META[decision].emoji,
|
|
98
|
+
label: MATRIX_APPROVAL_REACTION_META[decision].label
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
function buildMatrixApprovalReactionHint(allowedDecisions) {
|
|
102
|
+
const bindings = listMatrixApprovalReactionBindings(allowedDecisions);
|
|
103
|
+
if (bindings.length === 0) return null;
|
|
104
|
+
return `React here: ${bindings.map((binding) => `${binding.emoji} ${binding.label}`).join(", ")}`;
|
|
105
|
+
}
|
|
106
|
+
function resolveMatrixApprovalReactionDecision(reactionKey, allowedDecisions) {
|
|
107
|
+
const normalizedReaction = reactionKey.trim();
|
|
108
|
+
if (!normalizedReaction) return null;
|
|
109
|
+
const allowed = new Set(allowedDecisions);
|
|
110
|
+
for (const decision of MATRIX_APPROVAL_REACTION_ORDER) {
|
|
111
|
+
if (!allowed.has(decision)) continue;
|
|
112
|
+
if (MATRIX_APPROVAL_REACTION_META[decision].emoji === normalizedReaction) return decision;
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function registerMatrixApprovalReactionTarget(params) {
|
|
117
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
118
|
+
const approvalId = params.approvalId.trim();
|
|
119
|
+
const allowedDecisions = Array.from(new Set(params.allowedDecisions.filter((decision) => decision === "allow-once" || decision === "allow-always" || decision === "deny")));
|
|
120
|
+
if (!key || !approvalId || allowedDecisions.length === 0) return;
|
|
121
|
+
const target = {
|
|
122
|
+
approvalId,
|
|
123
|
+
allowedDecisions
|
|
124
|
+
};
|
|
125
|
+
matrixApprovalReactionTargets.set(key, target);
|
|
126
|
+
rememberPersistentApprovalReactionTarget({
|
|
127
|
+
key,
|
|
128
|
+
target,
|
|
129
|
+
ttlMs: params.ttlMs
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function unregisterMatrixApprovalReactionTarget(params) {
|
|
133
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
134
|
+
if (!key) return;
|
|
135
|
+
matrixApprovalReactionTargets.delete(key);
|
|
136
|
+
forgetPersistentApprovalReactionTarget(key);
|
|
137
|
+
}
|
|
138
|
+
function resolveTarget(params) {
|
|
139
|
+
const target = params.target;
|
|
140
|
+
if (!target) return null;
|
|
141
|
+
const decision = resolveMatrixApprovalReactionDecision(params.reactionKey, target.allowedDecisions);
|
|
142
|
+
if (!decision) return null;
|
|
143
|
+
return {
|
|
144
|
+
approvalId: target.approvalId,
|
|
145
|
+
decision
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function resolveMatrixApprovalReactionTargetWithPersistence(params) {
|
|
149
|
+
const key = buildReactionTargetKey(params.roomId, params.eventId);
|
|
150
|
+
if (!key) return null;
|
|
151
|
+
const inMemory = resolveTarget({
|
|
152
|
+
target: matrixApprovalReactionTargets.get(key),
|
|
153
|
+
reactionKey: params.reactionKey
|
|
154
|
+
});
|
|
155
|
+
if (inMemory) return inMemory;
|
|
156
|
+
return resolveTarget({
|
|
157
|
+
target: await lookupPersistentApprovalReactionTarget(key),
|
|
158
|
+
reactionKey: params.reactionKey
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { unregisterMatrixApprovalReactionTarget as a, resolveMatrixApprovalReactionTargetWithPersistence as i, listMatrixApprovalReactionBindings as n, registerMatrixApprovalReactionTarget as r, buildMatrixApprovalReactionHint as t };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region extensions/matrix/src/matrix/async-lock.ts
|
|
2
|
+
function createAsyncLock() {
|
|
3
|
+
let lock = Promise.resolve();
|
|
4
|
+
return async function withLock(fn) {
|
|
5
|
+
const previous = lock;
|
|
6
|
+
let release;
|
|
7
|
+
lock = new Promise((resolve) => {
|
|
8
|
+
release = resolve;
|
|
9
|
+
});
|
|
10
|
+
await previous;
|
|
11
|
+
try {
|
|
12
|
+
return await fn();
|
|
13
|
+
} finally {
|
|
14
|
+
release?.();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createAsyncLock as t };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { i as resolveMatrixCredentialsFilename, r as resolveMatrixCredentialsDir } from "./storage-paths-BJLdnCjV.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
|
6
|
+
//#region extensions/matrix/auth-presence.ts
|
|
7
|
+
function listMatrixCredentialPaths(_cfg, env = process.env) {
|
|
8
|
+
const credentialsDir = resolveMatrixCredentialsDir(resolveStateDir(env, os.homedir));
|
|
9
|
+
const paths = new Set([resolveMatrixCredentialsFilename(), resolveMatrixCredentialsFilename("default")]);
|
|
10
|
+
try {
|
|
11
|
+
const entries = fs.readdirSync(credentialsDir, { withFileTypes: true });
|
|
12
|
+
for (const entry of entries) if (entry.isFile() && /^credentials(?:-[a-z0-9._-]+)?\.json$/i.test(entry.name)) paths.add(entry.name);
|
|
13
|
+
} catch {}
|
|
14
|
+
return [...paths].map((filename) => path.join(credentialsDir, filename));
|
|
15
|
+
}
|
|
16
|
+
function hasAnyMatrixAuth(params, env = process.env) {
|
|
17
|
+
return listMatrixCredentialPaths(params && typeof params === "object" && "cfg" in params ? params.cfg : params, params && typeof params === "object" && "cfg" in params ? params.env ?? env : env).some((filePath) => {
|
|
18
|
+
try {
|
|
19
|
+
return fs.existsSync(filePath);
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { hasAnyMatrixAuth };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//#region extensions/matrix/src/matrix/backup-health.ts
|
|
2
|
+
function resolveMatrixRoomKeyBackupIssue(backup) {
|
|
3
|
+
if (!backup.serverVersion) return {
|
|
4
|
+
code: "missing-server-backup",
|
|
5
|
+
summary: "missing on server",
|
|
6
|
+
message: "no room-key backup exists on the homeserver"
|
|
7
|
+
};
|
|
8
|
+
if (backup.decryptionKeyCached === false) {
|
|
9
|
+
if (backup.keyLoadError) return {
|
|
10
|
+
code: "key-load-failed",
|
|
11
|
+
summary: "present but backup key unavailable on this device",
|
|
12
|
+
message: `backup decryption key could not be loaded from secret storage (${backup.keyLoadError})`
|
|
13
|
+
};
|
|
14
|
+
if (backup.keyLoadAttempted) return {
|
|
15
|
+
code: "key-not-loaded",
|
|
16
|
+
summary: "present but backup key unavailable on this device",
|
|
17
|
+
message: "backup decryption key is not loaded on this device (secret storage did not return a key)"
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
code: "key-not-loaded",
|
|
21
|
+
summary: "present but backup key unavailable on this device",
|
|
22
|
+
message: "backup decryption key is not loaded on this device"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (backup.matchesDecryptionKey === false) return {
|
|
26
|
+
code: "key-mismatch",
|
|
27
|
+
summary: "present but backup key mismatch on this device",
|
|
28
|
+
message: "backup key mismatch (this device does not have the matching backup decryption key)"
|
|
29
|
+
};
|
|
30
|
+
if (backup.trusted === false) return {
|
|
31
|
+
code: "untrusted-signature",
|
|
32
|
+
summary: "present but not trusted on this device",
|
|
33
|
+
message: "backup signature chain is not trusted by this device"
|
|
34
|
+
};
|
|
35
|
+
if (!backup.activeVersion) return {
|
|
36
|
+
code: "inactive",
|
|
37
|
+
summary: "present on server but inactive on this device",
|
|
38
|
+
message: "backup exists but is not active on this device"
|
|
39
|
+
};
|
|
40
|
+
if (backup.trusted === null || backup.matchesDecryptionKey === null || backup.decryptionKeyCached === null) return {
|
|
41
|
+
code: "indeterminate",
|
|
42
|
+
summary: "present but trust state unknown",
|
|
43
|
+
message: "backup trust state could not be fully determined"
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
code: "ok",
|
|
47
|
+
summary: "active and trusted on this device",
|
|
48
|
+
message: null
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function resolveMatrixRoomKeyBackupReadinessError(backup, opts) {
|
|
52
|
+
const issue = resolveMatrixRoomKeyBackupIssue(backup);
|
|
53
|
+
if (issue.code === "missing-server-backup") return opts.requireServerBackup ? "Matrix room key backup is missing on the homeserver." : null;
|
|
54
|
+
if (issue.code === "ok") return null;
|
|
55
|
+
if (issue.code === "untrusted-signature" && opts.allowUntrustedMatchingKey === true && backup.matchesDecryptionKey === true && backup.decryptionKeyCached === true) return null;
|
|
56
|
+
if (issue.message) return `Matrix room key backup is not usable: ${issue.message}.`;
|
|
57
|
+
return "Matrix room key backup is not usable on this device.";
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { resolveMatrixRoomKeyBackupReadinessError as n, resolveMatrixRoomKeyBackupIssue as t };
|