mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 21:30:17 +08:00
395783e22a
* 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.
58 lines
2.0 KiB
Rust
58 lines
2.0 KiB
Rust
//! 流式健康检查日志 DAO
|
|
|
|
use crate::database::{lock_conn, Database};
|
|
use crate::error::AppError;
|
|
use crate::services::stream_check::{StreamCheckConfig, StreamCheckResult};
|
|
|
|
impl Database {
|
|
/// 保存流式检查日志
|
|
pub fn save_stream_check_log(
|
|
&self,
|
|
provider_id: &str,
|
|
provider_name: &str,
|
|
app_type: &str,
|
|
result: &StreamCheckResult,
|
|
) -> Result<i64, AppError> {
|
|
let conn = lock_conn!(self.conn);
|
|
|
|
conn.execute(
|
|
"INSERT INTO stream_check_logs
|
|
(provider_id, provider_name, app_type, status, success, message,
|
|
response_time_ms, http_status, model_used, retry_count, tested_at)
|
|
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)",
|
|
rusqlite::params![
|
|
provider_id,
|
|
provider_name,
|
|
app_type,
|
|
format!("{:?}", result.status).to_lowercase(),
|
|
result.success,
|
|
result.message,
|
|
result.response_time_ms.map(|t| t as i64),
|
|
result.http_status.map(|s| s as i64),
|
|
result.model_used,
|
|
result.retry_count as i64,
|
|
result.tested_at,
|
|
],
|
|
)
|
|
.map_err(|e| AppError::Database(e.to_string()))?;
|
|
|
|
Ok(conn.last_insert_rowid())
|
|
}
|
|
|
|
/// 获取流式检查配置
|
|
pub fn get_stream_check_config(&self) -> Result<StreamCheckConfig, AppError> {
|
|
match self.get_setting("stream_check_config")? {
|
|
Some(json) => serde_json::from_str(&json)
|
|
.map_err(|e| AppError::Message(format!("解析配置失败: {e}"))),
|
|
None => Ok(StreamCheckConfig::default()),
|
|
}
|
|
}
|
|
|
|
/// 保存流式检查配置
|
|
pub fn save_stream_check_config(&self, config: &StreamCheckConfig) -> Result<(), AppError> {
|
|
let json = serde_json::to_string(config)
|
|
.map_err(|e| AppError::Message(format!("序列化配置失败: {e}")))?;
|
|
self.set_setting("stream_check_config", &json)
|
|
}
|
|
}
|