@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.
Files changed (206) hide show
  1. package/dist/account-config-D2W-V1eQ.js +96 -0
  2. package/dist/account-selection-BWwIruri.js +158 -0
  3. package/dist/accounts-Bm90Rzvp.js +130 -0
  4. package/dist/active-client-uhlxdhEy.js +20 -0
  5. package/dist/allowlist-sTzpCn5d.js +68 -0
  6. package/dist/api.js +12 -0
  7. package/dist/approval-handler.runtime-DWTQfd4m.js +370 -0
  8. package/dist/approval-ids-DoC2z7tR.js +7 -0
  9. package/dist/approval-reaction-auth-DbcA1gGd.js +27 -0
  10. package/dist/approval-reactions-o2_tuH8D.js +162 -0
  11. package/dist/async-lock-uQfhfQIY.js +19 -0
  12. package/dist/auth-presence.js +26 -0
  13. package/dist/backup-health-Cabu_WQC.js +60 -0
  14. package/dist/channel-H_6lMgwf.js +1116 -0
  15. package/dist/channel-plugin-api.js +2 -0
  16. package/dist/channel.runtime-BnO9f0pR.js +246 -0
  17. package/dist/cli-CYZ9yVcB.js +1340 -0
  18. package/dist/cli-metadata-DPIHnoa6.js +22 -0
  19. package/dist/cli-metadata.js +2 -0
  20. package/dist/client-DkcXnm0X.js +25 -0
  21. package/dist/client-_hckQNGW.js +31 -0
  22. package/dist/client-bootstrap-Rb8oHvhH.js +114 -0
  23. package/dist/config--5-S2Akv.js +452 -0
  24. package/dist/config-paths-nsVaysCu.js +19 -0
  25. package/dist/config-schema-nPLpEgHl.js +200 -0
  26. package/dist/config-secret-input.runtime-DiKFehsE.js +2 -0
  27. package/dist/config-update-wZX-HLMn.js +143 -0
  28. package/dist/contract-api.js +9 -0
  29. package/dist/create-client-DCnqDaqd.js +64 -0
  30. package/dist/credentials-DV6fWXhC.js +56 -0
  31. package/dist/credentials-read-cmHgousK.js +112 -0
  32. package/dist/credentials-write.runtime-zniTq-Gr.js +17 -0
  33. package/dist/crypto-node.runtime-pihzdpY7.js +12 -0
  34. package/dist/crypto-runtime-ZI0zAtn3.js +1214 -0
  35. package/dist/deps-C6WqKY7m.js +235 -0
  36. package/dist/device-health-UVYpbA_W.js +16 -0
  37. package/dist/direct-management-DMMMgtTB.js +249 -0
  38. package/dist/direct-room-XkutHjES.js +76 -0
  39. package/dist/directory-live-DmOtMhyr.js +150 -0
  40. package/dist/doctor-C4__7c-U.js +153 -0
  41. package/dist/doctor-contract-D4-64QuJ.js +246 -0
  42. package/dist/doctor-contract-api.js +2 -0
  43. package/dist/draft-stream-BE2QevQQ.js +144 -0
  44. package/dist/encryption-guidance-BPi3A_m3.js +15 -0
  45. package/dist/env-auth-BJqGI8M6.js +63 -0
  46. package/dist/env-vars-C7uQCTKn.js +63 -0
  47. package/dist/errors-CTcpEDq-.js +17 -0
  48. package/dist/exec-approval-resolver-Bza9Dhlm.js +15 -0
  49. package/dist/exec-approvals-Crnh543m.js +196 -0
  50. package/dist/helper-api.js +4 -0
  51. package/dist/http-client-C7AeVJay.js +319 -0
  52. package/dist/index.js +46 -0
  53. package/dist/legacy-crypto-inspector-poDWldgy.js +41 -0
  54. package/dist/legacy-crypto-restore-Biw-w2ng.js +85 -0
  55. package/dist/logger-CnZRVrux.js +78 -0
  56. package/dist/logging-DZHSPP5N.js +99 -0
  57. package/dist/matrix-migration.runtime-WY6ffcrf.js +525 -0
  58. package/dist/media-text-DU6nWZuj.js +146 -0
  59. package/dist/messages-BpihMh82.js +140 -0
  60. package/dist/migration-snapshot-backup-DaCHTp8C.js +69 -0
  61. package/dist/migration-snapshot.runtime-CKHE3xF9.js +2 -0
  62. package/dist/monitor-BaRCKyLd.js +4175 -0
  63. package/dist/plugin-entry.handlers.runtime.js +51 -0
  64. package/dist/probe.runtime-BvAzYAIe.js +3 -0
  65. package/dist/profile-BlHu0wDX.js +111 -0
  66. package/dist/profile-update-DjeBNgIV.js +69 -0
  67. package/dist/reaction-common-ejrL19w-.js +71 -0
  68. package/dist/reaction-events-CiARZfjk.js +121 -0
  69. package/dist/record-shared-CHWJCTWf.js +2 -0
  70. package/dist/recovery-key-store-BTJ6jz5v.js +294 -0
  71. package/dist/resolve-targets-YtJnw1Tb.js +140 -0
  72. package/dist/resolver.runtime-D9piiGEl.js +5 -0
  73. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  74. package/dist/route-D6rg-iXN.js +161 -0
  75. package/dist/runtime-C6X4h_SJ.js +6 -0
  76. package/dist/runtime-Dog86njy.js +8 -0
  77. package/dist/runtime-api-DTKcXOhp.js +24 -0
  78. package/dist/runtime-api.js +25 -0
  79. package/dist/runtime-heavy-api.js +3 -0
  80. package/dist/runtime-setter-api.js +2 -0
  81. package/dist/sdk-B2vZA27-.js +1416 -0
  82. package/dist/secret-contract-DcrJWCQI.js +120 -0
  83. package/dist/secret-contract-api.js +2 -0
  84. package/dist/send-Bo0DU1ca.js +1200 -0
  85. package/dist/session-store-metadata-DQXjgNLt.js +77 -0
  86. package/dist/setup-bootstrap-ImenBsMt.js +62 -0
  87. package/dist/setup-core-CfZy05oW.js +116 -0
  88. package/dist/setup-dm-policy-2-r1FrQh.js +194 -0
  89. package/dist/setup-entry.js +19 -0
  90. package/dist/setup-plugin-api.js +44 -0
  91. package/dist/setup-surface-CqT_o61M.js +540 -0
  92. package/dist/shared-CpMoYKm1.js +195 -0
  93. package/dist/startup-abort-56edvmbM.js +32 -0
  94. package/dist/startup-verification-Demyp0bP.js +132 -0
  95. package/dist/storage-paths-BJLdnCjV.js +52 -0
  96. package/dist/storage-tC3ujLiW.js +281 -0
  97. package/dist/subagent-hooks-DQbyqq9V.js +149 -0
  98. package/dist/subagent-hooks-api.js +23 -0
  99. package/dist/sync-state-C_beeevA.js +12 -0
  100. package/dist/target-ids-80nQ2gql.js +77 -0
  101. package/dist/test-api.js +4 -0
  102. package/dist/thread-binding-api-Cq_E-E1K.js +17 -0
  103. package/dist/thread-binding-api.js +2 -0
  104. package/dist/thread-bindings-B9mesxXk.js +352 -0
  105. package/dist/thread-bindings-runtime.js +2 -0
  106. package/dist/thread-bindings-shared-DK-d-oYX.js +97 -0
  107. package/dist/timeout-abort-signal-CtaIaP1v.js +2 -0
  108. package/dist/tool-actions.runtime-ThYhfHtZ.js +532 -0
  109. package/dist/url-validation-DiK9j7jz.js +36 -0
  110. package/dist/verification-CZ2rDeHL.js +345 -0
  111. package/openclaw.plugin.json +796 -1
  112. package/package.json +82 -16
  113. package/CHANGELOG.md +0 -104
  114. package/index.ts +0 -22
  115. package/src/actions.ts +0 -195
  116. package/src/channel.directory.test.ts +0 -135
  117. package/src/channel.ts +0 -461
  118. package/src/config-schema.test.ts +0 -26
  119. package/src/config-schema.ts +0 -62
  120. package/src/directory-live.test.ts +0 -85
  121. package/src/directory-live.ts +0 -209
  122. package/src/group-mentions.ts +0 -52
  123. package/src/matrix/accounts.test.ts +0 -131
  124. package/src/matrix/accounts.ts +0 -114
  125. package/src/matrix/actions/client.ts +0 -47
  126. package/src/matrix/actions/limits.test.ts +0 -15
  127. package/src/matrix/actions/limits.ts +0 -6
  128. package/src/matrix/actions/messages.ts +0 -126
  129. package/src/matrix/actions/pins.test.ts +0 -74
  130. package/src/matrix/actions/pins.ts +0 -84
  131. package/src/matrix/actions/reactions.test.ts +0 -109
  132. package/src/matrix/actions/reactions.ts +0 -102
  133. package/src/matrix/actions/room.ts +0 -85
  134. package/src/matrix/actions/summary.ts +0 -75
  135. package/src/matrix/actions/types.ts +0 -85
  136. package/src/matrix/actions.ts +0 -15
  137. package/src/matrix/active-client.ts +0 -32
  138. package/src/matrix/client/config.ts +0 -245
  139. package/src/matrix/client/create-client.ts +0 -125
  140. package/src/matrix/client/logging.ts +0 -46
  141. package/src/matrix/client/runtime.ts +0 -4
  142. package/src/matrix/client/shared.test.ts +0 -85
  143. package/src/matrix/client/shared.ts +0 -210
  144. package/src/matrix/client/startup.test.ts +0 -49
  145. package/src/matrix/client/startup.ts +0 -29
  146. package/src/matrix/client/storage.ts +0 -131
  147. package/src/matrix/client/types.ts +0 -34
  148. package/src/matrix/client-bootstrap.ts +0 -47
  149. package/src/matrix/client.test.ts +0 -56
  150. package/src/matrix/client.ts +0 -14
  151. package/src/matrix/credentials.ts +0 -125
  152. package/src/matrix/deps.test.ts +0 -74
  153. package/src/matrix/deps.ts +0 -126
  154. package/src/matrix/format.test.ts +0 -33
  155. package/src/matrix/format.ts +0 -22
  156. package/src/matrix/index.ts +0 -11
  157. package/src/matrix/monitor/access-policy.ts +0 -126
  158. package/src/matrix/monitor/allowlist.test.ts +0 -45
  159. package/src/matrix/monitor/allowlist.ts +0 -94
  160. package/src/matrix/monitor/auto-join.ts +0 -72
  161. package/src/matrix/monitor/direct.test.ts +0 -396
  162. package/src/matrix/monitor/direct.ts +0 -152
  163. package/src/matrix/monitor/events.test.ts +0 -186
  164. package/src/matrix/monitor/events.ts +0 -168
  165. package/src/matrix/monitor/handler.body-for-agent.test.ts +0 -196
  166. package/src/matrix/monitor/handler.ts +0 -768
  167. package/src/matrix/monitor/inbound-body.test.ts +0 -73
  168. package/src/matrix/monitor/inbound-body.ts +0 -28
  169. package/src/matrix/monitor/index.test.ts +0 -18
  170. package/src/matrix/monitor/index.ts +0 -414
  171. package/src/matrix/monitor/location.ts +0 -100
  172. package/src/matrix/monitor/media.test.ts +0 -86
  173. package/src/matrix/monitor/media.ts +0 -118
  174. package/src/matrix/monitor/mentions.test.ts +0 -154
  175. package/src/matrix/monitor/mentions.ts +0 -62
  176. package/src/matrix/monitor/replies.test.ts +0 -184
  177. package/src/matrix/monitor/replies.ts +0 -124
  178. package/src/matrix/monitor/room-info.ts +0 -55
  179. package/src/matrix/monitor/rooms.test.ts +0 -124
  180. package/src/matrix/monitor/rooms.ts +0 -47
  181. package/src/matrix/monitor/threads.ts +0 -68
  182. package/src/matrix/monitor/types.ts +0 -39
  183. package/src/matrix/poll-types.test.ts +0 -21
  184. package/src/matrix/poll-types.ts +0 -167
  185. package/src/matrix/probe.ts +0 -69
  186. package/src/matrix/sdk-runtime.ts +0 -18
  187. package/src/matrix/send/client.ts +0 -99
  188. package/src/matrix/send/formatting.ts +0 -93
  189. package/src/matrix/send/media.ts +0 -230
  190. package/src/matrix/send/targets.test.ts +0 -98
  191. package/src/matrix/send/targets.ts +0 -150
  192. package/src/matrix/send/types.ts +0 -110
  193. package/src/matrix/send-queue.test.ts +0 -145
  194. package/src/matrix/send-queue.ts +0 -28
  195. package/src/matrix/send.test.ts +0 -319
  196. package/src/matrix/send.ts +0 -267
  197. package/src/onboarding.ts +0 -462
  198. package/src/outbound.test.ts +0 -159
  199. package/src/outbound.ts +0 -58
  200. package/src/resolve-targets.test.ts +0 -68
  201. package/src/resolve-targets.ts +0 -125
  202. package/src/runtime.ts +0 -6
  203. package/src/secret-input.ts +0 -13
  204. package/src/test-mocks.ts +0 -53
  205. package/src/tool-actions.ts +0 -164
  206. package/src/types.ts +0 -118
