feat: 国产供应商一等支持(Kimi/Zhipu/DeepSeek 多协议 + 配额/余额监控)

后端:
- 协议凭证维度 credentials[api_protocol] ∈ chat_completions(默认)/anthropic/responses(deepseek)
- /v1/messages 零转换直通原生 Anthropic 端点(kimi/zhipu/deepseek),CC/Responses
  入站交叉组合走 apicompat 双向转换链(responses/chat_completions anthropic-native 转发器)
- count_tokens:anthropic 协议透传原生端点;其余 CN 协议本地 tiktoken 估算
- Coding Plan 额度探测(5h/weekly 滚动窗口)+ payg 余额探测(kimi/deepseek),
  deepseek 双币种 CNY+USD 明细,任一币种达标不停调
- 周期任务 [CNBalance] 并发探测 + 预算随工作量放大;响应式 429 冷却到最早窗口
  重置点;余额不足可恢复临时停调;智谱 CREDIT_LIMIT 不污染窗口解析
- CC→anthropic 流式客户端断开后继续排水上游保住 usage 计量

前端:
- 创建/编辑弹窗 account_mode + api_protocol + base_url 联动预设(含 watcher 竞态防护)
- 用量单元格:kimi/zhipu coding 显示 5h/weekly 窗口,kimi/deepseek payg 显示余额,
  多币种并列展示;探测失败保留快照;挂载自动探测 5min 去抖
- 调度阈值设置面板补 kimi/zhipu 平台(对齐后端 AllowedSchedulingThresholdPlatforms)
This commit is contained in:
Randark committed 2026-08-15 10:37:51 +00:00
1 parent 073e92d171
commit 901a0439f1
72 files changed
+5754 -125

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
/**
* Admin CN providers (Kimi / Zhipu / DeepSeek) API endpoints.
* Coding-plan rolling-window quota probe + payg balance probe.
*/
import { apiClient } from '../client'
/** 滚动用量窗口档(5 小时 / 每周),对齐后端 service.CNQuotaTier。 */
export interface CNQuotaTier {
window: '5h' | 'weekly'
used_percent: number
reset_at?: string
}
/** Coding Plan 额度探测结果(kimi / zhipu),对齐后端 CNProviderQuotaProbeResult。 */
export interface CNProviderQuotaProbeResult {
provider: string
source?: string
success: boolean
credential_valid: boolean
tiers?: CNQuotaTier[]
plan_level?: string
status_code?: number
fetched_at: number
persisted: boolean
error?: string
}
/** 单币种余额明细(deepseek 双币种账号含 CNY + USD 两条)。 */
export interface CNProviderBalanceEntry {
currency: string
balance: number
}
/** payg 余额探测结果(kimi / deepseek),对齐后端 CNProviderBalanceResult。 */
export interface CNProviderBalanceResult {
provider: string
success: boolean
/** 主币种余额(balances 首条,兼容单币种展示)。 */
balance: number
currency?: string
/** 多币种明细;缺省时按主币种展示。 */
balances?: CNProviderBalanceEntry[]
available: boolean
status_code?: number
fetched_at: number
persisted: boolean
error?: string
}
/** 查询 Coding Plan 滚动窗口用量(5h + weekly)。 */
export async function queryQuota(id: number): Promise<CNProviderQuotaProbeResult> {
const { data } = await apiClient.get<CNProviderQuotaProbeResult>(
`/admin/cn-providers/accounts/${id}/quota`
)
return data
}
/** 查询 payg 账号余额。 */
export async function queryBalance(id: number): Promise<CNProviderBalanceResult> {
const { data } = await apiClient.get<CNProviderBalanceResult>(
`/admin/cn-providers/accounts/${id}/balance`
)
return data
}
export default {
queryQuota,
queryBalance
}
+3
View File
@@ -18,6 +18,7 @@ import usageAPI from './usage'
import geminiAPI from './gemini'
import antigravityAPI from './antigravity'
import grokAPI from './grok'
import cnProvidersAPI from './cnProviders'
import userAttributesAPI from './userAttributes'
import opsAPI from './ops'
import errorPassthroughAPI from './errorPassthrough'
@@ -54,6 +55,7 @@ export const adminAPI = {
gemini: geminiAPI,
antigravity: antigravityAPI,
grok: grokAPI,
cnProviders: cnProvidersAPI,
userAttributes: userAttributesAPI,
ops: opsAPI,
errorPassthrough: errorPassthroughAPI,
@@ -88,6 +90,7 @@ export {
geminiAPI,
antigravityAPI,
grokAPI,
cnProvidersAPI,
userAttributesAPI,
opsAPI,
errorPassthroughAPI,
+6
View File
@@ -36,13 +36,19 @@ export type SchedulingThresholdPlatformType =
| "openai"
| "anthropic"
| "grok"
| "kimi"
| "zhipu"
export type AccountSchedulingThresholdsMap = Record<SchedulingThresholdPlatformType, number>
// 与后端 AllowedSchedulingThresholdPlatforms 保持一致(deepseek 为余额型,
// 走余额检测而非用量阈值)。
export const SCHEDULING_THRESHOLD_PLATFORMS: SchedulingThresholdPlatformType[] = [
"openai",
"anthropic",
"grok",
"kimi",
"zhipu",
]
export function normalizeAccountSchedulingThresholdsMap(