import { createLogger } from "../logger.js";
const log = createLogger("server");
let pending = null;
function isEagerWarmupEnabled() {
  return process.env.WIGOLO_EAGER_WARMUP === "1";
}
function maybeEagerWarmup() {
  if (!isEagerWarmupEnabled()) return;
  pending = (async () => {
    await Promise.all([warmEmbed(), warmRerank()]);
  })().finally(() => {
    pending = null;
  });
}
async function warmEmbed() {
  const start = Date.now();
  try {
    const mod = await import("../providers/embed-provider.js");
    const provider = await mod.getEmbedProvider();
    if (typeof provider.warmup === "function") {
      await provider.warmup();
    }
    log.info("eager warmup: embed ready", { ms: Date.now() - start });
  } catch (err) {
    log.warn("eager warmup: embed failed", {
      ms: Date.now() - start,
      error: err instanceof Error ? err.message : String(err)
    });
  }
}
async function warmRerank() {
  const start = Date.now();
  try {
    const mod = await import("../providers/rerank-provider.js");
    const provider = await mod.getRerankProvider();
    if (typeof provider.warmup === "function") {
      await provider.warmup();
    }
    log.info("eager warmup: rerank ready", { ms: Date.now() - start });
  } catch (err) {
    log.warn("eager warmup: rerank failed", {
      ms: Date.now() - start,
      error: err instanceof Error ? err.message : String(err)
    });
  }
}
function _getWarmupPendingForTest() {
  return pending;
}
export {
  _getWarmupPendingForTest,
  isEagerWarmupEnabled,
  maybeEagerWarmup
};
//# sourceMappingURL=warmup-on-start.js.map