mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-16 15:43:13 +08:00
feat(claude): 自动同步 Claude Code 客户端版本号
出站伪装用的 Claude Code 版本号此前硬编码在 claude.CLICurrentVersion, 只能靠环境变量 SUB2API_CLAUDE_CLI_VERSION 覆盖且需重启;Anthropic 抬高 版本下限时(如 Opus 5.5 要求 >= 2.1.280)必须改代码发版才能跟上。 改为每小时从官方 GitHub Releases 同步最新稳定版,无需重启也无需发版。 - 新增 ClaudeCodeVersionSyncService:1 小时间隔,数据源 anthropics/claude-code 的 releases/latest,失败回退最近 30 条列表;过滤 draft/prerelease; 只向前推进,拉取失败保留上次值不降级;面板可关闭 - 新增三个设置项:claude_code_client_version(管理员手动固定)、 claude_code_client_version_synced(同步服务独占写)、 claude_code_version_auto_sync_enabled(开关,默认开) - 取值优先级:面板手动值 -> 同步值 -> SUB2API_CLAUDE_CLI_VERSION -> 内置基线, 每层经 IsSupportedCLIVersion 校验,含 60s 缓存与 singleflight - 版本号运行期化:claude.DefaultHeaders 由包级 var 改为函数,新增 EffectiveCLIVersion/DefaultUserAgent 与 SetCLIVersionResolver(未注入时 与 CLIVersion() 等价);identity 的 defaultFingerprint 不再在包 init 固化, 指纹下限与主版本超前校验改用运行期值 - 守住一致性铁律:buildUpstreamRequest 与 count_tokens 各取一次 UA 字符串, 同时喂给出站 User-Agent 头与请求体 billing 的 cc_version,避免缓存翻转 瞬间头体版本不一致被判非正版客户端 - 管理后台设置页新增配置区块,含中英文案与「当前同步到」只读展示
This commit is contained in:
@@ -639,6 +639,9 @@ export interface SystemSettings {
|
||||
openai_codex_client_version: string;
|
||||
openai_codex_client_version_synced: string;
|
||||
openai_codex_version_auto_sync_enabled: boolean;
|
||||
claude_code_client_version: string;
|
||||
claude_code_client_version_synced: string;
|
||||
claude_code_version_auto_sync_enabled: boolean;
|
||||
// codex_cli_only 加固
|
||||
min_codex_version: string;
|
||||
max_codex_version: string;
|
||||
@@ -959,6 +962,8 @@ export interface UpdateSettingsRequest {
|
||||
openai_codex_user_agent?: string;
|
||||
openai_codex_client_version?: string;
|
||||
openai_codex_version_auto_sync_enabled?: boolean;
|
||||
claude_code_client_version?: string;
|
||||
claude_code_version_auto_sync_enabled?: boolean;
|
||||
// codex_cli_only 加固
|
||||
min_codex_version?: string;
|
||||
max_codex_version?: string;
|
||||
|
||||
@@ -542,6 +542,11 @@ export default {
|
||||
openaiCodexVersionAutoSync: 'Auto-sync Codex version',
|
||||
openaiCodexVersionAutoSyncHint: 'Fetches the latest stable client version from the official repository every 6 hours, so you never need to upgrade this service just to keep the version current. When disabled, only the version above or the built-in default is used.',
|
||||
openaiCodexVersionSyncedValue: 'Currently synced: {version}',
|
||||
claudeCodeClientVersion: 'Claude Code client version',
|
||||
claudeCodeClientVersionHint: "The client version this gateway declares upstream when impersonating the official Claude Code CLI. Leave empty to use the auto-synced latest official release; setting a value pins it and stops following auto-sync. The SUB2API_CLAUDE_CLI_VERSION environment variable still acts as a fallback and takes priority over this setting.",
|
||||
claudeCodeVersionAutoSync: 'Auto-sync Claude Code version',
|
||||
claudeCodeVersionAutoSyncHint: 'Fetches the latest Claude Code client version from the official release channel every hour, so you never need to upgrade this service just to keep the version current. When disabled, only the version above or the environment-variable fallback is used.',
|
||||
claudeCodeVersionSyncedValue: 'Currently synced: {version}',
|
||||
codexHardeningTitle: "Codex Settings",
|
||||
codexClientRestrictionTitle: "Codex client restriction",
|
||||
codexHardeningDesc:
|
||||
|
||||
@@ -535,6 +535,11 @@ export default {
|
||||
openaiCodexVersionAutoSync: '自动同步 Codex 版本号',
|
||||
openaiCodexVersionAutoSyncHint: '每 6 小时从官方仓库获取最新稳定版客户端版本号,无需为了跟版本而升级本服务。关闭后仅使用上方手填版本或内置版本。',
|
||||
openaiCodexVersionSyncedValue: '当前同步到:{version}',
|
||||
claudeCodeClientVersion: 'Claude Code 客户端版本号',
|
||||
claudeCodeClientVersionHint: '网关伪装为官方 Claude Code CLI 时对上游声明的客户端版本号。留空表示使用自动同步到的官方最新版本;填写后固定为该版本,不再跟随同步。环境变量 SUB2API_CLAUDE_CLI_VERSION 仍作为兜底,优先级高于此处配置。',
|
||||
claudeCodeVersionAutoSync: '自动同步 Claude Code 版本号',
|
||||
claudeCodeVersionAutoSyncHint: '每小时从官方发布渠道获取最新版本的 Claude Code 客户端版本号,无需为了跟版本而升级本服务。关闭后仅使用上方手填版本或环境变量兜底。',
|
||||
claudeCodeVersionSyncedValue: '当前同步到:{version}',
|
||||
codexHardeningTitle: 'Codex 设置',
|
||||
codexClientRestrictionTitle: 'Codex 客户端限制',
|
||||
codexHardeningDesc:
|
||||
|
||||
@@ -5775,6 +5775,61 @@
|
||||
<Toggle v-model="form.openai_codex_version_auto_sync_enabled" />
|
||||
</div>
|
||||
|
||||
<!-- Claude Code 客户端版本号 -->
|
||||
<div>
|
||||
<label
|
||||
class="mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
{{
|
||||
t(
|
||||
"admin.settings.gatewayForwarding.claudeCodeClientVersion",
|
||||
)
|
||||
}}
|
||||
</label>
|
||||
<input
|
||||
v-model="form.claude_code_client_version"
|
||||
type="text"
|
||||
class="input w-full font-mono text-sm"
|
||||
placeholder="2.1.280"
|
||||
/>
|
||||
<p class="mt-1.5 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{
|
||||
t(
|
||||
"admin.settings.gatewayForwarding.claudeCodeClientVersionHint",
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Claude Code 版本号自动同步 -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<label
|
||||
class="text-sm font-medium text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
{{
|
||||
t(
|
||||
"admin.settings.gatewayForwarding.claudeCodeVersionAutoSync",
|
||||
)
|
||||
}}
|
||||
</label>
|
||||
<p class="mt-0.5 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{
|
||||
t(
|
||||
"admin.settings.gatewayForwarding.claudeCodeVersionAutoSyncHint",
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
<p
|
||||
v-if="claudeSyncedVersionLabel"
|
||||
class="mt-0.5 text-xs text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
{{ claudeSyncedVersionLabel }}
|
||||
</p>
|
||||
</div>
|
||||
<Toggle v-model="form.claude_code_version_auto_sync_enabled" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9840,6 +9895,10 @@ const form = reactive<SettingsForm>({
|
||||
// 只读展示:自动同步任务写入的官方最新稳定版,不参与提交(提交载荷按字段显式构造)
|
||||
openai_codex_client_version_synced: "",
|
||||
openai_codex_version_auto_sync_enabled: true,
|
||||
claude_code_client_version: "",
|
||||
// 只读展示:自动同步任务写入的官方最新稳定版,不参与提交(提交载荷按字段显式构造)
|
||||
claude_code_client_version_synced: "",
|
||||
claude_code_version_auto_sync_enabled: true,
|
||||
// codex_cli_only 加固
|
||||
min_codex_version: "",
|
||||
max_codex_version: "",
|
||||
@@ -10827,6 +10886,14 @@ const codexSyncedVersionLabel = computed(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const claudeSyncedVersionLabel = computed(() => {
|
||||
const synced = form.claude_code_client_version_synced?.trim();
|
||||
if (!synced) return "";
|
||||
return t("admin.settings.gatewayForwarding.claudeCodeVersionSyncedValue", {
|
||||
version: synced,
|
||||
});
|
||||
});
|
||||
|
||||
async function loadSettings() {
|
||||
loading.value = true;
|
||||
loadFailed.value = false;
|
||||
@@ -11460,6 +11527,9 @@ async function saveSettings() {
|
||||
form.openai_codex_client_version?.trim() || "",
|
||||
openai_codex_version_auto_sync_enabled:
|
||||
form.openai_codex_version_auto_sync_enabled,
|
||||
claude_code_client_version: form.claude_code_client_version?.trim() || "",
|
||||
claude_code_version_auto_sync_enabled:
|
||||
form.claude_code_version_auto_sync_enabled,
|
||||
min_codex_version: form.min_codex_version?.trim() || "",
|
||||
max_codex_version: form.max_codex_version?.trim() || "",
|
||||
codex_cli_only_allow_app_server_clients:
|
||||
|
||||
Reference in New Issue
Block a user