@openclaw/mattermost 2026.9.1-beta.1 → 2026.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ import { bufferToBlobPart } from "openclaw/plugin-sdk/blob-runtime";
2
3
  import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
3
4
  import { collectErrorGraphCandidates } from "openclaw/plugin-sdk/error-runtime";
4
5
  import { buildTimeoutAbortSignal } from "openclaw/plugin-sdk/extension-shared";
@@ -10,9 +11,9 @@ import { retryAsync } from "openclaw/plugin-sdk/retry-runtime";
10
11
  import { fetchWithSsrFGuard, ssrfPolicyFromPrivateNetworkOptIn } from "openclaw/plugin-sdk/ssrf-runtime";
11
12
  import { z } from "zod";
12
13
  //#region extensions/mattermost/src/mattermost/client.ts
13
- const MATTERMOST_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
14
+ const MATTERMOST_ERROR_BODY_LIMIT_BYTES = 8192;
14
15
  const MATTERMOST_REQUEST_TIMEOUT_MS = 3e4;
15
- const MATTERMOST_TEXT_RESPONSE_LIMIT_BYTES = 64 * 1024;
16
+ const MATTERMOST_TEXT_RESPONSE_LIMIT_BYTES = 65536;
16
17
  const MattermostPostSchema = z.object({
17
18
  id: z.string(),
18
19
  user_id: z.string().nullable().optional(),
@@ -98,18 +99,20 @@ function createMattermostClient(params) {
98
99
  const fetchImpl = (externalFetchImpl ? async (input, init) => {
99
100
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
100
101
  const { timeoutMs: initTimeoutMs, ...requestInit } = init ?? {};
102
+ const timeoutMs = resolveTimerTimeoutMs(initTimeoutMs, requestTimeoutMs);
101
103
  const { signal: timeoutSignal, cleanup } = buildTimeoutAbortSignal({
102
- timeoutMs: resolveTimerTimeoutMs(initTimeoutMs, requestTimeoutMs),
104
+ timeoutMs,
103
105
  operation: "mattermost-api",
104
106
  url
105
107
  });
106
108
  const callerSignal = requestInit.signal ?? void 0;
107
109
  const signal = callerSignal && timeoutSignal ? AbortSignal.any([callerSignal, timeoutSignal]) : callerSignal ?? timeoutSignal;
108
110
  try {
109
- return responseWithRelease(await externalFetchImpl(input, {
111
+ const response = await externalFetchImpl(input, {
110
112
  ...requestInit,
111
113
  signal
112
- }), async () => cleanup());
114
+ });
115
+ return responseWithRelease(response, async () => cleanup());
113
116
  } catch (error) {
114
117
  cleanup();
115
118
  throw error;
@@ -351,8 +354,7 @@ async function deleteMattermostPost(client, postId) {
351
354
  async function uploadMattermostFile(client, params) {
352
355
  const form = new FormData();
353
356
  const fileName = normalizeOptionalString(params.fileName) ?? "upload";
354
- const bytes = Uint8Array.from(params.buffer);
355
- const blob = params.contentType ? new Blob([bytes], { type: params.contentType }) : new Blob([bytes]);
357
+ const blob = new Blob([bufferToBlobPart(params.buffer)], { type: params.contentType });
356
358
  form.append("files", blob, fileName);
357
359
  form.append("channel_id", params.channelId);
358
360
  const res = await client.fetchImpl(`${client.apiBaseUrl}/files`, {
@@ -0,0 +1,27 @@
1
+ import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
2
+ import { parseAccessGroupAllowFromEntry } from "openclaw/plugin-sdk/access-groups";
3
+ const mattermostIngressIdentity = {
4
+ key: "sender-id",
5
+ authentication: "verified",
6
+ normalize: normalizeMattermostAllowEntry,
7
+ aliases: [{
8
+ key: "sender-name",
9
+ kind: "plugin:mattermost-user-name",
10
+ normalizeEntry: normalizeMattermostAllowEntry,
11
+ normalizeSubject: normalizeMattermostAllowEntry,
12
+ authentication: "mutable"
13
+ }],
14
+ isWildcardEntry: (entry) => normalizeMattermostAllowEntry(entry) === "*",
15
+ resolveEntryId: ({ entryIndex, fieldKey }) => `mattermost-entry-${entryIndex + 1}:${fieldKey === "sender-name" ? "name" : "user"}`
16
+ };
17
+ function normalizeMattermostAllowEntry(entry) {
18
+ const trimmed = entry.trim();
19
+ if (!trimmed) return "";
20
+ if (trimmed === "*") return "*";
21
+ const accessGroupName = parseAccessGroupAllowFromEntry(trimmed);
22
+ if (accessGroupName) return `accessGroup:${accessGroupName}`;
23
+ const normalized = trimmed.replace(/^(mattermost|user):/i, "").replace(/^@/, "").trim();
24
+ return normalized ? normalizeLowercaseStringOrEmpty(normalized) : "";
25
+ }
26
+ //#endregion
27
+ export { normalizeMattermostAllowEntry as n, mattermostIngressIdentity as t };
@@ -1,12 +1,20 @@
1
1
  import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { v as updateMattermostPost } from "./client-DAIry9-2.js";
3
- import { C as resolveClientIp, m as isTrustedProxyAddress, y as readRequestBodyWithLimit } from "./monitor-auth-CVd_4FPD.js";
2
+ import { v as updateMattermostPost } from "./client-Dt7Q-j5B.js";
3
+ import { S as resolveClientIp, f as isRequestBodyLimitError, p as isTrustedProxyAddress, v as readRequestBodyWithLimit, w as sendHttpRequestRejection } from "./monitor-auth-C6RGYyn-.js";
4
4
  import { createHmac } from "node:crypto";
5
- import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
5
+ import { resolveGatewayPort } from "openclaw/plugin-sdk/gateway-config-runtime";
6
6
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
7
7
  import { normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
8
+ //#region extensions/mattermost/src/mattermost/callback-host.ts
9
+ function isWildcardBindHost(rawHost) {
10
+ const trimmed = rawHost.trim();
11
+ if (!trimmed) return false;
12
+ const host = trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
13
+ return host === "0.0.0.0" || host === "::" || host === "0:0:0:0:0:0:0:0" || host === "::0";
14
+ }
15
+ //#endregion
8
16
  //#region extensions/mattermost/src/mattermost/interactions.ts
9
- const INTERACTION_MAX_BODY_BYTES = 64 * 1024;
17
+ const INTERACTION_MAX_BODY_BYTES = 65536;
10
18
  const INTERACTION_BODY_TIMEOUT_MS = 1e4;
11
19
  const SIGNED_CHANNEL_ID_CONTEXT_KEY = "__openclaw_channel_id";
12
20
  const callbackUrls = /* @__PURE__ */ new Map();
@@ -16,12 +24,6 @@ function setInteractionCallbackUrl(accountId, url) {
16
24
  function resolveInteractionCallbackPath(accountId) {
17
25
  return `/mattermost/interactions/${accountId}`;
18
26
  }
19
- function isWildcardBindHost(rawHost) {
20
- const trimmed = rawHost.trim();
21
- if (!trimmed) return false;
22
- const host = trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
23
- return host === "0.0.0.0" || host === "::" || host === "0:0:0:0:0:0:0:0" || host === "::0";
24
- }
25
27
  function normalizeCallbackBaseUrl(baseUrl) {
26
28
  return baseUrl.trim().replace(/\/+$/, "");
27
29
  }
@@ -32,13 +34,14 @@ function headerValue(value) {
32
34
  function isAllowedInteractionSource(params) {
33
35
  const { allowedSourceIps } = params;
34
36
  if (!allowedSourceIps?.length) return true;
35
- return isTrustedProxyAddress(resolveClientIp({
37
+ const clientIp = resolveClientIp({
36
38
  remoteAddr: params.req.socket?.remoteAddress,
37
39
  forwardedFor: headerValue(params.req.headers["x-forwarded-for"]),
38
40
  realIp: headerValue(params.req.headers["x-real-ip"]),
39
41
  trustedProxies: params.trustedProxies,
40
42
  allowRealIpFallback: params.allowRealIpFallback
41
- }), allowedSourceIps);
43
+ });
44
+ return isTrustedProxyAddress(clientIp, allowedSourceIps);
42
45
  }
43
46
  /**
44
47
  * Resolve the interaction callback URL for an account.
@@ -99,7 +102,8 @@ function generateInteractionToken(context, accountId) {
99
102
  return createHmac("sha256", secret).update(payload).digest("hex");
100
103
  }
101
104
  function verifyInteractionToken(context, token, accountId) {
102
- return safeEqualSecret(generateInteractionToken(context, accountId), token);
105
+ const expected = generateInteractionToken(context, accountId);
106
+ return safeEqualSecret(expected, token);
103
107
  }
104
108
  /**
105
109
  * Build Mattermost `props.attachments` with interactive buttons.
@@ -165,7 +169,8 @@ function buildButtonProps(params) {
165
169
  function readInteractionBody(req) {
166
170
  return readRequestBodyWithLimit(req, {
167
171
  maxBytes: INTERACTION_MAX_BODY_BYTES,
168
- timeoutMs: INTERACTION_BODY_TIMEOUT_MS
172
+ timeoutMs: INTERACTION_BODY_TIMEOUT_MS,
173
+ destroyOnLimit: false
169
174
  });
170
175
  }
171
176
  function createMattermostInteractionHandler(params) {
@@ -203,6 +208,14 @@ function createMattermostInteractionHandler(params) {
203
208
  payload = parseInteractionPayload(await readInteractionBody(req));
204
209
  } catch (err) {
205
210
  log?.(`mattermost interaction: failed to parse body: ${String(err)}`);
211
+ if (isRequestBodyLimitError(err, "PAYLOAD_TOO_LARGE")) {
212
+ await sendHttpRequestRejection(req, res, 413, JSON.stringify({ error: "Payload too large" }), "application/json");
213
+ return;
214
+ }
215
+ if (isRequestBodyLimitError(err, "REQUEST_BODY_TIMEOUT")) {
216
+ await sendHttpRequestRejection(req, res, 408, JSON.stringify({ error: "Request body timeout" }), "application/json");
217
+ return;
218
+ }
206
219
  res.statusCode = 400;
207
220
  res.setHeader("Content-Type", "application/json");
208
221
  res.end(JSON.stringify({ error: "Invalid request body" }));
@@ -373,4 +386,4 @@ function createMattermostInteractionHandler(params) {
373
386
  };
374
387
  }
375
388
  //#endregion
376
- export { resolveInteractionCallbackPath as a, setInteractionSecret as c, createMattermostInteractionHandler as i, buildButtonProps as n, resolveInteractionCallbackUrl as o, computeInteractionCallbackUrl as r, setInteractionCallbackUrl as s, buildButtonAttachments as t };
389
+ export { resolveInteractionCallbackPath as a, setInteractionSecret as c, createMattermostInteractionHandler as i, isWildcardBindHost as l, buildButtonProps as n, resolveInteractionCallbackUrl as o, computeInteractionCallbackUrl as r, setInteractionCallbackUrl as s, buildButtonAttachments as t };
@@ -1,46 +1,26 @@
1
- import { isTrustedProxyAddress, resolveClientIp } from "openclaw/plugin-sdk/core";
2
- import { normalizeLowercaseStringOrEmpty, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
1
+ import { n as normalizeMattermostAllowEntry, t as mattermostIngressIdentity } from "./ingress-identity-DNl4yQSc.js";
2
+ import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { logInboundDrop } from "openclaw/plugin-sdk/channel-inbound";
4
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";
8
8
  import { listSkillCommandsForAgents } from "openclaw/plugin-sdk/command-auth-native";
9
- import { buildModelsProviderData } from "openclaw/plugin-sdk/models-provider-runtime";
9
+ import { buildPreparedModelsProviderData } from "openclaw/plugin-sdk/models-provider-runtime";
10
10
  import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
11
11
  import { resolveAllowlistProviderRuntimeGroupPolicy as resolveAllowlistProviderRuntimeGroupPolicy$1, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
12
- import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/media-runtime";
12
+ import { resolveChannelMediaMaxBytes as resolveChannelMediaMaxBytes$1 } from "openclaw/plugin-sdk/account-helpers";
13
13
  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
- import { isRequestBodyLimitError, readRequestBodyWithLimit } from "openclaw/plugin-sdk/webhook-ingress";
17
- import { parseAccessGroupAllowFromEntry } from "openclaw/plugin-sdk/access-groups";
16
+ import { isRequestBodyLimitError } from "openclaw/plugin-sdk/webhook-ingress";
17
+ import { readRequestBodyWithLimit, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
18
+ import { isTrustedProxyAddress, resolveClientIp } from "openclaw/plugin-sdk/core";
18
19
  import { resolveStableChannelMessageIngress } from "openclaw/plugin-sdk/channel-ingress-runtime";
19
20
  //#region extensions/mattermost/src/mattermost/monitor-auth.ts
20
- const mattermostIngressIdentity = {
21
- key: "sender-id",
22
- normalize: normalizeMattermostAllowEntry,
23
- aliases: [{
24
- key: "sender-name",
25
- kind: "plugin:mattermost-user-name",
26
- normalizeEntry: normalizeMattermostAllowEntry,
27
- normalizeSubject: normalizeMattermostAllowEntry,
28
- dangerous: true
29
- }],
30
- isWildcardEntry: (entry) => normalizeMattermostAllowEntry(entry) === "*",
31
- resolveEntryId: ({ entryIndex, fieldKey }) => `mattermost-entry-${entryIndex + 1}:${fieldKey === "sender-name" ? "name" : "user"}`
32
- };
33
- function normalizeMattermostAllowEntry(entry) {
34
- const trimmed = entry.trim();
35
- if (!trimmed) return "";
36
- if (trimmed === "*") return "*";
37
- const accessGroupName = parseAccessGroupAllowFromEntry(trimmed);
38
- if (accessGroupName) return `accessGroup:${accessGroupName}`;
39
- const normalized = trimmed.replace(/^(mattermost|user):/i, "").replace(/^@/, "").trim();
40
- return normalized ? normalizeLowercaseStringOrEmpty(normalized) : "";
41
- }
42
21
  function normalizeMattermostAllowList(entries) {
43
- return uniqueStrings(entries.map((entry) => normalizeMattermostAllowEntry(String(entry))).filter(Boolean));
22
+ const normalized = entries.map((entry) => normalizeMattermostAllowEntry(String(entry))).filter(Boolean);
23
+ return uniqueStrings(normalized);
44
24
  }
45
25
  function formatMattermostDirectMessageDropLog(params) {
46
26
  const reason = params.reasonCode ? ` reason=${params.reasonCode}` : "";
@@ -48,8 +28,9 @@ function formatMattermostDirectMessageDropLog(params) {
48
28
  return `mattermost: drop dm sender=${params.senderId} (dmPolicy=${params.dmPolicy}${reason}${hint})`;
49
29
  }
50
30
  function isMattermostSenderAllowed(params) {
31
+ const allowFrom = normalizeMattermostAllowList(params.allowFrom);
51
32
  return resolveAllowlistMatchSimple({
52
- allowFrom: normalizeMattermostAllowList(params.allowFrom),
33
+ allowFrom,
53
34
  senderId: normalizeMattermostAllowEntry(params.senderId),
54
35
  senderName: params.senderName ? normalizeMattermostAllowEntry(params.senderName) : void 0,
55
36
  allowNameMatching: params.allowNameMatching
@@ -181,4 +162,4 @@ async function authorizeMattermostCommandInvocation(params) {
181
162
  };
182
163
  }
183
164
  //#endregion
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 };
165
+ export { resolveDefaultGroupPolicy as C, resolveClientIp as S, warnMissingProviderGroupPolicyFallbackOnce as T, logTypingFailure as _, resolveMattermostMonitorInboundAccess as a, resolveAllowlistProviderRuntimeGroupPolicy$1 as b, buildPreparedModelsProviderData as c, createChannelPairingController as d, isRequestBodyLimitError as f, logInboundDrop as g, loadOutboundMediaFromUrl as h, normalizeMattermostAllowList as i, createChannelHistoryWindow as l, listSkillCommandsForAgents as m, formatMattermostDirectMessageDropLog as n, resolveMattermostTrustedChatKind as o, isTrustedProxyAddress as p, isMattermostSenderAllowed as r, DEFAULT_GROUP_HISTORY_LIMIT as s, authorizeMattermostCommandInvocation as t, createChannelMessageReplyPipeline as u, readRequestBodyWithLimit as v, sendHttpRequestRejection as w, resolveChannelMediaMaxBytes$1 as x, registerPluginHttpRoute as y };
@@ -1,8 +1,8 @@
1
- import { m as normalizeMattermostBaseUrl } from "./client-DAIry9-2.js";
1
+ import { m as normalizeMattermostBaseUrl } from "./client-Dt7Q-j5B.js";
2
2
  import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { resolveChannelPreviewStreamMode, resolveChannelStreamingBlockCoalesce, resolveChannelStreamingBlockEnabled, resolveChannelStreamingChunkMode } from "openclaw/plugin-sdk/channel-outbound";
4
- import { normalizeMessagePresentation, renderMessagePresentationFallbackText, resolveMessagePresentationControlValue } from "openclaw/plugin-sdk/interactive-runtime";
5
4
  import { createAccountListHelpers, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
5
+ import { normalizeMessagePresentation, renderMessagePresentationFallbackText, resolveMessagePresentationControlValue } from "openclaw/plugin-sdk/interactive-runtime";
6
6
  import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
7
7
  import { buildSecretInputSchema, hasConfiguredSecretInput, resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
8
8
  //#region extensions/mattermost/src/mattermost/accounts.ts
@@ -68,10 +68,18 @@ function resolveMattermostAccount(params) {
68
68
  });
69
69
  }
70
70
  function inspectMattermostAccount(params) {
71
- return resolveMattermostAccountWithMode({
71
+ const account = resolveMattermostAccountWithMode({
72
72
  ...params,
73
73
  mode: "inspect"
74
74
  });
75
+ return {
76
+ ...account,
77
+ configured: isMattermostConfigured(account),
78
+ dmPolicy: account.config.dmPolicy ?? "pairing"
79
+ };
80
+ }
81
+ function isMattermostConfigured(account) {
82
+ return (account.botTokenStatus ? account.botTokenStatus !== "missing" : Boolean(account.botToken)) && Boolean(account.baseUrl);
75
83
  }
76
84
  /**
77
85
  * Resolve the effective replyToMode for a given chat type.
@@ -148,4 +156,4 @@ function looksLikeMattermostTargetId(raw, _normalized) {
148
156
  return /^[a-z0-9]{26}$/i.test(trimmed) || /^[a-z0-9]{26}__[a-z0-9]{26}$/i.test(trimmed);
149
157
  }
150
158
  //#endregion
151
- export { inspectMattermostAccount as a, resolveMattermostAccount as c, hasConfiguredSecretInput as d, resolveMattermostPresentation as i, resolveMattermostReplyToMode as l, normalizeMattermostMessagingTarget as n, listMattermostAccountIds as o, requiresMattermostMediaUpload as r, resolveDefaultMattermostAccountId as s, looksLikeMattermostTargetId as t, buildSecretInputSchema as u };
159
+ export { inspectMattermostAccount as a, resolveDefaultMattermostAccountId as c, buildSecretInputSchema as d, hasConfiguredSecretInput as f, resolveMattermostPresentation as i, resolveMattermostAccount as l, normalizeMattermostMessagingTarget as n, isMattermostConfigured as o, requiresMattermostMediaUpload as r, listMattermostAccountIds as s, looksLikeMattermostTargetId as t, resolveMattermostReplyToMode as u };
@@ -1,2 +1,2 @@
1
- import { r as isMattermostSenderAllowed } from "./monitor-auth-CVd_4FPD.js";
1
+ import { r as isMattermostSenderAllowed } from "./monitor-auth-C6RGYyn-.js";
2
2
  export { isMattermostSenderAllowed };
@@ -1,23 +1,24 @@
1
1
  import { r as setMattermostRuntime } from "./runtime-CNB4YGqJ.js";
2
- import { DEFAULT_ACCOUNT_ID, buildChannelConfigSchema, createDedupeCache, isTrustedProxyAddress, parseStrictPositiveInteger, resolveClientIp } from "openclaw/plugin-sdk/core";
3
2
  import { formatInboundFromLabel, logInboundDrop } from "openclaw/plugin-sdk/channel-inbound";
4
3
  import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
5
4
  import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
6
5
  import { createAccountStatusSink, createChannelMessageReplyPipeline } from "openclaw/plugin-sdk/channel-outbound";
7
6
  import { logTypingFailure } from "openclaw/plugin-sdk/channel-feedback";
8
7
  import { listSkillCommandsForAgents, resolveControlCommandGate, resolveStoredModelOverride } from "openclaw/plugin-sdk/command-auth-native";
9
- import { buildModelsProviderData } from "openclaw/plugin-sdk/models-provider-runtime";
8
+ import { buildPreparedModelsProviderData } from "openclaw/plugin-sdk/models-provider-runtime";
10
9
  import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
11
10
  import { GROUP_POLICY_BLOCKED_LABEL, resolveAllowlistProviderRuntimeGroupPolicy, resolveDefaultGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
12
- import { getAgentScopedMediaLocalRoots, resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/media-runtime";
11
+ import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
13
12
  import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media";
14
13
  import { DEFAULT_GROUP_HISTORY_LIMIT, buildPendingHistoryContextFromMap, clearHistoryEntriesIfEnabled, createChannelHistoryWindow, recordPendingHistoryEntryIfEnabled } from "openclaw/plugin-sdk/reply-history";
15
14
  import { registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-targets";
16
15
  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";
20
20
  import { resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
21
21
  import { normalizeAccountId, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
22
+ import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
22
23
  import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
23
- export { DEFAULT_ACCOUNT_ID, DEFAULT_GROUP_HISTORY_LIMIT, GROUP_POLICY_BLOCKED_LABEL, applyAccountNameToChannelSection, applySetupAccountConfigPatch, buildChannelConfigSchema, buildComputedAccountStatusSnapshot, buildModelsProviderData, buildPendingHistoryContextFromMap, chunkTextForOutbound, clearHistoryEntriesIfEnabled, createAccountStatusSink, createChannelHistoryWindow, createChannelMessageReplyPipeline, createChannelPairingController, createDedupeCache, formatInboundFromLabel, getAgentScopedMediaLocalRoots, isDangerousNameMatchingEnabled, isRequestBodyLimitError, isTrustedProxyAddress, listSkillCommandsForAgents, loadOutboundMediaFromUrl, logInboundDrop, logTypingFailure, migrateBaseNameToDefaultAccount, normalizeAccountId, normalizeProviderId, parseStrictPositiveInteger, rawDataToString, readRequestBodyWithLimit, recordPendingHistoryEntryIfEnabled, registerPluginHttpRoute, resolveAllowlistMatchSimple, resolveAllowlistProviderRuntimeGroupPolicy, resolveChannelMediaMaxBytes, resolveClientIp, resolveControlCommandGate, resolveDefaultGroupPolicy, resolveStorePath, resolveStoredModelOverride, resolveThreadSessionKeys, setMattermostRuntime, warnMissingProviderGroupPolicyFallbackOnce };
24
+ export { DEFAULT_ACCOUNT_ID, DEFAULT_GROUP_HISTORY_LIMIT, GROUP_POLICY_BLOCKED_LABEL, applyAccountNameToChannelSection, applySetupAccountConfigPatch, buildChannelConfigSchema, buildComputedAccountStatusSnapshot, buildPendingHistoryContextFromMap, buildPreparedModelsProviderData, chunkTextForOutbound, clearHistoryEntriesIfEnabled, createAccountStatusSink, createChannelHistoryWindow, createChannelMessageReplyPipeline, createChannelPairingController, createDedupeCache, formatInboundFromLabel, getAgentScopedMediaLocalRoots, isDangerousNameMatchingEnabled, isRequestBodyLimitError, isTrustedProxyAddress, listSkillCommandsForAgents, loadOutboundMediaFromUrl, logInboundDrop, logTypingFailure, migrateBaseNameToDefaultAccount, normalizeAccountId, normalizeProviderId, parseStrictPositiveInteger, rawDataToString, readRequestBodyWithLimit, recordPendingHistoryEntryIfEnabled, registerPluginHttpRoute, resolveAllowlistMatchSimple, resolveAllowlistProviderRuntimeGroupPolicy, resolveChannelMediaMaxBytes, resolveClientIp, resolveControlCommandGate, resolveDefaultGroupPolicy, resolveStorePath, resolveStoredModelOverride, resolveThreadSessionKeys, setMattermostRuntime, warnMissingProviderGroupPolicyFallbackOnce };
@@ -1,2 +1,2 @@
1
- import { i as registerSlashCommandRoute } from "./slash-state-CfsJU7WW.js";
1
+ import { i as registerSlashCommandRoute } from "./slash-state-njvQCdwt.js";
2
2
  export { registerSlashCommandRoute };
@@ -1,8 +1,8 @@
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, h as parseMattermostApiStatus, i as createMattermostDirectChannelWithRetry, m as normalizeMattermostBaseUrl, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe, y as uploadMattermostFile } from "./client-DAIry9-2.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-k47k-7SP.js";
5
- import { c as resolveMattermostAccount, i as resolveMattermostPresentation, r as requiresMattermostMediaUpload } from "./normalize-bBDFEiyJ.js";
2
+ import { c as setInteractionSecret, l as isWildcardBindHost, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-DF1FH27_.js";
3
+ import { _ as sendMattermostTyping, a as createMattermostPost, 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, y as uploadMattermostFile } from "./client-Dt7Q-j5B.js";
4
+ import { _ as logTypingFailure, c as buildPreparedModelsProviderData, f as isRequestBodyLimitError, h as loadOutboundMediaFromUrl, i as normalizeMattermostAllowList, o as resolveMattermostTrustedChatKind, t as authorizeMattermostCommandInvocation, v as readRequestBodyWithLimit, w as sendHttpRequestRejection } from "./monitor-auth-C6RGYyn-.js";
5
+ import { i as resolveMattermostPresentation, l as resolveMattermostAccount, r as requiresMattermostMediaUpload } from "./normalize-R-ATEEHC.js";
6
6
  import { createHash } from "node:crypto";
7
7
  import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
8
8
  import { asFiniteNumber, normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringifiedOptionalString, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
@@ -11,12 +11,12 @@ import { asDateTimestampMs, parseStrictInteger, resolveExpiresAtMsFromDurationMs
11
11
  import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
12
12
  import { createMessageReceiptFromOutboundResults, listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbound";
13
13
  import { resolveStoredModelOverride } from "openclaw/plugin-sdk/command-auth-native";
14
- import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
14
+ import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
15
15
  import { deliverTextOrMediaReply, isReasoningReplyPayload, resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
16
16
  import { FormatCapabilityProfile, convertMarkdownTables } from "openclaw/plugin-sdk/text-chunking";
17
17
  import { getSessionEntry, resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
18
+ import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
18
19
  import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
19
- import { Readable } from "node:stream";
20
20
  import { truncateUtf16Safe, truncateUtf8Prefix } from "openclaw/plugin-sdk/text-utility-runtime";
21
21
  import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
22
22
  import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
@@ -341,12 +341,6 @@ function isSlashCommandsEnabled(config) {
341
341
  */
342
342
  function resolveCallbackUrl(params) {
343
343
  if (params.config.callbackUrl) return params.config.callbackUrl;
344
- const isWildcardBindHost = (rawHost) => {
345
- const trimmed = rawHost.trim();
346
- if (!trimmed) return false;
347
- const host = trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
348
- return host === "0.0.0.0" || host === "::" || host === "0:0:0:0:0:0:0:0" || host === "::0";
349
- };
350
344
  let host = params.gatewayHost && !isWildcardBindHost(params.gatewayHost) ? params.gatewayHost : "localhost";
351
345
  const path = normalizeCallbackPath(params.config.callbackPath);
352
346
  if (host.includes(":") && !(host.startsWith("[") && host.endsWith("]"))) host = `[${host}]`;
@@ -689,7 +683,7 @@ async function deliverMattermostReplyPayload(params) {
689
683
  //#endregion
690
684
  //#region extensions/mattermost/src/mattermost/target-resolution.ts
691
685
  const MATTERMOST_OPAQUE_TARGET_CACHE_MAX_ENTRIES = 1024;
692
- const MATTERMOST_OPAQUE_TARGET_CACHE_TTL_MS = 300 * 1e3;
686
+ const MATTERMOST_OPAQUE_TARGET_CACHE_TTL_MS = 3e5;
693
687
  const mattermostOpaqueTargetCache = /* @__PURE__ */ new Map();
694
688
  function cacheMattermostOpaqueTarget(key, kind) {
695
689
  mattermostOpaqueTargetCache.set(key, {
@@ -823,7 +817,8 @@ async function resolveMattermostOpaqueTarget(params) {
823
817
  };
824
818
  }
825
819
  try {
826
- const channelKind = resolveMattermostTrustedChatKind({ channelType: (await fetchMattermostChannel(client, input)).type }) === "group" ? "group" : "channel";
820
+ const channel = await fetchMattermostChannel(client, input);
821
+ const channelKind = resolveMattermostTrustedChatKind({ channelType: channel.type }) === "group" ? "group" : "channel";
827
822
  cacheMattermostOpaqueTarget(key, channelKind);
828
823
  return {
829
824
  kind: channelKind,
@@ -902,11 +897,12 @@ async function resolveBotUser(baseUrl, token, allowPrivateNetwork) {
902
897
  const key = cacheKey(baseUrl, token);
903
898
  const cached = botUserCache.get(key);
904
899
  if (cached) return cached;
905
- const user = await fetchMattermostMe(createMattermostClient({
900
+ const client = createMattermostClient({
906
901
  baseUrl,
907
902
  botToken: token,
908
903
  allowPrivateNetwork
909
- }));
904
+ });
905
+ const user = await fetchMattermostMe(client);
910
906
  cacheOutboundEntry(botUserCache, key, user, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
911
907
  return user;
912
908
  }
@@ -915,11 +911,12 @@ async function resolveUserIdByUsername(params) {
915
911
  const key = `${cacheKey(baseUrl, token)}::${normalizeLowercaseStringOrEmpty(username)}`;
916
912
  const cached = userByNameCache.get(key);
917
913
  if (cached?.id) return cached.id;
918
- const user = await fetchMattermostUserByUsername(createMattermostClient({
914
+ const client = createMattermostClient({
919
915
  baseUrl,
920
916
  botToken: token,
921
917
  allowPrivateNetwork: params.allowPrivateNetwork
922
- }), username);
918
+ });
919
+ const user = await fetchMattermostUserByUsername(client, username);
923
920
  cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
924
921
  return user.id;
925
922
  }
@@ -933,7 +930,8 @@ async function resolveChannelIdByName(params) {
933
930
  botToken: token,
934
931
  allowPrivateNetwork: params.allowPrivateNetwork
935
932
  });
936
- const teams = await fetchMattermostUserTeams(client, (await fetchMattermostMe(client)).id);
933
+ const me = await fetchMattermostMe(client);
934
+ const teams = await fetchMattermostUserTeams(client, me.id);
937
935
  for (const team of teams) try {
938
936
  const channel = await fetchMattermostChannelByName(client, team.id, name);
939
937
  if (channel?.id) {
@@ -974,11 +972,12 @@ async function resolveTargetChannelId(params) {
974
972
  const cachedDm = dmChannelCache.get(dmKey);
975
973
  if (cachedDm) return cachedDm;
976
974
  const botUser = await resolveBotUser(params.baseUrl, params.token, params.allowPrivateNetwork);
977
- const channel = await createMattermostDirectChannelWithRetry(createMattermostClient({
975
+ const client = createMattermostClient({
978
976
  baseUrl: params.baseUrl,
979
977
  botToken: params.token,
980
978
  allowPrivateNetwork: params.allowPrivateNetwork
981
- }), [botUser.id, userId], {
979
+ });
980
+ const channel = await createMattermostDirectChannelWithRetry(client, [botUser.id, userId], {
982
981
  ...params.dmRetryOptions,
983
982
  onRetry: (attempt, delayMs, error) => {
984
983
  params.dmRetryOptions?.onRetry?.(attempt, delayMs, error);
@@ -1035,13 +1034,18 @@ async function resolveMattermostSendContext(to, opts) {
1035
1034
  token,
1036
1035
  baseUrl,
1037
1036
  channelId,
1038
- allowPrivateNetwork
1037
+ allowPrivateNetwork,
1038
+ mediaMaxBytes: resolveChannelMediaMaxBytes({
1039
+ cfg,
1040
+ accountId: account.accountId,
1041
+ resolveChannelLimitMb: () => account.config.mediaMaxMb
1042
+ })
1039
1043
  };
1040
1044
  }
1041
1045
  async function sendMessageMattermost(to, text, opts) {
1042
1046
  const core = getCore();
1043
1047
  const logger = core.logging.getChildLogger({ module: "mattermost" });
1044
- const { cfg, accountId, token, baseUrl, channelId, allowPrivateNetwork } = await resolveMattermostSendContext(to, opts);
1048
+ const { cfg, accountId, token, baseUrl, channelId, allowPrivateNetwork, mediaMaxBytes } = await resolveMattermostSendContext(to, opts);
1045
1049
  const client = createMattermostClient({
1046
1050
  baseUrl,
1047
1051
  botToken: token,
@@ -1070,6 +1074,7 @@ async function sendMessageMattermost(to, text, opts) {
1070
1074
  const mediaUrl = opts.mediaUrl?.trim();
1071
1075
  if (mediaUrl) try {
1072
1076
  const media = await loadOutboundMediaFromUrl(mediaUrl, {
1077
+ maxBytes: mediaMaxBytes,
1073
1078
  mediaLocalRoots: opts.mediaLocalRoots,
1074
1079
  mediaReadFile: opts.mediaReadFile,
1075
1080
  workspaceDir: opts.workspaceDir
@@ -1082,7 +1087,7 @@ async function sendMessageMattermost(to, text, opts) {
1082
1087
  })).id];
1083
1088
  } catch (err) {
1084
1089
  uploadError = err instanceof Error ? err : new Error(String(err));
1085
- if (opts.requireMediaUpload) throw new Error(`Mattermost media upload failed: ${uploadError.message}`, { cause: err });
1090
+ if (opts.requireMediaUpload || mediaMaxBytes !== void 0) throw new Error(`Mattermost media upload failed: ${uploadError.message}`, { cause: err });
1086
1091
  if (core.logging.shouldLogVerbose()) logger.debug?.(`mattermost send: media upload failed, falling back to URL text: ${String(err)}`);
1087
1092
  message = normalizeMessage(message, isHttpUrl(mediaUrl) ? mediaUrl : "");
1088
1093
  }
@@ -1137,7 +1142,7 @@ async function sendMessageMattermost(to, text, opts) {
1137
1142
  }
1138
1143
  //#endregion
1139
1144
  //#region extensions/mattermost/src/mattermost/slash-http.ts
1140
- const MAX_BODY_BYTES = 64 * 1024;
1145
+ const MAX_BODY_BYTES = 65536;
1141
1146
  const BODY_READ_TIMEOUT_MS = 5e3;
1142
1147
  const COMMAND_LOOKUP_TIMEOUT_MS = 1e3;
1143
1148
  const COMMAND_VALIDATION_FAILURE_CACHE_MS = 5e3;
@@ -1163,7 +1168,8 @@ const SECRET_LOG_KEYS = /* @__PURE__ */ new Set([
1163
1168
  function readBody(req, maxBytes, timeoutMs = BODY_READ_TIMEOUT_MS) {
1164
1169
  return readRequestBodyWithLimit(req, {
1165
1170
  maxBytes,
1166
- timeoutMs
1171
+ timeoutMs,
1172
+ destroyOnLimit: false
1167
1173
  });
1168
1174
  }
1169
1175
  function sendJsonResponse(res, status, body) {
@@ -1179,7 +1185,7 @@ function isDeletedMattermostCommand(command) {
1179
1185
  return typeof command.delete_at === "number" && command.delete_at > 0;
1180
1186
  }
1181
1187
  function sanitizeCommandLookupError(error) {
1182
- return truncateUtf16Safe((error instanceof Error ? error.message : String(error)).replace(/[\r\n\t]/gu, " ").replace(/https?:\/\/[^\s)\]}]+/giu, (urlText) => {
1188
+ const sanitized = (error instanceof Error ? error.message : String(error)).replace(/[\r\n\t]/gu, " ").replace(/https?:\/\/[^\s)\]}]+/giu, (urlText) => {
1183
1189
  try {
1184
1190
  const url = new URL(urlText);
1185
1191
  if (url.username || url.password) {
@@ -1191,7 +1197,8 @@ function sanitizeCommandLookupError(error) {
1191
1197
  } catch {
1192
1198
  return urlText;
1193
1199
  }
1194
- }).replace(/(^|[^\w-])(Bearer|Token)\s+[A-Za-z0-9._~+/=-]+/giu, "$1$2 [redacted]").replace(/\b(token|authorization|access_token|refresh_token|client_secret|botToken)\b(\s*["']?\s*(?:=|:)\s*["']?)[^"',\s;}]+/giu, "$1$2[redacted]"), 300);
1200
+ }).replace(/(^|[^\w-])(Bearer|Token)\s+[A-Za-z0-9._~+/=-]+/giu, "$1$2 [redacted]").replace(/\b(token|authorization|access_token|refresh_token|client_secret|botToken)\b(\s*["']?\s*(?:=|:)\s*["']?)[^"',\s;}]+/giu, "$1$2[redacted]");
1201
+ return truncateUtf16Safe(sanitized, 300);
1195
1202
  }
1196
1203
  function sanitizeMattermostLogValue(value) {
1197
1204
  return truncateUtf16Safe(value.replace(/[\r\n\t]/gu, " "), 200);
@@ -1271,7 +1278,8 @@ function sweepCommandValidationLookupRateLimit(now = Date.now()) {
1271
1278
  }
1272
1279
  }
1273
1280
  function reserveCommandValidationLookup(params) {
1274
- const now = asDateTimestampMs(params.now ?? Date.now());
1281
+ const rawNow = params.now ?? Date.now();
1282
+ const now = asDateTimestampMs(rawNow);
1275
1283
  if (now === void 0) {
1276
1284
  commandValidationLookupRateLimit.clear();
1277
1285
  return { allowed: true };
@@ -1281,7 +1289,7 @@ function reserveCommandValidationLookup(params) {
1281
1289
  if (!existing) {
1282
1290
  commandValidationLookupRateLimit.set(params.key, {
1283
1291
  accountId: params.accountId,
1284
- tokens: COMMAND_VALIDATION_LOOKUP_BURST - 1,
1292
+ tokens: 19,
1285
1293
  updatedAt: now,
1286
1294
  lastLimitedLogAt: 0
1287
1295
  });
@@ -1457,7 +1465,7 @@ async function authorizeSlashInvocation(params) {
1457
1465
  */
1458
1466
  function createSlashCommandHttpHandler(params) {
1459
1467
  const { account, cfg, runtime, registeredCommands, triggerMap, log, bodyTimeoutMs } = params;
1460
- return async (req, res) => {
1468
+ return async (req, res, bufferedBody) => {
1461
1469
  if (req.method !== "POST") {
1462
1470
  res.statusCode = 405;
1463
1471
  res.setHeader("Allow", "POST");
@@ -1466,15 +1474,13 @@ function createSlashCommandHttpHandler(params) {
1466
1474
  }
1467
1475
  let body;
1468
1476
  try {
1469
- body = await readBody(req, MAX_BODY_BYTES, bodyTimeoutMs);
1477
+ body = bufferedBody ?? await readBody(req, MAX_BODY_BYTES, bodyTimeoutMs);
1470
1478
  } catch (error) {
1471
1479
  if (isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) {
1472
- res.statusCode = 408;
1473
- res.end("Request body timeout");
1480
+ await sendHttpRequestRejection(req, res, 408, "Request body timeout");
1474
1481
  return;
1475
1482
  }
1476
- res.statusCode = 413;
1477
- res.end("Payload Too Large");
1483
+ await sendHttpRequestRejection(req, res, 413, "Payload Too Large");
1478
1484
  return;
1479
1485
  }
1480
1486
  const contentType = req.headers["content-type"] ?? "";
@@ -1590,7 +1596,7 @@ async function handleSlashCommandAsync(params) {
1590
1596
  const to = kind === "direct" ? `user:${senderId}` : `channel:${channelId}`;
1591
1597
  const pickerEntry = resolveMattermostModelPickerEntry(commandText);
1592
1598
  if (pickerEntry) {
1593
- const data = await buildModelsProviderData(cfg, route.agentId);
1599
+ const data = await buildPreparedModelsProviderData(cfg, route.agentId);
1594
1600
  if (data.providers.length === 0) {
1595
1601
  await sendMessageMattermost(`channel:${channelId}`, "No models available.", {
1596
1602
  cfg,
@@ -1708,7 +1714,7 @@ async function handleSlashCommandAsync(params) {
1708
1714
  }
1709
1715
  //#endregion
1710
1716
  //#region extensions/mattermost/src/mattermost/slash-state.ts
1711
- const MULTI_ACCOUNT_BODY_MAX_BYTES = 64 * 1024;
1717
+ const MULTI_ACCOUNT_BODY_MAX_BYTES = 65536;
1712
1718
  const MULTI_ACCOUNT_BODY_TIMEOUT_MS = 5e3;
1713
1719
  /**
1714
1720
  * Map from accountId → per-account slash command state.
@@ -1886,16 +1892,15 @@ function registerSlashCommandRoute(api) {
1886
1892
  try {
1887
1893
  bodyStr = await readRequestBodyWithLimit(req, {
1888
1894
  maxBytes: MULTI_ACCOUNT_BODY_MAX_BYTES,
1889
- timeoutMs: MULTI_ACCOUNT_BODY_TIMEOUT_MS
1895
+ timeoutMs: MULTI_ACCOUNT_BODY_TIMEOUT_MS,
1896
+ destroyOnLimit: false
1890
1897
  });
1891
1898
  } catch (error) {
1892
1899
  if (isRequestBodyLimitError(error, "REQUEST_BODY_TIMEOUT")) {
1893
- res.statusCode = 408;
1894
- res.end("Request body timeout");
1900
+ await sendHttpRequestRejection(req, res, 408, "Request body timeout");
1895
1901
  return;
1896
1902
  }
1897
- res.statusCode = 413;
1898
- res.end("Payload Too Large");
1903
+ await sendHttpRequestRejection(req, res, 413, "Payload Too Large");
1899
1904
  return;
1900
1905
  }
1901
1906
  let token = null;
@@ -1932,15 +1937,7 @@ function registerSlashCommandRoute(api) {
1932
1937
  }));
1933
1938
  return;
1934
1939
  }
1935
- const matchedHandler = match.handler;
1936
- const syntheticReq = new Readable({ read() {
1937
- this.push(Buffer.from(bodyStr, "utf8"));
1938
- this.push(null);
1939
- } });
1940
- syntheticReq.method = req.method;
1941
- syntheticReq.url = req.url;
1942
- syntheticReq.headers = req.headers;
1943
- await matchedHandler(syntheticReq, res);
1940
+ await match.handler(req, res, bodyStr);
1944
1941
  };
1945
1942
  for (const callbackPath of callbackPaths) api.registerHttpRoute({
1946
1943
  path: callbackPath,