mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
Feat/provider icon color (#385)
* feat(ui): add color prop support to ProviderIcon component * feat(health): add stream check core functionality Add new stream-based health check module to replace model_test: - Add stream_check command layer with single and batch provider checks - Add stream_check DAO layer for config and log persistence - Add stream_check service layer with retry mechanism and health status evaluation - Add frontend HealthStatusIndicator component - Add frontend useStreamCheck hook This provides more comprehensive health checking capabilities. * refactor(health): replace model_test with stream_check Replace model_test module with stream_check across the codebase: - Remove model_test command and service modules - Update command registry in lib.rs to use stream_check commands - Update module exports in commands/mod.rs and services/mod.rs - Remove frontend useModelTest hook - Update stream_check command implementation This refactoring provides clearer naming and better separation of concerns. * refactor(db): clean up unused database tables and optimize schema Remove deprecated and unused database tables: - Remove proxy_usage table (replaced by proxy_request_logs) - Remove usage_daily_stats table (aggregation done on-the-fly) - Rename model_test_logs to stream_check_logs with updated schema - Remove related DAO methods for proxy_usage - Update usage_stats service to use proxy_request_logs only - Refactor usage_script to work with new schema This simplifies the database schema and removes redundant data storage. * refactor(ui): update frontend components for stream check Update frontend components to use stream check API: - Refactor ModelTestConfigPanel to use stream check config - Update API layer to use stream_check commands - Add HealthStatus type and StreamCheckResult interface - Update ProviderList to use new health check integration - Update AutoFailoverConfigPanel with stream check references - Improve UI layout and configuration options This completes the frontend migration from model_test to stream_check. * feat(health): add configurable test models and reasoning effort support Enhance stream check service with configurable test models: - Add claude_model, codex_model, gemini_model to StreamCheckConfig - Support reasoning effort syntax (model@level or model#level) - Parse and apply reasoning_effort for OpenAI-compatible models - Remove hardcoded model names from check functions - Add unit tests for model parsing logic - Remove obsolete model_test source files This allows users to customize which models are used for health checks.
This commit is contained in:
+27
-52
@@ -1,89 +1,64 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { AppId } from "./types";
|
||||
|
||||
export interface ModelTestConfig {
|
||||
// ===== 流式健康检查类型 =====
|
||||
|
||||
export type HealthStatus = "operational" | "degraded" | "failed";
|
||||
|
||||
export interface StreamCheckConfig {
|
||||
timeoutSecs: number;
|
||||
maxRetries: number;
|
||||
degradedThresholdMs: number;
|
||||
claudeModel: string;
|
||||
codexModel: string;
|
||||
geminiModel: string;
|
||||
testPrompt: string;
|
||||
timeoutSecs: number;
|
||||
}
|
||||
|
||||
export interface ModelTestResult {
|
||||
export interface StreamCheckResult {
|
||||
status: HealthStatus;
|
||||
success: boolean;
|
||||
message: string;
|
||||
responseTimeMs?: number;
|
||||
httpStatus?: number;
|
||||
modelUsed: string;
|
||||
testedAt: number;
|
||||
retryCount: number;
|
||||
}
|
||||
|
||||
export interface ModelTestLog {
|
||||
id: number;
|
||||
providerId: string;
|
||||
providerName: string;
|
||||
appType: string;
|
||||
model: string;
|
||||
prompt: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
responseTimeMs?: number;
|
||||
httpStatus?: number;
|
||||
testedAt: number;
|
||||
}
|
||||
// ===== 流式健康检查 API =====
|
||||
|
||||
/**
|
||||
* 测试单个供应商的模型可用性
|
||||
* 流式健康检查(单个供应商)
|
||||
*/
|
||||
export async function testProviderModel(
|
||||
export async function streamCheckProvider(
|
||||
appType: AppId,
|
||||
providerId: string,
|
||||
): Promise<ModelTestResult> {
|
||||
return invoke("test_provider_model", { appType, providerId });
|
||||
): Promise<StreamCheckResult> {
|
||||
return invoke("stream_check_provider", { appType, providerId });
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量测试所有供应商
|
||||
* 批量流式健康检查
|
||||
*/
|
||||
export async function testAllProvidersModel(
|
||||
export async function streamCheckAllProviders(
|
||||
appType: AppId,
|
||||
proxyTargetsOnly: boolean = false,
|
||||
): Promise<Array<[string, ModelTestResult]>> {
|
||||
return invoke("test_all_providers_model", { appType, proxyTargetsOnly });
|
||||
): Promise<Array<[string, StreamCheckResult]>> {
|
||||
return invoke("stream_check_all_providers", { appType, proxyTargetsOnly });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型测试配置
|
||||
* 获取流式检查配置
|
||||
*/
|
||||
export async function getModelTestConfig(): Promise<ModelTestConfig> {
|
||||
return invoke("get_model_test_config");
|
||||
export async function getStreamCheckConfig(): Promise<StreamCheckConfig> {
|
||||
return invoke("get_stream_check_config");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存模型测试配置
|
||||
* 保存流式检查配置
|
||||
*/
|
||||
export async function saveModelTestConfig(
|
||||
config: ModelTestConfig,
|
||||
export async function saveStreamCheckConfig(
|
||||
config: StreamCheckConfig,
|
||||
): Promise<void> {
|
||||
return invoke("save_model_test_config", { config });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型测试日志
|
||||
*/
|
||||
export async function getModelTestLogs(
|
||||
appType?: string,
|
||||
providerId?: string,
|
||||
limit?: number,
|
||||
): Promise<ModelTestLog[]> {
|
||||
return invoke("get_model_test_logs", { appType, providerId, limit });
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理旧的测试日志
|
||||
*/
|
||||
export async function cleanupModelTestLogs(
|
||||
keepCount?: number,
|
||||
): Promise<number> {
|
||||
return invoke("cleanup_model_test_logs", { keepCount });
|
||||
return invoke("save_stream_check_config", { config });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user