refactor: 前端全面替换 any 为 unknown 并统一错误处理,后端用量记录补写请求头/体

- 前端 API 层、stores、conversation 解析器、组件全面替换 any 为 unknown/具体类型
- 错误处理统一使用 parseApiError/getErrorStatus 替代 err.response?.data?.detail 模式
- 后端 handler/TaskService/UsageLifecycle/StreamTracker 链路传递 request_headers/request_body
- streaming/pending 状态更新时可补写客户端和提供商的请求头及请求体
- 新增 TaskService 和 UsageService 相关测试
This commit is contained in:
fawney19
2026-02-22 00:43:41 +08:00
parent 98e60e8f74
commit cf2eee222e
121 changed files with 1652 additions and 1179 deletions

View File

@@ -31,7 +31,7 @@ export async function createEndpoint(
body_rules?: BodyRule[]
max_retries?: number
is_active?: boolean
config?: Record<string, any>
config?: Record<string, unknown>
proxy?: ProxyConfig | null
format_acceptance_config?: FormatAcceptanceConfig | null
}
@@ -52,7 +52,7 @@ export async function updateEndpoint(
body_rules: BodyRule[] | null
max_retries: number
is_active: boolean
config: Record<string, any>
config: Record<string, unknown> | null
proxy: ProxyConfig | null
format_acceptance_config: FormatAcceptanceConfig | null
}>

View File

