@openclaw/mattermost 2026.9.8 → 2026.10.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/callback-host-CBsPjVAZ.mjs +34 -0
- package/dist/.setup/channel-plugin-api-Cg4FPSIP.mjs +3 -0
- package/dist/.setup/{channel-plugin-runtime-B0CAMiHe.mjs → channel-plugin-runtime-BsHE7a2R.mjs} +191 -200
- package/dist/.setup/{channel.runtime-E2B5dNrh.mjs → channel.runtime-B_P0FgP2.mjs} +24 -36
- package/dist/.setup/{client-CVeeTqCO.mjs → client-f2qstbX3.mjs} +8 -13
- package/dist/.setup/{doctor-contract-BI6SB2cd.mjs → doctor-contract-CjgZkyPm.mjs} +7 -10
- package/dist/.setup/gateway-auth-bypass-CfqoieHq.mjs +7 -0
- package/dist/.setup/{interactions-DMSZYnEx.mjs → interactions-CfOLvzca.mjs} +10 -26
- package/dist/.setup/{monitor-BZyzPkkb.mjs → monitor-mV676oDI.mjs} +64 -93
- package/dist/.setup/{normalize-BCjtmxtp.mjs → normalize-DhF6_2lt.mjs} +2 -3
- package/dist/.setup/{send-ClgX-usq.mjs → send-BI4525Fd.mjs} +21 -53
- package/dist/.setup/{slash-state-Dni1XNc1.mjs → slash-state-BtvU3GNd.mjs} +23 -89
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +1 -2
- package/dist/channel-plugin-runtime.js +1 -1
- package/dist/doctor-contract-api.js +1 -1
- package/dist/gateway-auth-api.js +1 -1
- package/dist/runtime-api.js +1 -2
- package/dist/setup-entry.js +1 -1
- package/dist/slash-route-api.js +1 -1
- package/package.json +4 -4
- package/dist/.setup/channel-plugin-api-Bc8Qc1-t.mjs +0 -3
- package/dist/.setup/channel-plugin-api-DXqHarCt.mjs +0 -40
- package/dist/.setup/gateway-auth-bypass-B93t91oq.mjs +0 -36
|
@@ -36,9 +36,7 @@ function parseMattermostApiStatus(error) {
|
|
|
36
36
|
if (!error || typeof error !== "object") return;
|
|
37
37
|
const message = "message" in error && typeof error.message === "string" ? error.message : "";
|
|
38
38
|
const match = /Mattermost API (\d{3})\b/.exec(message);
|
|
39
|
-
|
|
40
|
-
const status = Number(match[1]);
|
|
41
|
-
return Number.isFinite(status) ? status : void 0;
|
|
39
|
+
return match ? Number(match[1]) : void 0;
|
|
42
40
|
}
|
|
43
41
|
function normalizeMattermostBaseUrl(raw) {
|
|
44
42
|
const trimmed = raw?.trim();
|
|
@@ -230,14 +228,6 @@ async function sendMattermostTyping(client, params) {
|
|
|
230
228
|
discardResponse: true
|
|
231
229
|
});
|
|
232
230
|
}
|
|
233
|
-
async function createMattermostDirectChannel(client, userIds, signal, timeoutMs) {
|
|
234
|
-
return await client.request("/channels/direct", {
|
|
235
|
-
method: "POST",
|
|
236
|
-
body: JSON.stringify(userIds),
|
|
237
|
-
signal,
|
|
238
|
-
timeoutMs
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
231
|
const RETRYABLE_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
242
232
|
"ECONNRESET",
|
|
243
233
|
"ECONNREFUSED",
|
|
@@ -288,7 +278,12 @@ async function createMattermostDirectChannelWithRetry(client, userIds, options =
|
|
|
288
278
|
const controller = new AbortController();
|
|
289
279
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
290
280
|
try {
|
|
291
|
-
return await
|
|
281
|
+
return await client.request("/channels/direct", {
|
|
282
|
+
method: "POST",
|
|
283
|
+
body: JSON.stringify(userIds),
|
|
284
|
+
signal: controller.signal,
|
|
285
|
+
timeoutMs
|
|
286
|
+
});
|
|
292
287
|
} catch (err) {
|
|
293
288
|
throw err instanceof Error ? err : new Error(String(err));
|
|
294
289
|
} finally {
|
|
@@ -310,7 +305,7 @@ function isRetryableError(error) {
|
|
|
310
305
|
current.reason,
|
|
311
306
|
...Array.isArray(current.errors) ? current.errors : []
|
|
312
307
|
]);
|
|
313
|
-
const messages = candidates.map((candidate) => normalizeLowercaseStringOrEmpty(readStringField(asOptionalObjectRecord(candidate), "message")))
|
|
308
|
+
const messages = candidates.map((candidate) => normalizeLowercaseStringOrEmpty(readStringField(asOptionalObjectRecord(candidate), "message")));
|
|
314
309
|
if (messages.some((message) => /mattermost api 5\d{2}\b/.test(message))) return true;
|
|
315
310
|
if (messages.some((message) => /mattermost api 429\b/.test(message) || message.includes("too many requests"))) return true;
|
|
316
311
|
if (messages.some((message) => /mattermost api 4\d{2}\b/.test(message))) return false;
|
|
@@ -99,6 +99,12 @@ function createLegacyWebhookListenerDoctorContract(params) {
|
|
|
99
99
|
};
|
|
100
100
|
const prefix = `channels.${params.channelKey}`;
|
|
101
101
|
return {
|
|
102
|
+
historicalWebhookListener: {
|
|
103
|
+
channelId: params.channelKey,
|
|
104
|
+
port: params.defaultPort,
|
|
105
|
+
preserveAuthoredActivation: params.preserveAuthoredActivation,
|
|
106
|
+
...params.defaultHost === void 0 ? {} : { host: params.defaultHost }
|
|
107
|
+
},
|
|
102
108
|
legacyConfigRules: [{
|
|
103
109
|
path: ["channels", params.channelKey],
|
|
104
110
|
message: `${prefix} webhook listeners moved to Gateway routes. Run "openclaw doctor --fix" to preserve explicitly configured listener settings as legacyWebhook.`,
|
|
@@ -157,19 +163,10 @@ import * as import_openclaw_plugin_sdk_runtime_doctor_migrations from "openclaw/
|
|
|
157
163
|
__reExport(runtime_doctor_migrations_exports, import_openclaw_plugin_sdk_runtime_doctor_migrations);
|
|
158
164
|
//#endregion
|
|
159
165
|
//#region extensions/mattermost/src/doctor-contract.ts
|
|
160
|
-
const
|
|
161
|
-
const streamingAliasMigration = (0, runtime_doctor_migrations_exports.defineChannelAliasMigration)({
|
|
166
|
+
const { legacyConfigRules, normalizeChannelConfig: normalizeCompatibilityConfig } = (0, runtime_doctor_migrations_exports.defineChannelAliasMigration)({
|
|
162
167
|
channelId: "mattermost",
|
|
163
168
|
streaming: { defaultMode: "partial" },
|
|
164
169
|
accountStreamingReplacesRoot: true
|
|
165
170
|
});
|
|
166
|
-
const legacyConfigRules = [...networkContract.legacyConfigRules, ...streamingAliasMigration.legacyConfigRules];
|
|
167
|
-
function normalizeCompatibilityConfig({ cfg }) {
|
|
168
|
-
const network = networkContract.normalizeCompatibilityConfig({ cfg });
|
|
169
|
-
return streamingAliasMigration.normalizeChannelConfig({
|
|
170
|
-
cfg: network.config,
|
|
171
|
-
changes: network.changes
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
171
|
//#endregion
|
|
175
172
|
export { normalizeCompatibilityConfig as n, legacyConfigRules as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t as collectMattermostCallbackPaths } from "./callback-host-CBsPjVAZ.mjs";
|
|
2
|
+
//#region extensions/mattermost/src/gateway-auth-bypass.ts
|
|
3
|
+
function resolveMattermostGatewayAuthBypassPaths(params) {
|
|
4
|
+
return collectMattermostCallbackPaths(params.cfg.channels?.mattermost).filter((path) => path.startsWith("/api/channels/mattermost/"));
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { resolveMattermostGatewayAuthBypassPaths as t };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./rolldown-runtime-BBjsoOtd.mjs";
|
|
2
2
|
import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { r as resolveCallbackHost } from "./callback-host-CBsPjVAZ.mjs";
|
|
4
|
+
import { y as updateMattermostPost } from "./client-f2qstbX3.mjs";
|
|
4
5
|
import { D as sendHttpRequestRejection, T as resolveClientIp, g as isTrustedProxyAddress, h as isRequestBodyLimitError, x as readRequestBodyWithLimit } from "./monitor-auth-aZ0b1gqx.mjs";
|
|
5
6
|
import { createHmac } from "node:crypto";
|
|
6
7
|
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
7
8
|
import { normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
9
|
+
import { safeParseJson } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
8
10
|
//#region src/gateway/gateway-http-route-contracts.ts
|
|
9
11
|
const GATEWAY_PROBE_ROUTES = /* @__PURE__ */ new Map([
|
|
10
12
|
["/health", "live"],
|
|
@@ -144,14 +146,6 @@ var gateway_config_runtime_exports = /* @__PURE__ */ __exportAll({
|
|
|
144
146
|
import * as import_openclaw_plugin_sdk_gateway_config_runtime from "openclaw/plugin-sdk/gateway-config-runtime";
|
|
145
147
|
__reExport(gateway_config_runtime_exports, import_openclaw_plugin_sdk_gateway_config_runtime);
|
|
146
148
|
//#endregion
|
|
147
|
-
//#region extensions/mattermost/src/mattermost/callback-host.ts
|
|
148
|
-
function isWildcardBindHost(rawHost) {
|
|
149
|
-
const trimmed = rawHost.trim();
|
|
150
|
-
if (!trimmed) return false;
|
|
151
|
-
const host = trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
|
|
152
|
-
return host === "0.0.0.0" || host === "::" || host === "0:0:0:0:0:0:0:0" || host === "::0";
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
149
|
//#region extensions/mattermost/src/mattermost/interactions.ts
|
|
156
150
|
const INTERACTION_MAX_BODY_BYTES = 65536;
|
|
157
151
|
const INTERACTION_BODY_TIMEOUT_MS = 1e4;
|
|
@@ -188,9 +182,7 @@ function computeInteractionCallbackUrl(accountId, cfg) {
|
|
|
188
182
|
const callbackBaseUrl = normalizeOptionalString(cfg?.interactions?.callbackBaseUrl) ?? normalizeOptionalString(cfg?.channels?.mattermost?.interactions?.callbackBaseUrl);
|
|
189
183
|
if (callbackBaseUrl) return `${callbackBaseUrl.replace(/\/+$/, "")}${path}`;
|
|
190
184
|
const port = (0, gateway_config_runtime_exports.resolveGatewayPort)(cfg);
|
|
191
|
-
|
|
192
|
-
if (host.includes(":") && !(host.startsWith("[") && host.endsWith("]"))) host = `[${host}]`;
|
|
193
|
-
return `http://${host}:${port}${path}`;
|
|
185
|
+
return `http://${resolveCallbackHost(cfg?.gateway?.customBindHost, true)}:${port}${path}`;
|
|
194
186
|
}
|
|
195
187
|
/**
|
|
196
188
|
* Resolve the interaction callback URL for an account.
|
|
@@ -203,21 +195,15 @@ function resolveInteractionCallbackUrl(accountId, cfg) {
|
|
|
203
195
|
return computeInteractionCallbackUrl(accountId, cfg);
|
|
204
196
|
}
|
|
205
197
|
const interactionSecrets = /* @__PURE__ */ new Map();
|
|
206
|
-
let defaultInteractionSecret;
|
|
207
198
|
function deriveInteractionSecret(botToken) {
|
|
208
199
|
return createHmac("sha256", "openclaw-mattermost-interactions").update(botToken).digest("hex");
|
|
209
200
|
}
|
|
210
|
-
function setInteractionSecret(
|
|
211
|
-
|
|
212
|
-
interactionSecrets.set(accountIdOrBotToken, deriveInteractionSecret(botToken));
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
defaultInteractionSecret = deriveInteractionSecret(accountIdOrBotToken);
|
|
201
|
+
function setInteractionSecret(accountId, botToken) {
|
|
202
|
+
interactionSecrets.set(accountId, deriveInteractionSecret(botToken));
|
|
216
203
|
}
|
|
217
204
|
function getInteractionSecret(accountId) {
|
|
218
205
|
const scoped = accountId ? interactionSecrets.get(accountId) : void 0;
|
|
219
206
|
if (scoped) return scoped;
|
|
220
|
-
if (defaultInteractionSecret) return defaultInteractionSecret;
|
|
221
207
|
if (interactionSecrets.size === 1) {
|
|
222
208
|
const first = interactionSecrets.values().next().value;
|
|
223
209
|
if (typeof first === "string") return first;
|
|
@@ -300,11 +286,9 @@ function createMattermostInteractionHandler(params) {
|
|
|
300
286
|
const { client, accountId, log } = params;
|
|
301
287
|
const core = getMattermostRuntime();
|
|
302
288
|
function parseInteractionPayload(raw) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
throw new Error("Mattermost interaction body was malformed JSON");
|
|
307
|
-
}
|
|
289
|
+
const payload = safeParseJson(raw);
|
|
290
|
+
if (payload === null) throw new Error("Mattermost interaction body was malformed JSON");
|
|
291
|
+
return payload;
|
|
308
292
|
}
|
|
309
293
|
return async (req, res) => {
|
|
310
294
|
if (req.method !== "POST") {
|
|
@@ -476,4 +460,4 @@ function createMattermostInteractionHandler(params) {
|
|
|
476
460
|
};
|
|
477
461
|
}
|
|
478
462
|
//#endregion
|
|
479
|
-
export { resolveInteractionCallbackPath as a, setInteractionSecret as c, createMattermostInteractionHandler as i,
|
|
463
|
+
export { resolveInteractionCallbackPath as a, setInteractionSecret as c, createMattermostInteractionHandler as i, gateway_config_runtime_exports as l, buildButtonProps as n, resolveInteractionCallbackUrl as o, computeInteractionCallbackUrl as r, setInteractionCallbackUrl as s, buildButtonAttachments as t };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl
|
|
1
|
+
import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, l as gateway_config_runtime_exports, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl } from "./interactions-CfOLvzca.mjs";
|
|
2
2
|
import { n as getOptionalMattermostRuntime, t as getMattermostRuntime } from "./runtime-CNB4YGqJ.mjs";
|
|
3
|
-
import { a as createMattermostPost, d as fetchMattermostUser, h as normalizeMattermostBaseUrl, m as isRetryableError, n as buildMattermostApiUrl, o as deleteMattermostPost, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, t as MattermostPostSchema, u as fetchMattermostMe, v as sendMattermostTyping, y as updateMattermostPost } from "./client-
|
|
3
|
+
import { a as createMattermostPost, d as fetchMattermostUser, h as normalizeMattermostBaseUrl, m as isRetryableError, n as buildMattermostApiUrl, o as deleteMattermostPost, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, t as MattermostPostSchema, u as fetchMattermostMe, v as sendMattermostTyping, y as updateMattermostPost } from "./client-f2qstbX3.mjs";
|
|
4
4
|
import { C as resolveAllowlistProviderRuntimeGroupPolicy, E as resolveDefaultGroupPolicy, O as warnMissingProviderGroupPolicyFallbackOnce, S as registerPluginHttpRoute, _ as listSkillCommandsForAgents, a as resolveMattermostMonitorInboundAccess, b as logTypingFailure, c as DEFAULT_GROUP_HISTORY_LIMIT, d as createChannelMessageReplyPipeline, f as createChannelPairingController, l as buildPreparedModelsProviderData, m as isDangerousNameMatchingEnabled, n as formatMattermostDirectMessageDropLog, o as resolveMattermostTrustedChatKind, s as shouldRetainMattermostSenderHistory, t as authorizeMattermostCommandInvocation, u as createChannelHistoryWindow, w as resolveChannelMediaMaxBytes, y as logInboundDrop } from "./monitor-auth-aZ0b1gqx.mjs";
|
|
5
5
|
import { n as normalizeMattermostAllowEntry } from "./ingress-identity-DNl4yQSc.mjs";
|
|
6
|
-
import { d as resolveMattermostReplyToMode, r as parseMattermostQuestionContext, u as resolveMattermostAccount } from "./normalize-
|
|
7
|
-
import { _ as resolveSlashCommandConfig, a as deliverMattermostReplyPayload, c as parseMattermostModelPickerContext, d as resolveMattermostModelPickerCurrentModel, f as DEFAULT_COMMAND_SPECS, g as resolveCallbackUrl, h as registerSlashCommands, l as renderMattermostModelsPickerView, m as isSlashCommandsEnabled, n as deactivateSlashCommands, o as joinMattermostVisibleContent, p as cleanupSlashCommands, r as getSlashCommandState, s as buildMattermostAllowedModelRefs, t as activateSlashCommands, u as renderMattermostProviderPickerView } from "./slash-state-
|
|
8
|
-
import { t as sendMessageMattermost } from "./send-
|
|
6
|
+
import { d as resolveMattermostReplyToMode, r as parseMattermostQuestionContext, u as resolveMattermostAccount } from "./normalize-DhF6_2lt.mjs";
|
|
7
|
+
import { _ as resolveSlashCommandConfig, a as deliverMattermostReplyPayload, c as parseMattermostModelPickerContext, d as resolveMattermostModelPickerCurrentModel, f as DEFAULT_COMMAND_SPECS, g as resolveCallbackUrl, h as registerSlashCommands, l as renderMattermostModelsPickerView, m as isSlashCommandsEnabled, n as deactivateSlashCommands, o as joinMattermostVisibleContent, p as cleanupSlashCommands, r as getSlashCommandState, s as buildMattermostAllowedModelRefs, t as activateSlashCommands, u as renderMattermostProviderPickerView } from "./slash-state-BtvU3GNd.mjs";
|
|
8
|
+
import { t as sendMessageMattermost } from "./send-BI4525Fd.mjs";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { resolvePinnedMainDmOwnerFromAllowlist, sanitizeUntrustedFileName } from "openclaw/plugin-sdk/security-runtime";
|
|
11
11
|
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringEntries, normalizeTrimmedStringList, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
12
|
-
import {
|
|
12
|
+
import { escapeRegExp, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
13
|
+
import { createAcceptedChannelDeliveryResult, createChannelPartialDeliveryError, formatInboundEnvelope, formatInboundFromLabel, formatInboundMediaUnavailableText, formatMediaPlaceholderText, implicitMentionKindWhen, isChannelPartialDeliveryError, resolveInboundMentionDecision, resolveInboundSessionEnvelopeContext, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
|
|
13
14
|
import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
14
15
|
import { safeParseJsonWithSchema, safeParseWithSchema } from "openclaw/plugin-sdk/extension-shared";
|
|
15
16
|
import { asDateTimestampMs, resolveExpiresAtMsFromDurationMs, resolvePromptHistoryLimit } from "openclaw/plugin-sdk/number-runtime";
|
|
16
|
-
import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { bindIngressLifecycleToReplyOptions, createChannelIngressError, createChannelIngressMonitor, createChannelProgressDraftCompositor, createFinalizableDraftLifecycle, createLivePreviewLifecycle, createMessageReceiptFromOutboundResults, createPreviewMessageReceipt, listMessageReceiptPlatformIds, resolveChannelStreamingPreviewToolProgress } from "openclaw/plugin-sdk/channel-outbound";
|
|
19
19
|
import { rawDataToString } from "openclaw/plugin-sdk/webhook-ingress";
|
|
@@ -22,7 +22,6 @@ import { fanInChannelIngressLifecycles, resolveChannelImplicitMentions } from "o
|
|
|
22
22
|
import { resolveChannelGroups, resolveChannelGroupsConfigPath } from "openclaw/plugin-sdk/channel-policy";
|
|
23
23
|
import { buildTtsSupplementMediaPayload, countOutboundMedia, getReplyPayloadTtsSupplement, isReasoningReplyPayload, resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
|
24
24
|
import { isRecord } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
25
|
-
import { escapeRegExp, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
26
25
|
import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
|
|
27
26
|
import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
28
27
|
import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
|
|
@@ -34,10 +33,12 @@ import { createDebugProxyWebSocketAgent, resolveDebugProxySettings } from "openc
|
|
|
34
33
|
import { WebSocket } from "openclaw/plugin-sdk/websocket-runtime";
|
|
35
34
|
import { questionGatewayRuntime } from "openclaw/plugin-sdk/question-gateway-runtime";
|
|
36
35
|
import { resolveInboundLastRouteSessionKey, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
36
|
+
import { raceWithTimeout } from "openclaw/plugin-sdk/time-runtime";
|
|
37
37
|
import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
|
|
38
38
|
import { chunkMarkdownTextWithMode } from "openclaw/plugin-sdk/reply-chunking";
|
|
39
39
|
import { createPersistentDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";
|
|
40
40
|
import { createPluginStateErrorReporter } from "openclaw/plugin-sdk/plugin-state-runtime";
|
|
41
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
41
42
|
//#region extensions/mattermost/src/mattermost/monitor-helpers.ts
|
|
42
43
|
function buildMattermostBotMentionPattern(username) {
|
|
43
44
|
return `(?<![a-z0-9_])@${escapeRegExp(username)}(?![a-z0-9_]|[.:-]+[a-z0-9_])`;
|
|
@@ -140,6 +141,17 @@ function createMattermostConnectOnce(opts) {
|
|
|
140
141
|
const pongTimeoutMs = opts.pongTimeoutMs ?? 1e4;
|
|
141
142
|
return async () => {
|
|
142
143
|
const flowId = randomUUID();
|
|
144
|
+
const captureEvent = (event) => {
|
|
145
|
+
captureSdk.captureWsEventAsync?.({
|
|
146
|
+
...event,
|
|
147
|
+
url: opts.wsUrl,
|
|
148
|
+
flowId,
|
|
149
|
+
meta: {
|
|
150
|
+
subsystem: "mattermost-websocket",
|
|
151
|
+
...event.meta
|
|
152
|
+
}
|
|
153
|
+
}).catch(() => {});
|
|
154
|
+
};
|
|
143
155
|
const ws = webSocketFactory(opts.wsUrl, {
|
|
144
156
|
maxPayload: MATTERMOST_WEBSOCKET_MAX_PAYLOAD_BYTES,
|
|
145
157
|
handshakeTimeout: MATTERMOST_WEBSOCKET_HANDSHAKE_TIMEOUT_MS
|
|
@@ -247,13 +259,10 @@ function createMattermostConnectOnce(opts) {
|
|
|
247
259
|
};
|
|
248
260
|
ws.on("open", () => {
|
|
249
261
|
opened = true;
|
|
250
|
-
|
|
251
|
-
url: opts.wsUrl,
|
|
262
|
+
captureEvent({
|
|
252
263
|
direction: "local",
|
|
253
|
-
kind: "ws-open"
|
|
254
|
-
|
|
255
|
-
meta: { subsystem: "mattermost-websocket" }
|
|
256
|
-
}).catch(() => {});
|
|
264
|
+
kind: "ws-open"
|
|
265
|
+
});
|
|
257
266
|
opts.statusSink?.({
|
|
258
267
|
connected: true,
|
|
259
268
|
lifecycle: "starting"
|
|
@@ -264,17 +273,12 @@ function createMattermostConnectOnce(opts) {
|
|
|
264
273
|
action: "authentication_challenge",
|
|
265
274
|
data: { token: opts.botToken }
|
|
266
275
|
});
|
|
267
|
-
|
|
268
|
-
url: opts.wsUrl,
|
|
276
|
+
captureEvent({
|
|
269
277
|
direction: "outbound",
|
|
270
278
|
kind: "ws-frame",
|
|
271
|
-
flowId,
|
|
272
279
|
payload: authPayload,
|
|
273
|
-
meta: {
|
|
274
|
-
|
|
275
|
-
eventType: "authentication_challenge"
|
|
276
|
-
}
|
|
277
|
-
}).catch(() => {});
|
|
280
|
+
meta: { eventType: "authentication_challenge" }
|
|
281
|
+
});
|
|
278
282
|
ws.send(authPayload);
|
|
279
283
|
authTimer = setTimeout(() => {
|
|
280
284
|
authTimer = void 0;
|
|
@@ -293,14 +297,11 @@ function createMattermostConnectOnce(opts) {
|
|
|
293
297
|
});
|
|
294
298
|
ws.on("message", async (data) => {
|
|
295
299
|
const raw = rawDataToString(data);
|
|
296
|
-
|
|
297
|
-
url: opts.wsUrl,
|
|
300
|
+
captureEvent({
|
|
298
301
|
direction: "inbound",
|
|
299
302
|
kind: "ws-frame",
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
meta: { subsystem: "mattermost-websocket" }
|
|
303
|
-
}).catch(() => {});
|
|
303
|
+
payload: Buffer.from(raw)
|
|
304
|
+
});
|
|
304
305
|
const payload = parseMattermostEventPayload(raw);
|
|
305
306
|
if (!payload) return;
|
|
306
307
|
if (payload.status === "OK" && payload.seq_reply === authenticationSeq) {
|
|
@@ -328,15 +329,12 @@ function createMattermostConnectOnce(opts) {
|
|
|
328
329
|
}
|
|
329
330
|
});
|
|
330
331
|
ws.on("close", (code, reason) => {
|
|
331
|
-
|
|
332
|
-
url: opts.wsUrl,
|
|
332
|
+
captureEvent({
|
|
333
333
|
direction: "local",
|
|
334
334
|
kind: "ws-close",
|
|
335
|
-
flowId,
|
|
336
335
|
closeCode: code,
|
|
337
|
-
payload: reason
|
|
338
|
-
|
|
339
|
-
}).catch(() => {});
|
|
336
|
+
payload: reason
|
|
337
|
+
});
|
|
340
338
|
stopHealthChecks();
|
|
341
339
|
const message = reason.toString("utf8");
|
|
342
340
|
opts.statusSink?.({
|
|
@@ -359,14 +357,11 @@ function createMattermostConnectOnce(opts) {
|
|
|
359
357
|
rejectOnce(new WebSocketClosedBeforeOpenError(code, message || void 0));
|
|
360
358
|
});
|
|
361
359
|
ws.on("error", (err) => {
|
|
362
|
-
|
|
363
|
-
url: opts.wsUrl,
|
|
360
|
+
captureEvent({
|
|
364
361
|
direction: "local",
|
|
365
362
|
kind: "error",
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
meta: { subsystem: "mattermost-websocket" }
|
|
369
|
-
}).catch(() => {});
|
|
363
|
+
errorText: String(err)
|
|
364
|
+
});
|
|
370
365
|
opts.runtime.error?.(`mattermost websocket error: ${String(err)}`);
|
|
371
366
|
opts.statusSink?.({
|
|
372
367
|
connected: false,
|
|
@@ -1121,13 +1116,6 @@ function stripOncharPrefix(text, prefixes) {
|
|
|
1121
1116
|
}
|
|
1122
1117
|
//#endregion
|
|
1123
1118
|
//#region extensions/mattermost/src/mattermost/monitor-resources.ts
|
|
1124
|
-
async function buildMattermostInboundMediaPayload(media) {
|
|
1125
|
-
const facts = await toInboundMediaFactsWithMetadata(media);
|
|
1126
|
-
return {
|
|
1127
|
-
...buildChannelInboundMediaPayload(facts),
|
|
1128
|
-
media: facts
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
1119
|
function formatMattermostPendingMediaText(params) {
|
|
1132
1120
|
return [params.body, formatMediaPlaceholderText(params.media)].filter(Boolean).join("\n").trim();
|
|
1133
1121
|
}
|
|
@@ -1418,20 +1406,19 @@ function createMattermostThreadBackfill(params) {
|
|
|
1418
1406
|
const owner = recovery;
|
|
1419
1407
|
const controller = new AbortController();
|
|
1420
1408
|
const deadlineAt = performance.now() + TIMEOUT_MS;
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1409
|
+
const boundedOperation = raceWithTimeout(() => {
|
|
1410
|
+
const operation = fetchEntries(turn, controller.signal);
|
|
1411
|
+
inFlight.add(operation);
|
|
1412
|
+
operation.then(() => inFlight.delete(operation), () => inFlight.delete(operation));
|
|
1413
|
+
return operation;
|
|
1414
|
+
}, TIMEOUT_MS, () => {
|
|
1415
|
+
const error = new DOMException("Mattermost thread recovery deadline", "TimeoutError");
|
|
1416
|
+
controller.abort(error);
|
|
1417
|
+
throw error;
|
|
1428
1418
|
});
|
|
1429
|
-
const operation = fetchEntries(turn, controller.signal);
|
|
1430
|
-
inFlight.add(operation);
|
|
1431
|
-
operation.then(() => inFlight.delete(operation), () => inFlight.delete(operation));
|
|
1432
1419
|
owner.completion = (async () => {
|
|
1433
1420
|
try {
|
|
1434
|
-
const entries = await
|
|
1421
|
+
const entries = await boundedOperation;
|
|
1435
1422
|
if (performance.now() >= deadlineAt) throw new DOMException("Mattermost thread recovery deadline", "TimeoutError");
|
|
1436
1423
|
if (!owns(turn, owner)) return;
|
|
1437
1424
|
const live = channelHistories.get(turn.historyKey) ?? [];
|
|
@@ -1461,7 +1448,6 @@ function createMattermostThreadBackfill(params) {
|
|
|
1461
1448
|
monitor.logVerboseMessage(`mattermost: thread recovery ${owner.status === "pending" ? "retry scheduled" : "gave up"} attempt=${owner.attempts}/${MAX_ATTEMPTS}`);
|
|
1462
1449
|
return;
|
|
1463
1450
|
} finally {
|
|
1464
|
-
clearTimeout(timer);
|
|
1465
1451
|
owner.completion = void 0;
|
|
1466
1452
|
}
|
|
1467
1453
|
})();
|
|
@@ -1496,8 +1482,7 @@ function createMattermostDraftPreviewBoundaryController(params) {
|
|
|
1496
1482
|
hasStreamedContent = true;
|
|
1497
1483
|
},
|
|
1498
1484
|
async noteBoundary() {
|
|
1499
|
-
if (!params.enabled) return;
|
|
1500
|
-
if (!hasStreamedContent) return;
|
|
1485
|
+
if (!params.enabled || !hasStreamedContent) return;
|
|
1501
1486
|
hasStreamedContent = false;
|
|
1502
1487
|
await params.forceNewMessage();
|
|
1503
1488
|
}
|
|
@@ -1511,6 +1496,14 @@ function createMattermostDraftStream(params) {
|
|
|
1511
1496
|
final: false
|
|
1512
1497
|
};
|
|
1513
1498
|
let terminalAcceptedDeliveryError;
|
|
1499
|
+
const retainAcceptedDeliveryFailure = (err) => {
|
|
1500
|
+
if (isChannelPartialDeliveryError(err)) {
|
|
1501
|
+
const acceptedDeliveryError = toErrorObject(err, "Mattermost accepted delivery failed");
|
|
1502
|
+
streamState.stopped = true;
|
|
1503
|
+
terminalAcceptedDeliveryError = acceptedDeliveryError;
|
|
1504
|
+
return acceptedDeliveryError;
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1514
1507
|
const assertNoAcceptedDeliveryFailure = () => {
|
|
1515
1508
|
if (terminalAcceptedDeliveryError !== void 0) throw terminalAcceptedDeliveryError;
|
|
1516
1509
|
};
|
|
@@ -1522,7 +1515,6 @@ function createMattermostDraftStream(params) {
|
|
|
1522
1515
|
const sealedAssistantTexts = [];
|
|
1523
1516
|
const publishedAssistantParts = /* @__PURE__ */ new Map();
|
|
1524
1517
|
const sendOrEditStreamMessage = async (text) => {
|
|
1525
|
-
if (streamState.stopped && !streamState.final) return false;
|
|
1526
1518
|
const target = currentGeneration;
|
|
1527
1519
|
const normalized = normalizeMattermostDraftText(params.renderText?.(text) ?? text, maxChars);
|
|
1528
1520
|
if (!normalized) return false;
|
|
@@ -1544,8 +1536,7 @@ function createMattermostDraftStream(params) {
|
|
|
1544
1536
|
return true;
|
|
1545
1537
|
} catch (err) {
|
|
1546
1538
|
streamState.stopped = true;
|
|
1547
|
-
const acceptedDeliveryError =
|
|
1548
|
-
if (acceptedDeliveryError) terminalAcceptedDeliveryError = acceptedDeliveryError;
|
|
1539
|
+
const acceptedDeliveryError = retainAcceptedDeliveryFailure(err);
|
|
1549
1540
|
params.warn?.(`mattermost stream preview failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1550
1541
|
if (acceptedDeliveryError) throw acceptedDeliveryError;
|
|
1551
1542
|
return false;
|
|
@@ -1590,10 +1581,7 @@ function createMattermostDraftStream(params) {
|
|
|
1590
1581
|
assertNoAcceptedDeliveryFailure();
|
|
1591
1582
|
await inFlightAtBoundary;
|
|
1592
1583
|
assertNoAcceptedDeliveryFailure();
|
|
1593
|
-
if (streamState.stopped && !streamState.final)
|
|
1594
|
-
assertNoAcceptedDeliveryFailure();
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1584
|
+
if (streamState.stopped && !streamState.final) return;
|
|
1597
1585
|
const sourceText = pendingText.trim() ? pendingText : sealed.latestSourceText;
|
|
1598
1586
|
const finalizedText = (params.renderText?.(sourceText) ?? sourceText).trim();
|
|
1599
1587
|
const chunks = params.chunkText?.(finalizedText) ?? chunkMarkdownTextWithMode(finalizedText, maxChars, "length");
|
|
@@ -1628,11 +1616,7 @@ function createMattermostDraftStream(params) {
|
|
|
1628
1616
|
requiresBlockBoundary: true
|
|
1629
1617
|
});
|
|
1630
1618
|
} catch (err) {
|
|
1631
|
-
const acceptedDeliveryError =
|
|
1632
|
-
if (acceptedDeliveryError) {
|
|
1633
|
-
streamState.stopped = true;
|
|
1634
|
-
terminalAcceptedDeliveryError = acceptedDeliveryError;
|
|
1635
|
-
}
|
|
1619
|
+
const acceptedDeliveryError = retainAcceptedDeliveryFailure(err);
|
|
1636
1620
|
const publishedAssistantPrefix = assistantText?.slice(0, publishedAssistantOffset).trim();
|
|
1637
1621
|
if (publishedAssistantPrefix) sealedAssistantTexts.push({
|
|
1638
1622
|
text: publishedAssistantPrefix,
|
|
@@ -2568,7 +2552,7 @@ function createMattermostPostHandler(monitor) {
|
|
|
2568
2552
|
WasMentioned: kind !== "direct" ? mentionDecision.effectiveWasMentioned : void 0,
|
|
2569
2553
|
CommandAuthorized: commandAuthorized,
|
|
2570
2554
|
CommandSource: commandAuthorized && isControlCommand ? "text" : void 0,
|
|
2571
|
-
|
|
2555
|
+
media: await toInboundMediaFactsWithMetadata(mediaList)
|
|
2572
2556
|
});
|
|
2573
2557
|
const pinnedMainDmOwner = kind === "direct" ? resolvePinnedMainDmOwnerFromAllowlist({
|
|
2574
2558
|
dmScope: cfg.session?.dmScope,
|
|
@@ -2794,7 +2778,11 @@ async function runWithReconnect(connectFn, opts = {}) {
|
|
|
2794
2778
|
error
|
|
2795
2779
|
}) ?? true)) return;
|
|
2796
2780
|
opts.onReconnect?.(delayMs);
|
|
2797
|
-
|
|
2781
|
+
try {
|
|
2782
|
+
await setTimeout$1(delayMs, void 0, { signal: opts.abortSignal });
|
|
2783
|
+
} catch (delayError) {
|
|
2784
|
+
if (!opts.abortSignal?.aborted) throw delayError;
|
|
2785
|
+
}
|
|
2798
2786
|
if (outcome === "rejected") retryDelay = Math.min(retryDelay * 2, maxDelayMs);
|
|
2799
2787
|
attempt++;
|
|
2800
2788
|
}
|
|
@@ -2805,23 +2793,6 @@ function withJitter(baseMs, jitterRatio, random) {
|
|
|
2805
2793
|
const spread = baseMs * jitterRatio;
|
|
2806
2794
|
return Math.max(1, Math.round(baseMs - spread + normalized * spread * 2));
|
|
2807
2795
|
}
|
|
2808
|
-
function sleepAbortable(ms, signal) {
|
|
2809
|
-
return new Promise((resolve) => {
|
|
2810
|
-
if (signal?.aborted) {
|
|
2811
|
-
resolve();
|
|
2812
|
-
return;
|
|
2813
|
-
}
|
|
2814
|
-
const onAbort = () => {
|
|
2815
|
-
clearTimeout(timer);
|
|
2816
|
-
resolve();
|
|
2817
|
-
};
|
|
2818
|
-
const timer = setTimeout(() => {
|
|
2819
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2820
|
-
resolve();
|
|
2821
|
-
}, ms);
|
|
2822
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
2823
|
-
});
|
|
2824
|
-
}
|
|
2825
2796
|
//#endregion
|
|
2826
2797
|
//#region extensions/mattermost/src/mattermost/monitor.ts
|
|
2827
2798
|
function publishMattermostRecoveringStatus(statusSink, error) {
|
|
@@ -2862,7 +2833,7 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2862
2833
|
const client = createMattermostClient({
|
|
2863
2834
|
baseUrl,
|
|
2864
2835
|
botToken,
|
|
2865
|
-
allowPrivateNetwork:
|
|
2836
|
+
allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true
|
|
2866
2837
|
});
|
|
2867
2838
|
let botUser;
|
|
2868
2839
|
await runWithReconnect(async () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as normalizeMattermostBaseUrl } from "./client-
|
|
1
|
+
import { h as normalizeMattermostBaseUrl } from "./client-f2qstbX3.mjs";
|
|
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
4
|
import { createAccountListHelpers, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
|
|
@@ -16,9 +16,8 @@ const { listAccountIds: listMattermostAccountIds, resolveDefaultAccountId: resol
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
function resolveMattermostRequireMention(config) {
|
|
19
|
-
if (config.chatmode === "oncall") return true;
|
|
19
|
+
if (config.chatmode === "oncall" || config.chatmode === "onchar") return true;
|
|
20
20
|
if (config.chatmode === "onmessage") return false;
|
|
21
|
-
if (config.chatmode === "onchar") return true;
|
|
22
21
|
return config.requireMention;
|
|
23
22
|
}
|
|
24
23
|
function resolveMattermostAccountWithMode(params) {
|