From 1d126cddfb2001453190b8a0875c17e11437dc38 Mon Sep 17 00:00:00 2001 From: William Valentin Date: Mon, 9 Feb 2026 09:55:13 -0800 Subject: [PATCH] feat: add Zhipu AI (GLM) model provider support Adds zhipuai as a new provider using the OpenAI-compatible API at api.z.ai. Supports api_key config or ZHIPUAI_API_KEY env var, with optional endpoint override. Co-Authored-By: Claude Opus 4.6 --- CHANGELOG.md | 4 ++++ README.md | 3 ++- src/config/schema.ts | 2 +- src/daemon/clientFactory.test.ts | 9 +++++++++ src/daemon/index.ts | 6 ++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8adab1..034fd22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to Flynn are documented in this file. ### Added +- **Zhipu AI (GLM) Provider** -- Support for Zhipu AI's GLM models (glm-4.5, glm-4.7, etc.) + via their OpenAI-compatible API at `https://api.z.ai/api/paas/v4`. Uses `provider: zhipuai` + in config with `api_key` or `ZHIPUAI_API_KEY` env var. + - **Agent Tool: file.patch** -- Multi-file, multi-hunk structured patch tool. Apply line-based replacements, insertions, and deletions across multiple files in a single tool call. Hunks are applied bottom-up to preserve line numbers. 10 tests. diff --git a/README.md b/README.md index af2a470..64b8da5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Self-hosted personal AI assistant with Telegram and Terminal interfaces. ## Features - **Multi-Frontend**: Telegram bot + Terminal UI (minimal & fullscreen modes) + Web UI dashboard -- **Multi-Model**: Anthropic Claude, OpenAI, GitHub Copilot, Gemini, Bedrock, Ollama, llama.cpp with intelligent routing +- **Multi-Model**: Anthropic Claude, OpenAI, GitHub Copilot, Gemini, Bedrock, Zhipu AI (GLM), Ollama, llama.cpp with intelligent routing - **Multi-Channel**: Telegram, Discord, Slack, WhatsApp with unified adapter interface - **Web Dashboard**: SPA control panel with health monitoring, chat, session browser, and settings editor - **Model Switching**: Switch between cloud/local models on demand @@ -113,6 +113,7 @@ hooks: | Gemini | `provider: gemini`, `api_key` | | Bedrock | `provider: bedrock`, AWS credentials | | Ollama | `provider: ollama`, `model`, optional `endpoint` | +| Zhipu AI (GLM) | `provider: zhipuai`, `api_key` or `ZHIPUAI_API_KEY`, optional `endpoint` | | llama.cpp | `provider: llamacpp`, `endpoint` | ### Model Tiers diff --git a/src/config/schema.ts b/src/config/schema.ts index 92c4d49..d889494 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -19,7 +19,7 @@ const serverSchema = z.object({ }); const modelConfigBaseSchema = z.object({ - provider: z.enum(['anthropic', 'openai', 'gemini', 'ollama', 'llamacpp', 'openrouter', 'bedrock', 'github']), + provider: z.enum(['anthropic', 'openai', 'gemini', 'ollama', 'llamacpp', 'openrouter', 'bedrock', 'github', 'zhipuai']), model: z.string(), endpoint: z.string().optional(), api_key: z.string().optional(), diff --git a/src/daemon/clientFactory.test.ts b/src/daemon/clientFactory.test.ts index f98cdee..1f450b0 100644 --- a/src/daemon/clientFactory.test.ts +++ b/src/daemon/clientFactory.test.ts @@ -87,6 +87,15 @@ describe('createClientFromConfig', () => { expect(client).toBeInstanceOf(OpenAIClient); }); + it('creates OpenAIClient with Zhipu AI baseURL for zhipuai provider', () => { + const client = createClientFromConfig({ + provider: 'zhipuai', + model: 'glm-4.5', + api_key: 'test-key', + }); + expect(client).toBeInstanceOf(OpenAIClient); + }); + it('creates BedrockClient for bedrock provider', () => { const client = createClientFromConfig({ provider: 'bedrock', diff --git a/src/daemon/index.ts b/src/daemon/index.ts index 97c5a77..79b1b47 100644 --- a/src/daemon/index.ts +++ b/src/daemon/index.ts @@ -108,6 +108,12 @@ export function createClientFromConfig(cfg: ModelConfig): ModelClient { apiKey: cfg.api_key ?? process.env.OPENROUTER_API_KEY, baseURL: cfg.endpoint ?? 'https://openrouter.ai/api/v1', }); + case 'zhipuai': + return new OpenAIClient({ + model: cfg.model, + apiKey: cfg.api_key ?? process.env.ZHIPUAI_API_KEY, + baseURL: cfg.endpoint ?? 'https://api.z.ai/api/paas/v4', + }); case 'bedrock': return new BedrockClient({ model: cfg.model,