@openclaw/mattermost 2026.11.3 → 2026.11.5-beta.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 (46) hide show
  1. package/dist/.setup/channel-plugin-api-ClU67Wyc.mjs +1 -0
  2. package/dist/.setup/{channel-plugin-runtime-DJgVmmbD.mjs → channel-plugin-api-CuxSSPV8.mjs} +146 -130
  3. package/dist/.setup/{channel.runtime-Cl_09ZUI.mjs → channel.runtime-B3RvYLQi.mjs} +28 -34
  4. package/dist/.setup/{client-B_4C9q6z.mjs → client-CR-hGmGr.mjs} +11 -84
  5. package/dist/.setup/{interactions-LQ_rJSdf.mjs → interactions-D5hhyPam.mjs} +23 -36
  6. package/dist/.setup/{monitor-CmsQnrEk.mjs → monitor-Bw_pTSF8.mjs} +292 -400
  7. package/dist/.setup/{monitor-auth-rr4M-8gH.mjs → monitor-auth-BxpEUfvc.mjs} +5 -11
  8. package/dist/.setup/{normalize-Dli2PK7k.mjs → normalize-CNFRtT1O.mjs} +21 -7
  9. package/dist/.setup/secret-contract-api-Drz4m5pq.mjs +2 -0
  10. package/dist/.setup/{send-C_-GT5iF.mjs → send-BSae9PKV.mjs} +100 -198
  11. package/dist/.setup/{slash-state-DJN_cER0.mjs → slash-state-DpZH2wr6.mjs} +362 -409
  12. package/dist/.source-module-urls/8fb0cb1067b83fd2cf3f3ba0f7a23e627c27e8e3adf1a4ea18753ddb884ff71e.json +1 -0
  13. package/dist/api.js +2 -2
  14. package/dist/channel-plugin-api.js +1 -2
  15. package/dist/doctor-contract-api.js +1 -2
  16. package/dist/gateway-auth-api.js +1 -2
  17. package/dist/policy-api.js +1 -2
  18. package/dist/runtime-api.js +1 -2
  19. package/dist/secret-contract-api.js +1 -2
  20. package/dist/setup-entry.js +2 -2
  21. package/dist/slash-route-api.js +1 -2
  22. package/node_modules/zod/package.json +1 -1
  23. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  24. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  25. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  26. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  27. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  28. package/node_modules/zod/src/v4/core/util.ts +13 -0
  29. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  30. package/node_modules/zod/v4/core/compile.cjs +8 -0
  31. package/node_modules/zod/v4/core/compile.js +8 -0
  32. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  33. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  34. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  35. package/node_modules/zod/v4/core/schemas.js +30 -0
  36. package/node_modules/zod/v4/core/util.cjs +15 -0
  37. package/node_modules/zod/v4/core/util.d.cts +2 -0
  38. package/node_modules/zod/v4/core/util.d.ts +2 -0
  39. package/node_modules/zod/v4/core/util.js +14 -0
  40. package/node_modules/zod/v4/core/versions.cjs +1 -1
  41. package/node_modules/zod/v4/core/versions.js +1 -1
  42. package/openclaw.plugin.json +172 -0
  43. package/package.json +5 -5
  44. package/dist/.setup/channel-plugin-api-BKpd51G7.mjs +0 -3
  45. package/dist/.setup/secret-contract-api-BGz5_6WD.mjs +0 -3
  46. package/dist/channel-plugin-runtime.js +0 -2
@@ -0,0 +1 @@
1
+ export { t as mattermostPlugin, n as mattermostSetupPlugin } from "./channel-plugin-api-CuxSSPV8.mjs";
@@ -1,11 +1,10 @@
1
- import { h as normalizeMattermostBaseUrl } from "./client-B_4C9q6z.mjs";
1
+ import { h as normalizeMattermostBaseUrl } from "./client-CR-hGmGr.mjs";
2
2
  import { t as mattermostIngressIdentity } from "./ingress-identity-D6hxfxvo.mjs";
3
- import { a as resolveMattermostPresentation, c as listMattermostAccountIds, d as resolveMattermostReplyToMode, i as requiresMattermostMediaUpload, l as resolveDefaultMattermostAccountId, n as normalizeMattermostMessagingTarget, o as inspectMattermostAccount, s as isMattermostConfigured$1, t as looksLikeMattermostTargetId, u as resolveMattermostAccount } from "./normalize-Dli2PK7k.mjs";
3
+ import { a as resolveMattermostPresentation, c as isMattermostConfigured, d as resolveMattermostAccount, f as resolveMattermostReplyToMode, i as requiresMattermostMediaUpload, l as listMattermostAccountIds, n as normalizeMattermostMessagingTarget, s as inspectMattermostAccount, t as looksLikeMattermostTargetId, u as resolveDefaultMattermostAccountId } from "./normalize-CNFRtT1O.mjs";
4
4
  import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-Lf99Gilr.mjs";
5
5
  import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-CjgZkyPm.mjs";
6
6
  import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-fjlTFCmD.mjs";
