mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 08:14:33 +08:00
785e1b5add
* feat(db): add pricing config fields to proxy_config table - Add default_cost_multiplier field per app type - Add pricing_model_source field (request/response) - Add request_model field to proxy_request_logs table - Implement schema migration v5 * feat(api): add pricing config commands and provider meta fields - Add get/set commands for default cost multiplier - Add get/set commands for pricing model source - Extend ProviderMeta with cost_multiplier and pricing_model_source - Register new commands in Tauri invoke handler * fix(proxy): apply cost multiplier to total cost only - Move multiplier calculation from per-item to total cost - Add resolve_pricing_config for provider-level override - Include request_model and cost_multiplier in usage logs - Return new fields in get_request_logs API * feat(ui): add pricing config UI and usage log enhancements - Add pricing config section to provider advanced settings - Refactor PricingConfigPanel to compact table layout - Display all three apps (Claude/Codex/Gemini) in one view - Add multiplier column and request model display to logs - Add frontend API wrappers for pricing config * feat(i18n): add pricing config translations - Add zh/en/ja translations for pricing defaults config - Add translations for multiplier, requestModel, responseModel - Add provider pricing config translations * fix(pricing): align backfill cost calculation with real-time logic - Fix backfill to deduct cache_read_tokens from input (avoid double billing) - Apply multiplier only to total cost, not to each item - Add multiplier display in request detail panel with i18n support - Use AppError::localized for backend error messages - Fix init_proxy_config_rows to use per-app default values - Fix silent failure in set_default_cost_multiplier/set_pricing_model_source - Add clippy allow annotation for test mutex across await * style: format code with cargo fmt and prettier * fix(tests): correct error type assertions in proxy DAO tests The tests expected AppError::InvalidInput but the DAO functions use AppError::localized() which returns AppError::Localized variant. Updated assertions to match the correct error type with key validation. --------- Co-authored-by: Jason <farion1231@gmail.com>
117 lines
2.4 KiB
TypeScript
117 lines
2.4 KiB
TypeScript
// 使用统计相关类型定义
|
|
|
|
export interface TokenUsage {
|
|
inputTokens: number;
|
|
outputTokens: number;
|
|
cacheReadTokens: number;
|
|
cacheCreationTokens: number;
|
|
}
|
|
|
|
export interface RequestLog {
|
|
requestId: string;
|
|
providerId: string;
|
|
providerName?: string;
|
|
appType: string;
|
|
model: string;
|
|
requestModel?: string;
|
|
costMultiplier: string;
|
|
inputTokens: number;
|
|
outputTokens: number;
|
|
cacheReadTokens: number;
|
|
cacheCreationTokens: number;
|
|
inputCostUsd: string;
|
|
outputCostUsd: string;
|
|
cacheReadCostUsd: string;
|
|
cacheCreationCostUsd: string;
|
|
totalCostUsd: string;
|
|
isStreaming: boolean;
|
|
latencyMs: number;
|
|
firstTokenMs?: number;
|
|
durationMs?: number;
|
|
statusCode: number;
|
|
errorMessage?: string;
|
|
createdAt: number;
|
|
}
|
|
|
|
export interface PaginatedLogs {
|
|
data: RequestLog[];
|
|
total: number;
|
|
page: number;
|
|
pageSize: number;
|
|
}
|
|
|
|
export interface ModelPricing {
|
|
modelId: string;
|
|
displayName: string;
|
|
inputCostPerMillion: string;
|
|
outputCostPerMillion: string;
|
|
cacheReadCostPerMillion: string;
|
|
cacheCreationCostPerMillion: string;
|
|
}
|
|
|
|
export interface UsageSummary {
|
|
totalRequests: number;
|
|
totalCost: string;
|
|
totalInputTokens: number;
|
|
totalOutputTokens: number;
|
|
totalCacheCreationTokens: number;
|
|
totalCacheReadTokens: number;
|
|
successRate: number;
|
|
}
|
|
|
|
export interface DailyStats {
|
|
date: string;
|
|
requestCount: number;
|
|
totalCost: string;
|
|
totalTokens: number;
|
|
totalInputTokens: number;
|
|
totalOutputTokens: number;
|
|
totalCacheCreationTokens: number;
|
|
totalCacheReadTokens: number;
|
|
}
|
|
|
|
export interface ProviderStats {
|
|
providerId: string;
|
|
providerName: string;
|
|
requestCount: number;
|
|
totalTokens: number;
|
|
totalCost: string;
|
|
successRate: number;
|
|
avgLatencyMs: number;
|
|
}
|
|
|
|
export interface ModelStats {
|
|
model: string;
|
|
requestCount: number;
|
|
totalTokens: number;
|
|
totalCost: string;
|
|
avgCostPerRequest: string;
|
|
}
|
|
|
|
export interface LogFilters {
|
|
appType?: string;
|
|
providerName?: string;
|
|
model?: string;
|
|
statusCode?: number;
|
|
startDate?: number;
|
|
endDate?: number;
|
|
}
|
|
|
|
export interface ProviderLimitStatus {
|
|
providerId: string;
|
|
dailyUsage: string;
|
|
dailyLimit?: string;
|
|
dailyExceeded: boolean;
|
|
monthlyUsage: string;
|
|
monthlyLimit?: string;
|
|
monthlyExceeded: boolean;
|
|
}
|
|
|
|
export type TimeRange = "1d" | "7d" | "30d";
|
|
|
|
export interface StatsFilters {
|
|
timeRange: TimeRange;
|
|
providerId?: string;
|
|
appType?: string;
|
|
}
|