From 919cb4bf35a180a37c593dae10423c4615328de5 Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 2 Apr 2026 12:22:20 +0200 Subject: [PATCH] fix(local-llm): wrap @mlc-ai/web-llm in dynamic import for Docker builds Move hasModelInCache to local-llm package with dynamic import wrapper so the browser-only dependency doesn't break server-side builds. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../apps/web/src/routes/(app)/llm-test/+page.svelte | 2 +- packages/local-llm/src/cache.ts | 13 +++++++++++++ packages/local-llm/src/index.ts | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/local-llm/src/cache.ts diff --git a/apps/manacore/apps/web/src/routes/(app)/llm-test/+page.svelte b/apps/manacore/apps/web/src/routes/(app)/llm-test/+page.svelte index 2aa7f45c7..4bffd61f7 100644 --- a/apps/manacore/apps/web/src/routes/(app)/llm-test/+page.svelte +++ b/apps/manacore/apps/web/src/routes/(app)/llm-test/+page.svelte @@ -10,6 +10,7 @@ MODELS, type ModelKey, } from '@manacore/local-llm'; + import { hasModelInCache } from '@manacore/local-llm'; import { marked } from 'marked'; import { Robot, Trash, PaperPlaneRight, ClockCounterClockwise } from '@manacore/shared-icons'; @@ -29,7 +30,6 @@ if (typeof caches === 'undefined') return; for (const [key, config] of Object.entries(MODELS)) { try { - const { hasModelInCache } = await import('@mlc-ai/web-llm'); modelCacheStatus[key] = await hasModelInCache(config.modelId); } catch { modelCacheStatus[key] = false; diff --git a/packages/local-llm/src/cache.ts b/packages/local-llm/src/cache.ts new file mode 100644 index 000000000..373d4be1a --- /dev/null +++ b/packages/local-llm/src/cache.ts @@ -0,0 +1,13 @@ +/** + * Check if a model is cached in the browser's Cache API. + * Wraps @mlc-ai/web-llm's hasModelInCache with a dynamic import + * so it doesn't break SSR/Docker builds. + */ +export async function hasModelInCache(modelId: string): Promise { + try { + const { hasModelInCache: check } = await import('@mlc-ai/web-llm'); + return await check(modelId); + } catch { + return false; + } +} diff --git a/packages/local-llm/src/index.ts b/packages/local-llm/src/index.ts index 93092818f..03cd0ca33 100644 --- a/packages/local-llm/src/index.ts +++ b/packages/local-llm/src/index.ts @@ -14,6 +14,9 @@ export type { LoadingStatus, } from './types'; +// Cache utilities +export { hasModelInCache } from './cache'; + // Svelte 5 reactive helpers export { getLocalLlmStatus,