@openclaw/matrix 2026.9.2 → 2026.9.4

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 (68) hide show
  1. package/dist/{account-selection-DA-jfx22.js → account-selection-Bbtc483D.js} +9 -1
  2. package/dist/{accounts-DR1c4xF_.js → accounts-GwSAk9vY.js} +2 -2
  3. package/dist/api.js +6 -6
  4. package/dist/{approval-handler.runtime-BJCD4dLf.js → approval-handler.runtime-6I3IpyeX.js} +6 -6
  5. package/dist/{approval-ids-Bst7HM_o.js → approval-ids-C4NdeXNz.js} +1 -1
  6. package/dist/{approval-reaction-auth-DhH8QOSe.js → approval-reaction-auth-cbltZAUQ.js} +2 -2
  7. package/dist/{channel-Bs8VLb6q.js → channel-Cg97H4c1.js} +13 -202
  8. package/dist/channel-plugin-api.js +1 -1
  9. package/dist/{channel.runtime-CCJRhdH5.js → channel.runtime-Bhpfa1qc.js} +6 -11
  10. package/dist/{channel.setup-DhmDXwPp.js → channel.setup-DmS7m7aT.js} +3 -3
  11. package/dist/{cli-IvDUuiDH.js → cli-CLexRrQw.js} +9 -9
  12. package/dist/{cli-metadata-BGryAl2e.js → cli-metadata-zRyVmUOL.js} +1 -1
  13. package/dist/cli-metadata.js +1 -1
  14. package/dist/{client-oNOlldJI.js → client-C0nZFCTj.js} +2 -2
  15. package/dist/{client-Dj4mcf-s.js → client-CPcRv6ab.js} +6 -6
  16. package/dist/{client-bootstrap-n1Rqc8Go.js → client-bootstrap-DLN-K8Xb.js} +1 -6
  17. package/dist/contract-api.js +2 -2
  18. package/dist/{credentials-DJj2xs3q.js → credentials-DysXbkv2.js} +2 -2
  19. package/dist/{credentials-read-mexhw-Ur.js → credentials-read-WWpqi88V.js} +1 -1
  20. package/dist/{credentials-write.runtime-DQt-kgJq.js → credentials-write.runtime-D22lPwRO.js} +1 -1
  21. package/dist/{crypto-runtime-m1eplj3b.js → crypto-runtime-DiyH4R3D.js} +3 -25
  22. package/dist/{crypto-snapshot-doctor.runtime-D0v841D_.js → crypto-snapshot-doctor.runtime-DxgUMXUy.js} +2 -2
  23. package/dist/{directory-live-DLUgWBhA.js → directory-live-B8-GAVcc.js} +2 -2
  24. package/dist/doctor-contract-api.js +41 -21
  25. package/dist/{draft-stream-DglwxWzJ.js → draft-stream--NdEtnZ8.js} +16 -5
  26. package/dist/{encryption-guidance-BNcZNQZI.js → encryption-guidance-mDyxJV9U.js} +1 -1
  27. package/dist/{event-helpers-XRfAbOIh.js → event-helpers-CspuhE9k.js} +9 -1
  28. package/dist/helper-api.js +3 -3
  29. package/dist/{http-client-DOmFvKvB.js → http-client-BfPeF4CE.js} +1 -1
  30. package/dist/{idb-persistence-CU7CNLlX.js → idb-persistence-DBdwHSWg.js} +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/{messages-Czn8lNEh.js → messages-CpZfiQO0.js} +6 -99
  33. package/dist/{monitor-DouG43FJ.js → monitor-BUek91SW.js} +61 -92
  34. package/dist/{outbound-Co_tJyE6.js → outbound-D91JinYa.js} +1 -1
  35. package/dist/plugin-entry.handlers.runtime.js +1 -1
  36. package/dist/probe.runtime-DWdw74_H.js +2 -0
  37. package/dist/{profile-update-CAl8nZNG.js → profile-update-vnhxwjEt.js} +1 -1
  38. package/dist/{reaction-events-C_7G7bvI.js → reaction-events-2WM2nJe_.js} +5 -7
  39. package/dist/{resolve-targets-B64O69Nd.js → resolve-targets-K8D0HWPX.js} +1 -1
  40. package/dist/{resolver.runtime-TRmePJDV.js → resolver.runtime-C88GwQCx.js} +1 -1
  41. package/dist/{room-info-6viLR3NH.js → room-info-BPVJkXnp.js} +7 -4
  42. package/dist/runtime-api.js +2 -2
  43. package/dist/{sdk-C1yfda1L.js → sdk-B4By16Bt.js} +13 -6
  44. package/dist/{send-B5XChnvB.js → send-UWLIQ0bG.js} +211 -135
  45. package/dist/session-binding-contract-api.js +1 -1
  46. package/dist/{setup-bootstrap-S_loyUyM.js → setup-bootstrap-sVqkwtSY.js} +2 -2
  47. package/dist/{setup-core-XkIfQ65J.js → setup-core-8keb-Yre.js} +14 -29
  48. package/dist/setup-plugin-api.js +1 -1
  49. package/dist/{setup-surface-B2yZ8KGc.js → setup-surface-bcluelBI.js} +8 -17
  50. package/dist/{startup-verification-1Ney1mmI.js → startup-verification-BTSf31hS.js} +2 -1
  51. package/dist/storage-CV-pfV_2.js +320 -0
  52. package/dist/{storage-BVf4uucD.js → storage-metadata-DYArLcq1.js} +14 -319
  53. package/dist/{storage-paths-gUmSydsW.js → storage-paths-DVCANXTc.js} +13 -1
  54. package/dist/{sync-cache-state-d-A_OhbU.js → sync-cache-state-C-mhj3xb.js} +9 -3
  55. package/dist/{thread-bindings-BkBnn4te.js → thread-bindings-Bwv87Gve.js} +3 -2
  56. package/dist/{tool-actions.runtime-a5L5xGSP.js → tool-actions.runtime-Bf98Juk6.js} +295 -256
  57. package/dist/types-DzSc7Sqm.js +32 -0
  58. package/dist/{verification-XJtTc5DI.js → verification-BbG-VC9S.js} +2 -2
  59. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/package.json +1 -1
  60. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm.d.ts +69 -4
  61. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.cjs +526 -432
  62. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.js +358 -265
  63. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm +0 -0
  64. package/node_modules/@matrix-org/matrix-sdk-crypto-wasm/pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts +8 -7
  65. package/openclaw.plugin.json +27 -1
  66. package/package.json +5 -5
  67. package/dist/probe.runtime-B1YPxG9x.js +0 -2
  68. package/dist/runtime-BefyhPWv.js +0 -6
