From bce2d4d6c93897f941692ab2a935f44e7ed7e084 Mon Sep 17 00:00:00 2001 From: Kris Xia Date: Mon, 1 Jun 2026 20:31:47 +0800 Subject: [PATCH] feat: add modelink endpoint --- CLAUDE.md | 4 +++- README.en-US.md | 14 ++++++++------ README.md | 14 ++++++++------ src/lib/endpoints.ts | 12 +++++++++++- src/lib/tools/codex-tool.ts | 4 +++- src/locales/en_US.json | 4 +++- src/locales/zh_CN.json | 4 +++- 7 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 911ce6b..b4cceb1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,8 +59,10 @@ node dist/cli.js lang show ## API Endpoints -- 国内线路: `https://api.qnaigc.com` +- 国内线路: `https://openai.qiniu.com` +- 国内备用线路: `https://api.qnaigc.com` - 海外线路: `https://openai.sufy.com` +- Modelink 线路: `https://api.modelink.ai` - 支持接口: `/v1/chat/completions`、`/v1/messages`、`/v1/models` - API Key 校验: `/v2/stat/usage`(轻量级,验证 token 有效性) - 认证: Bearer token diff --git a/README.en-US.md b/README.en-US.md index d1f7f6d..1726436 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -27,7 +27,7 @@ ## ✨ Features - **🎯 Interactive Wizard** — Guided step-by-step setup for language, endpoint, API Key, and model on first run -- **🌐 Multi-Region Support** — Domestic (api.qnaigc.com) / International (openai.sufy.com) endpoints +- **🌐 Multi-Region Support** — Domestic (openai.qiniu.com) / Domestic Backup (api.qnaigc.com) / International (openai.sufy.com) / Modelink (api.modelink.ai) endpoints - **🔐 API Key Management** — Input, validate, save, and revoke API keys - **📦 Model Configuration** — Fetch available models from the API, with manual model ID input support - **⚡ Claude Code Integration** — Automatically writes environment variables to `~/.claude/settings.json` @@ -208,8 +208,10 @@ npx qiniu-coding-helper enter hermes | Region | Base URL | Best For | |--------|----------|----------| -| 🇨🇳 **Domestic** | `https://api.qnaigc.com` | Users in China | +| 🇨🇳 **Domestic** | `https://openai.qiniu.com` | Users in China | +| 🇨🇳 **Domestic Backup** | `https://api.qnaigc.com` | Users in China | | 🌍 **International** | `https://openai.sufy.com` | Users outside China | +| 🔁 **Modelink** | `https://api.modelink.ai` | Available in and outside China | ### 🔧 Claude Code Environment Variables @@ -218,7 +220,7 @@ When configuration is applied, these environment variables are set in `~/.claude ```json { "env": { - "ANTHROPIC_BASE_URL": "https://api.qnaigc.com", + "ANTHROPIC_BASE_URL": "https://openai.qiniu.com", "ANTHROPIC_AUTH_TOKEN": "", "API_TIMEOUT_MS": "3000000", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" @@ -239,7 +241,7 @@ model_provider = "qnaigc" [model_providers.qnaigc] name = "Qiniu" -base_url = "https://api.qnaigc.com/bypass/openai/v1" +base_url = "https://openai.qiniu.com/bypass/openai/v1" requires_openai_auth = true wire_api = "responses" @@ -263,7 +265,7 @@ The configuration flow lets you multi-select models from the Qiniu model market "id": "anthropic/claude-sonnet-4-5", "name": "Claude Sonnet 4.5", "vendor": "Qiniu", - "url": "https://api.qnaigc.com/v1/chat/completions", + "url": "https://openai.qiniu.com/v1/chat/completions", "apiKey": "", "maxInputTokens": 200000, "maxOutputTokens": 8192, @@ -300,7 +302,7 @@ Hermes Agent stores its configuration in `~/.hermes/config.yaml`. The configurat model: provider: custom default: anthropic/claude-sonnet-4-5 - base_url: https://api.qnaigc.com/v1 + base_url: https://openai.qiniu.com/v1 api_key: ``` diff --git a/README.md b/README.md index 4abea02..cdb7626 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ ## ✨ 功能特性 - **🎯 交互式向导** — 首次运行引导配置语言、线路、API Key 和模型,步步引导 -- **🌐 多线路支持** — 国内线路 (api.qnaigc.com) / 海外线路 (openai.sufy.com) +- **🌐 多线路支持** — 国内线路 (openai.qiniu.com) / 国内备用线路 (api.qnaigc.com) / 海外线路 (openai.sufy.com) / Modelink 线路 (api.modelink.ai) - **🔐 API Key 管理** — 输入、验证、保存、删除,一条龙管理 - **📦 模型配置** — 从 API 获取可用模型列表,也支持手动输入模型 ID - **⚡ Claude Code 集成** — 自动将环境变量写入 `~/.claude/settings.json` @@ -208,8 +208,10 @@ npx qiniu-coding-helper enter hermes | 线路 | 地址 | 适用场景 | |------|------|----------| -| 🇨🇳 **国内线路** | `https://api.qnaigc.com` | 中国大陆用户 | +| 🇨🇳 **国内线路** | `https://openai.qiniu.com` | 中国大陆用户 | +| 🇨🇳 **国内备用线路** | `https://api.qnaigc.com` | 中国大陆用户 | | 🌍 **海外线路** | `https://openai.sufy.com` | 海外用户 | +| 🔁 **Modelink 线路** | `https://api.modelink.ai` | 国内外通用 | ### 🔧 Claude Code 环境变量 @@ -218,7 +220,7 @@ npx qiniu-coding-helper enter hermes ```json { "env": { - "ANTHROPIC_BASE_URL": "https://api.qnaigc.com", + "ANTHROPIC_BASE_URL": "https://openai.qiniu.com", "ANTHROPIC_AUTH_TOKEN": "", "API_TIMEOUT_MS": "3000000", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" @@ -239,7 +241,7 @@ model_provider = "qnaigc" [model_providers.qnaigc] name = "Qiniu" -base_url = "https://api.qnaigc.com/bypass/openai/v1" +base_url = "https://openai.qiniu.com/bypass/openai/v1" requires_openai_auth = true wire_api = "responses" @@ -263,7 +265,7 @@ CodeBuddy 是一个 CLI 工具,配置保存在 `~/.codebuddy/models.json`。 "id": "anthropic/claude-sonnet-4-5", "name": "Claude Sonnet 4.5", "vendor": "Qiniu", - "url": "https://api.qnaigc.com/v1/chat/completions", + "url": "https://openai.qiniu.com/v1/chat/completions", "apiKey": "", "maxInputTokens": 200000, "maxOutputTokens": 8192, @@ -298,7 +300,7 @@ Hermes Agent 配置保存在 `~/.hermes/config.yaml`。配置流程会从七牛 model: provider: custom default: anthropic/claude-sonnet-4-5 - base_url: https://api.qnaigc.com/v1 + base_url: https://openai.qiniu.com/v1 api_key: ``` diff --git a/src/lib/endpoints.ts b/src/lib/endpoints.ts index 86380b5..422b30f 100644 --- a/src/lib/endpoints.ts +++ b/src/lib/endpoints.ts @@ -7,6 +7,11 @@ export interface EndpointDefinition { } export const ENDPOINT_DEFINITIONS: Record = { + qiniu: { + id: 'qiniu', + i18nKey: 'endpoint_qiniu', + baseUrl: 'https://openai.qiniu.com', + }, china: { id: 'china', i18nKey: 'endpoint_china', @@ -17,9 +22,14 @@ export const ENDPOINT_DEFINITIONS: Record = { i18nKey: 'endpoint_international', baseUrl: 'https://openai.sufy.com', }, + modelink: { + id: 'modelink', + i18nKey: 'endpoint_modelink', + baseUrl: 'https://api.modelink.ai', + }, }; -export const DEFAULT_ENDPOINT = 'china'; +export const DEFAULT_ENDPOINT = 'qiniu'; // 根据端点 ID 获取 base URL export function getBaseUrl(endpointId: string): string { diff --git a/src/lib/tools/codex-tool.ts b/src/lib/tools/codex-tool.ts index 5f82e18..4e05e1f 100644 --- a/src/lib/tools/codex-tool.ts +++ b/src/lib/tools/codex-tool.ts @@ -4,6 +4,7 @@ import os from 'node:os'; import { execSync } from 'node:child_process'; import type { ITool } from './base-tool.js'; import { configManager, type ModelConfig } from '../config.js'; +import { DEFAULT_ENDPOINT, getBaseUrl } from '../endpoints.js'; import { t } from '../i18n.js'; import { uiRenderer } from '../wizard/ui/ui-renderer.js'; import { promptHelper } from '../wizard/ui/prompt-helper.js'; @@ -14,6 +15,7 @@ const CODEX_AUTH_FILE = path.join(CODEX_DIR, 'auth.json'); const PROVIDER_NAME = 'qnaigc'; const PROFILE_NAME = 'qn-gpt'; const CODEX_MODEL = 'openai/gpt-5.5'; +const DEFAULT_CODEX_BASE_URL = getBaseUrl(DEFAULT_ENDPOINT); // Codex 工具实现 export class CodexTool implements ITool { @@ -88,7 +90,7 @@ export function buildCodexConfig(existing: string, baseUrl?: string, model?: str let content = removeManagedCodexConfig(existing); content = upsertTopLevelModelProvider(content); - const providerBaseUrl = `${(baseUrl || 'https://api.qnaigc.com').replace(/\/+$/, '')}/bypass/openai/v1`; + const providerBaseUrl = `${(baseUrl || DEFAULT_CODEX_BASE_URL).replace(/\/+$/, '')}/bypass/openai/v1`; const sections = [ `[model_providers.${PROVIDER_NAME}]`, 'name = "Qiniu"', diff --git a/src/locales/en_US.json b/src/locales/en_US.json index daa67bd..90f097f 100644 --- a/src/locales/en_US.json +++ b/src/locales/en_US.json @@ -6,8 +6,10 @@ "language_set": "Language set to: {{lang}}", "language_current": "Current language: {{lang}}", "endpoint_prompt": "Select API endpoint", - "endpoint_china": "China (api.qnaigc.com)", + "endpoint_qiniu": "Domestic (openai.qiniu.com)", + "endpoint_china": "Domestic Backup (api.qnaigc.com)", "endpoint_international": "International (openai.sufy.com)", + "endpoint_modelink": "Modelink (api.modelink.ai)", "endpoint_set": "Endpoint set to: {{endpoint}}", "apikey_hint": "To get an API Key, visit: https://portal.qiniu.com/ai-inference/api-key", "apikey_prompt": "Enter your API Key", diff --git a/src/locales/zh_CN.json b/src/locales/zh_CN.json index c4e2b70..387ef23 100644 --- a/src/locales/zh_CN.json +++ b/src/locales/zh_CN.json @@ -8,8 +8,10 @@ "language_current": "当前语言: {{lang}}", "endpoint_prompt": "请选择 API 线路", - "endpoint_china": "国内线路 (api.qnaigc.com)", + "endpoint_qiniu": "国内线路 (openai.qiniu.com)", + "endpoint_china": "国内备用线路 (api.qnaigc.com)", "endpoint_international": "海外线路 (openai.sufy.com)", + "endpoint_modelink": "Modelink 线路 (api.modelink.ai)", "endpoint_set": "线路已设置为: {{endpoint}}", "apikey_hint": "如需获取 API Key,请访问: https://portal.qiniu.com/ai-inference/api-key",