Merge remote-tracking branch 'origin/main'

This commit is contained in:
fawney19
2026-05-20 16:14:09 +08:00
45 changed files with 4099 additions and 164 deletions

View File

@@ -286,6 +286,74 @@ export async function refreshProviderQuota(
return response.data
}
export type ProviderKeyBalanceStatus =
| 'success'
| 'pending'
| 'auth_failed'
| 'auth_expired'
| 'rate_limited'
| 'network_error'
| 'parse_error'
| 'not_configured'
| 'not_supported'
| 'already_done'
| 'unknown_error'
export interface ProviderKeyBalanceInfo {
total_granted: number | null
total_used: number | null
total_available: number | null
expires_at: string | null
currency: string
extra: Record<string, unknown>
}
export interface ProviderKeyBalanceResult {
status: ProviderKeyBalanceStatus
action_type: 'query_balance'
data: ProviderKeyBalanceInfo | null
message: string | null
executed_at: string
response_time_ms: number | null
cache_ttl_seconds: number
saved_to_key?: boolean
saved_key_id?: string | null
save_message?: string | null
}
export interface ProviderKeyBalanceQuery {
key_id?: string
api_key?: string
auth_type?: 'api_key' | 'bearer' | 'service_account' | 'oauth'
api_formats?: string[]
architecture_id?: 'new_api' | 'sub2api' | 'generic_api'
custom_base_url?: string
new_api_user_id?: string
sub2api_credential_kind?: 'api_key' | 'access_token' | 'refresh_token'
custom_endpoint?: string
custom_method?: 'GET' | 'POST'
custom_currency?: string
custom_quota_divisor?: number
custom_balance_path?: string
custom_used_path?: string
custom_granted_path?: string
auto_refresh_interval_minutes?: number
save_balance_secret?: boolean
save_result?: boolean
}
export async function queryProviderKeyBalance(
providerId: string,
data: ProviderKeyBalanceQuery,
): Promise<ProviderKeyBalanceResult> {
const response = await client.post<ProviderKeyBalanceResult>(
`/api/admin/endpoints/providers/${providerId}/key-balance`,
data,
{ timeout: 60 * 1000 },
)
return response.data
}
/**
* 批量导入 OAuth 凭据(通用)
* 支持的 Provider 类型Codex、Antigravity、GeminiCli、ClaudeCode、Kiro

View File

@@ -402,12 +402,46 @@ export interface GrokUpstreamMetadata {
account_user_id?: string | null
}
export interface BalanceQueryUpstreamMetadata {
updated_at?: number
architecture_id?: string | null
status?: string | null
executed_at?: string | null
response_time_ms?: number | null
total_available?: number | null
total_used?: number | null
total_granted?: number | null
currency?: string | null
plan_name?: string | null
query_config?: {
custom_base_url?: string | null
new_api_user_id?: string | null
sub2api_credential_kind?: 'api_key' | 'access_token' | 'refresh_token' | string | null
custom_endpoint?: string | null
custom_method?: 'GET' | 'POST' | string | null
custom_currency?: string | null
custom_quota_divisor?: number | null
custom_balance_path?: string | null
custom_used_path?: string | null
custom_granted_path?: string | null
auto_refresh_interval_minutes?: number | null
has_saved_secret?: boolean | null
} | null
extra?: Record<string, unknown> | null
}
export interface ProviderKeyBalanceSummary extends BalanceQueryUpstreamMetadata {
key_id?: string | null
key_name?: string | null
}
export interface UpstreamMetadata {
codex?: CodexUpstreamMetadata
antigravity?: AntigravityUpstreamMetadata
kiro?: KiroUpstreamMetadata
chatgpt_web?: ChatGPTWebUpstreamMetadata
grok?: GrokUpstreamMetadata
balance_query?: BalanceQueryUpstreamMetadata
}
// 按格式的健康度数据
@@ -684,6 +718,7 @@ export interface ProviderWithEndpointsSummary {
failover_rules?: FailoverRulesConfig | null
ops_configured: boolean // 是否配置了扩展操作(余额监控等)
ops_architecture_id?: string // 扩展操作使用的架构 ID如 cubence, anyrouter
key_balance_summary?: ProviderKeyBalanceSummary | null
kiro_simulated_cache_enabled?: boolean
created_at: string
updated_at: string

View File

@@ -12,7 +12,13 @@ import client from './client'
// ==================== Types ====================
/** 认证类型 */
export type ConnectorAuthType = 'api_key' | 'session_login' | 'oauth' | 'cookie' | 'none'
export type ConnectorAuthType =
| 'api_key'
| 'refresh_token'
| 'session_login'
| 'oauth'
| 'cookie'
| 'none'
/** 操作类型 */
export type ProviderActionType =