|
8 | 8 | normalizeChannelProgressDraftLineIdentity, |
9 | 9 | resolveChannelProgressDraftMaxLines, |
10 | 10 | resolveChannelStreamingBlockEnabled, |
| 11 | + resolveChannelStreamingProgressCommentary, |
11 | 12 | resolveChannelStreamingPreviewToolProgress, |
12 | 13 | resolveChannelStreamingSuppressDefaultToolProgressMessages, |
13 | 14 | } from "openclaw/plugin-sdk/channel-streaming"; |
@@ -81,6 +82,8 @@ export function createDiscordDraftPreviewController(params: { |
81 | 82 | let finalReplyDelivered = false; |
82 | 83 | const previewToolProgressEnabled = |
83 | 84 | Boolean(draftStream) && resolveChannelStreamingPreviewToolProgress(params.discordConfig); |
| 85 | + const commentaryProgressEnabled = |
| 86 | + Boolean(draftStream) && resolveChannelStreamingProgressCommentary(params.discordConfig); |
84 | 87 | const suppressDefaultToolProgressMessages = |
85 | 88 | Boolean(draftStream) && |
86 | 89 | resolveChannelStreamingSuppressDefaultToolProgressMessages(params.discordConfig, { |
@@ -140,6 +143,7 @@ export function createDiscordDraftPreviewController(params: { |
140 | 143 | return { |
141 | 144 | draftStream, |
142 | 145 | previewToolProgressEnabled, |
| 146 | + commentaryProgressEnabled, |
143 | 147 | suppressDefaultToolProgressMessages, |
144 | 148 | get isProgressMode() { |
145 | 149 | return discordStreamMode === "progress"; |
@@ -266,6 +270,33 @@ export function createDiscordDraftPreviewController(params: { |
266 | 270 | await renderProgressDraft(); |
267 | 271 | } |
268 | 272 | }, |
| 273 | + async pushCommentaryProgress(text?: string, options?: { itemId?: string }) { |
| 274 | + if (!draftStream || discordStreamMode !== "progress" || !commentaryProgressEnabled || !text) { |
| 275 | + return; |
| 276 | + } |
| 277 | + if (finalReplyStarted || finalReplyDelivered) { |
| 278 | + return; |
| 279 | + } |
| 280 | + const normalized = normalizeCommentaryProgressText(text); |
| 281 | + if (!normalized) { |
| 282 | + return; |
| 283 | + } |
| 284 | + const lineId = options?.itemId?.trim() |
| 285 | + ? `commentary:${options.itemId.trim()}` |
| 286 | + : `commentary:${normalized}`; |
| 287 | + const line: ChannelProgressDraftLine = { |
| 288 | + id: lineId, |
| 289 | + kind: "item", |
| 290 | + text: normalized, |
| 291 | + label: "Commentary", |
| 292 | + prefix: false, |
| 293 | + }; |
| 294 | + previewToolProgressLines = mergeChannelProgressDraftLine(previewToolProgressLines, line, { |
| 295 | + maxLines: resolveChannelProgressDraftMaxLines(params.discordConfig), |
| 296 | + }); |
| 297 | + await progressDraftGate.startNow(); |
| 298 | + await renderProgressDraft(); |
| 299 | + }, |
269 | 300 | resolvePreviewFinalText(text?: string) { |
270 | 301 | if (typeof text !== "string") { |
271 | 302 | return undefined; |
@@ -403,6 +434,24 @@ function normalizeReasoningProgressLine(text: string): string { |
403 | 434 | .trim(); |
404 | 435 | } |
405 | 436 |
|
| 437 | +function normalizeCommentaryProgressText(text: string): string { |
| 438 | + const cleaned = stripInlineDirectiveTagsForDelivery(text).text.trim(); |
| 439 | + if (!cleaned || isSilentCommentaryProgressText(cleaned)) { |
| 440 | + return ""; |
| 441 | + } |
| 442 | + return cleaned |
| 443 | + .split(/\r?\n/u) |
| 444 | + .map((line) => line.replace(/\s+/g, " ").trim()) |
| 445 | + .filter(Boolean) |
| 446 | + .map((line) => `_${line}_`) |
| 447 | + .join("\n"); |
| 448 | +} |
| 449 | + |
| 450 | +function isSilentCommentaryProgressText(text: string): boolean { |
| 451 | + const normalized = text.replace(/^[\s*_`~]+|[\s*_`~]+$/gu, "").trim(); |
| 452 | + return /^NO_REPLY$/iu.test(normalized); |
| 453 | +} |
| 454 | + |
406 | 455 | function mergeReasoningProgressText(current: string, incoming: string): string { |
407 | 456 | if (!current) { |
408 | 457 | return incoming; |
|
0 commit comments