@openclaw/matrix 2026.9.1-beta.1 → 2026.9.2

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 (103) hide show
  1. package/dist/{account-config-BZWN9tGS.js → account-config-CRsKoMqJ.js} +1 -1
  2. package/dist/{account-selection-CWuhuFn1.js → account-selection-DA-jfx22.js} +74 -36
  3. package/dist/{accounts-BCzyubQt.js → accounts-DR1c4xF_.js} +4 -5
  4. package/dist/api.js +5 -5
  5. package/dist/{approval-handler.runtime-G9fLHUWe.js → approval-handler.runtime-BJCD4dLf.js} +34 -11
  6. package/dist/{approval-ids-C6FD3pVY.js → approval-ids-Bst7HM_o.js} +1 -1
  7. package/dist/{approval-reaction-auth-60xHiDtQ.js → approval-reaction-auth-DhH8QOSe.js} +2 -2
  8. package/dist/{approval-reactions-tXh9KYrW.js → approval-reactions-1fwEhoK9.js} +1 -1
  9. package/dist/{channel-CBEvelTE.js → channel-Bs8VLb6q.js} +63 -58
  10. package/dist/channel-plugin-api.js +1 -1
  11. package/dist/channel.runtime-CCJRhdH5.js +76 -0
  12. package/dist/{channel.setup-sWPOGyQG.js → channel.setup-DhmDXwPp.js} +32 -22
  13. package/dist/{cli-DrTD2a_q.js → cli-IvDUuiDH.js} +179 -135
  14. package/dist/{cli-metadata-DrYVwQ_r.js → cli-metadata-BGryAl2e.js} +1 -1
  15. package/dist/cli-metadata.js +1 -1
  16. package/dist/{client-hs1ePy2O.js → client-Dj4mcf-s.js} +73 -22
  17. package/dist/{client-bootstrap-BxdxjCwA.js → client-bootstrap-n1Rqc8Go.js} +1 -1
  18. package/dist/{client-BUtHbzib.js → client-oNOlldJI.js} +2 -2
  19. package/dist/{config-update-Bor_Pjsv.js → config-update-BnX26jCO.js} +48 -31
  20. package/dist/contract-api.js +2 -2
  21. package/dist/{credentials-BdAaWuiR.js → credentials-DJj2xs3q.js} +4 -8
  22. package/dist/{credentials-read-B37cQknZ.js → credentials-read-mexhw-Ur.js} +7 -5
  23. package/dist/{credentials-write.runtime-nAV2-5uR.js → credentials-write.runtime-DQt-kgJq.js} +1 -1
  24. package/dist/{crypto-runtime-C4WDYxlP.js → crypto-runtime-m1eplj3b.js} +7 -7
  25. package/dist/crypto-snapshot-doctor.runtime-D0v841D_.js +91 -0
  26. package/dist/{deps-CcVJfvRM.js → deps-mtxF2mHI.js} +1 -1
  27. package/dist/{directory-live-D0KfJlby.js → directory-live-DLUgWBhA.js} +8 -6
  28. package/dist/{doctor-EWf9CDso.js → doctor-CJE8wO6y.js} +1 -1
  29. package/dist/{doctor-contract-DEt4O4Zt.js → doctor-contract-HyWFZQVG.js} +5 -4
  30. package/dist/doctor-contract-api.js +89 -109
  31. package/dist/{draft-stream-B_m79Ynb.js → draft-stream-DglwxWzJ.js} +1 -1
  32. package/dist/{encryption-guidance-DmLY8NiO.js → encryption-guidance-BNcZNQZI.js} +3 -2
  33. package/dist/helper-api.js +1 -1
  34. package/dist/{http-client-D8o8b9u6.js → http-client-DOmFvKvB.js} +10 -7
  35. package/dist/{idb-persistence-DfgW720p.js → idb-persistence-CU7CNLlX.js} +2 -2
  36. package/dist/{idb-persistence-lock-DAJ49nZX.js → idb-persistence-lock-B3fZXyF_.js} +1 -1
  37. package/dist/{inbound-dedupe-RvSLqdsz.js → inbound-dedupe-Ch33GU06.js} +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/{messages-Dow9EOoJ.js → messages-Czn8lNEh.js} +154 -5
  40. package/dist/{monitor-DBB47wTy.js → monitor-DouG43FJ.js} +200 -156
  41. package/dist/outbound-Co_tJyE6.js +220 -0
  42. package/dist/plugin-entry.handlers.runtime.js +1 -1
  43. package/dist/probe.runtime-B1YPxG9x.js +2 -0
  44. package/dist/{profile-update-C61NR24_.js → profile-update-CAl8nZNG.js} +5 -4
  45. package/dist/{profile-D-Wubo0A.js → profile-vmjsmhh4.js} +1 -1
  46. package/dist/{reaction-events-BZUgLIZI.js → reaction-events-C_7G7bvI.js} +9 -7
  47. package/dist/{resolve-targets-DXzZwsIY.js → resolve-targets-B64O69Nd.js} +1 -1
  48. package/dist/{resolver.runtime-p5qJ3Kst.js → resolver.runtime-TRmePJDV.js} +1 -1
  49. package/dist/{room-info-BXQA7y10.js → room-info-6viLR3NH.js} +55 -1
  50. package/dist/runtime-api.js +2 -2
  51. package/dist/{sdk-CljOKEvc.js → sdk-C1yfda1L.js} +534 -26
  52. package/dist/{send-BKu9Ghi4.js → send-B5XChnvB.js} +31 -33
  53. package/dist/session-binding-contract-api.js +1 -1
  54. package/dist/{setup-bootstrap-CpE6C3qV.js → setup-bootstrap-S_loyUyM.js} +3 -3
  55. package/dist/{setup-core-CyvaCOOr.js → setup-core-XkIfQ65J.js} +8 -7
  56. package/dist/setup-plugin-api.js +1 -1
  57. package/dist/{setup-surface-DtRvRcCT.js → setup-surface-B2yZ8KGc.js} +84 -79
  58. package/dist/{startup-verification-Cs08ca8u.js → startup-verification-1Ney1mmI.js} +2 -2
  59. package/dist/{storage-BsGuHngK.js → storage-BVf4uucD.js} +5 -4
  60. package/dist/{subagent-hooks-CMoZaARG.js → subagent-hooks-DeICLbU5.js} +5 -1
  61. package/dist/subagent-hooks-api.js +1 -1
  62. package/dist/sync-cache-state-d-A_OhbU.js +234 -0
  63. package/dist/{thread-bindings-BvyU66kE.js → thread-bindings-BkBnn4te.js} +4 -4
  64. package/dist/{tool-actions.runtime-DD6jUxFK.js → tool-actions.runtime-a5L5xGSP.js} +226 -215
  65. package/dist/{verification-BP-3-XYn.js → verification-XJtTc5DI.js} +2 -2
  66. package/node_modules/markdown-it/dist/browser/markdown-it.esm.min.mjs +216 -183
  67. package/node_modules/markdown-it/dist/browser/markdown-it.esm.min.mjs.map +1 -1
  68. package/node_modules/markdown-it/dist/browser/markdown-it.umd.min.js +7 -7
  69. package/node_modules/markdown-it/dist/browser/markdown-it.umd.min.js.map +1 -1
  70. package/node_modules/markdown-it/dist/markdown-it.cjs.js +98 -106
  71. package/node_modules/markdown-it/dist/markdown-it.cjs.js.map +1 -1
  72. package/node_modules/markdown-it/dist/markdown-it.d.mts +42 -71
  73. package/node_modules/markdown-it/dist/markdown-it.mjs +98 -106
  74. package/node_modules/markdown-it/dist/markdown-it.mjs.map +1 -1
  75. package/node_modules/markdown-it/package.json +1 -2
  76. package/node_modules/matrix-js-sdk/lib/client.d.ts +2 -1
  77. package/node_modules/matrix-js-sdk/lib/client.js +6 -2
  78. package/node_modules/matrix-js-sdk/lib/sync.js +8 -8
  79. package/node_modules/matrix-js-sdk/src/client.ts +7 -3
  80. package/node_modules/matrix-js-sdk/src/sync.ts +8 -8
  81. package/node_modules/typebox/build/format/email.mjs +1 -1
  82. package/node_modules/typebox/build/format/idna/idn-hostname.mjs +19 -1
  83. package/node_modules/typebox/build/format/json_pointer.d.mts +2 -2
  84. package/node_modules/typebox/build/format/json_pointer.mjs +2 -2
  85. package/node_modules/typebox/build/format/json_pointer_uri_fragment.d.mts +2 -2
  86. package/node_modules/typebox/build/format/json_pointer_uri_fragment.mjs +2 -2
  87. package/node_modules/typebox/build/format/relative_json_pointer.d.mts +2 -2
  88. package/node_modules/typebox/build/format/relative_json_pointer.mjs +2 -2
  89. package/node_modules/typebox/build/system/memory/assign.mjs +2 -1
  90. package/node_modules/typebox/build/system/memory/create.mjs +3 -4
  91. package/node_modules/typebox/build/system/memory/discard.mjs +2 -2
  92. package/node_modules/typebox/build/system/memory/freeze.d.mts +4 -0
  93. package/node_modules/typebox/build/system/memory/freeze.mjs +6 -0
  94. package/node_modules/typebox/build/system/memory/update.mjs +3 -2
  95. package/node_modules/typebox/package.json +1 -1
  96. package/openclaw.plugin.json +17 -3
  97. package/package.json +8 -7
  98. package/dist/channel.runtime-CiDl9deX.js +0 -276
  99. package/dist/env-auth-MVS-Vv41.js +0 -64
  100. package/dist/file-sync-store-DjskBX2o.js +0 -436
  101. package/dist/media-text-OR9uoC4W.js +0 -153
  102. package/dist/probe.runtime-CRM7RIrB.js +0 -2
  103. package/dist/recovery-key-store-CognuDys.js +0 -276
