mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
@@ -24,6 +24,15 @@ function toSafeFloor(value, fallback = null) {
|
||||
return Number.isFinite(numeric) ? Math.floor(numeric) : fallback;
|
||||
}
|
||||
|
||||
function isTavernHelperPromptViewerSyntheticGeneration(runtime) {
|
||||
if (!runtime.isTavernHelperPromptViewerRefreshActive?.()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const pendingSendIntent = runtime.getPendingRecallSendIntent?.();
|
||||
return !runtime.isFreshRecallInputRecord?.(pendingSendIntent);
|
||||
}
|
||||
|
||||
export function registerBeforeCombinePromptsController(runtime, listener) {
|
||||
const makeFirst = runtime.getEventMakeFirst();
|
||||
if (typeof makeFirst === "function") {
|
||||
@@ -251,7 +260,33 @@ export function onMessageSentController(runtime, messageId) {
|
||||
}
|
||||
|
||||
if (!message?.is_user) return;
|
||||
if (runtime.isTrivialUserInput?.(message.mes || "")?.trivial) {
|
||||
const trivialInputResult = runtime.isTrivialUserInput?.(message.mes || "") || {
|
||||
trivial: false,
|
||||
reason: "",
|
||||
normalizedText: "",
|
||||
};
|
||||
const tokenEstimate =
|
||||
typeof runtime.estimateTokens === "function"
|
||||
? Number(runtime.estimateTokens(message.mes || ""))
|
||||
: Number.NaN;
|
||||
const isZeroTokenInput =
|
||||
Number.isFinite(tokenEstimate) && tokenEstimate <= 0;
|
||||
|
||||
if (trivialInputResult.trivial || isZeroTokenInput) {
|
||||
runtime.markCurrentGenerationTrivialSkip?.({
|
||||
reason: trivialInputResult.trivial
|
||||
? trivialInputResult.reason
|
||||
: "zero-token",
|
||||
chatId: context?.chatId || "",
|
||||
chatLength: Array.isArray(chat) ? chat.length : 0,
|
||||
});
|
||||
runtime.clearPendingRecallSendIntent?.();
|
||||
runtime.clearPendingHostGenerationInputSnapshot?.();
|
||||
console.info?.(
|
||||
`[ST-BME] trivial-input skip: reason=${
|
||||
trivialInputResult.trivial ? trivialInputResult.reason : "zero-token"
|
||||
} len=${String(trivialInputResult.normalizedText || message.mes || "").length} hook=MESSAGE_SENT`,
|
||||
);
|
||||
runtime.refreshPersistedRecallMessageUi?.();
|
||||
return;
|
||||
}
|
||||
@@ -307,6 +342,21 @@ export function onGenerationStartedController(
|
||||
const generationType = String(type || "normal").trim() || "normal";
|
||||
if (generationType !== "normal") return null;
|
||||
|
||||
if (isTavernHelperPromptViewerSyntheticGeneration(runtime)) {
|
||||
const context = runtime.getContext?.() || {};
|
||||
runtime.markCurrentGenerationTrivialSkip?.({
|
||||
reason: "tavern-helper-prompt-viewer",
|
||||
chatId: context?.chatId || "",
|
||||
chatLength: Array.isArray(context?.chat) ? context.chat.length : 0,
|
||||
});
|
||||
runtime.clearPendingRecallSendIntent?.();
|
||||
runtime.clearPendingHostGenerationInputSnapshot?.();
|
||||
console.debug?.(
|
||||
"[ST-BME] skip: tavern-helper-prompt-viewer hook=GENERATION_STARTED",
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const pendingSendIntent = runtime.getPendingRecallSendIntent?.();
|
||||
const pendingIntentText = runtime.isFreshRecallInputRecord?.(
|
||||
pendingSendIntent,
|
||||
@@ -419,6 +469,8 @@ export async function onGenerationAfterCommandsController(
|
||||
return;
|
||||
}
|
||||
|
||||
const generationType = String(type || "normal").trim() || "normal";
|
||||
|
||||
if (runtime.isMvuExtraAnalysisGuardActive?.()) {
|
||||
console.debug?.(
|
||||
"[ST-BME] skip: mvu-extra-analysis hook=GENERATION_AFTER_COMMANDS",
|
||||
@@ -426,7 +478,24 @@ export async function onGenerationAfterCommandsController(
|
||||
return;
|
||||
}
|
||||
|
||||
const generationType = String(type || "normal").trim() || "normal";
|
||||
if (
|
||||
generationType === "normal" &&
|
||||
isTavernHelperPromptViewerSyntheticGeneration(runtime)
|
||||
) {
|
||||
const context = runtime.getContext?.() || {};
|
||||
runtime.markCurrentGenerationTrivialSkip?.({
|
||||
reason: "tavern-helper-prompt-viewer",
|
||||
chatId: runtime.getCurrentChatId?.() || context?.chatId || "",
|
||||
chatLength: Array.isArray(context?.chat) ? context.chat.length : 0,
|
||||
});
|
||||
runtime.clearPendingRecallSendIntent?.();
|
||||
runtime.clearPendingHostGenerationInputSnapshot?.();
|
||||
console.debug?.(
|
||||
"[ST-BME] skip: tavern-helper-prompt-viewer hook=GENERATION_AFTER_COMMANDS",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const frozenInputSnapshot =
|
||||
generationType === "normal"
|
||||
? runtime.consumeHostGenerationInputSnapshot?.({ preserve: true }) ||
|
||||
@@ -569,6 +638,24 @@ export async function onBeforeCombinePromptsController(
|
||||
};
|
||||
}
|
||||
|
||||
if (isTavernHelperPromptViewerSyntheticGeneration(runtime)) {
|
||||
const context = runtime.getContext?.() || {};
|
||||
runtime.markCurrentGenerationTrivialSkip?.({
|
||||
reason: "tavern-helper-prompt-viewer",
|
||||
chatId: runtime.getCurrentChatId?.() || context?.chatId || "",
|
||||
chatLength: Array.isArray(context?.chat) ? context.chat.length : 0,
|
||||
});
|
||||
runtime.clearPendingRecallSendIntent?.();
|
||||
runtime.clearPendingHostGenerationInputSnapshot?.();
|
||||
console.debug?.(
|
||||
"[ST-BME] skip: tavern-helper-prompt-viewer hook=GENERATE_BEFORE_COMBINE_PROMPTS",
|
||||
);
|
||||
return {
|
||||
skipped: true,
|
||||
reason: "tavern-helper-prompt-viewer",
|
||||
};
|
||||
}
|
||||
|
||||
const frozenInputSnapshot =
|
||||
runtime.consumeHostGenerationInputSnapshot?.() ||
|
||||
runtime.getPendingHostGenerationInputSnapshot?.() ||
|
||||
|
||||
40
index.js
40
index.js
@@ -6738,6 +6738,27 @@ function isMvuExtraAnalysisGuardActive(now = Date.now()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isTavernHelperPromptViewerRefreshActive() {
|
||||
try {
|
||||
const doc = globalThis?.document;
|
||||
if (!doc?.querySelectorAll) return false;
|
||||
|
||||
const dialogs = Array.from(doc.querySelectorAll('[role="dialog"]'));
|
||||
for (const dialog of dialogs) {
|
||||
const dialogText = String(dialog?.textContent || "");
|
||||
if (!/(提示词查看器|prompt\s*viewer)/i.test(dialogText)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dialog.querySelector(".fa-rotate-right.animate-spin")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isGraphEffectivelyEmpty(graph) {
|
||||
if (!graph || typeof graph !== "object") {
|
||||
return true;
|
||||
@@ -12637,8 +12658,12 @@ function onChatLoaded() {
|
||||
function onMessageSent(messageId) {
|
||||
const result = onMessageSentController(
|
||||
{
|
||||
clearPendingHostGenerationInputSnapshot,
|
||||
clearPendingRecallSendIntent,
|
||||
estimateTokens,
|
||||
getContext,
|
||||
isTrivialUserInput,
|
||||
markCurrentGenerationTrivialSkip,
|
||||
recordRecallSentUserMessage,
|
||||
rebindRecallRecordToNewUserMessage,
|
||||
refreshPersistedRecallMessageUi: schedulePersistedRecallMessageUiRefresh,
|
||||
@@ -12744,6 +12769,7 @@ function onGenerationStarted(type, params = {}, dryRun = false) {
|
||||
getPendingRecallSendIntent: () => pendingRecallSendIntent,
|
||||
getSendTextareaValue,
|
||||
isFreshRecallInputRecord,
|
||||
isTavernHelperPromptViewerRefreshActive,
|
||||
isTrivialUserInput,
|
||||
markDryRunPromptPreview,
|
||||
markCurrentGenerationTrivialSkip,
|
||||
@@ -12783,6 +12809,8 @@ async function onGenerationAfterCommands(type, params = {}, dryRun = false) {
|
||||
{
|
||||
applyFinalRecallInjectionForGeneration,
|
||||
buildGenerationAfterCommandsRecallInput,
|
||||
clearPendingHostGenerationInputSnapshot,
|
||||
clearPendingRecallSendIntent,
|
||||
clearLiveRecallInjectionPromptForRewrite,
|
||||
consumeHostGenerationInputSnapshot,
|
||||
createGenerationRecallContext,
|
||||
@@ -12790,7 +12818,12 @@ async function onGenerationAfterCommands(type, params = {}, dryRun = false) {
|
||||
getContext,
|
||||
getGenerationRecallHookStateFromResult,
|
||||
getGenerationRecallTransactionResult,
|
||||
getCurrentChatId,
|
||||
getPendingRecallSendIntent: () => pendingRecallSendIntent,
|
||||
isFreshRecallInputRecord,
|
||||
isMvuExtraAnalysisGuardActive,
|
||||
isTavernHelperPromptViewerRefreshActive,
|
||||
markCurrentGenerationTrivialSkip,
|
||||
markGenerationRecallTransactionHookState,
|
||||
resolveGenerationRecallDeliveryMode,
|
||||
runRecall,
|
||||
@@ -12808,6 +12841,8 @@ async function onBeforeCombinePrompts(promptData = null) {
|
||||
applyFinalRecallInjectionForGeneration,
|
||||
buildHistoryGenerationRecallInput,
|
||||
buildNormalGenerationRecallInput,
|
||||
clearPendingHostGenerationInputSnapshot,
|
||||
clearPendingRecallSendIntent,
|
||||
clearLiveRecallInjectionPromptForRewrite,
|
||||
consumeDryRunPromptPreview,
|
||||
consumeHostGenerationInputSnapshot,
|
||||
@@ -12815,7 +12850,12 @@ async function onBeforeCombinePrompts(promptData = null) {
|
||||
getContext,
|
||||
getGenerationRecallHookStateFromResult,
|
||||
getGenerationRecallTransactionResult,
|
||||
getCurrentChatId,
|
||||
getPendingRecallSendIntent: () => pendingRecallSendIntent,
|
||||
isFreshRecallInputRecord,
|
||||
isMvuExtraAnalysisGuardActive,
|
||||
isTavernHelperPromptViewerRefreshActive,
|
||||
markCurrentGenerationTrivialSkip,
|
||||
markGenerationRecallTransactionHookState,
|
||||
resolveGenerationRecallDeliveryMode,
|
||||
runRecall,
|
||||
|
||||
Reference in New Issue
Block a user