Skip to content

fix(codegen): lazy-load @agentic-kit/ollama in embedder template#1252

Draft
yyyyaaa wants to merge 1 commit into
mainfrom
fix/embedder-lazy-import
Draft

fix(codegen): lazy-load @agentic-kit/ollama in embedder template#1252
yyyyaaa wants to merge 1 commit into
mainfrom
fix/embedder-lazy-import

Conversation

@yyyyaaa
Copy link
Copy Markdown
Contributor

@yyyyaaa yyyyaaa commented May 31, 2026

Summary

The generated CLI embedder module eagerly imports @agentic-kit/ollama at module top level. Because the generated CLI statically loads every command at boot (commands.tsagent/agent-skillembedder), this crashes the entire CLI with MODULE_NOT_FOUND whenever the optional @agentic-kit/ollama package isn't installed — even for plain CRUD commands. This broke constructive-hub's cli-e2e job after the latest SDK regeneration shipped the eager import into the committed CLI.

Fix

Defer the provider import in the codegen template (graphql/codegen/src/core/codegen/templates/embedder.ts): remove the top-level import OllamaClient from '@agentic-kit/ollama' and move it to a memoized dynamic import('@agentic-kit/ollama') inside the embedder closure, throwing a friendly "install @agentic-kit/ollama" error only if the ollama embedder is actually invoked.

  • createOllamaEmbedder / resolveEmbedder / buildEmbedder stay synchronous (no signature change → no ripple into generated agent-skill callers)
  • baseUrl / model / generateEmbedding(text, model) / result.embedding preserved
  • --auto-embed behavior unchanged; matches the existing await import() idiom in the codegen

Verification

pnpm --filter @constructive-io/graphql-codegen build passes (tsc CJS + ESM + copy:templates); the shipped dist template has no top-level @agentic-kit/ollama import. Cross-checked against the package's actual export default OllamaClient and generateEmbedding(text, model?) signature.

Follow-up

After this is published (new @constructive-io/graphql-codegen > 4.47.0), constructive-db regenerates sdk/constructive-cli/ (and adds @agentic-kit/ollama to optionalDependencies), which lets constructive-hub remove its temporary cli-e2e skip.

🤖 Generated with Claude Code

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant