@@ -345,6 +345,20 @@ export async function buildReplyPayloads(params: {
|
345 | 345 | dedupedPayloads.push(...textFiltered); |
346 | 346 | } |
347 | 347 | } |
| 348 | +const directlySentTextFragmentsByAssistantMessage = new Map<number | undefined, string[]>(); |
| 349 | +for (const sentPayload of params.directlySentBlockPayloads ?? []) { |
| 350 | +const sentText = sentPayload.text ?? resolveSendableOutboundReplyParts(sentPayload).trimmedText; |
| 351 | +if (!sentText) { |
| 352 | +continue; |
| 353 | +} |
| 354 | +const assistantMessageIndex = getReplyPayloadMetadata(sentPayload)?.assistantMessageIndex; |
| 355 | +const fragments = directlySentTextFragmentsByAssistantMessage.get(assistantMessageIndex); |
| 356 | +if (fragments) { |
| 357 | +fragments.push(sentText); |
| 358 | +} else { |
| 359 | +directlySentTextFragmentsByAssistantMessage.set(assistantMessageIndex, [sentText]); |
| 360 | +} |
| 361 | +} |
348 | 362 | const isDirectlySentBlockPayload = (payload: ReplyPayload) => |
349 | 363 | Boolean(params.directlySentBlockKeys?.has(createBlockReplyContentKey(payload))); |
350 | 364 | const hasDirectlySentText = (payload: ReplyPayload): boolean => { |
@@ -355,21 +369,10 @@ export async function buildReplyPayloads(params: {
|
355 | 369 | if (!text || !params.directlySentBlockPayloads?.length) { |
356 | 370 | return false; |
357 | 371 | } |
358 | | -const fragmentsByAssistantMessage = new Map<number | undefined, string[]>(); |
359 | | -for (const sentPayload of params.directlySentBlockPayloads) { |
360 | | -const sentText = |
361 | | -sentPayload.text ?? resolveSendableOutboundReplyParts(sentPayload).trimmedText; |
362 | | -if (!sentText) { |
363 | | -continue; |
364 | | -} |
365 | | -const assistantMessageIndex = getReplyPayloadMetadata(sentPayload)?.assistantMessageIndex; |
366 | | -const fragments = fragmentsByAssistantMessage.get(assistantMessageIndex) ?? []; |
367 | | -fragments.push(sentText); |
368 | | -fragmentsByAssistantMessage.set(assistantMessageIndex, fragments); |
369 | | -} |
370 | 372 | const normalizedText = text.trim(); |
371 | 373 | const assistantMessageIndex = getReplyPayloadMetadata(payload)?.assistantMessageIndex; |
372 | | -const applicableFragments = fragmentsByAssistantMessage.get(assistantMessageIndex); |
| 374 | +const applicableFragments = |
| 375 | +directlySentTextFragmentsByAssistantMessage.get(assistantMessageIndex); |
373 | 376 | return applicableFragments ? applicableFragments.join("").trim() === normalizedText : false; |
374 | 377 | }; |
375 | 378 | const preserveUnsentMediaAfterBlockSend = (payload: ReplyPayload): ReplyPayload | null => { |
|