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

推荐订阅源

量子位
F
Fortinet All Blogs
J
Java Code Geeks
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
M
MIT News - Artificial intelligence
腾讯CDC
Last Week in AI
Last Week in AI
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
博客园 - 叶小钗
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
L
LangChain Blog
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

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 transcript-backed truncated finals ...
steipete · 2026-05-16 · via Recent Commits to openclaw:main

@@ -52,6 +52,10 @@ type CreateLaneTextDelivererParams = {

5252

text: string;

5353

buttons?: TelegramInlineButtons;

5454

}) => Promise<void>;

55+

resolveFinalTextCandidate?: (params: {

56+

finalText: string;

57+

laneName: LaneName;

58+

}) => Promise<string | undefined> | string | undefined;

5559

log: (message: string) => void;

5660

markDelivered: () => void;

5761

};

@@ -101,6 +105,53 @@ function compactChunks(chunks: readonly string[]): string[] {

101105

return out;

102106

}

103107108+

function stripTrailingEllipsis(text: string): string {

109+

return text.replace(/(?:\s*(?:\.{3}|\u2026))+$/u, "").trimEnd();

110+

}

111+112+

const MIN_TRUNCATED_FINAL_PREFIX_CHARS = 48;

113+

const MIN_TRUNCATED_FINAL_CONTINUATION_CHARS = 24;

114+115+

function isPotentialTruncatedFinal(finalText: string): boolean {

116+

const trimmedFinal = finalText.trimEnd();

117+

const untruncatedFinal = stripTrailingEllipsis(trimmedFinal);

118+

return (

119+

untruncatedFinal.length >= MIN_TRUNCATED_FINAL_PREFIX_CHARS && untruncatedFinal !== trimmedFinal

120+

);

121+

}

122+123+

function selectLongerPreviewForFinal(params: {

124+

finalText: string;

125+

candidateTexts: readonly (string | undefined)[];

126+

}): string | undefined {

127+

const finalText = params.finalText.trimEnd();

128+

const untruncatedFinal = stripTrailingEllipsis(finalText);

129+

if (

130+

untruncatedFinal.length < MIN_TRUNCATED_FINAL_PREFIX_CHARS ||

131+

untruncatedFinal === finalText

132+

) {

133+

return undefined;

134+

}

135+

for (const candidate of params.candidateTexts) {

136+

const candidateText = candidate?.trimEnd();

137+

if (

138+

!candidateText ||

139+

candidateText.length <= finalText.length ||

140+

!candidateText.startsWith(untruncatedFinal)

141+

) {

142+

continue;

143+

}

144+

const continuation = candidateText.slice(untruncatedFinal.length).trimStart();

145+

if (

146+

continuation.length >= MIN_TRUNCATED_FINAL_CONTINUATION_CHARS &&

147+

/^[\p{L}\p{N}]/u.test(continuation)

148+

) {

149+

return candidateText;

150+

}

151+

}

152+

return undefined;

153+

}

154+104155

export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

105156

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

106157

params.applyTextToFollowUpPayload

@@ -138,6 +189,53 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {

138189

return undefined;

139190

}

140191192+

const retainedPreview =

193+

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

194+

? selectLongerPreviewForFinal({

195+

finalText: text,

196+

candidateTexts: [

197+

await params.resolveFinalTextCandidate?.({ finalText: text, laneName }),

198+

stream.lastDeliveredText?.(),

199+

lane.lastPartialText,

200+

],

201+

})

202+

: undefined;

203+

if (retainedPreview && (!buttons || retainedPreview.length <= params.draftMaxChars)) {

204+

const previewText = retainedPreview;

205+

lane.lastPartialText = previewText;

206+

lane.hasStreamedMessage = true;

207+

await params.stopDraftLane(lane);

208+

const messageId = stream.messageId();

209+

if (typeof messageId !== "number") {

210+

if (stream.sendMayHaveLanded?.()) {

211+

lane.finalized = true;

212+

params.markDelivered();

213+

return result("preview-retained");

214+

}

215+

return undefined;

216+

}

217+

const deliveredStreamText = stream.lastDeliveredText?.();

218+

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

219+

return undefined;

220+

}

221+

if (buttons) {

222+

try {

223+

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

224+

} catch (err) {

225+

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

226+

}

227+

}

228+

for (const chunk of remainingChunks) {

229+

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

230+

continue;

231+

}

232+

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

233+

}

234+

lane.finalized = true;

235+

params.markDelivered();

236+

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

237+

}

238+141239

lane.lastPartialText = firstChunk;

142240

lane.hasStreamedMessage = true;

143241

lane.finalized = false;