fix(context-engine): lazy-load legacy engine registration

This commit is contained in:
Vincent Koc
2026-04-11 15:45:19 +01:00
parent 463190ed95
commit 747b26ea0f

View File

@@ -1,10 +1,28 @@
import { registerContextEngineForOwner } from "./registry.js";
import type { ContextEngine } from "./types.js";
const LEGACY_CONTEXT_ENGINE_CANDIDATES = ["./legacy.js", "./legacy.ts"] as const;
type LegacyContextEngineModule = {
LegacyContextEngine: new () => ContextEngine;
};
async function loadLegacyContextEngineModule(): Promise<LegacyContextEngineModule> {
for (const candidate of LEGACY_CONTEXT_ENGINE_CANDIDATES) {
try {
return (await import(candidate)) as LegacyContextEngineModule;
} catch {
// Try runtime/source candidates in order.
}
}
throw new Error("Failed to load legacy context engine runtime.");
}
export function registerLegacyContextEngine(): void {
registerContextEngineForOwner(
"legacy",
async () => {
const { LegacyContextEngine } = await import("./legacy.js");
const { LegacyContextEngine } = await loadLegacyContextEngineModule();
return new LegacyContextEngine();
},
"core",