From 4f2f68d52c79a9e12e4ac9bfe5182a99bfc6f7c2 Mon Sep 17 00:00:00 2001 From: Reuven Date: Sun, 3 May 2026 16:42:47 -0400 Subject: [PATCH] fix(embeddings): graceful agentic-flow fallback in downloadEmbeddingModel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1700 item 2: `embeddings init` failed with `Cannot find package 'agentic-flow'` because downloadEmbeddingModel did not catch the dynamic import error, even though agentic-flow is declared as an optional peer. Now logs an informative warning and returns the target dir as a no-op success — @xenova/transformers fetches the model lazily on first embeddings_generate call. Bumps @claude-flow/embeddings to 3.0.0-alpha.13. ruflo@3.6.14 picks it up automatically via caret range. Verified in clean /tmp install: $ node -e "import('@claude-flow/embeddings').then(m => m.downloadEmbeddingModel('Xenova/all-MiniLM-L6-v2', '/tmp/test-models'))" [embeddings] agentic-flow not installed — skipping eager model download. Models will be fetched lazily by @xenova/transformers on first generate. downloadEmbeddingModel returned: "/tmp/test-models" PASS — graceful fallback worked Previously this threw "Cannot find package 'agentic-flow' imported from .../@claude-flow/embeddings/dist/neural-integration.js". Co-Authored-By: RuFlo --- v3/@claude-flow/embeddings/package.json | 2 +- .../embeddings/src/neural-integration.ts | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/v3/@claude-flow/embeddings/package.json b/v3/@claude-flow/embeddings/package.json index b8bf80984e..42b2c00f5b 100644 --- a/v3/@claude-flow/embeddings/package.json +++ b/v3/@claude-flow/embeddings/package.json @@ -1,6 +1,6 @@ { "name": "@claude-flow/embeddings", - "version": "3.0.0-alpha.12", + "version": "3.0.0-alpha.13", "description": "V3 Embedding Service - OpenAI, Transformers.js, Agentic-Flow (ONNX), Mock providers with hyperbolic embeddings, normalization, and chunking", "type": "module", "main": "./dist/index.js", diff --git a/v3/@claude-flow/embeddings/src/neural-integration.ts b/v3/@claude-flow/embeddings/src/neural-integration.ts index d7f7a1d125..5b71f5774e 100644 --- a/v3/@claude-flow/embeddings/src/neural-integration.ts +++ b/v3/@claude-flow/embeddings/src/neural-integration.ts @@ -283,13 +283,35 @@ export async function listEmbeddingModels(): Promise void ): Promise { - const { downloadModel } = await import('agentic-flow/embeddings'); - return downloadModel(modelId, targetDir ?? '.models', onProgress); + try { + const { downloadModel } = await import('agentic-flow/embeddings'); + return await downloadModel(modelId, targetDir ?? '.models', onProgress); + } catch (err) { + const msg = err instanceof Error ? err.message : String(err); + // Distinguish "package missing" from real download errors so callers + // can surface the right hint to users. + if (/Cannot find package 'agentic-flow'|Cannot find module/.test(msg)) { + console.warn('[embeddings] agentic-flow not installed — skipping eager model download. ' + + 'Models will be fetched lazily by @xenova/transformers on first generate. ' + + 'For pre-downloaded models, run: npm install agentic-flow'); + // Resolve to the target dir as a no-op completion — generate() will + // download via @xenova/transformers when first called. + return targetDir ?? '.models'; + } + throw err; + } }