fix: prevent duplicate final message when progress already shows the same text
When intermediate text was displayed as a progress message and the final result had the same content, both the progress message and a separate final message were sent to Discord. Now detects when the progress message already shows the final text and finalizes in-place without sending a duplicate.
This commit is contained in:
@@ -264,14 +264,16 @@ export class MessageTurnController {
|
|||||||
// Final arrived — flush any buffered progress that isn't the same text,
|
// Final arrived — flush any buffered progress that isn't the same text,
|
||||||
// then discard the pending buffer so it never shows up.
|
// then discard the pending buffer so it never shows up.
|
||||||
if (text) {
|
if (text) {
|
||||||
if (this.lastIntermediateText && text === this.lastIntermediateText) {
|
// If the progress message already shows the same text as the final
|
||||||
// Already sent as intermediate — skip duplicate, just finalize
|
// result, finalize it in-place instead of sending a duplicate message.
|
||||||
this.lastIntermediateText = null;
|
const alreadyVisible =
|
||||||
|
this.progressMessageId &&
|
||||||
|
this.latestProgressText === text;
|
||||||
|
if (alreadyVisible) {
|
||||||
await this.finalizeProgressMessage();
|
await this.finalizeProgressMessage();
|
||||||
this.visiblePhase = toVisiblePhase(phase);
|
this.visiblePhase = toVisiblePhase(phase);
|
||||||
this.latestProgressTextForFinal = null;
|
this.latestProgressTextForFinal = null;
|
||||||
} else {
|
} else {
|
||||||
this.lastIntermediateText = null;
|
|
||||||
await this.flushPendingProgress(text);
|
await this.flushPendingProgress(text);
|
||||||
await this.finalizeProgressMessage();
|
await this.finalizeProgressMessage();
|
||||||
await this.deliverFinalText(text);
|
await this.deliverFinalText(text);
|
||||||
|
|||||||
Reference in New Issue
Block a user