@openclaw/mattermost 2026.8.1-beta.2 → 2026.9.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,12 @@
1
1
  import { n as getOptionalMattermostRuntime, t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { a as createMattermostPost, d as fetchMattermostUser, g as readMattermostError, l as fetchMattermostChannelPosts, m as normalizeMattermostBaseUrl, n as buildMattermostApiUrl, o as deleteMattermostPost, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, t as MattermostPostSchema, u as fetchMattermostMe, v as sendMattermostTyping, y as updateMattermostPost } from "./client-B_hd-kwM.js";
2
+ import { _ as sendMattermostTyping, a as createMattermostPost, d as fetchMattermostUser, g as readMattermostError, l as fetchMattermostChannelPosts, m as normalizeMattermostBaseUrl, n as buildMattermostApiUrl, o as deleteMattermostPost, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, t as MattermostPostSchema, u as fetchMattermostMe, v as updateMattermostPost } from "./client-DAIry9-2.js";
3
3
  import { S as resolveChannelMediaMaxBytes, T as warnMissingProviderGroupPolicyFallbackOnce, _ as logInboundDrop, b as registerPluginHttpRoute, c as DEFAULT_GROUP_HISTORY_LIMIT, d as createChannelMessageReplyPipeline, f as createChannelPairingController, h as listSkillCommandsForAgents, i as normalizeMattermostAllowEntry, l as buildModelsProviderData, n as formatMattermostDirectMessageDropLog, o as resolveMattermostMonitorInboundAccess, s as resolveMattermostTrustedChatKind, t as authorizeMattermostCommandInvocation, u as createChannelHistoryWindow, v as logTypingFailure, w as resolveDefaultGroupPolicy, x as resolveAllowlistProviderRuntimeGroupPolicy$1 } from "./monitor-auth-CVd_4FPD.js";
4
- import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl } from "./interactions-Du_EJMeN.js";
5
- import { a as resolveMattermostReplyToMode, i as resolveMattermostAccount, n as listMattermostAccountIds, t as inspectMattermostAccount } from "./accounts-DspH-NMT.js";
6
- import { i as normalizeMattermostMessagingTarget } from "./channel-plugin-runtime-Dxt8Zv1j.js";
7
- import { _ as isSlashCommandsEnabled, a as sendMessageMattermost, b as resolveSlashCommandConfig, c as deliverMattermostReplyPayload, d as parseMattermostModelPickerContext, f as renderMattermostModelsPickerView, g as cleanupSlashCommands, h as DEFAULT_COMMAND_SPECS, l as joinMattermostVisibleContent, m as resolveMattermostModelPickerCurrentModel, n as deactivateSlashCommands, o as resolveMattermostOpaqueTarget, p as renderMattermostProviderPickerView, r as getSlashCommandState, s as createMattermostReplyDeliveryBarrier, t as activateSlashCommands, u as buildMattermostAllowedModelRefs, v as registerSlashCommands, y as resolveCallbackUrl } from "./slash-state-DUowGLl4.js";
4
+ import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl } from "./interactions-k47k-7SP.js";
5
+ import { a as inspectMattermostAccount, c as resolveMattermostAccount, l as resolveMattermostReplyToMode, n as normalizeMattermostMessagingTarget, o as listMattermostAccountIds } from "./normalize-bBDFEiyJ.js";
6
+ import { _ as registerSlashCommands, a as sendMessageMattermost, c as joinMattermostVisibleContent, d as renderMattermostModelsPickerView, f as renderMattermostProviderPickerView, g as isSlashCommandsEnabled, h as cleanupSlashCommands, l as buildMattermostAllowedModelRefs, m as DEFAULT_COMMAND_SPECS, n as deactivateSlashCommands, o as resolveMattermostOpaqueTarget, p as resolveMattermostModelPickerCurrentModel, r as getSlashCommandState, s as deliverMattermostReplyPayload, t as activateSlashCommands, u as parseMattermostModelPickerContext, v as resolveCallbackUrl, y as resolveSlashCommandConfig } from "./slash-state-CfsJU7WW.js";
8
7
  import { randomUUID } from "node:crypto";
9
8
  import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
