feat(auth): add explicit Z.AI compatibility routes - #206
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughProvider compatibility is centralized for thinking, tool, token, and reasoning behavior. Z.AI is split into independent coding and API routes with separate credentials, endpoints, catalogs, model identities, CLI commands, usage adapters, and UI handling. ChangesProvider compatibility and request shaping
Z.AI routing and interfaces
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant ZAIAuth
participant ZAIEndpoint
participant Config
User->>CLI: login --z-ai-coding or --z-ai-api
CLI->>ZAIAuth: submit route-specific API key
ZAIAuth->>ZAIEndpoint: discover route models
ZAIEndpoint-->>ZAIAuth: return catalog result
ZAIAuth->>Config: save route provider and models
Config-->>User: expose route-specific model identity
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/pythinker_code/llm.py (1)
525-546: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocstring is stale — scoping isn't limited to GPT-5 anymore.
"currently the OpenAI GPT-5 family" no longer matches reality:
compatibility.supported_thinking_levelsnow also scopes Z.AI GLM models (seetest_available_model_thinking_levels_prefers_profile_override). Worth a one-line update so future readers don't assume GPT-5 is still the only scoped family.🤖 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/pythinker_code/llm.py` around lines 525 - 546, Update the docstring of available_model_thinking_levels to describe provider-specific scoping generically rather than limiting it to the OpenAI GPT-5 family, reflecting that compatibility.supported_thinking_levels also covers Z.AI GLM models. Keep the existing fallback and selection behavior unchanged.
🤖 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 `@src/pythinker_code/llm.py`:
- Around line 76-78: Update the generation-kwargs logic in the affected helper
to access llm.compatibility.output_tokens_kwarg directly, removing the getattr
and None fallback. Then update the _fake_llm() test double in
test_compaction_overflow.py to provide a valid compatibility object matching the
LLM contract, while leaving supports_deferred_tool_search unchanged.
In `@tests/core/test_create_llm.py`:
- Around line 770-887: Rewrite the affected
tests—test_create_llm_zai_glm52_activates_explicit_profile_policy,
test_create_llm_zai_binary_model_maps_minimal_to_disabled, and
test_create_llm_self_hosted_qwen_uses_chat_template_thinking_toggle—to verify
observable request JSON instead of OpenAILegacy private attributes. Use the
existing respx request-capture pattern from test_z_ai_provider_requests.py,
covering the Z.AI thinking settings, reasoning effort, token limit, and Qwen
chat-template toggle, and remove assertions requiring reportPrivateUsage
ignores.
---
Outside diff comments:
In `@src/pythinker_code/llm.py`:
- Around line 525-546: Update the docstring of available_model_thinking_levels
to describe provider-specific scoping generically rather than limiting it to the
OpenAI GPT-5 family, reflecting that compatibility.supported_thinking_levels
also covers Z.AI GLM models. Keep the existing fallback and selection behavior
unchanged.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2b06a17a-9356-44d8-9bc8-ed6616de5196
⛔ Files ignored due to path filters (5)
docs/en/configuration/env-vars.mdis excluded by!docs/**docs/en/configuration/providers.mdis excluded by!docs/**docs/en/customization/architecture.mdis excluded by!docs/**docs/en/reference/slash-commands.mdis excluded by!docs/**docs/en/release-notes/changelog.mdis excluded by!docs/**
📒 Files selected for processing (29)
CHANGELOG.mdREADME.mdpackages/pythinker-core/src/pythinker_core/contrib/chat_provider/common.pypackages/pythinker-core/src/pythinker_core/contrib/chat_provider/openai_legacy.pypackages/pythinker-core/tests/api_snapshot_tests/test_openai_legacy.pysrc/pythinker_code/auth/__init__.pysrc/pythinker_code/auth/platforms.pysrc/pythinker_code/auth/z_ai.pysrc/pythinker_code/cli/__init__.pysrc/pythinker_code/llm.pysrc/pythinker_code/provider_compatibility.pysrc/pythinker_code/soul/pythinkersoul.pysrc/pythinker_code/ui/shell/oauth.pysrc/pythinker_code/ui/shell/slash.pysrc/pythinker_code/ui/shell/usage_adapters/__init__.pysrc/pythinker_code/ui/shell/usage_adapters/z_ai.pytests/auth/test_platforms.pytests/auth/test_z_ai_auth.pytests/cli/test_z_ai_login_cli.pytests/core/test_compaction_overflow.pytests/core/test_create_llm.pytests/core/test_model_thinking_levels.pytests/core/test_provider_compatibility.pytests/core/test_tool_search_gating.pytests/core/test_z_ai_provider_requests.pytests/ui/usage_adapters/test_provider_key_coverage.pytests/ui/usage_adapters/test_z_ai.pytests/ui_and_conv/test_model_profile_thinking.pytests/ui_and_conv/test_openai_shell_login.py
|
Also updated the outside-diff |
Related Issue
N/A — planned provider-compatibility and Z.AI route work following #205.
Description
Centralizes provider/model quirks behind immutable compatibility profiles and replaces the legacy single Z.AI route with two explicit OpenAI-compatible routes:
managed:z-ai-coding/z-ai-coding/*→https://api.z.ai/api/coding/paas/v4managed:z-ai-api/z-ai-api/*→https://api.z.ai/api/paas/v4The routes have independent environment variables, login/logout, model catalogs, refresh outcomes, defaults, usage notes, and rate-limit caches. There is no credential inference, migration, alias, endpoint fallback, or cross-route retry.
Compatibility profiles now own:
OpenAILegacykeeps direct-caller model inference when replay mode is omitted, while Pythinker factory callers pass explicit policy. Z.AI replay preserves only returnedreasoning_content, in order, without synthesizing missing reasoning.Curated Z.AI behavior
glm-*remain conservative.Verification
make check-pythinker-core— exit 0; existing advisory coretydiagnostics onlymake test-pythinker-core— 414 passedmake check-pythinker-code— Ruff/format/Pyright/ty cleanmake test-pythinker-code— 7,035 passed, 9 skipped, 1 xfailedgit diff --check— cleancd docs && npm run sync— generated changelog synchronized and idempotentmanaged:z-ai,z-ai/*, andapi.z.ai/api/anthropicPrimary Z.AI documentation was revalidated for endpoint, Bearer auth, 1M/128K limits, thinking/effort mapping, exact preserved-reasoning replay, and tool streaming.
Risk review
Checklist
## Unreleasedchangelog entry.docs/en/release-notes/changelog.mdonly vianpm run sync.Summary by CodeRabbit