mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 23:56:02 +08:00
f9d80b8dc3
- Add configurable test prompt field to StreamCheckConfig - Implement Claude CLI-compatible request format with proper headers: - Authorization + x-api-key dual auth - anthropic-beta, anthropic-version headers - x-stainless-* SDK headers with dynamic OS/arch detection - URL with ?beta=true parameter - Implement Codex CLI-compatible Responses API format: - /v1/responses endpoint - input array format with reasoning effort support - codex_cli_rs user-agent and originator headers - Add dynamic OS name and CPU architecture detection - Internationalize error messages (Chinese -> English) - Add test prompt Textarea UI component with i18n support - Remove obsolete testPromptDesc translation key
66 lines
1.5 KiB
TypeScript
66 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;
|
|
}
|
|
|
|
// ===== 流式健康检查 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 });
|
|
}
|