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) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-02 12:22:20 +02:00
parent d574dda6a4
commit 919cb4bf35
3 changed files with 17 additions and 1 deletions

View file

@ -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;

View file

@ -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<boolean> {
try {
const { hasModelInCache: check } = await import('@mlc-ai/web-llm');
return await check(modelId);
} catch {
return false;
}
}

View file

@ -14,6 +14,9 @@ export type {
LoadingStatus,
} from './types';
// Cache utilities
export { hasModelInCache } from './cache';
// Svelte 5 reactive helpers
export {
getLocalLlmStatus,