feat: add Zhipu (智谱) AI provider#18
Conversation
- Add Zhipu provider using @ai-sdk/openai-compatible with OpenAI-compatible API - Default model: glm-4.7-flash (free tier), embedding: embedding-3 (2048 dims) - Auto-detect from ZHIPU_API_KEY environment variable - Add to CLI wizard, dashboard config, and setup detection - Update all documentation (README, getting-started, configuration, search, troubleshooting, index) - Add CHANGELOG entry for v0.15.0
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR introduces support for Zhipu (智谱), an OpenAI-compatible AI provider offering text compression and embeddings capabilities. The implementation adds type contracts, provider instantiation via ChangesZhipu (智谱) Provider Integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR integrates Zhipu (智谱) as a sixth AI provider, using
Confidence Score: 3/5Not safe to merge as-is: Zhipu users who rely on auto-detection will silently receive the wrong default model and hit API errors, and the lock file distributes packages from a third-party registry mirror. Two real defects: Zhipu users following the documented auto-detection path will get a broken default model on every request, and the lock file bakes in Huawei Cloud as the download origin for four packages fetched by all contributors. src/config.ts needs the default model guard, and bun.lock needs to be regenerated against the official npm registry.
|
| Filename | Overview |
|---|---|
| src/ai/provider.ts | Adds Zhipu cases to createModel() and createEmbeddingModel() using @ai-sdk/openai-compatible, plus DEFAULT_FALLBACK_MODELS and resolveApiKeyForProvider() entries — pattern matches existing providers. |
| src/config.ts | Adds Zhipu embedding dimension (2048), auto-detection, and API key resolution — but missing the default-model override guard, causing Zhipu users who don't set OPEN_MEM_MODEL to receive an incorrect gemini-2.5-flash-lite default. |
| bun.lock | Adds @ai-sdk/openai-compatible@2.0.47 and sub-dependencies, but all new entries resolve from Huawei Cloud npm mirror instead of the official npmjs.com registry. |
| src/config/store.ts | Adds 'zhipu' to dashboard provider enum and also restores the previously missing 'openrouter' entry. |
| package.json | Adds @ai-sdk/openai-compatible dependency and --external flag across all 7 build scripts; changes are consistent and complete. |
| bin/cli.mjs | Adds ZHIPU_API_KEY to detectAIProviders(), wizard provider selection, and label map — consistent with existing provider pattern. |
Comments Outside Diff (2)
-
src/config.ts, line 301-304 (link)Missing default model override for Zhipu
When
OPEN_MEM_PROVIDER=zhipuis set (or auto-detected viaZHIPU_API_KEY) without an explicitOPEN_MEM_MODEL,config.modelwill remain"gemini-2.5-flash-lite"fromDEFAULT_CONFIG. Zhipu's API will reject this model name and return an error. The existingopenroutercase at this location shows the fix pattern — a parallel guard is needed forzhiputhat resets the model to"glm-4.7-flash"when still on the Google default.Prompt To Fix With AI
This is a comment left during a code review. Path: src/config.ts Line: 301-304 Comment: **Missing default model override for Zhipu** When `OPEN_MEM_PROVIDER=zhipu` is set (or auto-detected via `ZHIPU_API_KEY`) without an explicit `OPEN_MEM_MODEL`, `config.model` will remain `"gemini-2.5-flash-lite"` from `DEFAULT_CONFIG`. Zhipu's API will reject this model name and return an error. The existing `openrouter` case at this location shows the fix pattern — a parallel guard is needed for `zhipu` that resets the model to `"glm-4.7-flash"` when still on the Google default. How can I resolve this? If you propose a fix, please make it concise.
-
bun.lock, line 34-40 (link)Non-official registry URLs baked into lock file
The resolved URLs for
@ai-sdk/openai-compatible,@ai-sdk/provider@3.0.10,@ai-sdk/provider-utils@4.0.27, andeventsource-parser@3.0.8all point to the Huawei Cloud npm mirror rather than the official npm registry. Bun uses the stored URL when satisfying installs from a lock file, meaning every contributor and CI run will download these packages from the mirror instead of npmjs.com. The SHA512 checksums cover the tarball contents, but fetching from a third-party mirror is a supply chain risk for an open-source project. These entries should be regenerated against the defaulthttps://registry.npmjs.org/registry.Prompt To Fix With AI
This is a comment left during a code review. Path: bun.lock Line: 34-40 Comment: **Non-official registry URLs baked into lock file** The resolved URLs for `@ai-sdk/openai-compatible`, `@ai-sdk/provider@3.0.10`, `@ai-sdk/provider-utils@4.0.27`, and `eventsource-parser@3.0.8` all point to the Huawei Cloud npm mirror rather than the official npm registry. Bun uses the stored URL when satisfying installs from a lock file, meaning every contributor and CI run will download these packages from the mirror instead of npmjs.com. The SHA512 checksums cover the tarball contents, but fetching from a third-party mirror is a supply chain risk for an open-source project. These entries should be regenerated against the default `https://registry.npmjs.org/` registry. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
src/config.ts:301-304
**Missing default model override for Zhipu**
When `OPEN_MEM_PROVIDER=zhipu` is set (or auto-detected via `ZHIPU_API_KEY`) without an explicit `OPEN_MEM_MODEL`, `config.model` will remain `"gemini-2.5-flash-lite"` from `DEFAULT_CONFIG`. Zhipu's API will reject this model name and return an error. The existing `openrouter` case at this location shows the fix pattern — a parallel guard is needed for `zhipu` that resets the model to `"glm-4.7-flash"` when still on the Google default.
```suggestion
// Set default model for openrouter if still using the google default
if (config.provider === "openrouter" && config.model === "gemini-2.5-flash-lite") {
config.model = "google/gemini-2.5-flash-lite";
}
// Set default model for zhipu if still using the google default
if (config.provider === "zhipu" && config.model === "gemini-2.5-flash-lite") {
config.model = "glm-4.7-flash";
}
```
### Issue 2 of 2
bun.lock:34-40
**Non-official registry URLs baked into lock file**
The resolved URLs for `@ai-sdk/openai-compatible`, `@ai-sdk/provider@3.0.10`, `@ai-sdk/provider-utils@4.0.27`, and `eventsource-parser@3.0.8` all point to the Huawei Cloud npm mirror rather than the official npm registry. Bun uses the stored URL when satisfying installs from a lock file, meaning every contributor and CI run will download these packages from the mirror instead of npmjs.com. The SHA512 checksums cover the tarball contents, but fetching from a third-party mirror is a supply chain risk for an open-source project. These entries should be regenerated against the default `https://registry.npmjs.org/` registry.
Reviews (1): Last reviewed commit: "feat: add Zhipu (智谱) AI provider" | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
bin/cli.mjs (1)
814-822:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd missing
zhipuenv var instruction in wizard output.On Line 814 mapping,
zhipuis missing fromenvVarInstructions, so users who select Zhipu get no API key setup hint.🛠️ Suggested fix
const envVarInstructions = { auto: null, google: "export GOOGLE_GENERATIVE_AI_API_KEY=... # free key: https://aistudio.google.com/apikey", anthropic: "export ANTHROPIC_API_KEY=sk-ant-...", bedrock: "# Configure AWS credentials (AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY or AWS_PROFILE)", openai: "export OPENAI_API_KEY=sk-...", openrouter: "export OPENROUTER_API_KEY=sk-or-...", + zhipu: "export ZHIPU_API_KEY=...", none: null, };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bin/cli.mjs` around lines 814 - 822, The envVarInstructions mapping in bin/cli.mjs is missing an entry for the Zhipu provider, so when users pick "zhipu" the wizard prints no API-key hint; add a "zhipu" key to the envVarInstructions object (alongside auto/google/anthropic/..., e.g. "zhipu": "export ZHIPU_API_KEY=...") so the wizard shows the correct environment variable instruction for Zhipu when selected (update the envVarInstructions constant).
🧹 Nitpick comments (1)
src/types.ts (1)
129-129: ⚡ Quick winTighten
providerto a literal union instead ofstring.On Line 129, using
stringweakens compile-time validation and lets invalid providers flow until runtime errors. Prefer a closed union aligned with supported providers.♻️ Proposed change
- provider: string; // AI provider: "anthropic" | "bedrock" | "openai" | "google" | "zhipu" + provider: "anthropic" | "bedrock" | "openai" | "google" | "openrouter" | "zhipu";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/types.ts` at line 129, The provider field is currently typed as a plain string which allows invalid values; change the type of the provider property (in the relevant interface/type in types.ts) from string to a literal union of the supported values (e.g., "anthropic" | "bedrock" | "openai" | "google" | "zhipu") or define and reuse a Provider type/enum and reference it from the interface so callers get compile-time validation; update any usages of provider to use the new Provider type if necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/index.md`:
- Line 20: The provider list sentence "details: Distills raw tool outputs into
structured observations using Gemini, Claude, GPT, Bedrock, or Zhipu (智谱)." is
missing OpenRouter; update that sentence in docs/index.md to include
"OpenRouter" alongside the other providers so the list matches other
documentation and supported providers.
---
Outside diff comments:
In `@bin/cli.mjs`:
- Around line 814-822: The envVarInstructions mapping in bin/cli.mjs is missing
an entry for the Zhipu provider, so when users pick "zhipu" the wizard prints no
API-key hint; add a "zhipu" key to the envVarInstructions object (alongside
auto/google/anthropic/..., e.g. "zhipu": "export ZHIPU_API_KEY=...") so the
wizard shows the correct environment variable instruction for Zhipu when
selected (update the envVarInstructions constant).
---
Nitpick comments:
In `@src/types.ts`:
- Line 129: The provider field is currently typed as a plain string which allows
invalid values; change the type of the provider property (in the relevant
interface/type in types.ts) from string to a literal union of the supported
values (e.g., "anthropic" | "bedrock" | "openai" | "google" | "zhipu") or define
and reuse a Provider type/enum and reference it from the interface so callers
get compile-time validation; update any usages of provider to use the new
Provider type if necessary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: be1a82ab-7b3c-4b91-8da8-17f9df67b6ed
⛔ Files ignored due to path filters (2)
bun.lockis excluded by!**/*.lockdashboard/bun.lockis excluded by!**/*.lock
📒 Files selected for processing (13)
CHANGELOG.mdREADME.mdbin/cli.mjsdocs/configuration.mddocs/getting-started.mddocs/index.mddocs/search.mddocs/troubleshooting.mdpackage.jsonsrc/ai/provider.tssrc/config.tssrc/config/store.tssrc/types.ts
- Add default model override for zhipu in config.ts (P1 bug: auto-detected users would get gemini-2.5-flash-lite which Zhipu API rejects) - Regenerate bun.lock against official npmjs.org registry (supply chain fix) - Add OpenRouter to docs/index.md provider list - Add zhipu to envVarInstructions in CLI wizard
|
Thanks for the review feedback! All issues addressed in the latest push (d759e6e → follow-up commit): Greptile P1 — Default model override: Fixed in Greptile P1 — bun.lock registry: Regenerated CodeRabbit — docs/index.md: Added CodeRabbit — envVarInstructions: Added CodeRabbit nitpick — types.ts provider union: Intentionally skipped. The existing codebase uses |
Summary
Add Zhipu (智谱) as a supported AI provider for open-mem, enabling users in China and elsewhere to use Zhipu's GLM models for AI compression and embeddings.
Changes
Core
src/ai/provider.ts— Addedcase "zhipu"tocreateModel()(uses@ai-sdk/openai-compatiblewithhttps://open.bigmodel.cn/api/paas/v4),createEmbeddingModel()(modelembedding-3),DEFAULT_FALLBACK_MODELS(glm-4.7-flash), andresolveApiKeyForProvider()src/config.ts— Addedcase "zhipu"→ 2048 dimension, auto-detection fromZHIPU_API_KEY, API key resolutionsrc/types.ts— Updated provider type commentsrc/config/store.ts— Added"zhipu"to dashboard provider enumpackage.json— Added@ai-sdk/openai-compatibledependency, added--external @ai-sdk/openai-compatibleto all build scriptsCLI & Wizard
bin/cli.mjs— Added ZHIPU_API_KEY detection, Zhipu option in wizard provider selection, zhipu labelDocumentation
README.md— Updated to mention 6 providersdocs/getting-started.md— Added Zhipu config section + auto-detection table entrydocs/configuration.md— AddedZHIPU_API_KEYenv vardocs/search.md— Added Zhipu to embedding provider tabledocs/troubleshooting.md— AddedZHIPU_API_KEYto verification checklistdocs/index.md— Mentioned Zhipu in AI Compression featureCHANGELOG.md— Added v0.15.0 entryTesting
tsc --noEmitclean)bun run build— all 8 bundles compiled)Configuration
Embedding model:
embedding-3(2048 dimensions) — enables hybrid search (FTS5 + vector).Summary by CodeRabbit
New Features
Documentation