@@ -1,17 +1,17 @@
1
1
  import { a as resolveMatrixAccountConfig, o as resolveMatrixBaseConfig } from "./account-config-CRsKoMqJ.js";
2
- import { i as resolveMatrixAccount } from "./accounts-DR1c4xF_.js";
3
- import { l as resolveMatrixRoomConfig } from "./channel-Bs8VLb6q.js";
2
+ import { i as resolveMatrixAccount } from "./accounts-GwSAk9vY.js";
3
+ import { a as resolveMatrixRoomConfig } from "./channel-Cg97H4c1.js";
4
4
  import { i as normalizeMatrixResolvableTarget } from "./target-ids-Nwx7cMVE.js";
5
- import { i as buildMatrixReactionRelationsPath, o as selectOwnMatrixReactionEventIds, s as summarizeMatrixReactionEvents } from "./reaction-common-DkrQdBSZ.js";
6
- import { b as resolveMatrixRoomId, h as parsePollStart, l as buildPollResponseContent, m as isPollStartType, n as reactMatrixMessage } from "./send-B5XChnvB.js";
5
+ import { C as parsePollStart, O as resolveMatrixRoomId, S as isPollStartType, _ as buildPollResponseContent, n as reactMatrixMessage } from "./send-UWLIQ0bG.js";
7
6
  import { i as isStrictDirectMembership, n as hasDirectMatrixMemberFlag, o as readJoinedMatrixMembers } from "./direct-room-RinHjtqX.js";
8
- import { a as fetchEventSummary, i as sendMatrixMessage, n as editMatrixMessage, o as readPinnedEvents, p as resolveMatrixActionLimit, r as readMatrixMessages, s as EventType, t as deleteMatrixMessage } from "./messages-Czn8lNEh.js";
9
- import { n as withResolvedActionClient, r as withResolvedRoomAction } from "./client-oNOlldJI.js";
10
- import { r as parseMxc } from "./event-helpers-XRfAbOIh.js";
11
- import { t as applyMatrixProfileUpdate } from "./profile-update-CAl8nZNG.js";
12
- import { _ as scanMatrixVerificationQr, a as confirmMatrixVerificationSas, b as verifyMatrixRecoveryKey, c as getMatrixRoomKeyBackupStatus, d as listMatrixVerifications, f as mismatchMatrixVerificationSas, h as restoreMatrixRoomKeyBackup, i as confirmMatrixVerificationReciprocateQr, l as getMatrixVerificationSas, n as bootstrapMatrixVerification, o as generateMatrixVerificationQr, p as requestMatrixVerification, r as cancelMatrixVerification, s as getMatrixEncryptionStatus, t as acceptMatrixVerification, u as getMatrixVerificationStatus, v as startMatrixVerification } from "./verification-XJtTc5DI.js";
13
- import { n as getMatrixMemberInfo, r as getMatrixRoomInfo, t as createMatrixRoomInfoResolver } from "./room-info-6viLR3NH.js";
14
- import { isRecord, normalizeOptionalLowercaseString, uniqueStrings, uniqueValues } from "openclaw/plugin-sdk/string-coerce-runtime";
7
+ import { i as buildMatrixReactionRelationsPath, o as selectOwnMatrixReactionEventIds, s as summarizeMatrixReactionEvents } from "./reaction-common-DkrQdBSZ.js";
8
+ import { i as parseMxc } from "./event-helpers-CspuhE9k.js";
9
+ import { a as fetchEventSummary, c as resolveMatrixActionLimit, i as sendMatrixMessage, n as editMatrixMessage, o as readPinnedEvents, r as readMatrixMessages, s as EventType, t as deleteMatrixMessage } from "./messages-CpZfiQO0.js";
10
+ import { n as withResolvedActionClient, r as withResolvedRoomAction } from "./client-C0nZFCTj.js";
11
+ import { t as applyMatrixProfileUpdate } from "./profile-update-vnhxwjEt.js";
12
+ import { _ as scanMatrixVerificationQr, a as confirmMatrixVerificationSas, b as verifyMatrixRecoveryKey, c as getMatrixRoomKeyBackupStatus, d as listMatrixVerifications, f as mismatchMatrixVerificationSas, h as restoreMatrixRoomKeyBackup, i as confirmMatrixVerificationReciprocateQr, l as getMatrixVerificationSas, n as bootstrapMatrixVerification, o as generateMatrixVerificationQr, p as requestMatrixVerification, r as cancelMatrixVerification, s as getMatrixEncryptionStatus, t as acceptMatrixVerification, u as getMatrixVerificationStatus, v as startMatrixVerification } from "./verification-BbG-VC9S.js";
13
+ import { n as getMatrixMemberInfo, r as getMatrixRoomInfo, t as createMatrixRoomInfoResolver } from "./room-info-BPVJkXnp.js";
14
+ import { isRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, uniqueStrings, uniqueValues } from "openclaw/plugin-sdk/string-coerce-runtime";
15
15
  import { ToolAuthorizationError, createActionGate, jsonResult, readPositiveIntegerParam, readReactionParams, readStringArrayParam, readStringParam } from "openclaw/plugin-sdk/channel-actions";
