mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
refactor: move message received hook into event binding controller
This commit is contained in:
@@ -245,3 +245,39 @@ export async function onBeforeCombinePromptsController(runtime) {
|
|||||||
runtime.getGenerationRecallHookStateFromResult(recallResult),
|
runtime.getGenerationRecallHookStateFromResult(recallResult),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function onMessageReceivedController(runtime) {
|
||||||
|
if (runtime.getCurrentGraph()) {
|
||||||
|
if (
|
||||||
|
runtime.getGraphPersistenceState()?.pendingPersist &&
|
||||||
|
runtime.isGraphMetadataWriteAllowed()
|
||||||
|
) {
|
||||||
|
runtime.maybeFlushQueuedGraphPersist("message-received-pending-flush");
|
||||||
|
}
|
||||||
|
runtime.maybeCaptureGraphShadowSnapshot("message-received-passive-sync");
|
||||||
|
}
|
||||||
|
|
||||||
|
const pendingRecallSendIntent = runtime.getPendingRecallSendIntent();
|
||||||
|
if (
|
||||||
|
pendingRecallSendIntent?.text &&
|
||||||
|
!runtime.isFreshRecallInputRecord(pendingRecallSendIntent)
|
||||||
|
) {
|
||||||
|
runtime.setPendingRecallSendIntent(runtime.createRecallInputRecord());
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = runtime.getContext();
|
||||||
|
const chat = context?.chat;
|
||||||
|
const lastMessage =
|
||||||
|
Array.isArray(chat) && chat.length > 0 ? chat[chat.length - 1] : null;
|
||||||
|
|
||||||
|
if (runtime.isAssistantChatMessage(lastMessage)) {
|
||||||
|
runtime.queueMicrotask(() => {
|
||||||
|
void runtime.runExtraction().catch((error) => {
|
||||||
|
runtime.console.error("[ST-BME] 异步自动提取失败:", error);
|
||||||
|
runtime.notifyExtractionIssue(
|
||||||
|
error?.message || String(error) || "自动提取失败",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
48
index.js
48
index.js
@@ -64,6 +64,7 @@ import {
|
|||||||
onGenerationAfterCommandsController,
|
onGenerationAfterCommandsController,
|
||||||
onMessageDeletedController,
|
onMessageDeletedController,
|
||||||
onMessageEditedController,
|
onMessageEditedController,
|
||||||
|
onMessageReceivedController,
|
||||||
onMessageSentController,
|
onMessageSentController,
|
||||||
onMessageSwipedController,
|
onMessageSwipedController,
|
||||||
registerBeforeCombinePromptsController,
|
registerBeforeCombinePromptsController,
|
||||||
@@ -4456,36 +4457,25 @@ async function onBeforeCombinePrompts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onMessageReceived() {
|
function onMessageReceived() {
|
||||||
// 新消息到达,图状态可能需要更新
|
return onMessageReceivedController({
|
||||||
if (currentGraph) {
|
console,
|
||||||
if (graphPersistenceState.pendingPersist && isGraphMetadataWriteAllowed()) {
|
createRecallInputRecord,
|
||||||
maybeFlushQueuedGraphPersist("message-received-pending-flush");
|
getContext,
|
||||||
}
|
getCurrentGraph: () => currentGraph,
|
||||||
maybeCaptureGraphShadowSnapshot("message-received-passive-sync");
|
getGraphPersistenceState: () => graphPersistenceState,
|
||||||
}
|
getPendingRecallSendIntent: () => pendingRecallSendIntent,
|
||||||
|
isAssistantChatMessage,
|
||||||
if (
|
isFreshRecallInputRecord,
|
||||||
pendingRecallSendIntent.text &&
|
isGraphMetadataWriteAllowed,
|
||||||
!isFreshRecallInputRecord(pendingRecallSendIntent)
|
maybeCaptureGraphShadowSnapshot,
|
||||||
) {
|
maybeFlushQueuedGraphPersist,
|
||||||
pendingRecallSendIntent = createRecallInputRecord();
|
notifyExtractionIssue,
|
||||||
}
|
queueMicrotask,
|
||||||
|
runExtraction,
|
||||||
const context = getContext();
|
setPendingRecallSendIntent: (record) => {
|
||||||
const chat = context?.chat;
|
pendingRecallSendIntent = record;
|
||||||
const lastMessage =
|
},
|
||||||
Array.isArray(chat) && chat.length > 0 ? chat[chat.length - 1] : null;
|
|
||||||
|
|
||||||
if (isAssistantChatMessage(lastMessage)) {
|
|
||||||
queueMicrotask(() => {
|
|
||||||
void runExtraction().catch((error) => {
|
|
||||||
console.error("[ST-BME] 异步自动提取失败:", error);
|
|
||||||
notifyExtractionIssue(
|
|
||||||
error?.message || String(error) || "自动提取失败",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== UI 操作 ====================
|
// ==================== UI 操作 ====================
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
writeChatMetadataPatch,
|
writeChatMetadataPatch,
|
||||||
writeGraphShadowSnapshot,
|
writeGraphShadowSnapshot,
|
||||||
} from "../graph-persistence.js";
|
} from "../graph-persistence.js";
|
||||||
|
import { onMessageReceivedController } from "../event-binding.js";
|
||||||
|
|
||||||
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const indexPath = path.resolve(moduleDir, "../index.js");
|
const indexPath = path.resolve(moduleDir, "../index.js");
|
||||||
|
|||||||
Reference in New Issue
Block a user