/** * Shared messaging for the optional local embedding stack (#525). * * `@huggingface/transformers` and `onnxruntime-node` live in optionalDependencies * (still installed by default). Remote-only/Docker installs should prune those * packages after install — do not use `--omit=optional` alone, because that also * drops Turso's platform-specific native bindings. */ export const OPTIONAL_EMBEDDING_PACKAGES = [ "@huggingface/transformers", "onnxruntime-node", ] as const; /** Packages typically removable after install for remote-only embeddings. */ export const PRUNEABLE_LOCAL_EMBEDDING_PATHS = [ "node_modules/@huggingface/transformers", "node_modules/onnxruntime-node", "node_modules/onnxruntime-web", ] as const; /** Hint appended when the optional local embedding packages are missing. */ export function formatMissingOptionalEmbeddingStackHint(): string { return ( `Local embeddings need the optional packages ${OPTIONAL_EMBEDDING_PACKAGES.join(" and ")} ` + `(installed by default). Reinstall opencode-mem without pruning those packages, or configure ` + `remote embeddings via embeddingApiUrl + embeddingApiKey. For smaller Docker images, prune ` + `${PRUNEABLE_LOCAL_EMBEDDING_PATHS.join(", ")} after install — avoid --omit=optional alone, ` + `which also drops Turso platform bindings.` ); } export function formatMissingOptionalEmbeddingStackError( packageName: string, detail?: string ): string { const detailPart = detail?.trim() ? ` ${detail.trim()}` : ""; return ( `Cannot load optional local embedding package "${packageName}".` + `${detailPart} ${formatMissingOptionalEmbeddingStackHint()}` ); } /** True when a resolve/load error looks like a missing optional package. */ export function isMissingOptionalEmbeddingPackageError(error: unknown): boolean { const message = error instanceof Error ? error.message : String(error); return ( /Cannot find (module|package)/i.test(message) || /Cannot resolve @huggingface\/transformers/i.test(message) || message.includes("ERR_MODULE_NOT_FOUND") || message.includes("MODULE_NOT_FOUND") ); }