16
16
  import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
17
17
  import { resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
@@ -284,43 +284,6 @@ async function withAuthorizedMatrixReadTarget(params) {
284
284
  }
285
285
  //#endregion
286
286
  //#region extensions/matrix/src/tool-actions.ts
287
- const messageActions = /* @__PURE__ */ new Set([
288
- "sendMessage",
289
- "editMessage",
290
- "deleteMessage",
291
- "readMessages"
292
- ]);
293
- const reactionActions = /* @__PURE__ */ new Set([
294
- "react",
295
- "reactions",
296
- "emoji-list"
297
- ]);
298
- const pinActions = /* @__PURE__ */ new Set([
299
- "pinMessage",
300
- "unpinMessage",
301
- "listPins"
302
- ]);
303
- const pollActions = /* @__PURE__ */ new Set(["pollVote"]);
304
- const profileActions = /* @__PURE__ */ new Set(["setProfile"]);
305
- const verificationActions = /* @__PURE__ */ new Set([
306
- "encryptionStatus",
307
- "verificationList",
308
- "verificationRequest",
309
- "verificationAccept",
310
- "verificationCancel",
311
- "verificationStart",
312
- "verificationGenerateQr",
313
- "verificationScanQr",
314
- "verificationSas",
315
- "verificationConfirm",
316
- "verificationMismatch",
317
- "verificationConfirmQr",
318
- "verificationStatus",
319
- "verificationBootstrap",
320
- "verificationRecoveryKey",
321
- "verificationBackupStatus",
322
- "verificationBackupRestore"
323
- ]);
324
287
  function projectMatrixMessagesForDisplay(messages) {
325
288
  return messages.map((message) => ({
326
289
  ...message,
@@ -330,10 +293,9 @@ function projectMatrixMessagesForDisplay(messages) {
330
293
  ...typeof message.timestamp === "number" && Number.isFinite(message.timestamp) && Math.abs(message.timestamp) <= 864e13 ? { ts: new Date(message.timestamp).toISOString() } : {}
331
294
  }));
332
295
  }
333
- function readRoomId(params, required = true) {
296
+ function readRoomId(params) {
334
297
  const direct = readStringParam(params, "roomId") ?? readStringParam(params, "channelId");
335
298
  if (direct) return direct;
336
- if (!required) return readStringParam(params, "to") ?? "";
337
299
  return readStringParam(params, "to", { required: true });
338
300
  }
339
301
  function toSnakeCaseKey(key) {
@@ -367,202 +329,221 @@ function readPositiveIntegerArrayParam(params, key) {
367
329
  return index === void 0 ? [] : [index];
368
330
  });
369
331
  }
370
- async function handleMatrixAction(params, cfg, opts = {}) {
371
- const action = readStringParam(params, "action", { required: true });
372
- const accountId = readStringParam(params, "accountId") ?? void 0;
373
- const isActionEnabled = createActionGate(resolveMatrixAccountConfig({
374
- cfg,
375
- accountId
376
- }).actions);
377
- const clientOpts = {
378
- cfg,
379
- ...accountId ? { accountId } : {}
332
+ async function handleMatrixAction(ctx) {
333
+ const { action, params } = ctx;
334
+ const cfg = ctx.cfg;
335
+ const prepareAction = (gate) => {
336
+ const accountParams = action === "poll-vote" || action === "permissions" ? {
337
+ ...params,
338
+ ...ctx.accountId ? { accountId: ctx.accountId } : {}
339
+ } : { accountId: ctx.accountId };
340
+ const accountId = readStringParam(accountParams, "accountId");
341
+ const isActionEnabled = createActionGate(resolveMatrixAccountConfig({
342
+ cfg,
343
+ accountId
344
+ }).actions);
345
+ if (gate && !isActionEnabled(gate.name)) throw new Error(gate.disabledMessage);
346
+ const clientOpts = {
347
+ cfg,
348
+ ...accountId ? { accountId } : {}
349
+ };
350
+ const withReadTarget = async (roomId, run) => await withAuthorizedMatrixReadTarget({
351
+ cfg,
352
+ accountId,
353
+ roomId,
354
+ context: {
355
+ accountId: ctx.accountId,
356
+ requesterAccountId: ctx.requesterAccountId,
357
+ currentChannelId: ctx.toolContext?.currentChannelId,
358
+ currentChannelProvider: ctx.toolContext?.currentChannelProvider,
359
+ currentChatType: ctx.toolContext?.currentChatType,
360
+ conversationReadOrigin: ctx.conversationReadOrigin
361
+ },
362
+ opts: clientOpts,
363
+ run
364
+ });
365
+ return {
366
+ accountId,
367
+ clientOpts,
368
+ withReadTarget
369
+ };
380
370
  };
381
- const withReadTarget = async (roomId, run) => await withAuthorizedMatrixReadTarget({
382
- cfg,
383
- accountId,
384
- roomId,
385
- context: opts.readContext,
386
- opts: clientOpts,
387
- run
388
- });
389
- if (reactionActions.has(action)) {
390
- if (!isActionEnabled("reactions")) throw new Error("Matrix reactions are disabled.");
371
+ if (action === "send") {
372
+ const to = readStringParam(params, "to", { required: true });
373
+ const mediaUrl = readStringParam(params, "media", { trim: false }) ?? readStringParam(params, "mediaUrl", { trim: false }) ?? readStringParam(params, "filePath", { trim: false }) ?? readStringParam(params, "path", { trim: false });
374
+ const content = readStringParam(params, "message", {
375
+ required: !mediaUrl,
376
+ allowEmpty: true,
377
+ trim: false
378
+ });
379
+ const replyToId = readStringParam(params, "replyTo");
380
+ const threadId = readStringParam(params, "threadId");
381
+ const audioAsVoice = typeof params.asVoice === "boolean" ? params.asVoice : typeof params.audioAsVoice === "boolean" ? params.audioAsVoice : void 0;
382
+ const { clientOpts } = prepareAction({
383
+ name: "messages",
384
+ disabledMessage: "Matrix messages are disabled."
385
+ });
386
+ const result = await sendMatrixMessage(to, content, {
387
+ mediaUrl: mediaUrl ?? void 0,
388
+ ...ctx.mediaAccess ? { mediaAccess: ctx.mediaAccess } : {},
389
+ mediaLocalRoots: ctx.mediaLocalRoots,
390
+ replyToId: replyToId ?? void 0,
391
+ threadId: threadId ?? void 0,
392
+ audioAsVoice,
393
+ ...clientOpts
394
+ });
395
+ return jsonResult({
396
+ ok: true,
397
+ result
398
+ });
399
+ }
400
+ if (action === "react") {
401
+ const messageId = readStringParam(params, "messageId", { required: true });
402
+ const emojiValue = readStringParam(params, "emoji", { allowEmpty: true });
403
+ const removeValue = typeof params.remove === "boolean" ? params.remove : void 0;
391
404
  const roomId = readRoomId(params);
392
- if (action === "emoji-list") {
393
- const limit = readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." });
394
- const emojis = await withReadTarget(roomId, async (target) => listMatrixEmojis(target.roomId, {
405
+ const { clientOpts, withReadTarget } = prepareAction({
406
+ name: "reactions",
407
+ disabledMessage: "Matrix reactions are disabled."
408
+ });
409
+ const { emoji, remove, isEmpty } = readReactionParams({
410
+ emoji: emojiValue,
411
+ remove: removeValue
412
+ }, { removeErrorMessage: "Emoji is required to remove a Matrix reaction." });
413
+ if (remove || isEmpty) {
414
+ const result = await withReadTarget(roomId, async (target) => removeMatrixReactions(target.roomId, messageId, {
395
415
  ...clientOpts,
396
416
  client: target.client,
397
- limit
417
+ emoji: remove ? emoji : void 0
398
418
  }));
399
419
  return jsonResult({
400
420
  ok: true,
401
- emojis
421
+ removed: result.removed
402
422
  });
403
423
  }
424
+ await withReadTarget(roomId, async (target) => reactMatrixMessage(target.roomId, messageId, emoji, {
425
+ ...clientOpts,
426
+ client: target.client
427
+ }));
428
+ return jsonResult({
429
+ ok: true,
430
+ added: emoji
431
+ });
432
+ }
433
+ if (action === "reactions") {
404
434
  const messageId = readStringParam(params, "messageId", { required: true });
405
- if (action === "react") {
406
- const { emoji, remove, isEmpty } = readReactionParams(params, { removeErrorMessage: "Emoji is required to remove a Matrix reaction." });
407
- if (remove || isEmpty) {
408
- const result = await withReadTarget(roomId, async (target) => {
409
- return await removeMatrixReactions(target.roomId, messageId, {
410
- ...clientOpts,
411
- client: target.client,
412
- emoji: remove ? emoji : void 0
413
- });
414
- });
415
- return jsonResult({
416
- ok: true,
417
- removed: result.removed
418
- });
419
- }
420
- await withReadTarget(roomId, async (target) => {
421
- await reactMatrixMessage(target.roomId, messageId, emoji, {
422
- ...clientOpts,
423
- client: target.client
424
- });
425
- });
426
- return jsonResult({
427
- ok: true,
428
- added: emoji
429
- });
430
- }
431
435
  const limit = readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." });
432
- const reactions = await withReadTarget(roomId, async (target) => {
433
- return await listMatrixReactions(target.roomId, messageId, {
434
- ...clientOpts,
435
- client: target.client,
436
- limit: limit ?? void 0
437
- });
436
+ const roomId = readRoomId(params);
437
+ const { clientOpts, withReadTarget } = prepareAction({
438
+ name: "reactions",
439
+ disabledMessage: "Matrix reactions are disabled."
438
440
  });
441
+ const reactions = await withReadTarget(roomId, async (target) => listMatrixReactions(target.roomId, messageId, {
442
+ ...clientOpts,
443
+ client: target.client,
444
+ limit: limit ?? void 0
445
+ }));
439
446
  return jsonResult({
440
447
  ok: true,
441
448
  reactions
442
449
  });
443
450
  }
444
- if (pollActions.has(action)) {
451
+ if (action === "emoji-list") {
452
+ const roomId = readStringParam(params, "roomId") ?? readStringParam(params, "channelId") ?? readStringParam(params, "to") ?? (ctx.toolContext?.currentChannelProvider === "matrix" ? ctx.toolContext.currentChannelId : void 0);
453
+ if (!roomId) throw new Error("Matrix emoji-list requires a roomId or current Matrix conversation.");
454
+ const limit = readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." });
455
+ const { clientOpts, withReadTarget } = prepareAction({
456
+ name: "reactions",
457
+ disabledMessage: "Matrix reactions are disabled."
458
+ });
459
+ const emojis = await withReadTarget(readRoomId({ roomId }), async (target) => listMatrixEmojis(target.roomId, {
460
+ ...clientOpts,
461
+ client: target.client,
462
+ limit
463
+ }));
464
+ return jsonResult({
465
+ ok: true,
466
+ emojis
467
+ });
468
+ }
469
+ if (action === "read") {
470
+ const limit = readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." });
445
471
  const roomId = readRoomId(params);
446
- const pollId = readStringAliasParam(params, ["pollId", "messageId"], { required: true });
447
- if (!pollId) throw new Error("pollId required");
448
- const optionId = readStringParam(params, "pollOptionId");
449
- const optionIndex = readPositiveIntegerParam(params, "pollOptionIndex", { message: "pollOptionIndex must be a positive integer." });
450
- const optionIds = [...readStringArrayParam(params, "pollOptionIds") ?? [], ...optionId ? [optionId] : []];
451
- const optionIndexes = [...readPositiveIntegerArrayParam(params, "pollOptionIndexes"), ...optionIndex !== void 0 ? [optionIndex] : []];
472
+ const before = readStringParam(params, "before");
473
+ const after = readStringParam(params, "after");
474
+ const threadId = readStringParam(params, "threadId");
475
+ const { clientOpts, withReadTarget } = prepareAction({
476
+ name: "messages",
477
+ disabledMessage: "Matrix messages are disabled."
478
+ });
452
479
  const result = await withReadTarget(roomId, async (target) => {
453
- return await voteMatrixPoll(target.roomId, pollId, {
480
+ const messages = await readMatrixMessages(target.roomId, {
481
+ limit: limit ?? void 0,
482
+ before: before ?? void 0,
483
+ after: after ?? void 0,
484
+ threadId: threadId ?? void 0,
454
485
  ...clientOpts,
455
- client: target.client,
456
- optionIds,
457
- optionIndexes
486
+ client: target.client
458
487
  });
488
+ return {
489
+ ...messages,
490
+ messages: projectMatrixMessagesForDisplay(messages.messages),
491
+ roomId: target.roomId,
492
+ ...threadId ? { threadId } : {}
493
+ };
459
494
  });
460
495
  return jsonResult({
461
496
  ok: true,
462
- result
497
+ ...result
463
498
  });
464
499
  }
465
- if (messageActions.has(action)) {
466
- if (!isActionEnabled("messages")) throw new Error("Matrix messages are disabled.");
467
- switch (action) {
468
- case "sendMessage": {
469
- const to = readStringParam(params, "to", { required: true });
470
- const mediaUrl = readStringParam(params, "mediaUrl", { trim: false }) ?? readStringParam(params, "media", { trim: false }) ?? readStringParam(params, "filePath", { trim: false }) ?? readStringParam(params, "path", { trim: false });
471
- const content = readStringParam(params, "content", {
472
- required: !mediaUrl,
473
- allowEmpty: true,
474
- trim: false
475
- });
476
- const replyToId = readStringParam(params, "replyToId") ?? readStringParam(params, "replyTo");
477
- const threadId = readStringParam(params, "threadId");
478
- const audioAsVoice = typeof readRawParam(params, "audioAsVoice") === "boolean" ? readRawParam(params, "audioAsVoice") : typeof readRawParam(params, "asVoice") === "boolean" ? readRawParam(params, "asVoice") : void 0;
479
- const result = await sendMatrixMessage(to, content, {
480
- mediaUrl: mediaUrl ?? void 0,
481
- ...opts.mediaAccess ? { mediaAccess: opts.mediaAccess } : {},
482
- mediaLocalRoots: opts.mediaLocalRoots,
483
- replyToId: replyToId ?? void 0,
484
- threadId: threadId ?? void 0,
485
- audioAsVoice,
486
- ...clientOpts
487
- });
488
- return jsonResult({
489
- ok: true,
490
- result
491
- });
492
- }
493
- case "editMessage": {
494
- const roomId = readRoomId(params);
495
- const messageId = readStringParam(params, "messageId", { required: true });
496
- const content = readStringParam(params, "content", {
497
- required: true,
498
- trim: false
499
- });
500
- const result = await withReadTarget(roomId, async (target) => {
501
- return await editMatrixMessage(target.roomId, messageId, content, {
502
- ...clientOpts,
503
- client: target.client
504
- });
505
- });
506
- return jsonResult({
507
- ok: true,
508
- result
509
- });
510
- }
511
- case "deleteMessage": {
512
- const roomId = readRoomId(params);
513
- const messageId = readStringParam(params, "messageId", { required: true });
514
- const reason = readStringParam(params, "reason");
515
- await withReadTarget(roomId, async (target) => {
516
- await deleteMatrixMessage(target.roomId, messageId, {
517
- reason: reason ?? void 0,
518
- ...clientOpts,
519
- client: target.client
520
- });
521
- });
522
- return jsonResult({
523
- ok: true,
524
- deleted: true
525
- });
526
- }
527
- case "readMessages": {
528
- const roomId = readRoomId(params);
529
- const limit = readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." });
530
- const before = readStringParam(params, "before");
531
- const after = readStringParam(params, "after");
532
- const threadId = readStringParam(params, "threadId");
533
- const result = await withReadTarget(roomId, async (target) => {
534
- const messages = await readMatrixMessages(target.roomId, {
535
- limit: limit ?? void 0,
536
- before: before ?? void 0,
537
- after: after ?? void 0,
538
- threadId: threadId ?? void 0,
539
- ...clientOpts,
540
- client: target.client
541
- });
542
- return {
543
- ...messages,
544
- messages: projectMatrixMessagesForDisplay(messages.messages),
545
- roomId: target.roomId,
546
- ...threadId ? { threadId } : {}
547
- };
548
- });
549
- return jsonResult({
550
- ok: true,
551
- ...result
552
- });
553
- }
554
- }
500
+ if (action === "edit") {
501
+ const messageId = readStringParam(params, "messageId", { required: true });
502
+ const content = readStringParam(params, "message", {
503
+ required: true,
504
+ trim: false
505
+ });
506
+ const roomId = readRoomId(params);
507
+ const { clientOpts, withReadTarget } = prepareAction({
508
+ name: "messages",
509
+ disabledMessage: "Matrix messages are disabled."
510
+ });
511
+ const result = await withReadTarget(roomId, async (target) => editMatrixMessage(target.roomId, messageId, content, {
512
+ ...clientOpts,
513
+ client: target.client
514
+ }));
515
+ return jsonResult({
516
+ ok: true,
517
+ result
518
+ });
555
519
  }
556
- if (pinActions.has(action)) {
557
- if (!isActionEnabled("pins")) throw new Error("Matrix pins are disabled.");
520
+ if (action === "delete") {
521
+ const messageId = readStringParam(params, "messageId", { required: true });
558
522
  const roomId = readRoomId(params);
559
- const request = action === "pinMessage" ? {
560
- kind: "pin",
561
- messageId: readStringParam(params, "messageId", { required: true })
562
- } : action === "unpinMessage" ? {
563
- kind: "unpin",
523
+ const { clientOpts, withReadTarget } = prepareAction({
524
+ name: "messages",
525
+ disabledMessage: "Matrix messages are disabled."
526
+ });
527
+ await withReadTarget(roomId, async (target) => deleteMatrixMessage(target.roomId, messageId, {
528
+ reason: void 0,
529
+ ...clientOpts,
530
+ client: target.client
531
+ }));
532
+ return jsonResult({
533
+ ok: true,
534
+ deleted: true
535
+ });
536
+ }
537
+ if (action === "pin" || action === "unpin" || action === "list-pins") {
538
+ const request = action === "list-pins" ? { kind: "list" } : {
539
+ kind: action,
564
540
  messageId: readStringParam(params, "messageId", { required: true })
565
- } : { kind: "list" };
541
+ };
542
+ const roomId = readRoomId(params);
543
+ const { clientOpts, withReadTarget } = prepareAction({
544
+ name: "pins",
545
+ disabledMessage: "Matrix pins are disabled."
546
+ });
566
547
  return await withReadTarget(roomId, async (target) => {
567
548
  const actionOpts = {
568
549
  ...clientOpts,
@@ -591,54 +572,112 @@ async function handleMatrixAction(params, cfg, opts = {}) {
591
572
  });
592
573
  });
593
574
  }
594
- if (profileActions.has(action)) {
595
- if (!isActionEnabled("profile")) throw new Error("Matrix profile updates are disabled.");
575
+ if (action === "set-profile") {
576
+ if (ctx.senderIsOwner !== true) throw new ToolAuthorizationError("Matrix profile updates require owner access.");
596
577
  const avatarPath = readStringParam(params, "avatarPath") ?? readStringParam(params, "path") ?? readStringParam(params, "filePath");
578
+ const displayName = readStringParam(params, "displayName") ?? readStringParam(params, "name");
579
+ const avatarUrl = readStringParam(params, "avatarUrl");
580
+ const { accountId } = prepareAction({
581
+ name: "profile",
582
+ disabledMessage: "Matrix profile updates are disabled."
583
+ });
597
584
  const result = await applyMatrixProfileUpdate({
598
585
  cfg,
599
586
  account: accountId,
600
- displayName: readStringParam(params, "displayName") ?? readStringParam(params, "name"),
601
- avatarUrl: readStringParam(params, "avatarUrl"),
587
+ displayName,
588
+ avatarUrl,
602
589
  avatarPath,
603
- mediaLocalRoots: opts.mediaLocalRoots
590
+ mediaLocalRoots: ctx.mediaLocalRoots
604
591
  });
605
592
  return jsonResult({
606
593
  ok: true,
607
594
  ...result
608
595
  });
609
596
  }
610
- if (action === "memberInfo") {
611
- if (!isActionEnabled("memberInfo")) throw new Error("Matrix member info is disabled.");
597
+ if (action === "member-info") {
612
598
  const userId = readStringParam(params, "userId", { required: true });
613
- const result = await withReadTarget(readRoomId(params), async (target) => {
614
- return await getMatrixMemberInfo(userId, {
615
- roomId: target.roomId,
616
- ...clientOpts,
617
- client: target.client
618
- });
599
+ const roomId = readRoomId(params);
600
+ const { clientOpts, withReadTarget } = prepareAction({
601
+ name: "memberInfo",
602
+ disabledMessage: "Matrix member info is disabled."
619
603
  });
604
+ const result = await withReadTarget(roomId, async (target) => getMatrixMemberInfo(userId, {
605
+ roomId: target.roomId,
606
+ ...clientOpts,
607
+ client: target.client
608
+ }));
620
609
  return jsonResult({
621
610
  ok: true,
622
611
  member: result
623
612
  });
624
613
  }
625
- if (action === "channelInfo") {
626
- if (!isActionEnabled("channelInfo")) throw new Error("Matrix room info is disabled.");
627
- const result = await withReadTarget(readRoomId(params), async (target) => {
628
- return await getMatrixRoomInfo(target.roomId, {
614
+ if (action === "channel-info") {
615
+ const roomId = readRoomId(params);
616
+ const { clientOpts, withReadTarget } = prepareAction({
617
+ name: "channelInfo",
618
+ disabledMessage: "Matrix room info is disabled."
619
+ });
620
+ const result = await withReadTarget(roomId, async (target) => getMatrixRoomInfo(target.roomId, {
621
+ ...clientOpts,
622
+ client: target.client
623
+ }));
624
+ return jsonResult({
625
+ ok: true,
626
+ room: result
627
+ });
628
+ }
629
+ if (action === "poll-vote") {
630
+ const { clientOpts, withReadTarget } = prepareAction();
631
+ const roomId = readRoomId(params);
632
+ const pollId = readStringAliasParam(params, ["pollId", "messageId"], { required: true });
633
+ if (!pollId) throw new Error("pollId required");
634
+ const optionId = readStringParam(params, "pollOptionId");
635
+ const optionIndex = readPositiveIntegerParam(params, "pollOptionIndex", { message: "pollOptionIndex must be a positive integer." });
636
+ const optionIds = [...readStringArrayParam(params, "pollOptionIds") ?? [], ...optionId ? [optionId] : []];
637
+ const optionIndexes = [...readPositiveIntegerArrayParam(params, "pollOptionIndexes"), ...optionIndex !== void 0 ? [optionIndex] : []];
638
+ const result = await withReadTarget(roomId, async (target) => {
639
+ return await voteMatrixPoll(target.roomId, pollId, {
629
640
  ...clientOpts,
630
- client: target.client
641
+ client: target.client,
642
+ optionIds,
643
+ optionIndexes
631
644
  });
632
645
  });
633
646
  return jsonResult({
634
647
  ok: true,
635
- room: result
648
+ result
636
649
  });
637
650
  }
638
- if (verificationActions.has(action)) {
639
- if (!isActionEnabled("verification")) throw new Error("Matrix verification actions are disabled.");
651
+ if (action === "permissions") {
652
+ if (ctx.senderIsOwner !== true) throw new ToolAuthorizationError("Matrix verification actions require owner access.");
653
+ const operation = normalizeLowercaseStringOrEmpty(readStringParam(params, "operation") ?? readStringParam(params, "mode") ?? "verification-list");
654
+ const operationToAction = {
655
+ "encryption-status": "encryptionStatus",
656
+ "verification-status": "verificationStatus",
657
+ "verification-bootstrap": "verificationBootstrap",
658
+ "verification-recovery-key": "verificationRecoveryKey",
659
+ "verification-backup-status": "verificationBackupStatus",
660
+ "verification-backup-restore": "verificationBackupRestore",
661
+ "verification-list": "verificationList",
662
+ "verification-request": "verificationRequest",
663
+ "verification-accept": "verificationAccept",
664
+ "verification-cancel": "verificationCancel",
665
+ "verification-start": "verificationStart",
666
+ "verification-generate-qr": "verificationGenerateQr",
667
+ "verification-scan-qr": "verificationScanQr",
668
+ "verification-sas": "verificationSas",
669
+ "verification-confirm": "verificationConfirm",
670
+ "verification-mismatch": "verificationMismatch",
671
+ "verification-confirm-qr": "verificationConfirmQr"
672
+ };
673
+ if (!Object.hasOwn(operationToAction, operation)) throw new Error(`Unsupported Matrix permissions operation: ${operation}. Supported values: ${Object.keys(operationToAction).join(", ")}`);
674
+ const resolvedAction = operationToAction[operation];
675
+ const { clientOpts } = prepareAction({
676
+ name: "verification",
677
+ disabledMessage: "Matrix verification actions are disabled."
678
+ });
640
679
  const requestId = readStringParam(params, "requestId") ?? readStringParam(params, "verificationId") ?? readStringParam(params, "id");
641
- if (action === "encryptionStatus") {
680
+ if (resolvedAction === "encryptionStatus") {
642
681
  const includeRecoveryKey = params.includeRecoveryKey === true;
643
682
  const status = await getMatrixEncryptionStatus({
644
683
  includeRecoveryKey,
@@ -649,7 +688,7 @@ async function handleMatrixAction(params, cfg, opts = {}) {
649
688
  status
650
689
  });
651
690
  }
652
- if (action === "verificationStatus") {
691
+ if (resolvedAction === "verificationStatus") {
653
692
  const includeRecoveryKey = params.includeRecoveryKey === true;
654
693
  const status = await getMatrixVerificationStatus({
655
694
  includeRecoveryKey,
@@ -660,7 +699,7 @@ async function handleMatrixAction(params, cfg, opts = {}) {
660
699
  status
661
700
  });
662
701
  }
663
- if (action === "verificationBootstrap") {
702
+ if (resolvedAction === "verificationBootstrap") {
664
703
  const recoveryKey = readStringParam(params, "recoveryKey", { trim: false }) ?? readStringParam(params, "key", { trim: false });
665
704
  const result = await bootstrapMatrixVerification({
666
705
  recoveryKey: recoveryKey ?? void 0,
@@ -672,7 +711,7 @@ async function handleMatrixAction(params, cfg, opts = {}) {
672
711
  result
673
712
  });
674
713
  }
675
- if (action === "verificationRecoveryKey") {
714
+ if (resolvedAction === "verificationRecoveryKey") {
676
715
  const recoveryKey = readStringParam(params, "recoveryKey", { trim: false }) ?? readStringParam(params, "key", { trim: false });
677
716
  const result = await verifyMatrixRecoveryKey(readStringParam({ recoveryKey }, "recoveryKey", {
678
717
  required: true,
@@ -683,14 +722,14 @@ async function handleMatrixAction(params, cfg, opts = {}) {
683
722
  result
684
723
  });
685
724
  }
686
- if (action === "verificationBackupStatus") {
725
+ if (resolvedAction === "verificationBackupStatus") {
687
726
  const status = await getMatrixRoomKeyBackupStatus(clientOpts);
688
727
  return jsonResult({
689
728
  ok: true,
690
729
  status
691
730
  });
692
731
  }
693
- if (action === "verificationBackupRestore") {
732
+ if (resolvedAction === "verificationBackupRestore") {
694
733
  const recoveryKey = readStringParam(params, "recoveryKey", { trim: false }) ?? readStringParam(params, "key", { trim: false });
695
734
  const result = await restoreMatrixRoomKeyBackup({
696
735
  recoveryKey: recoveryKey ?? void 0,
@@ -701,14 +740,14 @@ async function handleMatrixAction(params, cfg, opts = {}) {
701
740
  result
702
741
  });
703
742
  }
704
- if (action === "verificationList") {
743
+ if (resolvedAction === "verificationList") {
705
744
  const verifications = await listMatrixVerifications(clientOpts);
706
745
  return jsonResult({
707
746
  ok: true,
708
747
  verifications
709
748
  });
710
749
  }
711
- if (action === "verificationRequest") {
750
+ if (resolvedAction === "verificationRequest") {
712
751
  const userId = readStringParam(params, "userId");
713
752
  const deviceId = readStringParam(params, "deviceId");
714
753
  const roomId = readStringParam(params, "roomId") ?? readStringParam(params, "channelId");
@@ -725,14 +764,14 @@ async function handleMatrixAction(params, cfg, opts = {}) {
725
764
  verification
726
765
  });
727
766
  }
728
- if (action === "verificationAccept") {
767
+ if (resolvedAction === "verificationAccept") {
729
768
  const verification = await acceptMatrixVerification(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
730
769
  return jsonResult({
731
770
  ok: true,
732
771
  verification
733
772
  });
734
773
  }
735
- if (action === "verificationCancel") {
774
+ if (resolvedAction === "verificationCancel") {
736
775
  const reason = readStringParam(params, "reason");
737
776
  const code = readStringParam(params, "code");
738
777
  const verification = await cancelMatrixVerification(readStringParam({ requestId }, "requestId", { required: true }), {
@@ -745,7 +784,7 @@ async function handleMatrixAction(params, cfg, opts = {}) {
745
784
  verification
746
785
  });
747
786
  }
748
- if (action === "verificationStart") {
787
+ if (resolvedAction === "verificationStart") {
749
788
  const methodRaw = readStringParam(params, "method");
750
789
  const method = normalizeOptionalLowercaseString(methodRaw);
751
790
  if (method && method !== "sas") throw new Error("Matrix verificationStart only supports method=sas; use verificationGenerateQr/verificationScanQr for QR flows.");
@@ -758,14 +797,14 @@ async function handleMatrixAction(params, cfg, opts = {}) {
758
797
  verification
759
798
  });
760
799
  }
761
- if (action === "verificationGenerateQr") {
800
+ if (resolvedAction === "verificationGenerateQr") {
762
801
  const qr = await generateMatrixVerificationQr(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
763
802
  return jsonResult({
764
803
  ok: true,
765
804
  ...qr
766
805
  });
767
806
  }
768
- if (action === "verificationScanQr") {
807
+ if (resolvedAction === "verificationScanQr") {
769
808
  const qrDataBase64 = readStringParam(params, "qrDataBase64") ?? readStringParam(params, "qrData") ?? readStringParam(params, "qr");
770
809
  const verification = await scanMatrixVerificationQr(readStringParam({ requestId }, "requestId", { required: true }), readStringParam({ qrDataBase64 }, "qrDataBase64", { required: true }), clientOpts);
771
810
  return jsonResult({
@@ -773,28 +812,28 @@ async function handleMatrixAction(params, cfg, opts = {}) {
773
812
  verification
774
813
  });
775
814
  }
776
- if (action === "verificationSas") {
815
+ if (resolvedAction === "verificationSas") {
777
816
  const sas = await getMatrixVerificationSas(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
778
817
  return jsonResult({
779
818
  ok: true,
780
819
  sas
781
820
  });
782
821
  }
783
- if (action === "verificationConfirm") {
822
+ if (resolvedAction === "verificationConfirm") {
784
823
  const verification = await confirmMatrixVerificationSas(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
785
824
  return jsonResult({
786
825
  ok: true,
787
826
  verification
788
827
  });
789
828
  }
790
- if (action === "verificationMismatch") {
829
+ if (resolvedAction === "verificationMismatch") {
791
830
  const verification = await mismatchMatrixVerificationSas(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
792
831
  return jsonResult({
793
832
  ok: true,
794
833
  verification
795
834
  });
796
835
  }
797
- if (action === "verificationConfirmQr") {
836
+ if (resolvedAction === "verificationConfirmQr") {
798
837
  const verification = await confirmMatrixVerificationReciprocateQr(readStringParam({ requestId }, "requestId", { required: true }), clientOpts);
799
838
  return jsonResult({
800
839
  ok: true,
@@ -802,7 +841,7 @@ async function handleMatrixAction(params, cfg, opts = {}) {
802
841
  });
803
842
  }
804
843
  }
805
- throw new Error(`Unsupported Matrix action: ${action}`);
844
+ throw new Error(`Action ${action} is not supported for provider matrix.`);
806
845
  }
807
846
  //#endregion
808
847
  export { handleMatrixAction };