From ddc654eb1a5dcca3dc32404e17cddf1b53a19cb9 Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Wed, 1 Apr 2026 16:16:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=AC=E5=9B=9E?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E7=AE=A1=E7=BA=BF=E4=B8=89=E4=B8=AA=E8=87=B4?= =?UTF-8?q?=E5=91=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. recordRecallSentUserMessage 不再在 MESSAGE_SENT 阶段清空 pendingRecallSendIntent/pendingHostGenerationInputSnapshot/transactions, 避免 GENERATION_AFTER_COMMANDS 找不到用户输入而跳过召回 2. resolveGenerationRecallDeliveryMode 将 GENERATION_AFTER_COMMANDS 从 deferred 改为 immediate,使召回完成后通过 setExtensionPrompt 即时注入 3. onGenerationAfterCommandsController 在 immediate 模式下完成 runRecall 后直接返回(注入已在 applyRecallInjection 内完成), GENERATE_BEFORE_COMBINE_PROMPTS 保留 deferred rewrite 兜底 --- event-binding.js | 6 +++++- index.js | 31 +++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/event-binding.js b/event-binding.js index b542b5f..90f6a09 100644 --- a/event-binding.js +++ b/event-binding.js @@ -337,7 +337,11 @@ export async function onGenerationAfterCommandsController( ); } - if (deliveryMode === "deferred") { + // immediate 模式下,runRecall → applyRecallInjection 内部已通过 + // setExtensionPrompt 完成了注入,此处直接返回召回结果。 + // 后续 GENERATE_BEFORE_COMBINE_PROMPTS 阶段会通过 + // applyFinalRecallInjectionForGeneration 做 deferred rewrite 兜底。 + if (deliveryMode === "immediate") { return recallResult; } diff --git a/index.js b/index.js index b307383..4f0a8bb 100644 --- a/index.js +++ b/index.js @@ -1152,20 +1152,11 @@ function recordRecallSentUserMessage(messageId, text, source = "message-sent") { at: Date.now(), }); - if (pendingRecallSendIntent.hash && pendingRecallSendIntent.hash === hash) { - pendingRecallSendIntent = createRecallInputRecord(); - } - if ( - pendingHostGenerationInputSnapshot.hash && - pendingHostGenerationInputSnapshot.hash === hash - ) { - pendingHostGenerationInputSnapshot = createRecallInputRecord(); - } - - const activeChatId = getCurrentChatId(); - if (activeChatId) { - clearGenerationRecallTransactionsForChat(activeChatId); - } + // 注意:不再在 MESSAGE_SENT 阶段清空 pendingRecallSendIntent / + // pendingHostGenerationInputSnapshot / transactions。 + // 这些数据在 GENERATION_AFTER_COMMANDS 中被消费;MESSAGE_SENT 先于 + // GENERATION_AFTER_COMMANDS 触发,提前清空会导致召回拿不到用户输入。 + // 真正的消费发生在 recall 执行后(runRecallController 内部)。 return lastRecallSentUserMessage; } @@ -5477,10 +5468,14 @@ function resolveGenerationRecallDeliveryMode( return "immediate"; } - return hookName === "GENERATION_AFTER_COMMANDS" || - hookName === "GENERATE_BEFORE_COMBINE_PROMPTS" - ? "deferred" - : "immediate"; + // GENERATION_AFTER_COMMANDS: immediate —— await 完召回后直接通过 + // setExtensionPrompt 注入记忆,与 shujuku 参考实现一致。 + // GENERATE_BEFORE_COMBINE_PROMPTS: deferred —— 作为兜底,通过 promptData + // rewrite 补救注入。 + if (hookName === "GENERATE_BEFORE_COMBINE_PROMPTS") { + return "deferred"; + } + return "immediate"; } function freezeGenerationRecallOptionsForTransaction(