10
- import { resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";
9
+ import { resolvePinnedMainDmOwnerFromAllowlist, sanitizeUntrustedFileName } from "openclaw/plugin-sdk/security-runtime";
11
10
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringEntries, normalizeTrimmedStringList, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
12
11
  import { buildChannelInboundMediaPayload, createChannelPartialDeliveryError, formatInboundEnvelope, formatInboundFromLabel, formatInboundMediaUnavailableText, formatMediaPlaceholderText, implicitMentionKindWhen, isChannelPartialDeliveryError, resolveInboundMentionDecision, resolveInboundSessionEnvelopeContext, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
13
12
  import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
@@ -24,9 +23,9 @@ import { buildTtsSupplementMediaPayload, countOutboundMedia, getReplyPayloadTtsS
24
23
  import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
25
24
  import { isRecord } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
26
25
  import { resolveInboundLastRouteSessionKey, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
26
+ import { escapeRegExp, runChannelProbe, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
27
27
  import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
28
28
  import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
29
- import { runChannelProbe, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
30
29
  import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
31
30
  import { channelReadyPatch, isLoopbackHost } from "openclaw/plugin-sdk/gateway-runtime";
32
31
  import { captureWsEvent, createDebugProxyWebSocketAgent, resolveDebugProxySettings } from "openclaw/plugin-sdk/proxy-capture";
@@ -50,17 +49,10 @@ function buildClient(params) {
50
49
  allowPrivateNetwork: isPrivateNetworkOptInEnabled(account.config)
51
50
  });
52
51
  }
53
- /**
54
- * Build clients from ALL enabled accounts (deduplicated by token).
55
- *
56
- * We always scan every account because:
57
- * - Private channels are only visible to bots that are members
58
- * - The requesting agent's account may have an expired/invalid token
59
- *
60
- * This means a single healthy bot token is enough for directory discovery.
61
- */
52
+ /** Build the requested account client, or aggregate accounts for an explicitly unscoped lookup. */
62
53
  function buildClients(params) {
63
- const accountIds = listMattermostAccountIds(params.cfg);
54
+ const requestedAccountId = params.accountId?.trim();
55
+ const accountIds = requestedAccountId ? [requestedAccountId] : listMattermostAccountIds(params.cfg);
64
56
  const seen = /* @__PURE__ */ new Set();
65
57
  const clients = [];
66
58
  for (const id of accountIds) {
@@ -182,22 +174,32 @@ function resolveThreadSessionKeys$1(params) {
182
174
  normalizeThreadId: (threadId) => threadId
183
175
  });
184
176
  }
177
+ function buildMattermostBotMentionPattern(username) {
178
+ return `(?<![a-z0-9_])@${escapeRegExp(username)}(?![a-z0-9_]|[.:-]+[a-z0-9_])`;
179
+ }
180
+ function matchesMattermostBotMention(text, botUsername) {
181
+ if (!botUsername) return false;
182
+ return new RegExp(buildMattermostBotMentionPattern(botUsername), "i").test(text);
183
+ }
185
184
  /**
186
185
  * Strip bot mention from message text while preserving newlines and
187
186
  * block-level Markdown formatting (headings, lists, blockquotes).
188
187
  */
189
188
  function normalizeMention(text, mention) {
190
189
  if (!mention) return text.trim();
191
- const escaped = mention.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
192
- const hasMentionRe = new RegExp(`@${escaped}\\b`, "i");
193
- const leadingMentionRe = new RegExp(`^([\\t ]*)@${escaped}\\b[\\t ]*`, "i");
194
- const trailingMentionRe = new RegExp(`[\\t ]*@${escaped}\\b[\\t ]*$`, "i");
190
+ const pattern = buildMattermostBotMentionPattern(mention);
191
+ const hasMentionRe = new RegExp(pattern, "i");
192
+ const leadingMentionRe = new RegExp(`^([\\t ]*)${pattern}[\\t ]*`, "i");
193
+ const trailingMentionRe = new RegExp(`[\\t ]*${pattern}[\\t ]*$`, "i");
195
194
  const normalizedLines = text.split("\n").map((line) => {
196
- const hadMention = hasMentionRe.test(line);
197
- const normalizedLine = line.replace(leadingMentionRe, "$1").replace(trailingMentionRe, "").replace(new RegExp(`@${escaped}\\b`, "gi"), "").replace(/(\S)[ \t]{2,}/g, "$1 ");
195
+ if (!hasMentionRe.test(line)) return {
196
+ text: line,
197
+ mentionOnlyBlank: false
198
+ };
199
+ const normalizedLine = line.replace(leadingMentionRe, "$1").replace(trailingMentionRe, "").replace(new RegExp(pattern, "gi"), "").replace(/(\S)[ \t]{2,}/g, "$1 ");
198
200
  return {
199
201
  text: normalizedLine,
200
- mentionOnlyBlank: hadMention && normalizedLine.trim() === ""
202
+ mentionOnlyBlank: normalizedLine.trim() === ""
201
203
  };
202
204
  });
203
205
  while (normalizedLines[0]?.mentionOnlyBlank) normalizedLines.shift();
@@ -412,15 +414,15 @@ function createMattermostConnectOnce(opts) {
412
414
  scheduleProtocolPing();
413
415
  });
414
416
  ws.on("message", async (data) => {
417
+ const raw = rawDataToString(data);
415
418
  captureWsEvent({
416
419
  url: opts.wsUrl,
417
420
  direction: "inbound",
418
421
  kind: "ws-frame",
419
422
  flowId,
420
- payload: Buffer.from(rawDataToString(data)),
423
+ payload: Buffer.from(raw),
421
424
  meta: { subsystem: "mattermost-websocket" }
422
425
  });
423
- const raw = rawDataToString(data);
424
426
  const payload = parseMattermostEventPayload(raw);
425
427
  if (!payload) return;
426
428
  if (payload.status === "OK" && payload.seq_reply === authenticationSeq) {
@@ -531,6 +533,7 @@ function inspectMattermostIngressEvent(rawEvent) {
531
533
  const data = isRecord(envelope.data) ? envelope.data : null;
532
534
  const post = parseRawPost(data?.post);
533
535
  const eventId = requiredString(post.id, "post.id");
536
+ requiredString(post.user_id, "post.user_id");
534
537
  const broadcast = isRecord(envelope.broadcast) ? envelope.broadcast : null;
535
538
  return {
536
539
  eventId,
@@ -542,9 +545,13 @@ function parseClaimedEvent(rawEvent, eventId) {
542
545
  if (!payload || payload.event !== "posted") throw new MattermostIngressPermanentError("invalid-event", `Mattermost ingress row ${eventId} is not a posted event.`);
543
546
  const post = parseMattermostPost(payload.data?.post);
544
547
  const claimedChannelId = post?.channel_id?.trim() || payload.data?.channel_id?.trim() || payload.broadcast?.channel_id?.trim();
545
- if (!post || post.id !== eventId || !claimedChannelId) throw new MattermostIngressPermanentError("invalid-event", `Mattermost ingress row ${eventId} has invalid post identity.`);
548
+ const senderId = post?.user_id?.trim();
549
+ if (!post || post.id !== eventId || !senderId || !claimedChannelId) throw new MattermostIngressPermanentError("invalid-event", `Mattermost ingress row ${eventId} has invalid post identity.`);
546
550
  return {
547
- post,
551
+ post: {
552
+ ...post,
553
+ user_id: senderId
554
+ },
548
555
  payload
549
556
  };
550
557
  }
@@ -601,7 +608,14 @@ function createMattermostIngressMonitor(options) {
601
608
  });
602
609
  monitor.start();
603
610
  return {
604
- receive: (rawEvent) => monitor.admit(rawEvent).then(() => void 0),
611
+ receive: async (rawEvent) => {
612
+ try {
613
+ await monitor.admit(rawEvent);
614
+ } catch (error) {
615
+ if (!(error instanceof MattermostIngressPermanentError) || error.reason !== "invalid-event") throw error;
616
+ options.runtime.error?.(`mattermost ingress rejected invalid event: ${error.message}`);
617
+ }
618
+ },
605
619
  stop: monitor.stop,
606
620
  waitForIdle: monitor.waitForIdle
607
621
  };
@@ -774,6 +788,8 @@ async function buildMattermostEventPlan(monitor, params) {
774
788
  ParentSessionKey: thread.parentSessionKey,
775
789
  AccountId: route.accountId,
776
790
  ChatType: kind,
791
+ ConversationRouteContextObserved: true,
792
+ ConversationRoutePeerId: kind === "direct" ? params.senderId : params.channelId,
777
793
  GroupChannel: channelName ? `#${channelName}` : void 0,
778
794
  GroupSpace: teamId,
779
795
  SenderId: params.senderId,
@@ -781,36 +797,31 @@ async function buildMattermostEventPlan(monitor, params) {
781
797
  Surface: "mattermost",
782
798
  ReplyToId: thread.effectiveReplyToId,
783
799
  MessageThreadId: thread.effectiveReplyToId,
800
+ NativeChannelId: params.channelId,
801
+ InboundAccessAuthorized: true,
784
802
  OriginatingChannel: "mattermost",
785
803
  OriginatingTo: to
786
804
  }),
787
- createReplyPlan: () => {
788
- const deliveryBarrier = createMattermostReplyDeliveryBarrier({
789
- isDirect: kind === "direct",
790
- dmRetryOptions: monitor.account.config.dmChannelRetry
791
- });
792
- return {
793
- textLimit: monitor.core.channel.text.resolveTextChunkLimit(monitor.cfg, "mattermost", monitor.account.accountId, { fallbackLimit: monitor.account.textChunkLimit ?? 4e3 }),
794
- tableMode: monitor.core.channel.text.resolveMarkdownTableMode({
795
- cfg: monitor.cfg,
796
- channel: "mattermost",
797
- accountId: monitor.account.accountId
798
- }),
799
- deliveryBarrier,
800
- replyPipeline: { typing: {
801
- start: () => monitor.resources.sendTypingIndicator(params.channelId, thread.effectiveReplyToId),
802
- onStartError: (error) => {
803
- logTypingFailure({
804
- log: monitor.logDebugMessage,
805
- channel: "mattermost",
806
- target: params.channelId,
807
- error
808
- });
809
- }
810
- } },
811
- replyOptions: { disableBlockStreaming: typeof monitor.account.blockStreaming === "boolean" ? !monitor.account.blockStreaming : void 0 }
812
- };
813
- }
805
+ createReplyPlan: () => ({
806
+ textLimit: monitor.core.channel.text.resolveTextChunkLimit(monitor.cfg, "mattermost", monitor.account.accountId, { fallbackLimit: monitor.account.textChunkLimit ?? 4e3 }),
807
+ tableMode: monitor.core.channel.text.resolveMarkdownTableMode({
808
+ cfg: monitor.cfg,
809
+ channel: "mattermost",
810
+ accountId: monitor.account.accountId
811
+ }),
812
+ replyPipeline: { typing: {
813
+ start: () => monitor.resources.sendTypingIndicator(params.channelId, thread.effectiveReplyToId),
814
+ onStartError: (error) => {
815
+ logTypingFailure({
816
+ log: monitor.logDebugMessage,
817
+ channel: "mattermost",
818
+ target: params.channelId,
819
+ error
820
+ });
821
+ }
822
+ } },
823
+ replyOptions: { disableBlockStreaming: typeof monitor.account.blockStreaming === "boolean" ? !monitor.account.blockStreaming : void 0 }
824
+ })
814
825
  };
815
826
  }
816
827
  //#endregion
@@ -885,7 +896,7 @@ function registerMattermostInteractions(params) {
885
896
  dropLabel: "interaction dispatch"
886
897
  });
887
898
  if (!eventPlan) return;
888
- const { channelDisplay, kind, route, thread, to } = eventPlan;
899
+ const { channelDisplay, channelId, kind, route, thread, to } = eventPlan;
889
900
  const bodyText = `[Button click: user @${button.userName} selected "${button.actionName}"]`;
890
901
  const ctxPayload = eventPlan.finalizeContext({
891
902
  Body: bodyText,
@@ -899,7 +910,7 @@ function registerMattermostInteractions(params) {
899
910
  WasMentioned: true,
900
911
  CommandAuthorized: false
901
912
  });
902
- const { deliveryBarrier, replyOptions, replyPipeline, tableMode, textLimit } = eventPlan.createReplyPlan();
913
+ const { replyOptions, replyPipeline, tableMode, textLimit } = eventPlan.createReplyPlan();
903
914
  await core.channel.inbound.dispatch({
904
915
  cfg,
905
916
  channel: "mattermost",
@@ -917,7 +928,7 @@ function registerMattermostInteractions(params) {
917
928
  core,
918
929
  cfg,
919
930
  payload,
920
- to,
931
+ channelId,
921
932
  accountId: account.accountId,
922
933
  agentId: route.agentId,
923
934
  replyToId: resolveMattermostInteractionReplyRootId({
@@ -929,8 +940,7 @@ function registerMattermostInteractions(params) {
929
940
  }),
930
941
  textLimit,
931
942
  tableMode,
932
- sendMessage: sendMessageMattermost,
933
- onDmChannelResolution: deliveryBarrier.trackDmChannelResolution
943
+ sendMessage: sendMessageMattermost
934
944
  });
935
945
  if (result.visibleReplySent) runtime.log?.(`delivered button-click reply to ${to}`);
936
946
  return result;
@@ -940,11 +950,7 @@ function registerMattermostInteractions(params) {
940
950
  }
941
951
  },
942
952
  replyPipeline,
943
- dispatcherOptions: {
944
- resolveFollowupAdmissionBarrierTimeoutPolicy: deliveryBarrier.resolveTimeoutPolicy,
945
- onDeliverySettled: deliveryBarrier.markDeliverySettled,
946
- humanDelay: resolveHumanDelayConfig(cfg, route.agentId)
947
- },
953
+ dispatcherOptions: { humanDelay: resolveHumanDelayConfig(cfg, route.agentId) },
948
954
  replyOptions
949
955
  });
950
956
  },
@@ -954,7 +960,6 @@ function registerMattermostInteractions(params) {
954
960
  source: "mattermost-interactions",
955
961
  accountId: account.accountId,
956
962
  log: (message) => runtime.log?.(message),
957
- replaceExisting: true,
958
963
  throwOnFailure: true
959
964
  });
960
965
  }
@@ -964,7 +969,7 @@ function createMattermostModelPickerInteractionHandler(monitor) {
964
969
  const { account, cfg, core, pairing, resources, runtime } = monitor;
965
970
  const { resolveChannelInfo, updateModelPickerPost } = resources;
966
971
  const runModelPickerCommand = async (params) => {
967
- const { channelDisplay, kind, roomLabel, route, thread, to } = params.eventPlan;
972
+ const { channelDisplay, channelId, kind, roomLabel, route, thread } = params.eventPlan;
968
973
  const fromLabel = kind === "direct" ? `Mattermost DM from ${params.senderName}` : `Mattermost message in ${roomLabel} from ${params.senderName}`;
969
974
  const ctxPayload = params.eventPlan.finalizeContext({
970
975
  Body: params.commandText,
@@ -980,7 +985,7 @@ function createMattermostModelPickerInteractionHandler(monitor) {
980
985
  CommandAuthorized: params.commandAuthorized,
981
986
  CommandSource: "native"
982
987
  });
983
- const { deliveryBarrier, replyOptions, replyPipeline, tableMode, textLimit } = params.eventPlan.createReplyPlan();
988
+ const { replyOptions, replyPipeline, tableMode, textLimit } = params.eventPlan.createReplyPlan();
984
989
  await core.channel.inbound.dispatch({
985
990
  cfg,
986
991
  channel: "mattermost",
@@ -1002,7 +1007,7 @@ function createMattermostModelPickerInteractionHandler(monitor) {
1002
1007
  core,
1003
1008
  cfg,
1004
1009
  payload: trimmedPayload,
1005
- to,
1010
+ channelId,
1006
1011
  accountId: account.accountId,
1007
1012
  agentId: route.agentId,
1008
1013
  replyToId: resolveMattermostInteractionReplyRootId({
@@ -1014,8 +1019,7 @@ function createMattermostModelPickerInteractionHandler(monitor) {
1014
1019
  }),
1015
1020
  textLimit,
1016
1021
  tableMode: "off",
1017
- sendMessage: sendMessageMattermost,
1018
- onDmChannelResolution: deliveryBarrier.trackDmChannelResolution
1022
+ sendMessage: sendMessageMattermost
1019
1023
  });
1020
1024
  },
1021
1025
  onError: (err, info) => {
@@ -1023,10 +1027,6 @@ function createMattermostModelPickerInteractionHandler(monitor) {
1023
1027
  }
1024
1028
  },
1025
1029
  replyPipeline,
1026
- dispatcherOptions: {
1027
- resolveFollowupAdmissionBarrierTimeoutPolicy: deliveryBarrier.resolveTimeoutPolicy,
1028
- onDeliverySettled: deliveryBarrier.markDeliverySettled
1029
- },
1030
1030
  replyOptions
1031
1031
  });
1032
1032
  };
@@ -1215,9 +1215,11 @@ function formatMattermostInboundMediaText(params) {
1215
1215
  const materializedCount = params.materializedMedia.filter((media) => Boolean(media.path) || Boolean(media.url)).length;
1216
1216
  const unavailableCount = Math.max(0, params.nativeMedia.length - materializedCount);
1217
1217
  if (unavailableCount === 0) return params.body;
1218
+ const unavailableFileNames = params.materializedMedia.filter((media) => !media.path && !media.url && media.fileName).map((media) => sanitizeUntrustedFileName(media.fileName ?? "", "")).filter(Boolean).join(", ");
1219
+ const fileNameNotice = unavailableFileNames ? ` ${JSON.stringify(truncateUtf16Safe(unavailableFileNames, 512))}` : "";
1218
1220
  return formatInboundMediaUnavailableText({
1219
1221
  body: params.body,
1220
- notice: `[mattermost ${unavailableCount > 1 ? `${unavailableCount} attachments` : "attachment"} unavailable]`
1222
+ notice: `[mattermost ${unavailableCount > 1 ? `${unavailableCount} attachments` : "attachment"} unavailable]${fileNameNotice}`
1221
1223
  });
1222
1224
  }
1223
1225
  const CHANNEL_CACHE_TTL_MS = 5 * 6e4;
@@ -1273,18 +1275,22 @@ function createMattermostMonitorResources(params) {
1273
1275
  out.push({
1274
1276
  path: saved.path,
1275
1277
  contentType,
1278
+ ...saved.fileName ? { fileName: saved.fileName } : {},
1276
1279
  kind: mediaKindFromMime(contentType) ?? "unknown"
1277
1280
  });
1278
1281
  } catch (err) {
1279
1282
  logger.debug?.(`mattermost: failed to download file ${fileId}: ${String(err)}`);
1280
- let contentType;
1283
+ let info;
1281
1284
  try {
1282
- contentType = (await client.request(`/files/${fileId}/info`)).mime_type?.trim() || void 0;
1285
+ info = await client.request(`/files/${fileId}/info`);
1283
1286
  } catch (infoErr) {
1284
1287
  logger.debug?.(`mattermost: failed to resolve metadata for file ${fileId}: ${String(infoErr)}`);
1285
1288
  }
1289
+ const contentType = info?.mime_type?.trim() || void 0;
1290
+ const fileName = info?.name?.trim();
1286
1291
  out.push({
1287
1292
  contentType,
1293
+ ...fileName ? { fileName } : {},
1288
1294
  kind: mediaKindFromMime(contentType) ?? "unknown"
1289
1295
  });
1290
1296
  }
@@ -1710,9 +1716,9 @@ async function deliverMattermostReplyWithDraftPreview(params) {
1710
1716
  confirmedPreviewDelivery = previewFinalResolution?.confirmedDelivery;
1711
1717
  previewFinalDeliveryText = previewFinalResolution?.deliveryText;
1712
1718
  previewFinalTextAlreadyDelivered = previewFinalResolution?.alreadyDelivered === true && payload.isError !== true;
1713
- useConfirmedPreviewAsWholeFinal = previewFinalTextAlreadyDelivered && !resolveSendableOutboundReplyParts(payload).hasMedia;
1719
+ useConfirmedPreviewAsWholeFinal = previewFinalTextAlreadyDelivered && !resolveSendableOutboundReplyParts(payload).hasMedia && !payload.presentation;
1714
1720
  const previewFinalText = previewFinalResolution?.editText;
1715
- if (hasMedia && !ttsSupplement || typeof previewFinalText !== "string" || payload.isError || !canFinalizeMattermostPreviewInPlace({
1721
+ if (hasMedia && !ttsSupplement || typeof previewFinalText !== "string" || payload.isError || payload.presentation || !canFinalizeMattermostPreviewInPlace({
1716
1722
  kind: params.kind,
1717
1723
  previewRootId: params.effectiveReplyToId,
1718
1724
  threadRootId: params.effectiveReplyToId,
@@ -1858,7 +1864,7 @@ async function dispatchMattermostInboundTurn(monitor, params) {
1858
1864
  const { channelHistories, ctxPayload, eventPlan, historyKey, historyLimit, pinnedMainDmOwner, post, rawText, turnAdoptionLifecycle } = params;
1859
1865
  const { channelId, kind, route, senderId, thread, to } = eventPlan;
1860
1866
  const { effectiveReplyToId } = thread;
1861
- const { deliveryBarrier, replyOptions, replyPipeline: baseReplyPipeline, tableMode, textLimit } = eventPlan.createReplyPlan();
1867
+ const { replyOptions, replyPipeline: baseReplyPipeline, tableMode, textLimit } = eventPlan.createReplyPlan();
1862
1868
  const chunkMode = core.channel.text.resolveChunkMode(cfg, "mattermost", account.accountId);
1863
1869
  const { onModelSelected, typingCallbacks, resolveResponsePrefix, ...dispatcherPipeline } = createChannelMessageReplyPipeline({
1864
1870
  cfg,
@@ -1980,8 +1986,6 @@ async function dispatchMattermostInboundTurn(monitor, params) {
1980
1986
  };
1981
1987
  const dispatcherOptions = {
1982
1988
  ...dispatcherPipeline,
1983
- resolveFollowupAdmissionBarrierTimeoutPolicy: deliveryBarrier.resolveTimeoutPolicy,
1984
- onDeliverySettled: deliveryBarrier.markDeliverySettled,
1985
1989
  humanDelay: resolveHumanDelayConfig(cfg, route.agentId),
1986
1990
  typingCallbacks
1987
1991
  };
@@ -2021,7 +2025,7 @@ async function dispatchMattermostInboundTurn(monitor, params) {
2021
2025
  core,
2022
2026
  cfg,
2023
2027
  payload: resolvedPayload,
2024
- to,
2028
+ channelId,
2025
2029
  accountId: account.accountId,
2026
2030
  agentId: route.agentId,
2027
2031
  replyToId: resolveMattermostReplyRootId({
@@ -2031,8 +2035,7 @@ async function dispatchMattermostInboundTurn(monitor, params) {
2031
2035
  }),
2032
2036
  textLimit,
2033
2037
  tableMode,
2034
- sendMessage: sendMessageMattermost,
2035
- onDmChannelResolution: deliveryBarrier.trackDmChannelResolution
2038
+ sendMessage: sendMessageMattermost
2036
2039
  }).catch((error) => {
2037
2040
  if (isChannelPartialDeliveryError(error)) markThreadParticipation();
2038
2041
  throw error;
@@ -2205,7 +2208,7 @@ function createMattermostPostHandler(monitor) {
2205
2208
  const { account, botUserId, botUsername, cfg, core, groupPolicy, pairing, resources } = monitor;
2206
2209
  const { resolveMattermostMedia, resolveUserInfo } = resources;
2207
2210
  const channelHistories = /* @__PURE__ */ new Map();
2208
- const historyLimit = Math.max(0, cfg.messages?.groupChat?.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
2211
+ const historyLimit = Math.max(0, account.config.historyLimit ?? cfg.messages?.groupChat?.historyLimit ?? DEFAULT_GROUP_HISTORY_LIMIT);
2209
2212
  return async (post, payload, turnAdoptionLifecycle, messageIds) => {
2210
2213
  const channelId = post.channel_id ?? payload.data?.channel_id ?? payload.broadcast?.channel_id;
2211
2214
  if (!channelId) {
@@ -2217,11 +2220,7 @@ function createMattermostPostHandler(monitor) {
2217
2220
  return;
2218
2221
  }
2219
2222
  const allMessageIds = messageIds?.length ? messageIds : [post.id];
2220
- const senderId = post.user_id ?? payload.broadcast?.user_id;
2221
- if (!senderId) {
2222
- monitor.logVerboseMessage("mattermost: drop post (missing sender id)");
2223
- return;
2224
- }
2223
+ const senderId = post.user_id;
2225
2224
  if (senderId === botUserId) {
2226
2225
  monitor.logVerboseMessage(`mattermost: drop post (self sender=${senderId})`);
2227
2226
  return;
@@ -2308,7 +2307,7 @@ function createMattermostPostHandler(monitor) {
2308
2307
  });
2309
2308
  monitor.logVerboseMessage(`mattermost: pairing request sender=${senderId} created=${created}`);
2310
2309
  if (created) try {
2311
- await sendMessageMattermost(`user:${senderId}`, core.channel.pairing.buildPairingReply({
2310
+ await sendMessageMattermost(`channel:${channelId}`, core.channel.pairing.buildPairingReply({
2312
2311
  channel: "mattermost",
2313
2312
  idLine: `Your Mattermost user id: ${senderId}`,
2314
2313
  code
@@ -2363,7 +2362,7 @@ function createMattermostPostHandler(monitor) {
2363
2362
  return;
2364
2363
  }
2365
2364
  const mentionRegexes = core.channel.mentions.buildMentionRegexes(cfg, route.agentId);
2366
- const wasMentioned = kind !== "direct" && ((botUsername ? normalizeLowercaseStringOrEmpty(rawText).includes(`@${normalizeLowercaseStringOrEmpty(botUsername)}`) : false) || core.channel.mentions.matchesMentionPatterns(rawText, mentionRegexes));
2365
+ const wasMentioned = kind !== "direct" && (matchesMattermostBotMention(rawText, botUsername) || core.channel.mentions.matchesMentionPatterns(rawText, mentionRegexes));
2367
2366
  const oncharEnabled = account.chatmode === "onchar" && kind !== "direct";
2368
2367
  const oncharPrefixes = oncharEnabled ? resolveOncharPrefixes(account.oncharPrefixes) : [];
2369
2368
  const oncharResult = oncharEnabled ? stripOncharPrefix(rawText, oncharPrefixes) : {
@@ -2903,12 +2902,12 @@ async function monitorMattermostProvider(opts = {}) {
2903
2902
  }),
2904
2903
  buildKey: (entry) => {
2905
2904
  const channelId = entry.post.channel_id ?? entry.payload.data?.channel_id ?? entry.payload.broadcast?.channel_id;
2906
- if (!channelId) return null;
2905
+ if (!channelId || !entry.post.user_id) return null;
2907
2906
  const threadId = normalizeOptionalString(entry.post.root_id);
2908
- return `mattermost:${account.accountId}:${channelId}:${threadId ? `thread:${threadId}` : "channel"}`;
2907
+ return `mattermost:${account.accountId}:${channelId}:${threadId ? `thread:${threadId}` : "channel"}:${entry.post.user_id}`;
2909
2908
  },
2910
2909
  shouldDebounce: (entry) => {
2911
- if (entry.post.file_ids?.length) return false;
2910
+ if (normalizeOptionalString(entry.post.type) !== void 0 || entry.post.file_ids?.length) return false;
2912
2911
  const text = normalizeOptionalString(entry.post.message) ?? "";
2913
2912
  return Boolean(text) && !core.channel.commands.isControlCommandMessage(text, cfg);
2914
2913
  },
@@ -197,19 +197,6 @@ async function createMattermostDirectChannel(client, userIds, signal, timeoutMs)
197
197
  timeoutMs
198
198
  });
199
199
  }
200
- const DM_REPLY_DELIVERY_BARRIER_SLACK_MS = 6e4;
201
- /** Covers DM creation retries without extending channel-delivery stalls. */
202
- function resolveMattermostReplyDeliveryBarrierTimeoutMs(params) {
203
- if (!params.isDirect) return;
204
- const deliveryCount = Object.values(params.queuedCounts).reduce((sum, count) => sum + count, 0);
205
- if (deliveryCount === 0) return;
206
- const maxRetries = params.dmRetryOptions?.maxRetries ?? 3;
207
- const maxDelayMs = params.dmRetryOptions?.maxDelayMs ?? 1e4;
208
- const timeoutMs = params.dmRetryOptions?.timeoutMs ?? 3e4;
209
- const perDeliveryTimeoutMs = (maxRetries + 1) * timeoutMs + maxRetries * maxDelayMs + DM_REPLY_DELIVERY_BARRIER_SLACK_MS;
210
- const totalTimeoutMs = perDeliveryTimeoutMs * deliveryCount + Math.max(0, params.humanDelayBudgetMs ?? 0);
211
- return resolveTimerTimeoutMs(Number.isFinite(totalTimeoutMs) ? totalTimeoutMs : Number.MAX_SAFE_INTEGER, perDeliveryTimeoutMs);
212
- }
213
200
  const RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
214
201
  "ECONNRESET",
215
202
  "ECONNREFUSED",
@@ -382,4 +369,4 @@ async function uploadMattermostFile(client, params) {
382
369
  return info;
383
370
  }
384
371
  //#endregion
385
- export { resolveMattermostReplyDeliveryBarrierTimeoutMs as _, createMattermostPost as a, uploadMattermostFile as b, fetchMattermostChannelByName as c, fetchMattermostUser as d, fetchMattermostUserByUsername as f, readMattermostError as g, parseMattermostApiStatus as h, createMattermostDirectChannelWithRetry as i, fetchMattermostChannelPosts as l, normalizeMattermostBaseUrl as m, buildMattermostApiUrl as n, deleteMattermostPost as o, fetchMattermostUserTeams as p, createMattermostClient as r, fetchMattermostChannel as s, MattermostPostSchema as t, fetchMattermostMe as u, sendMattermostTyping as v, updateMattermostPost as y };
372
+ export { sendMattermostTyping as _, createMattermostPost as a, fetchMattermostChannelByName as c, fetchMattermostUser as d, fetchMattermostUserByUsername as f, readMattermostError as g, parseMattermostApiStatus as h, createMattermostDirectChannelWithRetry as i, fetchMattermostChannelPosts as l, normalizeMattermostBaseUrl as m, buildMattermostApiUrl as n, deleteMattermostPost as o, fetchMattermostUserTeams as p, createMattermostClient as r, fetchMattermostChannel as s, MattermostPostSchema as t, fetchMattermostMe as u, updateMattermostPost as v, uploadMattermostFile as y };
@@ -1,5 +1,5 @@
1
1
  import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { y as updateMattermostPost } from "./client-B_hd-kwM.js";
2
+ import { v as updateMattermostPost } from "./client-DAIry9-2.js";
3
3
  import { C as resolveClientIp, m as isTrustedProxyAddress, y as readRequestBodyWithLimit } from "./monitor-auth-CVd_4FPD.js";
4
4
  import { createHmac } from "node:crypto";
5
5
  import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
@@ -1,6 +1,7 @@
1
- import { m as normalizeMattermostBaseUrl } from "./client-B_hd-kwM.js";
2
- import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-DAIry9-2.js";
2
+ import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { resolveChannelPreviewStreamMode, resolveChannelStreamingBlockCoalesce, resolveChannelStreamingBlockEnabled, resolveChannelStreamingChunkMode } from "openclaw/plugin-sdk/channel-outbound";
4
+ import { normalizeMessagePresentation, renderMessagePresentationFallbackText, resolveMessagePresentationControlValue } from "openclaw/plugin-sdk/interactive-runtime";
4
5
  import { createAccountListHelpers, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
5
6
  import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
6
7
  import { buildSecretInputSchema, hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
@@ -83,4 +84,68 @@ function resolveMattermostReplyToMode(account, kind) {
83
84
  return account.config.replyToMode ?? "off";
84
85
  }
85
86
  //#endregion
86
- export { resolveMattermostReplyToMode as a, resolveMattermostAccount as i, listMattermostAccountIds as n, buildSecretInputSchema as o, resolveDefaultMattermostAccountId as r, hasConfiguredSecretInput as s, inspectMattermostAccount as t };
87
+ //#region extensions/mattermost/src/normalize.ts
88
+ function resolveMattermostPresentation(params) {
89
+ const presentation = normalizeMessagePresentation(params.presentation);
90
+ return {
91
+ text: !presentation || params.presentationTextMode === "fallback" && params.text !== void 0 ? params.text ?? "" : renderMessagePresentationFallbackText({
92
+ text: params.text,
93
+ presentation
94
+ }),
95
+ buttons: presentation ? presentation.blocks.filter((block) => block.type === "buttons").map((block) => block.buttons.flatMap((button) => {
96
+ if (button.action) return [];
97
+ const value = resolveMessagePresentationControlValue(button);
98
+ return value ? [{
99
+ id: value,
100
+ text: button.label,
101
+ callback_data: value,
102
+ context: { callback_data: value },
103
+ style: button.style
104
+ }] : [];
105
+ })).filter((row) => row.length > 0) : []
106
+ };
107
+ }
108
+ function normalizeMattermostMessagingTarget(raw) {
109
+ const trimmed = raw.trim();
110
+ if (!trimmed) return;
111
+ const lower = normalizeLowercaseStringOrEmpty(trimmed);
112
+ if (lower.startsWith("channel:")) {
113
+ const id = trimmed.slice(8).trim();
114
+ return id ? `channel:${id}` : void 0;
115
+ }
116
+ if (lower.startsWith("group:")) {
117
+ const id = trimmed.slice(6).trim();
118
+ return id ? `channel:${id}` : void 0;
119
+ }
120
+ if (lower.startsWith("user:")) {
121
+ const id = trimmed.slice(5).trim();
122
+ return id ? `user:${id}` : void 0;
123
+ }
124
+ if (lower.startsWith("mattermost:")) {
125
+ const id = trimmed.slice(11).trim();
126
+ return id ? `user:${id}` : void 0;
127
+ }
128
+ if (trimmed.startsWith("@")) {
129
+ const id = trimmed.slice(1).trim();
130
+ return id ? `@${id}` : void 0;
131
+ }
132
+ if (trimmed.startsWith("#")) return;
133
+ }
134
+ /**
135
+ * True when media must be uploaded as a file: any non-empty, non-http(s) value
136
+ * (e.g. a local workspace path) has no address the server can fetch, so the
137
+ * send must require a successful upload rather than degrade to caption text.
138
+ */
139
+ function requiresMattermostMediaUpload(mediaUrl) {
140
+ const trimmed = mediaUrl?.trim();
141
+ return Boolean(trimmed && !/^https?:\/\//i.test(trimmed));
142
+ }
143
+ function looksLikeMattermostTargetId(raw, _normalized) {
144
+ const trimmed = raw.trim();
145
+ if (!trimmed) return false;
146
+ if (/^(user|channel|group|mattermost):/i.test(trimmed)) return true;
147
+ if (trimmed.startsWith("@")) return true;
148
+ return /^[a-z0-9]{26}$/i.test(trimmed) || /^[a-z0-9]{26}__[a-z0-9]{26}$/i.test(trimmed);
149
+ }
150
+ //#endregion
151
+ export { inspectMattermostAccount as a, resolveMattermostAccount as c, hasConfiguredSecretInput as d, resolveMattermostPresentation as i, resolveMattermostReplyToMode as l, normalizeMattermostMessagingTarget as n, listMattermostAccountIds as o, requiresMattermostMediaUpload as r, resolveDefaultMattermostAccountId as s, looksLikeMattermostTargetId as t, buildSecretInputSchema as u };
@@ -1,2 +1,2 @@
1
- import { i as registerSlashCommandRoute } from "./slash-state-DUowGLl4.js";
1
+ import { i as registerSlashCommandRoute } from "./slash-state-CfsJU7WW.js";
2
2
  export { registerSlashCommandRoute };