mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
diag: 添加召回管线诊断日志 [ST-BME:DIAG]
This commit is contained in:
@@ -17,17 +17,22 @@ export function registerBeforeCombinePromptsController(runtime, listener) {
|
|||||||
|
|
||||||
export function registerGenerationAfterCommandsController(runtime, listener) {
|
export function registerGenerationAfterCommandsController(runtime, listener) {
|
||||||
const makeFirst = runtime.getEventMakeFirst();
|
const makeFirst = runtime.getEventMakeFirst();
|
||||||
|
const eventName = runtime.eventTypes.GENERATION_AFTER_COMMANDS;
|
||||||
|
console.warn("[ST-BME:DIAG] Registering GENERATION_AFTER_COMMANDS:", {
|
||||||
|
eventName,
|
||||||
|
hasMakeFirst: typeof makeFirst === "function",
|
||||||
|
hasListener: typeof listener === "function",
|
||||||
|
});
|
||||||
if (typeof makeFirst === "function") {
|
if (typeof makeFirst === "function") {
|
||||||
return makeFirst(runtime.eventTypes.GENERATION_AFTER_COMMANDS, listener);
|
const cleanup = makeFirst(eventName, listener);
|
||||||
|
console.warn("[ST-BME:DIAG] Registered via makeFirst, cleanup:", typeof cleanup);
|
||||||
|
return cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.console.warn(
|
runtime.console.warn(
|
||||||
"[ST-BME] eventMakeFirst 不可用,GENERATION_AFTER_COMMANDS 回退到普通事件注册",
|
"[ST-BME] eventMakeFirst 不可用,GENERATION_AFTER_COMMANDS 回退到普通事件注册",
|
||||||
);
|
);
|
||||||
runtime.eventSource.on(
|
runtime.eventSource.on(eventName, listener);
|
||||||
runtime.eventTypes.GENERATION_AFTER_COMMANDS,
|
|
||||||
listener,
|
|
||||||
);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +268,11 @@ export async function onGenerationAfterCommandsController(
|
|||||||
params = {},
|
params = {},
|
||||||
dryRun = false,
|
dryRun = false,
|
||||||
) {
|
) {
|
||||||
if (dryRun) return;
|
console.warn("[ST-BME:DIAG] GENERATION_AFTER_COMMANDS fired", { type, dryRun, paramsKeys: Object.keys(params || {}) });
|
||||||
|
if (dryRun) {
|
||||||
|
console.warn("[ST-BME:DIAG] EXIT: dryRun=true");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const generationType = String(type || "normal").trim() || "normal";
|
const generationType = String(type || "normal").trim() || "normal";
|
||||||
const frozenInputSnapshot =
|
const frozenInputSnapshot =
|
||||||
@@ -271,9 +280,12 @@ export async function onGenerationAfterCommandsController(
|
|||||||
? runtime.consumeHostGenerationInputSnapshot?.({ preserve: true }) ||
|
? runtime.consumeHostGenerationInputSnapshot?.({ preserve: true }) ||
|
||||||
runtime.consumeHostGenerationInputSnapshot?.()
|
runtime.consumeHostGenerationInputSnapshot?.()
|
||||||
: null;
|
: null;
|
||||||
|
console.warn("[ST-BME:DIAG] frozenInputSnapshot:", frozenInputSnapshot?.text ? `"${frozenInputSnapshot.text.slice(0,50)}"` : "(empty)", "fresh:", !!frozenInputSnapshot?.at);
|
||||||
|
|
||||||
const context = runtime.getContext();
|
const context = runtime.getContext();
|
||||||
const chat = context?.chat;
|
const chat = context?.chat;
|
||||||
|
console.warn("[ST-BME:DIAG] chat length:", chat?.length, "last msg:", chat?.length ? { is_user: chat[chat.length-1]?.is_user, mes: (chat[chat.length-1]?.mes||"").slice(0,50) } : "(no chat)");
|
||||||
|
|
||||||
const recallOptions = runtime.buildGenerationAfterCommandsRecallInput(
|
const recallOptions = runtime.buildGenerationAfterCommandsRecallInput(
|
||||||
type,
|
type,
|
||||||
{
|
{
|
||||||
@@ -282,7 +294,11 @@ export async function onGenerationAfterCommandsController(
|
|||||||
},
|
},
|
||||||
chat,
|
chat,
|
||||||
);
|
);
|
||||||
if (!recallOptions) return;
|
if (!recallOptions) {
|
||||||
|
console.warn("[ST-BME:DIAG] EXIT: buildGenerationAfterCommandsRecallInput returned null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.warn("[ST-BME:DIAG] recallOptions:", { generationType: recallOptions.generationType, overrideUserMessage: recallOptions.overrideUserMessage?.slice(0,50), overrideSource: recallOptions.overrideSource, targetIdx: recallOptions.targetUserMessageIndex });
|
||||||
|
|
||||||
const recallContext = runtime.createGenerationRecallContext({
|
const recallContext = runtime.createGenerationRecallContext({
|
||||||
hookName: "GENERATION_AFTER_COMMANDS",
|
hookName: "GENERATION_AFTER_COMMANDS",
|
||||||
@@ -290,8 +306,10 @@ export async function onGenerationAfterCommandsController(
|
|||||||
recallOptions,
|
recallOptions,
|
||||||
});
|
});
|
||||||
if (!recallContext.shouldRun && !recallContext.transaction) {
|
if (!recallContext.shouldRun && !recallContext.transaction) {
|
||||||
|
console.warn("[ST-BME:DIAG] EXIT: shouldRun=false, no transaction. guardReason:", recallContext.guardReason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.warn("[ST-BME:DIAG] recallContext:", { shouldRun: recallContext.shouldRun, guardReason: recallContext.guardReason, transactionId: recallContext.transaction?.id });
|
||||||
|
|
||||||
const runtimeRecallOptions =
|
const runtimeRecallOptions =
|
||||||
recallContext.recallOptions || recallOptions || {};
|
recallContext.recallOptions || recallOptions || {};
|
||||||
@@ -304,6 +322,7 @@ export async function onGenerationAfterCommandsController(
|
|||||||
let recallResult = runtime.getGenerationRecallTransactionResult?.(
|
let recallResult = runtime.getGenerationRecallTransactionResult?.(
|
||||||
recallContext.transaction,
|
recallContext.transaction,
|
||||||
);
|
);
|
||||||
|
console.warn("[ST-BME:DIAG] deliveryMode:", deliveryMode, "shouldRun:", recallContext.shouldRun);
|
||||||
|
|
||||||
if (recallContext.shouldRun) {
|
if (recallContext.shouldRun) {
|
||||||
runtime.markGenerationRecallTransactionHookState(
|
runtime.markGenerationRecallTransactionHookState(
|
||||||
@@ -314,6 +333,7 @@ export async function onGenerationAfterCommandsController(
|
|||||||
if (deliveryMode === "deferred") {
|
if (deliveryMode === "deferred") {
|
||||||
runtime.clearLiveRecallInjectionPromptForRewrite?.();
|
runtime.clearLiveRecallInjectionPromptForRewrite?.();
|
||||||
}
|
}
|
||||||
|
console.warn("[ST-BME:DIAG] >>> Starting runRecall...");
|
||||||
recallResult = await runtime.runRecall({
|
recallResult = await runtime.runRecall({
|
||||||
...runtimeRecallOptions,
|
...runtimeRecallOptions,
|
||||||
deliveryMode,
|
deliveryMode,
|
||||||
@@ -321,6 +341,7 @@ export async function onGenerationAfterCommandsController(
|
|||||||
hookName: recallContext.hookName,
|
hookName: recallContext.hookName,
|
||||||
signal: params?.signal,
|
signal: params?.signal,
|
||||||
});
|
});
|
||||||
|
console.warn("[ST-BME:DIAG] <<< runRecall finished:", { status: recallResult?.status, ok: recallResult?.ok, reason: recallResult?.reason, injectionText: recallResult?.injectionText?.slice(0,80) });
|
||||||
runtime.storeGenerationRecallTransactionResult?.(
|
runtime.storeGenerationRecallTransactionResult?.(
|
||||||
recallContext.transaction,
|
recallContext.transaction,
|
||||||
recallResult,
|
recallResult,
|
||||||
@@ -342,6 +363,7 @@ export async function onGenerationAfterCommandsController(
|
|||||||
// 后续 GENERATE_BEFORE_COMBINE_PROMPTS 阶段会通过
|
// 后续 GENERATE_BEFORE_COMBINE_PROMPTS 阶段会通过
|
||||||
// applyFinalRecallInjectionForGeneration 做 deferred rewrite 兜底。
|
// applyFinalRecallInjectionForGeneration 做 deferred rewrite 兜底。
|
||||||
if (deliveryMode === "immediate") {
|
if (deliveryMode === "immediate") {
|
||||||
|
console.warn("[ST-BME:DIAG] DONE: immediate mode, injection via setExtensionPrompt in runRecall");
|
||||||
return recallResult;
|
return recallResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user