7
7
  import { asOptionalRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
- import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared";
9
8
  import { z } from "zod";
10
9
  import { formatNormalizedAllowFromEntries } from "openclaw/plugin-sdk/allow-from";
11
10
  import { createLoggedPairingApprovalNotifier } from "openclaw/plugin-sdk/channel-pairing";
@@ -19,6 +18,7 @@ import { identityEntryAuthenticationClassifier } from "openclaw/plugin-sdk/chann
19
18
  import { buildChannelGroupsScopeTree, buildMutableAllowEntryDetector, collectStandardAllowlistLists, createDangerousNameMatchingMutableAllowlistWarningCollector, createRestrictSendersChannelSecurity, resolveScopeRequireMention } from "openclaw/plugin-sdk/channel-policy";
20
19
  import { attachChannelToResult, createAttachedChannelResultAdapter } from "openclaw/plugin-sdk/channel-send-result";
21
20
  import { createChannelDirectoryAdapter } from "openclaw/plugin-sdk/directory-runtime";
21
+ import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared";
22
22
  import { resolveMessagePresentationButtonAction } from "openclaw/plugin-sdk/interactive-runtime";
23
23
  import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
24
24
  import { resolvePayloadMediaUrls, sendTextMediaPayload } from "openclaw/plugin-sdk/reply-payload";
@@ -28,9 +28,9 @@ import { textResult } from "openclaw/plugin-sdk/tool-results";
28
28
  import { createChannelApprovalAuth } from "openclaw/plugin-sdk/approval-auth-runtime";
29
29
  import { buildSecretInputSchema, hasConfiguredSecretInput } from "openclaw/plugin-sdk/secret-input";
30
30
  import { adaptScopedAccountAccessor, createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
31
- import { ChannelImplicitMentionsSchema, ChannelPreviewStreamingConfigSchema, ChannelStreamingPreviewSchema, ChannelStreamingProgressSchema, ContextVisibilityModeSchema, DmPolicySchema, GroupPolicySchema, MarkdownConfigSchema, buildChannelConfigSchema, buildGroupEntrySchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
31
+ import { ChannelBotLoopProtectionSchema, ChannelImplicitMentionsSchema, ChannelPreviewStreamingConfigSchema, ChannelStreamingPreviewSchema, ChannelStreamingProgressSchema, ContextVisibilityModeSchema, DmPolicySchema, GroupPolicySchema, MarkdownConfigSchema, buildChannelAllowBotsSchema, buildChannelConfigSchema, buildGroupEntrySchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
32
32
  import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
33
- import { applyAccountNameToChannelSection, applySetupAccountConfigPatch, baseUrlTextInput, createSetupTranslator, createStandardChannelSetupStatus, defineTokenCredential, formatDocsLink, migrateBaseNameToDefaultAccount, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
33
+ import { applyAccountNameToChannelSection, applySetupAccountConfigPatch, baseUrlTextInput, createSetupTranslator, createStandardChannelSetupStatus, defineTokenCredential, formatDocsLink, prepareScopedSetupConfig, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
34
34
  import { createSetupInputPresenceValidator } from "openclaw/plugin-sdk/setup-runtime";
35
35
  //#region extensions/mattermost/src/approval-auth.ts
36
36
  const MATTERMOST_USER_ID_RE = /^[a-z0-9]{26}$/;
@@ -95,7 +95,7 @@ const mattermostConfigAdapter = createScopedChannelConfigAdapter({
95
95
  function describeMattermostAccount(account) {
96
96
  return describeAccountSnapshot({
97
97
  account,
98
- configured: isMattermostConfigured$1(account),
98
+ configured: isMattermostConfigured(account),
99
99
  extra: {
100
100
  botTokenSource: account.botTokenSource,
101
101
  botTokenStatus: account.botTokenStatus,
@@ -122,7 +122,11 @@ function createMattermostDeliveryProgressReporter(onDeliveryResult) {
122
122
  }
123
123
  //#endregion
124
124
  //#region extensions/mattermost/src/config-schema-core.ts
125
- const MattermostGroupSchema = buildGroupEntrySchema({ requireMentionInBotThreads: z.boolean().optional() }).omit({
125
+ const MattermostGroupSchema = buildGroupEntrySchema({
126
+ requireMentionInBotThreads: z.boolean().optional(),
127
+ allowBots: buildChannelAllowBotsSchema({ allowMentions: true }),
128
+ botLoopProtection: ChannelBotLoopProtectionSchema.optional()
129
+ }).omit({
126
130
  tools: true,
127
131
  toolsBySender: true,
128
132
  skills: true,
@@ -197,6 +201,8 @@ const MattermostAccountSchemaBase = z.object({
197
201
  oncharPrefixes: z.array(z.string()).optional(),
198
202
  requireMention: z.boolean().optional(),
199
203
  requireMentionInBotThreads: z.boolean().optional(),
204
+ allowBots: buildChannelAllowBotsSchema({ allowMentions: true }),
205
+ botLoopProtection: ChannelBotLoopProtectionSchema.optional(),
200
206
  implicitMentions: ChannelImplicitMentionsSchema.optional(),
201
207
  dmPolicy: DmPolicySchema.optional().default("pairing"),
202
208
  allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
@@ -220,7 +226,6 @@ const MattermostAccountSchemaBase = z.object({
220
226
  groups: z.record(z.string(), MattermostGroupSchema.optional()).optional(),
221
227
  /** Network policy overrides for self-hosted Mattermost on trusted private/internal hosts. */
222
228
  network: MattermostNetworkSchema,
223
- /** Retry configuration for DM channel creation */
224
229
  dmChannelRetry: DmChannelRetrySchema
225
230
  }).strict();
226
231
  const MattermostConfigSchema = buildMultiAccountChannelSchema(MattermostAccountSchemaBase, {
@@ -236,7 +241,7 @@ const MattermostConfigSchema = buildMultiAccountChannelSchema(MattermostAccountS
236
241
  }
237
242
  });
238
243
  //#endregion
239
- //#region extensions/mattermost/src/config-ui-hints.ts
244
+ //#region extensions/mattermost/src/config-surface.ts
240
245
  const mattermostChannelConfigUiHints = {
241
246
  "": {
242
247
  label: "Mattermost",
@@ -250,6 +255,38 @@ const mattermostChannelConfigUiHints = {
250
255
  label: "Mention in Bot Threads",
251
256
  help: "Override bot-created thread mention policy for this Mattermost channel. Exact channel settings override the wildcard, then the account setting."
252
257
  },
258
+ allowBots: {
259
+ label: "Mattermost Allow Bot Posts",
260
+ help: "Allow posts from Mattermost bot accounts to trigger replies (default: true). Set false to ignore them, or \"mentions\" to require an explicit @mention or onchar trigger in channels; thread participation does not count. Access, mention, and loop-protection rules still apply."
261
+ },
262
+ "groups.*.allowBots": {
263
+ label: "Mattermost Allow Bot Posts",
264
+ help: "Override allowBots for this Mattermost channel. Exact channel settings override the wildcard, then the account setting."
265
+ },
266
+ botLoopProtection: {
267
+ label: "Mattermost Bot Loop Protection",
268
+ help: "Sliding-window guard for Mattermost bot-to-bot loops. Default is enabled whenever allowBots lets bot posts reach dispatch."
269
+ },
270
+ "botLoopProtection.enabled": {
271
+ label: "Mattermost Bot Loop Protection Enabled",
272
+ help: "Enable the bot-pair loop guard. Defaults to true when allowBots is true or \"mentions\"; bot posts are ignored when allowBots is false."
273
+ },
274
+ "botLoopProtection.maxEventsPerWindow": {
275
+ label: "Mattermost Bot Loop Events per Window",
276
+ help: "Maximum accepted bot-pair posts within the sliding window before suppression starts. Default: 20."
277
+ },
278
+ "botLoopProtection.windowSeconds": {
279
+ label: "Mattermost Bot Loop Window Seconds",
280
+ help: "Sliding window length for counting bot-pair posts. Default: 60."
281
+ },
282
+ "botLoopProtection.cooldownSeconds": {
283
+ label: "Mattermost Bot Loop Cooldown Seconds",
284
+ help: "How long to suppress the bot pair after it exceeds the budget. Default: 60."
285
+ },
286
+ "groups.*.botLoopProtection": {
287
+ label: "Mattermost Channel Bot Loop Protection",
288
+ help: "Per-channel loop guard overrides, merged key by key over the wildcard and account settings."
289
+ },
253
290
  ...createChannelConfigUiHints({
254
291
  channelLabel: "Mattermost",
255
292
  dmPolicy: { channelKey: "mattermost" },
@@ -265,28 +302,19 @@ const mattermostChannelConfigUiHints = {
265
302
  progress: {}
266
303
  })
267
304
  };
268
- //#endregion
269
- //#region extensions/mattermost/src/config-surface.ts
270
305
  const MattermostChannelConfigSchema = buildChannelConfigSchema(MattermostConfigSchema, { uiHints: mattermostChannelConfigUiHints });
271
306
  //#endregion
272
307
  //#region extensions/mattermost/src/setup-core.ts
273
308
  const channel$1 = "mattermost";
274
- function isMattermostConfigured(account) {
275
- return (Boolean(account.botToken?.trim()) || hasConfiguredSecretInput(account.config.botToken)) && Boolean(account.baseUrl);
276
- }
277
309
  function applyMattermostSetupConfigPatch(params) {
278
- const namedConfig = applyAccountNameToChannelSection({
279
- cfg: params.cfg,
280
- channelKey: channel$1,
281
- accountId: params.accountId,
282
- name: params.name
283
- });
284
- const next = params.accountId !== DEFAULT_ACCOUNT_ID ? migrateBaseNameToDefaultAccount({
285
- cfg: namedConfig,
286
- channelKey: channel$1
287
- }) : namedConfig;
288
310
  return applySetupAccountConfigPatch({
289
- cfg: next,
311
+ cfg: prepareScopedSetupConfig({
312
+ cfg: params.cfg,
313
+ channelKey: channel$1,
314
+ accountId: params.accountId,
315
+ name: params.name,
316
+ migrateBaseName: true
317
+ }),
290
318
  channelKey: channel$1,
291
319
  accountId: params.accountId,
292
320
  patch: params.patch
@@ -464,7 +492,7 @@ const mattermostSetupWizard = {
464
492
  //#region extensions/mattermost/src/channel.setup.ts
465
493
  const mattermostSetupPlugin = {
466
494
  id: "mattermost",
467
- meta: { ...mattermostMeta },
495
+ meta: mattermostMeta,
468
496
  capabilities: {
469
497
  chatTypes: [
470
498
  "direct",
@@ -489,7 +517,7 @@ const mattermostSetupPlugin = {
489
517
  configSchema: MattermostChannelConfigSchema,
490
518
  config: {
491
519
  ...mattermostConfigAdapter,
492
- isConfigured: isMattermostConfigured$1,
520
+ isConfigured: isMattermostConfigured,
493
521
  describeAccount: describeMattermostAccount
494
522
  },
495
523
  gateway: { resolveGatewayAuthBypassPaths: resolveMattermostGatewayAuthBypassPaths },
@@ -630,7 +658,7 @@ function resolveMattermostOutboundSessionRoute(params) {
630
658
  }
631
659
  //#endregion
632
660
  //#region extensions/mattermost/src/channel.ts
633
- const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-Cl_09ZUI.mjs"));
661
+ const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-B3RvYLQi.mjs"));
634
662
  const MATTERMOST_PRESENTATION_CAPABILITIES = {
635
663
  supported: true,
636
664
  buttons: true,
@@ -645,9 +673,6 @@ function hasMattermostPresentationNavigation(presentation) {
645
673
  return action?.type === "url" || action?.type === "web-app" && Boolean(action.url);
646
674
  }));
647
675
  }
648
- function readMattermostPayloadData(payload) {
649
- return asOptionalRecord(payload.channelData?.mattermost);
650
- }
651
676
  const mattermostSecurityAdapter = createRestrictSendersChannelSecurity({
652
677
  channelKey: "mattermost",
653
678
  resolveDmPolicy: (account) => account.config.dmPolicy,
@@ -671,87 +696,15 @@ function listEnabledMattermostAccounts({ cfg, accountId }) {
671
696
  accountId: listedAccountId
672
697
  }))).filter((account) => account.enabled && account.botToken?.trim() && account.baseUrl?.trim());
673
698
  }
674
- function describeMattermostMessageTool({ cfg, accountId }) {
675
- const enabledAccounts = listEnabledMattermostAccounts({
676
- cfg,
677
- accountId
678
- });
679
- const actions = [];
680
- if (enabledAccounts.length > 0) actions.push("send");
681
- const actionsConfig = (cfg.channels?.mattermost)?.actions;
682
- const baseMessages = actionsConfig?.messages;
683
- const baseReactions = actionsConfig?.reactions;
684
- if (enabledAccounts.some((account) => {
685
- return account.config.actions?.reactions ?? baseReactions ?? true;
686
- })) actions.push("react");
687
- if (enabledAccounts.some((account) => account.config.actions?.messages ?? baseMessages ?? false)) actions.push("read");
688
- return {
689
- actions,
690
- capabilities: enabledAccounts.length > 0 ? ["presentation"] : []
691
- };
692
- }
693
- function extractMattermostToolSend(args) {
694
- if (normalizeOptionalString(args.action) !== "send") return null;
695
- const to = normalizeOptionalString(args.to) ?? normalizeOptionalString(args.target);
696
- if (!to) return null;
697
- const threadId = normalizeOptionalString(args.threadId) ?? normalizeOptionalString(args.replyToId) ?? normalizeOptionalString(args.replyTo);
698
- const threadSuppressed = args.topLevel === true || args.threadId === null;
699
- return {
700
- to,
701
- accountId: normalizeOptionalString(args.accountId),
702
- ...threadId ? { threadId } : {},
703
- ...!threadId && !threadSuppressed ? { threadImplicit: true } : {},
704
- ...threadSuppressed ? { threadSuppressed: true } : {}
705
- };
706
- }
707
- function resolveMattermostAutoThreadId(params) {
708
- const replyToId = normalizeOptionalString(params.replyToId);
709
- const context = params.toolContext;
710
- const currentThreadId = normalizeOptionalString(context?.currentThreadTs);
711
- const currentMessageId = normalizeMattermostThreadId(context?.currentMessageId);
712
- const currentTarget = normalizeMattermostThreadTarget(context?.currentChannelId);
713
- if (currentThreadId && currentTarget === normalizeMattermostThreadTarget(params.to)) {
714
- if (replyToId === currentMessageId) return currentThreadId;
715
- if (!replyToId) {
716
- const replyToMode = context?.replyToMode;
717
- return replyToMode === "all" || replyToMode === "first" && context?.hasRepliedRef?.value !== true ? currentThreadId : void 0;
718
- }
719
- }
720
- return replyToId;
721
- }
722
699
  function normalizeMattermostThreadTarget(raw) {
723
700
  const normalized = raw ? normalizeMattermostMessagingTarget(raw) : void 0;
724
701
  if (normalized) return normalized;
725
702
  const trimmed = normalizeOptionalString(raw);
726
703
  return trimmed && /^[a-z0-9]{26}$/i.test(trimmed) ? `channel:${trimmed}` : void 0;
727
704
  }
728
- function matchesMattermostToolContextTarget(params) {
729
- const target = normalizeMattermostThreadTarget(params.target);
730
- if (!target) return false;
731
- return [params.toolContext.currentChannelId, params.toolContext.currentMessagingTarget].some((currentTarget) => normalizeMattermostThreadTarget(currentTarget) === target);
732
- }
733
705
  function normalizeMattermostThreadId(value) {
734
706
  return typeof value === "number" ? String(value) : normalizeOptionalString(value);
735
707
  }
736
- function buildMattermostThreadingToolContext(params) {
737
- const account = resolveMattermostAccount({
738
- cfg: params.cfg,
739
- accountId: params.accountId ?? resolveDefaultMattermostAccountId(params.cfg)
740
- });
741
- const chatType = params.context.ChatType === "direct" || params.context.ChatType === "group" || params.context.ChatType === "channel" ? params.context.ChatType : "channel";
742
- const configuredReplyToMode = resolveMattermostReplyToMode(account, chatType);
743
- const currentThreadTs = normalizeMattermostThreadId(params.context.MessageThreadId) ?? normalizeMattermostThreadId(params.context.TransportThreadId) ?? normalizeOptionalString(params.context.ReplyToId);
744
- const currentMessageId = normalizeMattermostThreadId(params.context.CurrentMessageId);
745
- const hasExistingThread = Boolean(currentThreadTs) && (!currentMessageId || currentThreadTs !== currentMessageId);
746
- return {
747
- currentChannelId: params.context.To ? normalizeMattermostMessagingTarget(params.context.To) : void 0,
748
- currentThreadTs,
749
- currentMessageId: params.context.CurrentMessageId,
750
- replyToMode: hasExistingThread ? "all" : configuredReplyToMode,
751
- hasRepliedRef: params.hasRepliedRef,
752
- sameChannelThreadRequired: Boolean(currentThreadTs)
753
- };
754
- }
755
708
  async function listMattermostDirectoryGroups(params) {
756
709
  if (listEnabledMattermostAccounts(params).length === 0) return [];
757
710
  return (await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params);
@@ -763,13 +716,44 @@ async function listMattermostDirectoryPeers(params) {
763
716
  const mattermostMessageActions = {
764
717
  providerOwnedReadGates: ["read"],
765
718
  readAuthorityActions: ["read"],
766
- describeMessageTool: describeMattermostMessageTool,
767
- extractToolSend: ({ args }) => extractMattermostToolSend(args),
719
+ describeMessageTool({ cfg, accountId }) {
720
+ const enabledAccounts = listEnabledMattermostAccounts({
721
+ cfg,
722
+ accountId
723
+ });
724
+ const actions = [];
725
+ if (enabledAccounts.length > 0) actions.push("send");
726
+ const actionsConfig = (cfg.channels?.mattermost)?.actions;
727
+ const baseMessages = actionsConfig?.messages;
728
+ const baseReactions = actionsConfig?.reactions;
729
+ if (enabledAccounts.some((account) => {
730
+ return account.config.actions?.reactions ?? baseReactions ?? true;
731
+ })) actions.push("react");
732
+ if (enabledAccounts.some((account) => account.config.actions?.messages ?? baseMessages ?? false)) actions.push("read");
733
+ return {
734
+ actions,
735
+ capabilities: enabledAccounts.length > 0 ? ["presentation"] : []
736
+ };
737
+ },
738
+ extractToolSend({ args }) {
739
+ if (normalizeOptionalString(args.action) !== "send") return null;
740
+ const to = normalizeOptionalString(args.to) ?? normalizeOptionalString(args.target);
741
+ if (!to) return null;
742
+ const threadId = normalizeOptionalString(args.threadId) ?? normalizeOptionalString(args.replyToId) ?? normalizeOptionalString(args.replyTo);
743
+ const threadSuppressed = args.topLevel === true || args.threadId === null;
744
+ return {
745
+ to,
746
+ accountId: normalizeOptionalString(args.accountId),
747
+ ...threadId ? { threadId } : {},
748
+ ...!threadId && !threadSuppressed ? { threadImplicit: true } : {},
749
+ ...threadSuppressed ? { threadSuppressed: true } : {}
750
+ };
751
+ },
768
752
  prepareSendPayload: ({ ctx, payload }) => {
769
753
  if (ctx.action !== "send") return null;
770
754
  const mediaUrl = resolveMattermostSendAttachmentMedia(ctx.params);
771
755
  const attachmentText = typeof ctx.params.attachmentText === "string" ? ctx.params.attachmentText : void 0;
772
- const existingMattermostData = readMattermostPayloadData(payload);
756
+ const existingMattermostData = asOptionalRecord(payload.channelData?.mattermost);
773
757
  return {
774
758
  ...payload,
775
759
  ...mediaUrl ? {
@@ -826,7 +810,11 @@ const mattermostMessageActions = {
826
810
  });
827
811
  }
828
812
  if (!(account.config.actions?.reactions ?? actionsConfig?.reactions ?? true)) throw new Error("Mattermost reactions are disabled in config");
829
- const { postId, emojiName, remove } = parseMattermostReactActionParams(params);
813
+ const postId = normalizeOptionalString(params.messageId) ?? normalizeOptionalString(params.postId);
814
+ if (!postId) throw new Error("Mattermost react requires messageId (post id)");
815
+ const emojiName = normalizeMattermostEmojiName(normalizeOptionalString(params.emoji));
816
+ if (!emojiName) throw new Error("Mattermost react requires emoji");
817
+ const remove = params.remove === true;
830
818
  const authorizedTarget = normalizeOptionalString(params.to);
831
819
  const runtime = await loadMattermostChannelRuntime();
832
820
  const result = await (remove ? runtime.removeMattermostReaction : runtime.addMattermostReaction)({
@@ -841,16 +829,11 @@ const mattermostMessageActions = {
841
829
  return textResult(remove ? `Removed reaction :${emojiName}: from ${postId}` : `Reacted with :${emojiName}: on ${postId}`, {});
842
830
  }
843
831
  };
844
- function parseMattermostReactActionParams(params) {
845
- const postId = normalizeOptionalString(params.messageId) ?? normalizeOptionalString(params.postId);
846
- if (!postId) throw new Error("Mattermost react requires messageId (post id)");
847
- const emojiName = normalizeMattermostEmojiName(normalizeOptionalString(params.emoji));
848
- if (!emojiName) throw new Error("Mattermost react requires emoji");
849
- return {
850
- postId,
851
- emojiName,
852
- remove: params.remove === true
853
- };
832
+ function hasUnsupportedMattermostAttachmentPayload(record) {
833
+ return ["buffer", "base64"].some((key) => {
834
+ const value = record[key];
835
+ return typeof value === "string" ? Boolean(value.trim()) : value != null;
836
+ });
854
837
  }
855
838
  function resolveMattermostSendAttachmentMedia(params) {
856
839
  const sourceKeys = [
@@ -862,13 +845,13 @@ function resolveMattermostSendAttachmentMedia(params) {
862
845
  ];
863
846
  const candidates = sourceKeys.map((key) => readStringParam(params, key));
864
847
  candidates.push(...readStringArrayParam(params, "mediaUrls") ?? []);
865
- let hasUnsupportedAttachmentPayload = Boolean(readStringParam(params, "buffer") ?? readStringParam(params, "base64"));
848
+ let hasUnsupportedAttachmentPayload = hasUnsupportedMattermostAttachmentPayload(params);
866
849
  if (Array.isArray(params.attachments)) for (const attachment of params.attachments) {
867
850
  if (!attachment || typeof attachment !== "object" || Array.isArray(attachment)) continue;
868
851
  const record = attachment;
869
852
  candidates.push(...sourceKeys.map((key) => readStringParam(record, key)));
870
853
  candidates.push(readStringParam(record, "url"));
871
- hasUnsupportedAttachmentPayload ||= Boolean(readStringParam(record, "buffer") ?? readStringParam(record, "base64"));
854
+ hasUnsupportedAttachmentPayload ||= hasUnsupportedMattermostAttachmentPayload(record);
872
855
  }
873
856
  if (hasUnsupportedAttachmentPayload) throw new Error("Mattermost send attachments require media, mediaUrl, path, filePath, fileUrl, mediaUrls, or attachments[] with one of those fields; buffer/base64 payloads are not supported.");
874
857
  const mediaUrls = [...new Set(candidates.filter((candidate) => Boolean(candidate)))];
@@ -928,7 +911,7 @@ const mattermostOutbound = {
928
911
  };
929
912
  },
930
913
  sendPayload: async (ctx) => {
931
- const mattermostData = readMattermostPayloadData(ctx.payload);
914
+ const mattermostData = asOptionalRecord(ctx.payload.channelData?.mattermost);
932
915
  const buttons = Array.isArray(mattermostData?.presentationButtons) ? mattermostData.presentationButtons : void 0;
933
916
  const rawAttachmentText = mattermostData?.attachmentText;
934
917
  const attachmentText = typeof rawAttachmentText === "string" ? rawAttachmentText : void 0;
@@ -1093,18 +1076,15 @@ const mattermostPlugin = createChatChannelPlugin({
1093
1076
  ...mattermostSetupPlugin.gateway,
1094
1077
  startAccount: async (ctx) => {
1095
1078
  const account = ctx.account;
1096
- const statusSink = createAccountStatusSink({
1097
- accountId: ctx.accountId,
1098
- setStatus: ctx.setStatus
1099
- });
1079
+ const statusSink = createAccountStatusSink(ctx);
1100
1080
  statusSink({
1101
1081
  baseUrl: account.baseUrl,
1102
1082
  botTokenSource: account.botTokenSource
1103
1083
  });
1104
1084
  ctx.log?.info(`[${account.accountId}] starting channel`);
1105
- return (await import("./monitor-CmsQnrEk.mjs")).monitorMattermostProvider({
1106
- botToken: account.botToken ?? void 0,
1107
- baseUrl: account.baseUrl ?? void 0,
1085
+ return (await import("./monitor-Bw_pTSF8.mjs")).monitorMattermostProvider({
1086
+ botToken: account.botToken,
1087
+ baseUrl: account.baseUrl,
1108
1088
  accountId: account.accountId,
1109
1089
  config: ctx.cfg,
1110
1090
  runtime: ctx.runtime,
@@ -1121,7 +1101,25 @@ const mattermostPlugin = createChatChannelPlugin({
1121
1101
  notify: createLoggedPairingApprovalNotifier(({ id }) => `[mattermost] User ${id} approved for pairing`)
1122
1102
  } },
1123
1103
  threading: {
1124
- buildToolContext: buildMattermostThreadingToolContext,
1104
+ buildToolContext(params) {
1105
+ const account = resolveMattermostAccount({
1106
+ cfg: params.cfg,
1107
+ accountId: params.accountId ?? resolveDefaultMattermostAccountId(params.cfg)
1108
+ });
1109
+ const chatType = params.context.ChatType === "direct" || params.context.ChatType === "group" || params.context.ChatType === "channel" ? params.context.ChatType : "channel";
1110
+ const configuredReplyToMode = resolveMattermostReplyToMode(account, chatType);
1111
+ const currentThreadTs = normalizeMattermostThreadId(params.context.MessageThreadId) ?? normalizeMattermostThreadId(params.context.TransportThreadId) ?? normalizeOptionalString(params.context.ReplyToId);
1112
+ const currentMessageId = normalizeMattermostThreadId(params.context.CurrentMessageId);
1113
+ const hasExistingThread = Boolean(currentThreadTs) && (!currentMessageId || currentThreadTs !== currentMessageId);
1114
+ return {
1115
+ currentChannelId: params.context.To ? normalizeMattermostMessagingTarget(params.context.To) : void 0,
1116
+ currentThreadTs,
1117
+ currentMessageId: params.context.CurrentMessageId,
1118
+ replyToMode: hasExistingThread ? "all" : configuredReplyToMode,
1119
+ hasRepliedRef: params.hasRepliedRef,
1120
+ sameChannelThreadRequired: Boolean(currentThreadTs)
1121
+ };
1122
+ },
1125
1123
  scopedAccountReplyToMode: {
1126
1124
  resolveAccount: (cfg, accountId) => resolveMattermostAccount({
1127
1125
  cfg,
@@ -1129,8 +1127,26 @@ const mattermostPlugin = createChatChannelPlugin({
1129
1127
  }),
1130
1128
  resolveReplyToMode: (account, chatType) => resolveMattermostReplyToMode(account, chatType === "direct" || chatType === "group" || chatType === "channel" ? chatType : "channel")
1131
1129
  },
1132
- resolveAutoThreadId: resolveMattermostAutoThreadId,
1133
- matchesToolContextTarget: matchesMattermostToolContextTarget,
1130
+ resolveAutoThreadId(params) {
1131
+ const replyToId = normalizeOptionalString(params.replyToId);
1132
+ const context = params.toolContext;
1133
+ const currentThreadId = normalizeOptionalString(context?.currentThreadTs);
1134
+ const currentMessageId = normalizeMattermostThreadId(context?.currentMessageId);
1135
+ const currentTarget = normalizeMattermostThreadTarget(context?.currentChannelId);
1136
+ if (currentThreadId && currentTarget === normalizeMattermostThreadTarget(params.to)) {
1137
+ if (replyToId === currentMessageId) return currentThreadId;
1138
+ if (!replyToId) {
1139
+ const replyToMode = context?.replyToMode;
1140
+ return replyToMode === "all" || replyToMode === "first" && context?.hasRepliedRef?.value !== true ? currentThreadId : void 0;
1141
+ }
1142
+ }
1143
+ return replyToId;
1144
+ },
1145
+ matchesToolContextTarget(params) {
1146
+ const target = normalizeMattermostThreadTarget(params.target);
1147
+ if (!target) return false;
1148
+ return [params.toolContext.currentChannelId, params.toolContext.currentMessagingTarget].some((currentTarget) => normalizeMattermostThreadTarget(currentTarget) === target);
1149
+ },
1134
1150
  resolveReplyTransport: ({ threadId, replyToId, replyToIsExplicit, replyDelivery }) => {
1135
1151
  const ambientThreadId = threadId != null ? String(threadId) : void 0;
1136
1152
  const isFlatDirect = replyDelivery?.chatType === "direct" && replyDelivery.replyToMode === "off";
@@ -1,7 +1,7 @@
1
- import { _ as readMattermostError, h as normalizeMattermostBaseUrl, l as fetchMattermostChannelPosts, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe } from "./client-B_4C9q6z.mjs";
2
- import { s as resolveMattermostTrustedChatKind } from "./monitor-auth-rr4M-8gH.mjs";
3
- import { c as listMattermostAccountIds, n as normalizeMattermostMessagingTarget, o as inspectMattermostAccount, u as resolveMattermostAccount } from "./normalize-Dli2PK7k.mjs";
4
- import { n as resolveMattermostOpaqueTarget, t as sendMessageMattermost } from "./send-C_-GT5iF.mjs";
1
+ import { _ as readMattermostError, h as normalizeMattermostBaseUrl, l as fetchMattermostChannelPosts, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe } from "./client-CR-hGmGr.mjs";
2
+ import { s as resolveMattermostTrustedChatKind } from "./monitor-auth-BxpEUfvc.mjs";
3
+ import { d as resolveMattermostAccount, l as listMattermostAccountIds, n as normalizeMattermostMessagingTarget, s as inspectMattermostAccount } from "./normalize-CNFRtT1O.mjs";
4
+ import { n as resolveMattermostOpaqueTarget, t as sendMessageMattermost } from "./send-BSae9PKV.mjs";
5
5
  import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
6
6
  import { runChannelProbe } from "openclaw/plugin-sdk/text-utility-runtime";
7
7
  import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
@@ -51,7 +51,7 @@ function buildClients(params) {
51
51
  async function listMattermostDirectoryGroups(params) {
52
52
  const clients = buildClients(params);
53
53
  if (!clients.length) return [];
54
- const q = normalizeLowercaseStringOrEmpty(params.query);
54
+ const q = normalizeLowercaseStringOrEmpty(params.query).normalize("NFC");
55
55
  const seenIds = /* @__PURE__ */ new Set();
56
56
  const entries = [];
57
57
  for (const client of clients) try {
@@ -61,8 +61,8 @@ async function listMattermostDirectoryGroups(params) {
61
61
  if (ch.type !== "O" && ch.type !== "P") continue;
62
62
  if (seenIds.has(ch.id)) continue;
63
63
  if (q) {
64
- const name = normalizeLowercaseStringOrEmpty(ch.name);
65
- const display = normalizeLowercaseStringOrEmpty(ch.display_name);
64
+ const name = normalizeLowercaseStringOrEmpty(ch.name).normalize("NFC");
65
+ const display = normalizeLowercaseStringOrEmpty(ch.display_name).normalize("NFC");
66
66
  if (!name.includes(q) && !display.includes(q)) continue;
67
67
  }
68
68
  seenIds.add(ch.id);
@@ -225,23 +225,6 @@ function parseAuthorizedReactionTarget(rawTarget) {
225
225
  }
226
226
  return null;
227
227
  }
228
- async function authorizeMattermostReactionResource(params) {
229
- const target = parseAuthorizedReactionTarget(params.authorizedTarget);
230
- if (!target) throw new Error("Mattermost delegated reactions require a canonical authorized conversation target.");
231
- const postChannelId = (await params.client.request(`/posts/${encodeURIComponent(params.postId)}`)).channel_id?.trim();
232
- if (!postChannelId) throw new Error("Mattermost reaction post is missing its conversation binding.");
233
- if (target.kind === "channel") {
234
- if (postChannelId !== target.id) throw new Error("Mattermost reaction post belongs to a different conversation.");
235
- return;
236
- }
237
- const botUserId = await resolveBotUserId(params.client, params.cacheKey);
238
- if (!botUserId) throw new Error("Mattermost reactions failed: could not resolve bot user id.");
239
- const channel = await fetchMattermostChannel(params.client, postChannelId);
240
- const participants = channel.name?.split("__").map((entry) => entry.trim()).filter(Boolean).toSorted() ?? [];
241
- const authorizedParticipants = [botUserId, target.id].toSorted();
242
- if (channel.type !== "D" || participants.length !== 2 || participants[0] !== authorizedParticipants[0] || participants[1] !== authorizedParticipants[1]) throw new Error("Mattermost reaction post belongs to a different direct conversation.");
243
- return botUserId;
244
- }
245
228
  async function runMattermostReaction(params, action) {
246
229
  const resolved = resolveMattermostAccount({
247
230
  cfg: params.cfg,
@@ -256,17 +239,29 @@ async function runMattermostReaction(params, action) {
256
239
  const client = createMattermostClient({
257
240
  baseUrl,
258
241
  botToken,
259
- fetchImpl: params.fetchImpl,
260
242
  allowPrivateNetwork: resolved.config.network?.dangerouslyAllowPrivateNetwork === true
261
243
  });
262
244
  const cacheKey = `${baseUrl}:${botToken}`;
263
245
  try {
264
- const userId = (params.conversationReadOrigin === "direct-operator" ? void 0 : await authorizeMattermostReactionResource({
265
- client,
266
- cacheKey,
267
- postId: params.postId,
268
- authorizedTarget: params.authorizedTarget
269
- })) ?? await resolveBotUserId(client, cacheKey);
246
+ async function authorizeMattermostReactionResource() {
247
+ const { postId, authorizedTarget } = params;
248
+ const target = parseAuthorizedReactionTarget(authorizedTarget);
249
+ if (!target) throw new Error("Mattermost delegated reactions require a canonical authorized conversation target.");
250
+ const postChannelId = (await client.request(`/posts/${encodeURIComponent(postId)}`)).channel_id?.trim();
251
+ if (!postChannelId) throw new Error("Mattermost reaction post is missing its conversation binding.");
252
+ if (target.kind === "channel") {
253
+ if (postChannelId !== target.id) throw new Error("Mattermost reaction post belongs to a different conversation.");
254
+ return;
255
+ }
256
+ const botUserId = await resolveBotUserId(client, cacheKey);
257
+ if (!botUserId) throw new Error("Mattermost reactions failed: could not resolve bot user id.");
258
+ const channel = await fetchMattermostChannel(client, postChannelId);
259
+ const participants = channel.name?.split("__").map((entry) => entry.trim()).filter(Boolean).toSorted() ?? [];
260
+ const authorizedParticipants = [botUserId, target.id].toSorted();
261
+ if (channel.type !== "D" || participants.length !== 2 || participants[0] !== authorizedParticipants[0] || participants[1] !== authorizedParticipants[1]) throw new Error("Mattermost reaction post belongs to a different direct conversation.");
262
+ return botUserId;
263
+ }
264
+ const userId = (params.conversationReadOrigin === "direct-operator" ? void 0 : await authorizeMattermostReactionResource()) ?? await resolveBotUserId(client, cacheKey);
270
265
  if (!userId) return {
271
266
  ok: false,
272
267
  error: "Mattermost reactions failed: could not resolve bot user id."
@@ -306,9 +301,9 @@ function parseMattermostChannelTarget(rawTarget) {
306
301
  function isCurrentMattermostReadTarget(params) {
307
302
  const toolContext = params.context.toolContext;
308
303
  const nativeChannelId = toolContext?.currentChannelId;
309
- if (typeof nativeChannelId === "string" && nativeChannelId.trim()) return parseMattermostChannelTarget(nativeChannelId) === params.channelId;
304
+ if (nativeChannelId?.trim()) return parseMattermostChannelTarget(nativeChannelId) === params.channelId;
310
305
  const messagingTarget = toolContext?.currentMessagingTarget;
311
- return typeof messagingTarget === "string" && Boolean(messagingTarget.trim()) && parseMattermostChannelTarget(messagingTarget) === params.channelId;
306
+ return messagingTarget !== void 0 && Boolean(messagingTarget.trim()) && parseMattermostChannelTarget(messagingTarget) === params.channelId;
312
307
  }
313
308
  function isConfiguredMattermostReadTarget(params) {
314
309
  const { groupPolicy } = resolveAllowlistProviderRuntimeGroupPolicy({
@@ -333,7 +328,6 @@ async function readMattermostMessages(params) {
333
328
  const client = createMattermostClient({
334
329
  baseUrl,
335
330
  botToken,
336
- fetchImpl: params.fetchImpl,
337
331
  allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true
338
332
  });
339
333
  if (params.context.conversationReadOrigin !== "direct-operator") {