diff --git a/src/auto-reply/reply/get-reply.ts b/src/auto-reply/reply/get-reply.ts index 295ec03e50f..ca308d6463e 100644 --- a/src/auto-reply/reply/get-reply.ts +++ b/src/auto-reply/reply/get-reply.ts @@ -47,6 +47,13 @@ let sessionResetModelRuntimePromise: Promise< let stageSandboxMediaRuntimePromise: Promise< typeof import("./stage-sandbox-media.runtime.js") > | null = null; +let mediaUnderstandingApplyRuntimePromise: Promise< + typeof import("../../media-understanding/apply.runtime.js") +> | null = null; +let linkUnderstandingApplyRuntimePromise: Promise< + typeof import("../../link-understanding/apply.runtime.js") +> | null = null; +let commandsCoreRuntimePromise: Promise | null = null; function loadSessionResetModelRuntime() { sessionResetModelRuntimePromise ??= import("./session-reset-model.runtime.js"); @@ -58,6 +65,21 @@ function loadStageSandboxMediaRuntime() { return stageSandboxMediaRuntimePromise; } +function loadMediaUnderstandingApplyRuntime() { + mediaUnderstandingApplyRuntimePromise ??= import("../../media-understanding/apply.runtime.js"); + return mediaUnderstandingApplyRuntimePromise; +} + +function loadLinkUnderstandingApplyRuntime() { + linkUnderstandingApplyRuntimePromise ??= import("../../link-understanding/apply.runtime.js"); + return linkUnderstandingApplyRuntimePromise; +} + +function loadCommandsCoreRuntime() { + commandsCoreRuntimePromise ??= import("./commands-core.runtime.js"); + return commandsCoreRuntimePromise; +} + let hookRunnerGlobalPromise: Promise | null = null; let originRoutingPromise: Promise | null = null; @@ -126,7 +148,7 @@ async function applyMediaUnderstandingIfNeeded(params: { if (!hasInboundMedia(params.ctx)) { return false; } - const { applyMediaUnderstanding } = await import("../../media-understanding/apply.runtime.js"); + const { applyMediaUnderstanding } = await loadMediaUnderstandingApplyRuntime(); await applyMediaUnderstanding(params); return true; } @@ -138,7 +160,7 @@ async function applyLinkUnderstandingIfNeeded(params: { if (!hasLinkCandidate(params.ctx)) { return false; } - const { applyLinkUnderstanding } = await import("../../link-understanding/apply.runtime.js"); + const { applyLinkUnderstanding } = await loadLinkUnderstandingApplyRuntime(); await applyLinkUnderstanding(params); return true; } @@ -488,7 +510,7 @@ export async function getReplyFromConfig( if (!resetMatch) { return; } - const { emitResetCommandHooks } = await import("./commands-core.runtime.js"); + const { emitResetCommandHooks } = await loadCommandsCoreRuntime(); const action: ResetCommandAction = resetMatch[1] === "reset" ? "reset" : "new"; await emitResetCommandHooks({ action,