@openclaw/mattermost 2026.7.2-beta.5 → 2026.8.1-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.
@@ -1,9 +1,9 @@
1
- import { p as normalizeMattermostBaseUrl } from "./client-w0lkxuKh.js";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-B_hd-kwM.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 { buildSecretInputSchema, hasConfiguredSecretInput, normalizeResolvedSecretInputString, normalizeSecretInputString } from "openclaw/plugin-sdk/secret-input";
6
+ import { buildSecretInputSchema, hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
7
7
  //#region extensions/mattermost/src/mattermost/accounts.ts
8
8
  const { listAccountIds: listMattermostAccountIds, resolveDefaultAccountId: resolveDefaultMattermostAccountId, resolveAccountConfig: mergeMattermostAccountConfig } = createAccountListHelpers("mattermost", {
9
9
  omitKeys: ["defaultAccount"],
@@ -19,7 +19,7 @@ function resolveMattermostRequireMention(config) {
19
19
  if (config.chatmode === "onchar") return true;
20
20
  return config.requireMention;
21
21
  }
22
- function resolveMattermostAccount(params) {
22
+ function resolveMattermostAccountWithMode(params) {
23
23
  const accountId = normalizeAccountId(params.accountId ?? resolveDefaultMattermostAccountId(params.cfg));
24
24
  const baseEnabled = params.cfg.channels?.mattermost?.enabled !== false;
25
25
  const merged = mergeMattermostAccountConfig(params.cfg, accountId);
@@ -28,15 +28,17 @@ function resolveMattermostAccount(params) {
28
28
  const allowEnv = accountId === DEFAULT_ACCOUNT_ID;
29
29
  const envToken = allowEnv ? process.env.MATTERMOST_BOT_TOKEN?.trim() : void 0;
30
30
  const envUrl = allowEnv ? process.env.MATTERMOST_URL?.trim() : void 0;
31
- const configToken = params.allowUnresolvedSecretRef ? normalizeSecretInputString(merged.botToken) : normalizeResolvedSecretInputString({
31
+ const configToken = resolveSecretInputString({
32
32
  value: merged.botToken,
33
- path: `channels.mattermost.accounts.${accountId}.botToken`
33
+ path: `channels.mattermost.accounts.${accountId}.botToken`,
34
+ mode: params.mode
34
35
  });
35
36
  const configUrl = merged.baseUrl?.trim();
36
- const botToken = configToken || envToken;
37
+ const botToken = configToken.status === "available" ? configToken.value : configToken.status === "missing" ? envToken : void 0;
37
38
  const baseUrl = normalizeMattermostBaseUrl(configUrl || envUrl);
38
39
  const requireMention = resolveMattermostRequireMention(merged);
39
- 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";
40
42
  const baseUrlSource = configUrl ? "config" : envUrl ? "env" : "none";
41
43
  return {
42
44
  accountId,
@@ -45,6 +47,7 @@ function resolveMattermostAccount(params) {
45
47
  botToken,
46
48
  baseUrl,
47
49
  botTokenSource,
50
+ botTokenStatus,
48
51
  baseUrlSource,
49
52
  config: merged,
50
53
  chatmode: merged.chatmode,
@@ -57,6 +60,18 @@ function resolveMattermostAccount(params) {
57
60
  blockStreamingCoalesce: resolveChannelStreamingBlockCoalesce(merged)
58
61
  };
59
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
+ }
60
75
  /**
61
76
  * Resolve the effective replyToMode for a given chat type.
62
77
  * Direct messages stay flat unless explicitly opted into a per-chat-type mode.
@@ -68,4 +83,4 @@ function resolveMattermostReplyToMode(account, kind) {
68
83
  return account.config.replyToMode ?? "off";
69
84
  }
70
85
  //#endregion
71
- 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-BOh6zLW9.js";
2
- import { t as buildButtonAttachments } from "./interactions-B4gg-KRm.js";
1
+ import { r as isMattermostSenderAllowed } from "./monitor-auth-CVd_4FPD.js";
2
+ import { t as buildButtonAttachments } from "./interactions-Du_EJMeN.js";
3
3
  export { buildButtonAttachments, isMattermostSenderAllowed };
@@ -1,5 +1,5 @@
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-DLBTUlbh.js";
2
- import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-CL1PxV3z.js";
1
+ import { a as MattermostChannelConfigSchema, c as mattermostConfigAdapter, l as mattermostMeta, n as mattermostSetupWizard, o as describeMattermostAccount, r as mattermostSetupContract, s as isMattermostConfigured, t as mattermostPlugin } from "./channel-plugin-runtime-Dxt8Zv1j.js";
2
+ import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-B93t91oq.js";
3
3
  //#region extensions/mattermost/src/channel.setup.ts
4
4
  const mattermostSetupPlugin = {
5
5
  id: "mattermost",
@@ -31,7 +31,6 @@ const mattermostSetupPlugin = {
31
31
  describeAccount: describeMattermostAccount
32
32
  },
33
33
  gateway: { resolveGatewayAuthBypassPaths: resolveMattermostGatewayAuthBypassPaths },
34
- setup: mattermostSetupAdapter,
35
34
  setupContract: mattermostSetupContract,
36
35
  setupWizard: mattermostSetupWizard
37
36
  };
@@ -1,8 +1,9 @@
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-BR6Nl5Qf.js";
3
- import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-CL1PxV3z.js";
4
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BaUvVh8e.js";
5
- import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-B4R5Bmhv.js";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-B_hd-kwM.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-DspH-NMT.js";
3
+ import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-B93t91oq.js";
4
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-mvORF4f6.js";
5
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-qg3NXRlS.js";
6
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, buildChannelOutboundSessionRoute, buildThreadAwareOutboundSessionRoute, stripChannelTargetPrefix, stripTargetKindPrefix } from "openclaw/plugin-sdk/core";
6
7
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
7
8
  import { buildPassiveProbedChannelStatusSummary } from "openclaw/plugin-sdk/extension-shared";
8
9
  import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
@@ -10,7 +11,8 @@ import { z } from "zod";
10
11
  import { formatNormalizedAllowFromEntries } from "openclaw/plugin-sdk/allow-from";
11
12
  import { createLoggedPairingApprovalNotifier } from "openclaw/plugin-sdk/channel-pairing";
12
13
  import { createAccountStatusSink, createChannelMessageAdapterFromOutbound } from "openclaw/plugin-sdk/channel-outbound";
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: \"status\" is the safe default; \"raw\" opts into command text."
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) {
@@ -397,47 +397,6 @@ function applyMattermostSetupConfigPatch(params) {
397
397
  patch: params.patch
398
398
  });
399
399
  }
400
- const mattermostSetupAdapter = {
401
- resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
402
- applyAccountName: ({ cfg, accountId, name }) => applyAccountNameToChannelSection({
403
- cfg,
404
- channelKey: channel$1,
405
- accountId,
406
- name
407
- }),
408
- validateInput: createSetupInputPresenceValidator({
409
- defaultAccountOnlyEnvError: "Mattermost env vars can only be used for the default account.",
410
- whenNotUseEnv: [{
411
- someOf: ["botToken", "token"],
412
- message: "Mattermost requires --bot-token and --http-url (or --use-env)."
413
- }, {
414
- someOf: ["httpUrl"],
415
- message: "Mattermost requires --bot-token and --http-url (or --use-env)."
416
- }],
417
- validate: ({ input }) => {
418
- const setupInput = input;
419
- const token = setupInput.botToken ?? setupInput.token;
420
- const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
421
- if (!setupInput.useEnv && (!token || !baseUrl)) return "Mattermost requires --bot-token and --http-url (or --use-env).";
422
- if (setupInput.httpUrl && !baseUrl) return "Mattermost --http-url must include a valid base URL.";
423
- return null;
424
- }
425
- }),
426
- applyAccountConfig: ({ cfg, accountId, input }) => {
427
- const setupInput = input;
428
- const token = setupInput.botToken ?? setupInput.token;
429
- const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
430
- return applyMattermostSetupConfigPatch({
431
- cfg,
432
- accountId,
433
- name: setupInput.name,
434
- patch: setupInput.useEnv ? {} : {
435
- ...token ? { botToken: token } : {},
436
- ...baseUrl ? { baseUrl } : {}
437
- }
438
- });
439
- }
440
- };
441
400
  const mattermostSetupContract = defineChannelSetupContract({
442
401
  fields: {
443
402
  token: {
@@ -468,10 +427,51 @@ const mattermostSetupContract = defineChannelSetupContract({
468
427
  cli: {
469
428
  flags: "--use-env",
470
429
  description: "Use Mattermost environment credentials"
471
- }
430
+ },
431
+ envVars: ["MATTERMOST_BOT_TOKEN", "MATTERMOST_URL"]
472
432
  }
473
433
  },
474
- legacyAdapter: mattermostSetupAdapter
434
+ legacyAdapter: {
435
+ resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
436
+ applyAccountName: ({ cfg, accountId, name }) => applyAccountNameToChannelSection({
437
+ cfg,
438
+ channelKey: channel$1,
439
+ accountId,
440
+ name
441
+ }),
442
+ validateInput: createSetupInputPresenceValidator({
443
+ defaultAccountOnlyEnvError: "Mattermost env vars can only be used for the default account.",
444
+ whenNotUseEnv: [{
445
+ someOf: ["botToken", "token"],
446
+ message: "Mattermost requires --bot-token and --http-url (or --use-env)."
447
+ }, {
448
+ someOf: ["httpUrl"],
449
+ message: "Mattermost requires --bot-token and --http-url (or --use-env)."
450
+ }],
451
+ validate: ({ input }) => {
452
+ const setupInput = input;
453
+ const token = setupInput.botToken ?? setupInput.token;
454
+ const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
455
+ if (!setupInput.useEnv && (!token || !baseUrl)) return "Mattermost requires --bot-token and --http-url (or --use-env).";
456
+ if (setupInput.httpUrl && !baseUrl) return "Mattermost --http-url must include a valid base URL.";
457
+ return null;
458
+ }
459
+ }),
460
+ applyAccountConfig: ({ cfg, accountId, input }) => {
461
+ const setupInput = input;
462
+ const token = setupInput.botToken ?? setupInput.token;
463
+ const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
464
+ return applyMattermostSetupConfigPatch({
465
+ cfg,
466
+ accountId,
467
+ name: setupInput.name,
468
+ patch: setupInput.useEnv ? {} : {
469
+ ...token ? { botToken: token } : {},
470
+ ...baseUrl ? { baseUrl } : {}
471
+ }
472
+ });
473
+ }
474
+ }
475
475
  });
476
476
  //#endregion
477
477
  //#region extensions/mattermost/src/setup-surface.ts
@@ -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-CR1V5M8l.js"));
562
+ const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime-FKnzxYBR.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
  };
@@ -994,7 +1073,6 @@ const mattermostPlugin = createChatChannelPlugin({
994
1073
  base: {
995
1074
  id: "mattermost",
996
1075
  meta: { ...mattermostMeta },
997
- setup: mattermostSetupAdapter,
998
1076
  setupContract: mattermostSetupContract,
999
1077
  setupWizard: mattermostSetupWizard,
1000
1078
  capabilities: {
@@ -1024,6 +1102,7 @@ const mattermostPlugin = createChatChannelPlugin({
1024
1102
  configSchema: MattermostChannelConfigSchema,
1025
1103
  config: {
1026
1104
  ...mattermostConfigAdapter,
1105
+ inspectAccount: adaptScopedAccountAccessor(inspectMattermostAccount),
1027
1106
  isConfigured: isMattermostConfigured$1,
1028
1107
  describeAccount: describeMattermostAccount
1029
1108
  },
@@ -1048,6 +1127,11 @@ const mattermostPlugin = createChatChannelPlugin({
1048
1127
  targetIdComparison: "case-sensitive",
1049
1128
  defaultMarkdownTableMode: "off",
1050
1129
  normalizeTarget: normalizeMattermostMessagingTarget,
1130
+ inferTargetChatType: ({ to }) => {
1131
+ const target = normalizeMattermostMessagingTarget(to);
1132
+ if (!target) return;
1133
+ return target.startsWith("user:") || target.startsWith("@") ? "direct" : "channel";
1134
+ },
1051
1135
  resolveDeliveryTarget: ({ conversationId, parentConversationId }) => {
1052
1136
  const parent = parentConversationId?.trim();
1053
1137
  const child = conversationId.trim();
@@ -1102,6 +1186,7 @@ const mattermostPlugin = createChatChannelPlugin({
1102
1186
  configured: Boolean(account.botToken && account.baseUrl),
1103
1187
  extra: {
1104
1188
  botTokenSource: account.botTokenSource,
1189
+ botTokenStatus: account.botTokenStatus,
1105
1190
  baseUrl: account.baseUrl,
1106
1191
  dmPolicy: account.config.dmPolicy ?? "pairing",
1107
1192
  connected: runtime?.connected ?? false,
@@ -1173,4 +1258,4 @@ const mattermostPlugin = createChatChannelPlugin({
1173
1258
  outbound: mattermostOutbound
1174
1259
  });
1175
1260
  //#endregion
1176
- export { normalizeMattermostMessagingTarget as a, isMattermostConfigured$1 as c, mattermostSetupContract as i, mattermostConfigAdapter as l, mattermostSetupWizard as n, MattermostChannelConfigSchema as o, mattermostSetupAdapter as r, describeMattermostAccount as s, mattermostPlugin as t, mattermostMeta as u };
1261
+ export { MattermostChannelConfigSchema as a, mattermostConfigAdapter as c, normalizeMattermostMessagingTarget as i, mattermostMeta as l, mattermostSetupWizard as n, describeMattermostAccount as o, mattermostSetupContract as r, isMattermostConfigured$1 as s, mattermostPlugin as t };
@@ -1,2 +1,2 @@
1
- import { t as mattermostPlugin } from "./channel-plugin-runtime-DLBTUlbh.js";
1
+ import { t as mattermostPlugin } from "./channel-plugin-runtime-Dxt8Zv1j.js";
2
2
  export { mattermostPlugin };