@kodelyth/matrix 2026.5.39 → 2026.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/account-selection-Y50DNJ2l.js +158 -0
  2. package/dist/active-client-CmFdvPdO.js +20 -0
  3. package/dist/api.js +12 -0
  4. package/dist/approval-handler.runtime-BIi4fL0R.js +377 -0
  5. package/dist/approval-ids-BGHK7PnZ.js +7 -0
  6. package/dist/approval-reaction-auth-CL0-nCNV.js +27 -0
  7. package/dist/approval-reactions-nDm2x-K5.js +162 -0
  8. package/dist/async-lock-SsmtFXtt.js +19 -0
  9. package/dist/auth-presence.js +26 -0
  10. package/dist/backup-health-3BHbHxyd.js +60 -0
  11. package/dist/channel-C0kCyTNB.js +1380 -0
  12. package/dist/channel-plugin-api.js +2 -0
  13. package/dist/channel.runtime-CdrdEN-0.js +250 -0
  14. package/dist/cli-FtY6Nuzw.js +1338 -0
  15. package/dist/cli-metadata-Dkwua7CB.js +22 -0
  16. package/dist/cli-metadata.js +2 -0
  17. package/dist/client-BnohYygh.js +25 -0
  18. package/dist/client-PhrTwuC4.js +30 -0
  19. package/dist/client-bootstrap-Mcj8ChJ5.js +114 -0
  20. package/dist/config-paths-DVvt6vM3.js +114 -0
  21. package/dist/config-schema-BMGOlhdI.js +308 -0
  22. package/dist/config-secret-input.runtime-Dv_4Br_f.js +2 -0
  23. package/dist/contract-api.js +8 -0
  24. package/dist/create-client-J0htTaRj.js +64 -0
  25. package/dist/credentials-B7GsBbgQ.js +56 -0
  26. package/dist/credentials-read-8fE4qoWs.js +112 -0
  27. package/dist/credentials-write.runtime-BibplB4Y.js +17 -0
  28. package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
  29. package/dist/crypto-runtime-1pKW4O2F.js +1214 -0
  30. package/dist/deps-DVpDS81G.js +208 -0
  31. package/dist/device-health-Ct2wDSPG.js +16 -0
  32. package/dist/directory-live-i3T8uORc.js +150 -0
  33. package/dist/doctor-contract-BLzYHl_9.js +246 -0
  34. package/dist/doctor-contract-api.js +2 -0
  35. package/dist/doctor-diR5gE7D.js +153 -0
  36. package/dist/draft-stream-HpPJ_VJt.js +143 -0
  37. package/dist/encryption-guidance-BNEgckrZ.js +15 -0
  38. package/dist/env-auth-UFiTGkDM.js +63 -0
  39. package/dist/env-vars-EQKQv-FE.js +63 -0
  40. package/dist/errors-BETj3zr9.js +17 -0
  41. package/dist/exec-approval-resolver-BxPorU_t.js +15 -0
  42. package/dist/helper-api.js +4 -0
  43. package/dist/http-client-DoQgbQsU.js +331 -0
  44. package/dist/index.js +46 -0
  45. package/dist/legacy-crypto-inspector-zK0hDCbt.js +41 -0
  46. package/dist/legacy-crypto-restore-DSFIXuDo.js +85 -0
  47. package/dist/logging-Df7aPD1z.js +99 -0
  48. package/dist/matrix-migration.runtime-BNoT1Prt.js +525 -0
  49. package/dist/media-text-ZhGA8Pcs.js +146 -0
  50. package/dist/messages-CRA9WGg0.js +140 -0
  51. package/dist/migration-snapshot-backup-BR-xD7Ew.js +69 -0
  52. package/dist/migration-snapshot.runtime-BLcy_Nvw.js +2 -0
  53. package/dist/monitor-DQm7_13y.js +4331 -0
  54. package/dist/plugin-entry.handlers.runtime.js +51 -0
  55. package/dist/probe.runtime-CjJS53Kz.js +3 -0
  56. package/dist/profile-update-DqkPgZ1P.js +68 -0
  57. package/dist/reaction-common-CmVLzP-u.js +71 -0
  58. package/dist/reaction-events-D0nUJuZV.js +121 -0
  59. package/dist/record-shared-DGvSFn5M.js +2 -0
  60. package/dist/resolve-targets-ChECUzD2.js +140 -0
  61. package/dist/resolver.runtime-hdY3n0GO.js +5 -0
  62. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  63. package/dist/route-xRKj_ESW.js +161 -0
  64. package/dist/runtime-B-Fyrmxo.js +8 -0
  65. package/dist/runtime-api-BYXXkxq2.js +24 -0
  66. package/dist/runtime-api.js +25 -0
  67. package/dist/runtime-heavy-api.js +3 -0
  68. package/dist/runtime-lwTSy9Yt.js +6 -0
  69. package/dist/runtime-setter-api.js +2 -0
  70. package/dist/sdk-Jhq7mLtD.js +1704 -0
  71. package/dist/secret-contract-DEMcDsjl.js +120 -0
  72. package/dist/secret-contract-api.js +2 -0
  73. package/dist/send-CJunc6QM.js +1517 -0
  74. package/dist/setup-bootstrap-rJ0qZWPe.js +62 -0
  75. package/dist/setup-core-BEYoXF3J.js +677 -0
  76. package/dist/setup-entry.js +19 -0
  77. package/dist/setup-plugin-api.js +43 -0
  78. package/dist/setup-surface-c28ON6jq.js +537 -0
  79. package/dist/shared-D6MFMnpG.js +642 -0
  80. package/dist/startup-abort-B2J3MU_h.js +109 -0
  81. package/dist/startup-verification-CkD4Cwce.js +132 -0
  82. package/dist/storage-nyO0DOFE.js +281 -0
  83. package/dist/storage-paths-BTAketfg.js +52 -0
  84. package/dist/subagent-hooks-api-Dr_xnMRG.js +170 -0
  85. package/dist/subagent-hooks-api.js +2 -0
  86. package/dist/sync-state-Bx0gPaGA.js +12 -0
  87. package/dist/target-ids-Bsazo8si.js +77 -0
  88. package/dist/test-api.js +4 -0
  89. package/dist/thread-binding-api-IGU0-L70.js +17 -0
  90. package/dist/thread-binding-api.js +2 -0
  91. package/dist/thread-bindings-FjAZmDUP.js +352 -0
  92. package/dist/thread-bindings-runtime.js +2 -0
  93. package/dist/thread-bindings-shared-fvfP7jVs.js +97 -0
  94. package/dist/timeout-abort-signal-DpSHDHhR.js +2 -0
  95. package/dist/tool-actions.runtime-Cbo7YcYZ.js +532 -0
  96. package/dist/url-validation-DlrXNjAE.js +36 -0
  97. package/dist/verification-7tDPRpJU.js +345 -0
  98. package/package.json +19 -7
  99. package/api.js +0 -7
  100. package/auth-presence.js +0 -7
  101. package/channel-plugin-api.js +0 -7
  102. package/cli-metadata.js +0 -7
  103. package/contract-api.js +0 -7
  104. package/doctor-contract-api.js +0 -7
  105. package/helper-api.js +0 -7
  106. package/index.js +0 -7
  107. package/plugin-entry.handlers.runtime.js +0 -7
  108. package/runtime-api.js +0 -7
  109. package/runtime-heavy-api.js +0 -7
  110. package/runtime-setter-api.js +0 -7
  111. package/secret-contract-api.js +0 -7
  112. package/setup-entry.js +0 -7
  113. package/setup-plugin-api.js +0 -7
  114. package/subagent-hooks-api.js +0 -7
  115. package/test-api.js +0 -7
  116. package/thread-binding-api.js +0 -7
  117. package/thread-bindings-runtime.js +0 -7
