@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.
- package/dist/{accounts-NaMdx9yF.js → accounts-DspH-NMT.js} +1 -1
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +2 -3
- package/dist/{channel-plugin-runtime-DlrMaSIu.js → channel-plugin-runtime-C_mWt_83.js} +76 -60
- package/dist/channel-plugin-runtime.js +1 -1
- package/dist/{channel.runtime-DndW9G7T.js → channel.runtime-CpQzh8-1.js} +136 -90
- package/dist/{client-CqqzTcno.js → client-B_hd-kwM.js} +37 -71
- package/dist/doctor-contract-api.js +1 -1
- package/dist/{doctor-contract-BaUvVh8e.js → doctor-contract-mvORF4f6.js} +1 -2
- package/dist/gateway-auth-api.js +1 -1
- package/dist/{gateway-auth-bypass-CL1PxV3z.js → gateway-auth-bypass-B93t91oq.js} +4 -6
- package/dist/{interactions-BQXY_48h.js → interactions-Du_EJMeN.js} +4 -3
- package/dist/{monitor-auth-rctDliGZ.js → monitor-auth-CVd_4FPD.js} +3 -4
- package/dist/policy-api.js +1 -1
- package/dist/runtime-api.js +2 -2
- package/dist/secret-contract-api.js +1 -1
- package/dist/secret-contract-qg3NXRlS.js +12 -0
- package/dist/slash-route-api.js +1 -1
- package/dist/{slash-state-DM8qmFJR.js → slash-state-BakgoSSL.js} +23 -39
- package/openclaw.plugin.json +51 -2
- package/package.json +9 -5
- package/dist/secret-contract-B4R5Bmhv.js +0 -28
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { n as getOptionalMattermostRuntime, t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl } from "./interactions-
|
|
5
|
-
import { a as resolveMattermostReplyToMode, i as resolveMattermostAccount, n as listMattermostAccountIds, t as inspectMattermostAccount } from "./accounts-
|
|
6
|
-
import {
|
|
7
|
-
import { _ as isSlashCommandsEnabled, a as sendMessageMattermost, b as resolveSlashCommandConfig, c as deliverMattermostReplyPayload, d as parseMattermostModelPickerContext, f as renderMattermostModelsPickerView, g as cleanupSlashCommands, h as DEFAULT_COMMAND_SPECS, l as joinMattermostVisibleContent, m as resolveMattermostModelPickerCurrentModel, n as deactivateSlashCommands, o as resolveMattermostOpaqueTarget, p as renderMattermostProviderPickerView, r as getSlashCommandState, s as createMattermostReplyDeliveryBarrier, t as activateSlashCommands, u as buildMattermostAllowedModelRefs, v as registerSlashCommands, y as resolveCallbackUrl } from "./slash-state-
|
|
2
|
+
import { a as createMattermostPost, d as fetchMattermostUser, g as readMattermostError, l as fetchMattermostChannelPosts, m as normalizeMattermostBaseUrl, 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-B_hd-kwM.js";
|
|
3
|
+
import { S as resolveChannelMediaMaxBytes, T as warnMissingProviderGroupPolicyFallbackOnce, _ as logInboundDrop, b as registerPluginHttpRoute, c as DEFAULT_GROUP_HISTORY_LIMIT, d as createChannelMessageReplyPipeline, f as createChannelPairingController, h as listSkillCommandsForAgents, i as normalizeMattermostAllowEntry, l as buildModelsProviderData, n as formatMattermostDirectMessageDropLog, o as resolveMattermostMonitorInboundAccess, s as resolveMattermostTrustedChatKind, t as authorizeMattermostCommandInvocation, u as createChannelHistoryWindow, v as logTypingFailure, w as resolveDefaultGroupPolicy, x as resolveAllowlistProviderRuntimeGroupPolicy$1 } from "./monitor-auth-CVd_4FPD.js";
|
|
4
|
+
import { a as resolveInteractionCallbackPath, c as setInteractionSecret, i as createMattermostInteractionHandler, n as buildButtonProps, r as computeInteractionCallbackUrl, s as setInteractionCallbackUrl } from "./interactions-Du_EJMeN.js";
|
|
5
|
+
import { a as resolveMattermostReplyToMode, i as resolveMattermostAccount, n as listMattermostAccountIds, t as inspectMattermostAccount } from "./accounts-DspH-NMT.js";
|
|
6
|
+
import { i as normalizeMattermostMessagingTarget } from "./channel-plugin-runtime-C_mWt_83.js";
|
|
7
|
+
import { _ as isSlashCommandsEnabled, a as sendMessageMattermost, b as resolveSlashCommandConfig, c as deliverMattermostReplyPayload, d as parseMattermostModelPickerContext, f as renderMattermostModelsPickerView, g as cleanupSlashCommands, h as DEFAULT_COMMAND_SPECS, l as joinMattermostVisibleContent, m as resolveMattermostModelPickerCurrentModel, n as deactivateSlashCommands, o as resolveMattermostOpaqueTarget, p as renderMattermostProviderPickerView, r as getSlashCommandState, s as createMattermostReplyDeliveryBarrier, t as activateSlashCommands, u as buildMattermostAllowedModelRefs, v as registerSlashCommands, y as resolveCallbackUrl } from "./slash-state-BakgoSSL.js";
|
|
8
8
|
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { resolveGatewayPort } from "openclaw/plugin-sdk/core";
|
|
9
10
|
import { resolvePinnedMainDmOwnerFromAllowlist } from "openclaw/plugin-sdk/security-runtime";
|
|
10
11
|
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString, normalizeStringEntries, normalizeTrimmedStringList, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
12
|
+
import { buildChannelInboundMediaPayload, createChannelPartialDeliveryError, formatInboundEnvelope, formatInboundFromLabel, formatInboundMediaUnavailableText, formatMediaPlaceholderText, implicitMentionKindWhen, isChannelPartialDeliveryError, resolveInboundMentionDecision, resolveInboundSessionEnvelopeContext, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
|
|
13
|
+
import { formatErrorMessage, toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
11
14
|
import { safeParseJsonWithSchema, safeParseWithSchema } from "openclaw/plugin-sdk/extension-shared";
|
|
12
15
|
import { asDateTimestampMs, resolveExpiresAtMsFromDurationMs, resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
|
|
13
16
|
import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
|
|
14
17
|
import { fetchWithSsrFGuard, isPrivateNetworkOptInEnabled, ssrfPolicyFromPrivateNetworkOptIn } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
15
18
|
import { z } from "zod";
|
|
16
|
-
import { buildChannelInboundMediaPayload, createChannelPartialDeliveryError, formatInboundEnvelope, formatInboundFromLabel, formatInboundMediaUnavailableText, formatMediaPlaceholderText, implicitMentionKindWhen, isChannelPartialDeliveryError, resolveInboundMentionDecision, resolveInboundSessionEnvelopeContext, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
|
|
17
19
|
import { bindIngressLifecycleToReplyOptions, buildChannelProgressDraftLineForEntry, createChannelIngressError, createChannelIngressMonitor, createChannelProgressDraftCompositor, createFinalizableDraftLifecycle, createMessageReceiptFromOutboundResults, defineFinalizableLivePreviewAdapter, deliverWithFinalizableLivePreviewAdapter, listMessageReceiptPlatformIds, resolveChannelStreamingPreviewToolProgress } from "openclaw/plugin-sdk/channel-outbound";
|
|
18
20
|
import { resolveAllowlistProviderRuntimeGroupPolicy } from "openclaw/plugin-sdk/runtime-group-policy";
|
|
19
21
|
import { rawDataToString } from "openclaw/plugin-sdk/webhook-ingress";
|
|
@@ -22,12 +24,11 @@ import { buildTtsSupplementMediaPayload, countOutboundMedia, getReplyPayloadTtsS
|
|
|
22
24
|
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
23
25
|
import { isRecord } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
24
26
|
import { resolveInboundLastRouteSessionKey, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
27
|
+
import { runChannelProbe, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
25
28
|
import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
|
|
26
29
|
import { finalizeInboundContext } from "openclaw/plugin-sdk/reply-runtime";
|
|
27
|
-
import { runChannelProbe, sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
28
30
|
import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
29
|
-
import { isLoopbackHost } from "openclaw/plugin-sdk/gateway-runtime";
|
|
30
|
-
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
31
|
+
import { channelReadyPatch, isLoopbackHost } from "openclaw/plugin-sdk/gateway-runtime";
|
|
31
32
|
import { captureWsEvent, createDebugProxyWebSocketAgent, resolveDebugProxySettings } from "openclaw/plugin-sdk/proxy-capture";
|
|
32
33
|
import WebSocket from "ws";
|
|
33
34
|
import { runDetachedWebhookWork } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
@@ -35,6 +36,7 @@ import { resolveChannelContextVisibilityMode, shouldIncludeSupplementalContext }
|
|
|
35
36
|
import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
|
|
36
37
|
import { chunkMarkdownTextWithMode } from "openclaw/plugin-sdk/reply-chunking";
|
|
37
38
|
import { createPersistentDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";
|
|
39
|
+
import { createPluginStateErrorReporter } from "openclaw/plugin-sdk/plugin-state-runtime";
|
|
38
40
|
//#region extensions/mattermost/src/mattermost/directory.ts
|
|
39
41
|
function buildClient(params) {
|
|
40
42
|
const account = inspectMattermostAccount({
|
|
@@ -48,17 +50,10 @@ function buildClient(params) {
|
|
|
48
50
|
allowPrivateNetwork: isPrivateNetworkOptInEnabled(account.config)
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Build clients from ALL enabled accounts (deduplicated by token).
|
|
53
|
-
*
|
|
54
|
-
* We always scan every account because:
|
|
55
|
-
* - Private channels are only visible to bots that are members
|
|
56
|
-
* - The requesting agent's account may have an expired/invalid token
|
|
57
|
-
*
|
|
58
|
-
* This means a single healthy bot token is enough for directory discovery.
|
|
59
|
-
*/
|
|
53
|
+
/** Build the requested account client, or aggregate accounts for an explicitly unscoped lookup. */
|
|
60
54
|
function buildClients(params) {
|
|
61
|
-
const
|
|
55
|
+
const requestedAccountId = params.accountId?.trim();
|
|
56
|
+
const accountIds = requestedAccountId ? [requestedAccountId] : listMattermostAccountIds(params.cfg);
|
|
62
57
|
const seen = /* @__PURE__ */ new Set();
|
|
63
58
|
const clients = [];
|
|
64
59
|
for (const id of accountIds) {
|
|
@@ -214,6 +209,8 @@ const MATTERMOST_WEBSOCKET_MAX_PAYLOAD_BYTES = 16 * 1024 * 1024;
|
|
|
214
209
|
const MATTERMOST_WEBSOCKET_HANDSHAKE_TIMEOUT_MS = 3e4;
|
|
215
210
|
const MattermostEventPayloadSchema = z.object({
|
|
216
211
|
event: z.string().optional(),
|
|
212
|
+
status: z.string().optional(),
|
|
213
|
+
seq_reply: z.number().optional(),
|
|
217
214
|
data: z.object({
|
|
218
215
|
post: z.unknown().optional(),
|
|
219
216
|
reaction: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
|
|
@@ -277,6 +274,7 @@ function createMattermostConnectOnce(opts) {
|
|
|
277
274
|
let protocolPingTimer;
|
|
278
275
|
let protocolPongTimer;
|
|
279
276
|
let initialUpdateAt;
|
|
277
|
+
let authenticationSeq;
|
|
280
278
|
const clearTimers = () => {
|
|
281
279
|
if (healthCheckTimer !== void 0) {
|
|
282
280
|
clearTimeout(healthCheckTimer);
|
|
@@ -376,11 +374,11 @@ function createMattermostConnectOnce(opts) {
|
|
|
376
374
|
});
|
|
377
375
|
opts.statusSink?.({
|
|
378
376
|
connected: true,
|
|
379
|
-
|
|
380
|
-
lastError: null
|
|
377
|
+
lifecycle: "starting"
|
|
381
378
|
});
|
|
379
|
+
authenticationSeq = opts.nextSeq();
|
|
382
380
|
const authPayload = JSON.stringify({
|
|
383
|
-
seq:
|
|
381
|
+
seq: authenticationSeq,
|
|
384
382
|
action: "authentication_challenge",
|
|
385
383
|
data: { token: opts.botToken }
|
|
386
384
|
});
|
|
@@ -407,17 +405,21 @@ function createMattermostConnectOnce(opts) {
|
|
|
407
405
|
scheduleProtocolPing();
|
|
408
406
|
});
|
|
409
407
|
ws.on("message", async (data) => {
|
|
408
|
+
const raw = rawDataToString(data);
|
|
410
409
|
captureWsEvent({
|
|
411
410
|
url: opts.wsUrl,
|
|
412
411
|
direction: "inbound",
|
|
413
412
|
kind: "ws-frame",
|
|
414
413
|
flowId,
|
|
415
|
-
payload: Buffer.from(
|
|
414
|
+
payload: Buffer.from(raw),
|
|
416
415
|
meta: { subsystem: "mattermost-websocket" }
|
|
417
416
|
});
|
|
418
|
-
const raw = rawDataToString(data);
|
|
419
417
|
const payload = parseMattermostEventPayload(raw);
|
|
420
418
|
if (!payload) return;
|
|
419
|
+
if (payload.status === "OK" && payload.seq_reply === authenticationSeq) {
|
|
420
|
+
opts.statusSink?.(channelReadyPatch());
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
421
423
|
if (payload.event === "reaction_added" || payload.event === "reaction_removed") {
|
|
422
424
|
if (!opts.onReaction) return;
|
|
423
425
|
try {
|
|
@@ -449,6 +451,7 @@ function createMattermostConnectOnce(opts) {
|
|
|
449
451
|
const message = reasonToString(reason);
|
|
450
452
|
opts.statusSink?.({
|
|
451
453
|
connected: false,
|
|
454
|
+
lifecycle: "recovering",
|
|
452
455
|
lastDisconnect: {
|
|
453
456
|
at: Date.now(),
|
|
454
457
|
status: code,
|
|
@@ -471,7 +474,11 @@ function createMattermostConnectOnce(opts) {
|
|
|
471
474
|
meta: { subsystem: "mattermost-websocket" }
|
|
472
475
|
});
|
|
473
476
|
opts.runtime.error?.(`mattermost websocket error: ${String(err)}`);
|
|
474
|
-
opts.statusSink?.({
|
|
477
|
+
opts.statusSink?.({
|
|
478
|
+
connected: false,
|
|
479
|
+
lifecycle: "recovering",
|
|
480
|
+
lastError: String(err)
|
|
481
|
+
});
|
|
475
482
|
try {
|
|
476
483
|
ws.close();
|
|
477
484
|
} catch {}
|
|
@@ -517,6 +524,7 @@ function inspectMattermostIngressEvent(rawEvent) {
|
|
|
517
524
|
const data = isRecord(envelope.data) ? envelope.data : null;
|
|
518
525
|
const post = parseRawPost(data?.post);
|
|
519
526
|
const eventId = requiredString(post.id, "post.id");
|
|
527
|
+
requiredString(post.user_id, "post.user_id");
|
|
520
528
|
const broadcast = isRecord(envelope.broadcast) ? envelope.broadcast : null;
|
|
521
529
|
return {
|
|
522
530
|
eventId,
|
|
@@ -528,9 +536,13 @@ function parseClaimedEvent(rawEvent, eventId) {
|
|
|
528
536
|
if (!payload || payload.event !== "posted") throw new MattermostIngressPermanentError("invalid-event", `Mattermost ingress row ${eventId} is not a posted event.`);
|
|
529
537
|
const post = parseMattermostPost(payload.data?.post);
|
|
530
538
|
const claimedChannelId = post?.channel_id?.trim() || payload.data?.channel_id?.trim() || payload.broadcast?.channel_id?.trim();
|
|
531
|
-
|
|
539
|
+
const senderId = post?.user_id?.trim();
|
|
540
|
+
if (!post || post.id !== eventId || !senderId || !claimedChannelId) throw new MattermostIngressPermanentError("invalid-event", `Mattermost ingress row ${eventId} has invalid post identity.`);
|
|
532
541
|
return {
|
|
533
|
-
post
|
|
542
|
+
post: {
|
|
543
|
+
...post,
|
|
544
|
+
user_id: senderId
|
|
545
|
+
},
|
|
534
546
|
payload
|
|
535
547
|
};
|
|
536
548
|
}
|
|
@@ -587,7 +599,14 @@ function createMattermostIngressMonitor(options) {
|
|
|
587
599
|
});
|
|
588
600
|
monitor.start();
|
|
589
601
|
return {
|
|
590
|
-
receive:
|
|
602
|
+
receive: async (rawEvent) => {
|
|
603
|
+
try {
|
|
604
|
+
await monitor.admit(rawEvent);
|
|
605
|
+
} catch (error) {
|
|
606
|
+
if (!(error instanceof MattermostIngressPermanentError) || error.reason !== "invalid-event") throw error;
|
|
607
|
+
options.runtime.error?.(`mattermost ingress rejected invalid event: ${error.message}`);
|
|
608
|
+
}
|
|
609
|
+
},
|
|
591
610
|
stop: monitor.stop,
|
|
592
611
|
waitForIdle: monitor.waitForIdle
|
|
593
612
|
};
|
|
@@ -760,6 +779,8 @@ async function buildMattermostEventPlan(monitor, params) {
|
|
|
760
779
|
ParentSessionKey: thread.parentSessionKey,
|
|
761
780
|
AccountId: route.accountId,
|
|
762
781
|
ChatType: kind,
|
|
782
|
+
ConversationRouteContextObserved: true,
|
|
783
|
+
ConversationRoutePeerId: kind === "direct" ? params.senderId : params.channelId,
|
|
763
784
|
GroupChannel: channelName ? `#${channelName}` : void 0,
|
|
764
785
|
GroupSpace: teamId,
|
|
765
786
|
SenderId: params.senderId,
|
|
@@ -767,6 +788,8 @@ async function buildMattermostEventPlan(monitor, params) {
|
|
|
767
788
|
Surface: "mattermost",
|
|
768
789
|
ReplyToId: thread.effectiveReplyToId,
|
|
769
790
|
MessageThreadId: thread.effectiveReplyToId,
|
|
791
|
+
NativeChannelId: params.channelId,
|
|
792
|
+
InboundAccessAuthorized: true,
|
|
770
793
|
OriginatingChannel: "mattermost",
|
|
771
794
|
OriginatingTo: to
|
|
772
795
|
}),
|
|
@@ -939,7 +962,9 @@ function registerMattermostInteractions(params) {
|
|
|
939
962
|
pluginId: "mattermost",
|
|
940
963
|
source: "mattermost-interactions",
|
|
941
964
|
accountId: account.accountId,
|
|
942
|
-
log: (message) => runtime.log?.(message)
|
|
965
|
+
log: (message) => runtime.log?.(message),
|
|
966
|
+
replaceExisting: true,
|
|
967
|
+
throwOnFailure: true
|
|
943
968
|
});
|
|
944
969
|
}
|
|
945
970
|
//#endregion
|
|
@@ -1369,6 +1394,10 @@ function createMattermostDraftStream(params) {
|
|
|
1369
1394
|
stopped: false,
|
|
1370
1395
|
final: false
|
|
1371
1396
|
};
|
|
1397
|
+
let terminalAcceptedDeliveryError;
|
|
1398
|
+
const assertNoAcceptedDeliveryFailure = () => {
|
|
1399
|
+
if (terminalAcceptedDeliveryError !== void 0) throw terminalAcceptedDeliveryError;
|
|
1400
|
+
};
|
|
1372
1401
|
let currentGeneration = {
|
|
1373
1402
|
lastSentText: "",
|
|
1374
1403
|
latestSourceText: "",
|
|
@@ -1395,20 +1424,17 @@ function createMattermostDraftStream(params) {
|
|
|
1395
1424
|
message: normalized,
|
|
1396
1425
|
rootId: params.rootId
|
|
1397
1426
|
});
|
|
1398
|
-
|
|
1399
|
-
if (!postId) {
|
|
1400
|
-
streamState.stopped = true;
|
|
1401
|
-
params.warn?.("mattermost stream preview stopped (missing post id from create)");
|
|
1402
|
-
return false;
|
|
1403
|
-
}
|
|
1404
|
-
target.postId = postId;
|
|
1427
|
+
target.postId = sent.id;
|
|
1405
1428
|
target.lastProviderText = sent.message ?? normalized;
|
|
1406
1429
|
}
|
|
1407
1430
|
target.lastSentText = normalized;
|
|
1408
1431
|
return true;
|
|
1409
1432
|
} catch (err) {
|
|
1410
1433
|
streamState.stopped = true;
|
|
1434
|
+
const acceptedDeliveryError = isChannelPartialDeliveryError(err) ? toErrorObject(err, "Mattermost accepted delivery failed") : void 0;
|
|
1435
|
+
if (acceptedDeliveryError) terminalAcceptedDeliveryError = acceptedDeliveryError;
|
|
1411
1436
|
params.warn?.(`mattermost stream preview failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1437
|
+
if (acceptedDeliveryError) throw acceptedDeliveryError;
|
|
1412
1438
|
return false;
|
|
1413
1439
|
}
|
|
1414
1440
|
};
|
|
@@ -1431,6 +1457,7 @@ function createMattermostDraftStream(params) {
|
|
|
1431
1457
|
warnPrefix: "mattermost stream preview cleanup failed"
|
|
1432
1458
|
});
|
|
1433
1459
|
const forceNewMessage = () => {
|
|
1460
|
+
if (terminalAcceptedDeliveryError !== void 0) return Promise.reject(terminalAcceptedDeliveryError);
|
|
1434
1461
|
if (streamState.stopped || streamState.final) return Promise.resolve();
|
|
1435
1462
|
const pendingText = loop.takePending();
|
|
1436
1463
|
const inFlightAtBoundary = loop.waitForInFlight();
|
|
@@ -1440,8 +1467,13 @@ function createMattermostDraftStream(params) {
|
|
|
1440
1467
|
const boundary = (async () => {
|
|
1441
1468
|
try {
|
|
1442
1469
|
await sealed.ready;
|
|
1470
|
+
assertNoAcceptedDeliveryFailure();
|
|
1443
1471
|
await inFlightAtBoundary;
|
|
1444
|
-
|
|
1472
|
+
assertNoAcceptedDeliveryFailure();
|
|
1473
|
+
if (streamState.stopped && !streamState.final) {
|
|
1474
|
+
assertNoAcceptedDeliveryFailure();
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1445
1477
|
const sourceText = pendingText.trim() ? pendingText : sealed.latestSourceText;
|
|
1446
1478
|
const finalizedText = (params.renderText?.(sourceText) ?? sourceText).trim();
|
|
1447
1479
|
const chunks = params.chunkText?.(finalizedText) ?? chunkMarkdownTextWithMode(finalizedText, maxChars, "length");
|
|
@@ -1479,12 +1511,10 @@ function createMattermostDraftStream(params) {
|
|
|
1479
1511
|
message: firstChunk,
|
|
1480
1512
|
rootId: params.rootId
|
|
1481
1513
|
});
|
|
1482
|
-
const firstPostId = firstPost.id?.trim();
|
|
1483
|
-
if (!firstPostId) throw new Error("missing post id from boundary create");
|
|
1484
1514
|
if (assistantText) {
|
|
1485
1515
|
const publishedContent = firstPost.message ?? firstChunk;
|
|
1486
1516
|
trackPublishedAssistantPart({
|
|
1487
|
-
messageId:
|
|
1517
|
+
messageId: firstPost.id,
|
|
1488
1518
|
content: publishedContent
|
|
1489
1519
|
});
|
|
1490
1520
|
publishedAssistantOffset = consumeMattermostPublishedChunk({
|
|
@@ -1500,12 +1530,10 @@ function createMattermostDraftStream(params) {
|
|
|
1500
1530
|
message: chunk,
|
|
1501
1531
|
rootId: params.rootId
|
|
1502
1532
|
});
|
|
1503
|
-
const postId = post.id?.trim();
|
|
1504
|
-
if (!postId) throw new Error("missing post id from boundary create");
|
|
1505
1533
|
if (assistantText) {
|
|
1506
1534
|
const publishedContent = post.message ?? chunk;
|
|
1507
1535
|
trackPublishedAssistantPart({
|
|
1508
|
-
messageId:
|
|
1536
|
+
messageId: post.id,
|
|
1509
1537
|
content: publishedContent
|
|
1510
1538
|
});
|
|
1511
1539
|
publishedAssistantOffset = consumeMattermostPublishedChunk({
|
|
@@ -1520,12 +1548,18 @@ function createMattermostDraftStream(params) {
|
|
|
1520
1548
|
requiresBlockBoundary: true
|
|
1521
1549
|
});
|
|
1522
1550
|
} catch (err) {
|
|
1551
|
+
const acceptedDeliveryError = isChannelPartialDeliveryError(err) ? toErrorObject(err, "Mattermost accepted delivery failed") : void 0;
|
|
1552
|
+
if (acceptedDeliveryError) {
|
|
1553
|
+
streamState.stopped = true;
|
|
1554
|
+
terminalAcceptedDeliveryError = acceptedDeliveryError;
|
|
1555
|
+
}
|
|
1523
1556
|
const publishedAssistantPrefix = assistantText?.slice(0, publishedAssistantOffset).trim();
|
|
1524
1557
|
if (publishedAssistantPrefix) sealedAssistantTexts.push({
|
|
1525
1558
|
text: publishedAssistantPrefix,
|
|
1526
1559
|
requiresBlockBoundary: false
|
|
1527
1560
|
});
|
|
1528
1561
|
params.warn?.(`mattermost stream preview boundary flush failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1562
|
+
if (acceptedDeliveryError) throw acceptedDeliveryError;
|
|
1529
1563
|
}
|
|
1530
1564
|
})();
|
|
1531
1565
|
currentGeneration = {
|
|
@@ -1537,23 +1571,33 @@ function createMattermostDraftStream(params) {
|
|
|
1537
1571
|
return boundary;
|
|
1538
1572
|
};
|
|
1539
1573
|
const flush = async () => {
|
|
1574
|
+
assertNoAcceptedDeliveryFailure();
|
|
1540
1575
|
await loop.flush();
|
|
1541
1576
|
await currentGeneration.ready;
|
|
1577
|
+
assertNoAcceptedDeliveryFailure();
|
|
1542
1578
|
};
|
|
1543
1579
|
const discardPending = async () => {
|
|
1580
|
+
assertNoAcceptedDeliveryFailure();
|
|
1544
1581
|
await stopForClear();
|
|
1545
1582
|
await currentGeneration.ready;
|
|
1583
|
+
assertNoAcceptedDeliveryFailure();
|
|
1546
1584
|
};
|
|
1547
1585
|
const clear = async () => {
|
|
1586
|
+
assertNoAcceptedDeliveryFailure();
|
|
1548
1587
|
await clearWithStop(discardPending);
|
|
1588
|
+
assertNoAcceptedDeliveryFailure();
|
|
1549
1589
|
};
|
|
1550
1590
|
const seal = async () => {
|
|
1591
|
+
assertNoAcceptedDeliveryFailure();
|
|
1551
1592
|
await sealLifecycle();
|
|
1552
1593
|
await currentGeneration.ready;
|
|
1594
|
+
assertNoAcceptedDeliveryFailure();
|
|
1553
1595
|
};
|
|
1554
1596
|
const stop = async () => {
|
|
1597
|
+
assertNoAcceptedDeliveryFailure();
|
|
1555
1598
|
await stopLifecycle();
|
|
1556
1599
|
await currentGeneration.ready;
|
|
1600
|
+
assertNoAcceptedDeliveryFailure();
|
|
1557
1601
|
};
|
|
1558
1602
|
const update = (text) => {
|
|
1559
1603
|
currentGeneration.latestSourceText = text;
|
|
@@ -1566,7 +1610,9 @@ function createMattermostDraftStream(params) {
|
|
|
1566
1610
|
updateLifecycle(text);
|
|
1567
1611
|
};
|
|
1568
1612
|
const settleBoundaries = async () => {
|
|
1613
|
+
assertNoAcceptedDeliveryFailure();
|
|
1569
1614
|
await currentGeneration.ready;
|
|
1615
|
+
assertNoAcceptedDeliveryFailure();
|
|
1570
1616
|
};
|
|
1571
1617
|
const resolveFinalText = (text) => {
|
|
1572
1618
|
const publishedParts = [...publishedAssistantParts.values()];
|
|
@@ -1690,6 +1736,7 @@ async function deliverMattermostReplyWithDraftPreview(params) {
|
|
|
1690
1736
|
resolveFinalizedId: (previewPostId) => finalizedPreviewPost?.id ?? previewPostId,
|
|
1691
1737
|
onPreviewFinalized: (_previewPostId, receipt) => {
|
|
1692
1738
|
params.previewState.finalizedViaPreviewPost = true;
|
|
1739
|
+
previewFinalTextAlreadyDelivered = true;
|
|
1693
1740
|
previewDeliveryResult = {
|
|
1694
1741
|
outcome: "text",
|
|
1695
1742
|
messageIds: listMessageReceiptPlatformIds(receipt),
|
|
@@ -1731,7 +1778,8 @@ async function deliverMattermostReplyWithDraftPreview(params) {
|
|
|
1731
1778
|
return combineMattermostVisibleDeliveryResults([
|
|
1732
1779
|
confirmedPreviewDelivery,
|
|
1733
1780
|
previewDeliveryResult,
|
|
1734
|
-
supplementalDeliveryResult
|
|
1781
|
+
supplementalDeliveryResult,
|
|
1782
|
+
normalDeliveryResult
|
|
1735
1783
|
]) ?? previewDeliveryResult;
|
|
1736
1784
|
} catch (error) {
|
|
1737
1785
|
const completedVisibleResults = [];
|
|
@@ -1774,14 +1822,8 @@ const threadParticipation = createPersistentDedupeCache({
|
|
|
1774
1822
|
namespace: "mattermost.thread-participation",
|
|
1775
1823
|
maxEntries: 1e3,
|
|
1776
1824
|
openStore: (options) => getOptionalMattermostRuntime()?.state.openKeyedStore(options),
|
|
1777
|
-
logError: (
|
|
1778
|
-
|
|
1779
|
-
getOptionalMattermostRuntime()?.logging.getChildLogger({
|
|
1780
|
-
plugin: "mattermost",
|
|
1781
|
-
feature: "thread-participation-state"
|
|
1782
|
-
}).warn("Mattermost persistent thread participation state failed", { error: String(error) });
|
|
1783
|
-
} catch {}
|
|
1784
|
-
}
|
|
1825
|
+
logError: createPluginStateErrorReporter(getOptionalMattermostRuntime, "mattermost", "thread-participation-state", "Mattermost persistent thread participation state failed"),
|
|
1826
|
+
readTimestamp: ({ repliedAt }) => repliedAt
|
|
1785
1827
|
}
|
|
1786
1828
|
});
|
|
1787
1829
|
function makeKey(accountId, channelId, threadRootId) {
|
|
@@ -2093,35 +2135,35 @@ async function dispatchMattermostInboundTurn(monitor, params) {
|
|
|
2093
2135
|
disableBlockStreaming: draftPreviewEnabled ? true : replyOptions.disableBlockStreaming,
|
|
2094
2136
|
...suppressDefaultToolProgressMessages ? { suppressDefaultToolProgressMessages: true } : {},
|
|
2095
2137
|
onModelSelected,
|
|
2096
|
-
onPartialReply: (payloadResult) => account.streamingMode === "progress" ?
|
|
2138
|
+
onPartialReply: (payloadResult) => account.streamingMode === "progress" ? false : updateDraftFromPartial(payloadResult.text),
|
|
2097
2139
|
onAssistantMessageStart: () => {
|
|
2098
2140
|
lastPartialText = "";
|
|
2099
2141
|
progressDraft.resetReasoningProgress();
|
|
2100
2142
|
if (account.streamingMode === "block") {
|
|
2101
2143
|
blockPreviewAssistantMessagePending = true;
|
|
2102
|
-
return;
|
|
2144
|
+
return false;
|
|
2103
2145
|
}
|
|
2104
2146
|
if (account.streamingMode !== "progress") progressDraft.reset();
|
|
2147
|
+
return false;
|
|
2105
2148
|
},
|
|
2106
2149
|
onReasoningEnd: () => {
|
|
2107
2150
|
lastPartialText = "";
|
|
2108
2151
|
progressDraft.resetReasoningProgress();
|
|
2109
2152
|
if (account.streamingMode !== "block" && account.streamingMode !== "progress") progressDraft.reset();
|
|
2153
|
+
return false;
|
|
2110
2154
|
},
|
|
2111
2155
|
onReasoningStream: async (payloadResult) => {
|
|
2112
|
-
if (account.streamingMode === "progress") {
|
|
2113
|
-
await progressDraft.pushReasoningProgress(payloadResult.text || "Thinking…", { snapshot: payloadResult.isReasoningSnapshot === true });
|
|
2114
|
-
return;
|
|
2115
|
-
}
|
|
2156
|
+
if (account.streamingMode === "progress") return await progressDraft.pushReasoningProgress(payloadResult.text || "Thinking…", { snapshot: payloadResult.isReasoningSnapshot === true });
|
|
2116
2157
|
if (!lastPartialText) {
|
|
2117
2158
|
const boundarySettled = enterBlockPreviewActivity("reasoning");
|
|
2118
2159
|
draftStream.update("Thinking…");
|
|
2119
2160
|
previewBoundaryController.noteUpdate();
|
|
2120
2161
|
await boundarySettled;
|
|
2121
2162
|
}
|
|
2163
|
+
return false;
|
|
2122
2164
|
},
|
|
2123
2165
|
onToolStart: async (payloadValue) => {
|
|
2124
|
-
if (!draftToolProgressEnabled) return;
|
|
2166
|
+
if (!draftToolProgressEnabled) return false;
|
|
2125
2167
|
const boundarySettled = enterBlockPreviewActivity("tool");
|
|
2126
2168
|
const progressSettled = progressDraft.pushToolProgress(buildChannelProgressDraftLineForEntry(account.config, {
|
|
2127
2169
|
event: "tool",
|
|
@@ -2132,10 +2174,11 @@ async function dispatchMattermostInboundTurn(monitor, params) {
|
|
|
2132
2174
|
args: payloadValue.args
|
|
2133
2175
|
}, payloadValue.detailMode ? { detailMode: payloadValue.detailMode } : void 0), { startImmediately: true });
|
|
2134
2176
|
previewBoundaryController.noteUpdate();
|
|
2135
|
-
await Promise.all([boundarySettled, progressSettled]);
|
|
2177
|
+
const [, visible] = await Promise.all([boundarySettled, progressSettled]);
|
|
2178
|
+
return visible;
|
|
2136
2179
|
},
|
|
2137
2180
|
onItemEvent: async (payloadLocal) => {
|
|
2138
|
-
if (!draftToolProgressEnabled) return;
|
|
2181
|
+
if (!draftToolProgressEnabled) return false;
|
|
2139
2182
|
const boundarySettled = enterBlockPreviewActivity("tool");
|
|
2140
2183
|
const progressSettled = progressDraft.pushToolProgress(buildChannelProgressDraftLineForEntry(account.config, {
|
|
2141
2184
|
event: "item",
|
|
@@ -2150,7 +2193,8 @@ async function dispatchMattermostInboundTurn(monitor, params) {
|
|
|
2150
2193
|
meta: payloadLocal.meta
|
|
2151
2194
|
}), { startImmediately: true });
|
|
2152
2195
|
previewBoundaryController.noteUpdate();
|
|
2153
|
-
await Promise.all([boundarySettled, progressSettled]);
|
|
2196
|
+
const [, visible] = await Promise.all([boundarySettled, progressSettled]);
|
|
2197
|
+
return visible;
|
|
2154
2198
|
}
|
|
2155
2199
|
}
|
|
2156
2200
|
})
|
|
@@ -2182,11 +2226,7 @@ function createMattermostPostHandler(monitor) {
|
|
|
2182
2226
|
return;
|
|
2183
2227
|
}
|
|
2184
2228
|
const allMessageIds = messageIds?.length ? messageIds : [post.id];
|
|
2185
|
-
const senderId = post.user_id
|
|
2186
|
-
if (!senderId) {
|
|
2187
|
-
monitor.logVerboseMessage("mattermost: drop post (missing sender id)");
|
|
2188
|
-
return;
|
|
2189
|
-
}
|
|
2229
|
+
const senderId = post.user_id;
|
|
2190
2230
|
if (senderId === botUserId) {
|
|
2191
2231
|
monitor.logVerboseMessage(`mattermost: drop post (self sender=${senderId})`);
|
|
2192
2232
|
return;
|
|
@@ -2607,7 +2647,7 @@ async function registerMattermostMonitorSlashCommands(params) {
|
|
|
2607
2647
|
const teams = await fetchMattermostUserTeams(params.client, params.botUserId);
|
|
2608
2648
|
const slashCallbackUrl = resolveCallbackUrl({
|
|
2609
2649
|
config: slashConfig,
|
|
2610
|
-
gatewayPort:
|
|
2650
|
+
gatewayPort: resolveGatewayPort(params.cfg),
|
|
2611
2651
|
gatewayHost: params.cfg.gateway?.customBindHost ?? void 0
|
|
2612
2652
|
});
|
|
2613
2653
|
warnOnSuspiciousCallbackUrl({
|
|
@@ -2728,6 +2768,13 @@ function sleepAbortable(ms, signal) {
|
|
|
2728
2768
|
}
|
|
2729
2769
|
//#endregion
|
|
2730
2770
|
//#region extensions/mattermost/src/mattermost/monitor.ts
|
|
2771
|
+
function publishMattermostRecoveringStatus(statusSink, error) {
|
|
2772
|
+
statusSink?.({
|
|
2773
|
+
lastError: String(error),
|
|
2774
|
+
connected: false,
|
|
2775
|
+
lifecycle: "recovering"
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2731
2778
|
async function monitorMattermostProvider(opts = {}) {
|
|
2732
2779
|
const core = getMattermostRuntime();
|
|
2733
2780
|
const runtime = opts.runtime ?? {
|
|
@@ -2765,10 +2812,7 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2765
2812
|
shouldReconnect: ({ outcome }) => outcome === "rejected",
|
|
2766
2813
|
onError: (err) => {
|
|
2767
2814
|
runtime.error?.(`mattermost: API auth failed: ${String(err)}`);
|
|
2768
|
-
opts.statusSink
|
|
2769
|
-
lastError: String(err),
|
|
2770
|
-
connected: false
|
|
2771
|
-
});
|
|
2815
|
+
publishMattermostRecoveringStatus(opts.statusSink, err);
|
|
2772
2816
|
},
|
|
2773
2817
|
onReconnect: (delayMs) => {
|
|
2774
2818
|
runtime.log?.(`mattermost: API not accessible, retrying in ${Math.round(delayMs / 1e3)}s`);
|
|
@@ -2778,15 +2822,6 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2778
2822
|
const botUserId = botUser.id;
|
|
2779
2823
|
const botUsername = normalizeOptionalString(botUser.username);
|
|
2780
2824
|
runtime.log?.(`mattermost connected as ${botUsername ? `@${botUsername}` : botUserId}`);
|
|
2781
|
-
await registerMattermostMonitorSlashCommands({
|
|
2782
|
-
client,
|
|
2783
|
-
cfg,
|
|
2784
|
-
runtime,
|
|
2785
|
-
account,
|
|
2786
|
-
baseUrl,
|
|
2787
|
-
botUserId
|
|
2788
|
-
});
|
|
2789
|
-
const slashEnabled = getSlashCommandState(account.accountId) != null;
|
|
2790
2825
|
setInteractionSecret(account.accountId, botToken);
|
|
2791
2826
|
const interactionPath = resolveInteractionCallbackPath(account.accountId);
|
|
2792
2827
|
const callbackUrl = computeInteractionCallbackUrl(account.accountId, {
|
|
@@ -2850,6 +2885,20 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2850
2885
|
allowedSourceIps: allowedInteractionSourceIps.length > 0 ? allowedInteractionSourceIps : ["127.0.0.1", "::1"],
|
|
2851
2886
|
handleModelPickerInteraction: createMattermostModelPickerInteractionHandler(monitor)
|
|
2852
2887
|
});
|
|
2888
|
+
try {
|
|
2889
|
+
await registerMattermostMonitorSlashCommands({
|
|
2890
|
+
client,
|
|
2891
|
+
cfg,
|
|
2892
|
+
runtime,
|
|
2893
|
+
account,
|
|
2894
|
+
baseUrl,
|
|
2895
|
+
botUserId
|
|
2896
|
+
});
|
|
2897
|
+
} catch (error) {
|
|
2898
|
+
unregisterInteractions();
|
|
2899
|
+
throw error;
|
|
2900
|
+
}
|
|
2901
|
+
const slashEnabled = getSlashCommandState(account.accountId) != null;
|
|
2853
2902
|
const handlePost = createMattermostPostHandler(monitor);
|
|
2854
2903
|
const handleReactionEvent = createMattermostReactionHandler(monitor);
|
|
2855
2904
|
const debouncer = core.channel.debounce.createInboundDebouncer({
|
|
@@ -2859,12 +2908,12 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2859
2908
|
}),
|
|
2860
2909
|
buildKey: (entry) => {
|
|
2861
2910
|
const channelId = entry.post.channel_id ?? entry.payload.data?.channel_id ?? entry.payload.broadcast?.channel_id;
|
|
2862
|
-
if (!channelId) return null;
|
|
2911
|
+
if (!channelId || !entry.post.user_id) return null;
|
|
2863
2912
|
const threadId = normalizeOptionalString(entry.post.root_id);
|
|
2864
|
-
return `mattermost:${account.accountId}:${channelId}:${threadId ? `thread:${threadId}` : "channel"}`;
|
|
2913
|
+
return `mattermost:${account.accountId}:${channelId}:${threadId ? `thread:${threadId}` : "channel"}:${entry.post.user_id}`;
|
|
2865
2914
|
},
|
|
2866
2915
|
shouldDebounce: (entry) => {
|
|
2867
|
-
if (entry.post.file_ids?.length) return false;
|
|
2916
|
+
if (normalizeOptionalString(entry.post.type) !== void 0 || entry.post.file_ids?.length) return false;
|
|
2868
2917
|
const text = normalizeOptionalString(entry.post.message) ?? "";
|
|
2869
2918
|
return Boolean(text) && !core.channel.commands.isControlCommandMessage(text, cfg);
|
|
2870
2919
|
},
|
|
@@ -2948,10 +2997,7 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2948
2997
|
jitterRatio: .2,
|
|
2949
2998
|
onError: (err) => {
|
|
2950
2999
|
runtime.error?.(`mattermost connection failed: ${String(err)}`);
|
|
2951
|
-
opts.statusSink
|
|
2952
|
-
lastError: String(err),
|
|
2953
|
-
connected: false
|
|
2954
|
-
});
|
|
3000
|
+
publishMattermostRecoveringStatus(opts.statusSink, err);
|
|
2955
3001
|
},
|
|
2956
3002
|
onReconnect: (delayMs) => {
|
|
2957
3003
|
runtime.log?.(`mattermost reconnecting in ${Math.round(delayMs / 1e3)}s`);
|
|
@@ -2959,7 +3005,7 @@ async function monitorMattermostProvider(opts = {}) {
|
|
|
2959
3005
|
});
|
|
2960
3006
|
} finally {
|
|
2961
3007
|
await ingress.stop();
|
|
2962
|
-
unregisterInteractions
|
|
3008
|
+
unregisterInteractions();
|
|
2963
3009
|
}
|
|
2964
3010
|
const slashShutdownCleanupPromise = slashShutdownCleanup;
|
|
2965
3011
|
if (slashShutdownCleanupPromise) await Promise.resolve(slashShutdownCleanupPromise);
|