@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,235 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
//#region extensions/matrix/src/matrix/deps.ts
|
|
8
|
+
const REQUIRED_MATRIX_PACKAGES = [
|
|
9
|
+
"matrix-js-sdk",
|
|
10
|
+
"@matrix-org/matrix-sdk-crypto-nodejs",
|
|
11
|
+
"@matrix-org/matrix-sdk-crypto-wasm"
|
|
12
|
+
];
|
|
13
|
+
const MIN_MATRIX_CRYPTO_NATIVE_BINDING_BYTES = 1e6;
|
|
14
|
+
function resolveMissingMatrixPackages() {
|
|
15
|
+
try {
|
|
16
|
+
const req = createRequire(import.meta.url);
|
|
17
|
+
return REQUIRED_MATRIX_PACKAGES.filter((pkg) => {
|
|
18
|
+
try {
|
|
19
|
+
req.resolve(pkg);
|
|
20
|
+
return false;
|
|
21
|
+
} catch {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
} catch {
|
|
26
|
+
return [...REQUIRED_MATRIX_PACKAGES];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isMatrixSdkAvailable() {
|
|
30
|
+
return resolveMissingMatrixPackages().length === 0;
|
|
31
|
+
}
|
|
32
|
+
function resolvePluginRoot() {
|
|
33
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
return path.resolve(currentDir, "..", "..");
|
|
35
|
+
}
|
|
36
|
+
let defaultMatrixCryptoRuntimeEnsurePromise = null;
|
|
37
|
+
async function runFixedCommandWithTimeout(params) {
|
|
38
|
+
return await new Promise((resolve) => {
|
|
39
|
+
const [command, ...args] = params.argv;
|
|
40
|
+
if (!command) {
|
|
41
|
+
resolve({
|
|
42
|
+
code: 1,
|
|
43
|
+
stdout: "",
|
|
44
|
+
stderr: "command is required"
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const proc = spawn(command, args, {
|
|
49
|
+
cwd: params.cwd,
|
|
50
|
+
env: {
|
|
51
|
+
...process.env,
|
|
52
|
+
...params.env
|
|
53
|
+
},
|
|
54
|
+
stdio: [
|
|
55
|
+
"ignore",
|
|
56
|
+
"pipe",
|
|
57
|
+
"pipe"
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
let stdout = "";
|
|
61
|
+
let stderr = "";
|
|
62
|
+
let settled = false;
|
|
63
|
+
let timer = null;
|
|
64
|
+
const killChildOnExit = () => {
|
|
65
|
+
if (!settled && proc.exitCode === null) proc.kill("SIGTERM");
|
|
66
|
+
};
|
|
67
|
+
const finalize = (result) => {
|
|
68
|
+
if (settled) return;
|
|
69
|
+
settled = true;
|
|
70
|
+
if (timer) clearTimeout(timer);
|
|
71
|
+
process.off("exit", killChildOnExit);
|
|
72
|
+
resolve(result);
|
|
73
|
+
};
|
|
74
|
+
process.once("exit", killChildOnExit);
|
|
75
|
+
proc.stdout?.on("data", (chunk) => {
|
|
76
|
+
stdout += chunk.toString();
|
|
77
|
+
});
|
|
78
|
+
proc.stderr?.on("data", (chunk) => {
|
|
79
|
+
stderr += chunk.toString();
|
|
80
|
+
});
|
|
81
|
+
timer = setTimeout(() => {
|
|
82
|
+
proc.kill("SIGKILL");
|
|
83
|
+
finalize({
|
|
84
|
+
code: 124,
|
|
85
|
+
stdout,
|
|
86
|
+
stderr: stderr || `command timed out after ${params.timeoutMs}ms`
|
|
87
|
+
});
|
|
88
|
+
}, params.timeoutMs);
|
|
89
|
+
proc.on("error", (err) => {
|
|
90
|
+
finalize({
|
|
91
|
+
code: 1,
|
|
92
|
+
stdout,
|
|
93
|
+
stderr: err.message
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
proc.on("close", (code) => {
|
|
97
|
+
finalize({
|
|
98
|
+
code: code ?? 1,
|
|
99
|
+
stdout,
|
|
100
|
+
stderr
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function defaultRequireFn(id) {
|
|
106
|
+
return createRequire(import.meta.url)(id);
|
|
107
|
+
}
|
|
108
|
+
function defaultResolveFn(id) {
|
|
109
|
+
return createRequire(import.meta.url).resolve(id);
|
|
110
|
+
}
|
|
111
|
+
function isMissingMatrixCryptoRuntimeError(error) {
|
|
112
|
+
const message = formatErrorMessage(error);
|
|
113
|
+
return message.includes("@matrix-org/matrix-sdk-crypto-nodejs-") || message.includes("matrix-sdk-crypto-nodejs") || message.includes("download-lib.js");
|
|
114
|
+
}
|
|
115
|
+
function isMuslRuntime() {
|
|
116
|
+
try {
|
|
117
|
+
return !(process.report?.getReport?.())?.header?.glibcVersionRuntime;
|
|
118
|
+
} catch {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function resolveMatrixCryptoNativeBindingFilename() {
|
|
123
|
+
switch (process.platform) {
|
|
124
|
+
case "darwin": return process.arch === "arm64" ? "matrix-sdk-crypto.darwin-arm64.node" : process.arch === "x64" ? "matrix-sdk-crypto.darwin-x64.node" : null;
|
|
125
|
+
case "linux":
|
|
126
|
+
if (process.arch === "x64") return isMuslRuntime() ? "matrix-sdk-crypto.linux-x64-musl.node" : "matrix-sdk-crypto.linux-x64-gnu.node";
|
|
127
|
+
if (process.arch === "arm64" && !isMuslRuntime()) return "matrix-sdk-crypto.linux-arm64-gnu.node";
|
|
128
|
+
if (process.arch === "arm") return "matrix-sdk-crypto.linux-arm-gnueabihf.node";
|
|
129
|
+
if (process.arch === "s390x") return "matrix-sdk-crypto.linux-s390x-gnu.node";
|
|
130
|
+
return null;
|
|
131
|
+
case "win32": return process.arch === "x64" ? "matrix-sdk-crypto.win32-x64-msvc.node" : process.arch === "ia32" ? "matrix-sdk-crypto.win32-ia32-msvc.node" : process.arch === "arm64" ? "matrix-sdk-crypto.win32-arm64-msvc.node" : null;
|
|
132
|
+
default: return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function resolveMatrixCryptoNativeBindingPath(resolveFn) {
|
|
136
|
+
const filename = resolveMatrixCryptoNativeBindingFilename();
|
|
137
|
+
if (!filename) return null;
|
|
138
|
+
try {
|
|
139
|
+
return path.join(path.dirname(resolveFn("@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js")), filename);
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function removeIncompleteMatrixCryptoNativeBinding(params) {
|
|
145
|
+
const bindingPath = params.bindingPath;
|
|
146
|
+
if (!bindingPath) return;
|
|
147
|
+
try {
|
|
148
|
+
const stat = fs.statSync(bindingPath);
|
|
149
|
+
if (!stat.isFile() || stat.size >= MIN_MATRIX_CRYPTO_NATIVE_BINDING_BYTES) return;
|
|
150
|
+
fs.unlinkSync(bindingPath);
|
|
151
|
+
params.log?.(`matrix: removed incomplete native crypto runtime (${stat.size} bytes); it will be downloaded again`);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (error.code !== "ENOENT") throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function ensureMatrixCryptoRuntime(params = {}) {
|
|
157
|
+
const usesDefaultRuntime = !params.requireFn && !params.runCommand && !params.resolveFn && !params.nodeExecutable;
|
|
158
|
+
if (usesDefaultRuntime && defaultMatrixCryptoRuntimeEnsurePromise) {
|
|
159
|
+
await defaultMatrixCryptoRuntimeEnsurePromise;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const ensurePromise = ensureMatrixCryptoRuntimeOnce(params);
|
|
163
|
+
if (!usesDefaultRuntime) {
|
|
164
|
+
await ensurePromise;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
defaultMatrixCryptoRuntimeEnsurePromise = ensurePromise.catch((error) => {
|
|
168
|
+
defaultMatrixCryptoRuntimeEnsurePromise = null;
|
|
169
|
+
throw error;
|
|
170
|
+
});
|
|
171
|
+
await defaultMatrixCryptoRuntimeEnsurePromise;
|
|
172
|
+
}
|
|
173
|
+
async function ensureMatrixCryptoRuntimeOnce(params) {
|
|
174
|
+
const resolveFn = params.resolveFn ?? defaultResolveFn;
|
|
175
|
+
const nativeBindingPath = resolveMatrixCryptoNativeBindingPath(resolveFn);
|
|
176
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
177
|
+
bindingPath: nativeBindingPath,
|
|
178
|
+
log: params.log
|
|
179
|
+
});
|
|
180
|
+
const requireFn = params.requireFn ?? defaultRequireFn;
|
|
181
|
+
try {
|
|
182
|
+
requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
183
|
+
return;
|
|
184
|
+
} catch (err) {
|
|
185
|
+
if (!isMissingMatrixCryptoRuntimeError(err)) throw err;
|
|
186
|
+
}
|
|
187
|
+
const scriptPath = resolveFn("@matrix-org/matrix-sdk-crypto-nodejs/download-lib.js");
|
|
188
|
+
params.log?.("matrix: bootstrapping native crypto runtime");
|
|
189
|
+
const result = await (params.runCommand ?? runFixedCommandWithTimeout)({
|
|
190
|
+
argv: [params.nodeExecutable ?? process.execPath, scriptPath],
|
|
191
|
+
cwd: path.dirname(scriptPath),
|
|
192
|
+
timeoutMs: 3e5,
|
|
193
|
+
env: { COREPACK_ENABLE_DOWNLOAD_PROMPT: "0" }
|
|
194
|
+
});
|
|
195
|
+
if (result.code !== 0) {
|
|
196
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
197
|
+
bindingPath: nativeBindingPath,
|
|
198
|
+
log: params.log
|
|
199
|
+
});
|
|
200
|
+
throw new Error(result.stderr.trim() || result.stdout.trim() || "Matrix crypto runtime bootstrap failed.");
|
|
201
|
+
}
|
|
202
|
+
removeIncompleteMatrixCryptoNativeBinding({
|
|
203
|
+
bindingPath: nativeBindingPath,
|
|
204
|
+
log: params.log
|
|
205
|
+
});
|
|
206
|
+
requireFn("@matrix-org/matrix-sdk-crypto-nodejs");
|
|
207
|
+
}
|
|
208
|
+
async function ensureMatrixSdkInstalled(params) {
|
|
209
|
+
if (isMatrixSdkAvailable()) return;
|
|
210
|
+
const confirm = params.confirm;
|
|
211
|
+
if (confirm) {
|
|
212
|
+
if (!await confirm("Matrix requires matrix-js-sdk, @matrix-org/matrix-sdk-crypto-nodejs, and @matrix-org/matrix-sdk-crypto-wasm. Install now?")) throw new Error("Matrix requires matrix-js-sdk, @matrix-org/matrix-sdk-crypto-nodejs, and @matrix-org/matrix-sdk-crypto-wasm (install dependencies first).");
|
|
213
|
+
}
|
|
214
|
+
const root = resolvePluginRoot();
|
|
215
|
+
const command = fs.existsSync(path.join(root, "pnpm-lock.yaml")) ? ["pnpm", "install"] : [
|
|
216
|
+
"npm",
|
|
217
|
+
"install",
|
|
218
|
+
"--omit=dev",
|
|
219
|
+
"--silent"
|
|
220
|
+
];
|
|
221
|
+
params.runtime.log?.(`matrix: installing dependencies via ${command[0]} (${root})…`);
|
|
222
|
+
const result = await runFixedCommandWithTimeout({
|
|
223
|
+
argv: command,
|
|
224
|
+
cwd: root,
|
|
225
|
+
timeoutMs: 3e5,
|
|
226
|
+
env: { COREPACK_ENABLE_DOWNLOAD_PROMPT: "0" }
|
|
227
|
+
});
|
|
228
|
+
if (result.code !== 0) throw new Error(result.stderr.trim() || result.stdout.trim() || "Matrix dependency install failed.");
|
|
229
|
+
if (!isMatrixSdkAvailable()) {
|
|
230
|
+
const missing = resolveMissingMatrixPackages();
|
|
231
|
+
throw new Error(missing.length > 0 ? `Matrix dependency install completed but required packages are still missing: ${missing.join(", ")}` : "Matrix dependency install completed but Matrix dependencies are still missing.");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
export { ensureMatrixSdkInstalled as n, isMatrixSdkAvailable as r, ensureMatrixCryptoRuntime as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region extensions/matrix/src/matrix/device-health.ts
|
|
2
|
+
const OPENCLAW_DEVICE_NAME_PREFIX = "OpenClaw ";
|
|
3
|
+
function isOpenClawManagedMatrixDevice(displayName) {
|
|
4
|
+
return displayName?.startsWith(OPENCLAW_DEVICE_NAME_PREFIX) === true;
|
|
5
|
+
}
|
|
6
|
+
function summarizeMatrixDeviceHealth(devices) {
|
|
7
|
+
const currentDeviceId = devices.find((device) => device.current)?.deviceId ?? null;
|
|
8
|
+
const openClawDevices = devices.filter((device) => isOpenClawManagedMatrixDevice(device.displayName));
|
|
9
|
+
return {
|
|
10
|
+
currentDeviceId,
|
|
11
|
+
staleOpenClawDevices: openClawDevices.filter((device) => !device.current),
|
|
12
|
+
currentOpenClawDevices: openClawDevices.filter((device) => device.current)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { isOpenClawManagedMatrixDevice, summarizeMatrixDeviceHealth };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { t as isMatrixQualifiedUserId } from "./target-ids-80nQ2gql.js";
|
|
3
|
+
import { n as MATRIX_REACTION_EVENT_TYPE, t as MATRIX_ANNOTATION_RELATION_TYPE } from "./reaction-common-ejrL19w-.js";
|
|
4
|
+
import { r as inspectMatrixDirectRoomEvidence } from "./direct-room-XkutHjES.js";
|
|
5
|
+
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
6
|
+
import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
|
|
7
|
+
//#region extensions/matrix/src/matrix/send/types.ts
|
|
8
|
+
const MsgType = {
|
|
9
|
+
Text: "m.text",
|
|
10
|
+
Image: "m.image",
|
|
11
|
+
Audio: "m.audio",
|
|
12
|
+
Video: "m.video",
|
|
13
|
+
File: "m.file",
|
|
14
|
+
Notice: "m.notice"
|
|
15
|
+
};
|
|
16
|
+
const RelationType = {
|
|
17
|
+
Annotation: MATRIX_ANNOTATION_RELATION_TYPE,
|
|
18
|
+
Replace: "m.replace",
|
|
19
|
+
Thread: "m.thread"
|
|
20
|
+
};
|
|
21
|
+
const EventType = {
|
|
22
|
+
Direct: "m.direct",
|
|
23
|
+
Reaction: MATRIX_REACTION_EVENT_TYPE,
|
|
24
|
+
RoomMessage: "m.room.message"
|
|
25
|
+
};
|
|
26
|
+
const MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY = "com.openclaw.finalized_preview";
|
|
27
|
+
/**
|
|
28
|
+
* MSC4357 live marker key.
|
|
29
|
+
* When present on event content, signals that the message is still being
|
|
30
|
+
* streamed (e.g. an LLM generating a response). Supporting clients render
|
|
31
|
+
* the message with a streaming animation until an edit without this marker
|
|
32
|
+
* arrives, indicating the stream is complete.
|
|
33
|
+
* @see https://github.com/matrix-org/matrix-spec-proposals/pull/4357
|
|
34
|
+
*/
|
|
35
|
+
const MSC4357_LIVE_KEY = "org.matrix.msc4357.live";
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region extensions/matrix/src/matrix/direct-management.ts
|
|
38
|
+
var direct_management_exports = /* @__PURE__ */ __exportAll({
|
|
39
|
+
inspectMatrixDirectRooms: () => inspectMatrixDirectRooms,
|
|
40
|
+
persistMatrixDirectRoomMapping: () => persistMatrixDirectRoomMapping,
|
|
41
|
+
promoteMatrixDirectRoomCandidate: () => promoteMatrixDirectRoomCandidate,
|
|
42
|
+
repairMatrixDirectRooms: () => repairMatrixDirectRooms
|
|
43
|
+
});
|
|
44
|
+
const DIRECT_ACCOUNT_DATA_QUEUE_KEY = EventType.Direct;
|
|
45
|
+
const directAccountDataWriteQueues = /* @__PURE__ */ new WeakMap();
|
|
46
|
+
async function readMatrixDirectAccountData(client) {
|
|
47
|
+
try {
|
|
48
|
+
const direct = await client.getAccountData(EventType.Direct);
|
|
49
|
+
return direct && typeof direct === "object" && !Array.isArray(direct) ? direct : {};
|
|
50
|
+
} catch {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function normalizeRemoteUserId(remoteUserId) {
|
|
55
|
+
const normalized = normalizeOptionalString(remoteUserId) ?? "";
|
|
56
|
+
if (!isMatrixQualifiedUserId(normalized)) throw new Error(`Matrix user IDs must be fully qualified (got "${remoteUserId}")`);
|
|
57
|
+
return normalized;
|
|
58
|
+
}
|
|
59
|
+
function normalizeMappedRoomIds(direct, remoteUserId) {
|
|
60
|
+
const current = direct[remoteUserId];
|
|
61
|
+
if (!Array.isArray(current)) return [];
|
|
62
|
+
const seen = /* @__PURE__ */ new Set();
|
|
63
|
+
const normalized = [];
|
|
64
|
+
for (const value of current) {
|
|
65
|
+
const roomId = normalizeOptionalString(value) ?? "";
|
|
66
|
+
if (!roomId || seen.has(roomId)) continue;
|
|
67
|
+
seen.add(roomId);
|
|
68
|
+
normalized.push(roomId);
|
|
69
|
+
}
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
function normalizeRoomIdList(values) {
|
|
73
|
+
const seen = /* @__PURE__ */ new Set();
|
|
74
|
+
const normalized = [];
|
|
75
|
+
for (const value of values) {
|
|
76
|
+
const roomId = value.trim();
|
|
77
|
+
if (!roomId || seen.has(roomId)) continue;
|
|
78
|
+
seen.add(roomId);
|
|
79
|
+
normalized.push(roomId);
|
|
80
|
+
}
|
|
81
|
+
return normalized;
|
|
82
|
+
}
|
|
83
|
+
function hasPrimaryMatrixDirectRoomMapping(params) {
|
|
84
|
+
return normalizeMappedRoomIds(params.directContent, params.remoteUserId)[0] === params.roomId;
|
|
85
|
+
}
|
|
86
|
+
function resolveDirectAccountDataWriteQueue(client) {
|
|
87
|
+
const existing = directAccountDataWriteQueues.get(client);
|
|
88
|
+
if (existing) return existing;
|
|
89
|
+
const created = new KeyedAsyncQueue();
|
|
90
|
+
directAccountDataWriteQueues.set(client, created);
|
|
91
|
+
return created;
|
|
92
|
+
}
|
|
93
|
+
async function writeMatrixDirectRoomMapping(params) {
|
|
94
|
+
return await resolveDirectAccountDataWriteQueue(params.client).enqueue(DIRECT_ACCOUNT_DATA_QUEUE_KEY, async () => {
|
|
95
|
+
const directContentBefore = await readMatrixDirectAccountData(params.client);
|
|
96
|
+
const directContentAfter = buildNextDirectContent({
|
|
97
|
+
directContent: directContentBefore,
|
|
98
|
+
remoteUserId: params.remoteUserId,
|
|
99
|
+
roomId: params.roomId
|
|
100
|
+
});
|
|
101
|
+
const changed = !hasPrimaryMatrixDirectRoomMapping({
|
|
102
|
+
directContent: directContentBefore,
|
|
103
|
+
remoteUserId: params.remoteUserId,
|
|
104
|
+
roomId: params.roomId
|
|
105
|
+
});
|
|
106
|
+
if (changed) await params.client.setAccountData(EventType.Direct, directContentAfter);
|
|
107
|
+
return {
|
|
108
|
+
changed,
|
|
109
|
+
directContentBefore,
|
|
110
|
+
directContentAfter
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function classifyDirectRoomCandidate(params) {
|
|
115
|
+
const evidence = await inspectMatrixDirectRoomEvidence({
|
|
116
|
+
client: params.client,
|
|
117
|
+
roomId: params.roomId,
|
|
118
|
+
remoteUserId: params.remoteUserId,
|
|
119
|
+
selfUserId: params.selfUserId
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
roomId: params.roomId,
|
|
123
|
+
joinedMembers: evidence.joinedMembers,
|
|
124
|
+
strict: evidence.strict && (params.source === "account-data" || evidence.memberStateFlag !== false),
|
|
125
|
+
explicit: evidence.strict && (params.source === "account-data" || evidence.memberStateFlag !== false) && (params.source === "account-data" || evidence.viaMemberState),
|
|
126
|
+
source: params.source
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function buildNextDirectContent(params) {
|
|
130
|
+
const current = normalizeMappedRoomIds(params.directContent, params.remoteUserId);
|
|
131
|
+
const nextRooms = normalizeRoomIdList([params.roomId, ...current]);
|
|
132
|
+
return {
|
|
133
|
+
...params.directContent,
|
|
134
|
+
[params.remoteUserId]: nextRooms
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async function persistMatrixDirectRoomMapping(params) {
|
|
138
|
+
const remoteUserId = normalizeRemoteUserId(params.remoteUserId);
|
|
139
|
+
return (await writeMatrixDirectRoomMapping({
|
|
140
|
+
client: params.client,
|
|
141
|
+
remoteUserId,
|
|
142
|
+
roomId: params.roomId
|
|
143
|
+
})).changed;
|
|
144
|
+
}
|
|
145
|
+
async function promoteMatrixDirectRoomCandidate(params) {
|
|
146
|
+
const remoteUserId = normalizeRemoteUserId(params.remoteUserId);
|
|
147
|
+
const evidence = await inspectMatrixDirectRoomEvidence({
|
|
148
|
+
client: params.client,
|
|
149
|
+
roomId: params.roomId,
|
|
150
|
+
remoteUserId,
|
|
151
|
+
selfUserId: params.selfUserId
|
|
152
|
+
});
|
|
153
|
+
if (!evidence.strict) return {
|
|
154
|
+
classifyAsDirect: false,
|
|
155
|
+
repaired: false,
|
|
156
|
+
reason: "not-strict"
|
|
157
|
+
};
|
|
158
|
+
if (evidence.memberStateFlag === false) return {
|
|
159
|
+
classifyAsDirect: false,
|
|
160
|
+
repaired: false,
|
|
161
|
+
reason: "local-explicit-false"
|
|
162
|
+
};
|
|
163
|
+
try {
|
|
164
|
+
const repaired = await persistMatrixDirectRoomMapping({
|
|
165
|
+
client: params.client,
|
|
166
|
+
remoteUserId,
|
|
167
|
+
roomId: params.roomId
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
classifyAsDirect: true,
|
|
171
|
+
repaired,
|
|
172
|
+
roomId: params.roomId,
|
|
173
|
+
reason: repaired ? "promoted" : "already-mapped"
|
|
174
|
+
};
|
|
175
|
+
} catch {
|
|
176
|
+
return {
|
|
177
|
+
classifyAsDirect: true,
|
|
178
|
+
repaired: false,
|
|
179
|
+
roomId: params.roomId,
|
|
180
|
+
reason: "repair-failed"
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async function inspectMatrixDirectRooms(params) {
|
|
185
|
+
const remoteUserId = normalizeRemoteUserId(params.remoteUserId);
|
|
186
|
+
const selfUserId = normalizeOptionalString(await params.client.getUserId().catch(() => null)) ?? null;
|
|
187
|
+
const mappedRoomIds = normalizeMappedRoomIds(await readMatrixDirectAccountData(params.client), remoteUserId);
|
|
188
|
+
const mappedRooms = await Promise.all(mappedRoomIds.map(async (roomId) => await classifyDirectRoomCandidate({
|
|
189
|
+
client: params.client,
|
|
190
|
+
roomId,
|
|
191
|
+
remoteUserId,
|
|
192
|
+
selfUserId,
|
|
193
|
+
source: "account-data"
|
|
194
|
+
})));
|
|
195
|
+
const mappedStrict = mappedRooms.find((room) => room.strict);
|
|
196
|
+
let joinedRooms = [];
|
|
197
|
+
if (!mappedStrict && typeof params.client.getJoinedRooms === "function") try {
|
|
198
|
+
const resolved = await params.client.getJoinedRooms();
|
|
199
|
+
joinedRooms = Array.isArray(resolved) ? resolved : [];
|
|
200
|
+
} catch {
|
|
201
|
+
joinedRooms = [];
|
|
202
|
+
}
|
|
203
|
+
const discoveredStrictRooms = [];
|
|
204
|
+
for (const roomId of normalizeRoomIdList(joinedRooms)) {
|
|
205
|
+
if (mappedRoomIds.includes(roomId)) continue;
|
|
206
|
+
const candidate = await classifyDirectRoomCandidate({
|
|
207
|
+
client: params.client,
|
|
208
|
+
roomId,
|
|
209
|
+
remoteUserId,
|
|
210
|
+
selfUserId,
|
|
211
|
+
source: "joined"
|
|
212
|
+
});
|
|
213
|
+
if (candidate.strict) discoveredStrictRooms.push(candidate);
|
|
214
|
+
}
|
|
215
|
+
const discoveredStrictRoomIds = discoveredStrictRooms.map((room) => room.roomId);
|
|
216
|
+
const discoveredExplicit = discoveredStrictRooms.find((room) => room.explicit);
|
|
217
|
+
return {
|
|
218
|
+
selfUserId,
|
|
219
|
+
remoteUserId,
|
|
220
|
+
mappedRoomIds,
|
|
221
|
+
mappedRooms,
|
|
222
|
+
discoveredStrictRoomIds,
|
|
223
|
+
activeRoomId: mappedStrict?.roomId ?? discoveredExplicit?.roomId ?? discoveredStrictRoomIds[0] ?? null
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
async function repairMatrixDirectRooms(params) {
|
|
227
|
+
const remoteUserId = normalizeRemoteUserId(params.remoteUserId);
|
|
228
|
+
const inspected = await inspectMatrixDirectRooms({
|
|
229
|
+
client: params.client,
|
|
230
|
+
remoteUserId
|
|
231
|
+
});
|
|
232
|
+
const activeRoomId = inspected.activeRoomId ?? await params.client.createDirectRoom(remoteUserId, { encrypted: params.encrypted === true });
|
|
233
|
+
const createdRoomId = inspected.activeRoomId ? null : activeRoomId;
|
|
234
|
+
const mappingWrite = await writeMatrixDirectRoomMapping({
|
|
235
|
+
client: params.client,
|
|
236
|
+
remoteUserId,
|
|
237
|
+
roomId: activeRoomId
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
...inspected,
|
|
241
|
+
activeRoomId,
|
|
242
|
+
createdRoomId,
|
|
243
|
+
changed: mappingWrite.changed,
|
|
244
|
+
directContentBefore: mappingWrite.directContentBefore,
|
|
245
|
+
directContentAfter: mappingWrite.directContentAfter
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
249
|
+
export { repairMatrixDirectRooms as a, MSC4357_LIVE_KEY as c, promoteMatrixDirectRoomCandidate as i, MsgType as l, inspectMatrixDirectRooms as n, EventType as o, persistMatrixDirectRoomMapping as r, MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY as s, direct_management_exports as t, RelationType as u };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
//#region extensions/matrix/src/matrix/direct-room.ts
|
|
3
|
+
var direct_room_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
hasDirectMatrixMemberFlag: () => hasDirectMatrixMemberFlag,
|
|
5
|
+
inspectMatrixDirectRoomEvidence: () => inspectMatrixDirectRoomEvidence,
|
|
6
|
+
isStrictDirectMembership: () => isStrictDirectMembership,
|
|
7
|
+
isStrictDirectRoom: () => isStrictDirectRoom,
|
|
8
|
+
normalizeJoinedMatrixMembers: () => normalizeJoinedMatrixMembers,
|
|
9
|
+
readJoinedMatrixMembers: () => readJoinedMatrixMembers
|
|
10
|
+
});
|
|
11
|
+
function trimMaybeString(value) {
|
|
12
|
+
if (typeof value !== "string") return null;
|
|
13
|
+
const trimmed = value.trim();
|
|
14
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
15
|
+
}
|
|
16
|
+
function normalizeJoinedMatrixMembers(joinedMembers) {
|
|
17
|
+
if (!Array.isArray(joinedMembers)) return [];
|
|
18
|
+
return joinedMembers.map((entry) => trimMaybeString(entry)).filter((entry) => Boolean(entry));
|
|
19
|
+
}
|
|
20
|
+
function isStrictDirectMembership(params) {
|
|
21
|
+
const selfUserId = trimMaybeString(params.selfUserId);
|
|
22
|
+
const remoteUserId = trimMaybeString(params.remoteUserId);
|
|
23
|
+
const joinedMembers = params.joinedMembers ?? [];
|
|
24
|
+
return Boolean(selfUserId && remoteUserId && joinedMembers.length === 2 && joinedMembers.includes(selfUserId) && joinedMembers.includes(remoteUserId));
|
|
25
|
+
}
|
|
26
|
+
async function readJoinedMatrixMembers(client, roomId) {
|
|
27
|
+
try {
|
|
28
|
+
return normalizeJoinedMatrixMembers(await client.getJoinedRoomMembers(roomId));
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function hasDirectMatrixMemberFlag(client, roomId, userId) {
|
|
34
|
+
const normalizedUserId = trimMaybeString(userId);
|
|
35
|
+
if (!normalizedUserId) return null;
|
|
36
|
+
try {
|
|
37
|
+
const state = await client.getRoomStateEvent(roomId, "m.room.member", normalizedUserId);
|
|
38
|
+
if (state?.is_direct === true) return true;
|
|
39
|
+
if (state?.is_direct === false) return false;
|
|
40
|
+
return null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function inspectMatrixDirectRoomEvidence(params) {
|
|
46
|
+
const selfUserId = params.selfUserId !== void 0 ? trimMaybeString(params.selfUserId) : trimMaybeString(await params.client.getUserId().catch(() => null));
|
|
47
|
+
const joinedMembers = await readJoinedMatrixMembers(params.client, params.roomId);
|
|
48
|
+
const strict = isStrictDirectMembership({
|
|
49
|
+
selfUserId,
|
|
50
|
+
remoteUserId: params.remoteUserId,
|
|
51
|
+
joinedMembers
|
|
52
|
+
});
|
|
53
|
+
if (!strict) return {
|
|
54
|
+
joinedMembers,
|
|
55
|
+
strict: false,
|
|
56
|
+
viaMemberState: false,
|
|
57
|
+
memberStateFlag: null
|
|
58
|
+
};
|
|
59
|
+
const memberStateFlag = await hasDirectMatrixMemberFlag(params.client, params.roomId, selfUserId);
|
|
60
|
+
return {
|
|
61
|
+
joinedMembers,
|
|
62
|
+
strict,
|
|
63
|
+
viaMemberState: memberStateFlag === true,
|
|
64
|
+
memberStateFlag
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async function isStrictDirectRoom(params) {
|
|
68
|
+
return (await inspectMatrixDirectRoomEvidence({
|
|
69
|
+
client: params.client,
|
|
70
|
+
roomId: params.roomId,
|
|
71
|
+
remoteUserId: params.remoteUserId,
|
|
72
|
+
selfUserId: params.selfUserId
|
|
73
|
+
})).strict;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { isStrictDirectRoom as a, isStrictDirectMembership as i, hasDirectMatrixMemberFlag as n, readJoinedMatrixMembers as o, inspectMatrixDirectRoomEvidence as r, direct_room_exports as t };
|