@@ -0,0 +1,51 @@
1
+ import { t as formatMatrixErrorMessage } from "./errors-BETj3zr9.js";
2
+ import { normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
3
+ //#region extensions/matrix/src/plugin-entry.runtime.ts
4
+ let matrixVerificationRuntimePromise;
5
+ function loadMatrixVerificationRuntime() {
6
+ matrixVerificationRuntimePromise ??= import("./verification-7tDPRpJU.js").then((n) => n.y);
7
+ return matrixVerificationRuntimePromise;
8
+ }
9
+ function sendError(respond, err) {
10
+ respond(false, { error: formatMatrixErrorMessage(err) });
11
+ }
12
+ async function handleVerifyRecoveryKey({ params, respond }) {
13
+ try {
14
+ const { verifyMatrixRecoveryKey } = await loadMatrixVerificationRuntime();
15
+ const key = normalizeOptionalString(params?.key);
16
+ if (!key) {
17
+ respond(false, { error: "key required" });
18
+ return;
19
+ }
20
+ const result = await verifyMatrixRecoveryKey(key, { accountId: normalizeOptionalString(params?.accountId) });
21
+ respond(result.success, result);
22
+ } catch (err) {
23
+ sendError(respond, err);
24
+ }
25
+ }
26
+ async function handleVerificationBootstrap({ params, respond }) {
27
+ try {
28
+ const { bootstrapMatrixVerification } = await loadMatrixVerificationRuntime();
29
+ const result = await bootstrapMatrixVerification({
30
+ accountId: normalizeOptionalString(params?.accountId),
31
+ recoveryKey: typeof params?.recoveryKey === "string" ? params.recoveryKey : void 0,
32
+ forceResetCrossSigning: params?.forceResetCrossSigning === true
33
+ });
34
+ respond(result.success, result);
35
+ } catch (err) {
36
+ sendError(respond, err);
37
+ }
38
+ }
39
+ async function handleVerificationStatus({ params, respond }) {
40
+ try {
41
+ const { getMatrixVerificationStatus } = await loadMatrixVerificationRuntime();
42
+ respond(true, await getMatrixVerificationStatus({
43
+ accountId: normalizeOptionalString(params?.accountId),
44
+ includeRecoveryKey: params?.includeRecoveryKey === true
45
+ }));
46
+ } catch (err) {
47
+ sendError(respond, err);
48
+ }
49
+ }
50
+ //#endregion
51
+ export { handleVerificationBootstrap, handleVerificationStatus, handleVerifyRecoveryKey };
@@ -0,0 +1,3 @@
1
+ import { t as createMatrixClient } from "./create-client-J0htTaRj.js";
2
+ import "./client-PhrTwuC4.js";
3
+ export { createMatrixClient };
@@ -0,0 +1,68 @@
1
+ import { t as getMatrixRuntime } from "./runtime-B-Fyrmxo.js";
2
+ import { c as resolveMatrixConfigPath, l as updateMatrixAccountConfig, o as syncMatrixOwnProfile } from "./setup-core-BEYoXF3J.js";
3
+ import { n as withResolvedActionClient } from "./client-BnohYygh.js";
4
+ import { normalizeAccountId } from "klaw/plugin-sdk/account-id";
5
+ //#region extensions/matrix/src/matrix/actions/profile.ts
6
+ async function updateMatrixOwnProfile(opts = {}) {
7
+ const displayName = opts.displayName?.trim();
8
+ const avatarUrl = opts.avatarUrl?.trim();
9
+ const avatarPath = opts.avatarPath?.trim();
10
+ const runtime = getMatrixRuntime();
11
+ return await withResolvedActionClient(opts, async (client) => {
12
+ return await syncMatrixOwnProfile({
13
+ client,
14
+ userId: await client.getUserId(),
15
+ displayName: displayName || void 0,
16
+ avatarUrl: avatarUrl || void 0,
17
+ avatarPath: avatarPath || void 0,
18
+ loadAvatarFromUrl: async (url, maxBytes) => await runtime.media.loadWebMedia(url, maxBytes),
19
+ loadAvatarFromPath: async (path, maxBytes) => await runtime.media.loadWebMedia(path, {
20
+ maxBytes,
21
+ localRoots: opts.mediaLocalRoots
22
+ })
23
+ });
24
+ }, "persist");
25
+ }
26
+ //#endregion
27
+ //#region extensions/matrix/src/profile-update.ts
28
+ async function applyMatrixProfileUpdate(params) {
29
+ const runtime = getMatrixRuntime();
30
+ const persistedCfg = runtime.config.current();
31
+ const accountId = normalizeAccountId(params.account);
32
+ const displayName = params.displayName?.trim() || null;
33
+ const avatarUrl = params.avatarUrl?.trim() || null;
34
+ const avatarPath = params.avatarPath?.trim() || null;
35
+ if (!displayName && !avatarUrl && !avatarPath) throw new Error("Provide name/displayName and/or avatarUrl/avatarPath.");
36
+ const synced = await updateMatrixOwnProfile({
37
+ cfg: params.cfg,
38
+ accountId,
39
+ displayName: displayName ?? void 0,
40
+ avatarUrl: avatarUrl ?? void 0,
41
+ avatarPath: avatarPath ?? void 0,
42
+ mediaLocalRoots: params.mediaLocalRoots
43
+ });
44
+ const persistedAvatarUrl = synced.uploadedAvatarSource && synced.resolvedAvatarUrl ? synced.resolvedAvatarUrl : avatarUrl;
45
+ const updated = updateMatrixAccountConfig(persistedCfg, accountId, {
46
+ name: displayName ?? void 0,
47
+ avatarUrl: persistedAvatarUrl ?? void 0
48
+ });
49
+ await runtime.config.replaceConfigFile({
50
+ nextConfig: updated,
51
+ afterWrite: { mode: "auto" }
52
+ });
53
+ return {
54
+ accountId,
55
+ displayName,
56
+ avatarUrl: persistedAvatarUrl ?? null,
57
+ profile: {
58
+ displayNameUpdated: synced.displayNameUpdated,
59
+ avatarUpdated: synced.avatarUpdated,
60
+ resolvedAvatarUrl: synced.resolvedAvatarUrl,
61
+ uploadedAvatarSource: synced.uploadedAvatarSource,
62
+ convertedAvatarFromHttp: synced.convertedAvatarFromHttp
63
+ },
64
+ configPath: resolveMatrixConfigPath(updated, accountId)
65
+ };
66
+ }
67
+ //#endregion
68
+ export { updateMatrixOwnProfile as n, applyMatrixProfileUpdate as t };
@@ -0,0 +1,71 @@
1
+ import { normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
2
+ //#region extensions/matrix/src/matrix/reaction-common.ts
3
+ const MATRIX_ANNOTATION_RELATION_TYPE = "m.annotation";
4
+ const MATRIX_REACTION_EVENT_TYPE = "m.reaction";
5
+ function normalizeMatrixReactionMessageId(messageId) {
6
+ const normalized = messageId.trim();
7
+ if (!normalized) throw new Error("Matrix reaction requires a messageId");
8
+ return normalized;
9
+ }
10
+ function normalizeMatrixReactionEmoji(emoji) {
11
+ const normalized = emoji.trim();
12
+ if (!normalized) throw new Error("Matrix reaction requires an emoji");
13
+ return normalized;
14
+ }
15
+ function buildMatrixReactionContent(messageId, emoji) {
16
+ return { "m.relates_to": {
17
+ rel_type: MATRIX_ANNOTATION_RELATION_TYPE,
18
+ event_id: normalizeMatrixReactionMessageId(messageId),
19
+ key: normalizeMatrixReactionEmoji(emoji)
20
+ } };
21
+ }
22
+ function buildMatrixReactionRelationsPath(roomId, messageId) {
23
+ return `/_matrix/client/v1/rooms/${encodeURIComponent(roomId)}/relations/${encodeURIComponent(normalizeMatrixReactionMessageId(messageId))}/${MATRIX_ANNOTATION_RELATION_TYPE}/${MATRIX_REACTION_EVENT_TYPE}`;
24
+ }
25
+ function extractMatrixReactionAnnotation(content) {
26
+ if (!content || typeof content !== "object") return;
27
+ const relatesTo = content["m.relates_to"];
28
+ if (!relatesTo || typeof relatesTo !== "object") return;
29
+ if (typeof relatesTo.rel_type === "string" && relatesTo.rel_type !== "m.annotation") return;
30
+ const key = normalizeOptionalString(relatesTo.key) ?? "";
31
+ if (!key) return;
32
+ return {
33
+ key,
34
+ eventId: (normalizeOptionalString(relatesTo.event_id) ?? "") || void 0
35
+ };
36
+ }
37
+ function extractMatrixReactionKey(content) {
38
+ return extractMatrixReactionAnnotation(content)?.key;
39
+ }
40
+ function summarizeMatrixReactionEvents(events) {
41
+ const summaries = /* @__PURE__ */ new Map();
42
+ for (const event of events) {
43
+ const key = extractMatrixReactionKey(event.content);
44
+ if (!key) continue;
45
+ const sender = normalizeOptionalString(event.sender) ?? "";
46
+ const entry = summaries.get(key) ?? {
47
+ key,
48
+ count: 0,
49
+ users: []
50
+ };
51
+ entry.count += 1;
52
+ if (sender && !entry.users.includes(sender)) entry.users.push(sender);
53
+ summaries.set(key, entry);
54
+ }
55
+ return Array.from(summaries.values());
56
+ }
57
+ function selectOwnMatrixReactionEventIds(events, userId, emoji) {
58
+ const senderId = normalizeOptionalString(userId) ?? "";
59
+ if (!senderId) return [];
60
+ const targetEmoji = normalizeOptionalString(emoji);
61
+ const ids = [];
62
+ for (const event of events) {
63
+ if ((normalizeOptionalString(event.sender) ?? "") !== senderId) continue;
64
+ if (targetEmoji && extractMatrixReactionKey(event.content) !== targetEmoji) continue;
65
+ const eventId = normalizeOptionalString(event.event_id);
66
+ if (eventId) ids.push(eventId);
67
+ }
68
+ return ids;
69
+ }
70
+ //#endregion
71
+ export { extractMatrixReactionAnnotation as a, buildMatrixReactionRelationsPath as i, MATRIX_REACTION_EVENT_TYPE as n, selectOwnMatrixReactionEventIds as o, buildMatrixReactionContent as r, summarizeMatrixReactionEvents as s, MATRIX_ANNOTATION_RELATION_TYPE as t };
@@ -0,0 +1,121 @@
1
+ import { c as resolveMatrixAccountConfig } from "./config-paths-DVvt6vM3.js";
2
+ import { a as extractMatrixReactionAnnotation } from "./reaction-common-CmVLzP-u.js";
3
+ import { a as unregisterMatrixApprovalReactionTarget, i as resolveMatrixApprovalReactionTargetWithPersistence } from "./approval-reactions-nDm2x-K5.js";
4
+ import { i as resolveMatrixThreadRouting, r as resolveMatrixThreadRootId, t as resolveMatrixInboundRoute } from "./route-xRKj_ESW.js";
5
+ import { getSessionBindingService } from "klaw/plugin-sdk/session-binding-runtime";
6
+ //#region extensions/matrix/src/matrix/monitor/reaction-events.ts
7
+ let approvalReactionAuthPromise;
8
+ let execApprovalResolverPromise;
9
+ function loadApprovalReactionAuth() {
10
+ approvalReactionAuthPromise ??= import("./approval-reaction-auth-CL0-nCNV.js");
11
+ return approvalReactionAuthPromise;
12
+ }
13
+ function loadExecApprovalResolver() {
14
+ execApprovalResolverPromise ??= import("./exec-approval-resolver-BxPorU_t.js");
15
+ return execApprovalResolverPromise;
16
+ }
17
+ function resolveMatrixReactionNotificationMode(params) {
18
+ const matrixConfig = params.cfg.channels?.matrix;
19
+ return resolveMatrixAccountConfig({
20
+ cfg: params.cfg,
21
+ accountId: params.accountId
22
+ }).reactionNotifications ?? matrixConfig?.reactionNotifications ?? "own";
23
+ }
24
+ async function maybeResolveMatrixApprovalReaction(params) {
25
+ if (!params.target) return false;
26
+ const approvalKind = params.target.approvalId.startsWith("plugin:") ? "plugin" : "exec";
27
+ const { isMatrixApprovalReactionAuthorizedSender } = await loadApprovalReactionAuth();
28
+ if (!isMatrixApprovalReactionAuthorizedSender({
29
+ ...params,
30
+ approvalKind
31
+ })) return false;
32
+ const { isApprovalNotFoundError, resolveMatrixApproval } = await loadExecApprovalResolver();
33
+ try {
34
+ await resolveMatrixApproval({
35
+ cfg: params.cfg,
36
+ approvalId: params.target.approvalId,
37
+ decision: params.target.decision,
38
+ senderId: params.senderId
39
+ });
40
+ params.logVerboseMessage(`matrix: approval reaction resolved id=${params.target.approvalId} sender=${params.senderId} decision=${params.target.decision}`);
41
+ return true;
42
+ } catch (err) {
43
+ if (isApprovalNotFoundError(err)) {
44
+ unregisterMatrixApprovalReactionTarget({
45
+ roomId: params.roomId,
46
+ eventId: params.targetEventId
47
+ });
48
+ params.logVerboseMessage(`matrix: approval reaction ignored for expired approval id=${params.target.approvalId} sender=${params.senderId}`);
49
+ return true;
50
+ }
51
+ params.logVerboseMessage(`matrix: approval reaction failed id=${params.target.approvalId} sender=${params.senderId}: ${String(err)}`);
52
+ return true;
53
+ }
54
+ }
55
+ async function handleInboundMatrixReaction(params) {
56
+ const reaction = extractMatrixReactionAnnotation(params.event.content);
57
+ if (!reaction?.eventId) return;
58
+ if (params.senderId === params.selfUserId) return;
59
+ const approvalTarget = await resolveMatrixApprovalReactionTargetWithPersistence({
60
+ roomId: params.roomId,
61
+ eventId: reaction.eventId,
62
+ reactionKey: reaction.key
63
+ });
64
+ if (await maybeResolveMatrixApprovalReaction({
65
+ cfg: params.cfg,
66
+ accountId: params.accountId,
67
+ senderId: params.senderId,
68
+ target: approvalTarget,
69
+ targetEventId: reaction.eventId,
70
+ roomId: params.roomId,
71
+ logVerboseMessage: params.logVerboseMessage
72
+ })) return;
73
+ const notificationMode = resolveMatrixReactionNotificationMode({
74
+ cfg: params.cfg,
75
+ accountId: params.accountId
76
+ });
77
+ if (notificationMode === "off") return;
78
+ const targetEvent = await params.client.getEvent(params.roomId, reaction.eventId).catch((err) => {
79
+ params.logVerboseMessage(`matrix: failed resolving reaction target room=${params.roomId} id=${reaction.eventId}: ${String(err)}`);
80
+ return null;
81
+ });
82
+ const targetSender = targetEvent && typeof targetEvent.sender === "string" ? targetEvent.sender.trim() : "";
83
+ if (!targetSender) return;
84
+ if (notificationMode === "own" && targetSender !== params.selfUserId) return;
85
+ const targetContent = targetEvent && targetEvent.content && typeof targetEvent.content === "object" ? targetEvent.content : void 0;
86
+ const threadRootId = targetContent ? resolveMatrixThreadRootId({
87
+ event: targetEvent,
88
+ content: targetContent
89
+ }) : void 0;
90
+ const accountConfig = resolveMatrixAccountConfig({
91
+ cfg: params.cfg,
92
+ accountId: params.accountId
93
+ });
94
+ const thread = resolveMatrixThreadRouting({
95
+ isDirectMessage: params.isDirectMessage,
96
+ threadReplies: accountConfig.threadReplies ?? "inbound",
97
+ dmThreadReplies: accountConfig.dm?.threadReplies,
98
+ messageId: reaction.eventId,
99
+ threadRootId
100
+ });
101
+ const { route, runtimeBindingId } = resolveMatrixInboundRoute({
102
+ cfg: params.cfg,
103
+ accountId: params.accountId,
104
+ roomId: params.roomId,
105
+ senderId: params.senderId,
106
+ isDirectMessage: params.isDirectMessage,
107
+ dmSessionScope: accountConfig.dm?.sessionScope ?? "per-user",
108
+ threadId: thread.threadId,
109
+ eventTs: params.event.origin_server_ts,
110
+ resolveAgentRoute: params.core.channel.routing.resolveAgentRoute
111
+ });
112
+ if (runtimeBindingId) getSessionBindingService().touch(runtimeBindingId, params.event.origin_server_ts);
113
+ const text = `Matrix reaction added: ${reaction.key} by ${params.senderLabel} on msg ${reaction.eventId}`;
114
+ params.core.system.enqueueSystemEvent(text, {
115
+ sessionKey: route.sessionKey,
116
+ contextKey: `matrix:reaction:add:${params.roomId}:${reaction.eventId}:${params.senderId}:${reaction.key}`
117
+ });
118
+ params.logVerboseMessage(`matrix: reaction event enqueued room=${params.roomId} target=${reaction.eventId} sender=${params.senderId} emoji=${reaction.key}`);
119
+ }
120
+ //#endregion
121
+ export { handleInboundMatrixReaction, resolveMatrixReactionNotificationMode };
@@ -0,0 +1,2 @@
1
+ import { isRecord } from "klaw/plugin-sdk/string-coerce-runtime";
2
+ export { isRecord as t };
@@ -0,0 +1,140 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { n as normalizeMatrixMessagingTarget, t as isMatrixQualifiedUserId } from "./target-ids-Bsazo8si.js";
3
+ import { n as listMatrixDirectoryGroupsLive, r as listMatrixDirectoryPeersLive } from "./directory-live-i3T8uORc.js";
4
+ import { normalizeOptionalLowercaseString } from "klaw/plugin-sdk/string-coerce-runtime";
5
+ //#region extensions/matrix/src/resolve-targets.ts
6
+ var resolve_targets_exports = /* @__PURE__ */ __exportAll({ resolveMatrixTargets: () => resolveMatrixTargets });
7
+ function normalizeLookupQuery(query) {
8
+ return normalizeOptionalLowercaseString(query) ?? "";
9
+ }
10
+ function findExactDirectoryMatches(matches, query) {
11
+ const normalized = normalizeLookupQuery(query);
12
+ if (!normalized) return [];
13
+ return matches.filter((match) => {
14
+ const id = normalizeOptionalLowercaseString(match.id);
15
+ const name = normalizeOptionalLowercaseString(match.name);
16
+ const handle = normalizeOptionalLowercaseString(match.handle);
17
+ return normalized === id || normalized === name || normalized === handle;
18
+ });
19
+ }
20
+ function pickBestGroupMatch(matches, query) {
21
+ if (matches.length === 0) return {};
22
+ const exact = findExactDirectoryMatches(matches, query);
23
+ if (exact.length > 1) return {
24
+ best: exact[0],
25
+ note: "multiple exact matches; chose first"
26
+ };
27
+ if (exact.length === 1) return { best: exact[0] };
28
+ return {
29
+ best: matches[0],
30
+ note: matches.length > 1 ? "multiple matches; chose first" : void 0
31
+ };
32
+ }
33
+ function pickBestUserMatch(matches, query) {
34
+ if (matches.length === 0) return;
35
+ const exact = findExactDirectoryMatches(matches, query);
36
+ if (exact.length === 1) return exact[0];
37
+ }
38
+ function describeUserMatchFailure(matches, query) {
39
+ if (matches.length === 0) return "no matches";
40
+ const normalized = normalizeLookupQuery(query);
41
+ if (!normalized) return "empty input";
42
+ const exact = findExactDirectoryMatches(matches, normalized);
43
+ if (exact.length === 0) return "no exact match; use full Matrix ID";
44
+ if (exact.length > 1) return "multiple exact matches; use full Matrix ID";
45
+ return "no exact match; use full Matrix ID";
46
+ }
47
+ async function readCachedMatches(cache, query, lookup) {
48
+ const key = normalizeLookupQuery(query);
49
+ if (!key) return [];
50
+ const cached = cache.get(key);
51
+ if (cached) return cached;
52
+ const matches = await lookup(query.trim());
53
+ cache.set(key, matches);
54
+ return matches;
55
+ }
56
+ async function resolveMatrixTargets(params) {
57
+ const results = [];
58
+ const userLookupCache = /* @__PURE__ */ new Map();
59
+ const groupLookupCache = /* @__PURE__ */ new Map();
60
+ for (const input of params.inputs) {
61
+ const trimmed = input.trim();
62
+ if (!trimmed) {
63
+ results.push({
64
+ input,
65
+ resolved: false,
66
+ note: "empty input"
67
+ });
68
+ continue;
69
+ }
70
+ if (params.kind === "user") {
71
+ const normalizedTarget = normalizeMatrixMessagingTarget(trimmed);
72
+ if (normalizedTarget && isMatrixQualifiedUserId(normalizedTarget)) {
73
+ results.push({
74
+ input,
75
+ resolved: true,
76
+ id: normalizedTarget
77
+ });
78
+ continue;
79
+ }
80
+ try {
81
+ const matches = await readCachedMatches(userLookupCache, trimmed, (query) => listMatrixDirectoryPeersLive({
82
+ cfg: params.cfg,
83
+ accountId: params.accountId,
84
+ query,
85
+ limit: 5
86
+ }));
87
+ const best = pickBestUserMatch(matches, trimmed);
88
+ results.push({
89
+ input,
90
+ resolved: Boolean(best?.id),
91
+ id: best?.id,
92
+ name: best?.name,
93
+ note: best ? void 0 : describeUserMatchFailure(matches, trimmed)
94
+ });
95
+ } catch (err) {
96
+ params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
97
+ results.push({
98
+ input,
99
+ resolved: false,
100
+ note: "lookup failed"
101
+ });
102
+ }
103
+ continue;
104
+ }
105
+ const normalizedTarget = normalizeMatrixMessagingTarget(trimmed);
106
+ if (normalizedTarget?.startsWith("!")) {
107
+ results.push({
108
+ input,
109
+ resolved: true,
110
+ id: normalizedTarget
111
+ });
112
+ continue;
113
+ }
114
+ try {
115
+ const { best, note } = pickBestGroupMatch(await readCachedMatches(groupLookupCache, trimmed, (query) => listMatrixDirectoryGroupsLive({
116
+ cfg: params.cfg,
117
+ accountId: params.accountId,
118
+ query,
119
+ limit: 5
120
+ })), trimmed);
121
+ results.push({
122
+ input,
123
+ resolved: Boolean(best?.id),
124
+ id: best?.id,
125
+ name: best?.name,
126
+ note
127
+ });
128
+ } catch (err) {
129
+ params.runtime?.error?.(`matrix resolve failed: ${String(err)}`);
130
+ results.push({
131
+ input,
132
+ resolved: false,
133
+ note: "lookup failed"
134
+ });
135
+ }
136
+ }
137
+ return results;
138
+ }
139
+ //#endregion
140
+ export { resolve_targets_exports as n, resolveMatrixTargets as t };
@@ -0,0 +1,5 @@
1
+ import { t as resolveMatrixTargets } from "./resolve-targets-ChECUzD2.js";
2
+ //#region extensions/matrix/src/resolver.runtime.ts
3
+ const matrixResolverRuntime = { resolveMatrixTargets };
4
+ //#endregion
5
+ export { matrixResolverRuntime };
@@ -0,0 +1,14 @@
1
+ import "node:module";
2
+ //#region \0rolldown/runtime.js
3
+ var __defProp = Object.defineProperty;
4
+ var __exportAll = (all, no_symbols) => {
5
+ let target = {};
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
+ return target;
12
+ };
13
+ //#endregion
14
+ export { __exportAll as t };
@@ -0,0 +1,161 @@
1
+ import { n as MATRIX_REACTION_EVENT_TYPE } from "./reaction-common-CmVLzP-u.js";
2
+ import { buildAgentSessionKey, deriveLastRoutePolicy, resolveAgentIdFromSessionKey, resolveThreadSessionKeys } from "klaw/plugin-sdk/routing";
3
+ import { resolveConfiguredAcpBindingRecord } from "klaw/plugin-sdk/acp-binding-resolve-runtime";
4
+ import { getSessionBindingService } from "klaw/plugin-sdk/session-binding-runtime";
5
+ //#region extensions/matrix/src/matrix/monitor/types.ts
6
+ const EventType = {
7
+ RoomMessage: "m.room.message",
8
+ RoomMessageEncrypted: "m.room.encrypted",
9
+ RoomMember: "m.room.member",
10
+ Location: "m.location",
11
+ Reaction: MATRIX_REACTION_EVENT_TYPE
12
+ };
13
+ const RelationType = {
14
+ Replace: "m.replace",
15
+ Thread: "m.thread"
16
+ };
17
+ //#endregion
18
+ //#region extensions/matrix/src/matrix/monitor/threads.ts
19
+ function resolveMatrixThreadSessionKeys(params) {
20
+ return resolveThreadSessionKeys({
21
+ ...params,
22
+ normalizeThreadId: (threadId) => threadId
23
+ });
24
+ }
25
+ function resolveMatrixRelatedReplyToEventId(relates) {
26
+ if (!relates || typeof relates !== "object") return;
27
+ if ("m.in_reply_to" in relates && typeof relates["m.in_reply_to"] === "object" && relates["m.in_reply_to"] && "event_id" in relates["m.in_reply_to"] && typeof relates["m.in_reply_to"].event_id === "string") return relates["m.in_reply_to"].event_id;
28
+ }
29
+ function resolveMatrixThreadRouting(params) {
30
+ const effectiveThreadReplies = params.isDirectMessage && params.dmThreadReplies !== void 0 ? params.dmThreadReplies : params.threadReplies;
31
+ const messageId = params.messageId.trim();
32
+ const threadRootId = params.threadRootId?.trim();
33
+ const inboundThreadId = threadRootId && threadRootId !== messageId ? threadRootId : void 0;
34
+ return { threadId: effectiveThreadReplies === "off" ? void 0 : effectiveThreadReplies === "inbound" ? inboundThreadId : inboundThreadId ?? (messageId || void 0) };
35
+ }
36
+ function resolveMatrixThreadRootId(params) {
37
+ const relates = params.content["m.relates_to"];
38
+ if (!relates || typeof relates !== "object") return;
39
+ if ("rel_type" in relates && relates.rel_type === RelationType.Thread) {
40
+ if ("event_id" in relates && typeof relates.event_id === "string") return relates.event_id;
41
+ return resolveMatrixRelatedReplyToEventId(relates);
42
+ }
43
+ }
44
+ function resolveMatrixReplyToEventId(content) {
45
+ return resolveMatrixRelatedReplyToEventId(content["m.relates_to"]);
46
+ }
47
+ //#endregion
48
+ //#region extensions/matrix/src/matrix/monitor/route.ts
49
+ function resolveMatrixDmSessionKey(params) {
50
+ if (params.dmSessionScope !== "per-room") return params.fallbackSessionKey;
51
+ return buildAgentSessionKey({
52
+ agentId: params.agentId,
53
+ channel: "matrix",
54
+ accountId: params.accountId,
55
+ peer: {
56
+ kind: "channel",
57
+ id: params.roomId
58
+ }
59
+ });
60
+ }
61
+ function shouldApplyMatrixPerRoomDmSessionScope(params) {
62
+ return params.isDirectMessage && !params.configuredSessionKey;
63
+ }
64
+ function resolveMatrixInboundRoute(params) {
65
+ const baseRoute = params.resolveAgentRoute({
66
+ cfg: params.cfg,
67
+ channel: "matrix",
68
+ accountId: params.accountId,
69
+ peer: {
70
+ kind: params.isDirectMessage ? "direct" : "channel",
71
+ id: params.isDirectMessage ? params.senderId : params.roomId
72
+ },
73
+ parentPeer: params.isDirectMessage ? {
74
+ kind: "channel",
75
+ id: params.roomId
76
+ } : void 0
77
+ });
78
+ const bindingConversationId = params.threadId ?? params.roomId;
79
+ const bindingParentConversationId = params.threadId ? params.roomId : void 0;
80
+ const runtimeBinding = getSessionBindingService().resolveByConversation({
81
+ channel: "matrix",
82
+ accountId: params.accountId,
83
+ conversationId: bindingConversationId,
84
+ parentConversationId: bindingParentConversationId
85
+ });
86
+ const boundSessionKey = runtimeBinding?.targetSessionKey?.trim();
87
+ if (runtimeBinding && boundSessionKey) return {
88
+ route: {
89
+ ...baseRoute,
90
+ sessionKey: boundSessionKey,
91
+ agentId: resolveAgentIdFromSessionKey(boundSessionKey) || baseRoute.agentId,
92
+ lastRoutePolicy: deriveLastRoutePolicy({
93
+ sessionKey: boundSessionKey,
94
+ mainSessionKey: baseRoute.mainSessionKey
95
+ }),
96
+ matchedBy: "binding.channel"
97
+ },
98
+ configuredBinding: null,
99
+ runtimeBindingId: runtimeBinding.bindingId
100
+ };
101
+ const configuredBinding = runtimeBinding == null ? resolveConfiguredAcpBindingRecord({
102
+ cfg: params.cfg,
103
+ channel: "matrix",
104
+ accountId: params.accountId,
105
+ conversationId: bindingConversationId,
106
+ parentConversationId: bindingParentConversationId
107
+ }) : null;
108
+ const configuredSessionKey = configuredBinding?.record.targetSessionKey?.trim();
109
+ const effectiveRoute = configuredBinding && configuredSessionKey ? {
110
+ ...baseRoute,
111
+ sessionKey: configuredSessionKey,
112
+ agentId: resolveAgentIdFromSessionKey(configuredSessionKey) || configuredBinding.spec.agentId || baseRoute.agentId,
113
+ lastRoutePolicy: deriveLastRoutePolicy({
114
+ sessionKey: configuredSessionKey,
115
+ mainSessionKey: baseRoute.mainSessionKey
116
+ }),
117
+ matchedBy: "binding.channel"
118
+ } : baseRoute;
119
+ const dmSessionKey = shouldApplyMatrixPerRoomDmSessionScope({
120
+ isDirectMessage: params.isDirectMessage,
121
+ configuredSessionKey
122
+ }) ? resolveMatrixDmSessionKey({
123
+ accountId: params.accountId,
124
+ agentId: effectiveRoute.agentId,
125
+ roomId: params.roomId,
126
+ dmSessionScope: params.dmSessionScope,
127
+ fallbackSessionKey: effectiveRoute.sessionKey
128
+ }) : effectiveRoute.sessionKey;
129
+ const routeWithDmScope = dmSessionKey === effectiveRoute.sessionKey ? effectiveRoute : {
130
+ ...effectiveRoute,
131
+ sessionKey: dmSessionKey,
132
+ lastRoutePolicy: "session"
133
+ };
134
+ if (!configuredBinding && !configuredSessionKey && params.threadId) {
135
+ const threadKeys = resolveMatrixThreadSessionKeys({
136
+ baseSessionKey: routeWithDmScope.sessionKey,
137
+ threadId: params.threadId,
138
+ parentSessionKey: routeWithDmScope.sessionKey
139
+ });
140
+ return {
141
+ route: {
142
+ ...routeWithDmScope,
143
+ sessionKey: threadKeys.sessionKey,
144
+ mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey,
145
+ lastRoutePolicy: deriveLastRoutePolicy({
146
+ sessionKey: threadKeys.sessionKey,
147
+ mainSessionKey: threadKeys.parentSessionKey ?? routeWithDmScope.sessionKey
148
+ })
149
+ },
150
+ configuredBinding,
151
+ runtimeBindingId: null
152
+ };
153
+ }
154
+ return {
155
+ route: routeWithDmScope,
156
+ configuredBinding,
157
+ runtimeBindingId: null
158
+ };
159
+ }
160
+ //#endregion
161
+ export { EventType as a, resolveMatrixThreadRouting as i, resolveMatrixReplyToEventId as n, RelationType as o, resolveMatrixThreadRootId as r, resolveMatrixInboundRoute as t };
@@ -0,0 +1,8 @@
1
+ import { createPluginRuntimeStore } from "klaw/plugin-sdk/runtime-store";
2
+ //#region extensions/matrix/src/runtime.ts
3
+ const { setRuntime: setMatrixRuntime, getRuntime: getMatrixRuntime, tryGetRuntime: getOptionalMatrixRuntime } = createPluginRuntimeStore({
4
+ pluginId: "matrix",
5
+ errorMessage: "Matrix runtime not initialized"
6
+ });
7
+ //#endregion
8
+ export { getOptionalMatrixRuntime as n, setMatrixRuntime as r, getMatrixRuntime as t };
@@ -0,0 +1,24 @@
1
+ import "./timeout-abort-signal-DpSHDHhR.js";
2
+ import "klaw/plugin-sdk/account-id";
3
+ import { resolveThreadBindingIdleTimeoutMsForChannel, resolveThreadBindingMaxAgeMsForChannel } from "klaw/plugin-sdk/conversation-runtime";
4
+ import "klaw/plugin-sdk/channel-message";
5
+ import { chunkTextForOutbound as chunkTextForOutbound$1 } from "klaw/plugin-sdk/text-chunking";
6
+ import { createActionGate as createActionGate$1, jsonResult, readNumberParam as readNumberParam$1, readReactionParams, readStringArrayParam, readStringParam as readStringParam$1 } from "klaw/plugin-sdk/channel-actions";
7
+ import "klaw/plugin-sdk/routing";
8
+ import "klaw/plugin-sdk/channel-status";
9
+ import "klaw/plugin-sdk/channel-config-primitives";
10
+ import "klaw/plugin-sdk/ssrf-runtime";
11
+ import "klaw/plugin-sdk/channel-location";
12
+ import "klaw/plugin-sdk/channel-logging";
13
+ import "klaw/plugin-sdk/channel-targets";
14
+ import "klaw/plugin-sdk/setup";
15
+ import "klaw/plugin-sdk/json-store";
16
+ import "klaw/plugin-sdk/outbound-media";
17
+ import "klaw/plugin-sdk/poll-runtime";
18
+ import { formatZonedTimestamp } from "klaw/plugin-sdk/time-runtime";
19
+ import "klaw/plugin-sdk/channel-feedback";
20
+ import { GROUP_POLICY_BLOCKED_LABEL, resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "klaw/plugin-sdk/runtime-group-policy";
21
+ import "klaw/plugin-sdk/inbound-reply-dispatch";
22
+ import "klaw/plugin-sdk/acp-binding-runtime";
23
+ import { resolveOutboundSendDep } from "klaw/plugin-sdk/outbound-send-deps";
24
+ export { jsonResult as a, readStringArrayParam as c, resolveDefaultGroupPolicy as d, resolveOutboundSendDep as f, warnMissingProviderGroupPolicyFallbackOnce as h, formatZonedTimestamp as i, readStringParam$1 as l, resolveThreadBindingMaxAgeMsForChannel as m, chunkTextForOutbound$1 as n, readNumberParam$1 as o, resolveThreadBindingIdleTimeoutMsForChannel as p, createActionGate$1 as r, readReactionParams as s, GROUP_POLICY_BLOCKED_LABEL as t, resolveAllowlistProviderRuntimeGroupPolicy as u };