diff --git a/host/event-binding.js b/host/event-binding.js index 6bb3a0c..ab6310a 100644 --- a/host/event-binding.js +++ b/host/event-binding.js @@ -358,6 +358,11 @@ export function onMessageDeletedController( } export function onMessageEditedController(runtime, messageId, meta = null) { + if (runtime.isMvuExtraAnalysisGuardActive?.()) { + console.debug?.("[ST-BME] skip: mvu-extra-analysis hook=MESSAGE_EDITED"); + runtime.refreshPersistedRecallMessageUi?.(); + return; + } runtime.invalidateRecallAfterHistoryMutation("消息已编辑"); runtime.scheduleHistoryMutationRecheck("message-edited", messageId, meta); runtime.refreshPersistedRecallMessageUi?.(); @@ -414,6 +419,13 @@ export async function onGenerationAfterCommandsController( return; } + if (runtime.isMvuExtraAnalysisGuardActive?.()) { + console.debug?.( + "[ST-BME] skip: mvu-extra-analysis hook=GENERATION_AFTER_COMMANDS", + ); + return; + } + const generationType = String(type || "normal").trim() || "normal"; const frozenInputSnapshot = generationType === "normal" @@ -530,6 +542,16 @@ export async function onBeforeCombinePromptsController( }; } + if (runtime.isMvuExtraAnalysisGuardActive?.()) { + console.debug?.( + "[ST-BME] skip: mvu-extra-analysis hook=GENERATE_BEFORE_COMBINE_PROMPTS", + ); + return { + skipped: true, + reason: "mvu-extra-analysis", + }; + } + const frozenInputSnapshot = runtime.consumeHostGenerationInputSnapshot?.() || runtime.getPendingHostGenerationInputSnapshot?.() || diff --git a/index.js b/index.js index a0de6ea..67b86ec 100644 --- a/index.js +++ b/index.js @@ -657,6 +657,7 @@ let pendingAutoExtraction = { let isHostGenerationRunning = false; let lastHostGenerationEndedAt = 0; let skipBeforeCombineRecallUntil = 0; +let mvuExtraAnalysisGuardUntil = 0; let lastPreGenerationRecallKey = ""; let lastPreGenerationRecallAt = 0; const generationRecallTransactions = new Map(); @@ -682,6 +683,7 @@ const persistedRecallPersistDiagnosticTimestamps = new Map(); const GENERATION_RECALL_TRANSACTION_TTL_MS = 15000; const PLANNER_RECALL_HANDOFF_TTL_MS = GENERATION_RECALL_TRANSACTION_TTL_MS; const GENERATION_RECALL_HOOK_BRIDGE_MS = 1200; +const MVU_EXTRA_ANALYSIS_GUARD_TTL_MS = 2500; const stageNoticeHandles = { extraction: null, vector: null, @@ -6286,6 +6288,54 @@ function consumeDryRunPromptPreview(now = Date.now()) { return true; } +function readMvuExtraAnalysisFlag() { + try { + const sameFrameMvu = globalThis?.window?.Mvu; + if (typeof sameFrameMvu?.isDuringExtraAnalysis === "function") { + return Boolean(sameFrameMvu.isDuringExtraAnalysis()); + } + } catch {} + + try { + const parentMvu = globalThis?.window?.parent?.Mvu; + if (typeof parentMvu?.isDuringExtraAnalysis === "function") { + return Boolean(parentMvu.isDuringExtraAnalysis()); + } + } catch {} + + try { + const getActivePinia = + globalThis?.window?.getActivePinia ?? + globalThis?.window?.parent?.getActivePinia; + if (typeof getActivePinia === "function") { + const pinia = getActivePinia(); + return Boolean( + pinia?.state?.value?.["MVU变量框架"]?.runtimes?.is_during_extra_analysis, + ); + } + } catch {} + + return false; +} + +function isMvuExtraAnalysisGuardActive(now = Date.now()) { + if (readMvuExtraAnalysisFlag()) { + mvuExtraAnalysisGuardUntil = Math.max( + mvuExtraAnalysisGuardUntil, + now + MVU_EXTRA_ANALYSIS_GUARD_TTL_MS, + ); + } + + if (mvuExtraAnalysisGuardUntil <= now) { + if (mvuExtraAnalysisGuardUntil !== 0) { + mvuExtraAnalysisGuardUntil = 0; + } + return false; + } + + return true; +} + function isGraphEffectivelyEmpty(graph) { if (!graph || typeof graph !== "object") { return true; @@ -12186,6 +12236,7 @@ function onMessageEdited(messageId, meta = null) { const result = onMessageEditedController( { invalidateRecallAfterHistoryMutation, + isMvuExtraAnalysisGuardActive, refreshPersistedRecallMessageUi: schedulePersistedRecallMessageUiRefresh, scheduleHistoryMutationRecheck, }, @@ -12283,6 +12334,7 @@ async function onGenerationAfterCommands(type, params = {}, dryRun = false) { getContext, getGenerationRecallHookStateFromResult, getGenerationRecallTransactionResult, + isMvuExtraAnalysisGuardActive, markGenerationRecallTransactionHookState, resolveGenerationRecallDeliveryMode, runRecall, @@ -12307,6 +12359,7 @@ async function onBeforeCombinePrompts(promptData = null) { getContext, getGenerationRecallHookStateFromResult, getGenerationRecallTransactionResult, + isMvuExtraAnalysisGuardActive, markGenerationRecallTransactionHookState, resolveGenerationRecallDeliveryMode, runRecall,