Files
CC-Switch/src/lib/api/model-test.ts
T
Dex Miller f9d80b8dc3 feat(stream-check): enhance health check with configurable prompt and CLI-compatible requests (#623)
- 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
2026-01-13 11:36:19 +08:00

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 });
}