From 747b26ea0ff92f836e2fedd9772f9217435bb2b6 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 11 Apr 2026 15:45:19 +0100 Subject: [PATCH] fix(context-engine): lazy-load legacy engine registration --- src/context-engine/legacy.registration.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/context-engine/legacy.registration.ts b/src/context-engine/legacy.registration.ts index 4c035db5717..e7e414421e1 100644 --- a/src/context-engine/legacy.registration.ts +++ b/src/context-engine/legacy.registration.ts @@ -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 { + 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",