@@ -1,29 +1,30 @@
1
- import { a as resolveMatrixAccountConfig, i as resolveMatrixAccountAllowlistConfig } from "./account-config-BZWN9tGS.js";
1
+ import { a as resolveMatrixAccountConfig, i as resolveMatrixAccountAllowlistConfig } from "./account-config-CRsKoMqJ.js";
2
2
  import { t as getMatrixRuntime } from "./runtime-6S3DNFNv.js";
3
- import { n as resolveConfiguredMatrixBotUserIds } from "./accounts-BCzyubQt.js";
4
- import { _ as logInboundDrop, a as resolveMatrixThreadRootId, b as summarizeMapping, c as RelationType, d as buildAllowlistResolutionSummary, f as canonicalizeAllowlistWithResolvedIds, g as getAgentScopedMediaLocalRoots, h as formatLocationText, i as resolveMatrixReplyToEventId, l as resolveMatrixRoomConfig, m as createTypingCallbacks, n as resolveMatrixStoredSessionMeta, o as resolveMatrixThreadRouting, p as createReplyPrefixOptions, r as resolveMatrixInboundRoute, s as EventType, u as addAllowlistUserEntriesFromConfigEntry, v as logTypingFailure, x as toLocationContext, y as patchAllowlistUsersInConfigEntries } from "./channel-CBEvelTE.js";
5
- import { a as normalizeMatrixUserId, i as normalizeMatrixAllowList, o as resolveMatrixAllowListMatch } from "./channel.setup-sWPOGyQG.js";
3
+ import { n as resolveConfiguredMatrixBotUserIds } from "./accounts-DR1c4xF_.js";
4
+ import { _ as logInboundDrop, a as resolveMatrixThreadRootId, b as summarizeMapping, c as RelationType, d as buildAllowlistResolutionSummary, f as canonicalizeAllowlistWithResolvedIds, g as getAgentScopedMediaLocalRoots, h as formatLocationText, i as resolveMatrixReplyToEventId, l as resolveMatrixRoomConfig, m as createTypingCallbacks, n as resolveMatrixStoredSessionMeta, o as resolveMatrixThreadRouting, p as createReplyPrefixOptions, r as resolveMatrixInboundRoute, s as EventType, u as addAllowlistUserEntriesFromConfigEntry, v as logTypingFailure, x as toLocationContext, y as patchAllowlistUsersInConfigEntries } from "./channel-Bs8VLb6q.js";
5
+ import { a as normalizeMatrixUserId, i as normalizeMatrixAllowList, o as resolveMatrixAllowListMatch } from "./channel.setup-DhmDXwPp.js";
6
6
  import { n as isMatrixRoomId, t as isMatrixQualifiedUserId } from "./target-ids-Nwx7cMVE.js";
7
- import { C as promoteMatrixDirectRoomCandidate, T as MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY, _ as parsePollStartContent, c as chunkMatrixText, f as formatPollAsText, h as isPollStartType, m as isPollEventType, r as sendMessageMatrix } from "./send-BKu9Ghi4.js";
7
+ import { S as promoteMatrixDirectRoomCandidate, d as formatPollAsText, g as parsePollStartContent, m as isPollStartType, p as isPollEventType, r as sendMessageMatrix, w as MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY } from "./send-B5XChnvB.js";
8
8
  import { i as isStrictDirectMembership, n as hasDirectMatrixMemberFlag, o as readJoinedMatrixMembers } from "./direct-room-RinHjtqX.js";
9
- import { t as createMatrixThreadBindingManager } from "./thread-bindings-BvyU66kE.js";
10
- import { a as resolveBundledMatrixReplacementContent, c as fetchMatrixPollSnapshot, i as isLikelyBareFilename, n as formatMatrixMediaUnavailableText, r as formatMatrixMessageText, t as formatMatrixMediaTooLargeText } from "./media-text-OR9uoC4W.js";
9
+ import { t as createMatrixThreadBindingManager } from "./thread-bindings-BkBnn4te.js";
10
+ import { c as formatMatrixMediaTooLargeText, d as isLikelyBareFilename, f as resolveBundledMatrixReplacementContent, l as formatMatrixMediaUnavailableText, m as fetchMatrixPollSnapshot, r as readMatrixMessages, u as formatMatrixMessageText } from "./messages-Czn8lNEh.js";
11
11
  import { t as isBunRuntime } from "./runtime-BefyhPWv.js";
12
- import { a as throwIfMatrixStartupAborted, c as resolveMatrixAuth, i as isMatrixStartupAbortError, l as resolveMatrixAuthContext, n as acquireSharedMatrixClient, s as backfillMatrixAuthDeviceIdAfterStartup } from "./client-hs1ePy2O.js";
13
- import { i as isMatrixMediaSizeLimitError, r as MatrixMediaSizeLimitError } from "./http-client-D8o8b9u6.js";
14
- import { t as resolveMatrixTargets } from "./resolve-targets-DXzZwsIY.js";
15
- import { t as formatMatrixEncryptedEventDisabledWarning } from "./encryption-guidance-DmLY8NiO.js";
16
- import { createMatrixInboundEventDeduper } from "./inbound-dedupe-RvSLqdsz.js";
12
+ import { a as throwIfMatrixStartupAborted, c as backfillMatrixAuthDeviceIdAfterStartup, i as isMatrixStartupAbortError, l as resolveMatrixAuth, n as acquireSharedMatrixClient, o as createMatrixMonitorTaskRunner, u as resolveMatrixAuthContext } from "./client-Dj4mcf-s.js";
13
+ import { i as isMatrixMediaSizeLimitError, r as MatrixMediaSizeLimitError } from "./http-client-DOmFvKvB.js";
14
+ import { n as prepareMatrixReplyPayload, r as resolveMatrixExtraContent } from "./outbound-Co_tJyE6.js";
15
+ import { t as resolveMatrixTargets } from "./resolve-targets-B64O69Nd.js";
16
+ import { t as formatMatrixEncryptedEventDisabledWarning } from "./encryption-guidance-BNcZNQZI.js";
17
+ import { createMatrixInboundEventDeduper } from "./inbound-dedupe-Ch33GU06.js";
17
18
  import { a as isMatrixAccessTokenInvalidatedError, d as isMatrixDisconnectedSyncState, f as isMatrixReadySyncState, p as isMatrixTerminalSyncState } from "./client-support-DLj4vDeu.js";
