@openclaw/mattermost 2026.7.2-beta.4 → 2026.7.2-beta.7

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,37 +1,25 @@
1
- import { p as normalizeMattermostBaseUrl } from "./client-w0lkxuKh.js";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-CqqzTcno.js";
2
2
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { resolveChannelPreviewStreamMode, resolveChannelStreamingBlockCoalesce, resolveChannelStreamingBlockEnabled, resolveChannelStreamingChunkMode } from "openclaw/plugin-sdk/channel-outbound";
4
4
  import { createAccountListHelpers, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
5
5
  import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
6
- import { resolveMergedAccountConfig } from "openclaw/plugin-sdk/account-resolution";
7
- import { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString, normalizeSecretInputString } from "openclaw/plugin-sdk/secret-input";
6
+ import { buildSecretInputSchema, hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
8
7
  //#region extensions/mattermost/src/mattermost/accounts.ts
9
- const mattermostAccountHelpers = createAccountListHelpers("mattermost", { hasImplicitDefaultAccount: (cfg) => {
10
- const mattermost = cfg.channels?.mattermost;
11
- return Boolean(mattermost?.baseUrl?.trim() && (hasConfiguredAccountValue(mattermost.botToken) || process.env.MATTERMOST_BOT_TOKEN?.trim()));
12
- } });
13
- function listMattermostAccountIds(cfg) {
14
- return mattermostAccountHelpers.listAccountIds(cfg);
15
- }
16
- function resolveDefaultMattermostAccountId(cfg) {
17
- return mattermostAccountHelpers.resolveDefaultAccountId(cfg);
18
- }
19
- function mergeMattermostAccountConfig(cfg, accountId) {
20
- return resolveMergedAccountConfig({
21
- channelConfig: cfg.channels?.mattermost,
22
- accounts: cfg.channels?.mattermost?.accounts,
23
- accountId,
24
- omitKeys: ["defaultAccount"],
25
- nestedObjectKeys: ["commands"]
26
- });
27
- }
8
+ const { listAccountIds: listMattermostAccountIds, resolveDefaultAccountId: resolveDefaultMattermostAccountId, resolveAccountConfig: mergeMattermostAccountConfig } = createAccountListHelpers("mattermost", {
9
+ omitKeys: ["defaultAccount"],
10
+ nestedObjectKeys: ["commands"],
11
+ hasImplicitDefaultAccount: (cfg) => {
12
+ const mattermost = cfg.channels?.mattermost;
13
+ return Boolean(mattermost?.baseUrl?.trim() && (hasConfiguredAccountValue(mattermost.botToken) || process.env.MATTERMOST_BOT_TOKEN?.trim()));
14
+ }
15
+ });
28
16
  function resolveMattermostRequireMention(config) {
29
17
  if (config.chatmode === "oncall") return true;
30
18
  if (config.chatmode === "onmessage") return false;
31
19
  if (config.chatmode === "onchar") return true;
32
20
  return config.requireMention;
33
21
  }
34
- function resolveMattermostAccount(params) {
22
+ function resolveMattermostAccountWithMode(params) {
35
23
  const accountId = normalizeAccountId(params.accountId ?? resolveDefaultMattermostAccountId(params.cfg));
36
24
  const baseEnabled = params.cfg.channels?.mattermost?.enabled !== false;
37
25
  const merged = mergeMattermostAccountConfig(params.cfg, accountId);
@@ -40,15 +28,17 @@ function resolveMattermostAccount(params) {
40
28
  const allowEnv = accountId === DEFAULT_ACCOUNT_ID;
41
29
  const envToken = allowEnv ? process.env.MATTERMOST_BOT_TOKEN?.trim() : void 0;
42
30
  const envUrl = allowEnv ? process.env.MATTERMOST_URL?.trim() : void 0;
43
- const configToken = params.allowUnresolvedSecretRef ? normalizeSecretInputString(merged.botToken) : normalizeResolvedSecretInputString({
31
+ const configToken = resolveSecretInputString({
44
32
  value: merged.botToken,
45
- path: `channels.mattermost.accounts.${accountId}.botToken`
33
+ path: `channels.mattermost.accounts.${accountId}.botToken`,
34
+ mode: params.mode
46
35
  });
47
36
  const configUrl = merged.baseUrl?.trim();
48
- const botToken = configToken || envToken;
37
+ const botToken = configToken.status === "available" ? configToken.value : configToken.status === "missing" ? envToken : void 0;
49
38
  const baseUrl = normalizeMattermostBaseUrl(configUrl || envUrl);
50
39
  const requireMention = resolveMattermostRequireMention(merged);
51
- const botTokenSource = configToken ? "config" : envToken ? "env" : "none";
40
+ const botTokenSource = configToken.status !== "missing" ? "config" : envToken ? "env" : "none";
41
+ const botTokenStatus = configToken.status !== "missing" ? configToken.status : envToken ? "available" : "missing";
52
42
  const baseUrlSource = configUrl ? "config" : envUrl ? "env" : "none";
53
43
  return {
54
44
  accountId,
@@ -57,6 +47,7 @@ function resolveMattermostAccount(params) {
57
47
  botToken,
58
48
  baseUrl,
59
49
  botTokenSource,
50
+ botTokenStatus,
60
51
  baseUrlSource,
61
52
  config: merged,
62
53
  chatmode: merged.chatmode,
@@ -69,6 +60,18 @@ function resolveMattermostAccount(params) {
69
60
  blockStreamingCoalesce: resolveChannelStreamingBlockCoalesce(merged)
70
61
  };
71
62
  }
63
+ function resolveMattermostAccount(params) {
64
+ return resolveMattermostAccountWithMode({
65
+ ...params,
66
+ mode: "strict"
67
+ });
68
+ }
69
+ function inspectMattermostAccount(params) {
70
+ return resolveMattermostAccountWithMode({
71
+ ...params,
72
+ mode: "inspect"
73
+ });
74
+ }
72
75
  /**
73
76
  * Resolve the effective replyToMode for a given chat type.
74
77
  * Direct messages stay flat unless explicitly opted into a per-chat-type mode.
@@ -80,4 +83,4 @@ function resolveMattermostReplyToMode(account, kind) {
80
83
  return account.config.replyToMode ?? "off";
81
84
  }
82
85
  //#endregion
83
- export { buildSecretInputSchema as a, resolveMattermostReplyToMode as i, resolveDefaultMattermostAccountId as n, hasConfiguredSecretInput as o, resolveMattermostAccount as r, listMattermostAccountIds as t };
86
+ export { resolveMattermostReplyToMode as a, resolveMattermostAccount as i, listMattermostAccountIds as n, buildSecretInputSchema as o, resolveDefaultMattermostAccountId as r, hasConfiguredSecretInput as s, inspectMattermostAccount as t };
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { r as isMattermostSenderAllowed } from "./monitor-auth-4zjr5tXP.js";
2
- import { t as buildButtonAttachments } from "./interactions-DODXaHdE.js";
1
+ import { r as isMattermostSenderAllowed } from "./monitor-auth-rctDliGZ.js";
2
+ import { t as buildButtonAttachments } from "./interactions-BQXY_48h.js";
3
3
  export { buildButtonAttachments, isMattermostSenderAllowed };
@@ -1,4 +1,4 @@
1
- import { c as isMattermostConfigured, i as mattermostSetupContract, l as mattermostConfigAdapter, n as mattermostSetupWizard, o as MattermostChannelConfigSchema, r as mattermostSetupAdapter, s as describeMattermostAccount, t as mattermostPlugin, u as mattermostMeta } from "./channel-plugin-runtime-CgRXlOvV.js";
1
+ import { c as isMattermostConfigured, i as mattermostSetupContract, l as mattermostConfigAdapter, n as mattermostSetupWizard, o as MattermostChannelConfigSchema, r as mattermostSetupAdapter, s as describeMattermostAccount, t as mattermostPlugin, u as mattermostMeta } from "./channel-plugin-runtime-DlrMaSIu.js";
2
2
  import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-CL1PxV3z.js";
3
3
  //#region extensions/mattermost/src/channel.setup.ts
4
4
  const mattermostSetupPlugin = {
@@ -1,5 +1,5 @@
1
- import { p as normalizeMattermostBaseUrl } from "./client-w0lkxuKh.js";
2
- import { a as buildSecretInputSchema, i as resolveMattermostReplyToMode, n as resolveDefaultMattermostAccountId, o as hasConfiguredSecretInput, r as resolveMattermostAccount, t as listMattermostAccountIds } from "./accounts-B-GrNVwP.js";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-CqqzTcno.js";
2
+ import { a as resolveMattermostReplyToMode, i as resolveMattermostAccount, n as listMattermostAccountIds, o as buildSecretInputSchema, r as resolveDefaultMattermostAccountId, s as hasConfiguredSecretInput, t as inspectMattermostAccount } from "./accounts-NaMdx9yF.js";
3
3
  import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-CL1PxV3z.js";
4
4
  import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BaUvVh8e.js";
5
5
  import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-B4R5Bmhv.js";
@@ -11,6 +11,8 @@ import { formatNormalizedAllowFromEntries } from "openclaw/plugin-sdk/allow-from
11
11
  import { createLoggedPairingApprovalNotifier } from "openclaw/plugin-sdk/channel-pairing";
12
12
  import { createAccountStatusSink, createChannelMessageAdapterFromOutbound } from "openclaw/plugin-sdk/channel-outbound";
13
13
  import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, buildChannelOutboundSessionRoute, buildThreadAwareOutboundSessionRoute, stripChannelTargetPrefix, stripTargetKindPrefix } from "openclaw/plugin-sdk/core";
14
+ import { jsonResult, readPositiveIntegerParam, readStringParam, withNormalizedTimestamp } from "openclaw/plugin-sdk/channel-actions";
15
+ import { adaptScopedAccountAccessor, createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
14
16
  import { createChannelConfigUiHints, createChatChannelPlugin } from "openclaw/plugin-sdk/channel-core";
15
17
  import { buildChannelGroupsScopeTree, buildMutableAllowEntryDetector, collectStandardAllowlistLists, createDangerousNameMatchingMutableAllowlistWarningCollector, createRestrictSendersChannelSecurity, resolveScopeRequireMention } from "openclaw/plugin-sdk/channel-policy";
16
18
  import { attachChannelToResult, createAttachedChannelResultAdapter } from "openclaw/plugin-sdk/channel-send-result";
@@ -23,7 +25,6 @@ import { chunkTextForOutbound, sanitizeAssistantVisibleText } from "openclaw/plu
23
25
  import { createChannelApprovalAuth } from "openclaw/plugin-sdk/approval-auth-runtime";
24
26
  import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
25
27
  import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
26
- import { adaptScopedAccountAccessor, createScopedChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
27
28
  import { BlockStreamingCoalesceSchema, ChannelImplicitMentionsSchema, DmPolicySchema, GroupPolicySchema, MarkdownConfigSchema, buildChannelConfigSchema, buildGroupEntrySchema, buildMultiAccountChannelSchema, requireOpenAllowFrom } from "openclaw/plugin-sdk/channel-config-schema";
28
29
  import { defineChannelSetupContract } from "openclaw/plugin-sdk/channel-setup";
29
30
  import { applyAccountNameToChannelSection, applySetupAccountConfigPatch, baseUrlTextInput, createSetupTranslator, createStandardChannelSetupStatus, defineTokenCredential, formatDocsLink, migrateBaseNameToDefaultAccount, setSetupChannelEnabled } from "openclaw/plugin-sdk/setup";
@@ -87,7 +88,7 @@ const mattermostConfigAdapter = createScopedChannelConfigAdapter({
87
88
  })
88
89
  });
89
90
  function isMattermostConfigured$1(account) {
90
- return Boolean(account.botToken && account.baseUrl);
91
+ return (account.botTokenStatus ? account.botTokenStatus !== "missing" : Boolean(account.botToken)) && Boolean(account.baseUrl);
91
92
  }
92
93
  function describeMattermostAccount(account) {
93
94
  return describeAccountSnapshot({
@@ -95,6 +96,7 @@ function describeMattermostAccount(account) {
95
96
  configured: isMattermostConfigured$1(account),
96
97
  extra: {
97
98
  botTokenSource: account.botTokenSource,
99
+ botTokenStatus: account.botTokenStatus,
98
100
  baseUrl: account.baseUrl
99
101
  }
100
102
  });
@@ -215,7 +217,10 @@ const MattermostChannelConfigSchema = buildChannelConfigSchema(buildMultiAccount
215
217
  replyToMode: MattermostReplyToModeSchema.optional(),
216
218
  replyToModeByChatType: MattermostReplyToModeByChatTypeSchema.optional(),
217
219
  responsePrefix: z.string().optional(),
218
- actions: z.object({ reactions: z.boolean().optional() }).optional(),
220
+ actions: z.object({
221
+ messages: z.boolean().optional(),
222
+ reactions: z.boolean().optional()
223
+ }).optional(),
219
224
  commands: MattermostSlashCommandsSchema,
220
225
  interactions: z.object({
221
226
  callbackBaseUrl: z.string().optional(),
@@ -244,36 +249,17 @@ const MattermostChannelConfigSchema = buildChannelConfigSchema(buildMultiAccount
244
249
  ...createChannelConfigUiHints({
245
250
  channelLabel: "Mattermost",
246
251
  dmPolicy: { channelKey: "mattermost" },
247
- implicitMentions: true
248
- }),
249
- streaming: {
250
- label: "Mattermost Streaming Mode",
251
- help: "Unified Mattermost stream preview mode: \"off\" | \"partial\" | \"block\" | \"progress\". \"progress\" keeps a single editable progress draft until final delivery."
252
- },
253
- "streaming.mode": {
254
- label: "Mattermost Streaming Mode",
255
- help: "Canonical Mattermost preview mode: \"off\" | \"partial\" | \"block\" | \"progress\"."
256
- },
257
- ...createChannelConfigUiHints({
258
- channelLabel: "Mattermost",
252
+ implicitMentions: true,
253
+ streaming: {
254
+ "": "Unified Mattermost stream preview mode: \"off\" | \"partial\" | \"block\" | \"progress\". \"progress\" keeps a single editable progress draft until final delivery.",
255
+ mode: "Canonical Mattermost preview mode: \"off\" | \"partial\" | \"block\" | \"progress\".",
256
+ "block.enabled": "Enable chunked block-style Mattermost preview delivery when channels.mattermost.streaming.mode=\"block\".",
257
+ "block.coalesce": "Merge streamed Mattermost block replies before final delivery.",
258
+ "preview.toolProgress": "Show tool/progress activity in the live draft preview post (default: true). Set false to hide interim tool updates while the draft preview stays active.",
259
+ "preview.commandText": "Command/exec detail in preview tool-progress lines: \"raw\" preserves released behavior; \"status\" shows only the tool label."
260
+ },
259
261
  progress: {}
260
- }),
261
- "streaming.preview.toolProgress": {
262
- label: "Mattermost Draft Tool Progress",
263
- help: "Show tool/progress activity in the live draft preview post (default: true). Set false to hide interim tool updates while the draft preview stays active."
264
- },
265
- "streaming.preview.commandText": {
266
- label: "Mattermost Draft Command Text",
267
- help: "Command/exec detail in preview tool-progress lines: \"raw\" preserves released behavior; \"status\" shows only the tool label."
268
- },
269
- "streaming.block.enabled": {
270
- label: "Mattermost Block Streaming Enabled",
271
- help: "Enable chunked block-style Mattermost preview delivery when channels.mattermost.streaming.mode=\"block\"."
272
- },
273
- "streaming.block.coalesce": {
274
- label: "Mattermost Block Streaming Coalesce",
275
- help: "Merge streamed Mattermost block replies before final delivery."
276
- }
262
+ })
277
263
  } });
278
264
  const mattermostDoctor = {
279
265
  legacyConfigRules,
@@ -335,6 +321,19 @@ function looksLikeMattermostTargetId(raw, _normalized) {
335
321
  }
336
322
  //#endregion
337
323
  //#region extensions/mattermost/src/session-route.ts
324
+ /**
325
+ * Reads the peer chat-kind already recorded for `peerId` in an agent session
326
+ * key. Agent session keys are
327
+ * `agent:<agentId>:mattermost:<direct|group|channel>:<peerId>[:thread:...]`, so
328
+ * the segment right after `mattermost:` is the authoritative inbound chat kind.
329
+ */
330
+ function mattermostSessionKeyPeerKind(sessionKey, peerId) {
331
+ if (!sessionKey || !peerId) return;
332
+ const match = /^agent:[^:]+:mattermost:(direct|group|channel):([^:]+)(?::thread:[^:]+)?$/i.exec(sessionKey);
333
+ const kind = match?.[1]?.toLowerCase();
334
+ if (!kind || match?.[2] !== peerId) return;
335
+ return kind;
336
+ }
338
337
  function resolveMattermostOutboundSessionRoute(params) {
339
338
  let trimmed = stripChannelTargetPrefix(params.target, "mattermost");
340
339
  if (!trimmed) return null;
@@ -346,6 +345,8 @@ function resolveMattermostOutboundSessionRoute(params) {
346
345
  if (!rawId) return null;
347
346
  const hasExplicitUserKind = resolvedKind === "user" || lower.startsWith("user:");
348
347
  const recipientSessionExact = isUser && hasExplicitUserKind && /^[a-z0-9]{26}$/.test(rawId);
348
+ const isGroup = !isUser && (resolvedKind === "group" || resolvedKind !== "channel" && (lower.startsWith("group:") || mattermostSessionKeyPeerKind(params.currentSessionKey, rawId) === "group"));
349
+ const kind = isUser ? "direct" : isGroup ? "group" : "channel";
349
350
  return buildThreadAwareOutboundSessionRoute({
350
351
  route: buildChannelOutboundSessionRoute({
351
352
  cfg: params.cfg,
@@ -354,11 +355,11 @@ function resolveMattermostOutboundSessionRoute(params) {
354
355
  accountId: params.accountId,
355
356
  recipientSessionExact,
356
357
  peer: {
357
- kind: isUser ? "direct" : "channel",
358
+ kind,
358
359
  id: rawId
359
360
  },
360
- chatType: isUser ? "direct" : "channel",
361
- from: isUser ? `mattermost:${rawId}` : `mattermost:channel:${rawId}`,
361
+ chatType: kind,
362
+ from: isUser ? `mattermost:${rawId}` : `mattermost:${kind}:${rawId}`,
362
363
  to: isUser ? `user:${rawId}` : `channel:${rawId}`
363
364
  }),
364
365
  replyToId: params.replyToId,
@@ -374,10 +375,9 @@ function isMattermostConfigured(account) {
374
375
  return (Boolean(account.botToken?.trim()) || hasConfiguredSecretInput(account.config.botToken)) && Boolean(account.baseUrl);
375
376
  }
376
377
  function resolveMattermostAccountWithSecrets(cfg, accountId) {
377
- return resolveMattermostAccount({
378
+ return inspectMattermostAccount({
378
379
  cfg,
379
- accountId,
380
- allowUnresolvedSecretRef: true
380
+ accountId
381
381
  });
382
382
  }
383
383
  function applyMattermostSetupConfigPatch(params) {
@@ -559,7 +559,7 @@ const mattermostSetupWizard = {
559
559
  };
560
560
  //#endregion
561
561
  //#region extensions/mattermost/src/channel.ts
562
- const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-VRis1MN2.js"));
562
+ const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-DndW9G7T.js"));
563
563
  function buildMattermostPresentationButtons(presentation) {
564
564
  return presentation.blocks.filter((block) => block.type === "buttons").map((block) => block.buttons.flatMap((button) => {
565
565
  if (button.action) return [];
@@ -587,8 +587,12 @@ function hasMattermostPresentationNavigation(presentation) {
587
587
  return action?.type === "url" || action?.type === "web-app" && Boolean(action.url);
588
588
  }));
589
589
  }
590
+ function readMattermostPayloadData(payload) {
591
+ const data = payload.channelData?.mattermost;
592
+ return data && typeof data === "object" && !Array.isArray(data) ? data : void 0;
593
+ }
590
594
  function readMattermostPresentationButtons(payload) {
591
- const buttons = (payload.channelData?.mattermost)?.presentationButtons;
595
+ const buttons = readMattermostPayloadData(payload)?.presentationButtons;
592
596
  return Array.isArray(buttons) ? buttons : void 0;
593
597
  }
594
598
  const mattermostSecurityAdapter = createRestrictSendersChannelSecurity({
@@ -604,29 +608,32 @@ const mattermostSecurityAdapter = createRestrictSendersChannelSecurity({
604
608
  normalizeDmEntry: (raw) => normalizeMattermostAllowEntry(raw)
605
609
  });
606
610
  function describeMattermostMessageTool({ cfg, accountId }) {
607
- const enabledAccounts = (accountId ? [resolveMattermostAccount({
611
+ const enabledAccounts = (accountId ? [inspectMattermostAccount({
608
612
  cfg,
609
613
  accountId
610
- })] : listMattermostAccountIds(cfg).map((listedAccountId) => resolveMattermostAccount({
614
+ })] : listMattermostAccountIds(cfg).map((listedAccountId) => inspectMattermostAccount({
611
615
  cfg,
612
616
  accountId: listedAccountId
613
617
  }))).filter((account) => account.enabled).filter((account) => Boolean(account.botToken?.trim() && account.baseUrl?.trim()));
614
618
  const actions = [];
615
619
  if (enabledAccounts.length > 0) actions.push("send");
616
- const baseReactions = (cfg.channels?.mattermost?.actions)?.reactions;
620
+ const actionsConfig = cfg.channels?.mattermost?.actions;
621
+ const baseMessages = actionsConfig?.messages;
622
+ const baseReactions = actionsConfig?.reactions;
617
623
  if (enabledAccounts.some((account) => {
618
624
  return account.config.actions?.reactions ?? baseReactions ?? true;
619
625
  })) actions.push("react");
626
+ if (enabledAccounts.some((account) => account.config.actions?.messages ?? baseMessages ?? false)) actions.push("read");
620
627
  return {
621
628
  actions,
622
629
  capabilities: enabledAccounts.length > 0 ? ["presentation"] : []
623
630
  };
624
631
  }
625
632
  function hasConfiguredMattermostDirectoryAccount({ cfg, accountId }) {
626
- return (accountId ? [resolveMattermostAccount({
633
+ return (accountId ? [inspectMattermostAccount({
627
634
  cfg,
628
635
  accountId
629
- })] : listMattermostAccountIds(cfg).map((listedAccountId) => resolveMattermostAccount({
636
+ })] : listMattermostAccountIds(cfg).map((listedAccountId) => inspectMattermostAccount({
630
637
  cfg,
631
638
  accountId: listedAccountId
632
639
  }))).some((account) => Boolean(account.enabled && account.botToken?.trim() && account.baseUrl?.trim()));
@@ -719,10 +726,67 @@ const mattermostMessageActions = {
719
726
  describeMessageTool: describeMattermostMessageTool,
720
727
  extractToolSend: ({ args }) => extractMattermostToolSend(args),
721
728
  extractToolSendResult: ({ result, send }) => extractMattermostToolSendResult(result, send),
729
+ prepareSendPayload: ({ ctx, payload }) => {
730
+ if (ctx.action !== "send") return null;
731
+ const mediaUrl = resolveMattermostSendAttachmentMedia(ctx.params);
732
+ const attachmentText = typeof ctx.params.attachmentText === "string" ? ctx.params.attachmentText : void 0;
733
+ const existingMattermostData = readMattermostPayloadData(payload);
734
+ return {
735
+ ...payload,
736
+ ...mediaUrl ? {
737
+ mediaUrl,
738
+ mediaUrls: [mediaUrl]
739
+ } : {},
740
+ ...attachmentText !== void 0 ? { channelData: {
741
+ ...payload.channelData,
742
+ mattermost: {
743
+ ...existingMattermostData,
744
+ attachmentText
745
+ }
746
+ } } : {}
747
+ };
748
+ },
722
749
  supportsAction: ({ action }) => {
723
- return action === "send" || action === "react";
750
+ return action === "send" || action === "react" || action === "read";
724
751
  },
725
- handleAction: async ({ action, params, cfg, accountId, mediaAccess, mediaLocalRoots, mediaReadFile, conversationReadOrigin }) => {
752
+ handleAction: async ({ action, params, cfg, accountId, mediaAccess, mediaLocalRoots, mediaReadFile, conversationReadOrigin, requesterAccountId, toolContext }) => {
753
+ if (action === "read") {
754
+ const resolvedAccountId = accountId ?? resolveDefaultMattermostAccountId(cfg);
755
+ const mattermostConfig = cfg.channels?.mattermost;
756
+ const account = resolveMattermostAccount({
757
+ cfg,
758
+ accountId: resolvedAccountId
759
+ });
760
+ if (!account.enabled) throw new Error(`Mattermost account "${resolvedAccountId}" is disabled`);
761
+ if (!(account.config.actions?.messages ?? mattermostConfig?.actions?.messages ?? false)) throw new Error("Mattermost message reads are disabled in config");
762
+ const rawTarget = readStringParam(params, "to") ?? readStringParam(params, "channelId") ?? readStringParam(params, "target");
763
+ if (!rawTarget) throw new Error("Mattermost read requires target, to, or channelId.");
764
+ const normalizedTarget = normalizeMattermostMessagingTarget(rawTarget);
765
+ const channelId = normalizedTarget?.startsWith("channel:") ? normalizedTarget.slice(8).trim() : !rawTarget.includes(":") ? rawTarget : "";
766
+ if (!channelId) throw new Error("Mattermost read requires a channel target.");
767
+ const before = readStringParam(params, "before");
768
+ const after = readStringParam(params, "after");
769
+ if (before && after) throw new Error("Mattermost read accepts either before or after, not both.");
770
+ const result = await (await loadMattermostChannelRuntime()).readMattermostMessages({
771
+ cfg,
772
+ channelId,
773
+ limit: readPositiveIntegerParam(params, "limit", { message: "limit must be a positive integer." }),
774
+ before,
775
+ after,
776
+ accountId: resolvedAccountId,
777
+ context: {
778
+ conversationReadOrigin,
779
+ requesterAccountId,
780
+ toolContext
781
+ }
782
+ });
783
+ return jsonResult({
784
+ ok: true,
785
+ channelId,
786
+ messages: result.messages.map((message) => withNormalizedTimestamp(message, message.create_at)),
787
+ hasMore: result.hasMore
788
+ });
789
+ }
726
790
  if (action === "react") {
727
791
  const resolvedAccountId = accountId ?? resolveDefaultMattermostAccountId(cfg);
728
792
  const mattermostConfig = cfg.channels?.mattermost;
@@ -779,9 +843,7 @@ const mattermostMessageActions = {
779
843
  }) : typeof params.message === "string" ? params.message : "";
780
844
  const replyToId = normalizeOptionalString(params.replyToId) ?? normalizeOptionalString(params.threadId) ?? normalizeOptionalString(params.replyTo);
781
845
  const resolvedAccountId = accountId || void 0;
782
- const attachmentMedia = collectMattermostAttachmentMedia(params);
783
- if (attachmentMedia.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.");
784
- if (attachmentMedia.mediaUrls.length > 1) throw new Error("Mattermost send supports one attachment per message; split multiple mediaUrls or attachments[] entries into separate sends.");
846
+ const mediaUrl = resolveMattermostSendAttachmentMedia(params);
785
847
  const buttons = presentation ? buildMattermostPresentationButtons(presentation) : [];
786
848
  const result = await (await loadMattermostChannelRuntime()).sendMessageMattermost(to, message, {
787
849
  cfg,
@@ -789,11 +851,11 @@ const mattermostMessageActions = {
789
851
  replyToId,
790
852
  buttons: buttons.length > 0 ? buttons : void 0,
791
853
  attachmentText: typeof params.attachmentText === "string" ? params.attachmentText : void 0,
792
- mediaUrl: attachmentMedia.mediaUrls[0],
854
+ mediaUrl,
793
855
  mediaLocalRoots: mediaLocalRoots ?? mediaAccess?.localRoots,
794
856
  mediaReadFile: mediaReadFile ?? mediaAccess?.readFile,
795
857
  ...mediaAccess?.workspaceDir ? { workspaceDir: mediaAccess.workspaceDir } : {},
796
- requireMediaUpload: requiresMattermostMediaUpload(attachmentMedia.mediaUrls[0]) ? true : void 0
858
+ requireMediaUpload: requiresMattermostMediaUpload(mediaUrl) ? true : void 0
797
859
  });
798
860
  return {
799
861
  content: [{
@@ -884,6 +946,17 @@ function collectMattermostAttachmentMedia(params) {
884
946
  hasUnsupportedAttachmentPayload
885
947
  };
886
948
  }
949
+ function resolveMattermostSendAttachmentMedia(params) {
950
+ const attachmentMedia = collectMattermostAttachmentMedia(params);
951
+ if (attachmentMedia.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.");
952
+ if (attachmentMedia.mediaUrls.length > 1) throw new Error("Mattermost send supports one attachment per message; split multiple mediaUrls or attachments[] entries into separate sends.");
953
+ return attachmentMedia.mediaUrls[0];
954
+ }
955
+ function createMattermostDeliveryProgressReporter(onDeliveryResult) {
956
+ return onDeliveryResult ? async (result) => {
957
+ await onDeliveryResult(attachChannelToResult("mattermost", result));
958
+ } : void 0;
959
+ }
887
960
  const mattermostOutbound = {
888
961
  deliveryMode: "direct",
889
962
  chunker: chunkTextForOutbound,
@@ -921,7 +994,9 @@ const mattermostOutbound = {
921
994
  },
922
995
  sendPayload: async (ctx) => {
923
996
  const buttons = readMattermostPresentationButtons(ctx.payload);
924
- if (buttons?.length) {
997
+ const rawAttachmentText = readMattermostPayloadData(ctx.payload)?.attachmentText;
998
+ const attachmentText = typeof rawAttachmentText === "string" ? rawAttachmentText : void 0;
999
+ if (buttons?.length || attachmentText !== void 0) {
925
1000
  const mediaUrl = resolvePayloadMediaUrls({
926
1001
  ...ctx.payload,
927
1002
  mediaUrl: ctx.payload.mediaUrl ?? ctx.mediaUrl
@@ -935,7 +1010,9 @@ const mattermostOutbound = {
935
1010
  ...ctx.mediaAccess?.workspaceDir ? { workspaceDir: ctx.mediaAccess.workspaceDir } : {},
936
1011
  requireMediaUpload: requiresMattermostMediaUpload(mediaUrl) ? true : void 0,
937
1012
  replyToId: ctx.replyToId ?? (ctx.threadId != null ? String(ctx.threadId) : void 0),
938
- buttons
1013
+ buttons: buttons?.length ? buttons : void 0,
1014
+ attachmentText,
1015
+ onDeliveryResult: createMattermostDeliveryProgressReporter(ctx.onDeliveryResult)
939
1016
  }));
940
1017
  }
941
1018
  return await sendTextMediaPayload({
@@ -957,12 +1034,13 @@ const mattermostOutbound = {
957
1034
  },
958
1035
  ...createAttachedChannelResultAdapter({
959
1036
  channel: "mattermost",
960
- sendText: async ({ cfg, to, text, accountId, replyToId, threadId }) => await (await loadMattermostChannelRuntime()).sendMessageMattermost(to, text, {
1037
+ sendText: async ({ cfg, to, text, accountId, replyToId, threadId, onDeliveryResult }) => await (await loadMattermostChannelRuntime()).sendMessageMattermost(to, text, {
961
1038
  cfg,
962
1039
  accountId: accountId ?? void 0,
963
- replyToId: replyToId ?? (threadId != null ? String(threadId) : void 0)
1040
+ replyToId: replyToId ?? (threadId != null ? String(threadId) : void 0),
1041
+ onDeliveryResult: createMattermostDeliveryProgressReporter(onDeliveryResult)
964
1042
  }),
965
- sendMedia: async ({ cfg, to, text, mediaUrl, mediaAccess, mediaLocalRoots, mediaReadFile, accountId, replyToId, threadId }) => await (await loadMattermostChannelRuntime()).sendMessageMattermost(to, text, {
1043
+ sendMedia: async ({ cfg, to, text, mediaUrl, mediaAccess, mediaLocalRoots, mediaReadFile, accountId, replyToId, threadId, onDeliveryResult }) => await (await loadMattermostChannelRuntime()).sendMessageMattermost(to, text, {
966
1044
  cfg,
967
1045
  accountId: accountId ?? void 0,
968
1046
  mediaUrl,
@@ -970,7 +1048,8 @@ const mattermostOutbound = {
970
1048
  mediaReadFile: mediaReadFile ?? mediaAccess?.readFile,
971
1049
  ...mediaAccess?.workspaceDir ? { workspaceDir: mediaAccess.workspaceDir } : {},
972
1050
  requireMediaUpload: requiresMattermostMediaUpload(mediaUrl) ? true : void 0,
973
- replyToId: replyToId ?? (threadId != null ? String(threadId) : void 0)
1051
+ replyToId: replyToId ?? (threadId != null ? String(threadId) : void 0),
1052
+ onDeliveryResult: createMattermostDeliveryProgressReporter(onDeliveryResult)
974
1053
  })
975
1054
  })
976
1055
  };
@@ -1024,6 +1103,7 @@ const mattermostPlugin = createChatChannelPlugin({
1024
1103
  configSchema: MattermostChannelConfigSchema,
1025
1104
  config: {
1026
1105
  ...mattermostConfigAdapter,
1106
+ inspectAccount: adaptScopedAccountAccessor(inspectMattermostAccount),
1027
1107
  isConfigured: isMattermostConfigured$1,
1028
1108
  describeAccount: describeMattermostAccount
1029
1109
  },
@@ -1102,6 +1182,7 @@ const mattermostPlugin = createChatChannelPlugin({
1102
1182
  configured: Boolean(account.botToken && account.baseUrl),
1103
1183
  extra: {
1104
1184
  botTokenSource: account.botTokenSource,
1185
+ botTokenStatus: account.botTokenStatus,
1105
1186
  baseUrl: account.baseUrl,
1106
1187
  dmPolicy: account.config.dmPolicy ?? "pairing",
1107
1188
  connected: runtime?.connected ?? false,
@@ -1,2 +1,2 @@
1
- import { t as mattermostPlugin } from "./channel-plugin-runtime-CgRXlOvV.js";
1
+ import { t as mattermostPlugin } from "./channel-plugin-runtime-DlrMaSIu.js";
2
2
  export { mattermostPlugin };