Skip to content

Commit 8539724

Browse files
systemimeclaude
andcommitted
feat: add Anthropic format compatibility and mock models terminal logging
- Add use_anthropic config option for Anthropic protocol compatibility - Fix null values in JSON Schema (required, enum, items, properties, etc.) - Convert Anthropic input_schema to OpenAI parameters format - Add terminal logging for mock models requests - Bump version to 0.8.4 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0243263 commit 8539724

6 files changed

Lines changed: 433 additions & 11 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Variables
44
APP_NAME := mask-ctl
55
SERVICE_BINARY := coding-plan-mask
6-
VERSION := 0.8.3
6+
VERSION := 0.8.4
77
BUILD_DIR := build
88
BIN_DIR := $(BUILD_DIR)/bin
99
CMD_DIR := cmd/coding-plan-mask

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[![Go Version](https://img.shields.io/badge/Go-1.21+-00ADD8?style=flat&logo=go)](https://golang.org/)
88
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
9-
[![Version](https://img.shields.io/badge/version-0.8.3-green.svg)](https://github.com/systemime/coding-plan-mask)
9+
[![Version](https://img.shields.io/badge/version-0.8.4-green.svg)](https://github.com/systemime/coding-plan-mask)
1010

1111
*Use your Coding Plan subscription with ANY OpenAI-compatible coding tool*
1212

@@ -71,22 +71,22 @@ Download the binary for your platform from [GitHub Releases](https://github.com/
7171

7272
```bash
7373
# Linux amd64
74-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-linux-amd64
74+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-linux-amd64
7575
chmod +x mask-ctl-linux-amd64
7676
sudo mv mask-ctl-linux-amd64 /usr/local/bin/mask-ctl
7777

7878
# Linux arm64
79-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-linux-arm64
79+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-linux-arm64
8080
chmod +x mask-ctl-linux-arm64
8181
sudo mv mask-ctl-linux-arm64 /usr/local/bin/mask-ctl
8282

8383
# macOS (Darwin amd64)
84-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-darwin-amd64
84+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-darwin-amd64
8585
chmod +x mask-ctl-darwin-amd64
8686
sudo mv mask-ctl-darwin-amd64 /usr/local/bin/mask-ctl
8787

8888
# macOS (Darwin arm64)
89-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-darwin-arm64
89+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-darwin-arm64
9090
chmod +x mask-ctl-darwin-arm64
9191
sudo mv mask-ctl-darwin-arm64 /usr/local/bin/mask-ctl
9292

@@ -157,6 +157,10 @@ remove_version_path = false
157157
mock_models = false
158158
# Mock /models response content (JSON string)
159159
mock_models_resp = '{"object":"list","data":[{"id":"gpt-4","object":"model","owned_by":"organization"}]}'
160+
# Anthropic format compatibility mode (default: false)
161+
# When enabled, fixes null values in JSON Schema (required, enum, items, etc.)
162+
# Useful for API providers using Anthropic native protocol
163+
use_anthropic = false
160164
```
161165

162166
#### 4. Start
@@ -274,6 +278,7 @@ You can also configure via environment variables:
274278
| `REMOVE_VERSION_PATH` | Remove version prefix (e.g., `/v1`) from request path when forwarding (true/false) |
275279
| `MOCK_MODELS` | Enable mock /models endpoint response (true/false) |
276280
| `MOCK_MODELS_RESP` | Mock /models response content (JSON string) |
281+
| `USE_ANTHROPIC` | Enable Anthropic format compatibility mode (true/false) |
277282

278283
### ⚠️ Risk Warning
279284

@@ -337,22 +342,22 @@ This project is provided for **educational and research purposes only**.
337342

338343
```bash
339344
# Linux amd64
340-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-linux-amd64
345+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-linux-amd64
341346
chmod +x mask-ctl-linux-amd64
342347
sudo mv mask-ctl-linux-amd64 /usr/local/bin/mask-ctl
343348

344349
# Linux arm64
345-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-linux-arm64
350+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-linux-arm64
346351
chmod +x mask-ctl-linux-arm64
347352
sudo mv mask-ctl-linux-arm64 /usr/local/bin/mask-ctl
348353

349354
# macOS amd64
350-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-darwin-amd64
355+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-darwin-amd64
351356
chmod +x mask-ctl-darwin-amd64
352357
sudo mv mask-ctl-darwin-amd64 /usr/local/bin/mask-ctl
353358

354359
# macOS arm64
355-
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.3/mask-ctl-darwin-arm64
360+
wget https://github.com/systemime/coding-plan-mask/releases/download/v0.8.4/mask-ctl-darwin-arm64
356361
chmod +x mask-ctl-darwin-arm64
357362
sudo mv mask-ctl-darwin-arm64 /usr/local/bin/mask-ctl
358363
```
@@ -419,6 +424,10 @@ remove_version_path = false
419424
mock_models = false
420425
# 模拟 /models 响应内容 (JSON 字符串)
421426
mock_models_resp = '{"object":"list","data":[{"id":"gpt-4","object":"model","owned_by":"organization"}]}'
427+
# Anthropic 格式兼容模式 (默认: false)
428+
# 启用后会修复请求体中的 schema 字段,将 null 转为正确的默认值
429+
# 适用于使用 Anthropic 原生协议的 API 供应商
430+
use_anthropic = false
422431
```
423432

424433
#### 4. 启动
@@ -518,6 +527,7 @@ curl http://127.0.0.1:8787/stats
518527
| `REMOVE_VERSION_PATH` | 转发时移除请求路径中的版本前缀(如 `/v1`)(true/false) |
519528
| `MOCK_MODELS` | 启用模拟 /models 端点响应 (true/false) |
520529
| `MOCK_MODELS_RESP` | 模拟 /models 响应内容 (JSON 字符串) |
530+
| `USE_ANTHROPIC` | 启用 Anthropic 格式兼容模式 (true/false) |
521531

522532
### ⚠️ 风险预警
523533

deploy/config.example.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ coding_url = ""
6666
auth_header = ""
6767
# 认证前缀 (留空使用默认 "Bearer ")
6868
auth_prefix = ""
69+
# Anthropic 格式兼容模式 (默认 false)
70+
# 启用后会修复请求体中的 schema 字段,将 null 转为正确的默认值
71+
# 适用于使用 Anthropic 原生协议的 API 供应商
72+
use_anthropic = false
6973

7074
# ============================================================================
7175
# 服务商默认 URL 参考

internal/config/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type APIConfig struct {
7777
MockModels bool `toml:"mock_models"`
7878
// 模拟 /models 响应内容 (JSON 字符串)
7979
MockModelsResp string `toml:"mock_models_resp"`
80+
// Anthropic 格式兼容模式
81+
// 启用后会修复请求体中的 schema 字段,将 null 转为正确的默认值
82+
UseAnthropic bool `toml:"use_anthropic"`
8083
}
8184

8285
// Config 应用配置(运行时使用)
@@ -107,6 +110,7 @@ type Config struct {
107110
RemoveVersionPath bool
108111
MockModels bool
109112
MockModelsResp string
113+
UseAnthropic bool // Anthropic 格式兼容模式
110114

111115
configPath string
112116
}
@@ -305,6 +309,7 @@ func LoadConfig(path string) (*Config, error) {
305309
cfg.CustomAuthPrefix = cfgFile.API.AuthPrefix
306310
cfg.RemoveVersionPath = cfgFile.API.RemoveVersionPath
307311
cfg.MockModels = cfgFile.API.MockModels
312+
cfg.UseAnthropic = cfgFile.API.UseAnthropic
308313
if cfgFile.API.MockModelsResp != "" {
309314
cfg.MockModelsResp = cfgFile.API.MockModelsResp
310315
}
@@ -362,6 +367,9 @@ func (c *Config) loadFromEnv() {
362367
if v := os.Getenv("MOCK_MODELS_RESP"); v != "" {
363368
c.MockModelsResp = v
364369
}
370+
if v := os.Getenv("USE_ANTHROPIC"); strings.ToLower(v) == "true" {
371+
c.UseAnthropic = true
372+
}
365373
}
366374

367375
// Set 设置配置项
@@ -412,6 +420,8 @@ func (c *Config) Set(key string, value string) error {
412420
c.MockModels = strings.ToLower(value) == "true"
413421
case "mock_models_resp":
414422
c.MockModelsResp = value
423+
case "use_anthropic":
424+
c.UseAnthropic = strings.ToLower(value) == "true"
415425
default:
416426
return fmt.Errorf("未知配置项: %s", key)
417427
}
@@ -530,6 +540,7 @@ func (c *Config) GetSafe() map[string]interface{} {
530540
"remove_version_path": c.RemoveVersionPath,
531541
"mock_models": c.MockModels,
532542
"mock_models_resp": c.MockModelsResp,
543+
"use_anthropic": c.UseAnthropic,
533544
}
534545
}
535546

@@ -639,6 +650,10 @@ remove_version_path = false
639650
mock_models = false
640651
# 模拟 /models 响应内容 (JSON 字符串)
641652
mock_models_resp = '{"object":"list","data":[{"id":"gpt-4","object":"model","owned_by":"organization"}]}'
653+
# Anthropic 格式兼容模式 (默认 false)
654+
# 启用后会修复请求体中的 schema 字段,将 null 转为正确的默认值
655+
# 适用于使用 Anthropic 原生协议的 API 供应商
656+
use_anthropic = false
642657
`
643658

644659
return os.WriteFile(path, []byte(defaultContent), 0644)

0 commit comments

Comments
 (0)