From 6d605b1bbece922c630720b4a204dfb10b1e49c3 Mon Sep 17 00:00:00 2001 From: yyyyaaa Date: Sun, 31 May 2026 22:59:21 +0700 Subject: [PATCH] fix(codegen): lazy-load @agentic-kit/ollama in embedder template The generated CLI loads every command at boot; the eager top-level @agentic-kit/ollama import crashed the CLI with MODULE_NOT_FOUND when the optional package was absent. Defer to a memoized dynamic import inside the embedder closure with a friendly error. createOllamaEmbedder/resolveEmbedder/buildEmbedder stay synchronous; --auto-embed behavior preserved. Fixes the constructive-hub cli-e2e boot crash. --- .../codegen/src/core/codegen/templates/embedder.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/graphql/codegen/src/core/codegen/templates/embedder.ts b/graphql/codegen/src/core/codegen/templates/embedder.ts index c71f255d3..2a55e6290 100644 --- a/graphql/codegen/src/core/codegen/templates/embedder.ts +++ b/graphql/codegen/src/core/codegen/templates/embedder.ts @@ -17,8 +17,6 @@ * Any changes here will affect all generated CLI embedder modules. */ -import OllamaClient from '@agentic-kit/ollama'; - // ─── Types ─────────────────────────────────────────────────────────────────── export type EmbedderFunction = (text: string) => Promise; @@ -38,8 +36,18 @@ function createOllamaEmbedder( baseUrl: string = 'http://localhost:11434', model: string = 'nomic-embed-text' ): EmbedderFunction { - const client = new OllamaClient(baseUrl); + let clientP: Promise<{ generateEmbedding: (text: string, model: string) => Promise<{ embedding: number[] }> }> | undefined; return async (text: string): Promise => { + if (!clientP) { + clientP = import('@agentic-kit/ollama') + .then((m) => new m.default(baseUrl)) + .catch(() => { + throw new Error( + 'The ollama embedder requires @agentic-kit/ollama. Install it: npm i @agentic-kit/ollama' + ); + }); + } + const client = await clientP; const result = await client.generateEmbedding(text, model); return result.embedding; };