@openclaw/mattermost 2026.10.10 → 2026.11.5-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.
Files changed (45) hide show
  1. package/dist/.setup/channel-plugin-api-C5kL5jd0.mjs +1 -0
  2. package/dist/.setup/{channel-plugin-runtime-CLBgUA35.mjs → channel-plugin-api-CC8EU4bs.mjs} +147 -130
  3. package/dist/.setup/{channel.runtime-BBMzxlPB.mjs → channel.runtime-ukouI9k4.mjs} +37 -37
  4. package/dist/.setup/{client-VHp4VYIf.mjs → client-CVipK0N2.mjs} +11 -84
  5. package/dist/.setup/{interactions-7eWssSf1.mjs → interactions-cgV9-piH.mjs} +23 -36
  6. package/dist/.setup/{monitor-agLGA4lV.mjs → monitor-Bn-I4iu7.mjs} +292 -398
  7. package/dist/.setup/{monitor-auth-0gZXtoHv.mjs → monitor-auth-D7Fl9CyF.mjs} +5 -11
  8. package/dist/.setup/{normalize-C_DYEHki.mjs → normalize-DuLSV4tT.mjs} +21 -7
  9. package/dist/.setup/secret-contract-BkDCURCE.mjs +19 -0
  10. package/dist/.setup/{secret-contract-api-CmBND3cW.mjs → secret-contract-api-DydsmAPQ.mjs} +1 -1
  11. package/dist/.setup/{send-3ye1gFt3.mjs → send-CoWXMKnY.mjs} +100 -198
  12. package/dist/.setup/{slash-state-V13EaHX9.mjs → slash-state-CwLVacYg.mjs} +361 -408
  13. package/dist/.source-module-urls/8fb0cb1067b83fd2cf3f3ba0f7a23e627c27e8e3adf1a4ea18753ddb884ff71e.json +1 -0
  14. package/dist/api.js +2 -2
  15. package/dist/channel-plugin-api.js +1 -1
  16. package/dist/policy-api.js +1 -1
  17. package/dist/secret-contract-api.js +1 -1
  18. package/dist/setup-entry.js +2 -2
  19. package/dist/slash-route-api.js +1 -1
  20. package/node_modules/zod/package.json +1 -1
  21. package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
  22. package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
  23. package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
  24. package/node_modules/zod/src/v4/core/compile.ts +9 -0
  25. package/node_modules/zod/src/v4/core/schemas.ts +35 -1
  26. package/node_modules/zod/src/v4/core/util.ts +13 -0
  27. package/node_modules/zod/src/v4/core/versions.ts +1 -1
  28. package/node_modules/zod/v4/core/compile.cjs +8 -0
  29. package/node_modules/zod/v4/core/compile.js +8 -0
  30. package/node_modules/zod/v4/core/schemas.cjs +30 -0
  31. package/node_modules/zod/v4/core/schemas.d.cts +3 -1
  32. package/node_modules/zod/v4/core/schemas.d.ts +3 -1
  33. package/node_modules/zod/v4/core/schemas.js +30 -0
  34. package/node_modules/zod/v4/core/util.cjs +15 -0
  35. package/node_modules/zod/v4/core/util.d.cts +2 -0
  36. package/node_modules/zod/v4/core/util.d.ts +2 -0
  37. package/node_modules/zod/v4/core/util.js +14 -0
  38. package/node_modules/zod/v4/core/versions.cjs +1 -1
  39. package/node_modules/zod/v4/core/versions.js +1 -1
  40. package/openclaw.plugin.json +172 -0
  41. package/package.json +5 -5
  42. package/dist/.setup/channel-plugin-api-Vq9imWd1.mjs +0 -2
  43. package/dist/.setup/secret-contract-H9g0kHHQ.mjs +0 -11
  44. package/dist/.source-module-urls/9b327bbbce22c2cbef393c115f9a63999afd57e223aad992389710cb3f1e29cc.json +0 -1
  45. package/dist/channel-plugin-runtime.js +0 -1
@@ -0,0 +1 @@
1
+ export { t as mattermostPlugin, n as mattermostSetupPlugin } from "./channel-plugin-api-CC8EU4bs.mjs";
@@ -1,11 +1,10 @@
1
- import { h as normalizeMattermostBaseUrl } from "./client-VHp4VYIf.mjs";
1
+ import { h as normalizeMattermostBaseUrl } from "./client-CVipK0N2.mjs";
2
2
  import { t as mattermostIngressIdentity } from "./ingress-identity-CtHiOUDu.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-C_DYEHki.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-DuLSV4tT.mjs";
4
4
  import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-DhWaV22L.mjs";
5
5
  import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-i788N90j.mjs";
6
- import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-H9g0kHHQ.mjs";
6
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-BkDCURCE.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
  // extensions/mattermost/src/approval-auth.ts
36
36
  const MATTERMOST_USER_ID_RE = /^[a-z0-9]{26}$/;
