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

@@ -10,7 +10,7 @@ interface CacheItem<T> {
}
class MemoryCache {
private cache: Map<string, CacheItem<any>> = new Map()
private cache: Map<string, CacheItem<unknown>> = new Map()
private defaultTTL = 60000 // 默认缓存60秒
/**

View File

@@ -121,13 +121,13 @@ export function parseNullableNumberInput(
* // In template:
* <Input @update:model-value="handleRateLimit" />
*/
export function createNumberInputHandler<T extends Record<string, any>>(
export function createNumberInputHandler<T extends Record<string, unknown>>(
obj: T,
field: keyof T,
options: Parameters<typeof parseNumberInput>[1] = {}
) {
return (value: string | number | null | undefined) => {
(obj as any)[field] = parseNumberInput(value, options)
(obj as Record<string, unknown>)[field as string] = parseNumberInput(value, options)
}
}

View File

@@ -7,7 +7,7 @@ const RETRY_DELAY = 1000 // 1秒
const CACHE_BUSTER_DELAY = 2000 // 2秒后尝试缓存清除
// 模块缓存
const moduleCache = new Map<string, Promise<any>>()
const moduleCache = new Map<string, Promise<unknown>>()
/**
* 清除浏览器缓存的工具函数
@@ -28,14 +28,15 @@ function clearBrowserCache() {
/**
* 检查错误是否是网络/缓存相关
*/
function isNetworkOrCacheError(error: any): boolean {
const errorMessage = error?.message || ''
function isNetworkOrCacheError(error: unknown): boolean {
const err = error as { message?: string; name?: string } | null
const errorMessage = err?.message || ''
return (
errorMessage.includes('Failed to fetch') ||
errorMessage.includes('Loading chunk') ||
errorMessage.includes('dynamically imported module') ||
errorMessage.includes('NetworkError') ||
error?.name === 'ChunkLoadError'
err?.name === 'ChunkLoadError'
)
}
@@ -46,7 +47,7 @@ function isNetworkOrCacheError(error: any): boolean {
* @param cacheKey 缓存键
* @returns Promise
*/
export async function importWithRetry<T = any>(
export async function importWithRetry<T = unknown>(
importFn: () => Promise<T>,
retries: number = MAX_RETRIES,
cacheKey?: string
@@ -54,7 +55,7 @@ export async function importWithRetry<T = any>(
try {
// 如果有缓存键且缓存中存在,直接返回
if (cacheKey && moduleCache.has(cacheKey)) {
return await moduleCache.get(cacheKey)!
return await moduleCache.get(cacheKey) as T
}
const importPromise = importFn()