Skip to content

feat: add Zhipu (智谱) AI provider#18

Open
wjiuxing wants to merge 2 commits into
clopca:mainfrom
wjiuxing:feature/add-zhipu-provider
Open

feat: add Zhipu (智谱) AI provider#18
wjiuxing wants to merge 2 commits into
clopca:mainfrom
wjiuxing:feature/add-zhipu-provider

Conversation

@wjiuxing
Copy link
Copy Markdown

@wjiuxing wjiuxing commented May 14, 2026

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 — Added case "zhipu" to createModel() (uses @ai-sdk/openai-compatible with https://open.bigmodel.cn/api/paas/v4), createEmbeddingModel() (model embedding-3), DEFAULT_FALLBACK_MODELS (glm-4.7-flash), and resolveApiKeyForProvider()
  • src/config.ts — Added case "zhipu" → 2048 dimension, auto-detection from ZHIPU_API_KEY, API key resolution
  • src/types.ts — Updated provider type comment
  • src/config/store.ts — Added "zhipu" to dashboard provider enum
  • package.json — Added @ai-sdk/openai-compatible dependency, added --external @ai-sdk/openai-compatible to all build scripts

CLI & Wizard

  • bin/cli.mjs — Added ZHIPU_API_KEY detection, Zhipu option in wizard provider selection, zhipu label

Documentation

  • README.md — Updated to mention 6 providers
  • docs/getting-started.md — Added Zhipu config section + auto-detection table entry
  • docs/configuration.md — Added ZHIPU_API_KEY env var
  • docs/search.md — Added Zhipu to embedding provider table
  • docs/troubleshooting.md — Added ZHIPU_API_KEY to verification checklist
  • docs/index.md — Mentioned Zhipu in AI Compression feature
  • CHANGELOG.md — Added v0.15.0 entry

Testing

  • Typecheck: ✅ (tsc --noEmit clean)
  • Lint: ✅ (biome)
  • Build: ✅ (bun run build — all 8 bundles compiled)
  • Tests: 950 pass / 3 fail (pre-existing E2E lifecycle timeouts due to SQLite extension loading on this environment — unrelated to changes)

Configuration

# Free tier available — get key at https://open.bigmodel.cn/
export OPEN_MEM_PROVIDER=zhipu
export ZHIPU_API_KEY=...
export OPEN_MEM_MODEL=glm-4.7-flash  # default, free

Embedding model: embedding-3 (2048 dimensions) — enables hybrid search (FTS5 + vector).

Summary by CodeRabbit

  • New Features

    • Added Zhipu (智谱) as a supported AI provider for text compression and search embeddings with a free tier model option.
    • Zhipu provider is now auto-detectable via environment variable and selectable in the interactive setup wizard.
  • Documentation

    • Updated configuration guides, getting-started instructions, and troubleshooting documentation to include Zhipu setup and support details.

Review Change Stack

- 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
@wjiuxing wjiuxing requested a review from clopca as a code owner May 14, 2026 02:39
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@wjiuxing has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 20 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19b9773e-db1a-448b-809f-6894da2f9baa

📥 Commits

Reviewing files that changed from the base of the PR and between d759e6e and 26876dd.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • bin/cli.mjs
  • docs/index.md
  • src/config.ts
📝 Walkthrough

Walkthrough

This PR introduces support for Zhipu (智谱), an OpenAI-compatible AI provider offering text compression and embeddings capabilities. The implementation adds type contracts, provider instantiation via @ai-sdk/openai-compatible, configuration auto-detection from environment variables, CLI wizard integration, and updates documentation across the project.

Changes

Zhipu (智谱) Provider Integration

Layer / File(s) Summary
Type & Schema Contracts
src/types.ts, src/ai/provider.ts, src/config/store.ts
Provider type unions extended with "zhipu" to enable type-safe provider selection and validation schema.
Provider Implementation
src/ai/provider.ts
createModel() and createEmbeddingModel() instantiate OpenAI-compatible clients with Zhipu's baseURL; fallback models and API key resolution wired for auto-selection.
Configuration & Auto-Detection
src/config.ts
ZHIPU_API_KEY triggers auto-detection, default embedding dimension set to 2048, API credentials resolved during config initialization.
CLI Setup Wizard & Detection
bin/cli.mjs
Provider detection includes ZHIPU_API_KEY environment variable; wizard menu adds Zhipu option; provider labels render localized name for user display.
Build Dependencies
package.json
Runtime dependency @ai-sdk/openai-compatible added; marked external in build scripts to prevent bundling.
Documentation & Release Notes
CHANGELOG.md, README.md, docs/*
Changelog documents v0.15.0; README lists 6 providers; comprehensive docs updated for configuration, setup, troubleshooting, and embeddings support.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A trusty new provider hops into the warren,
Zhipu GLM models join the compression caravan,
Free tiers and embeddings, dimension 2048,
Our AI toolkit grows — no delays, no wait,
Onward through the meadow, the system's more complete! 🌱✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change—adding Zhipu as a new AI provider.
Description check ✅ Passed The description covers the changes comprehensively but does not complete the required Quality Gates and Change Checklist sections from the template.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 14, 2026

Greptile Summary

This PR integrates Zhipu (智谱) as a sixth AI provider, using @ai-sdk/openai-compatible to connect to Zhipu's OpenAI-compatible API endpoint. Changes span the provider factory, config resolution, the setup wizard, and documentation — all following the existing provider pattern.

  • src/config.ts is missing a default model override for Zhipu: users who auto-detect via ZHIPU_API_KEY without setting OPEN_MEM_MODEL will inherit "gemini-2.5-flash-lite", which Zhipu's API will reject. The openrouter provider has an identical guard at the same location that was not ported.
  • bun.lock resolves @ai-sdk/openai-compatible and three of its sub-dependencies from the Huawei Cloud npm mirror rather than the official npmjs.com registry, creating a supply chain exposure for all contributors and CI runs.

Confidence Score: 3/5

Not 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.

Security Review

  • Supply chain risk — non-standard registry in bun.lock: Four new packages (@ai-sdk/openai-compatible@2.0.47, @ai-sdk/provider@3.0.10, @ai-sdk/provider-utils@4.0.27, eventsource-parser@3.0.8) are resolved from the Huawei Cloud npm mirror instead of the official npmjs.com registry. Any developer or CI system running bun install against this lock file will download these packages from the third-party mirror. SHA512 integrity hashes are present, but the resolved origin should be the official registry for an open-source project.

Important Files Changed

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)

  1. src/config.ts, line 301-304 (link)

    P1 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.

    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.
  2. bun.lock, line 34-40 (link)

    P1 security 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.

    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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add missing zhipu env var instruction in wizard output.

On Line 814 mapping, zhipu is missing from envVarInstructions, 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 win

Tighten provider to a literal union instead of string.

On Line 129, using string weakens 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

📥 Commits

Reviewing files that changed from the base of the PR and between 11f9935 and d759e6e.

⛔ Files ignored due to path filters (2)
  • bun.lock is excluded by !**/*.lock
  • dashboard/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • CHANGELOG.md
  • README.md
  • bin/cli.mjs
  • docs/configuration.md
  • docs/getting-started.md
  • docs/index.md
  • docs/search.md
  • docs/troubleshooting.md
  • package.json
  • src/ai/provider.ts
  • src/config.ts
  • src/config/store.ts
  • src/types.ts

Comment thread docs/index.md Outdated
- 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
@wjiuxing
Copy link
Copy Markdown
Author

Thanks for the review feedback! All issues addressed in the latest push (d759e6e → follow-up commit):

Greptile P1 — Default model override: Fixed in src/config.ts. Added a guard that resets config.model to glm-4.7-flash when zhipu is detected but model is still gemini-2.5-flash-lite. Follows the same pattern as the openrouter guard.

Greptile P1 — bun.lock registry: Regenerated bun.lock with BUN_CONFIG_REGISTRY=https://registry.npmjs.org/. All Huawei Cloud mirror references removed — all packages now resolve from the official npm registry.

CodeRabbit — docs/index.md: Added OpenRouter to the provider list sentence.

CodeRabbit — envVarInstructions: Added zhipu entry to the wizard's envVarInstructions map with export ZHIPU_API_KEY=... hint.

CodeRabbit nitpick — types.ts provider union: Intentionally skipped. The existing codebase uses string for all providers — changing to a literal union is out of scope for this PR and would affect unrelated code paths. Happy to address in a follow-up if maintainers prefer.

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