@openclaw/matrix 2026.3.13 → 2026.5.10-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-H_6lMgwf.js +1116 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-BnO9f0pR.js +246 -0
- package/dist/cli-CYZ9yVcB.js +1340 -0
- package/dist/cli-metadata-DPIHnoa6.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-BaRCKyLd.js +4175 -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-DTKcXOhp.js +24 -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-DQXjgNLt.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-ThYhfHtZ.js +532 -0
- package/dist/url-validation-DiK9j7jz.js +36 -0
- package/dist/verification-CZ2rDeHL.js +345 -0
- package/openclaw.plugin.json +796 -1
- package/package.json +82 -16
- package/CHANGELOG.md +0 -104
- package/index.ts +0 -22
- package/src/actions.ts +0 -195
- package/src/channel.directory.test.ts +0 -135
- 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 -94
- package/src/matrix/monitor/auto-join.ts +0 -72
- package/src/matrix/monitor/direct.test.ts +0 -396
- package/src/matrix/monitor/direct.ts +0 -152
- package/src/matrix/monitor/events.test.ts +0 -186
- 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 -768
- 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 -145
- package/src/matrix/send-queue.ts +0 -28
- package/src/matrix/send.test.ts +0 -319
- 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 -68
- package/src/resolve-targets.ts +0 -125
- package/src/runtime.ts +0 -6
- package/src/secret-input.ts +0 -13
- package/src/test-mocks.ts +0 -53
- package/src/tool-actions.ts +0 -164
- package/src/types.ts +0 -118
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
|
|
2
|
+
import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-80nQ2gql.js";
|
|
3
|
+
import { t as MatrixAuthedHttpClient } from "./http-client-C7AeVJay.js";
|
|
4
|
+
import { n as resolveMatrixAuth } from "./config--5-S2Akv.js";
|
|
5
|
+
import "./client-_hckQNGW.js";
|
|
6
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
|
+
//#region extensions/matrix/src/directory-live.ts
|
|
8
|
+
var directory_live_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
listMatrixDirectoryGroupsLive: () => listMatrixDirectoryGroupsLive,
|
|
10
|
+
listMatrixDirectoryPeersLive: () => listMatrixDirectoryPeersLive
|
|
11
|
+
});
|
|
12
|
+
const MATRIX_DIRECTORY_TIMEOUT_MS = 1e4;
|
|
13
|
+
function resolveMatrixDirectoryLimit(limit) {
|
|
14
|
+
return typeof limit === "number" && Number.isFinite(limit) && limit > 0 ? Math.max(1, Math.floor(limit)) : 20;
|
|
15
|
+
}
|
|
16
|
+
function createMatrixDirectoryClient(auth) {
|
|
17
|
+
return new MatrixAuthedHttpClient({
|
|
18
|
+
homeserver: auth.homeserver,
|
|
19
|
+
accessToken: auth.accessToken,
|
|
20
|
+
ssrfPolicy: auth.ssrfPolicy,
|
|
21
|
+
dispatcherPolicy: auth.dispatcherPolicy
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function resolveMatrixDirectoryContext(params) {
|
|
25
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
26
|
+
if (!query) return null;
|
|
27
|
+
const auth = await resolveMatrixAuth({
|
|
28
|
+
cfg: params.cfg,
|
|
29
|
+
accountId: params.accountId
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
auth,
|
|
33
|
+
client: createMatrixDirectoryClient(auth),
|
|
34
|
+
query,
|
|
35
|
+
queryLower: normalizeLowercaseStringOrEmpty(query)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createGroupDirectoryEntry(params) {
|
|
39
|
+
return {
|
|
40
|
+
kind: "group",
|
|
41
|
+
id: params.id,
|
|
42
|
+
name: params.name,
|
|
43
|
+
handle: params.handle
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function requestMatrixJson(client, params) {
|
|
47
|
+
return await client.requestJson({
|
|
48
|
+
method: params.method,
|
|
49
|
+
endpoint: params.endpoint,
|
|
50
|
+
body: params.body,
|
|
51
|
+
timeoutMs: MATRIX_DIRECTORY_TIMEOUT_MS
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function listMatrixDirectoryPeersLive(params) {
|
|
55
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
56
|
+
if (!query) return [];
|
|
57
|
+
const directUserId = normalizeMatrixMessagingTarget(query);
|
|
58
|
+
if (directUserId && isMatrixQualifiedUserId(directUserId)) return [{
|
|
59
|
+
kind: "user",
|
|
60
|
+
id: directUserId
|
|
61
|
+
}];
|
|
62
|
+
const context = await resolveMatrixDirectoryContext({
|
|
63
|
+
...params,
|
|
64
|
+
query
|
|
65
|
+
});
|
|
66
|
+
if (!context) return [];
|
|
67
|
+
return ((await requestMatrixJson(context.client, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
endpoint: "/_matrix/client/v3/user_directory/search",
|
|
70
|
+
body: {
|
|
71
|
+
search_term: context.query,
|
|
72
|
+
limit: resolveMatrixDirectoryLimit(params.limit)
|
|
73
|
+
}
|
|
74
|
+
})).results ?? []).map((entry) => {
|
|
75
|
+
const userId = normalizeOptionalString(entry.user_id);
|
|
76
|
+
if (!userId) return null;
|
|
77
|
+
const displayName = normalizeOptionalString(entry.display_name);
|
|
78
|
+
return {
|
|
79
|
+
kind: "user",
|
|
80
|
+
id: userId,
|
|
81
|
+
name: displayName,
|
|
82
|
+
handle: displayName ? `@${displayName}` : void 0,
|
|
83
|
+
raw: entry
|
|
84
|
+
};
|
|
85
|
+
}).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
async function resolveMatrixRoomAlias(client, alias) {
|
|
88
|
+
try {
|
|
89
|
+
return normalizeOptionalString((await requestMatrixJson(client, {
|
|
90
|
+
method: "GET",
|
|
91
|
+
endpoint: `/_matrix/client/v3/directory/room/${encodeURIComponent(alias)}`
|
|
92
|
+
})).room_id) ?? null;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function fetchMatrixRoomName(client, roomId) {
|
|
98
|
+
try {
|
|
99
|
+
return normalizeOptionalString((await requestMatrixJson(client, {
|
|
100
|
+
method: "GET",
|
|
101
|
+
endpoint: `/_matrix/client/v3/rooms/${encodeURIComponent(roomId)}/state/m.room.name`
|
|
102
|
+
})).name) ?? null;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function listMatrixDirectoryGroupsLive(params) {
|
|
108
|
+
const query = normalizeOptionalString(params.query) ?? "";
|
|
109
|
+
if (!query) return [];
|
|
110
|
+
const directTarget = normalizeMatrixMessagingTarget(query);
|
|
111
|
+
if (directTarget?.startsWith("!")) return [createGroupDirectoryEntry({
|
|
112
|
+
id: directTarget,
|
|
113
|
+
name: directTarget
|
|
114
|
+
})];
|
|
115
|
+
const context = await resolveMatrixDirectoryContext({
|
|
116
|
+
...params,
|
|
117
|
+
query
|
|
118
|
+
});
|
|
119
|
+
if (!context) return [];
|
|
120
|
+
const { client, queryLower } = context;
|
|
121
|
+
const limit = resolveMatrixDirectoryLimit(params.limit);
|
|
122
|
+
if (directTarget?.startsWith("#")) {
|
|
123
|
+
const roomId = await resolveMatrixRoomAlias(client, directTarget);
|
|
124
|
+
if (!roomId) return [];
|
|
125
|
+
return [createGroupDirectoryEntry({
|
|
126
|
+
id: roomId,
|
|
127
|
+
name: directTarget,
|
|
128
|
+
handle: directTarget
|
|
129
|
+
})];
|
|
130
|
+
}
|
|
131
|
+
const rooms = ((await requestMatrixJson(client, {
|
|
132
|
+
method: "GET",
|
|
133
|
+
endpoint: "/_matrix/client/v3/joined_rooms"
|
|
134
|
+
})).joined_rooms ?? []).map((roomId) => normalizeOptionalString(roomId)).filter((roomId) => Boolean(roomId));
|
|
135
|
+
const results = [];
|
|
136
|
+
for (const roomId of rooms) {
|
|
137
|
+
const name = await fetchMatrixRoomName(client, roomId);
|
|
138
|
+
if (!name || !normalizeLowercaseStringOrEmpty(name).includes(queryLower)) continue;
|
|
139
|
+
results.push({
|
|
140
|
+
kind: "group",
|
|
141
|
+
id: roomId,
|
|
142
|
+
name,
|
|
143
|
+
handle: `#${name}`
|
|
144
|
+
});
|
|
145
|
+
if (results.length >= limit) break;
|
|
146
|
+
}
|
|
147
|
+
return results;
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { listMatrixDirectoryGroupsLive as n, listMatrixDirectoryPeersLive as r, directory_live_exports as t };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { t as isRecord } from "./record-shared-CHWJCTWf.js";
|
|
2
|
+
import "./doctor-contract-D4-64QuJ.js";
|
|
3
|
+
import { i as autoPrepareLegacyMatrixCrypto, o as autoMigrateLegacyMatrixState, r as resolveMatrixMigrationStatus } from "./matrix-migration.runtime-WY6ffcrf.js";
|
|
4
|
+
import { t as maybeCreateMatrixMigrationSnapshot } from "./migration-snapshot-backup-DaCHTp8C.js";
|
|
5
|
+
import { detectPluginInstallPathIssue, formatPluginInstallPathIssue, removePluginFromConfig } from "openclaw/plugin-sdk/runtime-doctor";
|
|
6
|
+
//#region extensions/matrix/src/doctor.ts
|
|
7
|
+
function hasConfiguredMatrixChannel(cfg) {
|
|
8
|
+
const channels = cfg.channels;
|
|
9
|
+
return isRecord(channels?.matrix);
|
|
10
|
+
}
|
|
11
|
+
function hasConfiguredMatrixPluginSurface(cfg) {
|
|
12
|
+
return Boolean(cfg.plugins?.installs?.matrix || cfg.plugins?.entries?.matrix || cfg.plugins?.allow?.includes("matrix") || cfg.plugins?.deny?.includes("matrix"));
|
|
13
|
+
}
|
|
14
|
+
function hasConfiguredMatrixEnv(env) {
|
|
15
|
+
return Object.entries(env).some(([key, value]) => key.startsWith("MATRIX_") && typeof value === "string" && value.trim());
|
|
16
|
+
}
|
|
17
|
+
function configMayNeedMatrixDoctorSequence(cfg, env) {
|
|
18
|
+
return hasConfiguredMatrixChannel(cfg) || hasConfiguredMatrixPluginSurface(cfg) || hasConfiguredMatrixEnv(env);
|
|
19
|
+
}
|
|
20
|
+
function formatMatrixLegacyStatePreview(detection) {
|
|
21
|
+
return [
|
|
22
|
+
"- Matrix plugin upgraded in place.",
|
|
23
|
+
`- Legacy sync store: ${detection.legacyStoragePath} -> ${detection.targetStoragePath}`,
|
|
24
|
+
`- Legacy crypto store: ${detection.legacyCryptoPath} -> ${detection.targetCryptoPath}`,
|
|
25
|
+
...detection.selectionNote ? [`- ${detection.selectionNote}`] : [],
|
|
26
|
+
"- Run \"openclaw doctor --fix\" to migrate this Matrix state now."
|
|
27
|
+
].join("\n");
|
|
28
|
+
}
|
|
29
|
+
function formatMatrixLegacyCryptoPreview(detection) {
|
|
30
|
+
const notes = [];
|
|
31
|
+
for (const warning of detection.warnings) notes.push(`- ${warning}`);
|
|
32
|
+
for (const plan of detection.plans) notes.push([
|
|
33
|
+
`- Matrix encrypted-state migration is pending for account "${plan.accountId}".`,
|
|
34
|
+
`- Legacy crypto store: ${plan.legacyCryptoPath}`,
|
|
35
|
+
`- New recovery key file: ${plan.recoveryKeyPath}`,
|
|
36
|
+
`- Migration state file: ${plan.statePath}`,
|
|
37
|
+
"- Run \"openclaw doctor --fix\" to extract any saved backup key now. Backed-up room keys will restore automatically on next gateway start."
|
|
38
|
+
].join("\n"));
|
|
39
|
+
return notes;
|
|
40
|
+
}
|
|
41
|
+
async function collectMatrixInstallPathWarnings(cfg) {
|
|
42
|
+
const issue = await detectPluginInstallPathIssue({
|
|
43
|
+
pluginId: "matrix",
|
|
44
|
+
install: cfg.plugins?.installs?.matrix
|
|
45
|
+
});
|
|
46
|
+
if (!issue) return [];
|
|
47
|
+
return formatPluginInstallPathIssue({
|
|
48
|
+
issue,
|
|
49
|
+
pluginLabel: "Matrix",
|
|
50
|
+
defaultInstallCommand: "openclaw plugins install @openclaw/matrix"
|
|
51
|
+
}).map((entry) => `- ${entry}`);
|
|
52
|
+
}
|
|
53
|
+
async function cleanStaleMatrixPluginConfig(cfg) {
|
|
54
|
+
const issue = await detectPluginInstallPathIssue({
|
|
55
|
+
pluginId: "matrix",
|
|
56
|
+
install: cfg.plugins?.installs?.matrix
|
|
57
|
+
});
|
|
58
|
+
if (!issue || issue.kind !== "missing-path") return {
|
|
59
|
+
config: cfg,
|
|
60
|
+
changes: []
|
|
61
|
+
};
|
|
62
|
+
const { config, actions } = removePluginFromConfig(cfg, "matrix");
|
|
63
|
+
const removed = [];
|
|
64
|
+
if (actions.install) removed.push("install record");
|
|
65
|
+
if (actions.loadPath) removed.push("load path");
|
|
66
|
+
if (actions.entry) removed.push("plugin entry");
|
|
67
|
+
if (actions.allowlist) removed.push("allowlist entry");
|
|
68
|
+
if (removed.length === 0) return {
|
|
69
|
+
config: cfg,
|
|
70
|
+
changes: []
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
config,
|
|
74
|
+
changes: [`Removed stale Matrix plugin references (${removed.join(", ")}). The previous install path no longer exists: ${issue.path}`]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function applyMatrixDoctorRepair(params) {
|
|
78
|
+
const changes = [];
|
|
79
|
+
const warnings = [];
|
|
80
|
+
const migrationStatus = resolveMatrixMigrationStatus({
|
|
81
|
+
cfg: params.cfg,
|
|
82
|
+
env: params.env
|
|
83
|
+
});
|
|
84
|
+
let matrixSnapshotReady = true;
|
|
85
|
+
if (migrationStatus.actionable) try {
|
|
86
|
+
const snapshot = await maybeCreateMatrixMigrationSnapshot({
|
|
87
|
+
trigger: "doctor-fix",
|
|
88
|
+
env: params.env
|
|
89
|
+
});
|
|
90
|
+
changes.push(`Matrix migration snapshot ${snapshot.created ? "created" : "reused"} before applying Matrix upgrades.\n- ${snapshot.archivePath}`);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
matrixSnapshotReady = false;
|
|
93
|
+
warnings.push(`- Failed creating a Matrix migration snapshot before repair: ${String(error)}`);
|
|
94
|
+
warnings.push("- Skipping Matrix migration changes for now. Resolve the snapshot failure, then rerun \"openclaw doctor --fix\".");
|
|
95
|
+
}
|
|
96
|
+
else if (migrationStatus.pending) warnings.push("- Matrix migration warnings are present, but no on-disk Matrix mutation is actionable yet. No pre-migration snapshot was needed.");
|
|
97
|
+
if (!matrixSnapshotReady) return {
|
|
98
|
+
changes,
|
|
99
|
+
warnings
|
|
100
|
+
};
|
|
101
|
+
const matrixStateRepair = await autoMigrateLegacyMatrixState({
|
|
102
|
+
cfg: params.cfg,
|
|
103
|
+
env: params.env
|
|
104
|
+
});
|
|
105
|
+
if (matrixStateRepair.changes.length > 0) changes.push([
|
|
106
|
+
"Matrix plugin upgraded in place.",
|
|
107
|
+
...matrixStateRepair.changes.map((entry) => `- ${entry}`),
|
|
108
|
+
"- No user action required."
|
|
109
|
+
].join("\n"));
|
|
110
|
+
if (matrixStateRepair.warnings.length > 0) warnings.push(matrixStateRepair.warnings.map((entry) => `- ${entry}`).join("\n"));
|
|
111
|
+
const matrixCryptoRepair = await autoPrepareLegacyMatrixCrypto({
|
|
112
|
+
cfg: params.cfg,
|
|
113
|
+
env: params.env
|
|
114
|
+
});
|
|
115
|
+
if (matrixCryptoRepair.changes.length > 0) changes.push(["Matrix encrypted-state migration prepared.", ...matrixCryptoRepair.changes.map((entry) => `- ${entry}`)].join("\n"));
|
|
116
|
+
if (matrixCryptoRepair.warnings.length > 0) warnings.push(matrixCryptoRepair.warnings.map((entry) => `- ${entry}`).join("\n"));
|
|
117
|
+
return {
|
|
118
|
+
changes,
|
|
119
|
+
warnings
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function runMatrixDoctorSequence(params) {
|
|
123
|
+
const warningNotes = [];
|
|
124
|
+
const changeNotes = [];
|
|
125
|
+
const installWarnings = await collectMatrixInstallPathWarnings(params.cfg);
|
|
126
|
+
if (installWarnings.length > 0) warningNotes.push(installWarnings.join("\n"));
|
|
127
|
+
if (!configMayNeedMatrixDoctorSequence(params.cfg, params.env)) return {
|
|
128
|
+
changeNotes,
|
|
129
|
+
warningNotes
|
|
130
|
+
};
|
|
131
|
+
if (params.shouldRepair) {
|
|
132
|
+
const repair = await applyMatrixDoctorRepair({
|
|
133
|
+
cfg: params.cfg,
|
|
134
|
+
env: params.env
|
|
135
|
+
});
|
|
136
|
+
changeNotes.push(...repair.changes);
|
|
137
|
+
warningNotes.push(...repair.warnings);
|
|
138
|
+
} else {
|
|
139
|
+
const migrationStatus = resolveMatrixMigrationStatus({
|
|
140
|
+
cfg: params.cfg,
|
|
141
|
+
env: params.env
|
|
142
|
+
});
|
|
143
|
+
if (migrationStatus.legacyState) if ("warning" in migrationStatus.legacyState) warningNotes.push(`- ${migrationStatus.legacyState.warning}`);
|
|
144
|
+
else warningNotes.push(formatMatrixLegacyStatePreview(migrationStatus.legacyState));
|
|
145
|
+
if (migrationStatus.legacyCrypto.warnings.length > 0 || migrationStatus.legacyCrypto.plans.length > 0) warningNotes.push(...formatMatrixLegacyCryptoPreview(migrationStatus.legacyCrypto));
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
changeNotes,
|
|
149
|
+
warningNotes
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
export { cleanStaleMatrixPluginConfig, runMatrixDoctorSequence };
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { t as isRecord } from "./record-shared-CHWJCTWf.js";
|
|
2
|
+
import { hasLegacyFlatAllowPrivateNetworkAlias, migrateLegacyFlatAllowPrivateNetworkAlias } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
3
|
+
//#region extensions/matrix/src/doctor-contract.ts
|
|
4
|
+
function hasLegacyMatrixRoomAllowAlias(value) {
|
|
5
|
+
const room = isRecord(value) ? value : null;
|
|
6
|
+
return Boolean(room && typeof room.allow === "boolean");
|
|
7
|
+
}
|
|
8
|
+
function hasLegacyMatrixRoomMapAllowAliases(value) {
|
|
9
|
+
const rooms = isRecord(value) ? value : null;
|
|
10
|
+
return Boolean(rooms && Object.values(rooms).some((room) => hasLegacyMatrixRoomAllowAlias(room)));
|
|
11
|
+
}
|
|
12
|
+
function hasLegacyMatrixAccountRoomAllowAliases(value) {
|
|
13
|
+
const accounts = isRecord(value) ? value : null;
|
|
14
|
+
if (!accounts) return false;
|
|
15
|
+
return Object.values(accounts).some((account) => {
|
|
16
|
+
if (!isRecord(account)) return false;
|
|
17
|
+
return hasLegacyMatrixRoomMapAllowAliases(account.groups) || hasLegacyMatrixRoomMapAllowAliases(account.rooms);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function hasLegacyMatrixAccountPrivateNetworkAliases(value) {
|
|
21
|
+
const accounts = isRecord(value) ? value : null;
|
|
22
|
+
if (!accounts) return false;
|
|
23
|
+
return Object.values(accounts).some((account) => hasLegacyFlatAllowPrivateNetworkAlias(isRecord(account) ? account : {}));
|
|
24
|
+
}
|
|
25
|
+
function hasLegacyTrustedDmPolicy(value) {
|
|
26
|
+
const root = isRecord(value) ? value : null;
|
|
27
|
+
if (!root) return false;
|
|
28
|
+
return (isRecord(root.dm) ? root.dm : null)?.policy === "trusted";
|
|
29
|
+
}
|
|
30
|
+
function hasLegacyMatrixAccountTrustedDmPolicies(value) {
|
|
31
|
+
const accounts = isRecord(value) ? value : null;
|
|
32
|
+
if (!accounts) return false;
|
|
33
|
+
return Object.values(accounts).some((account) => hasLegacyTrustedDmPolicy(account));
|
|
34
|
+
}
|
|
35
|
+
function migrateLegacyTrustedDmPolicy(params) {
|
|
36
|
+
const dm = isRecord(params.entry.dm) ? params.entry.dm : null;
|
|
37
|
+
if (!dm || dm.policy !== "trusted") return {
|
|
38
|
+
entry: params.entry,
|
|
39
|
+
changed: false
|
|
40
|
+
};
|
|
41
|
+
const allowFromRaw = dm.allowFrom;
|
|
42
|
+
const allowFromEntries = Array.isArray(allowFromRaw) ? allowFromRaw.filter((entry) => typeof entry === "string" && entry.trim().length > 0).length : 0;
|
|
43
|
+
const nextPolicy = allowFromEntries > 0 ? "allowlist" : "pairing";
|
|
44
|
+
const nextDm = {
|
|
45
|
+
...dm,
|
|
46
|
+
policy: nextPolicy
|
|
47
|
+
};
|
|
48
|
+
params.changes.push(`Migrated ${params.pathPrefix}.dm.policy "trusted" → "${nextPolicy}" (legacy alias removed; ${allowFromEntries > 0 ? `preserved ${allowFromEntries} ${params.pathPrefix}.dm.allowFrom ${allowFromEntries === 1 ? "entry" : "entries"}` : "no allowFrom entries present, defaulting to pairing for safety"}).`);
|
|
49
|
+
return {
|
|
50
|
+
entry: {
|
|
51
|
+
...params.entry,
|
|
52
|
+
dm: nextDm
|
|
53
|
+
},
|
|
54
|
+
changed: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function normalizeMatrixRoomAllowAliases(params) {
|
|
58
|
+
let changed = false;
|
|
59
|
+
const nextRooms = { ...params.rooms };
|
|
60
|
+
for (const [roomId, roomValue] of Object.entries(params.rooms)) {
|
|
61
|
+
const room = isRecord(roomValue) ? roomValue : null;
|
|
62
|
+
if (!room || typeof room.allow !== "boolean") continue;
|
|
63
|
+
const nextRoom = { ...room };
|
|
64
|
+
if (typeof nextRoom.enabled !== "boolean") nextRoom.enabled = room.allow;
|
|
65
|
+
delete nextRoom.allow;
|
|
66
|
+
nextRooms[roomId] = nextRoom;
|
|
67
|
+
changed = true;
|
|
68
|
+
params.changes.push(`Moved ${params.pathPrefix}.${roomId}.allow → ${params.pathPrefix}.${roomId}.enabled (${String(nextRoom.enabled)}).`);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
rooms: nextRooms,
|
|
72
|
+
changed
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const legacyConfigRules = [
|
|
76
|
+
{
|
|
77
|
+
path: ["channels", "matrix"],
|
|
78
|
+
message: "channels.matrix.allowPrivateNetwork is legacy; use channels.matrix.network.dangerouslyAllowPrivateNetwork instead. Run \"openclaw doctor --fix\".",
|
|
79
|
+
match: (value) => hasLegacyFlatAllowPrivateNetworkAlias(isRecord(value) ? value : {})
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
path: [
|
|
83
|
+
"channels",
|
|
84
|
+
"matrix",
|
|
85
|
+
"accounts"
|
|
86
|
+
],
|
|
87
|
+
message: "channels.matrix.accounts.<id>.allowPrivateNetwork is legacy; use channels.matrix.accounts.<id>.network.dangerouslyAllowPrivateNetwork instead. Run \"openclaw doctor --fix\".",
|
|
88
|
+
match: hasLegacyMatrixAccountPrivateNetworkAliases
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
path: [
|
|
92
|
+
"channels",
|
|
93
|
+
"matrix",
|
|
94
|
+
"groups"
|
|
95
|
+
],
|
|
96
|
+
message: "channels.matrix.groups.<room>.allow is legacy; use channels.matrix.groups.<room>.enabled instead. Run \"openclaw doctor --fix\".",
|
|
97
|
+
match: hasLegacyMatrixRoomMapAllowAliases
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
path: [
|
|
101
|
+
"channels",
|
|
102
|
+
"matrix",
|
|
103
|
+
"rooms"
|
|
104
|
+
],
|
|
105
|
+
message: "channels.matrix.rooms.<room>.allow is legacy; use channels.matrix.rooms.<room>.enabled instead. Run \"openclaw doctor --fix\".",
|
|
106
|
+
match: hasLegacyMatrixRoomMapAllowAliases
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
path: [
|
|
110
|
+
"channels",
|
|
111
|
+
"matrix",
|
|
112
|
+
"accounts"
|
|
113
|
+
],
|
|
114
|
+
message: "channels.matrix.accounts.<id>.{groups,rooms}.<room>.allow is legacy; use channels.matrix.accounts.<id>.{groups,rooms}.<room>.enabled instead. Run \"openclaw doctor --fix\".",
|
|
115
|
+
match: hasLegacyMatrixAccountRoomAllowAliases
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
path: ["channels", "matrix"],
|
|
119
|
+
message: "channels.matrix.dm.policy \"trusted\" is legacy; use \"allowlist\" (with allowFrom entries) or \"pairing\" instead. Run \"openclaw doctor --fix\".",
|
|
120
|
+
match: hasLegacyTrustedDmPolicy
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
path: [
|
|
124
|
+
"channels",
|
|
125
|
+
"matrix",
|
|
126
|
+
"accounts"
|
|
127
|
+
],
|
|
128
|
+
message: "channels.matrix.accounts.<id>.dm.policy \"trusted\" is legacy; use \"allowlist\" (with allowFrom entries) or \"pairing\" instead. Run \"openclaw doctor --fix\".",
|
|
129
|
+
match: hasLegacyMatrixAccountTrustedDmPolicies
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
function normalizeCompatibilityConfig({ cfg }) {
|
|
133
|
+
const channels = isRecord(cfg.channels) ? cfg.channels : null;
|
|
134
|
+
const matrix = isRecord(channels?.matrix) ? channels.matrix : null;
|
|
135
|
+
if (!matrix) return {
|
|
136
|
+
config: cfg,
|
|
137
|
+
changes: []
|
|
138
|
+
};
|
|
139
|
+
const changes = [];
|
|
140
|
+
let updatedMatrix = matrix;
|
|
141
|
+
let changed = false;
|
|
142
|
+
const topLevelPrivateNetwork = migrateLegacyFlatAllowPrivateNetworkAlias({
|
|
143
|
+
entry: updatedMatrix,
|
|
144
|
+
pathPrefix: "channels.matrix",
|
|
145
|
+
changes
|
|
146
|
+
});
|
|
147
|
+
updatedMatrix = topLevelPrivateNetwork.entry;
|
|
148
|
+
changed = changed || topLevelPrivateNetwork.changed;
|
|
149
|
+
const topLevelTrustedDmPolicy = migrateLegacyTrustedDmPolicy({
|
|
150
|
+
entry: updatedMatrix,
|
|
151
|
+
pathPrefix: "channels.matrix",
|
|
152
|
+
changes
|
|
153
|
+
});
|
|
154
|
+
updatedMatrix = topLevelTrustedDmPolicy.entry;
|
|
155
|
+
changed = changed || topLevelTrustedDmPolicy.changed;
|
|
156
|
+
const normalizeTopLevelRoomScope = (key) => {
|
|
157
|
+
const rooms = isRecord(updatedMatrix[key]) ? updatedMatrix[key] : null;
|
|
158
|
+
if (!rooms) return;
|
|
159
|
+
const normalized = normalizeMatrixRoomAllowAliases({
|
|
160
|
+
rooms,
|
|
161
|
+
pathPrefix: `channels.matrix.${key}`,
|
|
162
|
+
changes
|
|
163
|
+
});
|
|
164
|
+
if (normalized.changed) {
|
|
165
|
+
updatedMatrix = {
|
|
166
|
+
...updatedMatrix,
|
|
167
|
+
[key]: normalized.rooms
|
|
168
|
+
};
|
|
169
|
+
changed = true;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
normalizeTopLevelRoomScope("groups");
|
|
173
|
+
normalizeTopLevelRoomScope("rooms");
|
|
174
|
+
const accounts = isRecord(updatedMatrix.accounts) ? updatedMatrix.accounts : null;
|
|
175
|
+
if (accounts) {
|
|
176
|
+
let accountsChanged = false;
|
|
177
|
+
const nextAccounts = { ...accounts };
|
|
178
|
+
for (const [accountId, accountValue] of Object.entries(accounts)) {
|
|
179
|
+
const account = isRecord(accountValue) ? accountValue : null;
|
|
180
|
+
if (!account) continue;
|
|
181
|
+
let nextAccount = account;
|
|
182
|
+
let accountChanged = false;
|
|
183
|
+
const privateNetworkMigration = migrateLegacyFlatAllowPrivateNetworkAlias({
|
|
184
|
+
entry: nextAccount,
|
|
185
|
+
pathPrefix: `channels.matrix.accounts.${accountId}`,
|
|
186
|
+
changes
|
|
187
|
+
});
|
|
188
|
+
if (privateNetworkMigration.changed) {
|
|
189
|
+
nextAccount = privateNetworkMigration.entry;
|
|
190
|
+
accountChanged = true;
|
|
191
|
+
}
|
|
192
|
+
const accountTrustedDmPolicy = migrateLegacyTrustedDmPolicy({
|
|
193
|
+
entry: nextAccount,
|
|
194
|
+
pathPrefix: `channels.matrix.accounts.${accountId}`,
|
|
195
|
+
changes
|
|
196
|
+
});
|
|
197
|
+
if (accountTrustedDmPolicy.changed) {
|
|
198
|
+
nextAccount = accountTrustedDmPolicy.entry;
|
|
199
|
+
accountChanged = true;
|
|
200
|
+
}
|
|
201
|
+
for (const key of ["groups", "rooms"]) {
|
|
202
|
+
const rooms = isRecord(nextAccount[key]) ? nextAccount[key] : null;
|
|
203
|
+
if (!rooms) continue;
|
|
204
|
+
const normalized = normalizeMatrixRoomAllowAliases({
|
|
205
|
+
rooms,
|
|
206
|
+
pathPrefix: `channels.matrix.accounts.${accountId}.${key}`,
|
|
207
|
+
changes
|
|
208
|
+
});
|
|
209
|
+
if (normalized.changed) {
|
|
210
|
+
nextAccount = {
|
|
211
|
+
...nextAccount,
|
|
212
|
+
[key]: normalized.rooms
|
|
213
|
+
};
|
|
214
|
+
accountChanged = true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (accountChanged) {
|
|
218
|
+
nextAccounts[accountId] = nextAccount;
|
|
219
|
+
accountsChanged = true;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (accountsChanged) {
|
|
223
|
+
updatedMatrix = {
|
|
224
|
+
...updatedMatrix,
|
|
225
|
+
accounts: nextAccounts
|
|
226
|
+
};
|
|
227
|
+
changed = true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!changed) return {
|
|
231
|
+
config: cfg,
|
|
232
|
+
changes: []
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
config: {
|
|
236
|
+
...cfg,
|
|
237
|
+
channels: {
|
|
238
|
+
...cfg.channels,
|
|
239
|
+
matrix: updatedMatrix
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
changes
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
//#endregion
|
|
246
|
+
export { normalizeCompatibilityConfig as n, legacyConfigRules as t };
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { n as editMessageMatrix, r as prepareMatrixSingleText, s as sendSingleTextMessageMatrix } from "./send-Bo0DU1ca.js";
|
|
2
|
+
import { l as MsgType } from "./direct-management-DMMMgtTB.js";
|
|
3
|
+
import { createDraftStreamLoop } from "openclaw/plugin-sdk/channel-lifecycle";
|
|
4
|
+
//#region extensions/matrix/src/matrix/draft-stream.ts
|
|
5
|
+
const DEFAULT_THROTTLE_MS = 1e3;
|
|
6
|
+
function resolveDraftPreviewOptions(mode) {
|
|
7
|
+
if (mode === "quiet") return {
|
|
8
|
+
msgtype: MsgType.Notice,
|
|
9
|
+
includeMentions: false
|
|
10
|
+
};
|
|
11
|
+
return { msgtype: MsgType.Text };
|
|
12
|
+
}
|
|
13
|
+
function createMatrixDraftStream(params) {
|
|
14
|
+
const { roomId, client, cfg, threadId, accountId, log } = params;
|
|
15
|
+
const preview = resolveDraftPreviewOptions(params.mode ?? "partial");
|
|
16
|
+
const useLive = params.mode !== "quiet";
|
|
17
|
+
let currentEventId;
|
|
18
|
+
let lastSentText = "";
|
|
19
|
+
let stopped = false;
|
|
20
|
+
let sendFailed = false;
|
|
21
|
+
let finalizeInPlaceBlocked = false;
|
|
22
|
+
let liveFinalized = false;
|
|
23
|
+
let replyToId = params.replyToId;
|
|
24
|
+
const sendOrEdit = async (text) => {
|
|
25
|
+
const trimmed = text.trimEnd();
|
|
26
|
+
if (!trimmed) return false;
|
|
27
|
+
const preparedText = prepareMatrixSingleText(trimmed, {
|
|
28
|
+
cfg,
|
|
29
|
+
accountId
|
|
30
|
+
});
|
|
31
|
+
if (!preparedText.fitsInSingleEvent) {
|
|
32
|
+
finalizeInPlaceBlocked = true;
|
|
33
|
+
if (!currentEventId) sendFailed = true;
|
|
34
|
+
stopped = true;
|
|
35
|
+
log?.(`draft-stream: preview exceeded single-event limit (${preparedText.convertedText.length} > ${preparedText.singleEventLimit})`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (sendFailed) return false;
|
|
39
|
+
if (preparedText.trimmedText === lastSentText) return true;
|
|
40
|
+
try {
|
|
41
|
+
if (!currentEventId) {
|
|
42
|
+
currentEventId = (await sendSingleTextMessageMatrix(roomId, preparedText.trimmedText, {
|
|
43
|
+
client,
|
|
44
|
+
cfg,
|
|
45
|
+
replyToId,
|
|
46
|
+
threadId,
|
|
47
|
+
accountId,
|
|
48
|
+
msgtype: preview.msgtype,
|
|
49
|
+
includeMentions: preview.includeMentions,
|
|
50
|
+
live: useLive
|
|
51
|
+
})).messageId;
|
|
52
|
+
lastSentText = preparedText.trimmedText;
|
|
53
|
+
log?.(`draft-stream: created message ${currentEventId}${useLive ? " (MSC4357 live)" : ""}`);
|
|
54
|
+
} else {
|
|
55
|
+
await editMessageMatrix(roomId, currentEventId, preparedText.trimmedText, {
|
|
56
|
+
client,
|
|
57
|
+
cfg,
|
|
58
|
+
threadId,
|
|
59
|
+
accountId,
|
|
60
|
+
msgtype: preview.msgtype,
|
|
61
|
+
includeMentions: preview.includeMentions,
|
|
62
|
+
live: useLive
|
|
63
|
+
});
|
|
64
|
+
lastSentText = preparedText.trimmedText;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
} catch (err) {
|
|
68
|
+
log?.(`draft-stream: send/edit failed: ${String(err)}`);
|
|
69
|
+
if (err instanceof Error && err.message.startsWith("Matrix single-message text exceeds limit")) finalizeInPlaceBlocked = true;
|
|
70
|
+
if (!currentEventId) sendFailed = true;
|
|
71
|
+
stopped = true;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const loop = createDraftStreamLoop({
|
|
76
|
+
throttleMs: DEFAULT_THROTTLE_MS,
|
|
77
|
+
isStopped: () => stopped,
|
|
78
|
+
sendOrEditStreamMessage: sendOrEdit
|
|
79
|
+
});
|
|
80
|
+
log?.(`draft-stream: ready (throttleMs=${DEFAULT_THROTTLE_MS})`);
|
|
81
|
+
const finalizeLive = async () => {
|
|
82
|
+
if (useLive && !liveFinalized && currentEventId && lastSentText) {
|
|
83
|
+
liveFinalized = true;
|
|
84
|
+
try {
|
|
85
|
+
await editMessageMatrix(roomId, currentEventId, lastSentText, {
|
|
86
|
+
client,
|
|
87
|
+
cfg,
|
|
88
|
+
threadId,
|
|
89
|
+
accountId,
|
|
90
|
+
msgtype: preview.msgtype,
|
|
91
|
+
includeMentions: preview.includeMentions,
|
|
92
|
+
live: false
|
|
93
|
+
});
|
|
94
|
+
log?.(`draft-stream: finalized ${currentEventId} (MSC4357 stream ended)`);
|
|
95
|
+
return true;
|
|
96
|
+
} catch (err) {
|
|
97
|
+
log?.(`draft-stream: finalize edit failed: ${String(err)}`);
|
|
98
|
+
finalizeInPlaceBlocked = true;
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
};
|
|
104
|
+
const stop = async () => {
|
|
105
|
+
await loop.flush();
|
|
106
|
+
stopped = true;
|
|
107
|
+
return currentEventId;
|
|
108
|
+
};
|
|
109
|
+
const discardPending = async () => {
|
|
110
|
+
stopped = true;
|
|
111
|
+
loop.stop();
|
|
112
|
+
await loop.waitForInFlight();
|
|
113
|
+
};
|
|
114
|
+
const reset = () => {
|
|
115
|
+
replyToId = params.preserveReplyId ? params.replyToId : void 0;
|
|
116
|
+
currentEventId = void 0;
|
|
117
|
+
lastSentText = "";
|
|
118
|
+
stopped = false;
|
|
119
|
+
sendFailed = false;
|
|
120
|
+
finalizeInPlaceBlocked = false;
|
|
121
|
+
liveFinalized = false;
|
|
122
|
+
loop.resetPending();
|
|
123
|
+
loop.resetThrottleWindow();
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
update: (text) => {
|
|
127
|
+
if (stopped) return;
|
|
128
|
+
loop.update(text);
|
|
129
|
+
},
|
|
130
|
+
flush: loop.flush,
|
|
131
|
+
stop,
|
|
132
|
+
discardPending,
|
|
133
|
+
finalizeLive,
|
|
134
|
+
reset,
|
|
135
|
+
eventId: () => currentEventId,
|
|
136
|
+
matchesPreparedText: (text) => prepareMatrixSingleText(text, {
|
|
137
|
+
cfg,
|
|
138
|
+
accountId
|
|
139
|
+
}).trimmedText === lastSentText,
|
|
140
|
+
mustDeliverFinalNormally: () => sendFailed || finalizeInPlaceBlocked
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { createMatrixDraftStream };
|