@@ -1,68 +0,0 @@
1
- import type { ChannelDirectoryEntry } from "openclaw/plugin-sdk/matrix";
2
- import { describe, expect, it, vi, beforeEach } from "vitest";
3
- import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
4
- import { resolveMatrixTargets } from "./resolve-targets.js";
5
-
6
- vi.mock("./directory-live.js", () => ({
7
- listMatrixDirectoryPeersLive: vi.fn(),
8
- listMatrixDirectoryGroupsLive: vi.fn(),
9
- }));
10
-
11
- async function resolveUserTarget(input = "Alice") {
12
- const [result] = await resolveMatrixTargets({
13
- cfg: {},
14
- inputs: [input],
15
- kind: "user",
16
- });
17
- return result;
18
- }
19
-
20
- describe("resolveMatrixTargets (users)", () => {
21
- beforeEach(() => {
22
- vi.mocked(listMatrixDirectoryPeersLive).mockReset();
23
- vi.mocked(listMatrixDirectoryGroupsLive).mockReset();
24
- });
25
-
26
- it("resolves exact unique display name matches", async () => {
27
- const matches: ChannelDirectoryEntry[] = [
28
- { kind: "user", id: "@alice:example.org", name: "Alice" },
29
- ];
30
- vi.mocked(listMatrixDirectoryPeersLive).mockResolvedValue(matches);
31
-
32
- const result = await resolveUserTarget();
33
-
34
- expect(result?.resolved).toBe(true);
35
- expect(result?.id).toBe("@alice:example.org");
36
- });
37
-
38
- it("does not resolve ambiguous or non-exact matches", async () => {
39
- const matches: ChannelDirectoryEntry[] = [
40
- { kind: "user", id: "@alice:example.org", name: "Alice" },
41
- { kind: "user", id: "@alice:evil.example", name: "Alice" },
42
- ];
43
- vi.mocked(listMatrixDirectoryPeersLive).mockResolvedValue(matches);
44
-
45
- const result = await resolveUserTarget();
46
-
47
- expect(result?.resolved).toBe(false);
48
- expect(result?.note).toMatch(/use full Matrix ID/i);
49
- });
50
-
51
- it("prefers exact group matches over first partial result", async () => {
52
- const matches: ChannelDirectoryEntry[] = [
53
- { kind: "group", id: "!one:example.org", name: "General", handle: "#general" },
54
- { kind: "group", id: "!two:example.org", name: "Team", handle: "#team" },
55
- ];
56
- vi.mocked(listMatrixDirectoryGroupsLive).mockResolvedValue(matches);
57
-
58
- const [result] = await resolveMatrixTargets({
59
- cfg: {},
60
- inputs: ["#team"],
61
- kind: "group",
62
- });
63
-
64
- expect(result?.resolved).toBe(true);
65
- expect(result?.id).toBe("!two:example.org");
66
- expect(result?.note).toBe("multiple matches; chose first");
67
- });
68
- });
@@ -1,125 +0,0 @@
1
- import { mapAllowlistResolutionInputs } from "openclaw/plugin-sdk/compat";
2
- import type {
3
- ChannelDirectoryEntry,
4
- ChannelResolveKind,
5
- ChannelResolveResult,
6
- RuntimeEnv,
7
- } from "openclaw/plugin-sdk/matrix";
8
- import { listMatrixDirectoryGroupsLive, listMatrixDirectoryPeersLive } from "./directory-live.js";
9
-
10
- function findExactDirectoryMatches(
11
- matches: ChannelDirectoryEntry[],
12
- query: string,
13
- ): ChannelDirectoryEntry[] {
14
- const normalized = query.trim().toLowerCase();
15
- if (!normalized) {
16
- return [];
17
- }
18
- return matches.filter((match) => {
19
- const id = match.id.trim().toLowerCase();
20
- const name = match.name?.trim().toLowerCase();
21
- const handle = match.handle?.trim().toLowerCase();
22
- return normalized === id || normalized === name || normalized === handle;
23
- });
24
- }
25
-
26
- function pickBestGroupMatch(
27
- matches: ChannelDirectoryEntry[],
28
- query: string,
29
- ): ChannelDirectoryEntry | undefined {
30
- if (matches.length === 0) {
31
- return undefined;
32
- }
33
- const [exact] = findExactDirectoryMatches(matches, query);
34
- return exact ?? matches[0];
35
- }
36
-
37
- function pickBestUserMatch(
38
- matches: ChannelDirectoryEntry[],
39
- query: string,
40
- ): ChannelDirectoryEntry | undefined {
41
- if (matches.length === 0) {
42
- return undefined;
43
- }
44
- const exact = findExactDirectoryMatches(matches, query);
45
- if (exact.length === 1) {
46
- return exact[0];
47
- }
48
- return undefined;
49
- }
50
-
51
- function describeUserMatchFailure(matches: ChannelDirectoryEntry[], query: string): string {
52
- if (matches.length === 0) {
53
- return "no matches";
54
- }
55
- const normalized = query.trim().toLowerCase();
56
- if (!normalized) {
57
- return "empty input";
58
- }
59
- const exact = findExactDirectoryMatches(matches, normalized);
60
- if (exact.length === 0) {
61
- return "no exact match; use full Matrix ID";
62
- }
63
- if (exact.length > 1) {
64
- return "multiple exact matches; use full Matrix ID";
65
- }
66
- return "no exact match; use full Matrix ID";
67
- }
68
-
69
- export async function resolveMatrixTargets(params: {
70
- cfg: unknown;
71
- inputs: string[];
72
- kind: ChannelResolveKind;
73
- runtime?: RuntimeEnv;
74
- }): Promise<ChannelResolveResult[]> {
75
- return await mapAllowlistResolutionInputs({
76
- inputs: params.inputs,
77
- mapInput: async (input): Promise<ChannelResolveResult> => {
78
- const trimmed = input.trim();
79
- if (!trimmed) {
80
- return { input, resolved: false, note: "empty input" };
81
- }
82
- if (params.kind === "user") {
83
- if (trimmed.startsWith("@") && trimmed.includes(":")) {
84
- return { input, resolved: true, id: trimmed };
85
- }
86
- try {
87
- const matches = await listMatrixDirectoryPeersLive({
88
- cfg: params.cfg,
89
- query: trimmed,
90
- limit: 5,
91
- });
92
- const best = pickBestUserMatch(matches, trimmed);
93
- return {
94
- input,
95
- resolved: Boolean(best?.id),
96
- id: best?.id,
97
- name: best?.name,
98
- note: best ? undefined : describeUserMatchFailure(matches, trimmed),
99
- };
100
- } catch (err) {
101
- params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
102
- return { input, resolved: false, note: "lookup failed" };
103
- }
104
- }
105
- try {
106
- const matches = await listMatrixDirectoryGroupsLive({
107
- cfg: params.cfg,
108
- query: trimmed,
109
- limit: 5,
110
- });
111
- const best = pickBestGroupMatch(matches, trimmed);
112
- return {
113
- input,
114
- resolved: Boolean(best?.id),
115
- id: best?.id,
116
- name: best?.name,
117
- note: matches.length > 1 ? "multiple matches; chose first" : undefined,
118
- };
119
- } catch (err) {
120
- params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
121
- return { input, resolved: false, note: "lookup failed" };
122
- }
123
- },
124
- });
125
- }
package/src/runtime.ts DELETED
@@ -1,6 +0,0 @@
1
- import { createPluginRuntimeStore } from "openclaw/plugin-sdk/compat";
2
- import type { PluginRuntime } from "openclaw/plugin-sdk/matrix";
3
-
4
- const { setRuntime: setMatrixRuntime, getRuntime: getMatrixRuntime } =
5
- createPluginRuntimeStore<PluginRuntime>("Matrix runtime not initialized");
6
- export { getMatrixRuntime, setMatrixRuntime };
@@ -1,13 +0,0 @@
1
- import {
2
- buildSecretInputSchema,
3
- hasConfiguredSecretInput,
4
- normalizeResolvedSecretInputString,
5
- normalizeSecretInputString,
6
- } from "openclaw/plugin-sdk/matrix";
7
-
8
- export {
9
- buildSecretInputSchema,
10
- hasConfiguredSecretInput,
11
- normalizeResolvedSecretInputString,
12
- normalizeSecretInputString,
13
- };
package/src/test-mocks.ts DELETED
@@ -1,53 +0,0 @@
1
- import type { Mock } from "vitest";
2
- import { vi } from "vitest";
3
-
4
- type MatrixBotSdkMockParams = {
5
- matrixClient?: unknown;
6
- simpleFsStorageProvider?: unknown;
7
- rustSdkCryptoStorageProvider?: unknown;
8
- includeVerboseLogService?: boolean;
9
- };
10
-
11
- type MatrixBotSdkMock = {
12
- ConsoleLogger: new () => {
13
- trace: Mock<() => void>;
14
- debug: Mock<() => void>;
15
- info: Mock<() => void>;
16
- warn: Mock<() => void>;
17
- error: Mock<() => void>;
18
- };
19
- MatrixClient: unknown;
20
- LogService: {
21
- setLogger: Mock<() => void>;
22
- warn?: Mock<() => void>;
23
- info?: Mock<() => void>;
24
- debug?: Mock<() => void>;
25
- };
26
- SimpleFsStorageProvider: unknown;
27
- RustSdkCryptoStorageProvider: unknown;
28
- };
29
-
30
- export function createMatrixBotSdkMock(params: MatrixBotSdkMockParams = {}): MatrixBotSdkMock {
31
- return {
32
- ConsoleLogger: class {
33
- trace = vi.fn();
34
- debug = vi.fn();
35
- info = vi.fn();
36
- warn = vi.fn();
37
- error = vi.fn();
38
- },
39
- MatrixClient: params.matrixClient ?? class {},
40
- LogService: {
41
- setLogger: vi.fn(),
42
- ...(params.includeVerboseLogService
43
- ? {
44
- warn: vi.fn(),
45
- info: vi.fn(),
46
- debug: vi.fn(),
47
- }
48
- : {}),
49
- },
50
- SimpleFsStorageProvider: params.simpleFsStorageProvider ?? class {},
51
- RustSdkCryptoStorageProvider: params.rustSdkCryptoStorageProvider ?? class {},
52
- };
53
- }
@@ -1,164 +0,0 @@
1
- import type { AgentToolResult } from "@mariozechner/pi-agent-core";
2
- import {
3
- createActionGate,
4
- jsonResult,
5
- readNumberParam,
6
- readReactionParams,
7
- readStringParam,
8
- } from "openclaw/plugin-sdk/matrix";
9
- import {
10
- deleteMatrixMessage,
11
- editMatrixMessage,
12
- getMatrixMemberInfo,
13
- getMatrixRoomInfo,
14
- listMatrixPins,
15
- listMatrixReactions,
16
- pinMatrixMessage,
17
- readMatrixMessages,
18
- removeMatrixReactions,
19
- sendMatrixMessage,
20
- unpinMatrixMessage,
21
- } from "./matrix/actions.js";
22
- import { reactMatrixMessage } from "./matrix/send.js";
23
- import type { CoreConfig } from "./types.js";
24
-
25
- const messageActions = new Set(["sendMessage", "editMessage", "deleteMessage", "readMessages"]);
26
- const reactionActions = new Set(["react", "reactions"]);
27
- const pinActions = new Set(["pinMessage", "unpinMessage", "listPins"]);
28
-
29
- function readRoomId(params: Record<string, unknown>, required = true): string {
30
- const direct = readStringParam(params, "roomId") ?? readStringParam(params, "channelId");
31
- if (direct) {
32
- return direct;
33
- }
34
- if (!required) {
35
- return readStringParam(params, "to") ?? "";
36
- }
37
- return readStringParam(params, "to", { required: true });
38
- }
39
-
40
- export async function handleMatrixAction(
41
- params: Record<string, unknown>,
42
- cfg: CoreConfig,
43
- ): Promise<AgentToolResult<unknown>> {
44
- const action = readStringParam(params, "action", { required: true });
45
- const isActionEnabled = createActionGate(cfg.channels?.matrix?.actions);
46
-
47
- if (reactionActions.has(action)) {
48
- if (!isActionEnabled("reactions")) {
49
- throw new Error("Matrix reactions are disabled.");
50
- }
51
- const roomId = readRoomId(params);
52
- const messageId = readStringParam(params, "messageId", { required: true });
53
- if (action === "react") {
54
- const { emoji, remove, isEmpty } = readReactionParams(params, {
55
- removeErrorMessage: "Emoji is required to remove a Matrix reaction.",
56
- });
57
- if (remove || isEmpty) {
58
- const result = await removeMatrixReactions(roomId, messageId, {
59
- emoji: remove ? emoji : undefined,
60
- });
61
- return jsonResult({ ok: true, removed: result.removed });
62
- }
63
- await reactMatrixMessage(roomId, messageId, emoji);
64
- return jsonResult({ ok: true, added: emoji });
65
- }
66
- const reactions = await listMatrixReactions(roomId, messageId);
67
- return jsonResult({ ok: true, reactions });
68
- }
69
-
70
- if (messageActions.has(action)) {
71
- if (!isActionEnabled("messages")) {
72
- throw new Error("Matrix messages are disabled.");
73
- }
74
- switch (action) {
75
- case "sendMessage": {
76
- const to = readStringParam(params, "to", { required: true });
77
- const content = readStringParam(params, "content", {
78
- required: true,
79
- allowEmpty: true,
80
- });
81
- const mediaUrl = readStringParam(params, "mediaUrl");
82
- const replyToId =
83
- readStringParam(params, "replyToId") ?? readStringParam(params, "replyTo");
84
- const threadId = readStringParam(params, "threadId");
85
- const result = await sendMatrixMessage(to, content, {
86
- mediaUrl: mediaUrl ?? undefined,
87
- replyToId: replyToId ?? undefined,
88
- threadId: threadId ?? undefined,
89
- });
90
- return jsonResult({ ok: true, result });
91
- }
92
- case "editMessage": {
93
- const roomId = readRoomId(params);
94
- const messageId = readStringParam(params, "messageId", { required: true });
95
- const content = readStringParam(params, "content", { required: true });
96
- const result = await editMatrixMessage(roomId, messageId, content);
97
- return jsonResult({ ok: true, result });
98
- }
99
- case "deleteMessage": {
100
- const roomId = readRoomId(params);
101
- const messageId = readStringParam(params, "messageId", { required: true });
102
- const reason = readStringParam(params, "reason");
103
- await deleteMatrixMessage(roomId, messageId, { reason: reason ?? undefined });
104
- return jsonResult({ ok: true, deleted: true });
105
- }
106
- case "readMessages": {
107
- const roomId = readRoomId(params);
108
- const limit = readNumberParam(params, "limit", { integer: true });
109
- const before = readStringParam(params, "before");
110
- const after = readStringParam(params, "after");
111
- const result = await readMatrixMessages(roomId, {
112
- limit: limit ?? undefined,
113
- before: before ?? undefined,
114
- after: after ?? undefined,
115
- });
116
- return jsonResult({ ok: true, ...result });
117
- }
118
- default:
119
- break;
120
- }
121
- }
122
-
123
- if (pinActions.has(action)) {
124
- if (!isActionEnabled("pins")) {
125
- throw new Error("Matrix pins are disabled.");
126
- }
127
- const roomId = readRoomId(params);
128
- if (action === "pinMessage") {
129
- const messageId = readStringParam(params, "messageId", { required: true });
130
- const result = await pinMatrixMessage(roomId, messageId);
131
- return jsonResult({ ok: true, pinned: result.pinned });
132
- }
133
- if (action === "unpinMessage") {
134
- const messageId = readStringParam(params, "messageId", { required: true });
135
- const result = await unpinMatrixMessage(roomId, messageId);
136
- return jsonResult({ ok: true, pinned: result.pinned });
137
- }
138
- const result = await listMatrixPins(roomId);
139
- return jsonResult({ ok: true, pinned: result.pinned, events: result.events });
140
- }
141
-
142
- if (action === "memberInfo") {
143
- if (!isActionEnabled("memberInfo")) {
144
- throw new Error("Matrix member info is disabled.");
145
- }
146
- const userId = readStringParam(params, "userId", { required: true });
147
- const roomId = readStringParam(params, "roomId") ?? readStringParam(params, "channelId");
148
- const result = await getMatrixMemberInfo(userId, {
149
- roomId: roomId ?? undefined,
150
- });
151
- return jsonResult({ ok: true, member: result });
152
- }
153
-
154
- if (action === "channelInfo") {
155
- if (!isActionEnabled("channelInfo")) {
156
- throw new Error("Matrix room info is disabled.");
157
- }
158
- const roomId = readRoomId(params);
159
- const result = await getMatrixRoomInfo(roomId);
160
- return jsonResult({ ok: true, room: result });
161
- }
162
-
163
- throw new Error(`Unsupported Matrix action: ${action}`);
164
- }
package/src/types.ts DELETED
@@ -1,118 +0,0 @@
1
- import type { DmPolicy, GroupPolicy, SecretInput } from "openclaw/plugin-sdk/matrix";
2
- export type { DmPolicy, GroupPolicy };
3
-
4
- export type ReplyToMode = "off" | "first" | "all";
5
-
6
- export type MatrixDmConfig = {
7
- /** If false, ignore all incoming Matrix DMs. Default: true. */
8
- enabled?: boolean;
9
- /** Direct message access policy (default: pairing). */
10
- policy?: DmPolicy;
11
- /** Allowlist for DM senders (matrix user IDs or "*"). */
12
- allowFrom?: Array<string | number>;
13
- };
14
-
15
- export type MatrixRoomConfig = {
16
- /** If false, disable the bot in this room (alias for allow: false). */
17
- enabled?: boolean;
18
- /** Legacy room allow toggle; prefer enabled. */
19
- allow?: boolean;
20
- /** Require mentioning the bot to trigger replies. */
21
- requireMention?: boolean;
22
- /** Optional tool policy overrides for this room. */
23
- tools?: { allow?: string[]; deny?: string[] };
24
- /** If true, reply without mention requirements. */
25
- autoReply?: boolean;
26
- /** Optional allowlist for room senders (matrix user IDs). */
27
- users?: Array<string | number>;
28
- /** Optional skill filter for this room. */
29
- skills?: string[];
30
- /** Optional system prompt snippet for this room. */
31
- systemPrompt?: string;
32
- };
33
-
34
- export type MatrixActionConfig = {
35
- reactions?: boolean;
36
- messages?: boolean;
37
- pins?: boolean;
38
- memberInfo?: boolean;
39
- channelInfo?: boolean;
40
- };
41
-
42
- /** Per-account Matrix config (excludes the accounts field to prevent recursion). */
43
- export type MatrixAccountConfig = Omit<MatrixConfig, "accounts">;
44
-
45
- export type MatrixConfig = {
46
- /** Optional display name for this account (used in CLI/UI lists). */
47
- name?: string;
48
- /** If false, do not start Matrix. Default: true. */
49
- enabled?: boolean;
50
- /** Multi-account configuration keyed by account ID. */
51
- accounts?: Record<string, MatrixAccountConfig>;
52
- /** Optional default account id when multiple accounts are configured. */
53
- defaultAccount?: string;
54
- /** Matrix homeserver URL (https://matrix.example.org). */
55
- homeserver?: string;
56
- /** Matrix user id (@user:server). */
57
- userId?: string;
58
- /** Matrix access token. */
59
- accessToken?: string;
60
- /** Matrix password (used only to fetch access token). */
61
- password?: SecretInput;
62
- /** Optional device name when logging in via password. */
63
- deviceName?: string;
64
- /** Initial sync limit for startup (default: @vector-im/matrix-bot-sdk default). */
65
- initialSyncLimit?: number;
66
- /** Enable end-to-end encryption (E2EE). Default: false. */
67
- encryption?: boolean;
68
- /** If true, enforce allowlists for groups + DMs regardless of policy. */
69
- allowlistOnly?: boolean;
70
- /** Group message policy (default: allowlist). */
71
- groupPolicy?: GroupPolicy;
72
- /** Allowlist for group senders (matrix user IDs). */
73
- groupAllowFrom?: Array<string | number>;
74
- /** Control reply threading when reply tags are present (off|first|all). */
75
- replyToMode?: ReplyToMode;
76
- /** How to handle thread replies (off|inbound|always). */
77
- threadReplies?: "off" | "inbound" | "always";
78
- /** Outbound text chunk size (chars). Default: 4000. */
79
- textChunkLimit?: number;
80
- /** Chunking mode: "length" (default) splits by size; "newline" splits on every newline. */
81
- chunkMode?: "length" | "newline";
82
- /** Outbound response prefix override for this channel/account. */
83
- responsePrefix?: string;
84
- /** Max outbound media size in MB. */
85
- mediaMaxMb?: number;
86
- /** Auto-join invites (always|allowlist|off). Default: always. */
87
- autoJoin?: "always" | "allowlist" | "off";
88
- /** Allowlist for auto-join invites (room IDs, aliases). */
89
- autoJoinAllowlist?: Array<string | number>;
90
- /** Direct message policy + allowlist overrides. */
91
- dm?: MatrixDmConfig;
92
- /** Room config allowlist keyed by room ID or alias (names resolved to IDs when possible). */
93
- groups?: Record<string, MatrixRoomConfig>;
94
- /** Room config allowlist keyed by room ID or alias. Legacy; use groups. */
95
- rooms?: Record<string, MatrixRoomConfig>;
96
- /** Per-action tool gating (default: true for all). */
97
- actions?: MatrixActionConfig;
98
- };
99
-
100
- export type CoreConfig = {
101
- channels?: {
102
- matrix?: MatrixConfig;
103
- defaults?: {
104
- groupPolicy?: "open" | "allowlist" | "disabled";
105
- };
106
- };
107
- commands?: {
108
- useAccessGroups?: boolean;
109
- };
110
- session?: {
111
- store?: string;
112
- };
113
- messages?: {
114
- ackReaction?: string;
115
- ackReactionScope?: "group-mentions" | "group-all" | "direct" | "all" | "off" | "none";
116
- };
117
- [key: string]: unknown;
118
- };