@@ -94,7 +94,7 @@ const mattermostConfigAdapter = createScopedChannelConfigAdapter({
94
94
  function describeMattermostAccount(account) {
95
95
  return describeAccountSnapshot({
96
96
  account,
97
- configured: isMattermostConfigured$1(account),
97
+ configured: isMattermostConfigured(account),
98
98
  extra: {
99
99
  botTokenSource: account.botTokenSource,
100
100
  botTokenStatus: account.botTokenStatus,
@@ -119,7 +119,11 @@ function createMattermostDeliveryProgressReporter(onDeliveryResult) {
119
119
  } : void 0;
120
120
  }
121
121
  // extensions/mattermost/src/config-schema-core.ts
122
- const MattermostGroupSchema = buildGroupEntrySchema({ requireMentionInBotThreads: z.boolean().optional() }).omit({
122
+ const MattermostGroupSchema = buildGroupEntrySchema({
123
+ requireMentionInBotThreads: z.boolean().optional(),
124
+ allowBots: buildChannelAllowBotsSchema({ allowMentions: true }),
125
+ botLoopProtection: ChannelBotLoopProtectionSchema.optional()
126
+ }).omit({
123
127
  tools: true,
124
128
  toolsBySender: true,
125
129
  skills: true,
@@ -194,6 +198,8 @@ const MattermostAccountSchemaBase = z.object({
194
198
  oncharPrefixes: z.array(z.string()).optional(),
195
199
  requireMention: z.boolean().optional(),
196
200
  requireMentionInBotThreads: z.boolean().optional(),
201
+ allowBots: buildChannelAllowBotsSchema({ allowMentions: true }),
202
+ botLoopProtection: ChannelBotLoopProtectionSchema.optional(),
197
203
  implicitMentions: ChannelImplicitMentionsSchema.optional(),
198
204
  dmPolicy: DmPolicySchema.optional().default("pairing"),
199
205
  allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
@@ -217,7 +223,6 @@ const MattermostAccountSchemaBase = z.object({
217
223
  groups: z.record(z.string(), MattermostGroupSchema.optional()).optional(),
218
224
  /** Network policy overrides for self-hosted Mattermost on trusted private/internal hosts. */
219
225
  network: MattermostNetworkSchema,
220
- /** Retry configuration for DM channel creation */
221
226
  dmChannelRetry: DmChannelRetrySchema
222
227
  }).strict();
223
228
  const MattermostConfigSchema = buildMultiAccountChannelSchema(MattermostAccountSchemaBase, {
@@ -232,7 +237,7 @@ const MattermostConfigSchema = buildMultiAccountChannelSchema(MattermostAccountS
232
237
  });
233
238
  }
234
239
  });
235
- // extensions/mattermost/src/config-ui-hints.ts
240
+ // extensions/mattermost/src/config-surface.ts
236
241
  const mattermostChannelConfigUiHints = {
237
242
  "": {
238
243
  label: "Mattermost",
@@ -246,6 +251,38 @@ const mattermostChannelConfigUiHints = {
246
251
  label: "Mention in Bot Threads",
247
252
  help: "Override bot-created thread mention policy for this Mattermost channel. Exact channel settings override the wildcard, then the account setting."
248
253
  },
254
+ allowBots: {
255
+ label: "Mattermost Allow Bot Posts",
256
+ 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."
257
+ },
258
+ "groups.*.allowBots": {
259
+ label: "Mattermost Allow Bot Posts",
260
+ help: "Override allowBots for this Mattermost channel. Exact channel settings override the wildcard, then the account setting."
261
+ },
262
+ botLoopProtection: {
263
+ label: "Mattermost Bot Loop Protection",
264
+ help: "Sliding-window guard for Mattermost bot-to-bot loops. Default is enabled whenever allowBots lets bot posts reach dispatch."
265
+ },
266
+ "botLoopProtection.enabled": {
267
+ label: "Mattermost Bot Loop Protection Enabled",
268
+ help: "Enable the bot-pair loop guard. Defaults to true when allowBots is true or \"mentions\"; bot posts are ignored when allowBots is false."
269
+ },
270
+ "botLoopProtection.maxEventsPerWindow": {
271
+ label: "Mattermost Bot Loop Events per Window",
272
+ help: "Maximum accepted bot-pair posts within the sliding window before suppression starts. Default: 20."
273
+ },
274
+ "botLoopProtection.windowSeconds": {
275
+ label: "Mattermost Bot Loop Window Seconds",
276
+ help: "Sliding window length for counting bot-pair posts. Default: 60."
277
+ },
278
+ "botLoopProtection.cooldownSeconds": {
279
+ label: "Mattermost Bot Loop Cooldown Seconds",
280
+ help: "How long to suppress the bot pair after it exceeds the budget. Default: 60."
281
+ },
282
+ "groups.*.botLoopProtection": {
283
+ label: "Mattermost Channel Bot Loop Protection",
284
+ help: "Per-channel loop guard overrides, merged key by key over the wildcard and account settings."
285
+ },
249
286
  ...createChannelConfigUiHints({
250
287
  channelLabel: "Mattermost",
251
288
  dmPolicy: { channelKey: "mattermost" },
@@ -261,26 +298,18 @@ const mattermostChannelConfigUiHints = {
261
298
  progress: {}
262
299
  })
263
300
  };
264
- // extensions/mattermost/src/config-surface.ts
265
301
  const MattermostChannelConfigSchema = buildChannelConfigSchema(MattermostConfigSchema, { uiHints: mattermostChannelConfigUiHints });
266
302
  // extensions/mattermost/src/setup-core.ts
267
303
  const channel$1 = "mattermost";
268
- function isMattermostConfigured(account) {
269
- return (Boolean(account.botToken?.trim()) || hasConfiguredSecretInput(account.config.botToken)) && Boolean(account.baseUrl);
270
- }
271
304
  function applyMattermostSetupConfigPatch(params) {
272
- const namedConfig = applyAccountNameToChannelSection({
273
- cfg: params.cfg,
274
- channelKey: channel$1,
275
- accountId: params.accountId,
276
- name: params.name
277
- });
278
- const next = params.accountId !== DEFAULT_ACCOUNT_ID ? migrateBaseNameToDefaultAccount({
279
- cfg: namedConfig,
280
- channelKey: channel$1
281
- }) : namedConfig;
282
305
  return applySetupAccountConfigPatch({
283
- cfg: next,
306
+ cfg: prepareScopedSetupConfig({
307
+ cfg: params.cfg,
308
+ channelKey: channel$1,
309
+ accountId: params.accountId,
310
+ name: params.name,
311
+ migrateBaseName: true
312
+ }),
284
313
  channelKey: channel$1,
285
314
  accountId: params.accountId,
286
315
  patch: params.patch
@@ -456,7 +485,7 @@ const mattermostSetupWizard = {
456
485
  // extensions/mattermost/src/channel.setup.ts
457
486
  const mattermostSetupPlugin = {
458
487
  id: "mattermost",
459
- meta: { ...mattermostMeta },
488
+ meta: mattermostMeta,
460
489
  capabilities: {
461
490
  chatTypes: [
462
491
  "direct",
@@ -481,7 +510,7 @@ const mattermostSetupPlugin = {
481
510
  configSchema: MattermostChannelConfigSchema,
482
511
  config: {
483
512
  ...mattermostConfigAdapter,
484
- isConfigured: isMattermostConfigured$1,
513
+ isConfigured: isMattermostConfigured,
485
514
  describeAccount: describeMattermostAccount
486
515
  },
487
516
  gateway: { resolveGatewayAuthBypassPaths: resolveMattermostGatewayAuthBypassPaths },
@@ -617,7 +646,7 @@ function resolveMattermostOutboundSessionRoute(params) {
617
646
  });
618
647
  }
619
648
  // extensions/mattermost/src/channel.ts
620
- const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-BBMzxlPB.mjs"));
649
+ const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-ukouI9k4.mjs"));
621
650
  const MATTERMOST_PRESENTATION_CAPABILITIES = {
622
651
  supported: true,
623
652
  buttons: true,
@@ -632,9 +661,6 @@ function hasMattermostPresentationNavigation(presentation) {
632
661
  return action?.type === "url" || action?.type === "web-app" && Boolean(action.url);
633
662
  }));
634
663
  }
635
- function readMattermostPayloadData(payload) {
636
- return asOptionalRecord(payload.channelData?.mattermost);
637
- }
638
664
  const mattermostSecurityAdapter = createRestrictSendersChannelSecurity({
639
665
  channelKey: "mattermost",
640
666
  resolveDmPolicy: (account) => account.config.dmPolicy,
@@ -658,87 +684,15 @@ function listEnabledMattermostAccounts({ cfg, accountId }) {
658
684
  accountId: listedAccountId
659
685
  }))).filter((account) => account.enabled && account.botToken?.trim() && account.baseUrl?.trim());
660
686
  }
661
- function describeMattermostMessageTool({ cfg, accountId }) {
662
- const enabledAccounts = listEnabledMattermostAccounts({
663
- cfg,
664
- accountId
665
- });
666
- const actions = [];
667
- if (enabledAccounts.length > 0) actions.push("send");
668
- const actionsConfig = (cfg.channels?.mattermost)?.actions;
669
- const baseMessages = actionsConfig?.messages;
670
- const baseReactions = actionsConfig?.reactions;
671
- if (enabledAccounts.some((account) => {
672
- return account.config.actions?.reactions ?? baseReactions ?? true;
673
- })) actions.push("react");
674
- if (enabledAccounts.some((account) => account.config.actions?.messages ?? baseMessages ?? false)) actions.push("read");
675
- return {
676
- actions,
677
- capabilities: enabledAccounts.length > 0 ? ["presentation"] : []
678
- };
679
- }
680
- function extractMattermostToolSend(args) {
681
- if (normalizeOptionalString(args.action) !== "send") return null;
682
- const to = normalizeOptionalString(args.to) ?? normalizeOptionalString(args.target);
683
- if (!to) return null;
684
- const threadId = normalizeOptionalString(args.threadId) ?? normalizeOptionalString(args.replyToId) ?? normalizeOptionalString(args.replyTo);
685
- const threadSuppressed = args.topLevel === true || args.threadId === null;
686
- return {
687
- to,
688
- accountId: normalizeOptionalString(args.accountId),
689
- ...threadId ? { threadId } : {},
690
- ...!threadId && !threadSuppressed ? { threadImplicit: true } : {},
691
- ...threadSuppressed ? { threadSuppressed: true } : {}
692
- };
693
- }
694
- function resolveMattermostAutoThreadId(params) {
695
- const replyToId = normalizeOptionalString(params.replyToId);
696
- const context = params.toolContext;
697
- const currentThreadId = normalizeOptionalString(context?.currentThreadTs);
698
- const currentMessageId = normalizeMattermostThreadId(context?.currentMessageId);
699
- const currentTarget = normalizeMattermostThreadTarget(context?.currentChannelId);
700
- if (currentThreadId && currentTarget === normalizeMattermostThreadTarget(params.to)) {
701
- if (replyToId === currentMessageId) return currentThreadId;
702
- if (!replyToId) {
703
- const replyToMode = context?.replyToMode;
704
- return replyToMode === "all" || replyToMode === "first" && context?.hasRepliedRef?.value !== true ? currentThreadId : void 0;
705
- }
706
- }
707
- return replyToId;
708
- }
709
687
  function normalizeMattermostThreadTarget(raw) {
710
688
  const normalized = raw ? normalizeMattermostMessagingTarget(raw) : void 0;
711
689
  if (normalized) return normalized;
712
690
  const trimmed = normalizeOptionalString(raw);
713
691
  return trimmed && /^[a-z0-9]{26}$/i.test(trimmed) ? `channel:${trimmed}` : void 0;
714
692
  }
715
- function matchesMattermostToolContextTarget(params) {
716
- const target = normalizeMattermostThreadTarget(params.target);
717
- if (!target) return false;
718
- return [params.toolContext.currentChannelId, params.toolContext.currentMessagingTarget].some((currentTarget) => normalizeMattermostThreadTarget(currentTarget) === target);
719
- }
720
693
  function normalizeMattermostThreadId(value) {
721
694
  return typeof value === "number" ? String(value) : normalizeOptionalString(value);
722
695
  }
723
- function buildMattermostThreadingToolContext(params) {
724
- const account = resolveMattermostAccount({
725
- cfg: params.cfg,
726
- accountId: params.accountId ?? resolveDefaultMattermostAccountId(params.cfg)
727
- });
728
- const chatType = params.context.ChatType === "direct" || params.context.ChatType === "group" || params.context.ChatType === "channel" ? params.context.ChatType : "channel";
729
- const configuredReplyToMode = resolveMattermostReplyToMode(account, chatType);
730
- const currentThreadTs = normalizeMattermostThreadId(params.context.MessageThreadId) ?? normalizeMattermostThreadId(params.context.TransportThreadId) ?? normalizeOptionalString(params.context.ReplyToId);
731
- const currentMessageId = normalizeMattermostThreadId(params.context.CurrentMessageId);
732
- const hasExistingThread = Boolean(currentThreadTs) && (!currentMessageId || currentThreadTs !== currentMessageId);
733
- return {
734
- currentChannelId: params.context.To ? normalizeMattermostMessagingTarget(params.context.To) : void 0,
735
- currentThreadTs,
736
- currentMessageId: params.context.CurrentMessageId,
737
- replyToMode: hasExistingThread ? "all" : configuredReplyToMode,
738
- hasRepliedRef: params.hasRepliedRef,
739
- sameChannelThreadRequired: Boolean(currentThreadTs)
740
- };
741
- }
742
696
  async function listMattermostDirectoryGroups(params) {
743
697
  if (listEnabledMattermostAccounts(params).length === 0) return [];
744
698
  return (await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params);
@@ -750,13 +704,44 @@ async function listMattermostDirectoryPeers(params) {
750
704
  const mattermostMessageActions = {
751
705
  providerOwnedReadGates: ["read"],
752
706
  readAuthorityActions: ["read"],
753
- describeMessageTool: describeMattermostMessageTool,
754
- extractToolSend: ({ args }) => extractMattermostToolSend(args),
707
+ describeMessageTool({ cfg, accountId }) {
708
+ const enabledAccounts = listEnabledMattermostAccounts({
709
+ cfg,
710
+ accountId
711
+ });
712
+ const actions = [];
713
+ if (enabledAccounts.length > 0) actions.push("send");
714
+ const actionsConfig = (cfg.channels?.mattermost)?.actions;
715
+ const baseMessages = actionsConfig?.messages;
716
+ const baseReactions = actionsConfig?.reactions;
717
+ if (enabledAccounts.some((account) => {
718
+ return account.config.actions?.reactions ?? baseReactions ?? true;
719
+ })) actions.push("react");
720
+ if (enabledAccounts.some((account) => account.config.actions?.messages ?? baseMessages ?? false)) actions.push("read");
721
+ return {
722
+ actions,
723
+ capabilities: enabledAccounts.length > 0 ? ["presentation"] : []
724
+ };
725
+ },
726
+ extractToolSend({ args }) {
727
+ if (normalizeOptionalString(args.action) !== "send") return null;
728
+ const to = normalizeOptionalString(args.to) ?? normalizeOptionalString(args.target);
729
+ if (!to) return null;
730
+ const threadId = normalizeOptionalString(args.threadId) ?? normalizeOptionalString(args.replyToId) ?? normalizeOptionalString(args.replyTo);
731
+ const threadSuppressed = args.topLevel === true || args.threadId === null;
732
+ return {
733
+ to,
734
+ accountId: normalizeOptionalString(args.accountId),
735
+ ...threadId ? { threadId } : {},
736
+ ...!threadId && !threadSuppressed ? { threadImplicit: true } : {},
737
+ ...threadSuppressed ? { threadSuppressed: true } : {}
738
+ };
739
+ },
755
740
  prepareSendPayload: ({ ctx, payload }) => {
756
741
  if (ctx.action !== "send") return null;
757
742
  const mediaUrl = resolveMattermostSendAttachmentMedia(ctx.params);
758
743
  const attachmentText = typeof ctx.params.attachmentText === "string" ? ctx.params.attachmentText : void 0;
759
- const existingMattermostData = readMattermostPayloadData(payload);
744
+ const existingMattermostData = asOptionalRecord(payload.channelData?.mattermost);
760
745
  return {
761
746
  ...payload,
762
747
  ...mediaUrl ? {
@@ -813,7 +798,11 @@ const mattermostMessageActions = {
813
798
  });
814
799
  }
815
800
  if (!(account.config.actions?.reactions ?? actionsConfig?.reactions ?? true)) throw new Error("Mattermost reactions are disabled in config");
816
- const { postId, emojiName, remove } = parseMattermostReactActionParams(params);
801
+ const postId = normalizeOptionalString(params.messageId) ?? normalizeOptionalString(params.postId);
802
+ if (!postId) throw new Error("Mattermost react requires messageId (post id)");
803
+ const emojiName = normalizeMattermostEmojiName(normalizeOptionalString(params.emoji));
804
+ if (!emojiName) throw new Error("Mattermost react requires emoji");
805
+ const remove = params.remove === true;
817
806
  const authorizedTarget = normalizeOptionalString(params.to);
818
807
  const runtime = await loadMattermostChannelRuntime();
819
808
  const result = await (remove ? runtime.removeMattermostReaction : runtime.addMattermostReaction)({
@@ -828,16 +817,11 @@ const mattermostMessageActions = {
828
817
  return textResult(remove ? `Removed reaction :${emojiName}: from ${postId}` : `Reacted with :${emojiName}: on ${postId}`, {});
829
818
  }
830
819
  };
831
- function parseMattermostReactActionParams(params) {
832
- const postId = normalizeOptionalString(params.messageId) ?? normalizeOptionalString(params.postId);
833
- if (!postId) throw new Error("Mattermost react requires messageId (post id)");
834
- const emojiName = normalizeMattermostEmojiName(normalizeOptionalString(params.emoji));
835
- if (!emojiName) throw new Error("Mattermost react requires emoji");
836
- return {
837
- postId,
838
- emojiName,
839
- remove: params.remove === true
840
- };
820
+ function hasUnsupportedMattermostAttachmentPayload(record) {
821
+ return ["buffer", "base64"].some((key) => {
822
+ const value = record[key];
823
+ return typeof value === "string" ? Boolean(value.trim()) : value != null;
824
+ });
841
825
  }
842
826
  function resolveMattermostSendAttachmentMedia(params) {
843
827
  const sourceKeys = [
@@ -849,13 +833,13 @@ function resolveMattermostSendAttachmentMedia(params) {
849
833
  ];
850
834
  const candidates = sourceKeys.map((key) => readStringParam(params, key));
851
835
  candidates.push(...readStringArrayParam(params, "mediaUrls") ?? []);
852
- let hasUnsupportedAttachmentPayload = Boolean(readStringParam(params, "buffer") ?? readStringParam(params, "base64"));
836
+ let hasUnsupportedAttachmentPayload = hasUnsupportedMattermostAttachmentPayload(params);
853
837
  if (Array.isArray(params.attachments)) for (const attachment of params.attachments) {
854
838
  if (!attachment || typeof attachment !== "object" || Array.isArray(attachment)) continue;
855
839
  const record = attachment;
856
840
  candidates.push(...sourceKeys.map((key) => readStringParam(record, key)));
857
841
  candidates.push(readStringParam(record, "url"));
858
- hasUnsupportedAttachmentPayload ||= Boolean(readStringParam(record, "buffer") ?? readStringParam(record, "base64"));
842
+ hasUnsupportedAttachmentPayload ||= hasUnsupportedMattermostAttachmentPayload(record);
859
843
  }
860
844
  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.");
861
845
  const mediaUrls = [...new Set(candidates.filter((candidate) => Boolean(candidate)))];
@@ -915,7 +899,7 @@ const mattermostOutbound = {
915
899
  };
916
900
  },
917
901
  sendPayload: async (ctx) => {
918
- const mattermostData = readMattermostPayloadData(ctx.payload);
902
+ const mattermostData = asOptionalRecord(ctx.payload.channelData?.mattermost);
919
903
  const buttons = Array.isArray(mattermostData?.presentationButtons) ? mattermostData.presentationButtons : void 0;
920
904
  const rawAttachmentText = mattermostData?.attachmentText;
921
905
  const attachmentText = typeof rawAttachmentText === "string" ? rawAttachmentText : void 0;
@@ -1080,18 +1064,15 @@ const mattermostPlugin = createChatChannelPlugin({
1080
1064
  ...mattermostSetupPlugin.gateway,
1081
1065
  startAccount: async (ctx) => {
1082
1066
  const account = ctx.account;
1083
- const statusSink = createAccountStatusSink({
1084
- accountId: ctx.accountId,
1085
- setStatus: ctx.setStatus
1086
- });
1067
+ const statusSink = createAccountStatusSink(ctx);
1087
1068
  statusSink({
1088
1069
  baseUrl: account.baseUrl,
1089
1070
  botTokenSource: account.botTokenSource
1090
1071
  });
1091
1072
  ctx.log?.info(`[${account.accountId}] starting channel`);
1092
- return (await import("./monitor-agLGA4lV.mjs")).monitorMattermostProvider({
1093
- botToken: account.botToken ?? void 0,
1094
- baseUrl: account.baseUrl ?? void 0,
1073
+ return (await import("./monitor-Bn-I4iu7.mjs")).monitorMattermostProvider({
1074
+ botToken: account.botToken,
1075
+ baseUrl: account.baseUrl,
1095
1076
  accountId: account.accountId,
1096
1077
  config: ctx.cfg,
1097
1078
  runtime: ctx.runtime,
@@ -1108,7 +1089,25 @@ const mattermostPlugin = createChatChannelPlugin({
1108
1089
  notify: createLoggedPairingApprovalNotifier(({ id }) => `[mattermost] User ${id} approved for pairing`)
1109
1090
  } },
1110
1091
  threading: {
1111
- buildToolContext: buildMattermostThreadingToolContext,
1092
+ buildToolContext(params) {
1093
+ const account = resolveMattermostAccount({
1094
+ cfg: params.cfg,
1095
+ accountId: params.accountId ?? resolveDefaultMattermostAccountId(params.cfg)
1096
+ });
1097
+ const chatType = params.context.ChatType === "direct" || params.context.ChatType === "group" || params.context.ChatType === "channel" ? params.context.ChatType : "channel";
1098
+ const configuredReplyToMode = resolveMattermostReplyToMode(account, chatType);
1099
+ const currentThreadTs = normalizeMattermostThreadId(params.context.MessageThreadId) ?? normalizeMattermostThreadId(params.context.TransportThreadId) ?? normalizeOptionalString(params.context.ReplyToId);
1100
+ const currentMessageId = normalizeMattermostThreadId(params.context.CurrentMessageId);
1101
+ const hasExistingThread = Boolean(currentThreadTs) && (!currentMessageId || currentThreadTs !== currentMessageId);
1102
+ return {
1103
+ currentChannelId: params.context.To ? normalizeMattermostMessagingTarget(params.context.To) : void 0,
1104
+ currentThreadTs,
1105
+ currentMessageId: params.context.CurrentMessageId,
1106
+ replyToMode: hasExistingThread ? "all" : configuredReplyToMode,
1107
+ hasRepliedRef: params.hasRepliedRef,
1108
+ sameChannelThreadRequired: Boolean(currentThreadTs)
1109
+ };
1110
+ },
1112
1111
  scopedAccountReplyToMode: {
1113
1112
  resolveAccount: (cfg, accountId) => resolveMattermostAccount({
1114
1113
  cfg,
@@ -1116,8 +1115,26 @@ const mattermostPlugin = createChatChannelPlugin({
1116
1115
  }),
1117
1116
  resolveReplyToMode: (account, chatType) => resolveMattermostReplyToMode(account, chatType === "direct" || chatType === "group" || chatType === "channel" ? chatType : "channel")
1118
1117
  },
1119
- resolveAutoThreadId: resolveMattermostAutoThreadId,
1120
- matchesToolContextTarget: matchesMattermostToolContextTarget,
1118
+ resolveAutoThreadId(params) {
1119
+ const replyToId = normalizeOptionalString(params.replyToId);
1120
+ const context = params.toolContext;
1121
+ const currentThreadId = normalizeOptionalString(context?.currentThreadTs);
1122
+ const currentMessageId = normalizeMattermostThreadId(context?.currentMessageId);
1123
+ const currentTarget = normalizeMattermostThreadTarget(context?.currentChannelId);
1124
+ if (currentThreadId && currentTarget === normalizeMattermostThreadTarget(params.to)) {
1125
+ if (replyToId === currentMessageId) return currentThreadId;
1126
+ if (!replyToId) {
1127
+ const replyToMode = context?.replyToMode;
1128
+ return replyToMode === "all" || replyToMode === "first" && context?.hasRepliedRef?.value !== true ? currentThreadId : void 0;
1129
+ }
1130
+ }
1131
+ return replyToId;
1132
+ },
1133
+ matchesToolContextTarget(params) {
1134
+ const target = normalizeMattermostThreadTarget(params.target);
1135
+ if (!target) return false;
1136
+ return [params.toolContext.currentChannelId, params.toolContext.currentMessagingTarget].some((currentTarget) => normalizeMattermostThreadTarget(currentTarget) === target);
1137
+ },
1121
1138
  resolveReplyTransport: ({ threadId, replyToId, replyToIsExplicit, replyDelivery }) => {
1122
1139
  const ambientThreadId = threadId != null ? String(threadId) : void 0;
1123
1140
  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-VHp4VYIf.mjs";
2
- import { s as resolveMattermostTrustedChatKind } from "./monitor-auth-0gZXtoHv.mjs";
3
- import { c as listMattermostAccountIds, n as normalizeMattermostMessagingTarget, o as inspectMattermostAccount, u as resolveMattermostAccount } from "./normalize-C_DYEHki.mjs";
4
- import { n as resolveMattermostOpaqueTarget, t as sendMessageMattermost } from "./send-3ye1gFt3.mjs";
1
+ import { _ as readMattermostError, h as normalizeMattermostBaseUrl, l as fetchMattermostChannelPosts, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe } from "./client-CVipK0N2.mjs";
2
+ import { s as resolveMattermostTrustedChatKind } from "./monitor-auth-D7Fl9CyF.mjs";
3
+ import { d as resolveMattermostAccount, l as listMattermostAccountIds, n as normalizeMattermostMessagingTarget, s as inspectMattermostAccount } from "./normalize-DuLSV4tT.mjs";
4
+ import { n as resolveMattermostOpaqueTarget, t as sendMessageMattermost } from "./send-CoWXMKnY.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";
@@ -23,13 +23,19 @@ function buildClients(params) {
23
23
  accountId: id
24
24
  });
25
25
  if (!account.enabled || !account.botToken || !account.baseUrl) continue;
26
+ const allowPrivateNetwork = account.config.network?.dangerouslyAllowPrivateNetwork === true;
26
27
  const client = createMattermostClient({
27
28
  baseUrl: account.baseUrl,
28
29
  botToken: account.botToken,
29
- allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true
30
+ allowPrivateNetwork
30
31
  });
31
- if (!seen.has(client.token)) {
32
- seen.add(client.token);
32
+ const key = JSON.stringify([
33
+ client.baseUrl,
34
+ client.token,
35
+ allowPrivateNetwork
36
+ ]);
37
+ if (!seen.has(key)) {
38
+ seen.add(key);
33
39
  clients.push(client);
34
40
  }
35
41
  }
@@ -45,7 +51,7 @@ function buildClients(params) {
45
51
  async function listMattermostDirectoryGroups(params) {
46
52
  const clients = buildClients(params);
47
53
  if (!clients.length) return [];
48
- const q = normalizeLowercaseStringOrEmpty(params.query);
54
+ const q = normalizeLowercaseStringOrEmpty(params.query).normalize("NFC");
49
55
  const seenIds = /* @__PURE__ */ new Set();
50
56
  const entries = [];
51
57
  for (const client of clients) try {
@@ -55,8 +61,8 @@ async function listMattermostDirectoryGroups(params) {
55
61
  if (ch.type !== "O" && ch.type !== "P") continue;
56
62
  if (seenIds.has(ch.id)) continue;
57
63
  if (q) {
58
- const name = normalizeLowercaseStringOrEmpty(ch.name);
59
- const display = normalizeLowercaseStringOrEmpty(ch.display_name);
64
+ const name = normalizeLowercaseStringOrEmpty(ch.name).normalize("NFC");
65
+ const display = normalizeLowercaseStringOrEmpty(ch.display_name).normalize("NFC");
60
66
  if (!name.includes(q) && !display.includes(q)) continue;
61
67
  }
62
68
  seenIds.add(ch.id);
@@ -217,23 +223,6 @@ function parseAuthorizedReactionTarget(rawTarget) {
217
223
  }
218
224
  return null;
219
225
  }
220
- async function authorizeMattermostReactionResource(params) {
221
- const target = parseAuthorizedReactionTarget(params.authorizedTarget);
222
- if (!target) throw new Error("Mattermost delegated reactions require a canonical authorized conversation target.");
223
- const postChannelId = (await params.client.request(`/posts/${encodeURIComponent(params.postId)}`)).channel_id?.trim();
224
- if (!postChannelId) throw new Error("Mattermost reaction post is missing its conversation binding.");
225
- if (target.kind === "channel") {
226
- if (postChannelId !== target.id) throw new Error("Mattermost reaction post belongs to a different conversation.");
227
- return;
228
- }
229
- const botUserId = await resolveBotUserId(params.client, params.cacheKey);
230
- if (!botUserId) throw new Error("Mattermost reactions failed: could not resolve bot user id.");
231
- const channel = await fetchMattermostChannel(params.client, postChannelId);
232
- const participants = channel.name?.split("__").map((entry) => entry.trim()).filter(Boolean).toSorted() ?? [];
233
- const authorizedParticipants = [botUserId, target.id].toSorted();
234
- 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.");
235
- return botUserId;
236
- }
237
226
  async function runMattermostReaction(params, action) {
238
227
  const resolved = resolveMattermostAccount({
239
228
  cfg: params.cfg,
@@ -248,17 +237,29 @@ async function runMattermostReaction(params, action) {
248
237
  const client = createMattermostClient({
249
238
  baseUrl,
250
239
  botToken,
251
- fetchImpl: params.fetchImpl,
252
240
  allowPrivateNetwork: resolved.config.network?.dangerouslyAllowPrivateNetwork === true
253
241
  });
254
242
  const cacheKey = `${baseUrl}:${botToken}`;
255
243
  try {
256
- const userId = (params.conversationReadOrigin === "direct-operator" ? void 0 : await authorizeMattermostReactionResource({
257
- client,
258
- cacheKey,
259
- postId: params.postId,
260
- authorizedTarget: params.authorizedTarget
261
- })) ?? await resolveBotUserId(client, cacheKey);
244
+ async function authorizeMattermostReactionResource() {
245
+ const { postId, authorizedTarget } = params;
246
+ const target = parseAuthorizedReactionTarget(authorizedTarget);
247
+ if (!target) throw new Error("Mattermost delegated reactions require a canonical authorized conversation target.");
248
+ const postChannelId = (await client.request(`/posts/${encodeURIComponent(postId)}`)).channel_id?.trim();
249
+ if (!postChannelId) throw new Error("Mattermost reaction post is missing its conversation binding.");
250
+ if (target.kind === "channel") {
251
+ if (postChannelId !== target.id) throw new Error("Mattermost reaction post belongs to a different conversation.");
252
+ return;
253
+ }
254
+ const botUserId = await resolveBotUserId(client, cacheKey);
255
+ if (!botUserId) throw new Error("Mattermost reactions failed: could not resolve bot user id.");
256
+ const channel = await fetchMattermostChannel(client, postChannelId);
257
+ const participants = channel.name?.split("__").map((entry) => entry.trim()).filter(Boolean).toSorted() ?? [];
258
+ const authorizedParticipants = [botUserId, target.id].toSorted();
259
+ 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.");
260
+ return botUserId;
261
+ }
262
+ const userId = (params.conversationReadOrigin === "direct-operator" ? void 0 : await authorizeMattermostReactionResource()) ?? await resolveBotUserId(client, cacheKey);
262
263
  if (!userId) return {
263
264
  ok: false,
264
265
  error: "Mattermost reactions failed: could not resolve bot user id."
@@ -297,9 +298,9 @@ function parseMattermostChannelTarget(rawTarget) {
297
298
  function isCurrentMattermostReadTarget(params) {
298
299
  const toolContext = params.context.toolContext;
299
300
  const nativeChannelId = toolContext?.currentChannelId;
300
- if (typeof nativeChannelId === "string" && nativeChannelId.trim()) return parseMattermostChannelTarget(nativeChannelId) === params.channelId;
301
+ if (nativeChannelId?.trim()) return parseMattermostChannelTarget(nativeChannelId) === params.channelId;
301
302
  const messagingTarget = toolContext?.currentMessagingTarget;
302
- return typeof messagingTarget === "string" && Boolean(messagingTarget.trim()) && parseMattermostChannelTarget(messagingTarget) === params.channelId;
303
+ return messagingTarget !== void 0 && Boolean(messagingTarget.trim()) && parseMattermostChannelTarget(messagingTarget) === params.channelId;
303
304
  }
304
305
  function isConfiguredMattermostReadTarget(params) {
305
306
  const { groupPolicy } = resolveAllowlistProviderRuntimeGroupPolicy({
@@ -324,7 +325,6 @@ async function readMattermostMessages(params) {
324
325
  const client = createMattermostClient({
325
326
  baseUrl,
326
327
  botToken,
327
- fetchImpl: params.fetchImpl,
328
328
  allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true
329
329
  });
330
330
  if (params.context.conversationReadOrigin !== "direct-operator") {