@openclaw/mattermost 2026.7.2-beta.7 → 2026.8.1-beta.3

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,5 +1,8 @@
1
1
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
3
+ import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
2
4
  import { buildTimeoutAbortSignal } from "openclaw/plugin-sdk/extension-shared";
5
+ import { responseWithRelease } from "openclaw/plugin-sdk/fetch-runtime";
3
6
  import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
4
7
  import { readProviderJsonResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
5
8
  import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
@@ -10,12 +13,6 @@ import { z } from "zod";
10
13
  const MATTERMOST_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
11
14
  const MATTERMOST_REQUEST_TIMEOUT_MS = 3e4;
12
15
  const MATTERMOST_TEXT_RESPONSE_LIMIT_BYTES = 64 * 1024;
13
- const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([
14
- 101,
15
- 204,
16
- 205,
17
- 304
18
- ]);
19
16
  const MattermostPostSchema = z.object({
20
17
  id: z.string(),
21
18
  user_id: z.string().nullable().optional(),
@@ -33,6 +30,14 @@ const MattermostPostListSchema = z.object({
33
30
  next_post_id: z.string().nullable().optional(),
34
31
  prev_post_id: z.string().nullable().optional()
35
32
  }).passthrough();
33
+ function parseMattermostApiStatus(error) {
34
+ if (!error || typeof error !== "object") return;
35
+ const message = "message" in error && typeof error.message === "string" ? error.message : "";
36
+ const match = /Mattermost API (\d{3})\b/.exec(message);
37
+ if (!match) return;
38
+ const status = Number(match[1]);
39
+ return Number.isFinite(status) ? status : void 0;
40
+ }
36
41
  function normalizeMattermostBaseUrl(raw) {
37
42
  const trimmed = raw?.trim();
38
43
  if (!trimmed) return;
@@ -69,48 +74,6 @@ async function readMattermostError(res) {
69
74
  }
70
75
  return text;
71
76
  }
72
- function responseWithRelease(response, release) {
73
- let released = false;
74
- const releaseOnce = async () => {
75
- if (released) return;
76
- released = true;
77
- await release();
78
- };
79
- if (!response.body || NULL_BODY_STATUSES.has(response.status)) {
80
- releaseOnce();
81
- return new Response(null, {
82
- status: response.status,
83
- statusText: response.statusText,
84
- headers: response.headers
85
- });
86
- }
87
- const reader = response.body.getReader();
88
- const body = new ReadableStream({
89
- async pull(controller) {
90
- try {
91
- const { done, value } = await reader.read();
92
- if (done) {
93
- await releaseOnce();
94
- controller.close();
95
- return;
96
- }
97
- if (value) controller.enqueue(value);
98
- } catch (error) {
99
- await releaseOnce();
100
- throw error;
101
- }
102
- },
103
- async cancel(reason) {
104
- await reader.cancel(reason).catch(() => void 0);
105
- await releaseOnce();
106
- }
107
- });
108
- return new Response(body, {
109
- status: response.status,
110
- statusText: response.statusText,
111
- headers: response.headers
112
- });
113
- }
114
77
  function createMattermostClient(params) {
115
78
  const baseUrl = normalizeMattermostBaseUrl(params.baseUrl);
116
79
  if (!baseUrl) throw new Error("Mattermost baseUrl is required");
@@ -166,8 +129,16 @@ function createMattermostClient(params) {
166
129
  throw new Error(`Mattermost API ${res.status} ${res.statusText}: ${detail || "unknown error"}`);
167
130
  }
168
131
  if (res.status === 204) return;
169
- if ((res.headers.get("content-type") ?? "").includes("application/json")) return await readProviderJsonResponse(res, `Mattermost API ${path}`);
170
- return await readMattermostSuccessText(res, path);
132
+ try {
133
+ if ((res.headers.get("content-type") ?? "").includes("application/json")) return await readProviderJsonResponse(res, `Mattermost API ${path}`);
134
+ return await readMattermostSuccessText(res, path);
135
+ } catch (error) {
136
+ if (path === "/posts" && init?.method?.toUpperCase() === "POST") throw createChannelPartialDeliveryError(error, {
137
+ messageIds: [],
138
+ visibleReplySent: true
139
+ });
140
+ throw error;
141
+ }
171
142
  };
172
143
  return {
173
144
  baseUrl,
@@ -305,7 +276,11 @@ async function createMattermostDirectChannelWithRetry(client, userIds, options =
305
276
  });
306
277
  }
307
278
  function isRetryableError(error) {
308
- const candidates = collectErrorCandidates(error);
279
+ const candidates = collectErrorGraphCandidates(error, (current) => [
280
+ current.cause,
281
+ current.reason,
282
+ ...Array.isArray(current.errors) ? current.errors : []
283
+ ]);
309
284
  const messages = candidates.map((candidate) => normalizeLowercaseStringOrEmpty(readErrorMessage(candidate))).filter((message) => Boolean(message));
310
285
  if (messages.some((message) => /mattermost api 5\d{2}\b/.test(message))) return true;
311
286
  if (messages.some((message) => /mattermost api 429\b/.test(message) || message.includes("too many requests"))) return true;
@@ -332,24 +307,6 @@ function isRetryableError(error) {
332
307
  if (names.some((name) => RETRYABLE_NETWORK_ERROR_NAMES.has(name))) return true;
333
308
  return messages.some((message) => RETRYABLE_NETWORK_MESSAGE_SNIPPETS.some((pattern) => message.includes(pattern)));
334
309
  }
335
- function collectErrorCandidates(error) {
336
- const queue = [error];
337
- let queueIndex = 0;
338
- const seen = /* @__PURE__ */ new Set();
339
- const candidates = [];
340
- while (queueIndex < queue.length) {
341
- const current = queue[queueIndex];
342
- queueIndex += 1;
343
- if (!current || seen.has(current)) continue;
344
- seen.add(current);
345
- candidates.push(current);
346
- if (typeof current !== "object") continue;
347
- const nested = current;
348
- queue.push(nested.cause, nested.reason);
349
- if (Array.isArray(nested.errors)) queue.push(...nested.errors);
350
- }
351
- return candidates;
352
- }
353
310
  function readErrorMessage(error) {
354
311
  if (!error || typeof error !== "object") return;
355
312
  const message = error.message;
@@ -375,10 +332,19 @@ async function createMattermostPost(client, params) {
375
332
  if (params.rootId) payload.root_id = params.rootId;
376
333
  if (params.fileIds?.length) payload.file_ids = params.fileIds;
377
334
  if (params.props) payload.props = params.props;
378
- return await client.request("/posts", {
335
+ const post = await client.request("/posts", {
379
336
  method: "POST",
380
337
  body: JSON.stringify(payload)
381
338
  });
339
+ const postId = post && typeof post === "object" ? normalizeOptionalString(post.id) : void 0;
340
+ if (!postId) throw createChannelPartialDeliveryError(/* @__PURE__ */ new Error("Mattermost post creation response did not include a post id"), {
341
+ messageIds: [],
342
+ visibleReplySent: true
343
+ });
344
+ return postId === post.id ? post : {
345
+ ...post,
346
+ id: postId
347
+ };
382
348
  }
383
349
  async function fetchMattermostUserTeams(client, userId) {
384
350
  return await client.request(`/users/${userId}/teams`);
@@ -416,4 +382,4 @@ async function uploadMattermostFile(client, params) {
416
382
  return info;
417
383
  }
418
384
  //#endregion
419
- export { sendMattermostTyping as _, createMattermostPost as a, fetchMattermostChannelByName as c, fetchMattermostUser as d, fetchMattermostUserByUsername as f, resolveMattermostReplyDeliveryBarrierTimeoutMs as g, readMattermostError as h, createMattermostDirectChannelWithRetry as i, fetchMattermostChannelPosts as l, normalizeMattermostBaseUrl as m, buildMattermostApiUrl as n, deleteMattermostPost as o, fetchMattermostUserTeams as p, createMattermostClient as r, fetchMattermostChannel as s, MattermostPostSchema as t, fetchMattermostMe as u, updateMattermostPost as v, uploadMattermostFile as y };
385
+ export { resolveMattermostReplyDeliveryBarrierTimeoutMs as _, createMattermostPost as a, uploadMattermostFile as b, fetchMattermostChannelByName as c, fetchMattermostUser as d, fetchMattermostUserByUsername as f, readMattermostError as g, parseMattermostApiStatus as h, createMattermostDirectChannelWithRetry as i, fetchMattermostChannelPosts as l, normalizeMattermostBaseUrl as m, buildMattermostApiUrl as n, deleteMattermostPost as o, fetchMattermostUserTeams as p, createMattermostClient as r, fetchMattermostChannel as s, MattermostPostSchema as t, fetchMattermostMe as u, sendMattermostTyping as v, updateMattermostPost as y };
@@ -1,2 +1,2 @@
1
- import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-BaUvVh8e.js";
1
+ import { n as normalizeCompatibilityConfig, t as legacyConfigRules } from "./doctor-contract-mvORF4f6.js";
2
2
  export { legacyConfigRules, normalizeCompatibilityConfig };
@@ -1,5 +1,4 @@
1
- import { createLegacyPrivateNetworkDoctorContract } from "openclaw/plugin-sdk/ssrf-runtime";
2
- import { defineChannelAliasMigration } from "openclaw/plugin-sdk/runtime-doctor";
1
+ import { createLegacyPrivateNetworkDoctorContract, defineChannelAliasMigration } from "openclaw/plugin-sdk/runtime-doctor-migrations";
3
2
  //#region extensions/mattermost/src/doctor-contract.ts
4
3
  const networkContract = createLegacyPrivateNetworkDoctorContract({ channelKey: "mattermost" });
5
4
  const streamingAliasMigration = defineChannelAliasMigration({
@@ -1,2 +1,2 @@
1
- import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-CL1PxV3z.js";
1
+ import { t as resolveMattermostGatewayAuthBypassPaths } from "./gateway-auth-bypass-B93t91oq.js";
2
2
  export { resolveMattermostGatewayAuthBypassPaths as resolveGatewayAuthBypassPaths };
@@ -1,22 +1,20 @@
1
+ import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
1
2
  //#region extensions/mattermost/src/gateway-auth-bypass.ts
2
3
  const DEFAULT_SLASH_CALLBACK_PATH = "/api/channels/mattermost/command";
3
- function readTrimmedString(value) {
4
- return typeof value === "string" && value.trim() ? value.trim() : void 0;
5
- }
6
4
  function normalizeCallbackPath(value) {
7
- const trimmed = readTrimmedString(value);
5
+ const trimmed = normalizeOptionalString(value);
8
6
  if (!trimmed) return DEFAULT_SLASH_CALLBACK_PATH;
9
7
  return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
10
8
  }
11
9
  function readMattermostCommands(value) {
12
- return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
10
+ return asOptionalRecord(value);
13
11
  }
14
12
  function isMattermostBypassPath(path) {
15
13
  return path === DEFAULT_SLASH_CALLBACK_PATH || path.startsWith("/api/channels/mattermost/");
16
14
  }
17
15
  function collectMattermostSlashCallbackPaths(raw) {
18
16
  const paths = /* @__PURE__ */ new Set([normalizeCallbackPath(raw?.callbackPath)]);
19
- const callbackUrl = readTrimmedString(raw?.callbackUrl);
17
+ const callbackUrl = normalizeOptionalString(raw?.callbackUrl);
20
18
  if (callbackUrl) try {
21
19
  const pathname = new URL(callbackUrl).pathname;
22
20
  if (pathname) paths.add(pathname);
@@ -1,7 +1,8 @@
1
1
  import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { v as updateMattermostPost } from "./client-CqqzTcno.js";
3
- import { b as readRequestBodyWithLimit, m as isTrustedProxyAddress, w as resolveClientIp } from "./monitor-auth-rctDliGZ.js";
2
+ import { y as updateMattermostPost } from "./client-B_hd-kwM.js";
3
+ import { C as resolveClientIp, m as isTrustedProxyAddress, y as readRequestBodyWithLimit } from "./monitor-auth-CVd_4FPD.js";
4
4
  import { createHmac } from "node:crypto";
5
+ import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
5
6
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
6
7
  import { normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
7
8
  //#region extensions/mattermost/src/mattermost/interactions.ts
@@ -47,7 +48,7 @@ function computeInteractionCallbackUrl(accountId, cfg) {
47
48
  const path = resolveInteractionCallbackPath(accountId);
48
49
  const callbackBaseUrl = normalizeOptionalString(cfg?.interactions?.callbackBaseUrl) ?? normalizeOptionalString(cfg?.channels?.mattermost?.interactions?.callbackBaseUrl);
49
50
  if (callbackBaseUrl) return `${normalizeCallbackBaseUrl(callbackBaseUrl)}${path}`;
50
- const port = typeof cfg?.gateway?.port === "number" ? cfg.gateway.port : 18789;
51
+ const port = resolveGatewayPort(cfg);
51
52
  let host = cfg?.gateway?.customBindHost && !isWildcardBindHost(cfg.gateway.customBindHost) ? cfg.gateway.customBindHost.trim() : "localhost";
52
53
  if (host.includes(":") && !(host.startsWith("[") && host.endsWith("]"))) host = `[${host}]`;
53
54
  return `http://${host}:${port}${path}`;
@@ -1,7 +1,7 @@
1
+ import { isTrustedProxyAddress, resolveClientIp } from "openclaw/plugin-sdk/core";
1
2
  import { normalizeLowercaseStringOrEmpty, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
2
- import { parseTcpPort } from "openclaw/plugin-sdk/number-runtime";
3
- import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
4
3
  import { logInboundDrop } from "openclaw/plugin-sdk/channel-inbound";
4
+ import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
5
5
  import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
6
6
  import { createChannelMessageReplyPipeline } from "openclaw/plugin-sdk/channel-outbound";
7
7
  import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
@@ -14,7 +14,6 @@ import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media";
14
14
  import { DEFAULT_GROUP_HISTORY_LIMIT, createChannelHistoryWindow } from "openclaw/plugin-sdk/reply-history";
15
15
  import { registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-targets";
16
16
  import { isRequestBodyLimitError, readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
17
- import { isTrustedProxyAddress, resolveClientIp } from "openclaw/plugin-sdk/core";
18
17
  import { parseAccessGroupAllowFromEntry } from "openclaw/plugin-sdk/access-groups";
19
18
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
20
19
  //#region extensions/mattermost/src/mattermost/monitor-auth.ts
@@ -182,4 +181,4 @@ async function authorizeMattermostCommandInvocation(params) {
182
181
  };
183
182
  }
184
183
  //#endregion
185
- export { resolveChannelMediaMaxBytes as C, warnMissingProviderGroupPolicyFallbackOnce as E, resolveAllowlistProviderRuntimeGroupPolicy$1 as S, resolveDefaultGroupPolicy as T, logInboundDrop as _, normalizeMattermostAllowList as a, readRequestBodyWithLimit as b, DEFAULT_GROUP_HISTORY_LIMIT as c, createChannelMessageReplyPipeline as d, createChannelPairingController as f, loadOutboundMediaFromUrl as g, listSkillCommandsForAgents as h, normalizeMattermostAllowEntry as i, buildModelsProviderData as l, isTrustedProxyAddress as m, formatMattermostDirectMessageDropLog as n, resolveMattermostMonitorInboundAccess as o, isRequestBodyLimitError as p, isMattermostSenderAllowed as r, resolveMattermostTrustedChatKind as s, authorizeMattermostCommandInvocation as t, createChannelHistoryWindow as u, logTypingFailure as v, resolveClientIp as w, registerPluginHttpRoute as x, parseTcpPort as y };
184
+ export { resolveClientIp as C, resolveChannelMediaMaxBytes as S, warnMissingProviderGroupPolicyFallbackOnce as T, logInboundDrop as _, normalizeMattermostAllowList as a, registerPluginHttpRoute as b, DEFAULT_GROUP_HISTORY_LIMIT as c, createChannelMessageReplyPipeline as d, createChannelPairingController as f, loadOutboundMediaFromUrl as g, listSkillCommandsForAgents as h, normalizeMattermostAllowEntry as i, buildModelsProviderData as l, isTrustedProxyAddress as m, formatMattermostDirectMessageDropLog as n, resolveMattermostMonitorInboundAccess as o, isRequestBodyLimitError as p, isMattermostSenderAllowed as r, resolveMattermostTrustedChatKind as s, authorizeMattermostCommandInvocation as t, createChannelHistoryWindow as u, logTypingFailure as v, resolveDefaultGroupPolicy as w, resolveAllowlistProviderRuntimeGroupPolicy$1 as x, readRequestBodyWithLimit as y };
@@ -1,2 +1,2 @@
1
- import { r as isMattermostSenderAllowed } from "./monitor-auth-rctDliGZ.js";
1
+ import { r as isMattermostSenderAllowed } from "./monitor-auth-CVd_4FPD.js";
2
2
  export { isMattermostSenderAllowed };
@@ -1,6 +1,7 @@
1
1
  import { r as setMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
2
+ import { DEFAULT_ACCOUNT_ID, buildChannelConfigSchema, createDedupeCache, isTrustedProxyAddress, parseStrictPositiveInteger, resolveClientIp } from "openclaw/plugin-sdk/core";
3
3
  import { formatInboundFromLabel, logInboundDrop } from "openclaw/plugin-sdk/channel-inbound";
4
+ import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
4
5
  import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
5
6
  import { createAccountStatusSink, createChannelMessageReplyPipeline } from "openclaw/plugin-sdk/channel-outbound";
6
7
  import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
@@ -13,7 +14,6 @@ import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media";
13
14
  import { DEFAULT_GROUP_HISTORY_LIMIT, buildPendingHistoryContextFromMap, clearHistoryEntriesIfEnabled, createChannelHistoryWindow, recordPendingHistoryEntryIfEnabled } from "openclaw/plugin-sdk/reply-history";
14
15
  import { registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-targets";
15
16
  import { isRequestBodyLimitError, rawDataToString, readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
16
- import { DEFAULT_ACCOUNT_ID, buildChannelConfigSchema, createDedupeCache, isTrustedProxyAddress, parseStrictPositiveInteger, resolveClientIp } from "openclaw/plugin-sdk/core";
17
17
  import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
18
18
  import { applyAccountNameToChannelSection, applySetupAccountConfigPatch, migrateBaseNameToDefaultAccount } from "openclaw/plugin-sdk/setup";
19
19
  import { buildComputedAccountStatusSnapshot } from "openclaw/plugin-sdk/channel-status";
@@ -1,2 +1,2 @@
1
- import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./secret-contract-B4R5Bmhv.js";
1
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries, t as channelSecrets } from "./secret-contract-qg3NXRlS.js";
2
2
  export { channelSecrets, collectRuntimeConfigAssignments, secretTargetRegistryEntries };
@@ -0,0 +1,12 @@
1
+ import { createSimpleChannelSecretContract } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
2
+ //#region extensions/mattermost/src/secret-contract.ts
3
+ const channelSecrets = createSimpleChannelSecretContract({
4
+ channelKey: "mattermost",
5
+ label: "Mattermost",
6
+ accountFields: ["botToken"],
7
+ channelFields: ["botToken"],
8
+ mode: "account-inheritance"
9
+ });
10
+ const { secretTargetRegistryEntries, collectRuntimeConfigAssignments } = channelSecrets;
11
+ //#endregion
12
+ export { collectRuntimeConfigAssignments as n, secretTargetRegistryEntries as r, channelSecrets as t };
@@ -1,2 +1,2 @@
1
- import { i as registerSlashCommandRoute } from "./slash-state-DM8qmFJR.js";
1
+ import { i as registerSlashCommandRoute } from "./slash-state-BakgoSSL.js";
2
2
  export { registerSlashCommandRoute };
@@ -1,14 +1,14 @@
1
1
  import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { _ as sendMattermostTyping, a as createMattermostPost, c as fetchMattermostChannelByName, d as fetchMattermostUser, f as fetchMattermostUserByUsername, g as resolveMattermostReplyDeliveryBarrierTimeoutMs, i as createMattermostDirectChannelWithRetry, m as normalizeMattermostBaseUrl, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe, y as uploadMattermostFile } from "./client-CqqzTcno.js";
3
- import { a as normalizeMattermostAllowList, b as readRequestBodyWithLimit, g as loadOutboundMediaFromUrl, l as buildModelsProviderData, p as isRequestBodyLimitError, s as resolveMattermostTrustedChatKind, t as authorizeMattermostCommandInvocation, v as logTypingFailure } from "./monitor-auth-rctDliGZ.js";
4
- import { c as setInteractionSecret, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-BQXY_48h.js";
5
- import { i as resolveMattermostAccount } from "./accounts-NaMdx9yF.js";
2
+ import { _ as resolveMattermostReplyDeliveryBarrierTimeoutMs, a as createMattermostPost, b as uploadMattermostFile, c as fetchMattermostChannelByName, d as fetchMattermostUser, f as fetchMattermostUserByUsername, h as parseMattermostApiStatus, i as createMattermostDirectChannelWithRetry, m as normalizeMattermostBaseUrl, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe, v as sendMattermostTyping } from "./client-B_hd-kwM.js";
3
+ import { a as normalizeMattermostAllowList, g as loadOutboundMediaFromUrl, l as buildModelsProviderData, p as isRequestBodyLimitError, s as resolveMattermostTrustedChatKind, t as authorizeMattermostCommandInvocation, v as logTypingFailure, y as readRequestBodyWithLimit } from "./monitor-auth-CVd_4FPD.js";
4
+ import { c as setInteractionSecret, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-Du_EJMeN.js";
5
+ import { i as resolveMattermostAccount } from "./accounts-DspH-NMT.js";
6
6
  import { createHash } from "node:crypto";
7
7
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
- import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ import { asFiniteNumber, normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
9
+ import { createChannelPartialDeliveryError, isChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
9
10
  import { asDateTimestampMs, parseStrictInteger, resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
10
11
  import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
11
- import { createChannelPartialDeliveryError, isChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
12
12
  import { createMessageReceiptFromOutboundResults, listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbound";
13
13
  import { resolveStoredModelOverride } from "openclaw/plugin-sdk/command-auth-native";
14
14
  import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
@@ -17,25 +17,14 @@ import { FormatCapabilityProfile, convertMarkdownTables } from "openclaw/plugin-
17
17
  import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
18
18
  import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
19
19
  import { Readable } from "node:stream";
20
+ import { truncateUtf16Safe, truncateUtf8Prefix } from "openclaw/plugin-sdk/text-utility-runtime";
20
21
  import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
21
22
  import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
22
- import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
23
23
  import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
24
24
  import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
25
+ import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
25
26
  import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
26
27
  const MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES = 128;
27
- function truncateMattermostCommandDescription(description) {
28
- if (Buffer.byteLength(description, "utf8") <= MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES) return description;
29
- let bytes = 0;
30
- let end = 0;
31
- for (const char of description) {
32
- const charBytes = Buffer.byteLength(char, "utf8");
33
- if (bytes + charBytes > MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES) break;
34
- bytes += charBytes;
35
- end += char.length;
36
- }
37
- return description.slice(0, end);
38
- }
39
28
  /**
40
29
  * Built-in OpenClaw commands to register as native slash commands.
41
30
  * These mirror the text-based commands already handled by the gateway.
@@ -162,7 +151,7 @@ async function registerSlashCommands(params) {
162
151
  }
163
152
  const registered = [];
164
153
  for (const spec of commands) {
165
- const description = truncateMattermostCommandDescription(spec.description);
154
+ const description = truncateUtf8Prefix(spec.description, MATTERMOST_COMMAND_DESCRIPTION_MAX_BYTES);
166
155
  const existingForTrigger = existingByTrigger.get(spec.trigger) ?? [];
167
156
  const ownedCommands = existingForTrigger.filter((cmd) => cmd.creator_id?.trim() === normalizedCreatorUserId);
168
157
  const foreignCommands = existingForTrigger.filter((cmd) => cmd.creator_id?.trim() !== normalizedCreatorUserId);
@@ -387,13 +376,11 @@ function splitModelRef(modelRef) {
387
376
  };
388
377
  }
389
378
  function readContextString(context, key, fallback = "") {
390
- const value = context[key];
391
- return typeof value === "string" ? value : fallback;
379
+ return readStringField(context, key) ?? fallback;
392
380
  }
393
381
  function readContextNumber(context, key) {
394
382
  const value = context[key];
395
- if (typeof value === "number" && Number.isFinite(value)) return value;
396
- if (typeof value === "string") return parseStrictInteger(value);
383
+ return asFiniteNumber(value) ?? parseStrictInteger(value);
397
384
  }
398
385
  function normalizePage(value) {
399
386
  if (!Number.isFinite(value)) return 1;
@@ -837,14 +824,6 @@ function isExplicitMattermostTarget(raw) {
837
824
  if (!trimmed) return false;
838
825
  return /^(channel|user|mattermost):/i.test(trimmed) || trimmed.startsWith("@") || trimmed.startsWith("#");
839
826
  }
840
- function parseMattermostApiStatus(err) {
841
- if (!err || typeof err !== "object") return;
842
- const msg = "message" in err && typeof err.message === "string" ? err.message : "";
843
- const match = /Mattermost API (\d{3})\b/.exec(msg);
844
- if (!match) return;
845
- const code = Number(match[1]);
846
- return Number.isFinite(code) ? code : void 0;
847
- }
848
827
  async function resolveMattermostOpaqueTarget(params) {
849
828
  const input = params.input.trim();
850
829
  if (!input || isExplicitMattermostTarget(input) || !isMattermostId(input)) return null;
@@ -924,15 +903,14 @@ function cacheOutboundEntry(cache, key, value, maxEntries) {
924
903
  }
925
904
  const getCore = () => getMattermostRuntime();
926
905
  function createMattermostSendReceipt(params) {
927
- const messageIds = params.messageId.trim() && params.messageId !== "unknown" ? [params.messageId] : [];
928
906
  return createMessageReceiptFromOutboundResults({
929
907
  kind: params.kind,
930
908
  ...params.replyToId ? { replyToId: params.replyToId } : {},
931
- results: messageIds.map((messageId) => ({
909
+ results: [{
932
910
  channel: "mattermost",
933
- messageId,
911
+ messageId: params.messageId,
934
912
  channelId: params.channelId
935
- }))
913
+ }]
936
914
  });
937
915
  }
938
916
  function resolveMattermostReceiptKind(params) {
@@ -1002,7 +980,9 @@ async function resolveChannelIdByName(params) {
1002
980
  cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
1003
981
  return channel.id;
1004
982
  }
1005
- } catch {}
983
+ } catch (error) {
984
+ if (parseMattermostApiStatus(error) !== 404) throw error;
985
+ }
1006
986
  throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
1007
987
  }
1008
988
  function mergeDmRetryOptions(base, override) {
@@ -1140,7 +1120,7 @@ async function sendMessageMattermost(to, text, opts) {
1140
1120
  fileIds = [(await uploadMattermostFile(client, {
1141
1121
  channelId,
1142
1122
  buffer: media.buffer,
1143
- fileName: media.fileName ?? "upload",
1123
+ fileName: media.fileName ?? `upload${extensionForMime(media.contentType) ?? ""}`,
1144
1124
  contentType: media.contentType ?? void 0
1145
1125
  })).id];
1146
1126
  } catch (err) {
@@ -1168,7 +1148,7 @@ async function sendMessageMattermost(to, text, opts) {
1168
1148
  fileIds,
1169
1149
  props
1170
1150
  });
1171
- const messageId = post.id ?? "unknown";
1151
+ const messageId = post.id;
1172
1152
  const receipt = createMattermostSendReceipt({
1173
1153
  messageId,
1174
1154
  channelId,
@@ -1698,7 +1678,10 @@ async function handleSlashCommandAsync(params) {
1698
1678
  SessionKey: route.sessionKey,
1699
1679
  AccountId: route.accountId,
1700
1680
  ChatType: chatType,
1681
+ ConversationRouteContextObserved: true,
1682
+ ConversationRoutePeerId: kind === "direct" ? senderId : channelId,
1701
1683
  ConversationLabel: fromLabel,
1684
+ GroupSpace: teamId,
1702
1685
  GroupSubject: kind !== "direct" ? channelDisplay || roomLabel : void 0,
1703
1686
  SenderName: senderName,
1704
1687
  SenderId: senderId,
@@ -1708,6 +1691,7 @@ async function handleSlashCommandAsync(params) {
1708
1691
  Timestamp: Date.now(),
1709
1692
  WasMentioned: true,
1710
1693
  CommandAuthorized: commandAuthorized,
1694
+ InboundAccessAuthorized: true,
1711
1695
  CommandSource: "native",
1712
1696
  OriginatingChannel: "mattermost",
1713
1697
  OriginatingTo: to
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "id": "mattermost",
3
+ "doctorContract": {
4
+ "configRepair": true
5
+ },
3
6
  "icon": "https://cdn.simpleicons.org/mattermost",
4
7
  "activation": {
5
8
  "onStartup": false
@@ -81,6 +84,29 @@
81
84
  ],
82
85
  "additionalProperties": false
83
86
  },
87
+ {
88
+ "type": "object",
89
+ "properties": {
90
+ "source": {
91
+ "type": "string",
92
+ "const": "store"
93
+ },
94
+ "provider": {
95
+ "type": "string",
96
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
97
+ },
98
+ "id": {
99
+ "type": "string",
100
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
101
+ }
102
+ },
103
+ "required": [
104
+ "source",
105
+ "provider",
106
+ "id"
107
+ ],
108
+ "additionalProperties": false
109
+ },
84
110
  {
85
111
  "type": "object",
86
112
  "properties": {
@@ -552,6 +578,29 @@
552
578
  ],
553
579
  "additionalProperties": false
554
580
  },
581
+ {
582
+ "type": "object",
583
+ "properties": {
584
+ "source": {
585
+ "type": "string",
586
+ "const": "store"
587
+ },
588
+ "provider": {
589
+ "type": "string",
590
+ "pattern": "^[a-z][a-z0-9_-]{0,63}$"
591
+ },
592
+ "id": {
593
+ "type": "string",
594
+ "pattern": "^[A-Z][A-Z0-9_]{0,127}$"
595
+ }
596
+ },
597
+ "required": [
598
+ "source",
599
+ "provider",
600
+ "id"
601
+ ],
602
+ "additionalProperties": false
603
+ },
555
604
  {
556
605
  "type": "object",
557
606
  "properties": {
@@ -1019,7 +1068,7 @@
1019
1068
  },
1020
1069
  "streaming.preview.commandText": {
1021
1070
  "label": "Mattermost Draft Command Text",
1022
- "help": "Command/exec detail in preview tool-progress lines: \"raw\" preserves released behavior; \"status\" shows only the tool label."
1071
+ "help": "Command/exec detail in preview tool-progress lines: \"status\" is the safe default; \"raw\" opts into command text."
1023
1072
  },
1024
1073
  "streaming.progress.label": {
1025
1074
  "label": "Mattermost Progress Label",
@@ -1043,7 +1092,7 @@
1043
1092
  },
1044
1093
  "streaming.progress.commandText": {
1045
1094
  "label": "Mattermost Progress Command Text",
1046
- "help": "Command/exec detail in progress draft lines: \"raw\" preserves released behavior; \"status\" shows only the tool label."
1095
+ "help": "Command/exec detail in progress draft lines: \"status\" is the safe default; \"raw\" opts into command text."
1047
1096
  }
1048
1097
  }
1049
1098
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/mattermost",
3
- "version": "2026.7.2-beta.7",
3
+ "version": "2026.8.1-beta.3",
4
4
  "description": "OpenClaw Mattermost channel plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  "zod": "4.4.3"
13
13
  },
14
14
  "peerDependencies": {
15
- "openclaw": ">=2026.7.2-beta.7"
15
+ "openclaw": ">=2026.8.1-beta.3"
16
16
  },
17
17
  "peerDependenciesMeta": {
18
18
  "openclaw": {
@@ -74,7 +74,11 @@
74
74
  "cli": {
75
75
  "flags": "--use-env",
76
76
  "description": "Use Mattermost environment credentials"
77
- }
77
+ },
78
+ "envVars": [
79
+ "MATTERMOST_BOT_TOKEN",
80
+ "MATTERMOST_URL"
81
+ ]
78
82
  }
79
83
  ]
80
84
  }
@@ -87,10 +91,10 @@
87
91
  "allowInvalidConfigRecovery": true
88
92
  },
89
93
  "compat": {
90
- "pluginApi": ">=2026.7.2-beta.7"
94
+ "pluginApi": ">=2026.8.1-beta.3"
91
95
  },
92
96
  "build": {
93
- "openclawVersion": "2026.7.2-beta.7",
97
+ "openclawVersion": "2026.8.1-beta.3",
94
98
  "bundledDist": false
95
99
  },
96
100
  "release": {
@@ -1,28 +0,0 @@
1
- import { collectSimpleChannelFieldAssignments, createChannelSecretTargetRegistryEntries, getChannelSurface } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
2
- //#region extensions/mattermost/src/secret-contract.ts
3
- const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries({
4
- channelKey: "mattermost",
5
- account: ["botToken"],
6
- channel: ["botToken"]
7
- });
8
- function collectRuntimeConfigAssignments(params) {
9
- const resolved = getChannelSurface(params.config, "mattermost");
10
- if (!resolved) return;
11
- const { channel: mattermost, surface } = resolved;
12
- collectSimpleChannelFieldAssignments({
13
- channelKey: "mattermost",
14
- field: "botToken",
15
- channel: mattermost,
16
- surface,
17
- defaults: params.defaults,
18
- context: params.context,
19
- topInactiveReason: "no enabled account inherits this top-level Mattermost botToken.",
20
- accountInactiveReason: "Mattermost account is disabled."
21
- });
22
- }
23
- const channelSecrets = {
24
- secretTargetRegistryEntries,
25
- collectRuntimeConfigAssignments
26
- };
27
- //#endregion
28
- export { collectRuntimeConfigAssignments as n, secretTargetRegistryEntries as r, channelSecrets as t };