fix(telegram): bound tool progress preview formatting · openclaw/openclaw@f29e15c
steipete
·
2026-04-25
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -547,6 +547,30 @@ describe("dispatchTelegramMessage draft streaming", () => {
|
547 | 547 | ); |
548 | 548 | }); |
549 | 549 | |
| 550 | +it("bounds Telegram tool progress markdown preview formatting", async () => { |
| 551 | +const draftStream = createDraftStream(); |
| 552 | +createTelegramDraftStream.mockReturnValue(draftStream); |
| 553 | +const longProgress = `${"`".repeat(1000)}${"x".repeat(1000)}[label](tg://user?id=123)`; |
| 554 | +dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ replyOptions }) => { |
| 555 | +await replyOptions?.onItemEvent?.({ progressText: longProgress }); |
| 556 | +return { queuedFinal: false }; |
| 557 | +}); |
| 558 | + |
| 559 | +await dispatchWithContext({ |
| 560 | +context: createContext(), |
| 561 | +streamMode: "partial", |
| 562 | +telegramCfg: { streaming: { preview: { toolProgress: true } } }, |
| 563 | +}); |
| 564 | + |
| 565 | +const lastPreviewText = draftStream.update.mock.calls.at(-1)?.[0] ?? ""; |
| 566 | +const progressLine = lastPreviewText.split("\n").at(1) ?? ""; |
| 567 | + |
| 568 | +expect(lastPreviewText.length).toBeLessThan(340); |
| 569 | +expect(progressLine).toMatch(/^• `{10}/); |
| 570 | +expect(progressLine).toContain("…"); |
| 571 | +expect(renderTelegramHtmlText(lastPreviewText)).not.toContain("<a "); |
| 572 | +}); |
| 573 | + |
550 | 574 | it("keeps block streaming enabled when account config enables it", async () => { |
551 | 575 | dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => { |
552 | 576 | await dispatcherOptions.deliver({ text: "Hello" }, { kind: "final" }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -207,13 +207,24 @@ function resolveTelegramReasoningLevel(params: {
|
207 | 207 | return "off"; |
208 | 208 | } |
209 | 209 | |
| 210 | +const MAX_PROGRESS_MARKDOWN_TEXT_CHARS = 300; |
| 211 | +const MAX_PROGRESS_MARKDOWN_FENCE_CHARS = 10; |
| 212 | + |
| 213 | +function clipProgressMarkdownText(text: string): string { |
| 214 | +if (text.length <= MAX_PROGRESS_MARKDOWN_TEXT_CHARS) { |
| 215 | +return text; |
| 216 | +} |
| 217 | +return `${text.slice(0, MAX_PROGRESS_MARKDOWN_TEXT_CHARS - 1).trimEnd()}…`; |
| 218 | +} |
| 219 | + |
210 | 220 | function formatProgressAsMarkdownCode(text: string): string { |
| 221 | +const clipped = clipProgressMarkdownText(text); |
211 | 222 | const maxBacktickRun = Math.max( |
212 | 223 | 0, |
213 | | - ...Array.from(text.matchAll(/`+/g), (match) => match[0].length), |
| 224 | + ...Array.from(clipped.matchAll(/`+/g), (match) => match[0].length), |
214 | 225 | ); |
215 | | -const fence = "`".repeat(maxBacktickRun + 1); |
216 | | -return `${fence}${text}${fence}`; |
| 226 | +const fence = "`".repeat(Math.min(maxBacktickRun + 1, MAX_PROGRESS_MARKDOWN_FENCE_CHARS)); |
| 227 | +return `${fence}${clipped}${fence}`; |
217 | 228 | } |
218 | 229 | |
219 | 230 | export const dispatchTelegramMessage = async ({ |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。