fix(telegram): deliver transcript-backed final replies · openclaw/openclaw@20c3580
obviyus
·
2026-05-16
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -96,6 +96,8 @@ import { beginTelegramInboundTurnDeliveryCorrelation } from "./inbound-turn-deli
|
96 | 96 | import { |
97 | 97 | createLaneDeliveryStateTracker, |
98 | 98 | createLaneTextDeliverer, |
| 99 | +isPotentialTruncatedFinal, |
| 100 | +selectLongerFinalText, |
99 | 101 | type DraftLaneState, |
100 | 102 | type LaneDeliveryResult, |
101 | 103 | type LaneName, |
@@ -1260,6 +1262,13 @@ export const dispatchTelegramMessage = async ({
|
1260 | 1262 | answerLane.finalized = true; |
1261 | 1263 | return delivered ? { kind: "sent" } : { kind: "skipped" }; |
1262 | 1264 | }; |
| 1265 | +const resolveTranscriptBackedFinalText = async (text: string): Promise<string> => |
| 1266 | +isPotentialTruncatedFinal(text) |
| 1267 | + ? (selectLongerFinalText({ |
| 1268 | +finalText: text, |
| 1269 | +candidateTexts: [await resolveCurrentTurnTranscriptFinalText()], |
| 1270 | +}) ?? text) |
| 1271 | + : text; |
1263 | 1272 | |
1264 | 1273 | if (isDmTopic) { |
1265 | 1274 | try { |
@@ -1383,13 +1392,14 @@ export const dispatchTelegramMessage = async ({
|
1383 | 1392 | text: string, |
1384 | 1393 | buttons?: TelegramInlineButtons, |
1385 | 1394 | ) => { |
| 1395 | +const finalText = await resolveTranscriptBackedFinalText(text); |
1386 | 1396 | if (streamMode === "progress") { |
1387 | | -return deliverProgressModeFinalAnswer(answerPayload, text); |
| 1397 | +return deliverProgressModeFinalAnswer(answerPayload, finalText); |
1388 | 1398 | } |
1389 | 1399 | await rotateAnswerLaneAfterToolProgress(); |
1390 | 1400 | return deliverLaneText({ |
1391 | 1401 | laneName: "answer", |
1392 | | - text, |
| 1402 | +text: finalText, |
1393 | 1403 | payload: answerPayload, |
1394 | 1404 | infoKind: "final", |
1395 | 1405 | buttons, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -112,26 +112,23 @@ function stripTrailingEllipsis(text: string): string {
|
112 | 112 | const MIN_TRUNCATED_FINAL_PREFIX_CHARS = 48; |
113 | 113 | const MIN_TRUNCATED_FINAL_CONTINUATION_CHARS = 24; |
114 | 114 | |
115 | | -function isPotentialTruncatedFinal(finalText: string): boolean { |
| 115 | +export function isPotentialTruncatedFinal(finalText: string): boolean { |
116 | 116 | const trimmedFinal = finalText.trimEnd(); |
117 | 117 | const untruncatedFinal = stripTrailingEllipsis(trimmedFinal); |
118 | 118 | return ( |
119 | 119 | untruncatedFinal.length >= MIN_TRUNCATED_FINAL_PREFIX_CHARS && untruncatedFinal !== trimmedFinal |
120 | 120 | ); |
121 | 121 | } |
122 | 122 | |
123 | | -function selectLongerPreviewForFinal(params: { |
| 123 | +export function selectLongerFinalText(params: { |
124 | 124 | finalText: string; |
125 | 125 | candidateTexts: readonly (string | undefined)[]; |
126 | 126 | }): string | undefined { |
127 | 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 | | -) { |
| 128 | +if (!isPotentialTruncatedFinal(finalText)) { |
133 | 129 | return undefined; |
134 | 130 | } |
| 131 | +const untruncatedFinal = stripTrailingEllipsis(finalText); |
135 | 132 | for (const candidate of params.candidateTexts) { |
136 | 133 | const candidateText = candidate?.trimEnd(); |
137 | 134 | if ( |
@@ -191,7 +188,7 @@ export function createLaneTextDeliverer(params: CreateLaneTextDelivererParams) {
|
191 | 188 | |
192 | 189 | const retainedPreview = |
193 | 190 | isFinal && remainingChunks.length === 0 && isPotentialTruncatedFinal(text) |
194 | | - ? selectLongerPreviewForFinal({ |
| 191 | + ? selectLongerFinalText({ |
195 | 192 | finalText: text, |
196 | 193 | candidateTexts: [ |
197 | 194 | await params.resolveFinalTextCandidate?.({ finalText: text, laneName }), |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | export { |
2 | 2 | createLaneTextDeliverer, |
| 3 | +isPotentialTruncatedFinal, |
| 4 | +selectLongerFinalText, |
3 | 5 | type DraftLaneState, |
4 | 6 | type LaneDeliveryResult, |
5 | 7 | type LaneName, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。