@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
package/src/channel.ts
DELETED
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildOpenGroupPolicyWarning,
|
|
3
|
-
collectAllowlistProviderGroupPolicyWarnings,
|
|
4
|
-
createScopedAccountConfigAccessors,
|
|
5
|
-
createScopedChannelConfigBase,
|
|
6
|
-
createScopedDmSecurityResolver,
|
|
7
|
-
} from "openclaw/plugin-sdk/compat";
|
|
8
|
-
import {
|
|
9
|
-
applyAccountNameToChannelSection,
|
|
10
|
-
buildChannelConfigSchema,
|
|
11
|
-
buildProbeChannelStatusSummary,
|
|
12
|
-
collectStatusIssuesFromLastError,
|
|
13
|
-
DEFAULT_ACCOUNT_ID,
|
|
14
|
-
normalizeAccountId,
|
|
15
|
-
PAIRING_APPROVED_MESSAGE,
|
|
16
|
-
type ChannelPlugin,
|
|
17
|
-
} from "openclaw/plugin-sdk/matrix";
|
|
18
|
-
import { buildTrafficStatusSummary } from "../../shared/channel-status-summary.js";
|
|
19
|
-
import { matrixMessageActions } from "./actions.js";
|
|
20
|
-
import { MatrixConfigSchema } from "./config-schema.js";
|
|
21
|
-
import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
|
|
22
|
-
import {
|
|
23
|
-
resolveMatrixGroupRequireMention,
|
|
24
|
-
resolveMatrixGroupToolPolicy,
|
|
25
|
-
} from "./group-mentions.js";
|
|
26
|
-
import {
|
|
27
|
-
listMatrixAccountIds,
|
|
28
|
-
resolveMatrixAccountConfig,
|
|
29
|
-
resolveDefaultMatrixAccountId,
|
|
30
|
-
resolveMatrixAccount,
|
|
31
|
-
type ResolvedMatrixAccount,
|
|
32
|
-
} from "./matrix/accounts.js";
|
|
33
|
-
import { resolveMatrixAuth } from "./matrix/client.js";
|
|
34
|
-
import { normalizeMatrixAllowList, normalizeMatrixUserId } from "./matrix/monitor/allowlist.js";
|
|
35
|
-
import { probeMatrix } from "./matrix/probe.js";
|
|
36
|
-
import { sendMessageMatrix } from "./matrix/send.js";
|
|
37
|
-
import { matrixOnboardingAdapter } from "./onboarding.js";
|
|
38
|
-
import { matrixOutbound } from "./outbound.js";
|
|
39
|
-
import { resolveMatrixTargets } from "./resolve-targets.js";
|
|
40
|
-
import { normalizeSecretInputString } from "./secret-input.js";
|
|
41
|
-
import type { CoreConfig } from "./types.js";
|
|
42
|
-
|
|
43
|
-
// Mutex for serializing account startup (workaround for concurrent dynamic import race condition)
|
|
44
|
-
let matrixStartupLock: Promise<void> = Promise.resolve();
|
|
45
|
-
|
|
46
|
-
const meta = {
|
|
47
|
-
id: "matrix",
|
|
48
|
-
label: "Matrix",
|
|
49
|
-
selectionLabel: "Matrix (plugin)",
|
|
50
|
-
docsPath: "/channels/matrix",
|
|
51
|
-
docsLabel: "matrix",
|
|
52
|
-
blurb: "open protocol; configure a homeserver + access token.",
|
|
53
|
-
order: 70,
|
|
54
|
-
quickstartAllowFrom: true,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function normalizeMatrixMessagingTarget(raw: string): string | undefined {
|
|
58
|
-
let normalized = raw.trim();
|
|
59
|
-
if (!normalized) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
const lowered = normalized.toLowerCase();
|
|
63
|
-
if (lowered.startsWith("matrix:")) {
|
|
64
|
-
normalized = normalized.slice("matrix:".length).trim();
|
|
65
|
-
}
|
|
66
|
-
const stripped = normalized.replace(/^(room|channel|user):/i, "").trim();
|
|
67
|
-
return stripped || undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function buildMatrixConfigUpdate(
|
|
71
|
-
cfg: CoreConfig,
|
|
72
|
-
input: {
|
|
73
|
-
homeserver?: string;
|
|
74
|
-
userId?: string;
|
|
75
|
-
accessToken?: string;
|
|
76
|
-
password?: string;
|
|
77
|
-
deviceName?: string;
|
|
78
|
-
initialSyncLimit?: number;
|
|
79
|
-
},
|
|
80
|
-
): CoreConfig {
|
|
81
|
-
const existing = cfg.channels?.matrix ?? {};
|
|
82
|
-
return {
|
|
83
|
-
...cfg,
|
|
84
|
-
channels: {
|
|
85
|
-
...cfg.channels,
|
|
86
|
-
matrix: {
|
|
87
|
-
...existing,
|
|
88
|
-
enabled: true,
|
|
89
|
-
...(input.homeserver ? { homeserver: input.homeserver } : {}),
|
|
90
|
-
...(input.userId ? { userId: input.userId } : {}),
|
|
91
|
-
...(input.accessToken ? { accessToken: input.accessToken } : {}),
|
|
92
|
-
...(input.password ? { password: input.password } : {}),
|
|
93
|
-
...(input.deviceName ? { deviceName: input.deviceName } : {}),
|
|
94
|
-
...(typeof input.initialSyncLimit === "number"
|
|
95
|
-
? { initialSyncLimit: input.initialSyncLimit }
|
|
96
|
-
: {}),
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const matrixConfigAccessors = createScopedAccountConfigAccessors({
|
|
103
|
-
resolveAccount: ({ cfg, accountId }) =>
|
|
104
|
-
resolveMatrixAccountConfig({ cfg: cfg as CoreConfig, accountId }),
|
|
105
|
-
resolveAllowFrom: (account) => account.dm?.allowFrom,
|
|
106
|
-
formatAllowFrom: (allowFrom) => normalizeMatrixAllowList(allowFrom),
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
const matrixConfigBase = createScopedChannelConfigBase<ResolvedMatrixAccount, CoreConfig>({
|
|
110
|
-
sectionKey: "matrix",
|
|
111
|
-
listAccountIds: listMatrixAccountIds,
|
|
112
|
-
resolveAccount: (cfg, accountId) => resolveMatrixAccount({ cfg, accountId }),
|
|
113
|
-
defaultAccountId: resolveDefaultMatrixAccountId,
|
|
114
|
-
clearBaseFields: [
|
|
115
|
-
"name",
|
|
116
|
-
"homeserver",
|
|
117
|
-
"userId",
|
|
118
|
-
"accessToken",
|
|
119
|
-
"password",
|
|
120
|
-
"deviceName",
|
|
121
|
-
"initialSyncLimit",
|
|
122
|
-
],
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const resolveMatrixDmPolicy = createScopedDmSecurityResolver<ResolvedMatrixAccount>({
|
|
126
|
-
channelKey: "matrix",
|
|
127
|
-
resolvePolicy: (account) => account.config.dm?.policy,
|
|
128
|
-
resolveAllowFrom: (account) => account.config.dm?.allowFrom,
|
|
129
|
-
allowFromPathSuffix: "dm.",
|
|
130
|
-
normalizeEntry: (raw) => normalizeMatrixUserId(raw),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
export const matrixPlugin: ChannelPlugin<ResolvedMatrixAccount> = {
|
|
134
|
-
id: "matrix",
|
|
135
|
-
meta,
|
|
136
|
-
onboarding: matrixOnboardingAdapter,
|
|
137
|
-
pairing: {
|
|
138
|
-
idLabel: "matrixUserId",
|
|
139
|
-
normalizeAllowEntry: (entry) => entry.replace(/^matrix:/i, ""),
|
|
140
|
-
notifyApproval: async ({ id }) => {
|
|
141
|
-
await sendMessageMatrix(`user:${id}`, PAIRING_APPROVED_MESSAGE);
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
capabilities: {
|
|
145
|
-
chatTypes: ["direct", "group", "thread"],
|
|
146
|
-
polls: true,
|
|
147
|
-
reactions: true,
|
|
148
|
-
threads: true,
|
|
149
|
-
media: true,
|
|
150
|
-
},
|
|
151
|
-
reload: { configPrefixes: ["channels.matrix"] },
|
|
152
|
-
configSchema: buildChannelConfigSchema(MatrixConfigSchema),
|
|
153
|
-
config: {
|
|
154
|
-
...matrixConfigBase,
|
|
155
|
-
isConfigured: (account) => account.configured,
|
|
156
|
-
describeAccount: (account) => ({
|
|
157
|
-
accountId: account.accountId,
|
|
158
|
-
name: account.name,
|
|
159
|
-
enabled: account.enabled,
|
|
160
|
-
configured: account.configured,
|
|
161
|
-
baseUrl: account.homeserver,
|
|
162
|
-
}),
|
|
163
|
-
...matrixConfigAccessors,
|
|
164
|
-
},
|
|
165
|
-
security: {
|
|
166
|
-
resolveDmPolicy: resolveMatrixDmPolicy,
|
|
167
|
-
collectWarnings: ({ account, cfg }) => {
|
|
168
|
-
return collectAllowlistProviderGroupPolicyWarnings({
|
|
169
|
-
cfg: cfg as CoreConfig,
|
|
170
|
-
providerConfigPresent: (cfg as CoreConfig).channels?.matrix !== undefined,
|
|
171
|
-
configuredGroupPolicy: account.config.groupPolicy,
|
|
172
|
-
collect: (groupPolicy) =>
|
|
173
|
-
groupPolicy === "open"
|
|
174
|
-
? [
|
|
175
|
-
buildOpenGroupPolicyWarning({
|
|
176
|
-
surface: "Matrix rooms",
|
|
177
|
-
openBehavior: "allows any room to trigger (mention-gated)",
|
|
178
|
-
remediation:
|
|
179
|
-
'Set channels.matrix.groupPolicy="allowlist" + channels.matrix.groups (and optionally channels.matrix.groupAllowFrom) to restrict rooms',
|
|
180
|
-
}),
|
|
181
|
-
]
|
|
182
|
-
: [],
|
|
183
|
-
});
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
groups: {
|
|
187
|
-
resolveRequireMention: resolveMatrixGroupRequireMention,
|
|
188
|
-
resolveToolPolicy: resolveMatrixGroupToolPolicy,
|
|
189
|
-
},
|
|
190
|
-
threading: {
|
|
191
|
-
resolveReplyToMode: ({ cfg, accountId }) =>
|
|
192
|
-
resolveMatrixAccountConfig({ cfg: cfg as CoreConfig, accountId }).replyToMode ?? "off",
|
|
193
|
-
buildToolContext: ({ context, hasRepliedRef }) => {
|
|
194
|
-
const currentTarget = context.To;
|
|
195
|
-
return {
|
|
196
|
-
currentChannelId: currentTarget?.trim() || undefined,
|
|
197
|
-
currentThreadTs:
|
|
198
|
-
context.MessageThreadId != null ? String(context.MessageThreadId) : context.ReplyToId,
|
|
199
|
-
hasRepliedRef,
|
|
200
|
-
};
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
messaging: {
|
|
204
|
-
normalizeTarget: normalizeMatrixMessagingTarget,
|
|
205
|
-
targetResolver: {
|
|
206
|
-
looksLikeId: (raw) => {
|
|
207
|
-
const trimmed = raw.trim();
|
|
208
|
-
if (!trimmed) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
if (/^(matrix:)?[!#@]/i.test(trimmed)) {
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
return trimmed.includes(":");
|
|
215
|
-
},
|
|
216
|
-
hint: "<room|alias|user>",
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
directory: {
|
|
220
|
-
self: async () => null,
|
|
221
|
-
listPeers: async ({ cfg, accountId, query, limit }) => {
|
|
222
|
-
const account = resolveMatrixAccount({ cfg: cfg as CoreConfig, accountId });
|
|
223
|
-
const q = query?.trim().toLowerCase() || "";
|
|
224
|
-
const ids = new Set<string>();
|
|
225
|
-
|
|
226
|
-
for (const entry of account.config.dm?.allowFrom ?? []) {
|
|
227
|
-
const raw = String(entry).trim();
|
|
228
|
-
if (!raw || raw === "*") {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
ids.add(raw.replace(/^matrix:/i, ""));
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
for (const entry of account.config.groupAllowFrom ?? []) {
|
|
235
|
-
const raw = String(entry).trim();
|
|
236
|
-
if (!raw || raw === "*") {
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
ids.add(raw.replace(/^matrix:/i, ""));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const groups = account.config.groups ?? account.config.rooms ?? {};
|
|
243
|
-
for (const room of Object.values(groups)) {
|
|
244
|
-
for (const entry of room.users ?? []) {
|
|
245
|
-
const raw = String(entry).trim();
|
|
246
|
-
if (!raw || raw === "*") {
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
ids.add(raw.replace(/^matrix:/i, ""));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return Array.from(ids)
|
|
254
|
-
.map((raw) => raw.trim())
|
|
255
|
-
.filter(Boolean)
|
|
256
|
-
.map((raw) => {
|
|
257
|
-
const lowered = raw.toLowerCase();
|
|
258
|
-
const cleaned = lowered.startsWith("user:") ? raw.slice("user:".length).trim() : raw;
|
|
259
|
-
if (cleaned.startsWith("@")) {
|
|
260
|
-
return `user:${cleaned}`;
|
|
261
|
-
}
|
|
262
|
-
return cleaned;
|
|
263
|
-
})
|
|
264
|
-
.filter((id) => (q ? id.toLowerCase().includes(q) : true))
|
|
265
|
-
.slice(0, limit && limit > 0 ? limit : undefined)
|
|
266
|
-
.map((id) => {
|
|
267
|
-
const raw = id.startsWith("user:") ? id.slice("user:".length) : id;
|
|
268
|
-
const incomplete = !raw.startsWith("@") || !raw.includes(":");
|
|
269
|
-
return {
|
|
270
|
-
kind: "user",
|
|
271
|
-
id,
|
|
272
|
-
...(incomplete ? { name: "incomplete id; expected @user:server" } : {}),
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
},
|
|
276
|
-
listGroups: async ({ cfg, accountId, query, limit }) => {
|
|
277
|
-
const account = resolveMatrixAccount({ cfg: cfg as CoreConfig, accountId });
|
|
278
|
-
const q = query?.trim().toLowerCase() || "";
|
|
279
|
-
const groups = account.config.groups ?? account.config.rooms ?? {};
|
|
280
|
-
const ids = Object.keys(groups)
|
|
281
|
-
.map((raw) => raw.trim())
|
|
282
|
-
.filter((raw) => Boolean(raw) && raw !== "*")
|
|
283
|
-
.map((raw) => raw.replace(/^matrix:/i, ""))
|
|
284
|
-
.map((raw) => {
|
|
285
|
-
const lowered = raw.toLowerCase();
|
|
286
|
-
if (lowered.startsWith("room:") || lowered.startsWith("channel:")) {
|
|
287
|
-
return raw;
|
|
288
|
-
}
|
|
289
|
-
if (raw.startsWith("!")) {
|
|
290
|
-
return `room:${raw}`;
|
|
291
|
-
}
|
|
292
|
-
return raw;
|
|
293
|
-
})
|
|
294
|
-
.filter((id) => (q ? id.toLowerCase().includes(q) : true))
|
|
295
|
-
.slice(0, limit && limit > 0 ? limit : undefined)
|
|
296
|
-
.map((id) => ({ kind: "group", id }) as const);
|
|
297
|
-
return ids;
|
|
298
|
-
},
|
|
299
|
-
listPeersLive: async ({ cfg, accountId, query, limit }) =>
|
|
300
|
-
listMatrixDirectoryPeersLive({ cfg, accountId, query, limit }),
|
|
301
|
-
listGroupsLive: async ({ cfg, accountId, query, limit }) =>
|
|
302
|
-
listMatrixDirectoryGroupsLive({ cfg, accountId, query, limit }),
|
|
303
|
-
},
|
|
304
|
-
resolver: {
|
|
305
|
-
resolveTargets: async ({ cfg, inputs, kind, runtime }) =>
|
|
306
|
-
resolveMatrixTargets({ cfg, inputs, kind, runtime }),
|
|
307
|
-
},
|
|
308
|
-
actions: matrixMessageActions,
|
|
309
|
-
setup: {
|
|
310
|
-
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
|
|
311
|
-
applyAccountName: ({ cfg, accountId, name }) =>
|
|
312
|
-
applyAccountNameToChannelSection({
|
|
313
|
-
cfg: cfg as CoreConfig,
|
|
314
|
-
channelKey: "matrix",
|
|
315
|
-
accountId,
|
|
316
|
-
name,
|
|
317
|
-
}),
|
|
318
|
-
validateInput: ({ input }) => {
|
|
319
|
-
if (input.useEnv) {
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
if (!input.homeserver?.trim()) {
|
|
323
|
-
return "Matrix requires --homeserver";
|
|
324
|
-
}
|
|
325
|
-
const accessToken = input.accessToken?.trim();
|
|
326
|
-
const password = normalizeSecretInputString(input.password);
|
|
327
|
-
const userId = input.userId?.trim();
|
|
328
|
-
if (!accessToken && !password) {
|
|
329
|
-
return "Matrix requires --access-token or --password";
|
|
330
|
-
}
|
|
331
|
-
if (!accessToken) {
|
|
332
|
-
if (!userId) {
|
|
333
|
-
return "Matrix requires --user-id when using --password";
|
|
334
|
-
}
|
|
335
|
-
if (!password) {
|
|
336
|
-
return "Matrix requires --password when using --user-id";
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return null;
|
|
340
|
-
},
|
|
341
|
-
applyAccountConfig: ({ cfg, input }) => {
|
|
342
|
-
const namedConfig = applyAccountNameToChannelSection({
|
|
343
|
-
cfg: cfg as CoreConfig,
|
|
344
|
-
channelKey: "matrix",
|
|
345
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
346
|
-
name: input.name,
|
|
347
|
-
});
|
|
348
|
-
if (input.useEnv) {
|
|
349
|
-
return {
|
|
350
|
-
...namedConfig,
|
|
351
|
-
channels: {
|
|
352
|
-
...namedConfig.channels,
|
|
353
|
-
matrix: {
|
|
354
|
-
...namedConfig.channels?.matrix,
|
|
355
|
-
enabled: true,
|
|
356
|
-
},
|
|
357
|
-
},
|
|
358
|
-
} as CoreConfig;
|
|
359
|
-
}
|
|
360
|
-
return buildMatrixConfigUpdate(namedConfig as CoreConfig, {
|
|
361
|
-
homeserver: input.homeserver?.trim(),
|
|
362
|
-
userId: input.userId?.trim(),
|
|
363
|
-
accessToken: input.accessToken?.trim(),
|
|
364
|
-
password: normalizeSecretInputString(input.password),
|
|
365
|
-
deviceName: input.deviceName?.trim(),
|
|
366
|
-
initialSyncLimit: input.initialSyncLimit,
|
|
367
|
-
});
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
outbound: matrixOutbound,
|
|
371
|
-
status: {
|
|
372
|
-
defaultRuntime: {
|
|
373
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
374
|
-
running: false,
|
|
375
|
-
lastStartAt: null,
|
|
376
|
-
lastStopAt: null,
|
|
377
|
-
lastError: null,
|
|
378
|
-
},
|
|
379
|
-
collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("matrix", accounts),
|
|
380
|
-
buildChannelSummary: ({ snapshot }) =>
|
|
381
|
-
buildProbeChannelStatusSummary(snapshot, { baseUrl: snapshot.baseUrl ?? null }),
|
|
382
|
-
probeAccount: async ({ account, timeoutMs, cfg }) => {
|
|
383
|
-
try {
|
|
384
|
-
const auth = await resolveMatrixAuth({
|
|
385
|
-
cfg: cfg as CoreConfig,
|
|
386
|
-
accountId: account.accountId,
|
|
387
|
-
});
|
|
388
|
-
return await probeMatrix({
|
|
389
|
-
homeserver: auth.homeserver,
|
|
390
|
-
accessToken: auth.accessToken,
|
|
391
|
-
userId: auth.userId,
|
|
392
|
-
timeoutMs,
|
|
393
|
-
});
|
|
394
|
-
} catch (err) {
|
|
395
|
-
return {
|
|
396
|
-
ok: false,
|
|
397
|
-
error: err instanceof Error ? err.message : String(err),
|
|
398
|
-
elapsedMs: 0,
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
buildAccountSnapshot: ({ account, runtime, probe }) => ({
|
|
403
|
-
accountId: account.accountId,
|
|
404
|
-
name: account.name,
|
|
405
|
-
enabled: account.enabled,
|
|
406
|
-
configured: account.configured,
|
|
407
|
-
baseUrl: account.homeserver,
|
|
408
|
-
running: runtime?.running ?? false,
|
|
409
|
-
lastStartAt: runtime?.lastStartAt ?? null,
|
|
410
|
-
lastStopAt: runtime?.lastStopAt ?? null,
|
|
411
|
-
lastError: runtime?.lastError ?? null,
|
|
412
|
-
probe,
|
|
413
|
-
lastProbeAt: runtime?.lastProbeAt ?? null,
|
|
414
|
-
...buildTrafficStatusSummary(runtime),
|
|
415
|
-
}),
|
|
416
|
-
},
|
|
417
|
-
gateway: {
|
|
418
|
-
startAccount: async (ctx) => {
|
|
419
|
-
const account = ctx.account;
|
|
420
|
-
ctx.setStatus({
|
|
421
|
-
accountId: account.accountId,
|
|
422
|
-
baseUrl: account.homeserver,
|
|
423
|
-
});
|
|
424
|
-
ctx.log?.info(`[${account.accountId}] starting provider (${account.homeserver ?? "matrix"})`);
|
|
425
|
-
|
|
426
|
-
// Serialize startup: wait for any previous startup to complete import phase.
|
|
427
|
-
// This works around a race condition with concurrent dynamic imports.
|
|
428
|
-
//
|
|
429
|
-
// INVARIANT: The import() below cannot hang because:
|
|
430
|
-
// 1. It only loads local ESM modules with no circular awaits
|
|
431
|
-
// 2. Module initialization is synchronous (no top-level await in ./matrix/index.js)
|
|
432
|
-
// 3. The lock only serializes the import phase, not the provider startup
|
|
433
|
-
const previousLock = matrixStartupLock;
|
|
434
|
-
let releaseLock: () => void = () => {};
|
|
435
|
-
matrixStartupLock = new Promise<void>((resolve) => {
|
|
436
|
-
releaseLock = resolve;
|
|
437
|
-
});
|
|
438
|
-
await previousLock;
|
|
439
|
-
|
|
440
|
-
// Lazy import: the monitor pulls the reply pipeline; avoid ESM init cycles.
|
|
441
|
-
// Wrap in try/finally to ensure lock is released even if import fails.
|
|
442
|
-
let monitorMatrixProvider: typeof import("./matrix/index.js").monitorMatrixProvider;
|
|
443
|
-
try {
|
|
444
|
-
const module = await import("./matrix/index.js");
|
|
445
|
-
monitorMatrixProvider = module.monitorMatrixProvider;
|
|
446
|
-
} finally {
|
|
447
|
-
// Release lock after import completes or fails
|
|
448
|
-
releaseLock();
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return monitorMatrixProvider({
|
|
452
|
-
runtime: ctx.runtime,
|
|
453
|
-
abortSignal: ctx.abortSignal,
|
|
454
|
-
mediaMaxMb: account.config.mediaMaxMb,
|
|
455
|
-
initialSyncLimit: account.config.initialSyncLimit,
|
|
456
|
-
replyToMode: account.config.replyToMode,
|
|
457
|
-
accountId: account.accountId,
|
|
458
|
-
});
|
|
459
|
-
},
|
|
460
|
-
},
|
|
461
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { MatrixConfigSchema } from "./config-schema.js";
|
|
3
|
-
|
|
4
|
-
describe("MatrixConfigSchema SecretInput", () => {
|
|
5
|
-
it("accepts SecretRef password at top-level", () => {
|
|
6
|
-
const result = MatrixConfigSchema.safeParse({
|
|
7
|
-
homeserver: "https://matrix.example.org",
|
|
8
|
-
userId: "@bot:example.org",
|
|
9
|
-
password: { source: "env", provider: "default", id: "MATRIX_PASSWORD" },
|
|
10
|
-
});
|
|
11
|
-
expect(result.success).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("accepts SecretRef password on account", () => {
|
|
15
|
-
const result = MatrixConfigSchema.safeParse({
|
|
16
|
-
accounts: {
|
|
17
|
-
work: {
|
|
18
|
-
homeserver: "https://matrix.example.org",
|
|
19
|
-
userId: "@bot:example.org",
|
|
20
|
-
password: { source: "env", provider: "default", id: "MATRIX_WORK_PASSWORD" },
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
expect(result.success).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
});
|
package/src/config-schema.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AllowFromListSchema,
|
|
3
|
-
buildNestedDmConfigSchema,
|
|
4
|
-
DmPolicySchema,
|
|
5
|
-
GroupPolicySchema,
|
|
6
|
-
} from "openclaw/plugin-sdk/compat";
|
|
7
|
-
import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/matrix";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import { buildSecretInputSchema } from "./secret-input.js";
|
|
10
|
-
|
|
11
|
-
const matrixActionSchema = z
|
|
12
|
-
.object({
|
|
13
|
-
reactions: z.boolean().optional(),
|
|
14
|
-
messages: z.boolean().optional(),
|
|
15
|
-
pins: z.boolean().optional(),
|
|
16
|
-
memberInfo: z.boolean().optional(),
|
|
17
|
-
channelInfo: z.boolean().optional(),
|
|
18
|
-
})
|
|
19
|
-
.optional();
|
|
20
|
-
|
|
21
|
-
const matrixRoomSchema = z
|
|
22
|
-
.object({
|
|
23
|
-
enabled: z.boolean().optional(),
|
|
24
|
-
allow: z.boolean().optional(),
|
|
25
|
-
requireMention: z.boolean().optional(),
|
|
26
|
-
tools: ToolPolicySchema,
|
|
27
|
-
autoReply: z.boolean().optional(),
|
|
28
|
-
users: AllowFromListSchema,
|
|
29
|
-
skills: z.array(z.string()).optional(),
|
|
30
|
-
systemPrompt: z.string().optional(),
|
|
31
|
-
})
|
|
32
|
-
.optional();
|
|
33
|
-
|
|
34
|
-
export const MatrixConfigSchema = z.object({
|
|
35
|
-
name: z.string().optional(),
|
|
36
|
-
enabled: z.boolean().optional(),
|
|
37
|
-
defaultAccount: z.string().optional(),
|
|
38
|
-
accounts: z.record(z.string(), z.unknown()).optional(),
|
|
39
|
-
markdown: MarkdownConfigSchema,
|
|
40
|
-
homeserver: z.string().optional(),
|
|
41
|
-
userId: z.string().optional(),
|
|
42
|
-
accessToken: z.string().optional(),
|
|
43
|
-
password: buildSecretInputSchema().optional(),
|
|
44
|
-
deviceName: z.string().optional(),
|
|
45
|
-
initialSyncLimit: z.number().optional(),
|
|
46
|
-
encryption: z.boolean().optional(),
|
|
47
|
-
allowlistOnly: z.boolean().optional(),
|
|
48
|
-
groupPolicy: GroupPolicySchema.optional(),
|
|
49
|
-
replyToMode: z.enum(["off", "first", "all"]).optional(),
|
|
50
|
-
threadReplies: z.enum(["off", "inbound", "always"]).optional(),
|
|
51
|
-
textChunkLimit: z.number().optional(),
|
|
52
|
-
chunkMode: z.enum(["length", "newline"]).optional(),
|
|
53
|
-
responsePrefix: z.string().optional(),
|
|
54
|
-
mediaMaxMb: z.number().optional(),
|
|
55
|
-
autoJoin: z.enum(["always", "allowlist", "off"]).optional(),
|
|
56
|
-
autoJoinAllowlist: AllowFromListSchema,
|
|
57
|
-
groupAllowFrom: AllowFromListSchema,
|
|
58
|
-
dm: buildNestedDmConfigSchema(),
|
|
59
|
-
groups: z.object({}).catchall(matrixRoomSchema).optional(),
|
|
60
|
-
rooms: z.object({}).catchall(matrixRoomSchema).optional(),
|
|
61
|
-
actions: matrixActionSchema,
|
|
62
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
|
|
3
|
-
import { resolveMatrixAuth } from "./matrix/client.js";
|
|
4
|
-
|
|
5
|
-
vi.mock("./matrix/client.js", () => ({
|
|
6
|
-
resolveMatrixAuth: vi.fn(),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
describe("matrix directory live", () => {
|
|
10
|
-
const cfg = { channels: { matrix: {} } };
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
vi.mocked(resolveMatrixAuth).mockReset();
|
|
14
|
-
vi.mocked(resolveMatrixAuth).mockResolvedValue({
|
|
15
|
-
homeserver: "https://matrix.example.org",
|
|
16
|
-
userId: "@bot:example.org",
|
|
17
|
-
accessToken: "test-token",
|
|
18
|
-
});
|
|
19
|
-
vi.stubGlobal(
|
|
20
|
-
"fetch",
|
|
21
|
-
vi.fn().mockResolvedValue({
|
|
22
|
-
ok: true,
|
|
23
|
-
json: async () => ({ results: [] }),
|
|
24
|
-
text: async () => "",
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
vi.unstubAllGlobals();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("passes accountId to peer directory auth resolution", async () => {
|
|
34
|
-
await listMatrixDirectoryPeersLive({
|
|
35
|
-
cfg,
|
|
36
|
-
accountId: "assistant",
|
|
37
|
-
query: "alice",
|
|
38
|
-
limit: 10,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(resolveMatrixAuth).toHaveBeenCalledWith({ cfg, accountId: "assistant" });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("passes accountId to group directory auth resolution", async () => {
|
|
45
|
-
await listMatrixDirectoryGroupsLive({
|
|
46
|
-
cfg,
|
|
47
|
-
accountId: "assistant",
|
|
48
|
-
query: "!room:example.org",
|
|
49
|
-
limit: 10,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(resolveMatrixAuth).toHaveBeenCalledWith({ cfg, accountId: "assistant" });
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("returns no peer results for empty query without resolving auth", async () => {
|
|
56
|
-
const result = await listMatrixDirectoryPeersLive({
|
|
57
|
-
cfg,
|
|
58
|
-
query: " ",
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(result).toEqual([]);
|
|
62
|
-
expect(resolveMatrixAuth).not.toHaveBeenCalled();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("returns no group results for empty query without resolving auth", async () => {
|
|
66
|
-
const result = await listMatrixDirectoryGroupsLive({
|
|
67
|
-
cfg,
|
|
68
|
-
query: "",
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(result).toEqual([]);
|
|
72
|
-
expect(resolveMatrixAuth).not.toHaveBeenCalled();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("preserves original casing for room IDs without :server suffix", async () => {
|
|
76
|
-
const mixedCaseId = "!EonMPPbOuhntHEHgZ2dnBO-c_EglMaXlIh2kdo8cgiA";
|
|
77
|
-
const result = await listMatrixDirectoryGroupsLive({
|
|
78
|
-
cfg,
|
|
79
|
-
query: mixedCaseId,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
expect(result).toHaveLength(1);
|
|
83
|
-
expect(result[0].id).toBe(mixedCaseId);
|
|
84
|
-
});
|
|
85
|
-
});
|