refactor: cache reply understanding imports

This commit is contained in:
Peter Steinberger
2026-04-18 20:28:46 +01:00
parent 2b7b5774b6
commit d1fb2d25ea

View File

@@ -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<typeof import("./commands-core.runtime.js")> | 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<typeof import("../../plugins/hook-runner-global.js")> | null =
null;
let originRoutingPromise: Promise<typeof import("./origin-routing.js")> | 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,