@openclaw/slack 2026.11.11 → 2026.12.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/{action-runtime-Cs2IxOLc.mjs → action-runtime-BvoZDGSu.mjs} +228 -85
- package/dist/.setup/action-runtime.runtime-BwRLINj-.mjs +1 -0
- package/dist/.setup/{actions-BNOabmV6.mjs → actions-DAWAKRJ9.mjs} +53 -3
- package/dist/.setup/{approval-handler.runtime-C2C-jNxi.mjs → approval-handler.runtime-BIePVIYr.mjs} +5 -5
- package/dist/.setup/{approval-message-updates-Bx2u_5-z.mjs → approval-message-updates-DocYhToX.mjs} +1 -1
- package/dist/.setup/{channel-DbcKs2sx.mjs → channel-paKIY8u4.mjs} +29 -17
- package/dist/.setup/{channel-type-ZG0ErPTI.mjs → channel-type-Ku_QceM7.mjs} +3 -3
- package/dist/.setup/{channel.setup-DNnvYUKL.mjs → channel.setup-BW3ogoi5.mjs} +1 -1
- package/dist/.setup/{cursor-pages-jVn3Vkfi.mjs → client-DQqLIemQ.mjs} +1 -24
- package/dist/.setup/cursor-pages-DiOrzZtc.mjs +30 -0
- package/dist/.setup/{directory-live-DNdw97LA.mjs → directory-live-CJl5MPac.mjs} +2 -1
- package/dist/.setup/{fork-DTKBA8Fm.mjs → fork-Cua6YBp0.mjs} +3 -3
- package/dist/.setup/{literal-text-DdCRYzYh.mjs → literal-text-CXYRhsDp.mjs} +1 -1
- package/dist/.setup/{message-tool-api-B38BpEaE.mjs → message-tool-api-CTxYxzPZ.mjs} +18 -2
- package/dist/.setup/{monitor-MmW89Bu-.mjs → monitor-CkoNScT9.mjs} +44 -32
- package/dist/.setup/{outbound-adapter-1JpFMcJD.mjs → outbound-adapter-lDejfL01.mjs} +4 -4
- package/dist/.setup/{pipeline.runtime-Jl0lv8Nv.mjs → pipeline.runtime-B4H65MB2.mjs} +1565 -164
- package/dist/.setup/{policy-klXrk5vE.mjs → policy-B7_AZUCl.mjs} +1 -1
- package/dist/.setup/{probe-BHqvMbno.mjs → probe-ME1HsC0x.mjs} +71 -107
- package/dist/.setup/{question-delivery-BGwm5Zmr.mjs → question-delivery-CFd8xhhn.mjs} +1 -1
- package/dist/.setup/{relay-source-CukshFI4.mjs → relay-source-D6xKiatj.mjs} +2 -2
- package/dist/.setup/{replies-iMC3Vvxk.mjs → replies-BLOhFQoK.mjs} +5 -5
- package/dist/.setup/{reply-blocks-CFy-O-2B.mjs → reply-blocks-BXQwrMaA.mjs} +1 -1
- package/dist/.setup/{resolve-channels-CF2JME9q.mjs → resolve-channels-CtkJuB1X.mjs} +2 -1
- package/dist/.setup/{resolve-users-DDcCAjH1.mjs → resolve-users-Bqf-wJF9.mjs} +2 -1
- package/dist/.setup/{scopes-DKl6yqIv.mjs → scopes-Dbu5pO1O.mjs} +2 -2
- package/dist/.setup/{send-kGJWQtLk.mjs → send-CNGjlL3z.mjs} +51 -15
- package/dist/.setup/setup-plugin-api-gni0-Cwn.mjs +2 -0
- package/dist/.setup/{setup-surface-CPFVFPFM.mjs → setup-surface--ug5_htx.mjs} +3 -3
- package/dist/.setup/{slash-dispatch.runtime-COX_8_Kh.mjs → slash-dispatch.runtime-ln-mu0Wb.mjs} +1 -1
- package/dist/.source-module-urls/c5ffd0957b234c7c12090e7de4eca2482ef339b8561e078da55b734211b0ba58.json +1 -1
- package/dist/api.js +9 -9
- package/dist/channel-plugin-api.js +1 -1
- package/dist/message-tool-api.js +1 -1
- package/dist/runtime-api.js +8 -8
- package/dist/setup-entry.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/undici/README.md +1 -1
- package/node_modules/undici/docs/docs/api/Dispatcher.md +4 -1
- package/node_modules/undici/docs/docs/api/RetryAgent.md +1 -1
- package/node_modules/undici/docs/docs/api/RetryHandler.md +1 -1
- package/node_modules/undici/docs/docs/index.md +1 -1
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +58 -12
- package/node_modules/undici/lib/dispatcher/client-h1.js +3 -1
- package/node_modules/undici/lib/dispatcher/client-h2.js +80 -23
- package/node_modules/undici/lib/dispatcher/parser-h1.js +2 -1
- package/node_modules/undici/lib/handler/cache-handler.js +305 -39
- package/node_modules/undici/lib/handler/decorator-handler.js +6 -2
- package/node_modules/undici/lib/handler/redirect-handler.js +32 -11
- package/node_modules/undici/lib/interceptor/cache.js +112 -23
- package/node_modules/undici/lib/mock/mock-utils.js +11 -1
- package/node_modules/undici/lib/web/fetch/body.js +28 -8
- package/node_modules/undici/lib/web/fetch/index.js +3 -9
- package/node_modules/undici/lib/web/fetch/request.js +93 -115
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +2 -2
- package/node_modules/undici/package.json +2 -2
- package/node_modules/undici/types/dispatcher.d.ts +1 -1
- package/node_modules/undici/types/formdata.d.ts +6 -6
- package/node_modules/undici/types/retry-handler.d.ts +3 -3
- package/package.json +5 -5
- package/dist/.setup/action-runtime.runtime-me4Yd3j7.mjs +0 -1
- package/dist/.setup/setup-plugin-api-UWUSCOAK.mjs +0 -2
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./rolldown-runtime-nwUcYXjP.mjs";
|
|
2
2
|
import { d as resolveSlackMarkdownOptions, o as resolveDefaultSlackAccountId, p as resolveSlackReplyToMode } from "./accounts-EaPP0fFY.mjs";
|
|
3
3
|
import { n as formatSlackTarget } from "./target-parsing-DwYAP3ts.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { $ as buildSlackBlocksFallbackText, D as truncateSlackText, E as countSlackTextUtf8Bytes, F as SLACK_SESSION_LINK_ACTION_ID, Gt as resolveSlackUserAllowed, O as truncateSlackTextByUtf8Bytes, Tt as escapeSlackMrkdwn, Vt as normalizeSlackAllowOwnerEntry, et as buildSlackCompleteBlocksFallbackText, g as formatSlackError, rt as hasSlackNativeDataBlock, vt as SLACK_EDIT_TEXT_MAX_BYTES, wt as normalizeSlackOutboundText, xt as SLACK_TEXT_LIMIT, y as qualifySlackRoutePeerId } from "./probe-ME1HsC0x.mjs";
|
|
5
5
|
import { n as resolveSlackReplyThreadTs } from "./thread-ts-47Au2-Yn.mjs";
|
|
6
|
-
import { c as resolveSlackReplyRenderPlan, i as prepareSlackReply, o as resolveSlackReplyBlocks } from "./reply-blocks-
|
|
7
|
-
import { d as
|
|
8
|
-
import { C as hasSlackTableBlock, D as buildSlackEditTextPayload, E as resolveSlackMessageText$1, T as resolveSlackBlocksText, a as editSlackRenderedMessage, b as formatSlackFileReference, d as reactSlackMessage, i as editSlackMessage, m as removeSlackReaction, n as deleteSlackMessage, w as isSlackUnfurlAttachment, x as formatSlackFileReferenceList } from "./actions-
|
|
9
|
-
import { a as clearSlackThreadFailureNotice, c as hasSlackThreadParticipation, d as recordSlackThreadParticipation, h as buildSlackNativeDataDeliveryPlan, l as hasSlackThreadParticipationWithPersistence, m as hasSlackMessageIdentity, s as hasSlackThreadFailureNotice, t as sendMessageSlack, u as recordSlackThreadFailureNotice } from "./send-
|
|
10
|
-
import { n as resolveSlackChannelConfig } from "./policy-
|
|
11
|
-
import {
|
|
12
|
-
import { a as emitSlackMessageSentHooks, i as sanitizeSlackMonitorReplyPayload, n as deliverReplies, t as createSlackReplyDeliveryPlan } from "./replies-
|
|
6
|
+
import { c as resolveSlackReplyRenderPlan, i as prepareSlackReply, o as resolveSlackReplyBlocks } from "./reply-blocks-BXQwrMaA.mjs";
|
|
7
|
+
import { d as readLruMapEntry, f as writeLruMapEntry, l as getOrCreateWeakOwnerMap } from "./client-DQqLIemQ.mjs";
|
|
8
|
+
import { C as hasSlackTableBlock, D as buildSlackEditTextPayload, E as resolveSlackMessageText$1, T as resolveSlackBlocksText, a as editSlackRenderedMessage, b as formatSlackFileReference, d as reactSlackMessage, i as editSlackMessage, m as removeSlackReaction, n as deleteSlackMessage, w as isSlackUnfurlAttachment, x as formatSlackFileReferenceList } from "./actions-DAWAKRJ9.mjs";
|
|
9
|
+
import { a as clearSlackThreadFailureNotice, c as hasSlackThreadParticipation, d as recordSlackThreadParticipation, h as buildSlackNativeDataDeliveryPlan, l as hasSlackThreadParticipationWithPersistence, m as hasSlackMessageIdentity, s as hasSlackThreadFailureNotice, t as sendMessageSlack, u as recordSlackThreadFailureNotice } from "./send-CNGjlL3z.mjs";
|
|
10
|
+
import { n as resolveSlackChannelConfig } from "./policy-B7_AZUCl.mjs";
|
|
11
|
+
import { D as readSlackAssistantThreadContext, E as buildSlackAssistantThreadMetadata, O as stripSlackMentionsForCommandDetection, S as stopSlackStream, T as resolveSlackChatType, _ as SlackStreamNotDeliveredError, b as markSlackStreamFallbackDelivered, c as registerSlackSessionRun, g as SlackStreamMessageTooLongError, h as resolveSlackEffectiveAllowFrom, l as resolveSlackThreadContext, m as resolveSlackCommandIngress, o as authorizeSlackDirectMessage, p as authorizeSlackBotRoomMessage, r as resolveSlackRoomContextHints, s as resolveSlackRoutingContext, u as trackSlackDraftMessage, v as appendSlackStream, w as normalizeSlackChannelType, x as startSlackStream, y as discardSlackStreamPendingText } from "./monitor-CkoNScT9.mjs";
|
|
12
|
+
import { a as emitSlackMessageSentHooks, i as sanitizeSlackMonitorReplyPayload, n as deliverReplies, t as createSlackReplyDeliveryPlan } from "./replies-BLOhFQoK.mjs";
|
|
13
13
|
import { asOptionalRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, normalizeOptionalString, readNonBlankString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
14
14
|
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
|
|
15
15
|
import { resolveInboundLastRouteSessionKey } from "openclaw/plugin-sdk/routing";
|
|
16
|
-
import { buildChannelProgressDraftLine, compactChannelProgressDraftLine, createChannelMessageReplyPipeline, createChannelProgressDraftCompositor, createChannelProgressWorkCounter, createDraftStreamLoop, createFinalizableDraftLifecycle, createLivePreviewLifecycle, createMessageReceiptFromOutboundResults, resolveAgentOutboundIdentity, resolveChannelMessageSourceReplyDeliveryMode, resolveChannelProgressDraftConfig, resolveChannelProgressDraftMaxLineChars, resolveChannelStreamingBlockEnabled, resolveChannelStreamingPreviewToolProgress, resolveChannelStreamingSuppressDefaultToolProgressMessages, selectPlanChecklistSteps } from "openclaw/plugin-sdk/channel-outbound";
|
|
16
|
+
import { buildChannelProgressDraftLine, compactChannelProgressDraftLine, createChannelMessageReplyPipeline, createChannelProgressDraftCompositor, createChannelProgressWorkCounter, createDraftStreamLoop, createFinalizableDraftLifecycle, createLivePreviewLifecycle, createMessageReceiptFromOutboundResults, resolveAgentOutboundIdentity, resolveChannelMessageSourceReplyDeliveryMode, resolveChannelProgressDraftConfig, resolveChannelProgressDraftMaxLineChars, resolveChannelProgressDraftMaxLines, resolveChannelStreamingBlockEnabled, resolveChannelStreamingPreviewToolProgress, resolveChannelStreamingSuppressDefaultToolProgressMessages, selectPlanChecklistSteps } from "openclaw/plugin-sdk/channel-outbound";
|
|
17
17
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
18
|
-
import { danger, logVerbose, shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
|
|
18
|
+
import { danger, logVerbose, shouldLogVerbose, warn } from "openclaw/plugin-sdk/runtime-env";
|
|
19
19
|
import { sanitizeAssistantVisibleText } from "openclaw/plugin-sdk/text-chunking";
|
|
20
20
|
import { normalizeStringEntriesLower } from "openclaw/plugin-sdk/string-normalization-runtime";
|
|
21
21
|
import { createStaleWhileRevalidateCache } from "openclaw/plugin-sdk/collection-runtime";
|
|
@@ -34,7 +34,6 @@ import { mergePairLoopGuardConfig } from "openclaw/plugin-sdk/pair-loop-guard-ru
|
|
|
34
34
|
import { getSessionEntryAsync, readSessionUpdatedAtAsync, resolveChannelResetConfig, resolveStorePath, updateLastRoute } from "openclaw/plugin-sdk/session-store-runtime";
|
|
35
35
|
import { enqueueRoutedSystemEvent } from "openclaw/plugin-sdk/system-event-runtime";
|
|
36
36
|
import { getGlobalHookRunner } from "openclaw/plugin-sdk/plugin-runtime";
|
|
37
|
-
import { shouldHandleTextCommands } from "openclaw/plugin-sdk/command-surface";
|
|
38
37
|
import { resolveHumanDelayConfig } from "openclaw/plugin-sdk/agent-runtime";
|
|
39
38
|
import { buildChannelInboundEventContext, buildMentionRegexes, classifyChannelInboundEvent, dispatchChannelInboundTurn, formatInboundEnvelope, formatInboundMediaUnavailableText, hasVisibleInboundReplyDispatch, isGroupThreadRouteExclusive, matchesMentionWithExplicit, readAgentRunTerminalOutcome, resolveEnvelopeFormatOptions, resolveGroupThreadConfig, resolveGroupThreadMentionFacts, resolveInboundMentionDecision, resolveUnmentionedGroupInboundPolicy, toInboundMediaFactsWithMetadata } from "openclaw/plugin-sdk/channel-inbound";
|
|
40
39
|
import { resolveGatewayPublicOrigin } from "openclaw/plugin-sdk/config-contracts";
|
|
@@ -42,9 +41,212 @@ import { buildControlUiSessionPath } from "openclaw/plugin-sdk/session-discussio
|
|
|
42
41
|
import { createStatusReactionController, logAckFailure, logTypingFailure, resolveAckReaction, shouldAckReaction } from "openclaw/plugin-sdk/channel-feedback";
|
|
43
42
|
import { hasControlCommand } from "openclaw/plugin-sdk/command-detection";
|
|
44
43
|
import { isAbortRequestText } from "openclaw/plugin-sdk/command-primitives-runtime";
|
|
44
|
+
import { shouldHandleTextCommands } from "openclaw/plugin-sdk/command-surface";
|
|
45
45
|
import { resolveChannelContextVisibilityMode } from "openclaw/plugin-sdk/context-visibility-runtime";
|
|
46
46
|
import { DEFAULT_GROUP_HISTORY_LIMIT, buildHistoryContextFromEntries, buildInboundHistoryFromEntries } from "openclaw/plugin-sdk/reply-history";
|
|
47
47
|
import { createChannelPreflightAudio, formatAudioTranscriptForAgent } from "openclaw/plugin-sdk/media-understanding-runtime";
|
|
48
|
+
// extensions/slack/src/stream-size.ts
|
|
49
|
+
/**
|
|
50
|
+
* Size accounting for one native Slack stream message.
|
|
51
|
+
*
|
|
52
|
+
* Slack documents no total size for a streamed message, but chat.startStream
|
|
53
|
+
* and chat.appendStream answer `msg_too_long` once a message that carries text
|
|
54
|
+
* passes a threshold. Measured 2026-11-15 against the live API with exact
|
|
55
|
+
* boundary searches (one more unit was rejected), through both methods:
|
|
56
|
+
*
|
|
57
|
+
* - Slack counts the message as it stores it: the plan block serialized as
|
|
58
|
+
* JSON plus the markdown text, against one ceiling of 13,200.
|
|
59
|
+
* - In the plan block each task costs its JSON, 46 plus its id; titles,
|
|
60
|
+
* `details` and `output` are JSON-escaped: ASCII is one unit (`"`, `\` and
|
|
61
|
+
* `/` two), every other UTF-16 unit six, so CJK costs six per character and
|
|
62
|
+
* an emoji twelve. `details` and `output` are rich text: 132 for the field,
|
|
63
|
+
* appends extend it, and an emoji in it becomes an element of about 50.
|
|
64
|
+
* - Text counts one per character (ASCII, accented Latin and CJK alike), with
|
|
65
|
+
* an emoji counted as its `:shortcode:` (🧠 7, 👍 4, ✅ 18), and is capped
|
|
66
|
+
* at 12,000 characters on its own.
|
|
67
|
+
* - Rows on a message without text are not checked (a 20,000-character title
|
|
68
|
+
* was accepted), nor was the plan title. The API accepts more than 50 task
|
|
69
|
+
* ids but renders 50.
|
|
70
|
+
*
|
|
71
|
+
* The ledger keeps the current value of every field (a title replaced by a
|
|
72
|
+
* longer one counts once) and measures it the same way, rounding up where the
|
|
73
|
+
* exact cost needs a table: every status as `in_progress`, an emoji at 20 in
|
|
74
|
+
* text (the longest measured shortcode is 18) and at 80 in rich text (the
|
|
75
|
+
* element plus the text element after it), and the plan title as if it
|
|
76
|
+
* counted. The budgets sit about 20% under the measured ceilings; the
|
|
77
|
+
* pipeline still treats `msg_too_long` as a signal to continue on a new
|
|
78
|
+
* message.
|
|
79
|
+
*/
|
|
80
|
+
const SLACK_STREAM_MESSAGE_BUDGET_UNITS = 10500;
|
|
81
|
+
/**
|
|
82
|
+
* Plan block units after which new rows go to a continuation message, so a
|
|
83
|
+
* 3,000-3,500 character answer still fits on the message that ends the turn.
|
|
84
|
+
*/
|
|
85
|
+
const SLACK_STREAM_MESSAGE_ROW_BUDGET_UNITS = 7e3;
|
|
86
|
+
/** Text units on one message, 20% under the 12,000-character text cap. */
|
|
87
|
+
const SLACK_STREAM_MESSAGE_TEXT_BUDGET_UNITS = 9600;
|
|
88
|
+
const SLACK_PLAN_BLOCK_UNITS = 58;
|
|
89
|
+
const SLACK_TASK_ROW_UNITS = 49;
|
|
90
|
+
const SLACK_RICH_FIELD_UNITS = 132;
|
|
91
|
+
const SLACK_TEXT_EMOJI_UNITS = 20;
|
|
92
|
+
const SLACK_RICH_TEXT_EMOJI_UNITS = 80;
|
|
93
|
+
const EMOJI_RE = /\p{Extended_Pictographic}/u;
|
|
94
|
+
/**
|
|
95
|
+
* Age after which a streamed message rolls at its next update. Measured
|
|
96
|
+
* 2026-11 against the live API: Slack closes a native stream about 600-610 s
|
|
97
|
+
* after chat.startStream however recently it was appended to, and later
|
|
98
|
+
* appends and the stop then fail with message_not_in_streaming_state. Eight
|
|
99
|
+
* minutes leaves room for a paced update to land first.
|
|
100
|
+
*/
|
|
101
|
+
const SLACK_STREAM_MESSAGE_MAX_AGE_MS = 48e4;
|
|
102
|
+
const SLACK_STREAM_MESSAGE_BUDGET = {
|
|
103
|
+
units: SLACK_STREAM_MESSAGE_BUDGET_UNITS,
|
|
104
|
+
rowUnits: SLACK_STREAM_MESSAGE_ROW_BUDGET_UNITS,
|
|
105
|
+
textUnits: SLACK_STREAM_MESSAGE_TEXT_BUDGET_UNITS,
|
|
106
|
+
tasks: 50
|
|
107
|
+
};
|
|
108
|
+
/** A string in the plan block's JSON: ASCII one unit, escapes two, every other UTF-16 unit six. */
|
|
109
|
+
function countSlackJsonStringUnits(text) {
|
|
110
|
+
const value = text ?? "";
|
|
111
|
+
let units = 0;
|
|
112
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
113
|
+
const code = value.charCodeAt(index);
|
|
114
|
+
units += code >= 128 || code < 32 ? 6 : code === 34 || code === 92 || code === 47 ? 2 : 1;
|
|
115
|
+
}
|
|
116
|
+
return units;
|
|
117
|
+
}
|
|
118
|
+
/** Rich text (`details`, `output`): JSON-escaped, with an emoji stored as an emoji element. */
|
|
119
|
+
function countSlackRichTextUnits(text) {
|
|
120
|
+
let units = 0;
|
|
121
|
+
for (const char of text ?? "") units += EMOJI_RE.test(char) ? SLACK_RICH_TEXT_EMOJI_UNITS : countSlackJsonStringUnits(char);
|
|
122
|
+
return units;
|
|
123
|
+
}
|
|
124
|
+
/** Markdown text: one unit per character, an emoji as its shortcode. */
|
|
125
|
+
function countSlackTextUnits(text) {
|
|
126
|
+
let units = 0;
|
|
127
|
+
for (const char of text ?? "") units += EMOJI_RE.test(char) ? SLACK_TEXT_EMOJI_UNITS : 1;
|
|
128
|
+
return units;
|
|
129
|
+
}
|
|
130
|
+
function appendRichField(current, text) {
|
|
131
|
+
const units = countSlackRichTextUnits(text);
|
|
132
|
+
return units === 0 ? current : current + (current === 0 ? SLACK_RICH_FIELD_UNITS : 0) + units;
|
|
133
|
+
}
|
|
134
|
+
/** Size units (see above) on one streamed message, by field. */
|
|
135
|
+
var SlackStreamMessageLedger = class SlackStreamMessageLedger {
|
|
136
|
+
constructor(taskLimit = 50) {
|
|
137
|
+
this.rows = /* @__PURE__ */ new Map();
|
|
138
|
+
this.text = 0;
|
|
139
|
+
this.startedAt = Date.now();
|
|
140
|
+
this.taskLimit = Math.max(1, Math.min(Math.floor(taskLimit), 50));
|
|
141
|
+
}
|
|
142
|
+
/** The message is old enough that it must roll before Slack closes its stream. */
|
|
143
|
+
get expiring() {
|
|
144
|
+
return Date.now() - this.startedAt >= SLACK_STREAM_MESSAGE_MAX_AGE_MS;
|
|
145
|
+
}
|
|
146
|
+
/** Size units on the message. */
|
|
147
|
+
get size() {
|
|
148
|
+
return this.rowSize + this.text;
|
|
149
|
+
}
|
|
150
|
+
/** Size units of the plan block: its title and task rows. */
|
|
151
|
+
get rowSize() {
|
|
152
|
+
if (this.planTitle === void 0 && this.rows.size === 0) return 0;
|
|
153
|
+
let total = SLACK_PLAN_BLOCK_UNITS + (this.planTitle ?? 0);
|
|
154
|
+
for (const row of this.rows.values()) total += row.task + row.details + row.output;
|
|
155
|
+
return total;
|
|
156
|
+
}
|
|
157
|
+
get textSize() {
|
|
158
|
+
return this.text;
|
|
159
|
+
}
|
|
160
|
+
get taskCount() {
|
|
161
|
+
return this.rows.size;
|
|
162
|
+
}
|
|
163
|
+
get isEmpty() {
|
|
164
|
+
return this.rows.size === 0 && this.planTitle === void 0 && this.text === 0;
|
|
165
|
+
}
|
|
166
|
+
hasTask(id) {
|
|
167
|
+
return this.rows.has(id);
|
|
168
|
+
}
|
|
169
|
+
/** An empty ledger for a new message, with the same task limit. */
|
|
170
|
+
fresh() {
|
|
171
|
+
return new SlackStreamMessageLedger(this.taskLimit);
|
|
172
|
+
}
|
|
173
|
+
clone() {
|
|
174
|
+
const copy = new SlackStreamMessageLedger(this.taskLimit);
|
|
175
|
+
for (const [id, row] of this.rows) copy.rows.set(id, { ...row });
|
|
176
|
+
copy.planTitle = this.planTitle;
|
|
177
|
+
copy.text = this.text;
|
|
178
|
+
return copy;
|
|
179
|
+
}
|
|
180
|
+
recordText(text) {
|
|
181
|
+
this.text += countSlackTextUnits(text);
|
|
182
|
+
}
|
|
183
|
+
recordChunk(chunk) {
|
|
184
|
+
if (chunk.type === "plan_update") {
|
|
185
|
+
this.planTitle = countSlackJsonStringUnits(chunk.title);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (chunk.type === "markdown_text") {
|
|
189
|
+
this.text += countSlackTextUnits(chunk.text);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (chunk.type !== "task_update") return;
|
|
193
|
+
const row = this.rows.get(chunk.id) ?? {
|
|
194
|
+
task: 0,
|
|
195
|
+
details: 0,
|
|
196
|
+
output: 0
|
|
197
|
+
};
|
|
198
|
+
row.task = SLACK_TASK_ROW_UNITS + countSlackJsonStringUnits(chunk.id) + countSlackJsonStringUnits(chunk.title);
|
|
199
|
+
row.details = appendRichField(row.details, chunk.details);
|
|
200
|
+
row.output = appendRichField(row.output, chunk.output);
|
|
201
|
+
this.rows.set(chunk.id, row);
|
|
202
|
+
}
|
|
203
|
+
/** Accounts for an update the caller is about to send. */
|
|
204
|
+
record(update) {
|
|
205
|
+
this.recordText(update.text);
|
|
206
|
+
for (const chunk of update.chunks ?? []) this.recordChunk(chunk);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Splits an update into what the current message can still take and what
|
|
211
|
+
* must continue on a new one. Updates to rows already on the message always
|
|
212
|
+
* apply (Slack replaces their titles in place); text and new rows are admitted
|
|
213
|
+
* in order until a budget is reached, and once one new row is deferred every
|
|
214
|
+
* later one is too so the plan keeps its order across messages. An empty
|
|
215
|
+
* message admits at least the text and one row, since rolling could not help.
|
|
216
|
+
*/
|
|
217
|
+
function planSlackStreamUpdateFit(ledger, update, budget = SLACK_STREAM_MESSAGE_BUDGET) {
|
|
218
|
+
const empty = ledger.isEmpty;
|
|
219
|
+
const base = ledger.clone();
|
|
220
|
+
const incoming = [];
|
|
221
|
+
for (const chunk of update.chunks ?? []) if (chunk.type === "task_update" && !ledger.hasTask(chunk.id)) incoming.push(chunk);
|
|
222
|
+
else base.recordChunk(chunk);
|
|
223
|
+
const textUnits = countSlackTextUnits(update.text);
|
|
224
|
+
const textFits = textUnits === 0 || empty || base.size + textUnits <= budget.units && base.textSize + textUnits <= budget.textUnits;
|
|
225
|
+
if (textFits) base.recordText(update.text);
|
|
226
|
+
const admittedTaskIds = /* @__PURE__ */ new Set();
|
|
227
|
+
const deferredTaskIds = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const chunk of incoming) {
|
|
229
|
+
if (chunk.type !== "task_update") continue;
|
|
230
|
+
if (deferredTaskIds.size > 0) {
|
|
231
|
+
deferredTaskIds.add(chunk.id);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const next = base.clone();
|
|
235
|
+
next.recordChunk(chunk);
|
|
236
|
+
if (next.taskCount <= Math.min(budget.tasks, ledger.taskLimit) && next.rowSize <= budget.rowUnits && next.size <= budget.units || empty && base.taskCount === 0) {
|
|
237
|
+
admittedTaskIds.add(chunk.id);
|
|
238
|
+
base.recordChunk(chunk);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
deferredTaskIds.add(chunk.id);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
fits: textFits && deferredTaskIds.size === 0,
|
|
245
|
+
textFits,
|
|
246
|
+
admittedTaskIds,
|
|
247
|
+
deferredTaskIds
|
|
248
|
+
};
|
|
249
|
+
}
|
|
48
250
|
// extensions/slack/src/monitor/message-handler/timestamp.ts
|
|
49
251
|
const SLACK_TIMESTAMP_RE = /^\d+(?:\.\d+)?$/;
|
|
50
252
|
const MAX_SAFE_SLACK_TIMESTAMP_SECONDS = Number.MAX_SAFE_INTEGER / 1e3;
|
|
@@ -85,6 +287,18 @@ function resolveExplicitSlackProgressTitle(entry) {
|
|
|
85
287
|
const trimmed = label.trim();
|
|
86
288
|
return trimmed && trimmed.toLowerCase() !== "auto" ? trimmed : void 0;
|
|
87
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Task rows per native stream message. `progress.maxLines` caps it only when
|
|
292
|
+
* the account sets the key itself: its default (eight) sizes the draft card's
|
|
293
|
+
* rolling window, and a native message without it holds Slack's 50 rows. A
|
|
294
|
+
* message needs one slot for a row it carries (the quiet card's summary row,
|
|
295
|
+
* a tool still running) and one for new work, so the cap is at least two.
|
|
296
|
+
*/
|
|
297
|
+
function resolveSlackNativeMessageRowLimit(entry) {
|
|
298
|
+
if (resolveChannelProgressDraftConfig(entry).maxLines === void 0) return 50;
|
|
299
|
+
const maxLines = resolveChannelProgressDraftMaxLines(entry, 50);
|
|
300
|
+
return Math.max(2, Math.min(maxLines, 50));
|
|
301
|
+
}
|
|
88
302
|
function resolveSlackProgressStyle(entry, hasReplyThread) {
|
|
89
303
|
const progress = entry?.streaming?.progress;
|
|
90
304
|
if (!hasReplyThread && !Object.entries(progress ?? {}).some(([key, value]) => key !== "nativeTaskCards" || value !== true)) return "none";
|
|
@@ -303,6 +517,141 @@ function createSlackDraftStream(params) {
|
|
|
303
517
|
channelId: () => streamMessage?.channelId
|
|
304
518
|
};
|
|
305
519
|
}
|
|
520
|
+
// extensions/slack/src/progress-reasoning.ts
|
|
521
|
+
/**
|
|
522
|
+
* Streamed reasoning rendered as native task cards: fixed-size segments, one
|
|
523
|
+
* task row each, so the whole thought stays readable in the plan block
|
|
524
|
+
* instead of one compacted narration line.
|
|
525
|
+
*/
|
|
526
|
+
/**
|
|
527
|
+
* Reasoning text per card in UTF-16 units, the unit of our 250-unit title cap
|
|
528
|
+
* in `progress-blocks.ts`. With the 3-unit lane prefix a card stays within
|
|
529
|
+
* it, so no segment is ever truncated, emoji and all. The cap is our choice,
|
|
530
|
+
* under the 256 characters Slack documents per `task_update` title
|
|
531
|
+
* (https://docs.slack.dev/reference/methods/chat.appendStream/); the API does
|
|
532
|
+
* not enforce that figure.
|
|
533
|
+
*/
|
|
534
|
+
const SLACK_REASONING_CARD_CHARS = 240;
|
|
535
|
+
const SLACK_REASONING_CARD_LINE_ID_PREFIX = "reasoning:";
|
|
536
|
+
const SLACK_REASONING_CARD_TEXT_PREFIX = "🧠 ";
|
|
537
|
+
/** Running plan title of a continuation message. */
|
|
538
|
+
const SLACK_REASONING_CONTINUED_TITLE = "Thinking, continued";
|
|
539
|
+
function createSlackReasoningCardState() {
|
|
540
|
+
return {
|
|
541
|
+
sealed: [],
|
|
542
|
+
open: "",
|
|
543
|
+
openSealedPrefix: "",
|
|
544
|
+
toolCalls: 0
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
function isSlackReasoningCardLine(line) {
|
|
548
|
+
return line.id?.startsWith(SLACK_REASONING_CARD_LINE_ID_PREFIX) === true;
|
|
549
|
+
}
|
|
550
|
+
function normalizeReasoningText(text) {
|
|
551
|
+
return text.replace(/\s+/gu, " ").trim();
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Splits reasoning into segments of at most `maxChars` UTF-16 units, never
|
|
555
|
+
* splitting a code point, cutting at the last space in the second half of
|
|
556
|
+
* each window. Cuts depend only on the text before them, so segments already
|
|
557
|
+
* shown never change as the text grows.
|
|
558
|
+
*/
|
|
559
|
+
function segmentReasoningText(text, maxChars = SLACK_REASONING_CARD_CHARS) {
|
|
560
|
+
const chars = Array.from(normalizeReasoningText(text));
|
|
561
|
+
return segmentReasoningChars(chars, maxChars).map((segment) => chars.slice(segment.start, segment.end).join("").trim());
|
|
562
|
+
}
|
|
563
|
+
/** Windows (code-point indexes) of each segment of an already normalized text, sized in UTF-16 units. */
|
|
564
|
+
function segmentReasoningChars(chars, maxChars) {
|
|
565
|
+
if (chars.length === 0) return [];
|
|
566
|
+
const offsets = [0];
|
|
567
|
+
for (const char of chars) offsets.push((offsets.at(-1) ?? 0) + char.length);
|
|
568
|
+
const units = (from, to) => (offsets[to] ?? 0) - (offsets[from] ?? 0);
|
|
569
|
+
const segments = [];
|
|
570
|
+
let start = 0;
|
|
571
|
+
while (units(start, chars.length) > maxChars) {
|
|
572
|
+
let end = start;
|
|
573
|
+
while (end < chars.length && units(start, end + 1) <= maxChars) end += 1;
|
|
574
|
+
let cut = end;
|
|
575
|
+
for (let index = end; units(start, index) > Math.floor(maxChars / 2); index -= 1) if (chars[index] === " ") {
|
|
576
|
+
cut = index;
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
segments.push({
|
|
580
|
+
start,
|
|
581
|
+
end: cut
|
|
582
|
+
});
|
|
583
|
+
start = cut;
|
|
584
|
+
while (chars[start] === " ") start += 1;
|
|
585
|
+
}
|
|
586
|
+
if (start < chars.length) segments.push({
|
|
587
|
+
start,
|
|
588
|
+
end: chars.length
|
|
589
|
+
});
|
|
590
|
+
return segments;
|
|
591
|
+
}
|
|
592
|
+
function resolveOpenReasoningWindow(state) {
|
|
593
|
+
const chars = Array.from(normalizeReasoningText(state.open));
|
|
594
|
+
const prefix = Array.from(state.openSealedPrefix);
|
|
595
|
+
let start = 0;
|
|
596
|
+
while (start < prefix.length && start < chars.length && chars[start] === prefix[start]) start += 1;
|
|
597
|
+
while (chars[start] === " ") start += 1;
|
|
598
|
+
return {
|
|
599
|
+
chars,
|
|
600
|
+
start
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
/** Open text not yet sealed by a rollover. */
|
|
604
|
+
function resolveOpenReasoningText(state) {
|
|
605
|
+
const { chars, start } = resolveOpenReasoningWindow(state);
|
|
606
|
+
return chars.slice(start).join("").trim();
|
|
607
|
+
}
|
|
608
|
+
/** Closes the open phase: a tool call or the end of reasoning starts new cards afterwards. */
|
|
609
|
+
function sealSlackReasoningCards(state) {
|
|
610
|
+
state.sealed.push(...segmentReasoningText(resolveOpenReasoningText(state)));
|
|
611
|
+
state.open = "";
|
|
612
|
+
state.openSealedPrefix = "";
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Closes the cards through `throughCard` (1-based, across the turn) without
|
|
616
|
+
* closing the phase: the message they are on is finished. Cards after it and
|
|
617
|
+
* text streamed later stay open and continue on the next message, while the
|
|
618
|
+
* compositor keeps merging the same phase. Segments are cut where they were,
|
|
619
|
+
* because a cut depends only on the text before it.
|
|
620
|
+
*/
|
|
621
|
+
function rolloverSlackReasoningCards(state, throughCard) {
|
|
622
|
+
const openCards = throughCard - state.sealed.length;
|
|
623
|
+
if (openCards <= 0) return;
|
|
624
|
+
const { chars, start } = resolveOpenReasoningWindow(state);
|
|
625
|
+
const remainder = chars.slice(start);
|
|
626
|
+
const windows = segmentReasoningChars(remainder, SLACK_REASONING_CARD_CHARS);
|
|
627
|
+
state.sealed.push(...windows.slice(0, openCards).map((window) => remainder.slice(window.start, window.end).join("").trim()));
|
|
628
|
+
const nextOpen = windows[openCards];
|
|
629
|
+
state.openSealedPrefix = chars.slice(0, nextOpen ? start + nextOpen.start : chars.length).join("");
|
|
630
|
+
}
|
|
631
|
+
function reasoningCardLine(id, text, done) {
|
|
632
|
+
return {
|
|
633
|
+
id,
|
|
634
|
+
kind: "item",
|
|
635
|
+
text: `${SLACK_REASONING_CARD_TEXT_PREFIX}${text}`,
|
|
636
|
+
label: "Reasoning",
|
|
637
|
+
prefix: false,
|
|
638
|
+
...done ? { status: "completed" } : {}
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Card rows for the current reasoning state. Every segment but the newest is
|
|
643
|
+
* complete. Ids number the segments across the whole turn; the stream
|
|
644
|
+
* pipeline decides which message each card lands on.
|
|
645
|
+
*/
|
|
646
|
+
function planSlackReasoningCards(state) {
|
|
647
|
+
const openSegments = segmentReasoningText(resolveOpenReasoningText(state));
|
|
648
|
+
const segments = [...state.sealed, ...openSegments];
|
|
649
|
+
const openIndex = openSegments.length > 0 ? segments.length - 1 : -1;
|
|
650
|
+
return segments.map((segment, index) => reasoningCardLine(`${SLACK_REASONING_CARD_LINE_ID_PREFIX}${index + 1}`, segment, index !== openIndex));
|
|
651
|
+
}
|
|
652
|
+
function formatReasoningSummaryTitle(params) {
|
|
653
|
+
return `Thought for ${Math.max(1, Math.round(params.elapsedMs / 1e3))}s${params.toolCalls > 0 ? `, ${params.toolCalls} tool call${params.toolCalls === 1 ? "" : "s"}` : ""}`;
|
|
654
|
+
}
|
|
306
655
|
// extensions/slack/src/stream-mode.ts
|
|
307
656
|
function resolveSlackStreamingConfig(params) {
|
|
308
657
|
return {
|
|
@@ -358,6 +707,7 @@ const DEFAULT_SLACK_PROGRESS_DETAIL_MAX_CHARS = 120;
|
|
|
358
707
|
const DEFAULT_SLACK_PROGRESS_TASK_DETAIL_MAX_CHARS = 48;
|
|
359
708
|
const SLACK_PROGRESS_CHUNK_TEXT_MAX = 256;
|
|
360
709
|
const SLACK_PROGRESS_TASK_TITLE_MAX = 120;
|
|
710
|
+
const SLACK_PROGRESS_REASONING_TITLE_MAX = 250;
|
|
361
711
|
const SLACK_PROGRESS_PLAN_FALLBACK_TITLE = "Thinking";
|
|
362
712
|
const SLACK_PROGRESS_LINE_DELTA_RE = /(?:^|\s)\+(\d+)\s+[−-](\d+)(?=\s|$)/u;
|
|
363
713
|
const SLACK_ATTENTION_TASK_PREFIX = "openclaw-attention-";
|
|
@@ -414,6 +764,7 @@ function lineDetailParts(line) {
|
|
|
414
764
|
return [line.detail, line.status && line.status !== "completed" && !line.detail?.includes(line.status) ? line.status : void 0].map((part) => part?.trim()).filter((part) => Boolean(part));
|
|
415
765
|
}
|
|
416
766
|
function lineTaskTitle(line) {
|
|
767
|
+
if (isSlackReasoningCardLine(line)) return compactTitle(line.text, SLACK_PROGRESS_REASONING_TITLE_MAX);
|
|
417
768
|
const label = line.label.replace(/\s+/g, " ").trim() || line.toolName || line.kind || "Update";
|
|
418
769
|
const fallback = line.text.replace(/\s+/g, " ").trim();
|
|
419
770
|
if (fallback && fallback !== label) return compactTitle(lineDetailParts(line).length > 0 || line.status ? label : fallback);
|
|
@@ -437,8 +788,18 @@ function stableTaskIdPart(value, slugValue = value) {
|
|
|
437
788
|
const suffix = hash("sha256", value, "hex").slice(0, 8);
|
|
438
789
|
return `${(slug || "task").slice(0, 48)}_${suffix}`;
|
|
439
790
|
}
|
|
791
|
+
/** Native task id of a line that carries its own id; content-keyed lines have none until rendered. */
|
|
792
|
+
function resolveSlackNativeLineTaskId(line) {
|
|
793
|
+
return line.id?.trim() ? stableTaskIdPart(line.id) : void 0;
|
|
794
|
+
}
|
|
795
|
+
/** 1-based card number behind a native task id minted for a `reasoning:<n>` line. */
|
|
796
|
+
function resolveSlackReasoningTaskIndex(id) {
|
|
797
|
+
const match = /^reasoning_(\d+)_[0-9a-f]{8}$/u.exec(id);
|
|
798
|
+
return match ? Number(match[1]) : void 0;
|
|
799
|
+
}
|
|
440
800
|
function resolveLineTaskIdentity(line, contentIdOccurrences) {
|
|
441
|
-
|
|
801
|
+
const ownId = resolveSlackNativeLineTaskId(line);
|
|
802
|
+
if (ownId) return ownId;
|
|
442
803
|
const id = stableTaskIdPart([
|
|
443
804
|
line.kind,
|
|
444
805
|
line.toolName,
|
|
@@ -461,7 +822,7 @@ function formatProgressAttentionTitle(line, finalStatus) {
|
|
|
461
822
|
}
|
|
462
823
|
function buildSlackProgressStreamChunks(params) {
|
|
463
824
|
const approvals = params.lines.filter((line) => line.kind === "approval");
|
|
464
|
-
const taskLines = params.
|
|
825
|
+
const taskLines = params.lines.filter((line) => line.kind !== "approval" && (!params.summaryRow || isSlackReasoningCardLine(line)));
|
|
465
826
|
const tasks = (params.plan ?? []).map((entry, index) => ({
|
|
466
827
|
id: `plan_step_${index + 1}`,
|
|
467
828
|
title: compactTitle(entry.step),
|
|
@@ -469,12 +830,15 @@ function buildSlackProgressStreamChunks(params) {
|
|
|
469
830
|
}));
|
|
470
831
|
const maxLineChars = resolveMaxLineChars(params.maxLineChars, DEFAULT_SLACK_PROGRESS_TASK_DETAIL_MAX_CHARS);
|
|
471
832
|
const taskContentIdOccurrences = /* @__PURE__ */ new Map();
|
|
833
|
+
const reasoningTaskIds = /* @__PURE__ */ new Set();
|
|
472
834
|
for (const line of taskLines) {
|
|
835
|
+
const id = resolveLineTaskIdentity(line, taskContentIdOccurrences);
|
|
473
836
|
const task = {
|
|
474
|
-
id
|
|
837
|
+
id,
|
|
475
838
|
title: lineTaskTitle(line),
|
|
476
839
|
status: lineTaskStatus(line)
|
|
477
840
|
};
|
|
841
|
+
if (isSlackReasoningCardLine(line)) reasoningTaskIds.add(id);
|
|
478
842
|
const detail = line.detail?.replace(SLACK_PROGRESS_LINE_DELTA_RE, "").replace(/\s+·\s*$/u, "").trim();
|
|
479
843
|
const details = detail && detail !== line.status?.trim() ? compactDetail(detail, maxLineChars) : void 0;
|
|
480
844
|
const output = lineTaskOutput(line);
|
|
@@ -494,10 +858,10 @@ function buildSlackProgressStreamChunks(params) {
|
|
|
494
858
|
}
|
|
495
859
|
const headline = params.title?.trim();
|
|
496
860
|
const summaryTitle = params.finalInProgressStatus === "error" ? "Failed" : params.finalInProgressStatus === "complete" || !params.summaryRow ? "Completed" : "Working";
|
|
497
|
-
const newest = tasks.
|
|
498
|
-
const title = compactTitle(headline || (newest?.details ? `${newest.title} — ${newest.details}` : newest?.title) || (params.summaryRow ? summaryTitle : attention.at(-1)?.title) || SLACK_PROGRESS_PLAN_FALLBACK_TITLE, SLACK_PROGRESS_CHUNK_TEXT_MAX);
|
|
861
|
+
const newest = tasks.findLast((task) => !reasoningTaskIds.has(task.id));
|
|
862
|
+
const title = compactTitle(headline || (newest?.details ? `${newest.title} — ${newest.details}` : newest?.title) || (params.summaryRow ? summaryTitle : attention.at(-1)?.title) || params.fallbackTitle || SLACK_PROGRESS_PLAN_FALLBACK_TITLE, SLACK_PROGRESS_CHUNK_TEXT_MAX);
|
|
499
863
|
const diffOutput = params.diffStat && (params.diffStat.added > 0 || params.diffStat.removed > 0) ? `+${params.diffStat.added} −${params.diffStat.removed}` : void 0;
|
|
500
|
-
if (tasks.length
|
|
864
|
+
if (!(params.summaryRow ? tasks.some((task) => !reasoningTaskIds.has(task.id)) : tasks.length > 0) && (params.summaryRow || params.sessionLinks?.length || diffOutput)) tasks.unshift({
|
|
501
865
|
id: "openclaw_summary",
|
|
502
866
|
title: params.summaryRow ? compactTitle(title) : summaryTitle,
|
|
503
867
|
status: params.finalInProgressStatus ?? (params.summaryRow ? "in_progress" : "complete")
|
|
@@ -751,7 +1115,7 @@ function resolveNativeProgressLines(snapshot) {
|
|
|
751
1115
|
return explanationLine ? [...lines, explanationLine] : lines;
|
|
752
1116
|
}
|
|
753
1117
|
function resolveNativeProgressNarration(snapshot) {
|
|
754
|
-
const paragraphs = resolveStructuredProgressLines(snapshot.lines).filter((line) => line.id
|
|
1118
|
+
const paragraphs = resolveStructuredProgressLines(snapshot.lines).filter((line) => line.id?.startsWith("commentary:") === true).map((line) => line.text.trim()).filter((text, index, values) => Boolean(text) && values.indexOf(text) === index);
|
|
755
1119
|
return paragraphs.length > 0 ? paragraphs.join("\n\n") : void 0;
|
|
756
1120
|
}
|
|
757
1121
|
function combineProgressHeadlineAndExplanation(headline, explanation) {
|
|
@@ -996,14 +1360,14 @@ function createSlackNativeProgressTransport(params) {
|
|
|
996
1360
|
const startPromise = delivery.startStream({
|
|
997
1361
|
threadTs: streamThreadTs,
|
|
998
1362
|
...update.text ? { text: update.text } : {},
|
|
999
|
-
...update.chunks
|
|
1363
|
+
...update.chunks ? { chunks: update.chunks } : {},
|
|
1000
1364
|
taskDisplayMode: "plan"
|
|
1001
1365
|
});
|
|
1002
1366
|
delivery.nativeProgressStreamStartPromise = startPromise;
|
|
1003
1367
|
try {
|
|
1004
1368
|
await startPromise;
|
|
1005
1369
|
const delivered = markDelivered(streamThreadTs);
|
|
1006
|
-
return update.chunks
|
|
1370
|
+
return update.chunks ? delivered : true;
|
|
1007
1371
|
} finally {
|
|
1008
1372
|
delivery.nativeProgressStreamStartPromise = null;
|
|
1009
1373
|
}
|
|
@@ -1012,6 +1376,7 @@ function createSlackNativeProgressTransport(params) {
|
|
|
1012
1376
|
if (await delivery.rotateInterruptedStream()) return "rotated";
|
|
1013
1377
|
const session = delivery.streamSession;
|
|
1014
1378
|
if (!session) return false;
|
|
1379
|
+
delivery.streamLedger.record(update);
|
|
1015
1380
|
await appendSlackStream({
|
|
1016
1381
|
session,
|
|
1017
1382
|
...update.text ? { text: update.text } : {},
|
|
@@ -1026,6 +1391,1046 @@ function createSlackNativeProgressTransport(params) {
|
|
|
1026
1391
|
waitForStart
|
|
1027
1392
|
};
|
|
1028
1393
|
}
|
|
1394
|
+
// extensions/slack/src/monitor/message-handler/dispatch-progress-reasoning.ts
|
|
1395
|
+
const SLACK_REASONING_CARDS_WINDOW_LINES = Number.MAX_SAFE_INTEGER;
|
|
1396
|
+
/**
|
|
1397
|
+
* Reasoning outside progress mode: one rolling preview row, shown only with
|
|
1398
|
+
* tool progress previews. Each merge reprocesses the accumulated reasoning,
|
|
1399
|
+
* so a long stream with no preview to show it would block the event loop for
|
|
1400
|
+
* nothing. Tool admission closes reasoning bursts, so the still-open lane is
|
|
1401
|
+
* restored after it.
|
|
1402
|
+
*/
|
|
1403
|
+
async function pushSlackReasoningPreview(compositor, payload, previewEnabled) {
|
|
1404
|
+
if (!previewEnabled) return false;
|
|
1405
|
+
const normalized = compositor.mergeReasoningProgress(payload.text, { snapshot: payload.isReasoningSnapshot === true }).replace(/^_(.*)_$/su, "$1").trim();
|
|
1406
|
+
if (!normalized) return false;
|
|
1407
|
+
const visible = await compositor.pushToolProgress({
|
|
1408
|
+
id: "reasoning",
|
|
1409
|
+
kind: "item",
|
|
1410
|
+
text: normalized,
|
|
1411
|
+
label: "Reasoning"
|
|
1412
|
+
});
|
|
1413
|
+
compositor.mergeReasoningProgress(normalized, { snapshot: true });
|
|
1414
|
+
return visible;
|
|
1415
|
+
}
|
|
1416
|
+
function withSlackReasoningCardsWindow(entry, unbounded) {
|
|
1417
|
+
const progress = entry.streaming?.progress;
|
|
1418
|
+
return {
|
|
1419
|
+
...entry,
|
|
1420
|
+
streaming: {
|
|
1421
|
+
...entry.streaming,
|
|
1422
|
+
progress: {
|
|
1423
|
+
...progress,
|
|
1424
|
+
get maxLines() {
|
|
1425
|
+
return unbounded() ? SLACK_REASONING_CARDS_WINDOW_LINES : progress?.maxLines;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Projects per-turn reasoning into compositor lines, sharing the paced update
|
|
1433
|
+
* loop, start gate and reconciler with tool rows. Quiet cards retain reasoning
|
|
1434
|
+
* below their summary row without enabling tool rows.
|
|
1435
|
+
*/
|
|
1436
|
+
function createSlackReasoningCardsRuntime(params) {
|
|
1437
|
+
const enabled = params.nativeCard;
|
|
1438
|
+
const now = params.now ?? Date.now;
|
|
1439
|
+
let state = createSlackReasoningCardState();
|
|
1440
|
+
let pushedKeys = /* @__PURE__ */ new Map();
|
|
1441
|
+
let startedAt;
|
|
1442
|
+
const cardKey = (line) => `${line.status ?? ""} ${line.text}`;
|
|
1443
|
+
let queuedLines = [];
|
|
1444
|
+
const holdsLine = (id) => params.compositor().getSnapshot().lines.some((line) => typeof line === "object" && line.id === id);
|
|
1445
|
+
const render = async () => {
|
|
1446
|
+
let visible = false;
|
|
1447
|
+
const plan = planSlackReasoningCards(state);
|
|
1448
|
+
queuedLines = [];
|
|
1449
|
+
for (const [index, line] of plan.entries()) {
|
|
1450
|
+
const key = cardKey(line);
|
|
1451
|
+
const pushed = pushedKeys.get(line.id);
|
|
1452
|
+
if (pushed === key) continue;
|
|
1453
|
+
if (pushed === void 0 && !params.admits(line)) {
|
|
1454
|
+
queuedLines = plan.slice(index).filter((later) => !pushedKeys.has(later.id));
|
|
1455
|
+
params.noteQueued();
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
pushedKeys.set(line.id, key);
|
|
1459
|
+
visible = await params.compositor().pushToolProgress(line, { reasoningLine: true }) || visible;
|
|
1460
|
+
if (pushed === void 0 && !holdsLine(line.id)) {
|
|
1461
|
+
pushedKeys.delete(line.id);
|
|
1462
|
+
queuedLines = plan.slice(index).filter((later) => !pushedKeys.has(later.id));
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return visible;
|
|
1467
|
+
};
|
|
1468
|
+
const seal = async () => {
|
|
1469
|
+
if (!enabled || !state.open) return false;
|
|
1470
|
+
sealSlackReasoningCards(state);
|
|
1471
|
+
params.compositor().resetReasoningProgress();
|
|
1472
|
+
return await render() === true;
|
|
1473
|
+
};
|
|
1474
|
+
return {
|
|
1475
|
+
enabled,
|
|
1476
|
+
compositorEntry: enabled ? withSlackReasoningCardsWindow(params.entry, () => params.toolRows || startedAt !== void 0) : params.entry,
|
|
1477
|
+
reset() {
|
|
1478
|
+
state = createSlackReasoningCardState();
|
|
1479
|
+
pushedKeys = /* @__PURE__ */ new Map();
|
|
1480
|
+
queuedLines = [];
|
|
1481
|
+
startedAt = void 0;
|
|
1482
|
+
},
|
|
1483
|
+
async push(payload) {
|
|
1484
|
+
const normalized = params.compositor().mergeReasoningProgress(payload.text, { snapshot: payload.isReasoningSnapshot === true });
|
|
1485
|
+
if (!normalized) return false;
|
|
1486
|
+
startedAt ??= now();
|
|
1487
|
+
state.open = normalized;
|
|
1488
|
+
return await render() === true;
|
|
1489
|
+
},
|
|
1490
|
+
seal,
|
|
1491
|
+
async noteToolCall() {
|
|
1492
|
+
if (!enabled) return false;
|
|
1493
|
+
state.toolCalls += 1;
|
|
1494
|
+
const visible = await seal();
|
|
1495
|
+
if (queuedLines.length > 0) await params.flushQueued();
|
|
1496
|
+
return visible;
|
|
1497
|
+
},
|
|
1498
|
+
/**
|
|
1499
|
+
* The message carrying cards up to `throughCard` is finished. Later text
|
|
1500
|
+
* of the same phase starts a new card on the next message; the merge
|
|
1501
|
+
* state is untouched so cumulative snapshots keep extending the phase.
|
|
1502
|
+
* Runs inside a stream send, so it must not push compositor lines.
|
|
1503
|
+
*/
|
|
1504
|
+
rollover(throughCard) {
|
|
1505
|
+
if (enabled) rolloverSlackReasoningCards(state, throughCard);
|
|
1506
|
+
},
|
|
1507
|
+
/** Cards the message being built refused for room. */
|
|
1508
|
+
pendingRows: () => queuedLines.length,
|
|
1509
|
+
/** Admits queued cards the message being built can take now. */
|
|
1510
|
+
release: async () => enabled ? await render() : false,
|
|
1511
|
+
/** The queued cards, in order, for a chain that must place them itself. */
|
|
1512
|
+
peekPendingLines: () => [...queuedLines],
|
|
1513
|
+
/** Cards the chain placed on a message without the compositor. */
|
|
1514
|
+
markPlaced(lineIds) {
|
|
1515
|
+
const placed = new Set(lineIds);
|
|
1516
|
+
for (const line of queuedLines) if (placed.has(line.id)) pushedKeys.set(line.id, cardKey(line));
|
|
1517
|
+
queuedLines = queuedLines.filter((line) => !placed.has(line.id));
|
|
1518
|
+
},
|
|
1519
|
+
/**
|
|
1520
|
+
* Completion headline for the think, once reasoning has streamed. The
|
|
1521
|
+
* quiet card keeps its own headline.
|
|
1522
|
+
*/
|
|
1523
|
+
summaryTitle() {
|
|
1524
|
+
return enabled && params.toolRows && startedAt !== void 0 ? formatReasoningSummaryTitle({
|
|
1525
|
+
elapsedMs: now() - startedAt,
|
|
1526
|
+
toolCalls: state.toolCalls
|
|
1527
|
+
}) : void 0;
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
// extensions/slack/src/monitor/message-handler/dispatch-progress-stream-order.ts
|
|
1532
|
+
/**
|
|
1533
|
+
* Ordering for native stream work. Each update's compute -> append -> commit
|
|
1534
|
+
* runs as one task, since delta state commits only after Slack accepts it.
|
|
1535
|
+
* A compositor publish can land while a task runs (a card
|
|
1536
|
+
* released from inside a send, an event during a Slack call); it must not
|
|
1537
|
+
* wait for the task it is part of, and a release from inside the pacing
|
|
1538
|
+
* loop's send must not wait for the startup flush that holds that send.
|
|
1539
|
+
*/
|
|
1540
|
+
function createSlackNativeStreamOrder() {
|
|
1541
|
+
let tail = Promise.resolve();
|
|
1542
|
+
let depth = 0;
|
|
1543
|
+
let flushesPending = 0;
|
|
1544
|
+
let flushesSettled = Promise.resolve();
|
|
1545
|
+
let settleFlushes;
|
|
1546
|
+
let loopSendInFlight = false;
|
|
1547
|
+
const run = (task) => {
|
|
1548
|
+
const ordered = async () => {
|
|
1549
|
+
depth += 1;
|
|
1550
|
+
try {
|
|
1551
|
+
return await task();
|
|
1552
|
+
} finally {
|
|
1553
|
+
depth -= 1;
|
|
1554
|
+
}
|
|
1555
|
+
};
|
|
1556
|
+
const next = tail.then(ordered, ordered);
|
|
1557
|
+
tail = next.catch(() => void 0);
|
|
1558
|
+
return next;
|
|
1559
|
+
};
|
|
1560
|
+
return {
|
|
1561
|
+
run,
|
|
1562
|
+
/** The pacing loop's send: a release inside it never waits on a flush. */
|
|
1563
|
+
runLoopSend: (task) => run(async () => {
|
|
1564
|
+
loopSendInFlight = true;
|
|
1565
|
+
try {
|
|
1566
|
+
return await task();
|
|
1567
|
+
} finally {
|
|
1568
|
+
loopSendInFlight = false;
|
|
1569
|
+
}
|
|
1570
|
+
}),
|
|
1571
|
+
get inTask() {
|
|
1572
|
+
return depth > 0;
|
|
1573
|
+
},
|
|
1574
|
+
async trackFlush(flush) {
|
|
1575
|
+
flushesPending += 1;
|
|
1576
|
+
if (flushesPending === 1) flushesSettled = new Promise((resolve) => {
|
|
1577
|
+
settleFlushes = resolve;
|
|
1578
|
+
});
|
|
1579
|
+
try {
|
|
1580
|
+
await flush();
|
|
1581
|
+
} finally {
|
|
1582
|
+
flushesPending -= 1;
|
|
1583
|
+
if (flushesPending === 0) {
|
|
1584
|
+
settleFlushes?.();
|
|
1585
|
+
settleFlushes = void 0;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
},
|
|
1589
|
+
/** False when a release must wait for the next paced send. */
|
|
1590
|
+
async waitForFlushes() {
|
|
1591
|
+
if (flushesPending > 0) {
|
|
1592
|
+
if (loopSendInFlight) return false;
|
|
1593
|
+
await flushesSettled;
|
|
1594
|
+
}
|
|
1595
|
+
return true;
|
|
1596
|
+
}
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
// extensions/slack/src/monitor/message-handler/dispatch-progress-stream-rows.ts
|
|
1600
|
+
function isSlackTurnScopedTaskId(id) {
|
|
1601
|
+
return isSlackPlanStepTaskId(id) || id.startsWith("openclaw");
|
|
1602
|
+
}
|
|
1603
|
+
function isSlackPlanStepTaskId(id) {
|
|
1604
|
+
return id.startsWith("plan_step_");
|
|
1605
|
+
}
|
|
1606
|
+
function isTaskUpdate(chunk) {
|
|
1607
|
+
return chunk.type === "task_update";
|
|
1608
|
+
}
|
|
1609
|
+
function resolveSlackPlanStepRendering(row) {
|
|
1610
|
+
return JSON.stringify([
|
|
1611
|
+
row.title,
|
|
1612
|
+
row.status,
|
|
1613
|
+
row.details ?? "",
|
|
1614
|
+
row.output ?? ""
|
|
1615
|
+
]);
|
|
1616
|
+
}
|
|
1617
|
+
/** A plan step no message has shown in its current state (never shown, or changed since). */
|
|
1618
|
+
function isSlackPlanStepUnshown(row, shown) {
|
|
1619
|
+
return shown.get(row.id) !== resolveSlackPlanStepRendering(row);
|
|
1620
|
+
}
|
|
1621
|
+
function buildSlackPlanRows(plan) {
|
|
1622
|
+
return (buildSlackProgressStreamChunks({
|
|
1623
|
+
lines: [],
|
|
1624
|
+
...plan
|
|
1625
|
+
}) ?? []).filter((chunk) => isTaskUpdate(chunk) && isSlackPlanStepTaskId(chunk.id));
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Order in which plan rows take the slots a message has left for them:
|
|
1629
|
+
* running steps, then steps not started, then completed ones, and within
|
|
1630
|
+
* each group steps no message has shown yet before steps whose status
|
|
1631
|
+
* changed since a message showed them, in step order. A step a message
|
|
1632
|
+
* already shows in its current state is not repeated.
|
|
1633
|
+
*/
|
|
1634
|
+
function prioritizeSlackPlanRows(rows, shown) {
|
|
1635
|
+
const rank = (row) => row.status === "in_progress" ? 0 : row.status === "complete" ? 2 : 1;
|
|
1636
|
+
return rows.map((row, index) => ({
|
|
1637
|
+
row,
|
|
1638
|
+
index
|
|
1639
|
+
})).filter((entry) => isSlackPlanStepUnshown(entry.row, shown)).toSorted((left, right) => rank(left.row) - rank(right.row) || Number(shown.has(left.row.id)) - Number(shown.has(right.row.id)) || left.index - right.index).map((entry) => entry.row);
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Fits the opening of a continuation under a fresh message's budget with
|
|
1643
|
+
* capacity for pending work first: the text (or room for it), the rows
|
|
1644
|
+
* that must carry, the pending cards the runtime will release next, and
|
|
1645
|
+
* only then plan rows in priority order. Plan rows that do not fit wait
|
|
1646
|
+
* for the next continuation, which the chain opens for them (see
|
|
1647
|
+
* `countUnshownPlanSteps`); they are not deferred work.
|
|
1648
|
+
*/
|
|
1649
|
+
function budgetSlackContinuationOpening(open) {
|
|
1650
|
+
const planRows = [];
|
|
1651
|
+
const otherRows = [];
|
|
1652
|
+
const rest = [];
|
|
1653
|
+
for (const chunk of open.chunks) if (!isTaskUpdate(chunk)) rest.push(chunk);
|
|
1654
|
+
else if (isSlackPlanStepTaskId(chunk.id)) planRows.push(chunk);
|
|
1655
|
+
else otherRows.push(chunk);
|
|
1656
|
+
const present = new Set(open.chunks.flatMap((chunk) => isTaskUpdate(chunk) ? [chunk.id] : []));
|
|
1657
|
+
const reserved = open.reserveFor.filter((chunk) => isTaskUpdate(chunk) && !present.has(chunk.id));
|
|
1658
|
+
const fresh = new SlackStreamMessageLedger(open.taskLimit);
|
|
1659
|
+
fresh.recordText(open.text);
|
|
1660
|
+
const workFit = planSlackStreamUpdateFit(fresh, { chunks: [
|
|
1661
|
+
...rest,
|
|
1662
|
+
...otherRows,
|
|
1663
|
+
...reserved
|
|
1664
|
+
] });
|
|
1665
|
+
const fit = planSlackStreamUpdateFit(fresh, { chunks: [
|
|
1666
|
+
...rest,
|
|
1667
|
+
...otherRows.filter((row) => workFit.admittedTaskIds.has(row.id)),
|
|
1668
|
+
...reserved.filter((row) => workFit.admittedTaskIds.has(row.id)),
|
|
1669
|
+
...prioritizeSlackPlanRows(planRows, open.shownPlanSteps)
|
|
1670
|
+
] });
|
|
1671
|
+
const admittedPlan = planRows.filter((row) => fit.admittedTaskIds.has(row.id));
|
|
1672
|
+
return {
|
|
1673
|
+
chunks: [
|
|
1674
|
+
...rest,
|
|
1675
|
+
...admittedPlan,
|
|
1676
|
+
...otherRows.filter((row) => workFit.admittedTaskIds.has(row.id))
|
|
1677
|
+
],
|
|
1678
|
+
planStepIds: new Set(admittedPlan.map((row) => row.id)),
|
|
1679
|
+
deferred: otherRows.some((row) => workFit.deferredTaskIds.has(row.id))
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Closeout of a message that rolls: the "continued below" title and every
|
|
1684
|
+
* row it holds or takes with the closeout, running ones painted complete
|
|
1685
|
+
* (closing the message does not finish their tools; the chain carries them).
|
|
1686
|
+
*/
|
|
1687
|
+
function planSlackRolloverCloseout(roll) {
|
|
1688
|
+
const kept = [{
|
|
1689
|
+
type: "plan_update",
|
|
1690
|
+
title: roll.title
|
|
1691
|
+
}];
|
|
1692
|
+
for (const chunk of roll.full ?? []) if (chunk.type === "task_update" && (roll.previous.tasks.has(chunk.id) || roll.admittedTaskIds?.has(chunk.id))) kept.push(chunk.status === "in_progress" ? {
|
|
1693
|
+
...chunk,
|
|
1694
|
+
status: "complete"
|
|
1695
|
+
} : chunk);
|
|
1696
|
+
return reconcileSlackNativeTaskChunks({
|
|
1697
|
+
previous: roll.previous,
|
|
1698
|
+
finalStatus: "complete",
|
|
1699
|
+
chunks: kept
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Reason a message rolled, for the roll log: a budget roll with every row
|
|
1704
|
+
* slot taken (rows on the message plus rows admitted with its closeout) is a
|
|
1705
|
+
* roll on rows.
|
|
1706
|
+
*/
|
|
1707
|
+
function resolveSlackRollReason(roll, ledger) {
|
|
1708
|
+
const unrecorded = [...roll.admittedTaskIds ?? []].filter((id) => !ledger.hasTask(id)).length;
|
|
1709
|
+
return roll.reason === "budget" && ledger.taskCount + unrecorded >= ledger.taskLimit ? "rows" : roll.reason;
|
|
1710
|
+
}
|
|
1711
|
+
/** Rendered state of a task row: what a later result would change. */
|
|
1712
|
+
function resolveSlackFrozenRowState(chunk) {
|
|
1713
|
+
return chunk.type === "task_update" ? JSON.stringify([
|
|
1714
|
+
chunk.title,
|
|
1715
|
+
chunk.status,
|
|
1716
|
+
chunk.details ?? "",
|
|
1717
|
+
chunk.output ?? ""
|
|
1718
|
+
]) : void 0;
|
|
1719
|
+
}
|
|
1720
|
+
/** Frozen rows whose rendered state moved on: they carry a result and may render again. */
|
|
1721
|
+
function resolveThawedSlackRows(params) {
|
|
1722
|
+
const frozenLines = params.lines.filter((line) => {
|
|
1723
|
+
const id = resolveSlackNativeLineTaskId(line);
|
|
1724
|
+
return id !== void 0 && params.frozenRows.has(id);
|
|
1725
|
+
});
|
|
1726
|
+
if (frozenLines.length === 0) return [];
|
|
1727
|
+
const thawed = [];
|
|
1728
|
+
for (const chunk of buildSlackProgressStreamChunks({
|
|
1729
|
+
lines: frozenLines,
|
|
1730
|
+
maxLineChars: params.maxLineChars,
|
|
1731
|
+
summaryRow: params.summaryRow
|
|
1732
|
+
}) ?? []) {
|
|
1733
|
+
if (chunk.type !== "task_update") continue;
|
|
1734
|
+
const frozen = params.frozenRows.get(chunk.id);
|
|
1735
|
+
if (frozen !== void 0 && frozen !== resolveSlackFrozenRowState(chunk)) thawed.push(chunk.id);
|
|
1736
|
+
}
|
|
1737
|
+
return thawed;
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Authored plan steps across one turn's chain of messages. The first message
|
|
1741
|
+
* shows the whole plan; a continuation shows the plan rows chosen when it
|
|
1742
|
+
* opened. A step a message already shows in its current state is not
|
|
1743
|
+
* repeated, and no step is dropped: while a step left out of the current
|
|
1744
|
+
* continuation has not been on a message as it stands, the chain owes it
|
|
1745
|
+
* another continuation.
|
|
1746
|
+
*/
|
|
1747
|
+
var SlackChainPlanSteps = class {
|
|
1748
|
+
constructor() {
|
|
1749
|
+
this.shown = /* @__PURE__ */ new Map();
|
|
1750
|
+
}
|
|
1751
|
+
/** Whether a task row may go on the current message. */
|
|
1752
|
+
admits(id) {
|
|
1753
|
+
return !this.onMessage || !isSlackPlanStepTaskId(id) || this.onMessage.has(id);
|
|
1754
|
+
}
|
|
1755
|
+
/** Records the plan rows a finished message holds. */
|
|
1756
|
+
retire(tasks) {
|
|
1757
|
+
for (const [id, task] of tasks) if (isSlackPlanStepTaskId(id)) this.shown.set(id, resolveSlackPlanStepRendering({
|
|
1758
|
+
title: task.title,
|
|
1759
|
+
status: task.status,
|
|
1760
|
+
details: task.details?.source,
|
|
1761
|
+
output: task.output?.source
|
|
1762
|
+
}));
|
|
1763
|
+
}
|
|
1764
|
+
/** Plan steps the chain still owes a message; zero on the first message. */
|
|
1765
|
+
countOwed(source) {
|
|
1766
|
+
const onMessage = this.onMessage;
|
|
1767
|
+
return onMessage ? buildSlackPlanRows(source).filter((row) => !onMessage.has(row.id) && isSlackPlanStepUnshown(row, this.shown)).length : 0;
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Lets plan rows the continuation left out onto it, in priority order as
|
|
1771
|
+
* far as they fit beside what it holds, the text to come and the queued
|
|
1772
|
+
* cards it must still take: a step whose status or title changed since a
|
|
1773
|
+
* message showed it then lands here instead of being skipped or opening
|
|
1774
|
+
* another continuation, and the last message shows those changes too.
|
|
1775
|
+
*/
|
|
1776
|
+
admitUnshown(source) {
|
|
1777
|
+
const onMessage = this.onMessage;
|
|
1778
|
+
const candidates = onMessage ? buildSlackPlanRows(source).filter((row) => !onMessage.has(row.id)) : [];
|
|
1779
|
+
if (!onMessage || candidates.length === 0) return;
|
|
1780
|
+
const plan = prioritizeSlackPlanRows(candidates, this.shown);
|
|
1781
|
+
if (plan.length === 0) return;
|
|
1782
|
+
const fit = planSlackStreamUpdateFit(source.ledger, {
|
|
1783
|
+
...source.reserveText ? { text: source.reserveText } : {},
|
|
1784
|
+
chunks: [...source.reserveFor ?? [], ...plan]
|
|
1785
|
+
});
|
|
1786
|
+
for (const row of plan) if (fit.admittedTaskIds.has(row.id)) onMessage.add(row.id);
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
/**
|
|
1790
|
+
* What a finished message keeps. Rows Slack acknowledged are retired, and
|
|
1791
|
+
* the reasoning cards through the newest one among them are sealed. Rows
|
|
1792
|
+
* still running when the message closed stay with the chain (closing a
|
|
1793
|
+
* message does not finish its tools; the newest reasoning card is not one
|
|
1794
|
+
* of them, its cut is final) unless the message overflowed with rows it
|
|
1795
|
+
* could not take: then they are frozen with their rendered state, retired
|
|
1796
|
+
* like delivered rows so continuations do not fill up with them again, and
|
|
1797
|
+
* thaw when a result changes that state. When the closeout was rejected,
|
|
1798
|
+
* every row it would have changed (a card extended since it was sent, a
|
|
1799
|
+
* tool row with new details, output or a terminal status) also stays, as
|
|
1800
|
+
* the reconciler decides field by field against what Slack holds.
|
|
1801
|
+
*/
|
|
1802
|
+
function planSlackMessageRetirement(retire) {
|
|
1803
|
+
const onMessage = retire.chunksRejected ? retire.previous : retire.finished;
|
|
1804
|
+
const overflowing = (retire.full ?? []).some((chunk) => chunk.type === "task_update" && !isSlackTurnScopedTaskId(chunk.id) && !onMessage.tasks.has(chunk.id));
|
|
1805
|
+
const carried = /* @__PURE__ */ new Set();
|
|
1806
|
+
const frozenRows = /* @__PURE__ */ new Map();
|
|
1807
|
+
const intended = [];
|
|
1808
|
+
const intendedIds = /* @__PURE__ */ new Set();
|
|
1809
|
+
for (const chunk of retire.full ?? []) {
|
|
1810
|
+
if (chunk.type !== "task_update") continue;
|
|
1811
|
+
if (chunk.status === "in_progress" && resolveSlackReasoningTaskIndex(chunk.id) === void 0) {
|
|
1812
|
+
if (!overflowing) carried.add(chunk.id);
|
|
1813
|
+
else if (onMessage.tasks.has(chunk.id)) frozenRows.set(chunk.id, resolveSlackFrozenRowState(chunk) ?? "");
|
|
1814
|
+
}
|
|
1815
|
+
if (retire.chunksRejected && retire.previous.tasks.has(chunk.id)) {
|
|
1816
|
+
intended.push(chunk);
|
|
1817
|
+
intendedIds.add(chunk.id);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
if (retire.chunksRejected) {
|
|
1821
|
+
const changes = reconcileSlackNativeTaskChunks({
|
|
1822
|
+
previous: retire.previous,
|
|
1823
|
+
chunks: intended
|
|
1824
|
+
});
|
|
1825
|
+
for (const chunk of changes.chunks ?? []) if (chunk.type === "task_update" && intendedIds.has(chunk.id)) carried.add(chunk.id);
|
|
1826
|
+
}
|
|
1827
|
+
const retiredTaskIds = [];
|
|
1828
|
+
let rolledThroughCard = 0;
|
|
1829
|
+
for (const id of onMessage.tasks.keys()) {
|
|
1830
|
+
if (isSlackTurnScopedTaskId(id) || carried.has(id)) continue;
|
|
1831
|
+
retiredTaskIds.push(id);
|
|
1832
|
+
const card = resolveSlackReasoningTaskIndex(id);
|
|
1833
|
+
if (card !== void 0) rolledThroughCard = Math.max(rolledThroughCard, card);
|
|
1834
|
+
}
|
|
1835
|
+
return {
|
|
1836
|
+
retiredTaskIds,
|
|
1837
|
+
frozenRows,
|
|
1838
|
+
rolledThroughCard
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Plans the opening of a message of the chain under a fresh message's
|
|
1843
|
+
* budget. Text first: a fresh message always takes it, and rows are admitted
|
|
1844
|
+
* only beside it (the planner's one-row allowance for an empty message must
|
|
1845
|
+
* not put a row next to text that already fills the message). A
|
|
1846
|
+
* continuation holds room for pending work before plan rows (see
|
|
1847
|
+
* budgetSlackContinuationOpening); the first message shows the whole plan.
|
|
1848
|
+
*/
|
|
1849
|
+
function planSlackMessageOpening(open) {
|
|
1850
|
+
const text = open.text ?? open.reserveText;
|
|
1851
|
+
const budgeted = open.continuation ? budgetSlackContinuationOpening({
|
|
1852
|
+
chunks: open.chunks ?? [],
|
|
1853
|
+
reserveFor: open.reserveFor ?? [],
|
|
1854
|
+
...text ? { text } : {},
|
|
1855
|
+
shownPlanSteps: open.shownPlanSteps,
|
|
1856
|
+
taskLimit: open.taskLimit
|
|
1857
|
+
}) : void 0;
|
|
1858
|
+
const chunks = budgeted?.chunks ?? open.chunks;
|
|
1859
|
+
const fresh = new SlackStreamMessageLedger(open.taskLimit);
|
|
1860
|
+
fresh.recordText(text);
|
|
1861
|
+
const fit = planSlackStreamUpdateFit(fresh, { chunks });
|
|
1862
|
+
const opening = reconcileSlackNativeTaskChunks({
|
|
1863
|
+
previous: EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT,
|
|
1864
|
+
finalStatus: open.finalStatus,
|
|
1865
|
+
chunks: chunks?.filter((chunk) => chunk.type !== "task_update" || fit.admittedTaskIds.has(chunk.id))
|
|
1866
|
+
});
|
|
1867
|
+
const textSent = Boolean(open.text);
|
|
1868
|
+
const sent = opening.chunks?.length ? opening.chunks : textSent ? void 0 : [{
|
|
1869
|
+
type: "plan_update",
|
|
1870
|
+
title: SLACK_REASONING_CONTINUED_TITLE
|
|
1871
|
+
}];
|
|
1872
|
+
return {
|
|
1873
|
+
update: {
|
|
1874
|
+
...textSent && open.text ? { text: open.text } : {},
|
|
1875
|
+
chunks: sent ?? []
|
|
1876
|
+
},
|
|
1877
|
+
snapshot: opening.chunks?.length ? opening.snapshot : {
|
|
1878
|
+
planTitle: SLACK_REASONING_CONTINUED_TITLE,
|
|
1879
|
+
tasks: /* @__PURE__ */ new Map()
|
|
1880
|
+
},
|
|
1881
|
+
textSent,
|
|
1882
|
+
admittedTaskIds: fit.admittedTaskIds,
|
|
1883
|
+
deferred: budgeted ? budgeted.deferred : fit.deferredTaskIds.size > 0,
|
|
1884
|
+
planStepIds: budgeted?.planStepIds
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
// extensions/slack/src/monitor/message-handler/dispatch-progress-stream.ts
|
|
1888
|
+
const SLACK_STREAM_ROLLOVER_BASE_ROUNDS = 4;
|
|
1889
|
+
const SLACK_STREAM_DRAIN_PASSES = 3;
|
|
1890
|
+
/**
|
|
1891
|
+
* Owns the current message's task/narration snapshot and continuation chain.
|
|
1892
|
+
* Rollover reuses interruption sealing: close the message, retain its thread,
|
|
1893
|
+
* and reconcile the continuation against a fresh message snapshot.
|
|
1894
|
+
*/
|
|
1895
|
+
function createSlackNativeProgressStream(params) {
|
|
1896
|
+
const { delivery, transport, replyPlan, runtime } = params;
|
|
1897
|
+
let snapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
1898
|
+
let snapshotSession = delivery.streamSession;
|
|
1899
|
+
let narration = {
|
|
1900
|
+
rendered: "",
|
|
1901
|
+
source: ""
|
|
1902
|
+
};
|
|
1903
|
+
let completionSent = false;
|
|
1904
|
+
let rolledTaskIds = /* @__PURE__ */ new Set();
|
|
1905
|
+
let frozenRows = /* @__PURE__ */ new Map();
|
|
1906
|
+
let planSteps = new SlackChainPlanSteps();
|
|
1907
|
+
let rolledMessages = 0;
|
|
1908
|
+
const resolveNarrationUpdate = (incoming) => {
|
|
1909
|
+
const next = applyAppendOnlyStreamUpdate({
|
|
1910
|
+
incoming: incoming ?? "",
|
|
1911
|
+
...narration
|
|
1912
|
+
});
|
|
1913
|
+
return {
|
|
1914
|
+
next,
|
|
1915
|
+
delta: next.changed ? next.rendered.slice(narration.rendered.length) : ""
|
|
1916
|
+
};
|
|
1917
|
+
};
|
|
1918
|
+
const commitNarration = (next) => {
|
|
1919
|
+
if (next.changed) narration = next;
|
|
1920
|
+
};
|
|
1921
|
+
const resolveCurrentMessageLines = (draft) => {
|
|
1922
|
+
const lines = resolveNativeProgressLines(draft);
|
|
1923
|
+
if (frozenRows.size > 0) for (const id of resolveThawedSlackRows({
|
|
1924
|
+
lines,
|
|
1925
|
+
frozenRows,
|
|
1926
|
+
maxLineChars: params.maxLineChars,
|
|
1927
|
+
summaryRow: params.summaryRow
|
|
1928
|
+
})) {
|
|
1929
|
+
frozenRows.delete(id);
|
|
1930
|
+
rolledTaskIds.delete(id);
|
|
1931
|
+
}
|
|
1932
|
+
if (rolledTaskIds.size === 0) return lines;
|
|
1933
|
+
return lines.filter((line) => {
|
|
1934
|
+
const id = resolveSlackNativeLineTaskId(line);
|
|
1935
|
+
return !id || !rolledTaskIds.has(id);
|
|
1936
|
+
});
|
|
1937
|
+
};
|
|
1938
|
+
const buildCurrentMessageChunks = (build) => {
|
|
1939
|
+
const { draft } = build;
|
|
1940
|
+
const chunks = buildSlackProgressStreamChunks({
|
|
1941
|
+
title: params.resolveTitle(draft, build.completed),
|
|
1942
|
+
lines: resolveCurrentMessageLines(draft),
|
|
1943
|
+
plan: draft.plan,
|
|
1944
|
+
maxLineChars: params.maxLineChars,
|
|
1945
|
+
summaryRow: params.summaryRow,
|
|
1946
|
+
...build.finalInProgressStatus ? {
|
|
1947
|
+
finalInProgressStatus: build.finalInProgressStatus,
|
|
1948
|
+
diffStat: draft.diffStat,
|
|
1949
|
+
sessionLinks: params.resolveSessionLinks()
|
|
1950
|
+
} : {},
|
|
1951
|
+
...rolledMessages > 0 ? { fallbackTitle: SLACK_REASONING_CONTINUED_TITLE } : {}
|
|
1952
|
+
});
|
|
1953
|
+
if (rolledTaskIds.size === 0 && !planSteps.onMessage) return chunks;
|
|
1954
|
+
return chunks?.filter((chunk) => chunk.type !== "task_update" || !rolledTaskIds.has(chunk.id) && planSteps.admits(chunk.id));
|
|
1955
|
+
};
|
|
1956
|
+
/** Chunks for the queued cards, so an opening can hold room for them. */
|
|
1957
|
+
const pendingCardChunks = () => {
|
|
1958
|
+
const lines = params.peekPendingLines();
|
|
1959
|
+
return lines.length === 0 ? [] : buildSlackProgressStreamChunks({
|
|
1960
|
+
lines,
|
|
1961
|
+
maxLineChars: params.maxLineChars,
|
|
1962
|
+
summaryRow: params.summaryRow
|
|
1963
|
+
}) ?? [];
|
|
1964
|
+
};
|
|
1965
|
+
/** Lets changed plan rows the continuation left out onto it, as far as they fit. */
|
|
1966
|
+
const admitUnshownPlanRows = (reserveText, reserveFor) => {
|
|
1967
|
+
if (delivery.streamSession) planSteps.admitUnshown({
|
|
1968
|
+
plan: params.getSnapshot().plan,
|
|
1969
|
+
ledger: delivery.streamLedger,
|
|
1970
|
+
...reserveText ? { reserveText } : {},
|
|
1971
|
+
...reserveFor?.length ? { reserveFor } : {},
|
|
1972
|
+
maxLineChars: params.maxLineChars,
|
|
1973
|
+
summaryRow: params.summaryRow
|
|
1974
|
+
});
|
|
1975
|
+
};
|
|
1976
|
+
const buildRunningChunks = (draft) => buildCurrentMessageChunks({ draft });
|
|
1977
|
+
/** Queued cards plus plan steps the chain still owes a message. */
|
|
1978
|
+
const countOwedRows = () => params.pendingRows() + (params.rollover && delivery.streamSession ? planSteps.countOwed({
|
|
1979
|
+
plan: params.getSnapshot().plan,
|
|
1980
|
+
maxLineChars: params.maxLineChars,
|
|
1981
|
+
summaryRow: params.summaryRow
|
|
1982
|
+
}) : 0);
|
|
1983
|
+
const buildCompletionChunks = (finalInProgressStatus) => {
|
|
1984
|
+
const draft = params.getSnapshot();
|
|
1985
|
+
const lines = resolveCurrentMessageLines(draft);
|
|
1986
|
+
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(draft));
|
|
1987
|
+
const hasRetirableNativeTasks = [...snapshot.tasks.values()].some((task) => task.status !== "complete" && task.status !== "error");
|
|
1988
|
+
if (lines.length === 0 && !draft.plan?.length && !hasRetirableNativeTasks && !draft.diffStat && !narrationUpdate.delta && params.resolveSessionLinks().length === 0) return;
|
|
1989
|
+
const completion = reconcileSlackNativeTaskChunks({
|
|
1990
|
+
previous: snapshot,
|
|
1991
|
+
finalStatus: finalInProgressStatus,
|
|
1992
|
+
chunks: buildCurrentMessageChunks({
|
|
1993
|
+
draft,
|
|
1994
|
+
completed: true,
|
|
1995
|
+
finalInProgressStatus
|
|
1996
|
+
})
|
|
1997
|
+
}).chunks;
|
|
1998
|
+
return narrationUpdate.delta ? [{
|
|
1999
|
+
type: "markdown_text",
|
|
2000
|
+
text: narrationUpdate.delta
|
|
2001
|
+
}, ...completion ?? []] : completion;
|
|
2002
|
+
};
|
|
2003
|
+
const reportFailure = (err) => {
|
|
2004
|
+
runtime.error?.(danger(`slack-stream: native progress stream failed: ${formatSlackError(err)}, falling back`));
|
|
2005
|
+
delivery.streamFailed = true;
|
|
2006
|
+
};
|
|
2007
|
+
const forgetCurrentMessage = () => {
|
|
2008
|
+
rolledMessages += 1;
|
|
2009
|
+
snapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
2010
|
+
planSteps.onMessage = void 0;
|
|
2011
|
+
};
|
|
2012
|
+
/** Records what a finished message keeps (see planSlackMessageRetirement), then forgets it. */
|
|
2013
|
+
const retireMessage = (retire) => {
|
|
2014
|
+
const plan = planSlackMessageRetirement(retire);
|
|
2015
|
+
for (const id of plan.retiredTaskIds) rolledTaskIds.add(id);
|
|
2016
|
+
planSteps.retire((retire.chunksRejected ? retire.previous : retire.finished).tasks);
|
|
2017
|
+
for (const [id, state] of plan.frozenRows) frozenRows.set(id, state);
|
|
2018
|
+
params.onRolled(plan.rolledThroughCard);
|
|
2019
|
+
forgetCurrentMessage();
|
|
2020
|
+
};
|
|
2021
|
+
/**
|
|
2022
|
+
* The one place a continuation (or a turn's first message) is started.
|
|
2023
|
+
* Fits the opening under a fresh message's budget: the text (or, for
|
|
2024
|
+
* `reserveText`, room for text the caller appends right after), then rows in
|
|
2025
|
+
* order until the budget; rows that do not fit stay where they are for the
|
|
2026
|
+
* next round. Records only what Slack accepted.
|
|
2027
|
+
*/
|
|
2028
|
+
const openMessage = async (open) => {
|
|
2029
|
+
const planned = planSlackMessageOpening({
|
|
2030
|
+
...open,
|
|
2031
|
+
continuation: rolledMessages > 0,
|
|
2032
|
+
shownPlanSteps: planSteps.shown,
|
|
2033
|
+
taskLimit: delivery.streamRowLimit
|
|
2034
|
+
});
|
|
2035
|
+
const retainedThreadTs = delivery.interruptedThreadTs;
|
|
2036
|
+
const refused = {
|
|
2037
|
+
accepted: false,
|
|
2038
|
+
textSent: false,
|
|
2039
|
+
admittedTaskIds: /* @__PURE__ */ new Set(),
|
|
2040
|
+
deferred: false
|
|
2041
|
+
};
|
|
2042
|
+
try {
|
|
2043
|
+
if (!await transport.start(planned.update, retainedThreadTs)) return refused;
|
|
2044
|
+
} catch (err) {
|
|
2045
|
+
reportFailure(err);
|
|
2046
|
+
return refused;
|
|
2047
|
+
}
|
|
2048
|
+
if (!retainedThreadTs) replyPlan.markSent();
|
|
2049
|
+
snapshot = planned.snapshot;
|
|
2050
|
+
snapshotSession = delivery.streamSession;
|
|
2051
|
+
planSteps.onMessage = planned.planStepIds;
|
|
2052
|
+
return {
|
|
2053
|
+
accepted: true,
|
|
2054
|
+
textSent: planned.textSent,
|
|
2055
|
+
admittedTaskIds: planned.admittedTaskIds,
|
|
2056
|
+
deferred: planned.deferred
|
|
2057
|
+
};
|
|
2058
|
+
};
|
|
2059
|
+
/**
|
|
2060
|
+
* Finishes the current stream message as one that continues below: the
|
|
2061
|
+
* rows it holds plus the admitted new rows, every running row marked
|
|
2062
|
+
* complete, the rolled plan title, optional narration text. Not rolled
|
|
2063
|
+
* when the stop failed (delivery then leaves streaming) or Slack's Stop
|
|
2064
|
+
* cancelled the turn (nothing more is written).
|
|
2065
|
+
*/
|
|
2066
|
+
const rollMessage = async (roll) => {
|
|
2067
|
+
if (!delivery.streamSession) return { rolled: false };
|
|
2068
|
+
const finish = planSlackRolloverCloseout({
|
|
2069
|
+
...roll,
|
|
2070
|
+
title: params.explicitTitle ?? "Thinking, continued below"
|
|
2071
|
+
});
|
|
2072
|
+
const finishChunks = [...roll.text ? [{
|
|
2073
|
+
type: "markdown_text",
|
|
2074
|
+
text: roll.text
|
|
2075
|
+
}] : [], ...finish.chunks ?? []];
|
|
2076
|
+
const { size, taskCount } = delivery.streamLedger;
|
|
2077
|
+
const sealed = await delivery.sealStream(finishChunks);
|
|
2078
|
+
if (!sealed || delivery.streamFailed) return { rolled: false };
|
|
2079
|
+
retireMessage({
|
|
2080
|
+
previous: roll.previous,
|
|
2081
|
+
full: roll.full,
|
|
2082
|
+
finished: finish.snapshot,
|
|
2083
|
+
chunksRejected: sealed.chunksRejected
|
|
2084
|
+
});
|
|
2085
|
+
logVerbose(`slack-stream: native progress message ${rolledMessages} rolled (${resolveSlackRollReason(roll, delivery.streamLedger)}; ${size} size units, ${taskCount} rows${sealed.chunksRejected ? "; closeout rejected, carried over" : ""}); continuing in a new message`);
|
|
2086
|
+
return {
|
|
2087
|
+
rolled: true,
|
|
2088
|
+
closeoutDelivered: !sealed.chunksRejected
|
|
2089
|
+
};
|
|
2090
|
+
};
|
|
2091
|
+
/**
|
|
2092
|
+
* Sends the latest draft and queued cards, rolling on size, rows or age.
|
|
2093
|
+
* A msg_too_long rejection gets one rollover retry. Settled means every
|
|
2094
|
+
* draft row has reached a message and no card remains queued.
|
|
2095
|
+
*/
|
|
2096
|
+
const send = async () => {
|
|
2097
|
+
let sent = false;
|
|
2098
|
+
let tooLongRetried = false;
|
|
2099
|
+
const unsentRows = params.rollover ? (buildRunningChunks(params.getSnapshot()) ?? []).filter((chunk) => chunk.type === "task_update" && !snapshot.tasks.has(chunk.id)).length : 0;
|
|
2100
|
+
const maxRounds = SLACK_STREAM_ROLLOVER_BASE_ROUNDS + 2 * (countOwedRows() + unsentRows);
|
|
2101
|
+
for (let round = 0; round < maxRounds; round += 1) {
|
|
2102
|
+
if (delivery.streamSession?.stoppedBySlack) return {
|
|
2103
|
+
sent,
|
|
2104
|
+
settled: true
|
|
2105
|
+
};
|
|
2106
|
+
await delivery.rotateInterruptedStream();
|
|
2107
|
+
if (snapshotSession !== delivery.streamSession) snapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
2108
|
+
const released = params.rollover ? await params.releasePending() : false;
|
|
2109
|
+
const draft = params.getSnapshot();
|
|
2110
|
+
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(draft));
|
|
2111
|
+
let text = narrationUpdate.delta;
|
|
2112
|
+
if (text) delivery.pendingTextIsProgress = true;
|
|
2113
|
+
const commitText = () => {
|
|
2114
|
+
commitNarration(narrationUpdate.next);
|
|
2115
|
+
text = "";
|
|
2116
|
+
};
|
|
2117
|
+
const hadSession = Boolean(delivery.streamSession);
|
|
2118
|
+
if (params.rollover) admitUnshownPlanRows(text, pendingCardChunks());
|
|
2119
|
+
const previous = snapshot;
|
|
2120
|
+
const full = buildRunningChunks(draft);
|
|
2121
|
+
const reconciled = reconcileSlackNativeTaskChunks({
|
|
2122
|
+
previous,
|
|
2123
|
+
chunks: full
|
|
2124
|
+
});
|
|
2125
|
+
const chunks = reconciled.chunks;
|
|
2126
|
+
const pending = params.rollover ? params.pendingRows() : 0;
|
|
2127
|
+
if (!chunks?.length && !text) {
|
|
2128
|
+
const owed = params.rollover ? countOwedRows() : 0;
|
|
2129
|
+
if (!hadSession || owed === pending && (pending === 0 || released === void 0)) return {
|
|
2130
|
+
sent,
|
|
2131
|
+
settled: owed === 0
|
|
2132
|
+
};
|
|
2133
|
+
if (!(await rollMessage({
|
|
2134
|
+
previous,
|
|
2135
|
+
full,
|
|
2136
|
+
reason: "budget"
|
|
2137
|
+
})).rolled) return {
|
|
2138
|
+
sent,
|
|
2139
|
+
settled: false
|
|
2140
|
+
};
|
|
2141
|
+
sent = true;
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
if (params.rollover && !hadSession) {
|
|
2145
|
+
const opened = await openMessage({
|
|
2146
|
+
chunks: full,
|
|
2147
|
+
...text ? { text } : {},
|
|
2148
|
+
reserveFor: pendingCardChunks()
|
|
2149
|
+
});
|
|
2150
|
+
if (!opened.accepted) return {
|
|
2151
|
+
sent,
|
|
2152
|
+
settled: false
|
|
2153
|
+
};
|
|
2154
|
+
if (opened.textSent) commitText();
|
|
2155
|
+
sent = true;
|
|
2156
|
+
if (countOwedRows() === 0 && !opened.deferred) return {
|
|
2157
|
+
sent: true,
|
|
2158
|
+
settled: true
|
|
2159
|
+
};
|
|
2160
|
+
continue;
|
|
2161
|
+
}
|
|
2162
|
+
if (params.rollover && delivery.streamLedger.expiring) {
|
|
2163
|
+
if (!(await rollMessage({
|
|
2164
|
+
previous,
|
|
2165
|
+
full,
|
|
2166
|
+
reason: "age"
|
|
2167
|
+
})).rolled) return {
|
|
2168
|
+
sent,
|
|
2169
|
+
settled: false
|
|
2170
|
+
};
|
|
2171
|
+
sent = true;
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
const update = {
|
|
2175
|
+
...text ? { text } : {},
|
|
2176
|
+
...chunks?.length ? { chunks } : {}
|
|
2177
|
+
};
|
|
2178
|
+
const fit = params.rollover ? planSlackStreamUpdateFit(delivery.streamLedger, update) : void 0;
|
|
2179
|
+
if (fit && !fit.fits) {
|
|
2180
|
+
const roll = await rollMessage({
|
|
2181
|
+
previous,
|
|
2182
|
+
full,
|
|
2183
|
+
admittedTaskIds: fit.admittedTaskIds,
|
|
2184
|
+
...fit.textFits && text ? { text } : {},
|
|
2185
|
+
reason: "budget"
|
|
2186
|
+
});
|
|
2187
|
+
if (!roll.rolled) return {
|
|
2188
|
+
sent,
|
|
2189
|
+
settled: false
|
|
2190
|
+
};
|
|
2191
|
+
if (fit.textFits && roll.closeoutDelivered) commitText();
|
|
2192
|
+
sent = true;
|
|
2193
|
+
continue;
|
|
2194
|
+
}
|
|
2195
|
+
try {
|
|
2196
|
+
const retainedThreadTs = delivery.interruptedThreadTs;
|
|
2197
|
+
const accepted = hadSession ? await transport.append(update) : await transport.start(update, retainedThreadTs);
|
|
2198
|
+
if (accepted === "rotated") continue;
|
|
2199
|
+
if (!accepted) return {
|
|
2200
|
+
sent,
|
|
2201
|
+
settled: false
|
|
2202
|
+
};
|
|
2203
|
+
if (!hadSession && !retainedThreadTs) replyPlan.markSent();
|
|
2204
|
+
snapshotSession = delivery.streamSession;
|
|
2205
|
+
commitText();
|
|
2206
|
+
if (chunks?.length) snapshot = reconciled.snapshot;
|
|
2207
|
+
sent = true;
|
|
2208
|
+
if (!params.rollover || countOwedRows() === 0) return {
|
|
2209
|
+
sent: true,
|
|
2210
|
+
settled: true
|
|
2211
|
+
};
|
|
2212
|
+
} catch (err) {
|
|
2213
|
+
if (params.rollover && !tooLongRetried && err instanceof SlackStreamMessageTooLongError) {
|
|
2214
|
+
tooLongRetried = true;
|
|
2215
|
+
runtime.log?.(warn(`slack-stream: Slack rejected a progress update with msg_too_long at ${delivery.streamLedger.size} size units; continuing in a new message`));
|
|
2216
|
+
if (delivery.streamSession) discardSlackStreamPendingText(delivery.streamSession);
|
|
2217
|
+
if (!(await rollMessage({
|
|
2218
|
+
previous,
|
|
2219
|
+
full,
|
|
2220
|
+
reason: "msg_too_long"
|
|
2221
|
+
})).rolled) return {
|
|
2222
|
+
sent,
|
|
2223
|
+
settled: false
|
|
2224
|
+
};
|
|
2225
|
+
continue;
|
|
2226
|
+
}
|
|
2227
|
+
reportFailure(err);
|
|
2228
|
+
return {
|
|
2229
|
+
sent,
|
|
2230
|
+
settled: false
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
return {
|
|
2235
|
+
sent,
|
|
2236
|
+
settled: false
|
|
2237
|
+
};
|
|
2238
|
+
};
|
|
2239
|
+
/**
|
|
2240
|
+
* Finishes the current message as rolled and opens the continuation with
|
|
2241
|
+
* the rows that carry over and room for the text the caller appends next,
|
|
2242
|
+
* so streamed text can go on there. Used before narration that would not
|
|
2243
|
+
* fit and after Slack rejected narration.
|
|
2244
|
+
*/
|
|
2245
|
+
const rollForNarration = async (reserveText, rejected) => {
|
|
2246
|
+
if (rejected) discardSlackStreamPendingText(rejected);
|
|
2247
|
+
const draft = params.getSnapshot();
|
|
2248
|
+
if (!(await rollMessage({
|
|
2249
|
+
previous: snapshot,
|
|
2250
|
+
full: buildRunningChunks(draft),
|
|
2251
|
+
reason: rejected ? "msg_too_long" : delivery.streamLedger.expiring ? "age" : "budget"
|
|
2252
|
+
})).rolled) return false;
|
|
2253
|
+
return (await openMessage({
|
|
2254
|
+
chunks: buildRunningChunks(draft),
|
|
2255
|
+
reserveText,
|
|
2256
|
+
reserveFor: pendingCardChunks()
|
|
2257
|
+
})).accepted;
|
|
2258
|
+
};
|
|
2259
|
+
/**
|
|
2260
|
+
* The answer would not fit under the think on this message. Close the
|
|
2261
|
+
* message as the finished think (its completion chunks and summary title)
|
|
2262
|
+
* and leave no session, so the answer streams as its own message in the
|
|
2263
|
+
* same thread. Also the retry path when Slack rejects the answer itself.
|
|
2264
|
+
*/
|
|
2265
|
+
const finishBeforeAnswer = async (rejected) => {
|
|
2266
|
+
if (!delivery.streamSession) return false;
|
|
2267
|
+
if (rejected) discardSlackStreamPendingText(rejected);
|
|
2268
|
+
const draft = params.getSnapshot();
|
|
2269
|
+
const previous = snapshot;
|
|
2270
|
+
const completion = completionSent ? void 0 : buildCompletionChunks("complete");
|
|
2271
|
+
const size = delivery.streamLedger.size;
|
|
2272
|
+
const reason = rejected ? "msg_too_long" : delivery.streamLedger.expiring ? "age" : "budget";
|
|
2273
|
+
const sealed = await delivery.sealStream(completion);
|
|
2274
|
+
if (!sealed || delivery.streamFailed) return false;
|
|
2275
|
+
if (completion?.length && sealed.chunksRejected) {
|
|
2276
|
+
retireMessage({
|
|
2277
|
+
previous,
|
|
2278
|
+
full: buildRunningChunks(draft),
|
|
2279
|
+
finished: previous,
|
|
2280
|
+
chunksRejected: true
|
|
2281
|
+
});
|
|
2282
|
+
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(draft));
|
|
2283
|
+
const opened = await openMessage({
|
|
2284
|
+
chunks: buildCurrentMessageChunks({
|
|
2285
|
+
draft,
|
|
2286
|
+
completed: true,
|
|
2287
|
+
finalInProgressStatus: "complete"
|
|
2288
|
+
}),
|
|
2289
|
+
...narrationUpdate.delta ? { text: narrationUpdate.delta } : {},
|
|
2290
|
+
finalStatus: "complete"
|
|
2291
|
+
});
|
|
2292
|
+
if (!opened.accepted) return false;
|
|
2293
|
+
if (opened.textSent) commitNarration(narrationUpdate.next);
|
|
2294
|
+
completionSent = true;
|
|
2295
|
+
logVerbose(`slack-stream: native progress message finished at ${size} size units (${reason}); Slack rejected its closeout, carried to the message that streams the answer`);
|
|
2296
|
+
return true;
|
|
2297
|
+
}
|
|
2298
|
+
if (completion?.length) completionSent = true;
|
|
2299
|
+
forgetCurrentMessage();
|
|
2300
|
+
logVerbose(`slack-stream: native progress message finished at ${size} size units (${reason}); streaming the answer as a new message`);
|
|
2301
|
+
return true;
|
|
2302
|
+
};
|
|
2303
|
+
/**
|
|
2304
|
+
* Last resort for cards still queued after sends settled nothing (the
|
|
2305
|
+
* compositor refused a release): place them straight from the queue on
|
|
2306
|
+
* budgeted messages, so no closeout carries them. The terminal reconcile
|
|
2307
|
+
* settles their status.
|
|
2308
|
+
*/
|
|
2309
|
+
const placePendingRemainder = async () => {
|
|
2310
|
+
let guard = params.pendingRows() + 1;
|
|
2311
|
+
while (params.pendingRows() > 0 && guard-- > 0 && !delivery.streamFailed && !delivery.streamSession?.stoppedBySlack) {
|
|
2312
|
+
const lines = params.peekPendingLines();
|
|
2313
|
+
const draft = params.getSnapshot();
|
|
2314
|
+
if (delivery.streamSession && !(await rollMessage({
|
|
2315
|
+
previous: snapshot,
|
|
2316
|
+
full: buildRunningChunks(draft),
|
|
2317
|
+
reason: "budget"
|
|
2318
|
+
})).rolled) return;
|
|
2319
|
+
const opened = await openMessage({ chunks: buildRunningChunks({
|
|
2320
|
+
...draft,
|
|
2321
|
+
lines: [...draft.lines, ...lines]
|
|
2322
|
+
}) });
|
|
2323
|
+
if (!opened.accepted) return;
|
|
2324
|
+
const placed = [];
|
|
2325
|
+
for (const id of opened.admittedTaskIds) {
|
|
2326
|
+
const card = resolveSlackReasoningTaskIndex(id);
|
|
2327
|
+
if (card !== void 0) placed.push(`reasoning:${card}`);
|
|
2328
|
+
}
|
|
2329
|
+
if (placed.length === 0) return;
|
|
2330
|
+
params.markPendingPlaced(placed);
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
/**
|
|
2334
|
+
* Drains through the compositor first, then places cards it refused directly
|
|
2335
|
+
* on budgeted messages. Closeout must never bypass this admission budget.
|
|
2336
|
+
*/
|
|
2337
|
+
const drain = async () => {
|
|
2338
|
+
if (!params.rollover || !delivery.streamSession) return;
|
|
2339
|
+
for (let pass = 0; pass < SLACK_STREAM_DRAIN_PASSES; pass += 1) if (delivery.streamFailed || delivery.streamSession?.stoppedBySlack || (await send()).settled) return;
|
|
2340
|
+
await placePendingRemainder();
|
|
2341
|
+
};
|
|
2342
|
+
return {
|
|
2343
|
+
get snapshot() {
|
|
2344
|
+
return snapshot;
|
|
2345
|
+
},
|
|
2346
|
+
get narrationRenderedText() {
|
|
2347
|
+
return narration.rendered;
|
|
2348
|
+
},
|
|
2349
|
+
get completionSent() {
|
|
2350
|
+
return completionSent;
|
|
2351
|
+
},
|
|
2352
|
+
set completionSent(value) {
|
|
2353
|
+
completionSent = value;
|
|
2354
|
+
},
|
|
2355
|
+
resolveNarrationUpdate,
|
|
2356
|
+
commitNarration,
|
|
2357
|
+
buildCompletionChunks,
|
|
2358
|
+
send,
|
|
2359
|
+
/** Per-turn reset: the next message starts a new chain. */
|
|
2360
|
+
reset() {
|
|
2361
|
+
snapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
2362
|
+
narration = {
|
|
2363
|
+
rendered: "",
|
|
2364
|
+
source: ""
|
|
2365
|
+
};
|
|
2366
|
+
completionSent = false;
|
|
2367
|
+
rolledTaskIds = /* @__PURE__ */ new Set();
|
|
2368
|
+
frozenRows = /* @__PURE__ */ new Map();
|
|
2369
|
+
planSteps = new SlackChainPlanSteps();
|
|
2370
|
+
rolledMessages = 0;
|
|
2371
|
+
},
|
|
2372
|
+
/** Makes room for streamed narration; false when the stream is lost. */
|
|
2373
|
+
async ensureRoomForNarration(delta) {
|
|
2374
|
+
if (!params.rollover || !delivery.streamSession || delivery.streamFailed || !delivery.streamLedger.expiring && planSlackStreamUpdateFit(delivery.streamLedger, { text: delta }).textFits) return true;
|
|
2375
|
+
return await rollForNarration(delta);
|
|
2376
|
+
},
|
|
2377
|
+
retryNarrationOnNewMessage: async (rejected) => {
|
|
2378
|
+
runtime.log?.(warn(`slack-stream: Slack rejected streamed text with msg_too_long at ${delivery.streamLedger.size} size units; retrying in a new message`));
|
|
2379
|
+
return await rollForNarration(rejected.pendingText, rejected);
|
|
2380
|
+
},
|
|
2381
|
+
/**
|
|
2382
|
+
* Whether the message being built can take one more row on top of the
|
|
2383
|
+
* rows already admitted for it (sent or not), rows and size.
|
|
2384
|
+
*/
|
|
2385
|
+
admitsRow(line) {
|
|
2386
|
+
if (!params.rollover) return true;
|
|
2387
|
+
const draft = params.getSnapshot();
|
|
2388
|
+
const chunks = buildRunningChunks({
|
|
2389
|
+
...draft,
|
|
2390
|
+
lines: [...draft.lines, line]
|
|
2391
|
+
});
|
|
2392
|
+
return planSlackStreamUpdateFit(delivery.streamSession ? delivery.streamLedger : delivery.streamLedger.fresh(), { chunks }).fits;
|
|
2393
|
+
},
|
|
2394
|
+
/**
|
|
2395
|
+
* Rows still queued behind the pacing loop when the turn ends go out
|
|
2396
|
+
* budgeted, rolling as needed, before any closeout: a completion append
|
|
2397
|
+
* or stop carrying them could pass Slack's size or its 50-row plan block.
|
|
2398
|
+
*/
|
|
2399
|
+
async drainBeforeClose() {
|
|
2400
|
+
await drain();
|
|
2401
|
+
admitUnshownPlanRows();
|
|
2402
|
+
},
|
|
2403
|
+
/**
|
|
2404
|
+
* Closeout (statuses, title, rows still queued behind the cancelled pacing
|
|
2405
|
+
* loop) and the answer share the message. When they would not fit, send
|
|
2406
|
+
* the queued rows first, rolling as needed; if the answer still does not
|
|
2407
|
+
* fit, finish the think here so the answer streams on its own.
|
|
2408
|
+
*/
|
|
2409
|
+
async prepareForAnswer(payload) {
|
|
2410
|
+
if (!params.rollover || !delivery.streamSession || delivery.streamSession.stoppedBySlack) return;
|
|
2411
|
+
const answer = `\n${resolveSendableOutboundReplyParts(payload).trimmedText}`;
|
|
2412
|
+
const answerFits = () => planSlackStreamUpdateFit(delivery.streamLedger, {
|
|
2413
|
+
text: answer,
|
|
2414
|
+
chunks: buildCompletionChunks("complete")
|
|
2415
|
+
}).fits;
|
|
2416
|
+
if (params.pendingRows() > 0) await drain();
|
|
2417
|
+
admitUnshownPlanRows(answer);
|
|
2418
|
+
if (!delivery.streamSession || delivery.streamFailed) return;
|
|
2419
|
+
if (delivery.streamLedger.expiring) {
|
|
2420
|
+
await finishBeforeAnswer();
|
|
2421
|
+
return;
|
|
2422
|
+
}
|
|
2423
|
+
if (answerFits()) return;
|
|
2424
|
+
await drain();
|
|
2425
|
+
admitUnshownPlanRows(answer);
|
|
2426
|
+
if (delivery.streamSession && !delivery.streamFailed && !answerFits()) await finishBeforeAnswer();
|
|
2427
|
+
},
|
|
2428
|
+
retryAnswerOnNewMessage: async (rejected) => {
|
|
2429
|
+
runtime.log?.(warn(`slack-stream: Slack rejected the answer with msg_too_long at ${delivery.streamLedger.size} size units; retrying as a new message`));
|
|
2430
|
+
return await finishBeforeAnswer(rejected);
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
1029
2434
|
// extensions/slack/src/monitor/message-handler/dispatch-progress.ts
|
|
1030
2435
|
function createSlackProgressRuntime(runtimeParams) {
|
|
1031
2436
|
const { setup, delivery } = runtimeParams;
|
|
@@ -1057,30 +2462,29 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1057
2462
|
previewToolProgressEnabled,
|
|
1058
2463
|
previewStreamingEnabled
|
|
1059
2464
|
});
|
|
1060
|
-
let nativeStreamSnapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
1061
|
-
let nativeSnapshotSession = delivery.streamSession;
|
|
1062
2465
|
let appendState = {
|
|
1063
2466
|
rendered: "",
|
|
1064
2467
|
source: ""
|
|
1065
2468
|
};
|
|
1066
|
-
let nativeProgressCompletionSent = false;
|
|
1067
2469
|
let cardPostRequested = false;
|
|
1068
2470
|
let nativeProgressTerminalStatus = "complete";
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
source: ""
|
|
1072
|
-
};
|
|
1073
|
-
let nativeStreamOrder = Promise.resolve();
|
|
1074
|
-
const withNativeStreamOrder = (task) => {
|
|
1075
|
-
const run = nativeStreamOrder.then(task, task);
|
|
1076
|
-
nativeStreamOrder = run.catch(() => void 0);
|
|
1077
|
-
return run;
|
|
1078
|
-
};
|
|
2471
|
+
const nativeStreamOrder = createSlackNativeStreamOrder();
|
|
2472
|
+
const withNativeStreamOrder = nativeStreamOrder.run;
|
|
1079
2473
|
const progressWorkCounter = createChannelProgressWorkCounter();
|
|
1080
2474
|
const progressSeed = `${account.accountId}:${message.channel}`;
|
|
1081
2475
|
const preambleOnlyProgress = isProgressMode && slackProgressStyle === "compact" && !previewToolProgressEnabled;
|
|
1082
2476
|
const useDraftProgressCard = shouldUseDraftStream && isProgressMode && slackProgressStyle === "card";
|
|
1083
2477
|
const explicitProgressTitle = resolveExplicitSlackProgressTitle(account.config);
|
|
2478
|
+
const reasoningCards = createSlackReasoningCardsRuntime({
|
|
2479
|
+
entry: account.config,
|
|
2480
|
+
nativeCard: useNativeProgressStreaming,
|
|
2481
|
+
toolRows: previewToolProgressEnabled,
|
|
2482
|
+
compositor: () => progressDraft,
|
|
2483
|
+
admits: (line) => nativeStream.admitsRow(line),
|
|
2484
|
+
flushQueued: () => withNativeStreamOrder(() => nativeStream.drainBeforeClose()),
|
|
2485
|
+
noteQueued: () => nativeUpdates.update(true)
|
|
2486
|
+
});
|
|
2487
|
+
const useStreamRollover = useNativeProgressStreaming;
|
|
1084
2488
|
const progressDraftMaxLineChars = resolveChannelProgressDraftMaxLineChars(account.config);
|
|
1085
2489
|
const progressCard = createSlackDraftProgressCardRuntime({
|
|
1086
2490
|
setup,
|
|
@@ -1104,74 +2508,54 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1104
2508
|
const appendNativeProgressCompletion = async (isError) => {
|
|
1105
2509
|
const session = delivery.streamSession;
|
|
1106
2510
|
if (isError) nativeProgressTerminalStatus = "error";
|
|
1107
|
-
if (!session || delivery.streamFailed ||
|
|
2511
|
+
if (!session || delivery.streamFailed || nativeStream.completionSent) return;
|
|
1108
2512
|
const chunks = buildNativeProgressCompletionChunks(isError ? "error" : "complete");
|
|
1109
|
-
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(progressDraft.getSnapshot()));
|
|
2513
|
+
const narrationUpdate = nativeStream.resolveNarrationUpdate(resolveNativeProgressNarration(progressDraft.getSnapshot()));
|
|
1110
2514
|
if (!chunks?.length && !narrationUpdate.delta) return;
|
|
1111
2515
|
try {
|
|
2516
|
+
delivery.streamLedger.record({ chunks });
|
|
1112
2517
|
await appendSlackStream({
|
|
1113
2518
|
session,
|
|
1114
2519
|
chunks
|
|
1115
2520
|
});
|
|
1116
|
-
|
|
1117
|
-
|
|
2521
|
+
nativeStream.commitNarration(narrationUpdate.next);
|
|
2522
|
+
nativeStream.completionSent = true;
|
|
1118
2523
|
delivery.observedReplyDelivery ||= session.delivered;
|
|
1119
2524
|
} catch (err) {
|
|
1120
2525
|
delivery.streamFailed = true;
|
|
1121
2526
|
runtime.error?.(danger(`slack-stream: native progress completion failed: ${formatSlackError(err)}`));
|
|
1122
2527
|
}
|
|
1123
2528
|
};
|
|
1124
|
-
const resolveNativeProgressTitle = (snapshot) => combineProgressHeadlineAndExplanation(explicitProgressTitle ?? snapshot.statusHeadline, snapshot.planExplanation);
|
|
1125
|
-
const
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
2529
|
+
const resolveNativeProgressTitle = (snapshot, completed = false) => combineProgressHeadlineAndExplanation(explicitProgressTitle ?? (completed ? reasoningCards.summaryTitle() : void 0) ?? snapshot.statusHeadline, snapshot.planExplanation);
|
|
2530
|
+
const nativeStream = createSlackNativeProgressStream({
|
|
2531
|
+
delivery,
|
|
2532
|
+
transport: nativeTransport,
|
|
2533
|
+
replyPlan,
|
|
2534
|
+
runtime,
|
|
2535
|
+
rollover: useStreamRollover,
|
|
2536
|
+
explicitTitle: explicitProgressTitle,
|
|
2537
|
+
maxLineChars: progressDraftMaxLineChars,
|
|
2538
|
+
summaryRow: !previewToolProgressEnabled,
|
|
2539
|
+
getSnapshot: () => progressDraft.getSnapshot(),
|
|
2540
|
+
resolveTitle: resolveNativeProgressTitle,
|
|
2541
|
+
resolveSessionLinks: () => progressCard.resolveSessionLinks(),
|
|
2542
|
+
onRolled: (throughCard) => reasoningCards.rollover(throughCard),
|
|
2543
|
+
pendingRows: () => reasoningCards.pendingRows(),
|
|
2544
|
+
releasePending: async () => await nativeStreamOrder.waitForFlushes() ? await reasoningCards.release() : void 0,
|
|
2545
|
+
peekPendingLines: () => reasoningCards.peekPendingLines(),
|
|
2546
|
+
markPendingPlaced: (lineIds) => reasoningCards.markPlaced(lineIds)
|
|
2547
|
+
});
|
|
2548
|
+
const buildNativeProgressCompletionChunks = nativeStream.buildCompletionChunks;
|
|
2549
|
+
const drainNativeProgressBeforeCloseNow = async () => {
|
|
2550
|
+
if (useStreamRollover) await nativeStream.drainBeforeClose();
|
|
2551
|
+
};
|
|
2552
|
+
const drainNativeProgressBeforeClose = async () => {
|
|
2553
|
+
if (useStreamRollover && !nativeStream.completionSent) await withNativeStreamOrder(drainNativeProgressBeforeCloseNow);
|
|
1134
2554
|
};
|
|
1135
2555
|
const updateNativeProgressStreamNow = async () => {
|
|
1136
2556
|
if (!useNativeProgressStreaming || delivery.streamFailed || nativeUpdatesStopped) return false;
|
|
1137
2557
|
if (!await nativeTransport.waitForStart()) return false;
|
|
1138
|
-
await
|
|
1139
|
-
if (nativeSnapshotSession !== delivery.streamSession) nativeStreamSnapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
1140
|
-
const snapshot = progressDraft.getSnapshot();
|
|
1141
|
-
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(snapshot));
|
|
1142
|
-
const reconciled = reconcileSlackNativeTaskChunks({
|
|
1143
|
-
previous: nativeStreamSnapshot,
|
|
1144
|
-
chunks: buildSlackProgressStreamChunks({
|
|
1145
|
-
title: resolveNativeProgressTitle(snapshot),
|
|
1146
|
-
lines: resolveNativeProgressLines(snapshot),
|
|
1147
|
-
plan: snapshot.plan,
|
|
1148
|
-
maxLineChars: progressDraftMaxLineChars,
|
|
1149
|
-
summaryRow: !previewToolProgressEnabled
|
|
1150
|
-
})
|
|
1151
|
-
});
|
|
1152
|
-
const chunks = reconciled.chunks;
|
|
1153
|
-
if (!chunks?.length && !narrationUpdate.delta) return false;
|
|
1154
|
-
try {
|
|
1155
|
-
const hadSession = Boolean(delivery.streamSession);
|
|
1156
|
-
const retainedThreadTs = delivery.interruptedThreadTs;
|
|
1157
|
-
const streamUpdate = {
|
|
1158
|
-
...narrationUpdate.delta ? { text: narrationUpdate.delta } : {},
|
|
1159
|
-
...chunks?.length ? { chunks } : {}
|
|
1160
|
-
};
|
|
1161
|
-
if (narrationUpdate.delta) delivery.pendingTextIsProgress = true;
|
|
1162
|
-
const accepted = hadSession ? await nativeTransport.append(streamUpdate) : await nativeTransport.start(streamUpdate, retainedThreadTs);
|
|
1163
|
-
if (accepted === "rotated") return await updateNativeProgressStreamNow();
|
|
1164
|
-
if (!accepted) return false;
|
|
1165
|
-
if (!hadSession && !retainedThreadTs) replyPlan.markSent();
|
|
1166
|
-
nativeSnapshotSession = delivery.streamSession;
|
|
1167
|
-
if (narrationUpdate.next.changed) nativeNarration = narrationUpdate.next;
|
|
1168
|
-
if (chunks?.length) nativeStreamSnapshot = reconciled.snapshot;
|
|
1169
|
-
return true;
|
|
1170
|
-
} catch (err) {
|
|
1171
|
-
runtime.error?.(danger(`slack-stream: native progress stream failed: ${formatSlackError(err)}, falling back`));
|
|
1172
|
-
delivery.streamFailed = true;
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
2558
|
+
return (await nativeStream.send()).sent;
|
|
1175
2559
|
};
|
|
1176
2560
|
let nativeUpdatesStopped = false;
|
|
1177
2561
|
const nativeUpdates = createDraftStreamLoop({
|
|
@@ -1180,7 +2564,7 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1180
2564
|
emptyValue: false,
|
|
1181
2565
|
isEmpty: (pending) => !pending,
|
|
1182
2566
|
isStopped: () => nativeUpdatesStopped,
|
|
1183
|
-
sendOrEditStreamMessage: () =>
|
|
2567
|
+
sendOrEditStreamMessage: () => nativeStreamOrder.runLoopSend(updateNativeProgressStreamNow),
|
|
1184
2568
|
onBackgroundFlushError: (err) => runtime.error?.(danger(`slack-stream: progress update failed: ${formatSlackError(err)}`))
|
|
1185
2569
|
});
|
|
1186
2570
|
const cancelNativeUpdates = async () => {
|
|
@@ -1190,29 +2574,28 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1190
2574
|
};
|
|
1191
2575
|
const appendNativeNarration = (payload, kind) => withNativeStreamOrder(async () => {
|
|
1192
2576
|
if (isSlackProgressTitleText(payload.text, progressDraft.getSnapshot(), explicitProgressTitle)) return { visibleReplySent: false };
|
|
1193
|
-
const narrationUpdate = resolveNarrationUpdate(payload.text?.trimEnd());
|
|
1194
|
-
if (!narrationUpdate.delta) return { visibleReplySent: false };
|
|
2577
|
+
const narrationUpdate = nativeStream.resolveNarrationUpdate(payload.text?.trimEnd());
|
|
2578
|
+
if (!narrationUpdate.delta || !await nativeStream.ensureRoomForNarration(narrationUpdate.delta)) return { visibleReplySent: false };
|
|
1195
2579
|
const result = await delivery.deliverWithStreaming({
|
|
1196
2580
|
payload,
|
|
1197
2581
|
kind,
|
|
1198
2582
|
streamText: narrationUpdate.delta,
|
|
1199
2583
|
appendSeparator: false,
|
|
1200
|
-
taskDisplayMode: "plan"
|
|
2584
|
+
taskDisplayMode: "plan",
|
|
2585
|
+
...useStreamRollover ? { onMessageTooLong: nativeStream.retryNarrationOnNewMessage } : {}
|
|
1201
2586
|
});
|
|
1202
|
-
if (result.visibleReplySent && !delivery.streamFailed)
|
|
2587
|
+
if (result.visibleReplySent && !delivery.streamFailed) nativeStream.commitNarration(narrationUpdate.next);
|
|
1203
2588
|
return result;
|
|
1204
2589
|
});
|
|
1205
2590
|
const resetProgressTurnState = () => {
|
|
1206
2591
|
progressWorkCounter.reset();
|
|
1207
2592
|
cardPostRequested = false;
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
source: ""
|
|
1211
|
-
};
|
|
2593
|
+
reasoningCards.reset();
|
|
2594
|
+
nativeStream.reset();
|
|
1212
2595
|
};
|
|
1213
2596
|
const progressDraft = createChannelProgressDraftCompositor({
|
|
1214
2597
|
preparedItems: true,
|
|
1215
|
-
entry:
|
|
2598
|
+
entry: reasoningCards.compositorEntry,
|
|
1216
2599
|
mode: slackStreaming.mode,
|
|
1217
2600
|
active: progressDraftActive,
|
|
1218
2601
|
seed: progressSeed,
|
|
@@ -1222,12 +2605,13 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1222
2605
|
updateOnLineChange: useNativeProgressStreaming || useDraftProgressCard || preambleOnlyProgress,
|
|
1223
2606
|
update: async (previewText, options) => {
|
|
1224
2607
|
if (useNativeProgressStreaming && !delivery.streamFailed) {
|
|
1225
|
-
const priorSnapshot =
|
|
1226
|
-
const priorNarration =
|
|
2608
|
+
const priorSnapshot = nativeStream.snapshot;
|
|
2609
|
+
const priorNarration = nativeStream.narrationRenderedText;
|
|
1227
2610
|
nativeUpdates.update(true);
|
|
1228
|
-
if (
|
|
2611
|
+
if (useStreamRollover && nativeStreamOrder.inTask) return false;
|
|
2612
|
+
if (options?.flush) await nativeStreamOrder.trackFlush(() => nativeUpdates.flush());
|
|
1229
2613
|
else await nativeUpdates.waitForInFlight();
|
|
1230
|
-
if (!delivery.streamFailed) return priorSnapshot !==
|
|
2614
|
+
if (!delivery.streamFailed) return priorSnapshot !== nativeStream.snapshot || priorNarration !== nativeStream.narrationRenderedText;
|
|
1231
2615
|
}
|
|
1232
2616
|
if (!draftStream || delivery.streamSession?.stoppedBySlack) return false;
|
|
1233
2617
|
const snapshot = options.snapshot;
|
|
@@ -1288,7 +2672,9 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1288
2672
|
}
|
|
1289
2673
|
} : void 0,
|
|
1290
2674
|
cleanupUndelivered: true,
|
|
1291
|
-
onFinalStarted: () =>
|
|
2675
|
+
onFinalStarted: () => {
|
|
2676
|
+
if (!useStreamRollover) progressDraft.markFinalReplyStarted();
|
|
2677
|
+
},
|
|
1292
2678
|
onFinalDelivered: () => progressDraft.markFinalReplyDelivered(),
|
|
1293
2679
|
onCleanupFailure: (error) => logVerbose(`slack: progress preview cleanup failed (${formatSlackError(error)})`)
|
|
1294
2680
|
});
|
|
@@ -1304,12 +2690,17 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1304
2690
|
await delivery.rotateInterruptedStream();
|
|
1305
2691
|
const finalThreadTs = delivery.nativeFinalThreadTs();
|
|
1306
2692
|
if (delivery.canFinishNativeFinal(payload, streamReady)) {
|
|
2693
|
+
await nativeStream.prepareForAnswer(payload);
|
|
2694
|
+
progressDraft.markFinalReplyStarted();
|
|
1307
2695
|
await appendNativeProgressCompletion(false);
|
|
1308
2696
|
return await delivery.deliverWithStreaming({
|
|
1309
2697
|
payload,
|
|
1310
|
-
kind
|
|
2698
|
+
kind,
|
|
2699
|
+
...useStreamRollover ? { onMessageTooLong: nativeStream.retryAnswerOnNewMessage } : {}
|
|
1311
2700
|
});
|
|
1312
2701
|
}
|
|
2702
|
+
await drainNativeProgressBeforeCloseNow();
|
|
2703
|
+
progressDraft.markFinalReplyStarted();
|
|
1313
2704
|
const result = await delivery.deliverNormally({
|
|
1314
2705
|
payload,
|
|
1315
2706
|
kind,
|
|
@@ -1318,35 +2709,9 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1318
2709
|
await appendNativeProgressCompletion(payload.isError === true);
|
|
1319
2710
|
return result;
|
|
1320
2711
|
};
|
|
1321
|
-
const buildNativeProgressCompletionChunks = (finalInProgressStatus) => {
|
|
1322
|
-
const snapshot = progressDraft.getSnapshot();
|
|
1323
|
-
const lines = resolveNativeProgressLines(snapshot);
|
|
1324
|
-
const sessionLinks = progressCard.resolveSessionLinks();
|
|
1325
|
-
const narrationUpdate = resolveNarrationUpdate(resolveNativeProgressNarration(snapshot));
|
|
1326
|
-
const hasRetirableNativeTasks = [...nativeStreamSnapshot.tasks.values()].some((task) => task.status !== "complete" && task.status !== "error");
|
|
1327
|
-
if (lines.length === 0 && !snapshot.plan?.length && !hasRetirableNativeTasks && !snapshot.diffStat && !narrationUpdate.delta && sessionLinks.length === 0) return;
|
|
1328
|
-
const completion = reconcileSlackNativeTaskChunks({
|
|
1329
|
-
previous: nativeStreamSnapshot,
|
|
1330
|
-
finalStatus: finalInProgressStatus,
|
|
1331
|
-
chunks: buildSlackProgressStreamChunks({
|
|
1332
|
-
title: resolveNativeProgressTitle(snapshot),
|
|
1333
|
-
lines,
|
|
1334
|
-
plan: snapshot.plan,
|
|
1335
|
-
maxLineChars: progressDraftMaxLineChars,
|
|
1336
|
-
summaryRow: !previewToolProgressEnabled,
|
|
1337
|
-
finalInProgressStatus,
|
|
1338
|
-
diffStat: snapshot.diffStat,
|
|
1339
|
-
sessionLinks
|
|
1340
|
-
})
|
|
1341
|
-
}).chunks;
|
|
1342
|
-
return narrationUpdate.delta ? [{
|
|
1343
|
-
type: "markdown_text",
|
|
1344
|
-
text: narrationUpdate.delta
|
|
1345
|
-
}, ...completion ?? []] : completion;
|
|
1346
|
-
};
|
|
1347
2712
|
const finishNativeProgressTurn = async (completionChunks) => {
|
|
1348
2713
|
if (delivery.nativeProgressStreamStartPromise) await delivery.nativeProgressStreamStartPromise.catch(() => null);
|
|
1349
|
-
if (completionChunks?.length)
|
|
2714
|
+
if (completionChunks?.length) nativeStream.completionSent = true;
|
|
1350
2715
|
await delivery.finishStream(completionChunks);
|
|
1351
2716
|
await previewLifecycle.cleanup();
|
|
1352
2717
|
draftStream?.forceNewMessage();
|
|
@@ -1383,19 +2748,8 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1383
2748
|
};
|
|
1384
2749
|
const pushReasoningProgress = async (payload) => {
|
|
1385
2750
|
if (!payload?.text) return false;
|
|
1386
|
-
if (!isProgressMode)
|
|
1387
|
-
|
|
1388
|
-
const normalized = progressDraft.mergeReasoningProgress(payload.text, { snapshot: payload.isReasoningSnapshot === true }).replace(/^_(.*)_$/su, "$1").trim();
|
|
1389
|
-
if (!normalized) return false;
|
|
1390
|
-
const visible = await progressDraft.pushToolProgress({
|
|
1391
|
-
id: "reasoning",
|
|
1392
|
-
kind: "item",
|
|
1393
|
-
text: normalized,
|
|
1394
|
-
label: "Reasoning"
|
|
1395
|
-
});
|
|
1396
|
-
progressDraft.mergeReasoningProgress(normalized, { snapshot: true });
|
|
1397
|
-
return visible;
|
|
1398
|
-
}
|
|
2751
|
+
if (!isProgressMode) return await pushSlackReasoningPreview(progressDraft, payload, previewToolProgressEnabled);
|
|
2752
|
+
if (reasoningCards.enabled) return await reasoningCards.push(payload);
|
|
1399
2753
|
return await progressDraft.pushReasoningProgress(payload.text, { snapshot: payload.isReasoningSnapshot === true });
|
|
1400
2754
|
};
|
|
1401
2755
|
const resetDraftDeliveryState = () => {
|
|
@@ -1409,9 +2763,10 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1409
2763
|
if (!nativeUpdatesStopped && options?.force !== true) return false;
|
|
1410
2764
|
if (options?.force !== true) await nativeFinalDelivery;
|
|
1411
2765
|
await cancelNativeUpdates();
|
|
2766
|
+
await drainNativeProgressBeforeClose();
|
|
1412
2767
|
}
|
|
1413
2768
|
const priorSnapshot = progressDraft.getSnapshot();
|
|
1414
|
-
const completionChunks = useNativeProgressStreaming && !
|
|
2769
|
+
const completionChunks = useNativeProgressStreaming && !nativeStream.completionSent ? buildNativeProgressCompletionChunks(nativeProgressTerminalStatus) : void 0;
|
|
1415
2770
|
if (!progressDraft.beginNewTurn(options)) return false;
|
|
1416
2771
|
if (useNativeProgressStreaming) await finishNativeProgressTurn(completionChunks);
|
|
1417
2772
|
else {
|
|
@@ -1421,8 +2776,6 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1421
2776
|
await dropDetachedProgressCards();
|
|
1422
2777
|
}
|
|
1423
2778
|
resetProgressTurnState();
|
|
1424
|
-
nativeStreamSnapshot = EMPTY_SLACK_NATIVE_STREAM_SNAPSHOT;
|
|
1425
|
-
nativeProgressCompletionSent = false;
|
|
1426
2779
|
nativeProgressTerminalStatus = "complete";
|
|
1427
2780
|
nativeUpdatesStopped = false;
|
|
1428
2781
|
nativeUpdates.resetThrottleWindow();
|
|
@@ -1456,7 +2809,8 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1456
2809
|
if (useNativeProgressStreaming) {
|
|
1457
2810
|
progressDraft.markFinalReplyStarted();
|
|
1458
2811
|
await cancelNativeUpdates();
|
|
1459
|
-
await
|
|
2812
|
+
await drainNativeProgressBeforeClose();
|
|
2813
|
+
await finishNativeProgressTurn(nativeStream.completionSent ? void 0 : buildNativeProgressCompletionChunks(nativeProgressTerminalStatus));
|
|
1460
2814
|
return;
|
|
1461
2815
|
}
|
|
1462
2816
|
if (!useDraftProgressCard) {
|
|
@@ -1483,10 +2837,10 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1483
2837
|
await cancelNativeUpdates();
|
|
1484
2838
|
},
|
|
1485
2839
|
get nativeProgressCompletionSent() {
|
|
1486
|
-
return
|
|
2840
|
+
return nativeStream.completionSent;
|
|
1487
2841
|
},
|
|
1488
2842
|
set nativeProgressCompletionSent(value) {
|
|
1489
|
-
|
|
2843
|
+
nativeStream.completionSent = value;
|
|
1490
2844
|
},
|
|
1491
2845
|
get nativeProgressTerminalStatus() {
|
|
1492
2846
|
return nativeProgressTerminalStatus;
|
|
@@ -1494,6 +2848,7 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1494
2848
|
appendNativeNarration,
|
|
1495
2849
|
buildNativeProgressCompletionChunks,
|
|
1496
2850
|
deliverNativeFinal,
|
|
2851
|
+
drainNativeProgressBeforeClose,
|
|
1497
2852
|
dropDetachedProgressCards,
|
|
1498
2853
|
finalizeDraftProgressCard: progressCard.finalize,
|
|
1499
2854
|
onVisibleWorkSessions: progressCard.onVisibleWorkSessions,
|
|
@@ -1502,6 +2857,7 @@ function createSlackProgressRuntime(runtimeParams) {
|
|
|
1502
2857
|
onQueuedFollowupSettled,
|
|
1503
2858
|
pushPlanProgress,
|
|
1504
2859
|
pushReasoningProgress,
|
|
2860
|
+
reasoningCards,
|
|
1505
2861
|
updateDraftFromPartial
|
|
1506
2862
|
};
|
|
1507
2863
|
}
|
|
@@ -1729,10 +3085,16 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1729
3085
|
cfg: ctx.cfg,
|
|
1730
3086
|
accountId: account.accountId
|
|
1731
3087
|
});
|
|
3088
|
+
const boundaryState = {
|
|
3089
|
+
streamBoundary: null,
|
|
3090
|
+
interruptedThreadTs: void 0
|
|
3091
|
+
};
|
|
3092
|
+
const streamRowLimit = resolveSlackNativeMessageRowLimit(account.config);
|
|
1732
3093
|
const state = {
|
|
1733
3094
|
streamSession: null,
|
|
1734
|
-
|
|
1735
|
-
|
|
3095
|
+
streamRowLimit,
|
|
3096
|
+
streamLedger: new SlackStreamMessageLedger(streamRowLimit),
|
|
3097
|
+
...boundaryState,
|
|
1736
3098
|
streamInterrupted: false,
|
|
1737
3099
|
nativeProgressStreamStartPromise: null,
|
|
1738
3100
|
nativeProgressStreamThreadTs: void 0,
|
|
@@ -1769,6 +3131,8 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1769
3131
|
userId: message.user
|
|
1770
3132
|
});
|
|
1771
3133
|
state.streamSession = session;
|
|
3134
|
+
state.streamLedger = new SlackStreamMessageLedger(streamRowLimit);
|
|
3135
|
+
state.streamLedger.record(params);
|
|
1772
3136
|
state.interruptedThreadTs = void 0;
|
|
1773
3137
|
if (session.streamer.ts) boundary.setMessageTs(session.streamer.ts);
|
|
1774
3138
|
return session;
|
|
@@ -1869,10 +3233,16 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1869
3233
|
threadId: sent.threadTs ?? session.threadTs
|
|
1870
3234
|
};
|
|
1871
3235
|
};
|
|
3236
|
+
/**
|
|
3237
|
+
* Stops the current stream message, with the closeout chunks when given.
|
|
3238
|
+
* `chunksRejected`: Slack refused the closeout with msg_too_long and the
|
|
3239
|
+
* message was stopped without it, so the caller still owns that content.
|
|
3240
|
+
*/
|
|
1872
3241
|
const finishStream = async (chunks) => {
|
|
1873
3242
|
state.streamBoundary?.stop();
|
|
1874
3243
|
state.streamBoundary = null;
|
|
1875
3244
|
const session = state.streamSession;
|
|
3245
|
+
let chunksRejected = false;
|
|
1876
3246
|
if (session && !session.stopped) try {
|
|
1877
3247
|
try {
|
|
1878
3248
|
await stopStream(session, chunks);
|
|
@@ -1880,6 +3250,7 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1880
3250
|
} catch (error) {
|
|
1881
3251
|
if (error instanceof SlackStreamMessageTooLongError && chunks?.length) {
|
|
1882
3252
|
runtime.error?.(danger("slack-stream: Slack rejected the closeout with msg_too_long; stopping without it"));
|
|
3253
|
+
chunksRejected = true;
|
|
1883
3254
|
markSlackStreamFallbackDelivered(session);
|
|
1884
3255
|
await stopStream(session);
|
|
1885
3256
|
state.observedReplyDelivery ||= session.delivered;
|
|
@@ -1890,6 +3261,24 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1890
3261
|
state.streamFailed = true;
|
|
1891
3262
|
runtime.error?.(danger(`slack-stream: failed to stop stream: ${formatSlackError(error)}`));
|
|
1892
3263
|
}
|
|
3264
|
+
return { chunksRejected };
|
|
3265
|
+
};
|
|
3266
|
+
/**
|
|
3267
|
+
* Finishes the current message and keeps its thread for the next one: a
|
|
3268
|
+
* human interruption seals it, a full message continues below it. Undefined
|
|
3269
|
+
* when Slack's Stop cancelled the turn; the stopped session then stays
|
|
3270
|
+
* current so every later delivery path stays suppressed.
|
|
3271
|
+
*/
|
|
3272
|
+
const sealStream = async (chunks) => {
|
|
3273
|
+
const threadTs = state.streamSession?.threadTs ?? state.nativeProgressStreamThreadTs;
|
|
3274
|
+
const finished = await finishStream(chunks);
|
|
3275
|
+
if (state.streamSession?.stoppedBySlack) return;
|
|
3276
|
+
state.streamSession = null;
|
|
3277
|
+
state.interruptedThreadTs = threadTs;
|
|
3278
|
+
return {
|
|
3279
|
+
threadTs,
|
|
3280
|
+
chunksRejected: finished.chunksRejected
|
|
3281
|
+
};
|
|
1893
3282
|
};
|
|
1894
3283
|
const rotateInterruptedStream = async () => {
|
|
1895
3284
|
if (!state.streamInterrupted) return;
|
|
@@ -1901,12 +3290,7 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1901
3290
|
state.streamBoundary = null;
|
|
1902
3291
|
return;
|
|
1903
3292
|
}
|
|
1904
|
-
|
|
1905
|
-
await finishStream();
|
|
1906
|
-
if (state.streamSession?.stoppedBySlack) return;
|
|
1907
|
-
state.streamSession = null;
|
|
1908
|
-
state.interruptedThreadTs = threadTs;
|
|
1909
|
-
return threadTs;
|
|
3293
|
+
return (await sealStream())?.threadTs;
|
|
1910
3294
|
};
|
|
1911
3295
|
const deliverNormally = async (params) => {
|
|
1912
3296
|
if (state.streamSession?.stoppedBySlack) return { visibleReplySent: false };
|
|
@@ -1992,19 +3376,31 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
1992
3376
|
let messageId;
|
|
1993
3377
|
let fallbackDelivery;
|
|
1994
3378
|
state.pendingTextIsProgress = false;
|
|
1995
|
-
|
|
1996
|
-
if (session)
|
|
1997
|
-
|
|
1998
|
-
text:
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
3379
|
+
const sendText = async () => {
|
|
3380
|
+
if (session) {
|
|
3381
|
+
const streamText = `${params.appendSeparator === false ? "" : "\n"}${text}`;
|
|
3382
|
+
state.streamLedger.record({ text: streamText });
|
|
3383
|
+
await appendSlackStream({
|
|
3384
|
+
session,
|
|
3385
|
+
text: streamText,
|
|
3386
|
+
chunks: []
|
|
3387
|
+
});
|
|
3388
|
+
} else session = await startStream({
|
|
2002
3389
|
threadTs,
|
|
2003
3390
|
text,
|
|
2004
3391
|
chunks: [],
|
|
2005
3392
|
...params.taskDisplayMode ? { taskDisplayMode: params.taskDisplayMode } : {}
|
|
2006
3393
|
});
|
|
2007
3394
|
messageId = session.streamer.ts;
|
|
3395
|
+
};
|
|
3396
|
+
try {
|
|
3397
|
+
try {
|
|
3398
|
+
await sendText();
|
|
3399
|
+
} catch (error) {
|
|
3400
|
+
if (!(error instanceof SlackStreamMessageTooLongError) || !session || !await params.onMessageTooLong?.(session)) throw error;
|
|
3401
|
+
session = state.streamSession;
|
|
3402
|
+
await sendText();
|
|
3403
|
+
}
|
|
2008
3404
|
} catch (error) {
|
|
2009
3405
|
state.streamFailed = true;
|
|
2010
3406
|
if (!(error instanceof SlackStreamNotDeliveredError)) {
|
|
@@ -2032,6 +3428,7 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
2032
3428
|
throw fallbackError;
|
|
2033
3429
|
}
|
|
2034
3430
|
}
|
|
3431
|
+
if (!session) return { visibleReplySent: false };
|
|
2035
3432
|
if (session.stoppedBySlack && session.pendingText) {
|
|
2036
3433
|
emitStreamedDelivery(hookContent, {
|
|
2037
3434
|
success: false,
|
|
@@ -2058,6 +3455,7 @@ function createSlackStreamingDeliveryRuntime(setup) {
|
|
|
2058
3455
|
const canFinishNativeFinal = (payload, streamReady) => payload.isError !== true && streamReady && Boolean(state.streamSession || state.interruptedThreadTs) && isStreamingEligible(payload, { maxTextBytes: 4e3 });
|
|
2059
3456
|
return Object.assign(state, {
|
|
2060
3457
|
canFinishNativeFinal,
|
|
3458
|
+
sealStream,
|
|
2061
3459
|
deliverNormally,
|
|
2062
3460
|
deliverWithStreaming,
|
|
2063
3461
|
finishStream,
|
|
@@ -2404,6 +3802,7 @@ async function dispatchSlackMessageWithSetup(setup, beginSessionRun, turnAdoptio
|
|
|
2404
3802
|
return false;
|
|
2405
3803
|
} : void 0,
|
|
2406
3804
|
onReasoningEnd: async () => {
|
|
3805
|
+
await progress.reasoningCards.seal();
|
|
2407
3806
|
await progress.onDraftBoundary?.();
|
|
2408
3807
|
return false;
|
|
2409
3808
|
},
|
|
@@ -2416,6 +3815,7 @@ async function dispatchSlackMessageWithSetup(setup, beginSessionRun, turnAdoptio
|
|
|
2416
3815
|
},
|
|
2417
3816
|
onToolStart: async (payload) => {
|
|
2418
3817
|
if (statusReactionsEnabled) await statusReactions.setTool(payload.name);
|
|
3818
|
+
if (payload.phase === "start") await progress.reasoningCards.noteToolCall();
|
|
2419
3819
|
return await progress.progressDraft.pushToolEvent(payload);
|
|
2420
3820
|
},
|
|
2421
3821
|
onItemEvent: async (payload) => {
|
|
@@ -2445,6 +3845,7 @@ async function dispatchSlackMessageWithSetup(setup, beginSessionRun, turnAdoptio
|
|
|
2445
3845
|
await progress.cancel();
|
|
2446
3846
|
if (!progress.useDraftProgressCard) await draftStream?.discardPending();
|
|
2447
3847
|
}
|
|
3848
|
+
await progress.drainNativeProgressBeforeClose();
|
|
2448
3849
|
const completionChunks = progress.useNativeProgressStreaming && !progress.nativeProgressCompletionSent ? progress.buildNativeProgressCompletionChunks(dispatchError || agentRunFailed ? "error" : progress.nativeProgressTerminalStatus) : void 0;
|
|
2449
3850
|
if (completionChunks?.length) progress.nativeProgressCompletionSent = true;
|
|
2450
3851
|
await delivery.finishStream(completionChunks);
|
|
@@ -2736,7 +4137,7 @@ const SLACK_MENTION_RESOLUTION_CONCURRENCY = 4;
|
|
|
2736
4137
|
const SLACK_MENTION_RESOLUTION_MAX_LOOKUPS_PER_MESSAGE = 20;
|
|
2737
4138
|
const SLACK_USER_MENTION_RE$1 = /<@([A-Z0-9]+)(?:\|[^>]+)?>/gi;
|
|
2738
4139
|
const MAX_SLACK_UNAVAILABLE_FILE_TEXT_CHARS = 2e3;
|
|
2739
|
-
const loadSlackMediaModule$2 = createLazyRuntimeModule(() => import("./actions-
|
|
4140
|
+
const loadSlackMediaModule$2 = createLazyRuntimeModule(() => import("./actions-DAWAKRJ9.mjs").then((n) => n._));
|
|
2740
4141
|
function formatSlackUnavailableMedia(params) {
|
|
2741
4142
|
let fileReferences = params.files?.map((file) => `${formatSlackFileReference(file)} unavailable (${file.reason})`).join(", ");
|
|
2742
4143
|
if (fileReferences && fileReferences.length > MAX_SLACK_UNAVAILABLE_FILE_TEXT_CHARS) fileReferences = `${truncateUtf16Safe(fileReferences, MAX_SLACK_UNAVAILABLE_FILE_TEXT_CHARS)}; … (file references truncated)`;
|
|
@@ -2921,7 +4322,7 @@ const SLACK_HISTORY_MEDIA_MAX_ATTACHMENTS = 4;
|
|
|
2921
4322
|
const SLACK_HISTORY_MEDIA_MAX_BYTES = 10485760;
|
|
2922
4323
|
const SLACK_HISTORY_MEDIA_IDLE_TIMEOUT_MS = 1e3;
|
|
2923
4324
|
const SLACK_HISTORY_MEDIA_TOTAL_TIMEOUT_MS = 3e3;
|
|
2924
|
-
const loadSlackMediaModule$1 = createLazyRuntimeModule(() => import("./actions-
|
|
4325
|
+
const loadSlackMediaModule$1 = createLazyRuntimeModule(() => import("./actions-DAWAKRJ9.mjs").then((n) => n._));
|
|
2925
4326
|
async function resolveSlackRoomHistory(params) {
|
|
2926
4327
|
if (params.ctx.historyLimit <= 0 || !params.message.ts) return [];
|
|
2927
4328
|
const warnOmission = (reason) => {
|
|
@@ -3067,7 +4468,7 @@ function resolveSlackGroupSessionSubject(params) {
|
|
|
3067
4468
|
return `Slack Channel (Workspace ID: ${params.workspaceId}, Channel ID: ${params.channelId})`;
|
|
3068
4469
|
}
|
|
3069
4470
|
// extensions/slack/src/monitor/message-handler/prepare-thread-context.ts
|
|
3070
|
-
const loadSlackMediaModule = createLazyRuntimeModule(() => import("./actions-
|
|
4471
|
+
const loadSlackMediaModule = createLazyRuntimeModule(() => import("./actions-DAWAKRJ9.mjs").then((n) => n._));
|
|
3071
4472
|
const SLACK_THREAD_CONTEXT_USER_LOOKUP_CONCURRENCY = 4;
|
|
3072
4473
|
function formatSlackThreadLabelSnippet(text) {
|
|
3073
4474
|
return truncateUtf16Safe(text.replace(/\s+/g, " "), 80);
|