-
Notifications
You must be signed in to change notification settings - Fork 0
feat(provider): add ZAI/GLM provider with full thinking support #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: howcode
Are you sure you want to change the base?
Conversation
- Add GLM system prompt (session/prompt/glm.txt) - Update session/system.ts to route GLM models to the new prompt - Update session/index.ts to extract token usage from metadata (fixes ZAI/Anthropic token counting)
- Add zai-coding-plan to provider priority list - Add GLM hint to auth selection - Add specific prompt instructions for ZAI API key
- Add zai-coding-plan to CUSTOM_LOADERS in provider.ts with correct baseURL - Inject default zai-coding-plan provider definition in models.ts for CLI visibility
- Implement rigorous system prompt for GLM models - Add 'Ambition vs Precision' heuristic from Codex - Add detailed workflow from Beast/Anthropic - Add strict XML constraints for steerability (no emojis, no logs) - Align with agent-architect skill best practices
- Override npm to @ai-sdk/anthropic for zai-coding-plan (fixes SDK selection from cache) - Add default thinking options (budgetTokens: 8000) for glm-4.7 - Add thinking variants: none, low (4k), medium (12k), high (24k), max (64k) - Merge model variants from ModelsDev into provider variants - Minor cleanup: remove redundant type casts in session
Summary of ChangesHello @IgorWarzocha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the platform's capabilities by integrating ZAI/GLM models as a new, fully supported provider. It ensures seamless interaction with these models by configuring the appropriate SDK, offering flexible "thinking" token budget options, and providing a specialized system prompt for optimal performance. Additionally, the changes streamline the user experience for setting up ZAI API keys within the application. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for ZAI/GLM models as a new provider. The changes are comprehensive, covering authentication, provider configuration, token usage calculation, and system prompts. The implementation looks solid, particularly the fixes for token counting in session/index.ts and the variant merging logic in provider/provider.ts. I have one suggestion in packages/opencode/src/provider/models.ts to refactor the logic for configuring the new provider, which will improve maintainability and fix a potential logic gap.
| if (parsed["zai-coding-plan"]) { | ||
| parsed["zai-coding-plan"].npm = "@ai-sdk/anthropic" | ||
| // Inject thinking options and variants for glm-4.7 if it exists in cache | ||
| if (parsed["zai-coding-plan"].models["glm-4.7"]) { | ||
| parsed["zai-coding-plan"].models["glm-4.7"].options = { | ||
| ...parsed["zai-coding-plan"].models["glm-4.7"].options, | ||
| ...glmDefaultOptions, | ||
| } | ||
| parsed["zai-coding-plan"].models["glm-4.7"].variants = glmVariants | ||
| } | ||
| } else { | ||
| parsed["zai-coding-plan"] = { | ||
| id: "zai-coding-plan", | ||
| name: "ZAI (GLM)", | ||
| env: [], | ||
| npm: "@ai-sdk/anthropic", | ||
| models: { | ||
| "glm-4.7": { | ||
| id: "glm-4.7", | ||
| name: "GLM 4.7", | ||
| release_date: "2025-11-24", | ||
| attachment: true, | ||
| reasoning: true, | ||
| temperature: true, | ||
| tool_call: true, | ||
| interleaved: true, | ||
| cost: { | ||
| input: 0, | ||
| output: 0, | ||
| }, | ||
| limit: { | ||
| context: 200000, | ||
| output: 128000, | ||
| }, | ||
| options: glmDefaultOptions, | ||
| variants: glmVariants, | ||
| }, | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for ensuring the zai-coding-plan provider is correctly configured has some room for improvement:
- Code Duplication: The entire definition for the
glm-4.7model is duplicated in theelseblock. This makes the code harder to maintain, as any updates to the model definition would need to be made in two places. - Potential Logic Flaw: If
models.devreturns azai-coding-planprovider but without theglm-4.7model, your currentifblock will not add it. The model configuration is only injected ifparsed["zai-coding-plan"].models["glm-4.7"]already exists. Theelseblock, which does create the model, is never reached.
A more robust approach is to ensure the provider and model exist, creating them if necessary, and then applying the overrides. This avoids duplication and fixes the logic gap.
const providerId = "zai-coding-plan";
const modelId = "glm-4.7";
const provider = (parsed[providerId] ??= {
id: providerId,
name: "ZAI (GLM)",
env: [],
models: {},
});
provider.npm = "@ai-sdk/anthropic";
const model = (provider.models[modelId] ??= {
id: modelId,
name: "GLM 4.7",
release_date: "2025-11-24",
attachment: true,
reasoning: true,
temperature: true,
tool_call: true,
interleaved: true,
cost: { input: 0, output: 0 },
limit: { context: 200000, output: 128000 },
options: {},
variants: {},
});
model.options = { ...model.options, ...glmDefaultOptions };
model.variants = glmVariants;Address code review feedback: - Use ??= to reduce duplication - Fix edge case where provider exists but model is missing - Cleaner, more maintainable code structure
|
@codex triple check if pr looks sound after the changes |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
/opencode verify all of this is sound. check for DRY, no excessive console logs and comments. I know for a fact it does something to models.dev.json or whatever it is called, so the changes seem to persist even when switching to upstream release build. Can you confirm/deny. And will models.dev cache get refreshed when they update the remote database? |
Analysis Complete✅ DRY PrincipleCode is DRY - uses ✅ Console LogsMinimal and appropriate - only in ✅ CommentsMinimal - only 2 lines (models.ts:92-93) explaining ZAI Anthropic compatibility. 🔍 models.dev.json BehaviorDENIED: Changes do NOT persist to cache file How it works:
Result:
✅ Cache RefreshYes, cache refreshes automatically Line 183: Refreshes every hour. When remote models.dev updates, next refresh cycle pulls new data. Verdict: Code is sound. Runtime-only modifications, no file pollution, automatic refresh works correctly. |

Summary
Add first-class support for ZAI/GLM models (GLM-4.7) as a new provider with Anthropic-compatible API.
Features
zai-coding-planprovider with GLM-4.7 modelnone: disabledlow: 4k tokensmedium: 12k tokens (default: 8k)high: 24k tokensmax: 64k tokensTechnical Changes
models.ts: Override npm to@ai-sdk/anthropicand inject thinking config for zai-coding-planprovider.ts: Merge model variants from ModelsDev into provider variantsauth.ts: Add zai-coding-plan to auth menu with helpful promptssystem.ts: Add GLM prompt selectionglm.txt: Comprehensive system prompt for GLM modelsFiles Changed
packages/opencode/src/cli/cmd/auth.tspackages/opencode/src/provider/models.tspackages/opencode/src/provider/provider.tspackages/opencode/src/session/index.tspackages/opencode/src/session/prompt/glm.txtpackages/opencode/src/session/system.ts