Skip to content

feat(providers): add Z.AI GLM Coding Plan provider and glm-5.2 model - #2

Closed
yuanmingyi wants to merge 1 commit into
mainfrom
feat/zai-provider-update
Closed

feat(providers): add Z.AI GLM Coding Plan provider and glm-5.2 model#2
yuanmingyi wants to merge 1 commit into
mainfrom
feat/zai-provider-update

Conversation

@yuanmingyi

Copy link
Copy Markdown
Owner

What does this PR do?

Adds a dedicated zai-coding (Z.AI / GLM Coding Plan) provider as a sibling to the existing direct-API zai provider. The two share the same API-key env vars (GLM_API_KEY/ZAI_API_KEY/Z_AI_API_KEY) and may reuse each other's stored credential, but are kept on separate billing paths — direct /api/paas/v4 vs coding-plan /api/coding/paas/v4 — so a cached or legacy GLM_BASE_URL cannot bleed across endpoints (a direct key hitting the coding path returns "Insufficient balance", and vice versa). Also adds the glm-5.2 model to both providers' catalogs and to the Z.AI endpoint probe candidates.

The Z.AI endpoint-detection logic is generalized into reusable provider-family helpers (endpoint_family_providers, base_url_matches_endpoint_family, resolve_provider_endpoint_family_base_url) backed by an official-URL canonical key that normalizes default ports (:443), trailing dots/slashes, and casing, so cross-family official URLs are reliably rejected.

Related Issue

Supersedes #1 (closed prior attempt). No tracking issue — Fixes #.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

  • New provider: zai-coding ProviderConfig (hermes_cli/auth.py), ProviderProfile (plugins/model-providers/zai/__init__.py), HermesOverlay (hermes_cli/providers.py), with aliases (zai-coding-plan, z-ai-coding, glm-coding, glm-coding-plan, zhipu-coding, zhipu-coding-plan) and coding-plan base URL.
  • Model: add glm-5.2 to the zai and zai-coding catalogs (hermes_cli/models.py, hermes_cli/setup.py) and to the Z.AI endpoint probe candidates.
  • Endpoint-family isolation: split ZAI_ENDPOINTS into ZAI_DIRECT_ENDPOINTS / ZAI_CODING_ENDPOINTS; new _official_base_url_key + base_url_matches_endpoint_family guard; guards applied at all base-URL resolution sites (hermes_cli/runtime_provider.py, agent/credential_pool.py, hermes_cli/model_setup_flows.py).
  • Shared credentials: shared_credential_provider_ids() lets zai/zai-coding fall back to each other's stored pool key while the endpoint still follows the selected provider's family.
  • Setup flow: Z.AI endpoint picker (Global / China / custom proxy) in _select_endpoint_family_base_url, persisted to GLM_BASE_URL.
  • Wiring: aux model glm-5-turbo and vision model glm-5v-turbo for zai-coding (agent/auxiliary_client.py); /coding/ URL inference → zai-coding (agent/model_metadata.py); models.dev mapping (agent/models_dev.py); /model picker + PROVIDER_GROUPS, canonical providers, labels, doctor/status labels, model_normalize prefix-strip.
  • Tests: endpoint-family isolation (probe, env-override, cache), shared-credential reuse, family-guard canonicalization (:443/trailing-dot), picker fallback, and zai-coding/... normalization.

How to Test

  1. scripts/run_tests.sh tests/hermes_cli/test_api_key_providers.py tests/hermes_cli/test_runtime_provider_resolution.py tests/hermes_cli/test_model_provider_persistence.py tests/hermes_cli/test_model_validation.py tests/hermes_cli/test_model_normalize.py tests/agent/test_auxiliary_named_custom_providers.py tests/providers/test_provider_profiles.py — affected zai/coding tests pass (189 passed, 0 failed).
  2. hermes /model → Z.AI / GLM group → Coding Plan; confirm the endpoint picker offers Global / China / custom proxy and persists the choice to GLM_BASE_URL.
  3. Configure a Coding Plan key, start a session on zai-coding, and confirm requests hit https://api.z.ai/api/coding/paas/v4 (not the direct path).
  4. Switch between zai and zai-coding and confirm no cross-family base-URL bleed (stale cached/GLM_BASE_URL values are rejected with a warning and re-probed).

Checklist

Code

  • My commit messages follow Conventional Commits (feat(providers): …)
  • I searched for existing PRs to make sure this isn't a duplicate (supersedes closed feat: add Z.AI GLM coding plan provider #1)
  • My PR contains only changes related to this fix/feature (no unrelated commits; package-lock.json excluded)
  • I've run pytest tests/ -q and all tests pass — ran the affected test files (189 passed); full suite not yet run on this branch
  • I've added tests for my changes
  • I've tested on my platform: macOS 15 (darwin)

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A (provider is auto-discovered via plugins/model-providers/zai/; no new config keys)
  • I've updated cli-config.yaml.example — N/A (reuses existing GLM_API_KEY / GLM_BASE_URL)
  • I've updated CONTRIBUTING.md or AGENTS.md — N/A
  • I've considered cross-platform impact — N/A (pure-Python provider logic; no platform-specific code)

Screenshots / Logs

N/A

Add a dedicated zai-coding provider as a sibling to the direct-API zai provider. They share API-key env vars (GLM_API_KEY/ZAI_API_KEY/Z_AI_API_KEY) and may reuse each other's stored credential, but are kept on separate billing paths so a cached or legacy base URL cannot bleed across the direct (/api/paas/v4) and coding-plan (/api/coding/paas/v4) endpoints.

Add the glm-5.2 model to both the zai (direct API) and zai-coding (Coding Plan) provider catalogs and to the Z.AI endpoint probe candidates.

Generalize Z.AI endpoint detection into provider-family helpers (endpoint_family_providers, base_url_matches_endpoint_family, resolve_provider_endpoint_family_base_url) with an official-URL canonical key that normalizes default ports, trailing dots/slashes, and casing. Add endpoint-family guards at all base-URL resolution sites (runtime, credential pool, setup picker), a Z.AI endpoint picker in the setup flow, and wire zai-coding across registries, overlays, profiles, aliases, model catalogs, aux/vision models, doctor/status labels, and model-metadata URL inference while keeping its curated model list separate from the direct catalog.

Includes focused tests for endpoint-family isolation, credential sharing, the family guard, picker fallback, cache invalidation, and model normalization.
@github-actions

Copy link
Copy Markdown

🔎 Lint report: feat/zai-provider-update vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10973 on HEAD, 10962 on base (🆕 +11)

🆕 New issues (3):

Rule Count
unresolved-attribute 2
invalid-argument-type 1
First entries
tests/hermes_cli/test_runtime_provider_resolution.py:1405: [invalid-argument-type] invalid-argument-type: Argument to function `_resolve_runtime_from_pool_entry` is incorrect: Expected `PooledCredential`, found `_Entry`
tests/providers/test_provider_profiles.py:107: [unresolved-attribute] unresolved-attribute: Attribute `display_name` is not defined on `None` in union `ProviderProfile | None`
tests/providers/test_provider_profiles.py:110: [unresolved-attribute] unresolved-attribute: Attribute `fallback_models` is not defined on `None` in union `ProviderProfile | None`

✅ Fixed issues: none

Unchanged: 5773 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@yuanmingyi

Copy link
Copy Markdown
Owner Author

Redirected to upstream: NousResearch#47140 (targets NousResearch/hermes-agent:main).

@yuanmingyi yuanmingyi closed this Jun 16, 2026
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