mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
Fix CI test compatibility on Node 20
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
onMessageReceivedController,
|
||||
onMessageSentController,
|
||||
} from "../../host/event-binding.js";
|
||||
import { isSystemMessageForExtraction } from "../../maintenance/chat-history.js";
|
||||
import { resolveAutoExtractionPlanController } from "../../maintenance/extraction-controller.js";
|
||||
import {
|
||||
GRAPH_LOAD_STATES,
|
||||
@@ -125,12 +126,22 @@ export function createGenerationRecallHarness(options = {}) {
|
||||
isTrivialUserInput,
|
||||
getAssistantTurns: (chat = []) =>
|
||||
chat.flatMap((message, index) =>
|
||||
!message?.is_user && !message?.is_system ? [index] : [],
|
||||
!message?.is_user &&
|
||||
!isSystemMessageForExtraction(message, { index, chat })
|
||||
? [index]
|
||||
: [],
|
||||
),
|
||||
isSystemMessageForExtraction,
|
||||
getLatestUserChatMessage: (chat = []) =>
|
||||
[...chat].reverse().find((message) => message?.is_user) || null,
|
||||
getLastNonSystemChatMessage: (chat = []) =>
|
||||
[...chat].reverse().find((message) => !message?.is_system) || null,
|
||||
[...chat]
|
||||
.map((message, index) => ({ message, index }))
|
||||
.reverse()
|
||||
.find(
|
||||
({ message, index }) =>
|
||||
!isSystemMessageForExtraction(message, { index, chat }),
|
||||
)?.message || null,
|
||||
getSmartTriggerDecision,
|
||||
getSendTextareaValue: () => context.__sendTextareaValue,
|
||||
getRecallUserMessageSourceLabel: (source = "") => source,
|
||||
|
||||
54
tests/helpers/register-hooks-compat.mjs
Normal file
54
tests/helpers/register-hooks-compat.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
import { register, registerHooks } from "node:module";
|
||||
|
||||
export function toDataModuleUrl(source = "") {
|
||||
return `data:text/javascript,${encodeURIComponent(String(source || ""))}`;
|
||||
}
|
||||
|
||||
export function installResolveHooks(entries = []) {
|
||||
const normalizedEntries = (Array.isArray(entries) ? entries : [])
|
||||
.map((entry) => ({
|
||||
specifiers: Array.isArray(entry?.specifiers)
|
||||
? entry.specifiers.map((value) => String(value || "")).filter(Boolean)
|
||||
: [],
|
||||
url: String(entry?.url || ""),
|
||||
}))
|
||||
.filter((entry) => entry.specifiers.length > 0 && entry.url);
|
||||
|
||||
if (typeof registerHooks === "function") {
|
||||
registerHooks({
|
||||
resolve(specifier, context, nextResolve) {
|
||||
for (const entry of normalizedEntries) {
|
||||
if (entry.specifiers.includes(specifier)) {
|
||||
return {
|
||||
shortCircuit: true,
|
||||
url: entry.url,
|
||||
};
|
||||
}
|
||||
}
|
||||
return nextResolve(specifier, context);
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof register === "function") {
|
||||
const loaderSource = `
|
||||
const entries = ${JSON.stringify(normalizedEntries)};
|
||||
export async function resolve(specifier, context, nextResolve) {
|
||||
for (const entry of entries) {
|
||||
if (Array.isArray(entry.specifiers) && entry.specifiers.includes(specifier)) {
|
||||
return {
|
||||
shortCircuit: true,
|
||||
url: entry.url,
|
||||
};
|
||||
}
|
||||
}
|
||||
return nextResolve(specifier, context);
|
||||
}
|
||||
`;
|
||||
register(toDataModuleUrl(loaderSource), import.meta.url);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error("No compatible module hook API available");
|
||||
}
|
||||
Reference in New Issue
Block a user