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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
罗磊的独立博客
量子位
Jina AI
Jina AI
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
美团技术团队
雷峰网
雷峰网
爱范儿
爱范儿
S
SegmentFault 最新的问题
小众软件
小众软件
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

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): retain streamed long final prefixes · open...
obviyus · 2026-05-28 · via Recent Commits to openclaw:main

@@ -115,6 +115,15 @@ function compactChunks(chunks: readonly string[]): string[] {

115115

return out;

116116

}

117117118+

function isDeliveredPrefix(params: { deliveredText: string | undefined; finalText: string }) {

119+

if (!params.deliveredText || params.deliveredText.length === 0) {

120+

return false;

121+

}

122+

return (

123+

params.finalText === params.deliveredText || params.finalText.startsWith(params.deliveredText)

124+

);

125+

}

126+118127

export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

119128

const followUpPayload = (payload: ReplyPayload, text: string) =>

120129

params.applyTextToFollowUpPayload

@@ -270,6 +279,53 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

270279

if (!firstChunk || firstChunk.length > params.draftMaxChars) {

271280

return undefined;

272281

}

282+

const finalText = text.trimEnd();

283+

const deliveredStreamTextBeforeUpdate = stream.lastDeliveredText?.();

284+

const deliveredPrefixBeforeUpdate =

285+

isFinal &&

286+

deliveredStreamTextBeforeUpdate !== undefined &&

287+

isDeliveredPrefix({

288+

deliveredText: deliveredStreamTextBeforeUpdate,

289+

finalText,

290+

}) &&

291+

deliveredStreamTextBeforeUpdate.length > firstChunk.trimEnd().length;

292+

const finalizeDeliveredPrefix = async (

293+

deliveredStreamText: string,

294+

messageId: number,

295+

): Promise<LaneDeliveryResult> => {

296+

lane.finalized = true;

297+

params.markDelivered();

298+

let buttonsAttached = false;

299+

if (buttons) {

300+

const deliveredChunks = compactChunks(

301+

params.splitFinalTextForStream?.(deliveredStreamText) ?? [],

302+

);

303+

const currentChunk = deliveredChunks.at(-1);

304+

if (currentChunk && currentChunk.length <= params.draftMaxChars) {

305+

try {

306+

await params.editStreamMessage({ laneName, messageId, text: currentChunk, buttons });

307+

buttonsAttached = true;

308+

} catch (err) {

309+

params.log(`telegram: ${laneName} stream button edit failed: ${String(err)}`);

310+

}

311+

}

312+

}

313+

const suffix = finalText.slice(deliveredStreamText.length);

314+

if (suffix.trim().length > 0) {

315+

for (const chunk of compactChunks(params.splitFinalTextForStream?.(suffix) ?? [])) {

316+

if (chunk.trim().length === 0) {

317+

continue;

318+

}

319+

await params.sendPayload(followUpPayload(payload, chunk));

320+

}

321+

}

322+

return result("preview-finalized", {

323+

content: text,

324+

promptContextContent: deliveredStreamText,

325+

messageId,

326+

buttonsAttached,

327+

});

328+

};

273329274330

const retainedPreview =

275331

isFinal && remainingChunks.length === 0 && isPotentialTruncatedFinal(text)

@@ -296,8 +352,11 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

296352

}

297353

return undefined;

298354

}

299-

const deliveredStreamText = stream.lastDeliveredText?.();

300-

if (deliveredStreamText !== undefined && deliveredStreamText !== previewText) {

355+

const deliveredStreamTextAfterStop = stream.lastDeliveredText?.();

356+

if (

357+

deliveredStreamTextAfterStop !== undefined &&

358+

deliveredStreamTextAfterStop !== previewText

359+

) {

301360

return undefined;

302361

}

303362

let buttonsAttached = false;

@@ -320,10 +379,12 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

320379

return result("preview-finalized", { content: previewText, messageId, buttonsAttached });

321380

}

322381323-

lane.lastPartialText = firstChunk;

324-

lane.hasStreamedMessage = true;

325-

lane.finalized = false;

326-

stream.update(firstChunk);

382+

if (!deliveredPrefixBeforeUpdate) {

383+

lane.lastPartialText = firstChunk;

384+

lane.hasStreamedMessage = true;

385+

lane.finalized = false;

386+

stream.update(firstChunk);

387+

}

327388

if (isFinal) {

328389

await params.stopDraftLane(lane);

329390

} else {

@@ -340,15 +401,25 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

340401

return undefined;

341402

}

342403343-

const deliveredStreamText = stream.lastDeliveredText?.();

404+

const deliveredStreamTextAfterStop = stream.lastDeliveredText?.();

344405

if (

345406

isFinal &&

346-

deliveredStreamText !== undefined &&

347-

deliveredStreamText !== firstChunk.trimEnd()

407+

deliveredStreamTextAfterStop !== undefined &&

408+

deliveredStreamTextAfterStop !== firstChunk.trimEnd()

348409

) {

410+

if (

411+

isDeliveredPrefix({ deliveredText: deliveredStreamTextAfterStop, finalText }) &&

412+

deliveredStreamTextAfterStop.length > firstChunk.trimEnd().length

413+

) {

414+

return await finalizeDeliveredPrefix(deliveredStreamTextAfterStop, messageId);

415+

}

349416

return undefined;

350417

}

351418419+

if (deliveredPrefixBeforeUpdate && deliveredStreamTextAfterStop === undefined) {

420+

return await finalizeDeliveredPrefix(deliveredStreamTextBeforeUpdate, messageId);

421+

}

422+352423

params.markDelivered();

353424

let buttonsAttached = false;

354425

if (buttons) {