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

2.0 KB
Raw Blame
import type { QueryClient } from "@tanstack/react-query";
import { openclawKeys } from "@/hooks/useOpenClaw";
import { hermesKeys } from "@/hooks/useHermes";
import { invalidateZcodeProviderCaches } from "@/hooks/useZcode";
import { appHas } from "@/config/appSpecs";
import type { AppId } from "@/lib/api/types";
import { invalidatePiProviderCaches } from "./pi";

/**
 * 累加式应用的「已添加」和「默认」都现读客户端文件:往客户端文件里加了、删了供应商
 * (列表上的添加 / 移除、深链接导入、托盘添加)之后都要重读,否则卡片会停在旧的分组里。
 */
export async function refreshAdditiveLiveState(
  queryClient: QueryClient,
  app: AppId,
): Promise<void> {
  if (appHas(app, "piFamily")) {
    await invalidatePiProviderCaches(queryClient, app);
  } else if (app === "opencode") {
    await Promise.all([
      queryClient.invalidateQueries({
        queryKey: ["opencodeLiveProviderIds"],
      }),
      queryClient.invalidateQueries({ queryKey: ["opencodeDefaultModel"] }),
      queryClient.invalidateQueries({
        queryKey: ["omo", "current-provider-id"],
      }),
      queryClient.invalidateQueries({
        queryKey: ["omo-slim", "current-provider-id"],
      }),
    ]);
  } else if (app === "openclaw") {
    await Promise.all([
      queryClient.invalidateQueries({
        queryKey: openclawKeys.liveProviderIds,
      }),
      queryClient.invalidateQueries({ queryKey: openclawKeys.defaultModel }),
      queryClient.invalidateQueries({ queryKey: openclawKeys.health }),
    ]);
  } else if (app === "hermes") {
    await Promise.all([
      queryClient.invalidateQueries({ queryKey: hermesKeys.liveProviderIds }),
      queryClient.invalidateQueries({ queryKey: hermesKeys.modelConfig }),
    ]);
  } else if (app === "zcode") {
    await invalidateZcodeProviderCaches(queryClient);
  } else if (appHas(app, "additive")) {
    await queryClient.invalidateQueries({ queryKey: ["providers", app] });
  }
}