18
- import { n as setBoundedMap, t as createMatrixRoomInfoResolver } from "./room-info-BXQA7y10.js";
19
+ import { i as setBoundedMap, r as getMatrixRoomInfo, t as createMatrixRoomInfoResolver } from "./room-info-6viLR3NH.js";
19
20
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
20
- import { buildChannelProgressDraftLineForEntry, createChannelProgressDraftCompositor, createMessageReceiptFromOutboundResults, createPreviewMessageReceipt, defineFinalizableLivePreviewAdapter, deliverWithFinalizableLivePreviewAdapter, formatChannelProgressDraftLine, formatChannelProgressDraftText, listMessageReceiptPlatformIds, resolveChannelStreamingBlockEnabled, waitUntilAbort } from "openclaw/plugin-sdk/channel-outbound";
21
+ import { createChannelProgressDraftCompositor, createMessageReceiptFromOutboundResults, createPreviewMessageReceipt, defineFinalizableLivePreviewAdapter, deliverWithFinalizableLivePreviewAdapter, formatChannelProgressDraftText, listMessageReceiptPlatformIds, resolveChannelStreamingBlockEnabled, waitUntilAbort } from "openclaw/plugin-sdk/channel-outbound";
21
22
  import { normalizeLowercaseStringOrEmpty, normalizeNullableString, normalizeOptionalString, normalizeStringifiedEntries, readStringValue, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
22
23
  import { stripReasoningTagsFromText } from "openclaw/plugin-sdk/text-chunking";
23
24
  import { CHANNEL_APPROVAL_NATIVE_RUNTIME_CONTEXT_CAPABILITY } from "openclaw/plugin-sdk/approval-handler-adapter-runtime";
24
- import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
25
+ import { extractErrorCode, formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
25
26
  import { isFutureDateTimestampMs, parseStrictFiniteNumber, resolveExpiresAtMsFromDurationMs, resolveOptionalIntegerOption } from "openclaw/plugin-sdk/number-runtime";
26
- import { resolveInboundLastRouteSessionKey } from "openclaw/plugin-sdk/routing";
27
+ import { resolveAgentRoute, resolveInboundLastRouteSessionKey } from "openclaw/plugin-sdk/routing";
27
28
  import { createChannelInboundEnvelopeBuilder, createChannelPartialDeliveryError, hasFinalInboundReplyDispatch, isChannelPartialDeliveryError, resolveInboundMentionDecision, resolveInboundReplyDispatchCounts, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
28
29
  import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
29
30
  import { KeyedAsyncQueue } from "openclaw/plugin-sdk/keyed-async-queue";
@@ -35,6 +36,7 @@ import { registerChannelRuntimeContext } from "openclaw/plugin-sdk/channel-runti
35
36
  import { GROUP_POLICY_BLOCKED_LABEL, resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
36
37
  import { resolveThreadBindingIdleTimeoutMsForChannel, resolveThreadBindingMaxAgeMsForChannel } from "openclaw/plugin-sdk/thread-bindings-runtime";
37
38
  import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
39
+ import { reportChannelRoomJoin } from "openclaw/plugin-sdk/channel-join-intro-runtime";
38
40
  import { createChannelIngressResolver, defineStableChannelIngressIdentity } from "openclaw/plugin-sdk/channel-ingress-runtime";
39
41
  import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
40
42
  import { evaluateSupplementalContextVisibility, resolveChannelContextVisibilityMode } from "openclaw/plugin-sdk/context-visibility-runtime";
@@ -326,15 +328,16 @@ async function resolveMatrixMonitorLiveUserAllowlist(params) {
326
328
  });
327
329
  }
328
330
  if (pending.length === 0) return effective;
331
+ const resolution = await resolveMatrixMonitorUserEntries({
332
+ cfg: params.cfg,
333
+ accountId: params.accountId,
334
+ entries: pending,
335
+ runtime: params.runtime,
336
+ resolveTargets: params.resolveTargets ?? resolveMatrixTargets
337
+ });
329
338
  const canonicalized = canonicalizeAllowlistWithResolvedIds({
330
339
  existing: pending,
331
- resolvedMap: (await resolveMatrixMonitorUserEntries({
332
- cfg: params.cfg,
333
- accountId: params.accountId,
334
- entries: pending,
335
- runtime: params.runtime,
336
- resolveTargets: params.resolveTargets ?? resolveMatrixTargets
337
- })).resolvedMap,
340
+ resolvedMap: resolution.resolvedMap,
338
341
  entryKey: normalizeMatrixUserId
339
342
  });
340
343
  const resolvedEntries = params.failClosedOnUnresolved ? filterFailClosedMatrixAllowlistEntries(canonicalized) : filterResolvedMatrixAllowlistEntries(canonicalized);
@@ -604,7 +607,7 @@ function createDirectRoomTracker(client, opts = {}) {
604
607
  return false;
605
608
  }
606
609
  const selfUserId = params.selfUserId ?? await ensureSelfUserId();
607
- const joinedMembers = await resolveJoinedMembers(roomId);
610
+ const joinedMembers = params.joinedMembers ?? await resolveJoinedMembers(roomId);
608
611
  const strictDirectMembership = isStrictDirectMembership({
609
612
  selfUserId,
610
613
  remoteUserId: senderId,
@@ -820,7 +823,7 @@ const matrixVerificationConstants = {
820
823
  const MAX_TRACKED_VERIFICATION_EVENTS = 1024;
821
824
  const SAS_NOTICE_RETRY_DELAY_MS = 750;
822
825
  const VERIFICATION_EVENT_STARTUP_GRACE_MS = 3e4;
823
- const loadMatrixDirectRoomDeps = createLazyRuntimeModule(() => Promise.all([import("./send-BKu9Ghi4.js").then((n) => n.S), import("./direct-room-RinHjtqX.js").then((n) => n.t)]).then(([directManagementModule, directRoomModule]) => ({
826
+ const loadMatrixDirectRoomDeps = createLazyRuntimeModule(() => Promise.all([import("./send-B5XChnvB.js").then((n) => n.x), import("./direct-room-RinHjtqX.js").then((n) => n.t)]).then(([directManagementModule, directRoomModule]) => ({
824
827
  inspectMatrixDirectRooms: directManagementModule.inspectMatrixDirectRooms,
825
828
  isStrictDirectRoom: directRoomModule.isStrictDirectRoom
826
829
  })));
@@ -930,10 +933,11 @@ async function resolveVerificationSummaryForSignal(client, params) {
930
933
  const byTransactionId = list.find((entry) => candidates.some((candidate) => entry.transactionId === candidate));
931
934
  if (byTransactionId) return byTransactionId;
932
935
  const { inspectMatrixDirectRooms, isStrictDirectRoom } = await loadMatrixDirectRoomDeps();
933
- const activeRoomId = normalizeNullableString((await inspectMatrixDirectRooms({
936
+ const inspection = await inspectMatrixDirectRooms({
934
937
  client,
935
938
  remoteUserId: params.senderId
936
- }).catch(() => null))?.activeRoomId);
939
+ }).catch(() => null);
940
+ const activeRoomId = normalizeNullableString(inspection?.activeRoomId);
937
941
  if (activeRoomId) {
938
942
  if (activeRoomId !== params.roomId) return null;
939
943
  } else if (!await isStrictDirectRoom({
@@ -1013,10 +1017,11 @@ function createMatrixVerificationEventRouter(params) {
1013
1017
  const verificationUserRooms = /* @__PURE__ */ new Map();
1014
1018
  async function resolveActiveDirectRoomId(remoteUserId) {
1015
1019
  const { inspectMatrixDirectRooms } = await loadMatrixDirectRoomDeps();
1016
- return normalizeNullableString((await inspectMatrixDirectRooms({
1020
+ const inspection = await inspectMatrixDirectRooms({
1017
1021
  client: params.client,
1018
1022
  remoteUserId
1019
- }).catch(() => null))?.activeRoomId);
1023
+ }).catch(() => null);
1024
+ return normalizeNullableString(inspection?.activeRoomId);
1020
1025
  }
1021
1026
  function shouldEmitVerificationEventNotice(event) {
1022
1027
  const eventTs = typeof event.origin_server_ts === "number" && Number.isFinite(event.origin_server_ts) ? event.origin_server_ts : null;
@@ -1169,7 +1174,7 @@ function createMatrixVerificationEventRouter(params) {
1169
1174
  }
1170
1175
  //#endregion
1171
1176
  //#region extensions/matrix/src/matrix/monitor/events.ts
1172
- const MATRIX_POST_HEALTHY_SYNC_DECRYPT_FAILURE_WINDOW_MS = 2 * 6e4;
1177
+ const MATRIX_POST_HEALTHY_SYNC_DECRYPT_FAILURE_WINDOW_MS = 12e4;
1173
1178
  const MATRIX_POST_HEALTHY_SYNC_DECRYPT_FAILURE_THRESHOLD = 3;
1174
1179
  const MATRIX_POST_HEALTHY_SYNC_DECRYPT_FAILURE_SAMPLE_LIMIT = 3;
1175
1180
  function formatMatrixPostHealthySyncDecryptionHint(accountId) {
@@ -1357,6 +1362,67 @@ function registerMatrixMonitorEvents(params) {
1357
1362
  directTracker?.invalidateRoom(roomId);
1358
1363
  const eventId = event?.event_id ?? "unknown";
1359
1364
  logVerboseMessage(`matrix: join room=${roomId} id=${eventId}`);
1365
+ if (event.membershipProvenance !== "transition" || event.state_key !== auth.userId) return;
1366
+ runMonitorTask(`join introduction room=${roomId}`, async () => {
1367
+ const members = await readJoinedMatrixMembers(client, roomId);
1368
+ const remoteUserId = members?.find((member) => member !== auth.userId);
1369
+ if (!members?.includes(auth.userId) || !remoteUserId || await directTracker.isDirectMessage({
1370
+ roomId,
1371
+ senderId: remoteUserId,
1372
+ selfUserId: auth.userId,
1373
+ joinedMembers: members
1374
+ })) return;
1375
+ const roomInfo = await params.getRoomInfo(roomId, { includeAliases: params.needsRoomAliasesForConfig });
1376
+ const roomConfig = resolveMatrixRoomConfig({
1377
+ rooms: params.roomsConfig,
1378
+ roomId,
1379
+ aliases: [roomInfo.canonicalAlias ?? "", ...roomInfo.altAliases].filter(Boolean)
1380
+ });
1381
+ const roomAllowed = (!params.needsRoomAliasesForConfig || roomInfo.aliasesResolved) && params.groupPolicy !== "disabled" && (roomConfig.config ? roomConfig.allowed : params.groupPolicy === "open");
1382
+ const options = {
1383
+ cfg,
1384
+ accountId: auth.accountId,
1385
+ client
1386
+ };
1387
+ await reportChannelRoomJoin({
1388
+ cfg,
1389
+ channel: "matrix",
1390
+ accountId: auth.accountId,
1391
+ conversationId: roomId,
1392
+ deliverTo: `room:${roomId}`,
1393
+ route: resolveMatrixInboundRoute({
1394
+ cfg,
1395
+ accountId: auth.accountId,
1396
+ roomId,
1397
+ senderId: auth.userId,
1398
+ isDirectMessage: false,
1399
+ resolveAgentRoute
1400
+ }).route,
1401
+ roomAllowed,
1402
+ resolveRoomContext: async ({ messageLimit }) => {
1403
+ const info = await getMatrixRoomInfo(roomId, options);
1404
+ const context = {
1405
+ title: info.name ?? void 0,
1406
+ purpose: info.topic ?? void 0
1407
+ };
1408
+ try {
1409
+ const { messages } = await readMatrixMessages(roomId, {
1410
+ ...options,
1411
+ limit: messageLimit
1412
+ });
1413
+ return {
1414
+ ...context,
1415
+ recentMessages: messages.toReversed().flatMap(({ sender, body }) => body?.trim() ? [{
1416
+ sender,
1417
+ text: body
1418
+ }] : [])
1419
+ };
1420
+ } catch {
1421
+ return context;
1422
+ }
1423
+ }
1424
+ });
1425
+ });
1360
1426
  };
1361
1427
  const onRoomEvent = (roomId, event) => {
1362
1428
  const eventType = event?.type ?? "unknown";
@@ -1518,11 +1584,7 @@ function resolveMatrixSharedDmContextNotice(params) {
1518
1584
  if (currentSession.accountId && currentSession.accountId !== params.accountId) return null;
1519
1585
  if (!currentSession.directUserId) return null;
1520
1586
  if (!currentSession.roomId || currentSession.roomId === params.roomId) return null;
1521
- return [
1522
- "This Matrix DM is sharing a session with another Matrix DM room.",
1523
- "Use /focus here for a one-off isolated thread session when thread bindings are enabled, or set",
1524
- "channels.matrix.dm.sessionScope to per-room to isolate each Matrix DM room."
1525
- ].join(" ");
1587
+ return ["This Matrix DM is sharing a session with another Matrix DM room.", "Set channels.matrix.dm.sessionScope to per-room to isolate each Matrix DM room."].join(" ");
1526
1588
  } catch (err) {
1527
1589
  params.logVerboseMessage(`matrix: failed checking shared DM session notice room=${params.roomId} (${String(err)})`);
1528
1590
  return null;
@@ -1530,10 +1592,13 @@ function resolveMatrixSharedDmContextNotice(params) {
1530
1592
  }
1531
1593
  function resolveMatrixPendingHistoryText(params) {
1532
1594
  if (!params.mediaUrl) return params.mentionPrecheckText;
1595
+ const body = typeof params.content.body === "string" ? params.content.body : void 0;
1596
+ const filename = typeof params.content.filename === "string" ? params.content.filename : void 0;
1597
+ const msgtype = typeof params.content.msgtype === "string" ? params.content.msgtype : void 0;
1533
1598
  return formatMatrixMessageText({
1534
- body: typeof params.content.body === "string" ? params.content.body : void 0,
1535
- filename: typeof params.content.filename === "string" ? params.content.filename : void 0,
1536
- msgtype: typeof params.content.msgtype === "string" ? params.content.msgtype : void 0
1599
+ body,
1600
+ filename,
1601
+ msgtype
1537
1602
  }) ?? params.mentionPrecheckText;
1538
1603
  }
1539
1604
  function resolveMatrixInboundMediaContent(content) {
@@ -1566,7 +1631,7 @@ function resolveMatrixAllowBotsMode(value) {
1566
1631
  return "off";
1567
1632
  }
1568
1633
  function formatMatrixToolProgressMarkdownCode(text) {
1569
- return `\`${(text.length <= MATRIX_TOOL_PROGRESS_MAX_CHARS ? text : `${truncateUtf16Safe(text, MATRIX_TOOL_PROGRESS_MAX_CHARS - 1).trimEnd()}...`).replaceAll("`", "'")}\``;
1634
+ return `\`${(text.length <= MATRIX_TOOL_PROGRESS_MAX_CHARS ? text : `${truncateUtf16Safe(text, 299).trimEnd()}...`).replaceAll("`", "'")}\``;
1570
1635
  }
1571
1636
  //#endregion
1572
1637
  //#region extensions/matrix/src/matrix/monitor/handler-runtime.ts
@@ -1576,11 +1641,11 @@ async function redactMatrixDraftEvent(client, roomId, draftEventId) {
1576
1641
  function buildMatrixFinalizedPreviewContent() {
1577
1642
  return { [MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY]: true };
1578
1643
  }
1579
- const loadMatrixSendModule = createLazyRuntimeModule(() => import("./send-BKu9Ghi4.js").then((n) => n.s));
1644
+ const loadMatrixSendModule = createLazyRuntimeModule(() => import("./send-B5XChnvB.js").then((n) => n.s));
1580
1645
  const loadAcpBindingRuntime = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/acp-binding-runtime"));
1581
1646
  const loadSessionBindingRuntime = createLazyRuntimeModule(() => import("openclaw/plugin-sdk/session-binding-runtime"));
1582
- const loadMatrixReactionEvents = createLazyRuntimeModule(() => import("./reaction-events-BZUgLIZI.js"));
1583
- const loadMatrixDraftStream = createLazyRuntimeModule(() => import("./draft-stream-B_m79Ynb.js"));
1647
+ const loadMatrixReactionEvents = createLazyRuntimeModule(() => import("./reaction-events-C_7G7bvI.js"));
1648
+ const loadMatrixDraftStream = createLazyRuntimeModule(() => import("./draft-stream-DglwxWzJ.js"));
1584
1649
  async function matrixTextWouldActivateMentions(client, text) {
1585
1650
  const { resolveMatrixMentionsForBody } = await loadMatrixSendModule();
1586
1651
  const mentions = await resolveMatrixMentionsForBody({
@@ -1609,7 +1674,7 @@ const MAX_CACHED_REPLY_CONTEXTS = 256;
1609
1674
  const MAX_REPLY_BODY_LENGTH = 500;
1610
1675
  function truncateReplyBody(value) {
1611
1676
  if (value.length <= MAX_REPLY_BODY_LENGTH) return value;
1612
- return `${sliceUtf16Safe(value, 0, MAX_REPLY_BODY_LENGTH - 3)}...`;
1677
+ return `${sliceUtf16Safe(value, 0, 497)}...`;
1613
1678
  }
1614
1679
  function summarizeMatrixReplyEvent(event) {
1615
1680
  const body = summarizeMatrixMessageContextEvent(event);
@@ -1662,7 +1727,7 @@ const MAX_TRACKED_THREAD_STARTERS = 256;
1662
1727
  const MAX_THREAD_STARTER_BODY_LENGTH = 500;
1663
1728
  function truncateThreadStarterBody(value) {
1664
1729
  if (value.length <= MAX_THREAD_STARTER_BODY_LENGTH) return value;
1665
- return `${sliceUtf16Safe(value, 0, MAX_THREAD_STARTER_BODY_LENGTH - 3)}...`;
1730
+ return `${sliceUtf16Safe(value, 0, 497)}...`;
1666
1731
  }
1667
1732
  function summarizeMatrixThreadStarterEvent(event) {
1668
1733
  const body = summarizeMatrixMessageContextEvent(event);
@@ -1847,7 +1912,8 @@ async function resolveMatrixInboundContext(config) {
1847
1912
  agentId: _route.agentId,
1848
1913
  dmScope: _route.dmScope,
1849
1914
  accountId: _route.accountId,
1850
- routeSessionKey: _route.sessionKey
1915
+ routeSessionKey: _route.sessionKey,
1916
+ parentSessionKey: threadTarget && _route.matchedBy !== "binding.channel" ? _route.mainSessionKey : void 0
1851
1917
  },
1852
1918
  reply: {
1853
1919
  to: `room:${roomId}`,
@@ -1935,8 +2001,7 @@ async function createMatrixDraftController(params) {
1935
2001
  accountId,
1936
2002
  log: logVerboseMessage
1937
2003
  })) : void 0;
1938
- const shouldStreamPreviewToolProgress = Boolean(draftStream) && previewToolProgressEnabled;
1939
- const shouldSuppressDefaultToolProgressMessages = Boolean(draftStream) && (shouldStreamPreviewToolProgress || params.streaming === "progress");
2004
+ const shouldSuppressDefaultToolProgressMessages = Boolean(draftStream) && (Boolean(draftStream) && previewToolProgressEnabled || params.streaming === "progress");
1940
2005
  let currentDraftMessageGeneration = 0;
1941
2006
  let currentDraftBlockOffset = 0;
1942
2007
  let latestDraftFullText = "";
@@ -1963,7 +2028,6 @@ async function createMatrixDraftController(params) {
1963
2028
  active: Boolean(draftStream),
1964
2029
  seed: progressSeed,
1965
2030
  formatLine: formatMatrixToolProgressMarkdownCode,
1966
- buildProgressEventLine: (input, options) => input.event === "approval" ? formatChannelProgressDraftLine(input, options) : buildChannelProgressDraftLineForEntry(progressConfigEntry, input, options),
1967
2031
  update: async (text, options) => {
1968
2032
  const previewText = !progressDraftStreaming && (previewPlan || previewPlanExplanation) ? renderPreviewPlan() : text.replace(/^• /gmu, "- ");
1969
2033
  if (!draftStream) return false;
@@ -1980,10 +2044,8 @@ async function createMatrixDraftController(params) {
1980
2044
  };
1981
2045
  const buildPreviewToolProgressReplyOptions = () => {
1982
2046
  if (!shouldSuppressDefaultToolProgressMessages) return {};
1983
- const options = { suppressDefaultToolProgressMessages: true };
1984
- if (!shouldStreamPreviewToolProgress) return options;
1985
2047
  return {
1986
- ...options,
2048
+ suppressDefaultToolProgressMessages: true,
1987
2049
  onToolStart: async (payload) => {
1988
2050
  return await progressDraft.pushToolEvent(payload);
1989
2051
  },
@@ -2428,7 +2490,7 @@ async function resolveMatrixIngressAccess(config) {
2428
2490
  };
2429
2491
  const storeAllowFrom = isDirectMessage && dmPolicy !== "allowlist" && dmPolicy !== "open" ? await readStoreAllowFrom() : [];
2430
2492
  const roomUsers = roomConfig?.users ?? [];
2431
- const { liveDmAllowFrom, liveGroupAllowFrom } = await resolveLiveAccountAllowlists();
2493
+ const { liveCfg, liveDmAllowFrom, liveGroupAllowFrom } = await resolveLiveAccountAllowlists();
2432
2494
  const accessState = await resolveMatrixMonitorAccessState({
2433
2495
  allowFrom: liveDmAllowFrom,
2434
2496
  storeAllowFrom,
@@ -2517,6 +2579,8 @@ async function resolveMatrixIngressAccess(config) {
2517
2579
  return;
2518
2580
  }
2519
2581
  return {
2582
+ cfg: liveCfg,
2583
+ liveDmAllowFrom,
2520
2584
  content,
2521
2585
  messageId,
2522
2586
  audioPreflightMode,
@@ -2731,8 +2795,8 @@ function resolveMentions(params) {
2731
2795
  //#region extensions/matrix/src/matrix/monitor/handler-ingress-content.ts
2732
2796
  async function resolveMatrixIngressContent(config) {
2733
2797
  const { handler, params: paramsLocal, access, roomId, event, eventType, isPollEvent, eventTs, senderId, roomHistoryTracker, commitInboundEventIfClaimed } = config;
2734
- const { client, core, cfg, accountId, accountConfig, logger, logVerboseMessage, historyLimit, mediaMaxBytes, dmSessionScope, getMemberDisplayName } = handler;
2735
- const { content: accessContent, messageId, audioPreflightMode, isDirectMessage, isRoom, locationPayload, reservedHistorySlot, threadRootId, thread, historyThreadId, discardReservedHistorySlot, markReservedHistorySlotConsumed, commitInboundEventIfClaimedAndDiscardReserved, roomConfig, allowBotsMode, isConfiguredBotSender, selfUserId, botLoopProtection, roomMatchMeta, getSenderName, accessState, effectiveGroupAllowFrom, effectiveRoomUsers } = access;
2798
+ const { client, core, accountId, accountConfig, logger, logVerboseMessage, historyLimit, mediaMaxBytes, dmSessionScope, getMemberDisplayName } = handler;
2799
+ const { cfg, liveDmAllowFrom, content: accessContent, messageId, audioPreflightMode, isDirectMessage, isRoom, locationPayload, reservedHistorySlot, threadRootId, thread, historyThreadId, discardReservedHistorySlot, markReservedHistorySlotConsumed, commitInboundEventIfClaimedAndDiscardReserved, roomConfig, allowBotsMode, isConfiguredBotSender, selfUserId, botLoopProtection, roomMatchMeta, getSenderName, accessState, effectiveGroupAllowFrom, effectiveRoomUsers } = access;
2736
2800
  const { messageIngress, resolveMessageIngress } = accessState;
2737
2801
  let content = accessContent;
2738
2802
  let pollSnapshotPromise = null;
@@ -2773,7 +2837,6 @@ async function resolveMatrixIngressContent(config) {
2773
2837
  isDirectMessage,
2774
2838
  dmSessionScope,
2775
2839
  threadId: thread.threadId,
2776
- eventTs: eventTs ?? void 0,
2777
2840
  resolveAgentRoute: core.channel.routing.resolveAgentRoute
2778
2841
  });
2779
2842
  const hasExplicitSessionBinding = _configuredBinding !== null || _runtimeBindingId !== null;
@@ -2999,7 +3062,10 @@ async function resolveMatrixIngressContent(config) {
2999
3062
  }
3000
3063
  if (_runtimeBindingId) {
3001
3064
  const { getSessionBindingService } = await loadSessionBindingRuntime();
3002
- getSessionBindingService().touch(_runtimeBindingId, eventTs ?? void 0);
3065
+ getSessionBindingService().touch(_runtimeBindingId, eventTs ?? void 0, {
3066
+ channel: "matrix",
3067
+ accountId
3068
+ });
3003
3069
  }
3004
3070
  const preparedTrigger = isRoom && historyLimit > 0 ? reservedHistorySlot ? roomHistoryTracker.prepareReservedTrigger(_route.agentId, roomId, historyLimit, reservedHistorySlot, {
3005
3071
  sender: senderName,
@@ -3014,6 +3080,8 @@ async function resolveMatrixIngressContent(config) {
3014
3080
  }, historyThreadId) : void 0;
3015
3081
  if (reservedHistorySlot && preparedTrigger) markReservedHistorySlotConsumed();
3016
3082
  return {
3083
+ cfg,
3084
+ liveDmAllowFrom,
3017
3085
  messageIngress,
3018
3086
  resolveMessageIngress,
3019
3087
  route: _route,
@@ -3213,11 +3281,6 @@ function resolveVisibleMatrixReplyText(text) {
3213
3281
  }
3214
3282
  async function deliverMatrixReplies(params) {
3215
3283
  const core = getMatrixRuntime();
3216
- const tableMode = params.tableMode ?? core.channel.text.resolveMarkdownTableMode({
3217
- cfg: params.cfg,
3218
- channel: "matrix",
3219
- accountId: params.accountId
3220
- });
3221
3284
  const logVerbose = (message) => {
3222
3285
  if (core.logging.shouldLogVerbose()) params.runtime.log?.(message);
3223
3286
  };
@@ -3246,24 +3309,17 @@ async function deliverMatrixReplies(params) {
3246
3309
  acceptedResults.push(result);
3247
3310
  if (replyToIdForReply) hasRepliedRef.value = true;
3248
3311
  };
3312
+ const extraContent = resolveMatrixExtraContent(reply);
3249
3313
  if (mediaUrls.length === 0) {
3250
- const { chunks } = chunkMatrixText(rawText, {
3314
+ await sendMessageMatrix(params.roomId, rawText, {
3315
+ client: params.client,
3251
3316
  cfg: params.cfg,
3317
+ replyToId: replyToIdForReply,
3318
+ threadId: params.threadId,
3252
3319
  accountId: params.accountId,
3253
- tableMode,
3254
- preserveWhitespace: true
3320
+ extraContent,
3321
+ onDeliveryResult
3255
3322
  });
3256
- for (const chunk of chunks) {
3257
- if (!chunk.trim()) continue;
3258
- await sendMessageMatrix(params.roomId, chunk, {
3259
- client: params.client,
3260
- cfg: params.cfg,
3261
- replyToId: replyToIdForReply,
3262
- threadId: params.threadId,
3263
- accountId: params.accountId,
3264
- onDeliveryResult
3265
- });
3266
- }
3267
3323
  continue;
3268
3324
  }
3269
3325
  let first = true;
@@ -3278,6 +3334,7 @@ async function deliverMatrixReplies(params) {
3278
3334
  threadId: params.threadId,
3279
3335
  audioAsVoice: reply.audioAsVoice,
3280
3336
  accountId: params.accountId,
3337
+ extraContent: first ? extraContent : void 0,
3281
3338
  onDeliveryResult
3282
3339
  });
3283
3340
  first = false;
@@ -3291,7 +3348,7 @@ async function deliverMatrixReplies(params) {
3291
3348
  //#endregion
3292
3349
  //#region extensions/matrix/src/matrix/monitor/handler-reply-dispatcher.ts
3293
3350
  function createMatrixReplyDispatcher(config) {
3294
- const { cfg, prefixOptions, humanDelay, typingCallbacks, streaming, draftStream, draftController, client, roomId, runtime, textLimit, replyToMode, threadTarget, replyToEventId, accountId, mediaLocalRoots, tableMode, logVerboseMessage } = config;
3351
+ const { cfg, prefixOptions, humanDelay, typingCallbacks, streaming, draftStream, draftController, client, roomId, runtime, replyToMode, threadTarget, replyToEventId, accountId, mediaLocalRoots, logVerboseMessage } = config;
3295
3352
  const quietDraftStreaming = streaming === "quiet" || streaming === "progress";
3296
3353
  const hasRepliedRef = { value: false };
3297
3354
  let finalReplyDeliveryFailed = false;
@@ -3363,14 +3420,12 @@ function createMatrixReplyDispatcher(config) {
3363
3420
  roomId,
3364
3421
  client,
3365
3422
  runtime,
3366
- textLimit,
3367
3423
  replyToMode,
3368
3424
  hasRepliedRef,
3369
3425
  threadId: threadTarget,
3370
3426
  replyToId: threadTarget ?? replyToEventId ?? void 0,
3371
3427
  accountId,
3372
- mediaLocalRoots,
3373
- tableMode
3428
+ mediaLocalRoots
3374
3429
  }));
3375
3430
  }
3376
3431
  const payloadReplyMismatch = !threadTarget && (replyToMode !== "off" || payload.replyToTag || payload.replyToCurrent) && normalizeOptionalString(payload.replyToId) !== draftController.currentReplyToId();
@@ -3401,11 +3456,18 @@ function createMatrixReplyDispatcher(config) {
3401
3456
  discardPending: async () => {},
3402
3457
  id: () => draftEventId
3403
3458
  },
3404
- buildFinalEdit: () => ({
3405
- text: finalPreviewText,
3406
- finalizeLive: !(quietDraftStreaming || !draftStream.matchesPreparedText(finalPreviewText)),
3407
- ...quietDraftStreaming ? { extraContent: buildMatrixFinalizedPreviewContent() } : {}
3408
- }),
3459
+ buildFinalEdit: () => {
3460
+ const presentationContent = resolveMatrixExtraContent(payload);
3461
+ const extraContent = {
3462
+ ...quietDraftStreaming ? buildMatrixFinalizedPreviewContent() : {},
3463
+ ...presentationContent
3464
+ };
3465
+ return {
3466
+ text: finalPreviewText,
3467
+ finalizeLive: !(quietDraftStreaming || Boolean(presentationContent) || !draftStream.matchesPreparedText(finalPreviewText)),
3468
+ ...Object.keys(extraContent).length > 0 ? { extraContent } : {}
3469
+ };
3470
+ },
3409
3471
  editFinal: async (_draftEventId, edit) => {
3410
3472
  if (edit.finalizeLive) {
3411
3473
  if (!await draftStream.finalizeLive()) throw new Error("Matrix draft live finalize failed");
@@ -3441,14 +3503,12 @@ function createMatrixReplyDispatcher(config) {
3441
3503
  roomId,
3442
3504
  client,
3443
3505
  runtime,
3444
- textLimit,
3445
3506
  replyToMode,
3446
3507
  hasRepliedRef,
3447
3508
  threadId: threadTarget,
3448
3509
  replyToId: threadTarget ?? replyToEventId ?? void 0,
3449
3510
  accountId,
3450
- mediaLocalRoots,
3451
- tableMode
3511
+ mediaLocalRoots
3452
3512
  })
3453
3513
  });
3454
3514
  return fallbackResult.visibleReplySent;
@@ -3504,14 +3564,12 @@ function createMatrixReplyDispatcher(config) {
3504
3564
  roomId,
3505
3565
  client,
3506
3566
  runtime,
3507
- textLimit,
3508
3567
  replyToMode,
3509
3568
  hasRepliedRef,
3510
3569
  threadId: threadTarget,
3511
3570
  replyToId: threadTarget ?? replyToEventId ?? void 0,
3512
3571
  accountId,
3513
- mediaLocalRoots,
3514
- tableMode
3572
+ mediaLocalRoots
3515
3573
  });
3516
3574
  if (reusesDraftAsFinalText) {
3517
3575
  draftController.markDraftConsumed();
@@ -3537,14 +3595,12 @@ function createMatrixReplyDispatcher(config) {
3537
3595
  roomId,
3538
3596
  client,
3539
3597
  runtime,
3540
- textLimit,
3541
3598
  replyToMode,
3542
3599
  hasRepliedRef,
3543
3600
  threadId: threadTarget,
3544
3601
  replyToId: threadTarget ?? replyToEventId ?? void 0,
3545
3602
  accountId,
3546
- mediaLocalRoots,
3547
- tableMode
3603
+ mediaLocalRoots
3548
3604
  });
3549
3605
  const draftContent = draftStream.content();
3550
3606
  if (shouldRedactDraft && draftEventId && draftContent) return await completeDelivery(await settleDraftReplacement({
@@ -3560,14 +3616,12 @@ function createMatrixReplyDispatcher(config) {
3560
3616
  roomId,
3561
3617
  client,
3562
3618
  runtime,
3563
- textLimit,
3564
3619
  replyToMode,
3565
3620
  hasRepliedRef,
3566
3621
  threadId: threadTarget,
3567
3622
  replyToId: threadTarget ?? replyToEventId ?? void 0,
3568
3623
  accountId,
3569
- mediaLocalRoots,
3570
- tableMode
3624
+ mediaLocalRoots
3571
3625
  }));
3572
3626
  },
3573
3627
  onError: (err, info) => {
@@ -3590,7 +3644,7 @@ function createMatrixReplyDispatcher(config) {
3590
3644
  //#endregion
3591
3645
  //#region extensions/matrix/src/matrix/monitor/handler-state.ts
3592
3646
  const ALLOW_FROM_STORE_CACHE_TTL_MS = 3e4;
3593
- const PAIRING_REPLY_COOLDOWN_MS = 5 * 6e4;
3647
+ const PAIRING_REPLY_COOLDOWN_MS = 3e5;
3594
3648
  const MAX_TRACKED_PAIRING_REPLY_SENDERS = 512;
3595
3649
  function createMatrixHandlerState(config) {
3596
3650
  const { core, accountId, runtime, allowFromResolvedEntries, groupAllowFromResolvedEntries, resolveLiveUserAllowlist } = config;
@@ -3692,8 +3746,10 @@ function createMatrixHandlerState(config) {
3692
3746
  }
3693
3747
  //#endregion
3694
3748
  //#region extensions/matrix/src/matrix/monitor/handler.ts
3749
+ const SESSION_RESTART_RECOVERY_TOMBSTONE_ERROR_CODE = "SESSION_RESTART_RECOVERY_TOMBSTONE";
3750
+ const RESTART_RECOVERY_TOMBSTONE_NOTICE = "This session ended during gateway restart recovery and cannot accept more messages. Send /new or /reset to start a replacement session.";
3695
3751
  function createMatrixRoomMessageHandler(params) {
3696
- const { client, core, cfg, accountId, runtime, logger, logVerboseMessage, allowFromResolvedEntries = [], groupAllowFromResolvedEntries = [], configuredBotUserIds = /* @__PURE__ */ new Set(), groupPolicy, replyToMode, dmSessionScope, streaming, previewToolProgressEnabled, blockStreamingEnabled, textLimit, historyLimit, startupMs, startupGraceMs, dropPreStartupMessages, inboundDeduper, directTracker, getRoomInfo, getMemberDisplayName, resolveLiveUserAllowlist = resolveMatrixMonitorLiveUserAllowlist, resolveStorePath: resolveStorePathImpl = resolveStorePath, createChannelInboundEnvelopeBuilder: createChannelInboundEnvelopeBuilderImpl = createChannelInboundEnvelopeBuilder, finalizeInboundContext, resolveHumanDelayConfig: resolveHumanDelayConfigImpl = resolveHumanDelayConfig } = params;
3752
+ const { client, core, cfg: startupConfig, accountId, runtime, logger, logVerboseMessage, allowFromResolvedEntries = [], groupAllowFromResolvedEntries = [], configuredBotUserIds = /* @__PURE__ */ new Set(), groupPolicy, replyToMode, dmSessionScope, streaming, previewToolProgressEnabled, blockStreamingEnabled, historyLimit, startupMs, startupGraceMs, dropPreStartupMessages, inboundDeduper, directTracker, getRoomInfo, getMemberDisplayName, resolveLiveUserAllowlist = resolveMatrixMonitorLiveUserAllowlist, resolveStorePath: resolveStorePathImpl = resolveStorePath, createChannelInboundEnvelopeBuilder: createChannelInboundEnvelopeBuilderImpl = createChannelInboundEnvelopeBuilder, finalizeInboundContext, resolveHumanDelayConfig: resolveHumanDelayConfigImpl = resolveHumanDelayConfig } = params;
3697
3753
  const handlerConfig = {
3698
3754
  ...params,
3699
3755
  allowFromResolvedEntries,
@@ -3704,11 +3760,6 @@ function createMatrixRoomMessageHandler(params) {
3704
3760
  createChannelInboundEnvelopeBuilder: createChannelInboundEnvelopeBuilderImpl,
3705
3761
  resolveHumanDelayConfig: resolveHumanDelayConfigImpl
3706
3762
  };
3707
- const contextVisibilityMode = resolveChannelContextVisibilityMode({
3708
- cfg,
3709
- channel: "matrix",
3710
- accountId
3711
- });
3712
3763
  const handlerState = createMatrixHandlerState({
3713
3764
  core,
3714
3765
  accountId,
@@ -3814,7 +3865,7 @@ function createMatrixRoomMessageHandler(params) {
3814
3865
  ...prefix,
3815
3866
  audioPreflightMode: shouldDeferMatrixAudioPreflightForRoomIngress({
3816
3867
  content: prefix.content,
3817
- cfg
3868
+ cfg: startupConfig
3818
3869
  }) ? "defer" : "run"
3819
3870
  });
3820
3871
  return result && "deferredPrefix" in result ? { deferredPrefix: result.deferredPrefix } : { ingressResult: result };
@@ -3826,7 +3877,12 @@ function createMatrixRoomMessageHandler(params) {
3826
3877
  })();
3827
3878
  if (!resolvedIngressResult) return;
3828
3879
  if ("deferredPrefix" in resolvedIngressResult) return;
3829
- const { route: _route, hasExplicitSessionBinding, roomConfig, isDirectMessage, isRoom, shouldRequireMention, wasMentioned, effectiveWasMentioned, shouldBypassMention, canDetectMention, commandAuthorized, inboundHistory, senderName, bodyText, commandBodyText, media, preflightAudioTranscript, locationPayload, messageId, triggerSnapshot, threadRootId, thread, botLoopProtection, effectiveGroupAllowFrom, effectiveRoomUsers, resolveMessageIngress } = resolvedIngressResult;
3880
+ const { cfg, liveDmAllowFrom, route: _route, hasExplicitSessionBinding, roomConfig, isDirectMessage, isRoom, shouldRequireMention, wasMentioned, effectiveWasMentioned, shouldBypassMention, canDetectMention, commandAuthorized, inboundHistory, senderName, bodyText, commandBodyText, media, preflightAudioTranscript, locationPayload, messageId, triggerSnapshot, threadRootId, thread, botLoopProtection, effectiveGroupAllowFrom, effectiveRoomUsers, resolveMessageIngress } = resolvedIngressResult;
3881
+ const contextVisibilityMode = resolveChannelContextVisibilityMode({
3882
+ cfg,
3883
+ channel: "matrix",
3884
+ accountId
3885
+ });
3830
3886
  const inboundContext = await resolveMatrixInboundContext({
3831
3887
  resolveMessageIngress,
3832
3888
  client,
@@ -3876,11 +3932,6 @@ function createMatrixRoomMessageHandler(params) {
3876
3932
  });
3877
3933
  if (!inboundContext) return;
3878
3934
  const { replyToEventId, threadTarget, storePath, ctxPayload, replyTarget, sharedDmContextNotice } = inboundContext;
3879
- const tableMode = core.channel.text.resolveMarkdownTableMode({
3880
- cfg,
3881
- channel: "matrix",
3882
- accountId: _route.accountId
3883
- });
3884
3935
  const mediaLocalRoots = getAgentScopedMediaLocalRoots(cfg, _route.agentId);
3885
3936
  const { onModelSelected, ...prefixOptions } = createReplyPrefixOptions({
3886
3937
  cfg,
@@ -3944,24 +3995,19 @@ function createMatrixRoomMessageHandler(params) {
3944
3995
  client,
3945
3996
  roomId,
3946
3997
  runtime,
3947
- textLimit,
3948
3998
  replyToMode,
3949
3999
  threadTarget,
3950
4000
  replyToEventId: replyToEventId ?? void 0,
3951
4001
  accountId: _route.accountId,
3952
4002
  mediaLocalRoots,
3953
- tableMode,
3954
4003
  logVerboseMessage
3955
4004
  });
3956
4005
  const { deliverReply, onReplyError, turnDispatcherOptions } = replyDispatcher;
3957
- const pinnedMainDmOwner = isDirectMessage ? await (async () => {
3958
- const { liveCfg, liveDmAllowFrom } = await handlerState.resolveLiveAccountAllowlists();
3959
- return resolvePinnedMainDmOwnerFromAllowlist({
3960
- dmScope: liveCfg.session?.dmScope,
3961
- allowFrom: liveDmAllowFrom,
3962
- normalizeEntry: normalizeMatrixUserId
3963
- });
3964
- })() : null;
4006
+ const pinnedMainDmOwner = isDirectMessage ? resolvePinnedMainDmOwnerFromAllowlist({
4007
+ dmScope: cfg.session?.dmScope,
4008
+ allowFrom: liveDmAllowFrom,
4009
+ normalizeEntry: normalizeMatrixUserId
4010
+ }) : null;
3965
4011
  const inboundLastRouteSessionKey = resolveInboundLastRouteSessionKey({
3966
4012
  route: _route,
3967
4013
  sessionKey: _route.sessionKey
@@ -3982,7 +4028,7 @@ function createMatrixRoomMessageHandler(params) {
3982
4028
  replayClaimAtDispatch.release();
3983
4029
  }
3984
4030
  } : void 0;
3985
- const turnResult = await core.channel.inbound.run({
4031
+ const turnResultPromise = core.channel.inbound.run({
3986
4032
  channel: "matrix",
3987
4033
  accountId: _route.accountId,
3988
4034
  raw: event,
@@ -4039,6 +4085,7 @@ function createMatrixRoomMessageHandler(params) {
4039
4085
  },
4040
4086
  delivery: {
4041
4087
  observeMessageSent: true,
4088
+ preparePayload: prepareMatrixReplyPayload,
4042
4089
  deliver: deliverReply,
4043
4090
  onError: (err, info) => onReplyError(err, info)
4044
4091
  },
@@ -4067,6 +4114,30 @@ function createMatrixRoomMessageHandler(params) {
4067
4114
  })
4068
4115
  }
4069
4116
  });
4117
+ let turnResult;
4118
+ try {
4119
+ turnResult = await turnResultPromise;
4120
+ } catch (err) {
4121
+ if (extractErrorCode(err) !== SESSION_RESTART_RECOVERY_TOMBSTONE_ERROR_CODE) throw err;
4122
+ try {
4123
+ const { sendMessageMatrix } = await loadMatrixSendModule();
4124
+ await sendMessageMatrix(roomId, RESTART_RECOVERY_TOMBSTONE_NOTICE, {
4125
+ cfg,
4126
+ client,
4127
+ accountId: _route.accountId,
4128
+ replyToId: threadTarget ?? (replyToMode === "off" ? void 0 : messageId),
4129
+ threadId: threadTarget,
4130
+ deliveryQueueId: `matrix:restart-recovery-tombstone:${_route.accountId}:${roomId}:${eventId}`,
4131
+ deliveryPartIndex: 0,
4132
+ deliveryPartCount: 1,
4133
+ extraContent: { msgtype: "m.notice" }
4134
+ });
4135
+ await commitInboundEventIfClaimed();
4136
+ } catch (noticeError) {
4137
+ runtime.error?.(`matrix: failed completing restart-recovery tombstone notice room=${roomId} id=${eventId || "unknown"}: ${String(noticeError)}`);
4138
+ }
4139
+ return;
4140
+ }
4070
4141
  if (!turnResult.dispatched) {
4071
4142
  if (turnResult.admission.kind === "drop" && turnResult.admission.reason === "bot-loop-protection") await commitInboundEventIfClaimed();
4072
4143
  return;
@@ -4120,10 +4191,10 @@ function shouldPromoteRecentInviteRoom(params) {
4120
4191
  //#endregion
4121
4192
  //#region extensions/matrix/src/matrix/monitor/startup.ts
4122
4193
  const loadMatrixStartupMaintenanceDeps = createLazyRuntimeModule(() => Promise.all([
4123
- import("./config-update-Bor_Pjsv.js").then((n) => n.t),
4194
+ import("./config-update-BnX26jCO.js").then((n) => n.t),
4124
4195
  import("./device-health-B4-YXtJR.js").then((n) => n.t),
4125
- import("./profile-D-Wubo0A.js").then((n) => n.n),
4126
- import("./startup-verification-Cs08ca8u.js")
4196
+ import("./profile-vmjsmhh4.js").then((n) => n.n),
4197
+ import("./startup-verification-1Ney1mmI.js")
4127
4198
  ]).then(([configUpdateModule, deviceHealthModule, profileModule, startupVerificationModule]) => ({
4128
4199
  updateMatrixAccountConfig: configUpdateModule.updateMatrixAccountConfig,
4129
4200
  summarizeMatrixDeviceHealth: deviceHealthModule.summarizeMatrixDeviceHealth,
@@ -4345,35 +4416,6 @@ function createMatrixMonitorSyncLifecycle(params) {
4345
4416
  };
4346
4417
  }
4347
4418
  //#endregion
4348
- //#region extensions/matrix/src/matrix/monitor/task-runner.ts
4349
- function createMatrixMonitorTaskRunner(params) {
4350
- const inFlight = /* @__PURE__ */ new Set();
4351
- let closed = false;
4352
- const runDetachedTask = (label, task) => {
4353
- if (closed) return Promise.resolve();
4354
- const trackedTask = Promise.resolve().then(task).catch((error) => {
4355
- const message = String(error);
4356
- params.logVerboseMessage(`matrix: ${label} failed (${message})`);
4357
- params.logger.warn("matrix background task failed", {
4358
- task: label,
4359
- error: message
4360
- });
4361
- }).finally(() => {
4362
- inFlight.delete(trackedTask);
4363
- });
4364
- inFlight.add(trackedTask);
4365
- return trackedTask;
4366
- };
4367
- const waitForIdle = async () => {
4368
- while (inFlight.size > 0) await Promise.allSettled(Array.from(inFlight));
4369
- };
4370
- return {
4371
- close: () => closed = true,
4372
- runDetachedTask,
4373
- waitForIdle
4374
- };
4375
- }
4376
- //#endregion
4377
4419
  //#region extensions/matrix/src/matrix/monitor/index.ts
4378
4420
  function resolveMatrixStreamingMode(streaming) {
4379
4421
  const mode = streaming?.mode;
@@ -4382,7 +4424,7 @@ function resolveMatrixStreamingMode(streaming) {
4382
4424
  }
4383
4425
  function resolveMatrixPreviewToolProgress(streaming) {
4384
4426
  if (!streaming) return true;
4385
- if (resolveMatrixStreamingMode(streaming) === "progress") return streaming.progress?.toolProgress ?? streaming.preview?.toolProgress ?? true;
4427
+ if (resolveMatrixStreamingMode(streaming) === "progress") return streaming.progress?.toolProgress ?? streaming.preview?.toolProgress ?? false;
4386
4428
  return streaming.preview?.toolProgress ?? true;
4387
4429
  }
4388
4430
  function resolveMatrixPreviewToolProgressEnabled(streaming) {
@@ -4527,7 +4569,6 @@ async function monitorMatrixProvider(opts = {}) {
4527
4569
  const dmPolicyRaw = dmConfig?.policy ?? "pairing";
4528
4570
  const dmPolicy = allowlistOnly && dmPolicyRaw !== "disabled" ? "allowlist" : dmPolicyRaw;
4529
4571
  const dmSessionScope = dmConfig?.sessionScope ?? "per-user";
4530
- const textLimit = core.channel.text.resolveTextChunkLimit(cfg, "matrix", effectiveAccountId);
4531
4572
  const globalGroupChatHistoryLimit = cfg.messages?.groupChat?.historyLimit;
4532
4573
  const historyLimit = Math.max(0, accountConfig.historyLimit ?? globalGroupChatHistoryLimit ?? 0);
4533
4574
  const mediaMaxMb = opts.mediaMaxMb ?? accountConfig.mediaMaxMb ?? DEFAULT_MEDIA_MAX_MB;
@@ -4657,7 +4698,6 @@ async function monitorMatrixProvider(opts = {}) {
4657
4698
  blockStreamingEnabled,
4658
4699
  dmEnabled,
4659
4700
  dmPolicy,
4660
- textLimit,
4661
4701
  mediaMaxBytes,
4662
4702
  historyLimit,
4663
4703
  startupMs,
@@ -4699,6 +4739,10 @@ async function monitorMatrixProvider(opts = {}) {
4699
4739
  accountId: effectiveAccountId
4700
4740
  }).catch(() => []),
4701
4741
  directTracker,
4742
+ groupPolicy,
4743
+ roomsConfig,
4744
+ needsRoomAliasesForConfig,
4745
+ getRoomInfo,
4702
4746
  invalidateMemberDisplayName,
4703
4747
  logVerboseMessage,
4704
4748
  warnedEncryptedRooms,