Repository navigation
chore: validate Zhipu API keys during onboarding - #335
Conversation
📝 WalkthroughWalkthroughThis PR adds Zhipu (GLM) API key validation during onboarding by implementing a reusable bearer-token validation helper function, registering the zhipu provider with its specific endpoint, extending error messaging for zhipu-specific scenarios, and adding regression tests for provider validation and runtime resolution. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
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)
📝 Coding Plan for PR comments
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cli/common.rs (1)
513-515: Consider extracting the default base URL to avoid duplication.The default URL
"https://open.bigmodel.cn/api/paas/v4"is duplicated here and insrc/providers/registry.rs:100. While the testtest_zhipu_resolves_with_default_base_urlguards against drift, consider referencing thePROVIDER_REGISTRYconstant to eliminate the duplication:let spec = zeptoclaw::providers::PROVIDER_REGISTRY .iter() .find(|s| s.name == "zhipu"); let base = api_base .or(spec.and_then(|s| s.default_base_url)) .unwrap_or("https://open.bigmodel.cn/api/paas/v4");This is a minor maintenance consideration; the current approach works correctly.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cli/common.rs` around lines 513 - 515, The default base URL string is duplicated; update the zhipu branch that calls validate_bearer_models_key to derive base from the provider registry instead of hardcoding the literal. Look up the provider spec in zeptoclaw::providers::PROVIDER_REGISTRY (find where s.name == "zhipu"), use spec.default_base_url if present, then fallback to api_base and finally the original literal; adjust the code around validate_bearer_models_key to use this resolved base (preserve behavior covered by test_zhipu_resolves_with_default_base_url).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/cli/common.rs`:
- Around line 513-515: The default base URL string is duplicated; update the
zhipu branch that calls validate_bearer_models_key to derive base from the
provider registry instead of hardcoding the literal. Look up the provider spec
in zeptoclaw::providers::PROVIDER_REGISTRY (find where s.name == "zhipu"), use
spec.default_base_url if present, then fallback to api_base and finally the
original literal; adjust the code around validate_bearer_models_key to use this
resolved base (preserve behavior covered by
test_zhipu_resolves_with_default_base_url).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 79438a49-c408-4acb-9304-1c1f78ed9393
📒 Files selected for processing (4)
AGENTS.mdCLAUDE.mdsrc/cli/common.rssrc/providers/registry.rs
## Summary - add explicit Zhipu/GLM API key validation through the read-only /models endpoint - reuse the bearer /models validation path for OpenAI-compatible key checks and show Zhipu-specific help URLs on auth and billing errors - add regression coverage for Zhipu validation and default base URL resolution, and update AGENTS.md and CLAUDE.md Closes qhkm#332 ## Verification - cargo fmt -- --check - cargo clippy -- -D warnings - cargo test validate_api_key_zhipu -- --nocapture - cargo test friendly_api_error_401_zhipu -- --nocapture - cargo test zhipu_resolves_with_default_base_url -- --nocapture - cargo test --lib - cargo test --doc ## Notes - cargo nextest run --lib could not run in this environment because cargo-nextest is not installed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated provider documentation with onboarding validation details and OpenAI-compatible endpoint support notes. * **New Features** * Added support for Zhipu/GLM provider. * Enhanced provider error handling with new error types (Auth, RateLimit, Billing, ServerError, InvalidRequest, ModelNotFound, Timeout). * Per-provider model override capability. * Token-by-token streaming support via StreamEvent. * New OutputFormat options (Text, Json, JsonSchema). * **Tests** * Added Zhipu provider validation tests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Closes #332
Verification
Notes
Summary by CodeRabbit
Documentation
New Features
Tests