@@ -59,7 +59,7 @@ export interface RevealKeyResult {
auth_type: 'api_key' | 'vertex_ai' | 'oauth'
api_key?: string
refresh_token?: string
auth_config?: string | Record<string, any>
auth_config?: string | Record<string, unknown>
}
export async function revealEndpointKey(keyId: string): Promise<RevealKeyResult> {
@@ -70,7 +70,7 @@ export async function revealEndpointKey(keyId: string): Promise<RevealKeyResult>
/**
* 导出 OAuth Key 凭据(扁平 JSON用于跨实例迁移
*/
export async function exportKey(keyId: string): Promise<Record<string, any>> {
export async function exportKey(keyId: string): Promise<Record<string, unknown>> {
const response = await client.get(`/api/admin/endpoints/keys/${keyId}/export`)
return response.data
}
@@ -104,7 +104,7 @@ export async function addProviderKey(
api_formats: string[] // 支持的 API 格式列表(必填)
api_key: string
auth_type?: 'api_key' | 'vertex_ai' | 'oauth' // 认证类型
auth_config?: Record<string, any> // 认证配置Vertex AI Service Account JSON
auth_config?: Record<string, unknown> // 认证配置Vertex AI Service Account JSON
name: string
rate_multipliers?: Record<string, number> | null // 按 API 格式的成本倍率
internal_priority?: number
@@ -132,7 +132,7 @@ export async function updateProviderKey(
api_formats: string[] // 支持的 API 格式列表
api_key: string
auth_type: 'api_key' | 'vertex_ai' | 'oauth' // 认证类型
auth_config: Record<string, any> // 认证配置Vertex AI Service Account JSON
auth_config: Record<string, unknown> // 认证配置Vertex AI Service Account JSON
name: string
rate_multipliers: Record<string, number> | null // 按 API 格式的成本倍率
internal_priority: number
@@ -175,7 +175,7 @@ export interface RefreshQuotaResult {
key_name: string
status: 'success' | 'no_metadata' | 'error'
// Codex: 额度字段为扁平结构Antigravity: 返回 { antigravity: { quota_by_model: ... } }
metadata?: Record<string, any>
metadata?: Record<string, unknown>
message?: string
status_code?: number
}>

View File

@@ -5,7 +5,6 @@ import type {
ModelUpdate,
ModelCatalogResponse,
ProviderAvailableSourceModelsResponse,
UpstreamModel,
ImportFromUpstreamResponse,
} from './types'

View File

@@ -29,7 +29,7 @@ export interface Model {
global_model_id?: string // 关联的 GlobalModel ID
provider_model_name: string // Provider 侧的主模型名称
provider_model_mappings?: ProviderModelMapping[] | null // 模型名称映射列表(带优先级)
config?: Record<string, any> | null // 额外配置(如 billing/video 等)
config?: Record<string, unknown> | null // 额外配置(如 billing/video 等)
// 原始配置值(可能为空,为空时使用 GlobalModel 默认值)
price_per_request?: number | null // 按次计费价格
tiered_pricing?: TieredPricingConfig | null // 阶梯计费配置
@@ -56,7 +56,7 @@ export interface Model {
global_model_name?: string
global_model_display_name?: string
// 有效配置(合并 Model 和 GlobalModel 的 config
effective_config?: Record<string, any> | null
effective_config?: Record<string, unknown> | null
}
export interface ModelCreate {
@@ -73,7 +73,7 @@ export interface ModelCreate {
supports_extended_thinking?: boolean
supports_image_generation?: boolean
is_active?: boolean
config?: Record<string, any>
config?: Record<string, unknown>
}
export interface ModelUpdate {
@@ -89,7 +89,7 @@ export interface ModelUpdate {
supports_image_generation?: boolean
is_active?: boolean
is_available?: boolean
config?: Record<string, any> | null
config?: Record<string, unknown> | null
}
export interface ModelCapabilities {
@@ -183,7 +183,7 @@ export interface GlobalModelCreate {
// Key 能力配置 - 模型支持的能力列表
supported_capabilities?: string[]
// 模型配置JSON格式- 包含能力、规格、元信息等
config?: Record<string, any>
config?: Record<string, unknown>
is_active?: boolean
}
@@ -197,7 +197,7 @@ export interface GlobalModelUpdate {
// Key 能力配置 - 模型支持的能力列表
supported_capabilities?: string[] | null
// 模型配置JSON格式- 包含能力、规格、元信息等
config?: Record<string, any> | null
config?: Record<string, unknown> | null
}
export interface GlobalModelResponse {
@@ -212,7 +212,7 @@ export interface GlobalModelResponse {
// Key 能力配置 - 模型支持的能力列表
supported_capabilities?: string[] | null
// 模型配置JSON格式
config?: Record<string, any> | null
config?: Record<string, unknown> | null
// 统计数据
provider_count?: number
active_provider_count?: number

View File

@@ -52,7 +52,7 @@ export type HeaderRule = HeaderRuleSet | HeaderRuleDrop | HeaderRuleRename
export interface BodyRuleSet {
action: 'set'
path: string
value: any
value: unknown
}
/**
@@ -87,7 +87,7 @@ export interface BodyRuleRename {
export interface BodyRuleAppend {
action: 'append'
path: string
value: any
value: unknown
}
/**
@@ -101,7 +101,7 @@ export interface BodyRuleInsert {
action: 'insert'
path: string
index: number
value: any
value: unknown
}
/**
@@ -132,7 +132,7 @@ export type BodyRuleConditionOp =
export interface BodyRuleCondition {
path: string
op: BodyRuleConditionOp
value?: any // exists / not_exists 不需要 value
value?: unknown // exists / not_exists 不需要 value
}
/**
@@ -174,7 +174,7 @@ export interface ProviderEndpoint {
body_rules?: BodyRule[] // 请求体规则列表,支持 set/drop/rename 操作
max_retries: number
is_active: boolean
config?: Record<string, any>
config?: Record<string, unknown>
proxy?: ProxyConfig | null
// 格式转换配置
format_acceptance_config?: FormatAcceptanceConfig | null
@@ -352,7 +352,7 @@ export interface EndpointAPIKeyUpdate {
name?: string
api_key?: string // 仅在需要更新时提供
auth_type?: 'api_key' | 'vertex_ai' | 'oauth' // 认证类型
auth_config?: Record<string, any> // 认证配置Vertex AI Service Account JSON
auth_config?: Record<string, unknown> // 认证配置Vertex AI Service Account JSON
rate_multipliers?: Record<string, number> | null // 按 API 格式的成本倍率
internal_priority?: number
global_priority_by_format?: Record<string, number> | null // 按 API 格式的全局优先级
@@ -492,7 +492,7 @@ export interface HealthStatus {
key_consecutive_failures?: number
key_last_failure_at?: string
key_is_active?: boolean
key_statistics?: Record<string, any>
key_statistics?: Record<string, unknown>
}
export interface HealthSummary {
@@ -537,6 +537,6 @@ export interface AdaptiveStatsResponse {
old_limit: number
new_limit: number
reason: string
[key: string]: any
[key: string]: unknown
}>
}