Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

6.4 KB
Raw Blame
export interface ProxyStatus {
  running: boolean;
  address: string;
  port: number;
  active_connections: number;
  total_requests: number;
  success_requests: number;
  failed_requests: number;
  success_rate: number;
  uptime_seconds: number;
  current_provider: string | null;
  current_provider_id: string | null;
  last_request_at: string | null;
  last_error: string | null;
  failover_count: number;
  active_targets?: ActiveTarget[];
}

export interface ActiveTarget {
  app_type: string;
  provider_name: string;
  provider_id: string;
}

export interface ProxyServerInfo {
  address: string;
  port: number;
  started_at: string;
}

export interface ProxyTakeoverStatus {
  claude: boolean;
  "claude-desktop"?: boolean;
  codex: boolean;
  gemini: boolean;
  grokbuild: boolean;
  agy?: boolean;
}

/** Applied under the backend switch lock, not inferred from a possibly stale UI mode. */
export interface RouteSwitchResult {
  kind: "remembered" | "route" | "stack";
  clientConfigChanged: boolean;
}

/** 应用当前的连接方式。 */
export type AppMode = "direct" | "route" | "stack";

/** 应用页模式行用的状态(后端 `get_app_mode`)。 */
export interface AppModeView {
  mode: AppMode;
  /** 客户端文件指着代理(CC Switch 运行时为真) */
  attached: boolean;
  /** 路由目标;直连模式下是上次路由的那家 */
  routeProviderId: string | null;
  /** 直连那家:直连时写进客户端的、回到直连时写回的 */
  directProviderId: string | null;
}

/** 启动时没能接上代理、已退回直连的应用。 */
export interface StartupAttachFailure {
  appType: string;
  stack: boolean;
  error: string;
}

/** Stack 模型:名单里的一家和它发布给客户端的模型 id。 */
export interface ProxyStackMember {
  providerId: string;
  modelIds: string[];
  /** 这家是默认那家(代理路由):模型走默认路由,`modelIds` 等默认换到别家后才发布。 */
  route: boolean;
  /** 这家不做默认、只做成员时发布几个模型(换默认的预览用;默认那家的 `modelIds` 可能为空)。 */
  memberModels: number;
  /** Antigravity:这家作为成员发布不了模型的原因(默认那家没有)。 */
  unpublished?: "cannotRoute" | "wireProtocol" | "noModels";
}

/**
 * Codex Stack 模型客户端看不到或看不全:`routeOwnsCatalog` 路由供应商使用自己的模型目录文件,
 * Stack 模型不发布;官方做路由时官方模型列表暂未取到:`officialModelsBundled` 暂用 Codex
 * 自带的列表(可能缺账号专属的模型),`officialModelsUnavailable` Stack 模型暂不可用;
 * `officialModelsOutdated` 本机 Codex 太旧,拉到的官方列表里没有能选的模型。
 */
export type ProxyStackNotice =
  | "routeOwnsCatalog"
  | "officialModelsBundled"
  | "officialModelsUnavailable"
  | "officialModelsOutdated";

/**
 * 官方模型列表没取到的原因(`officialModelsBundled` / `officialModelsUnavailable` 时):先是官方
 * 列表的,不可用时再跟 Codex 自带列表的。
 */
export type ProxyStackNoticeReason =
  | "noLogin"
  | "loginStale"
  | "loginIncomplete"
  | "noVersion"
  | "fetchFailed"
  | "invalidList"
  | "noCli"
  | "cliFailed"
  | "nothingUsable";

/**
 * 还在用旧模型列表的 Codex 客户端(它们只在启动时读模型目录):`daemon` 是 `codex` 命令行连的
 * 托管守护进程,可以一键重启;`others` 是桌面版、编辑器插件,要用户自己彻底退出再开。
 */
export interface CodexStaleClients {
  daemon: boolean;
  others: boolean;
  /** File-store account changed after startup; the process may cache the old login. */
  auth?: boolean;
  /**
   * 看不到桌面版、编辑器插件的进程(Windows):`others` 只表示上次确认之后目录或登录变了,
   * 不知道有没有开着。关掉提示时要告诉后端(`acknowledgeCodexStaleClients`)。
   */
  unverified?: boolean;
}

/** Codex 聚合设置里「子代理模型」下拉的一项:发布的模型和它在合并目录里的推理强度档位。 */
export interface ProxyStackSubagentModel {
  /** 发布给客户端的模型 id(`ccs-<key>/<model>`),也是写进 `[agents]` 的值。 */
  id: string;
  providerId: string;
  /** `<模型显示名>(<供应商名>)`,和 Codex 模型选择器里一样。 */
  displayName: string;
  efforts: string[];
  defaultEffort?: string;
}

/** Stack 模式的状态、名单和提示。 */
export interface ProxyStack {
  /** 在 Stack 模式(代理模式且 Stack 模式开着)。 */
  active: boolean;
  members: ProxyStackMember[];
  notice?: ProxyStackNotice;
  noticeReasons?: ProxyStackNoticeReason[];
  staleClients?: CodexStaleClients;
  /** `staleClients` 对应的目录和登录:关掉提示后这个值变了(同一个供应商上又改了目录),重新显示。 */
  staleRevision?: string;
  /** Codex:聚合设置里「子代理模型」下拉的选项,发布 Stack 模型的成员按名单顺序。 */
  subagentModels?: ProxyStackSubagentModel[];
}

/** 重启 Codex 守护进程的结果:`notRunning` 表示它没在运行,什么都没做。 */
export type CodexDaemonRestartOutcome = "restarted" | "notRunning";

/** 增删 Stack 模型失败。`partial` 为真:已部分写入,下次操作或重启 CC Switch 时补完。 */
export interface ProxyStackWriteError {
  partial: boolean;
  message: string;
}

export interface ProviderHealth {
  provider_id: string;
  app_type: string;
  is_healthy: boolean;
  consecutive_failures: number;
  last_success_at: string | null;
  last_failure_at: string | null;
  last_error: string | null;
  updated_at: string;
}

// 故障转移队列条目
export interface FailoverQueueItem {
  providerId: string;
  providerName: string;
  providerNotes?: string;
  sortIndex?: number;
}

// 全局代理配置(统一字段,三行镜像)
export interface GlobalProxyConfig {
  proxyEnabled: boolean;
  listenAddress: string;
  listenPort: number;
  enableLogging: boolean;
}

// 应用级代理配置(每个 app 独立)
export interface AppProxyConfig {
  appType: string;
  enabled: boolean;
  autoFailoverEnabled: boolean;
  maxRetries: number;
  streamingFirstByteTimeout: number;
  streamingIdleTimeout: number;
  nonStreamingTimeout: number;
  circuitFailureThreshold: number;
  circuitSuccessThreshold: number;
  circuitTimeoutSeconds: number;
  circuitErrorRateThreshold: number;
  circuitMinRequests: number;
}