惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
博客园 - Franky
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
博客园 - 司徒正美
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
博客园_首页
S
SegmentFault 最新的问题
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
H
Help Net Security
MongoDB | Blog
MongoDB | Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(telegram): render progress drafts with clean HTML tra...
snowzlmbot · 2026-06-22 · via Recent Commits to openclaw:main

@@ -30,6 +30,7 @@ import {

3030

type ChannelProgressDraftLine,

3131

type ChannelProgressDraftCompositorLine,

3232

createChannelProgressDraftCompositor,

33+

resolveChannelProgressDraftLabel,

3334

resolveChannelStreamingBlockEnabled,

3435

resolveTranscriptBackedChannelFinalText,

3536

} from "openclaw/plugin-sdk/channel-outbound";

@@ -152,7 +153,6 @@ const silentReplyDispatchLogger = createSubsystemLogger("telegram/silent-reply-d

152153153154

/** Minimum chars before sending first streaming message (improves push notification UX) */

154155

const DRAFT_MIN_INITIAL_CHARS = 30;

155-

const DRAFT_MIN_INITIAL_DELAY_MS = 5_000;

156156157157

type DraftPartialTextUpdate = {

158158

text: string;

@@ -434,18 +434,6 @@ function sanitizeProgressMarkdownText(text: string): string {

434434

return text.replaceAll("`", "'");

435435

}

436436437-

function formatProgressAsMarkdownCode(text: string): string {

438-

const clipped = clipProgressMarkdownText(text);

439-

return `\`${sanitizeProgressMarkdownText(clipped)}\``;

440-

}

441-442-

function formatTelegramProgressLine(text: string): string {

443-

const trimmed = text.trim();

444-

return trimmed.startsWith("_") && trimmed.endsWith("_")

445-

? trimmed

446-

: formatProgressAsMarkdownCode(text);

447-

}

448-449437

function escapeTelegramProgressHtml(text: string): string {

450438

return text

451439

.replaceAll("&", "&")

@@ -454,21 +442,39 @@ function escapeTelegramProgressHtml(text: string): string {

454442

.replaceAll('"', """);

455443

}

456444457-

function renderTelegramProgressStringLine(text: string): string {

458-

const clipped = clipProgressMarkdownText(text.trim());

445+

function normalizeTelegramProgressText(text: string, options?: { trim?: boolean }): string {

446+

const source = options?.trim === false ? text : text.trim();

447+

const clipped = clipProgressMarkdownText(source);

459448

const italic = clipped.match(/^_(.*)_$/u);

460449

if (italic) {

461-

return `<i>${escapeTelegramProgressHtml(italic[1] ?? "")}</i>`;

450+

return italic[1] ?? "";

451+

}

452+

return clipped;

453+

}

454+455+

function formatTelegramProgressLine(text: string): string {

456+

return sanitizeProgressMarkdownText(normalizeTelegramProgressText(text, { trim: false }));

457+

}

458+459+

function renderTelegramProgressHtmlStringLine(text: string): string {

460+

const normalized = normalizeTelegramProgressText(text);

461+

const italic = text.trim().match(/^_(.*)_$/u);

462+

if (italic) {

463+

return `<i>${escapeTelegramProgressHtml(normalized)}</i>`;

462464

}

463-

return `<code>${escapeTelegramProgressHtml(clipped)}</code>`;

465+

return `<code>${escapeTelegramProgressHtml(normalized)}</code>`;

464466

}

465467466-

function renderTelegramProgressLine(line: ChannelProgressDraftCompositorLine): string {

468+

function renderTelegramProgressHtmlLine(line: ChannelProgressDraftCompositorLine): string {

467469

if (typeof line === "string") {

468-

return line.split(/\r?\n/u).map(renderTelegramProgressStringLine).filter(Boolean).join("<br>");

470+

return line

471+

.split(/\r?\n/u)

472+

.map(renderTelegramProgressHtmlStringLine)

473+

.filter(Boolean)

474+

.join("\n");

469475

}

470476

if (!line.icon && line.label === "Commentary") {

471-

return renderTelegramProgressStringLine(line.text);

477+

return renderTelegramProgressHtmlStringLine(line.text);

472478

}

473479

const label = [line.icon, line.label].filter(Boolean).join(" ");

474480

const parts = [`<b>${escapeTelegramProgressHtml(label)}</b>`];

@@ -478,7 +484,7 @@ function renderTelegramProgressLine(line: ChannelProgressDraftCompositorLine): s

478484

} else {

479485

const text = line.text.trim();

480486

if (text && text !== label) {

481-

parts.push(renderTelegramProgressStringLine(text));

487+

parts.push(renderTelegramProgressHtmlStringLine(text));

482488

}

483489

}

484490

if (line.status && line.status !== "completed" && line.status !== line.detail) {

@@ -490,18 +496,19 @@ function renderTelegramProgressLine(line: ChannelProgressDraftCompositorLine): s

490496

function renderTelegramProgressDraftPreview(

491497

text: string,

492498

lines: readonly ChannelProgressDraftCompositorLine[],

493-

richMessages: boolean,

499+

label: string | undefined,

494500

): TelegramDraftPreview {

495501

const trimmed = text.trimEnd();

496-

const [heading] = trimmed.split(/\r?\n/u, 1);

497-

const renderedLines = lines.map(renderTelegramProgressLine).filter(Boolean);

498-

const htmlParts = heading?.trim()

499-

? [`<b>${escapeTelegramProgressHtml(heading.trim())}</b>`, ...renderedLines]

500-

: renderedLines;

501-

const html = htmlParts.join("<br>");

502-

if (!richMessages) {

503-

return { text: html, parseMode: "HTML" };

504-

}

502+

const textLines = trimmed.split(/\r?\n/u);

503+

const labelVisible =

504+

label !== undefined && (trimmed === label || (textLines[0] === label && textLines[1] === ""));

505+

const bodyLines = labelVisible ? textLines.slice(textLines[1] === "" ? 2 : 1) : textLines;

506+

const renderedLines = lines.map(renderTelegramProgressHtmlLine).filter(Boolean);

507+

const visibleLines = renderedLines.slice(-bodyLines.filter(Boolean).length);

508+

const htmlParts = labelVisible

509+

? [`<b>${escapeTelegramProgressHtml(label)}</b>`, ...visibleLines]

510+

: visibleLines;

511+

const html = htmlParts.join("\n");

505512

return {

506513

text: trimmed,

507514

richMessage: buildTelegramRichHtml(html, { skipEntityDetection: true }),

@@ -1029,7 +1036,6 @@ export const dispatchTelegramMessage = async ({

10291036

replyToMessageId: draftReplyToMessageId,

10301037

richMessages: telegramCfg.richMessages,

10311038

minInitialChars: draftMinInitialChars,

1032-

minInitialDelayMs: draftMinInitialChars > 0 ? DRAFT_MIN_INITIAL_DELAY_MS : undefined,

10331039

renderText: renderStreamText,

10341040

onSupersededPreview: (superseded) => {

10351041

if (superseded.retain) {

@@ -1107,7 +1113,7 @@ export const dispatchTelegramMessage = async ({

11071113

renderTelegramProgressDraftPreview(

11081114

streamText,

11091115

options?.lines ?? [],

1110-

telegramCfg.richMessages === true,

1116+

resolveChannelProgressDraftLabel({ entry: telegramCfg, seed: progressSeed }),

11111117

),

11121118

);

11131119

if (options?.flush) {

@@ -1389,7 +1395,7 @@ export const dispatchTelegramMessage = async ({

13891395

recomputeQueuedAnswerBlockRotations();

13901396

}

13911397

};

1392-

const updateDraftFromPartial = async (lane: DraftLaneState, update: DraftPartialTextUpdate) => {

1398+

const updateDraftFromPartial = (lane: DraftLaneState, update: DraftPartialTextUpdate) => {

13931399

const laneStream = lane.stream;

13941400

if (!laneStream || !update.text) {

13951401

return;

@@ -1401,7 +1407,6 @@ export const dispatchTelegramMessage = async ({

14011407

}

14021408

if (lane === answerLane) {

14031409

if (streamMode === "progress") {

1404-

await progressDraft.noteActivity();

14051410

return;

14061411

}

14071412

resetAnswerToolProgressDraft();

@@ -1428,7 +1433,7 @@ export const dispatchTelegramMessage = async ({

14281433

reasoningStepState.noteReasoningHint();

14291434

reasoningStepState.noteReasoningDelivered();

14301435

}

1431-

await updateDraftFromPartial(lanes[segment.lane], segment.update);

1436+

updateDraftFromPartial(lanes[segment.lane], segment.update);

14321437

}

14331438

};

14341439

const flushDraftLane = async (lane: DraftLaneState) => {

@@ -2145,9 +2150,6 @@ export const dispatchTelegramMessage = async ({

21452150

}

21462151

if (segment.lane === "answer" && info.kind === "tool") {

21472152

if (verboseProgressActive()) {

2148-

if (streamMode === "progress") {

2149-

await rotateAnswerLaneAfterToolProgress();

2150-

}

21512153

if (

21522154

await sendPayload(

21532155

applyTextToPayload(effectivePayload, segment.update.text),

@@ -2299,9 +2301,6 @@ export const dispatchTelegramMessage = async ({

22992301

}

23002302

return;

23012303

}

2302-

if (streamMode === "progress" && info.kind === "tool") {

2303-

await rotateAnswerLaneAfterToolProgress();

2304-

}

23052304

const delivered = await sendPayload(effectivePayload, {

23062305

durable: info.kind === "final",

23072306

});