mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 16:26:16 +08:00
507bf038a9
* chore(stream-check): update default health check models to latest Replaces deprecated gpt-5.1-codex@low with gpt-5.4@low and switches the Gemini default from gemini-3-pro-preview to gemini-3-flash-preview to pick the lightest variant of the latest series for fast, low-cost health checks. https://claude.ai/code/session_01NGWLchcTP76rJHjiP5Ehte * feat(stream-check): detect model-not-found errors with dedicated toast Health check previously classified failures purely by HTTP status code, which meant deprecated/invalid models showed up as a generic "Not found (404)" error pointing users to check the Base URL — misleading when the URL is fine and only the test model is wrong (e.g. gpt-5.1-codex after it was retired). Backend: add detect_error_category() that inspects 4xx response bodies for model-not-found indicators (model_not_found, does not exist, invalid model, not_found_error, etc.) and returns a "modelNotFound" category. Thread the resolved test model through build_stream_check_result so the failed result carries it in model_used. Add StreamCheckResult .error_category field (serde-skipped when None). Frontend: useStreamCheck branches on errorCategory === "modelNotFound" before the HTTP-status fallback and renders a toast.error with the model name and a description pointing to Model Test Config. Add i18n keys (modelNotFound / modelNotFoundHint) for zh/en/ja. Tests: unit-test detect_error_category against real OpenAI/Anthropic error shapes, 5xx false-positive avoidance, and plain 401 auth errors. https://claude.ai/code/session_01NGWLchcTP76rJHjiP5Ehte * fix(stream-check): add missing error_category field in fallback The error_category field was added to StreamCheckResult in this branch but the fallback constructor in stream_check_all_providers was not updated, which broke cargo build. --------- Co-authored-by: Claude <noreply@anthropic.com>
68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import type { AppId } from "./types";
|
|
|
|
// ===== 流式健康检查类型 =====
|
|
|
|
export type HealthStatus = "operational" | "degraded" | "failed";
|
|
|
|
export interface StreamCheckConfig {
|
|
timeoutSecs: number;
|
|
maxRetries: number;
|
|
degradedThresholdMs: number;
|
|
claudeModel: string;
|
|
codexModel: string;
|
|
geminiModel: string;
|
|
testPrompt: string;
|
|
}
|
|
|
|
export interface StreamCheckResult {
|
|
status: HealthStatus;
|
|
success: boolean;
|
|
message: string;
|
|
responseTimeMs?: number;
|
|
httpStatus?: number;
|
|
modelUsed: string;
|
|
testedAt: number;
|
|
retryCount: number;
|
|
/** 细粒度错误分类,如 "modelNotFound" */
|
|
errorCategory?: string;
|
|
}
|
|
|
|
// ===== 流式健康检查 API =====
|
|
|
|
/**
|
|
* 流式健康检查(单个供应商)
|
|
*/
|
|
export async function streamCheckProvider(
|
|
appType: AppId,
|
|
providerId: string,
|
|
): Promise<StreamCheckResult> {
|
|
return invoke("stream_check_provider", { appType, providerId });
|
|
}
|
|
|
|
/**
|
|
* 批量流式健康检查
|
|
*/
|
|
export async function streamCheckAllProviders(
|
|
appType: AppId,
|
|
proxyTargetsOnly: boolean = false,
|
|
): Promise<Array<[string, StreamCheckResult]>> {
|
|
return invoke("stream_check_all_providers", { appType, proxyTargetsOnly });
|
|
}
|
|
|
|
/**
|
|
* 获取流式检查配置
|
|
*/
|
|
export async function getStreamCheckConfig(): Promise<StreamCheckConfig> {
|
|
return invoke("get_stream_check_config");
|
|
}
|
|
|
|
/**
|
|
* 保存流式检查配置
|
|
*/
|
|
export async function saveStreamCheckConfig(
|
|
config: StreamCheckConfig,
|
|
): Promise<void> {
|
|
return invoke("save_stream_check_config", { config });
|
|
}
|