A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
import { useMemo, useState, useEffect } from "react";
import { GripVertical, ChevronDown, ChevronUp } from "lucide-react";
import { useTranslation } from "react-i18next";
import type { QueryKey } from "@tanstack/react-query";
import type {
DraggableAttributes,
DraggableSyntheticListeners,
} from "@dnd-kit/core";
import type { Provider } from "@/types";
import type { AppId } from "@/lib/api";
import { cn } from "@/lib/utils";
import { ProviderIconBox } from "@/components/ProviderIconBox";
import { HoverTip } from "@/components/ui/hover-tip";
import UsageFooter from "@/components/UsageFooter";
import SubscriptionQuotaFooter from "@/components/SubscriptionQuotaFooter";
import CopilotCliQuotaFooter from "@/components/CopilotCliQuotaFooter";
import CopilotQuotaFooter from "@/components/CopilotQuotaFooter";
import CodexOauthQuotaFooter from "@/components/CodexOauthQuotaFooter";
import XaiOauthQuotaFooter from "@/components/XaiOauthQuotaFooter";
import AgyAccountQuotaFooter from "@/components/AgyAccountQuotaFooter";
import { ClaudeBoundAccountLine } from "@/components/providers/forms/ClaudeOfficialSection";
import { GrokBoundAccountLine } from "@/components/providers/forms/GrokOfficialAccount";
import ClaudeAccountQuotaFooter from "@/components/ClaudeAccountQuotaFooter";
import { claudePlanLabel } from "@/lib/claudePlan";
import {
subscriptionKeys,
useClaudeDefaultPlan,
} from "@/lib/query/subscription";
import { useQuotaPlan } from "@/lib/query/accountPlans";
import type { CopilotQuota } from "@/lib/query/copilot";
import KimiAccountQuotaFooter from "@/components/KimiAccountQuotaFooter";
import { PROVIDER_TYPES, TEMPLATE_TYPES } from "@/config/constants";
import {
extractCodexExperimentalBearerToken,
extractProviderBaseUrl,
} from "@/utils/codexConfigUtils";
import {
copilotByokConfigOf,
copilotEnvOf,
isCopilotByok,
} from "@/config/copilotConfig";
import {
canSwitchAgyAccount,
resolveManagedAccountId,
} from "@/lib/authBinding";
import {
isOfficialAccount,
resolveCodexOfficialIdentity,
supportsConnectivityCheck,
} from "@/utils/providerCapabilities";
import { useProviderHealth } from "@/lib/query/failover";
import { useUsageQuery } from "@/lib/query/queries";
import { resolveProviderIcon } from "@/utils/providerIcon";
import { isWorkBuddyOfficial } from "@/components/providers/workbuddyOfficial";
import { WorkBuddyOfficialAccountLine } from "@/components/providers/WorkBuddyOfficialAccountLine";
import { WorkBuddyQuotaFooter } from "@/components/providers/WorkBuddyQuotaFooter";
import {
AgyOfficialSubtitle,
CodebuddyOfficialAccountLine,
CodebuddyOfficialQuota,
CodexOauthAccountLine,
CopilotAccountSubtitle,
XaiAccountSubtitle,
} from "./ProviderCardAccountLines";
import { ProviderCardActions } from "./ProviderCardActions";
import {
terminalAvailable,
terminalIsIsolated,
terminalNeedsRoute,
} from "./OpenTerminalDialog";
import type { CardChip, CardPresentation, CardTone } from "./presentation";
import { appHas } from "@/config/appSpecs";
const copilotPlan = (data: unknown) => (data as CopilotQuota).plan;
interface DragHandleProps {
attributes: DraggableAttributes;
listeners: DraggableSyntheticListeners;
isDragging: boolean;
}
interface ProviderCardProps {
provider: Provider;
appId: AppId;
/** 卡片怎么画:模式色、状态 / 按钮、徽标(由列表按模式算好) */
presentation: CardPresentation;
/** 用来决定官方订阅 / OAuth 额度是否自动查询 */
isCurrent: boolean;
onEdit: (provider: Provider) => void;
onDelete: (provider: Provider) => void;
onConfigureUsage?: (provider: Provider) => void;
onOpenWebsite: (url: string) => void;
onDuplicate?: (provider: Provider) => void;
onTest?: (provider: Provider) => void;
onOpenTerminal?: (provider: Provider) => void;
isTesting?: boolean;
dragHandleProps?: DragHandleProps;
}
/** 当前那张:模式色边框 + 淡底;共存式应用的默认那家同直连色。 */
const TONE_CLASS: Record<CardTone, string> = {
direct: "border-direct-border bg-direct-soft",
route: "border-route-border bg-route-soft",
stack: "border-stack-border bg-stack-soft",
};
const CHIP_CLASS: Record<CardChip["tone"], string> = {
outline: "border border-border-strong text-fg-2",
direct: "bg-direct-soft text-direct-text",
route: "bg-route-soft text-route-text",
stack: "bg-stack-soft text-stack-text",
success: "bg-success-soft text-success-text",
warning: "bg-warning-soft text-warning-text",
danger: "bg-danger-soft text-danger-text",
};
export function CardChipBadge({ chip }: { chip: CardChip }) {
return (
<span
title={chip.title}
className={cn(
"inline-flex h-[18px] shrink-0 items-center whitespace-nowrap rounded-full px-1.5 text-badge",
CHIP_CLASS[chip.tone],
chip.title && "cursor-help",
)}
>
{chip.label}
</span>
);
}
function HealthChip({
consecutiveFailures,
isHealthy,
}: {
consecutiveFailures: number;
isHealthy?: boolean;
}) {
const { t } = useTranslation();
const chip: CardChip =
consecutiveFailures === 0
? { key: "health", label: t("health.operational"), tone: "success" }
: isHealthy !== false
? { key: "health", label: t("health.degraded"), tone: "warning" }
: { key: "health", label: t("health.circuitOpen"), tone: "danger" };
return <CardChipBadge chip={chip} />;
}
/** 判断是否为官方供应商(无自定义 base URL / API key,直连官方 API) */
function isOfficialProvider(provider: Provider, appId: AppId): boolean {
if (appId === "kimi") return isOfficialAccount(appId, provider);
if (provider.category === "official") {
return true;
}
if (appId === "copilot") return !isCopilotByok(provider.settingsConfig);
const config = provider.settingsConfig as Record<string, any>;
if (appId === "claude") {
const baseUrl = config?.env?.ANTHROPIC_BASE_URL;
return !baseUrl || (typeof baseUrl === "string" && baseUrl.trim() === "");
}
if (appId === "codex") {
// 无 OPENAI_API_KEY → 使用 Codex CLI 内置 OAuth(官方)
const apiKey = config?.auth?.OPENAI_API_KEY;
const bearerToken =
typeof config?.config === "string"
? extractCodexExperimentalBearerToken(config.config)
: undefined;
return (
!bearerToken &&
(!apiKey || (typeof apiKey === "string" && apiKey.trim() === ""))
);
}
if (appId === "gemini" || appId === "agy") {
// 无 GEMINI_API_KEY 且无 GOOGLE_GEMINI_BASE_URL → Google OAuth 官方模式
const apiKey = config?.env?.GEMINI_API_KEY;
const baseUrl = config?.env?.GOOGLE_GEMINI_BASE_URL;
return (
(!apiKey || (typeof apiKey === "string" && apiKey.trim() === "")) &&
(!baseUrl || (typeof baseUrl === "string" && baseUrl.trim() === ""))
);
}
return false;
}
/** Copilot CLI 卡片显示模型(`COPILOT_MODEL`),自带模型卡再带上地址。 */
function extractCopilotSummary(provider: Provider): string | null {
// 官方卡写的是 --model;自带模型卡写 providers.json 里的第一个模型(打开终端用它)和地址
if (!isCopilotByok(provider.settingsConfig)) {
return copilotEnvOf(provider.settingsConfig).COPILOT_MODEL?.trim() || null;
}
const { provider: node, models } = copilotByokConfigOf(
provider.settingsConfig,
);
const ids = models.map((model) => model.id.trim()).filter(Boolean);
const model = ids.length > 1 ? `${ids[0]} +${ids.length - 1}` : ids[0];
const baseUrl = node.baseUrl.trim();
if (model && baseUrl) return `${model} · ${baseUrl}`;
return model || baseUrl || null;
}
const extractApiUrl = (provider: Provider, fallbackText: string) => {
if (provider.notes?.trim()) {
return provider.notes.trim();
}
if (provider.websiteUrl) {
return provider.websiteUrl;
}
return extractProviderBaseUrl(provider.settingsConfig) ?? fallbackText;
};
export function ProviderCard({
provider,
appId,
presentation,
isCurrent,
onEdit,
onDelete,
onConfigureUsage,
onOpenWebsite,
onDuplicate,
onTest,
onOpenTerminal,
isTesting,
dragHandleProps,
}: ProviderCardProps) {
const { t } = useTranslation();
const codexOfficialIdentity = resolveCodexOfficialIdentity(appId, provider);
const isBoundCodexOfficial = codexOfficialIdentity === "managed_account";
const isCodexOauth =
appId === "codex"
? isBoundCodexOfficial
: provider.meta?.providerType === PROVIDER_TYPES.CODEX_OAUTH;
const managedCodexAccountId = resolveManagedAccountId(
provider.meta,
"codex_oauth",
)?.trim();
// CodeBuddy 官方登录卡:第二行写绑定的账号,右侧写这个号的套餐积分
const isCodebuddyOfficial =
appId === "codebuddy" && provider.category === "official";
const codebuddyAccountId = isCodebuddyOfficial
? resolveManagedAccountId(provider.meta, "codebuddy_oauth")?.trim() || null
: null;
const manualNote = provider.notes?.trim() || undefined;
const { data: health } = useProviderHealth(
provider.id,
appId,
Boolean(presentation.showHealth) && appHas(appId, "localProxy"),
);
const fallbackUrlText = t("provider.notConfigured", {
defaultValue: "未配置接口地址",
});
const displayUrl = useMemo(() => {
return extractApiUrl(provider, fallbackUrlText);
}, [provider, fallbackUrlText]);
const copilotSummary = useMemo(
() => (appId === "copilot" ? extractCopilotSummary(provider) : null),
[appId, provider],
);
const isClickableUrl = useMemo(() => {
if (provider.notes?.trim()) {
return false;
}
if (displayUrl === fallbackUrlText) {
return false;
}
return true;
}, [provider.notes, displayUrl, fallbackUrlText]);
const isOfficial = isOfficialProvider(provider, appId);
// Claude 官方卡绑了 Claude 官方账号:副标题写账号,额度按这个号查
const claudeBoundAccountId =
appId === "claude" && isOfficial
? resolveManagedAccountId(provider.meta, "claude_official")?.trim() ||
null
: null;
// Grok 官方卡绑了授权中心的 xAI 账号:额度按这个号查,和 xai_oauth 卡同一份缓存
const grokBoundAccountId =
appId === "grokbuild" && isOfficial
? resolveManagedAccountId(
provider.meta,
PROVIDER_TYPES.XAI_OAUTH,
)?.trim() || null
: null;
// Antigravity 官方卡(绑号或跟随 agy 当前登录)没存过用量配置时默认查官方额度(同托盘)
const agyOfficialDefaultsOn =
appId === "agy" && isOfficial && !provider.meta?.usage_script;
// 绑了账号的官方卡(Codex / Claude / Grok)默认查额度,和 Kimi、agy 的账号卡一样(同托盘)
const usageEnabled =
provider.meta?.usage_script?.enabled ??
(isBoundCodexOfficial ||
Boolean(claudeBoundAccountId) ||
Boolean(grokBoundAccountId) ||
agyOfficialDefaultsOn);
const supportsOfficialSubscription =
isOfficial && appHas(appId, "officialSubscription");
const isOfficialSubscriptionUsage =
agyOfficialDefaultsOn ||
provider.meta?.usage_script?.templateType ===
TEMPLATE_TYPES.OFFICIAL_SUBSCRIPTION;
const officialSubscriptionEnabled =
supportsOfficialSubscription && usageEnabled && isOfficialSubscriptionUsage;
// 没绑账号的 Claude 官方卡用 Claude Code 的默认登录:开了额度查询时,地址后面跟默认登录的套餐
const showClaudeDefaultPlan =
appId === "claude" &&
isOfficial &&
!claudeBoundAccountId &&
officialSubscriptionEnabled;
const { data: claudeDefaultPlan } = useClaudeDefaultPlan(
showClaudeDefaultPlan,
);
const claudeDefaultPlanLabel = showClaudeDefaultPlan
? claudePlanLabel(
t,
claudeDefaultPlan?.subscriptionType,
claudeDefaultPlan?.rateLimitTier,
)
: null;
// Copilot CLI 官方卡的 Premium 额度可在「配置用量查询」里开关;没设置过时,绑了授权中心
// 账号的卡默认显示,没绑的默认不显示(打开后跟着 Copilot CLI 当前登录的账号查)。
const isCopilotCliOfficial = appId === "copilot" && isOfficial;
const copilotCliQuotaEnabled =
isCopilotCliOfficial &&
(provider.meta?.usage_script?.enabled ??
Boolean(resolveManagedAccountId(provider.meta, "github_copilot")));
const isCopilot =
appId !== "copilot" &&
(provider.meta?.providerType === PROVIDER_TYPES.GITHUB_COPILOT ||
provider.meta?.usage_script?.templateType === "github_copilot");
// Copilot 反代卡和 Codex OAuth 卡同一套写法:副标题(官网地址的位置)写绑定的
// GitHub 账号,未绑定时回落授权中心的默认账号;账号读不到就保留原来的网址。
const copilotAccountId = isCopilot
? resolveManagedAccountId(
provider.meta,
PROVIDER_TYPES.GITHUB_COPILOT,
)?.trim() || undefined
: undefined;
// xAI OAuth (SuperGrok 反代):额度经自管 OAuth token 自动显示,副标题同 Copilot / Codex OAuth 写账号
const isXaiOauthProvider =
provider.meta?.providerType === PROVIDER_TYPES.XAI_OAUTH;
// 绑了 xAI 账号的 Grok 官方卡额度也走 xai_oauth;副标题另由 GrokBoundAccountLine 显示
const isXaiOauth = isXaiOauthProvider || Boolean(grokBoundAccountId);
const xaiAccountId = isXaiOauthProvider
? resolveManagedAccountId(
provider.meta,
PROVIDER_TYPES.XAI_OAUTH,
)?.trim() || undefined
: undefined;
// 支持 agy 切号的平台上,Antigravity 官方卡查询所绑定账号的额度与在用状态(由条件挂载的子组件订阅缓存)。
const canShowAgyAccount =
appId === "agy" && isOfficial && canSwitchAgyAccount();
const agyBoundAccountId = canShowAgyAccount
? resolveManagedAccountId(provider.meta, "agy_oauth")?.trim() || null
: null;
// 副标题末尾的套餐:读右边额度那个查询的缓存(键和各额度 footer 一致),额度查到才有。
// Claude 官方卡另有写法(claudeDefaultPlanLabel / ClaudeBoundAccountLine)
const quotaPlanKey: QueryKey | null = isCopilot
? [
"copilot",
"quota",
resolveManagedAccountId(provider.meta, PROVIDER_TYPES.GITHUB_COPILOT) ??
"default",
]
: isCodexOauth
? !isBoundCodexOfficial || usageEnabled
? [
"codex_oauth",
"quota",
resolveManagedAccountId(
provider.meta,
PROVIDER_TYPES.CODEX_OAUTH,
) ?? "default",
]
: null
: isXaiOauth
? !grokBoundAccountId || usageEnabled
? [
"xai_oauth",
"quota",
resolveManagedAccountId(
provider.meta,
PROVIDER_TYPES.XAI_OAUTH,
) ?? "default",
]
: null
: appId === "kimi" && isOfficial
? ["kimi_oauth", "quota", provider.id]
: isOfficial && officialSubscriptionEnabled && appId !== "claude"
? agyBoundAccountId
? ["agy_oauth", "quota", agyBoundAccountId]
: subscriptionKeys.quota(appId)
: null;
const quotaPlan = useQuotaPlan(
quotaPlanKey,
isCopilot ? copilotPlan : undefined,
);
const subtitlePlan = claudeDefaultPlanLabel ?? quotaPlan;
const planSuffix = (className = "-ms-1") =>
subtitlePlan ? (
<span className={cn("shrink-0", className)}>· {subtitlePlan}</span>
) : null;
// 获取用量数据以判断是否有多套餐,按用户配置刷新,不依赖供应商启用状态。
const autoQueryInterval = provider.meta?.usage_script?.autoQueryInterval ?? 0;
// Copilot 额度由专用 footer 查询;展开判定必须复用脚本查询谓词,
// 因为禁用的 React Query observer 仍会返回同 key 的旧缓存。
const scriptUsageActive =
usageEnabled && !isOfficial && !isOfficialSubscriptionUsage && !isCopilot;
const { data: usage } = useUsageQuery(provider.id, appId, {
enabled: scriptUsageActive,
autoQueryInterval,
});
const isTokenPlan =
provider.meta?.usage_script?.templateType === "token_plan";
// 官方订阅的额度窗口不能按普通多套餐展开;缓存残留的旧脚本结果同样不认。
const hasMultiplePlans =
scriptUsageActive &&
!isTokenPlan &&
usage?.success &&
usage.data &&
usage.data.length > 1;
const [isExpanded, setIsExpanded] = useState(false);
const expandLabel = isExpanded
? t("usage.collapse", { defaultValue: "收起" })
: t("usage.expand", { defaultValue: "展开" });
useEffect(() => {
if (hasMultiplePlans) {
setIsExpanded(true);
}
}, [hasMultiplePlans]);
const handleOpenWebsite = () => {
if (!isClickableUrl) {
return;
}
onOpenWebsite(displayUrl);
};
const defaultUrlSubtitle =
displayUrl && subtitlePlan ? (
<div className="mt-0.5 flex min-w-0 items-center gap-2 text-caption text-fg-2">
<button
type="button"
onClick={handleOpenWebsite}
className={cn(
"inline-flex min-w-0 items-center overflow-hidden text-start",
isClickableUrl
? "cursor-pointer decoration-border-strong underline-offset-[3px] hover:underline"
: "cursor-default",
)}
title={displayUrl}
disabled={!isClickableUrl}
>
<span className="min-w-0 truncate">{displayUrl}</span>
</button>
{planSuffix()}
</div>
) : displayUrl ? (
<button
type="button"
onClick={handleOpenWebsite}
className={cn(
"mt-0.5 inline-flex max-w-full items-center overflow-hidden text-start text-caption text-fg-2",
isClickableUrl
? "cursor-pointer decoration-border-strong underline-offset-[3px] hover:underline"
: "cursor-default",
)}
title={displayUrl}
disabled={!isClickableUrl}
>
<span className="min-w-0 truncate">{displayUrl}</span>
</button>
) : null;
const xaiSubtitle = isXaiOauthProvider ? (
<XaiAccountSubtitle
providerName={provider.name}
accountId={xaiAccountId}
manualNote={manualNote}
planSuffix={planSuffix()}
fallback={defaultUrlSubtitle}
/>
) : (
defaultUrlSubtitle
);
const oauthSubtitle = isCopilot ? (
<CopilotAccountSubtitle
providerName={provider.name}
accountId={copilotAccountId}
manualNote={manualNote}
planSuffix={planSuffix()}
fallback={xaiSubtitle}
/>
) : (
xaiSubtitle
);
return (
<div
data-tour="provider-card"
className={cn(
"group relative rounded-panel border transition-[border-color,box-shadow,background-color] duration-150",
presentation.tone
? TONE_CLASS[presentation.tone]
: "border-border bg-surface hover:border-border-strong hover:shadow-v7-sm",
dragHandleProps?.isDragging && "cursor-grabbing shadow-v7-md",
)}
>
<div className="flex min-h-card items-center gap-3 py-card-y pe-3 ps-2">
{dragHandleProps ? (
<button
type="button"
className={cn(
"flex h-6 w-4 shrink-0 cursor-grab items-center justify-center text-fg-3 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100 active:cursor-grabbing",
dragHandleProps.isDragging && "cursor-grabbing opacity-100",
)}
aria-label={t("provider.dragHandle")}
{...dragHandleProps.attributes}
{...dragHandleProps.listeners}
>
<GripVertical className="h-4 w-4" />
</button>
) : (
<span className="w-4 shrink-0" />
)}
<ProviderIconBox
icon={resolveProviderIcon(appId, provider.icon, provider.iconColor)}
name={provider.name}
color={provider.iconColor}
className={cn(
// 不再垫白底:单色 / 近黑笔画的图标跟随文字色(ProviderIcon 里换成 currentColor),
// 自带底色的 tile 图标铺满整框
"bg-transparent text-fg-1",
presentation.dim && "opacity-60",
)}
fallbackClassName="bg-transparent text-fg-2"
/>
<div className="min-w-0 flex-1">
<div className="flex min-w-0 items-center gap-1.5">
<h3
className={cn(
"m-0 min-w-0 truncate text-strong",
presentation.dim ? "text-fg-2" : "text-fg-1",
)}
title={provider.name}
>
{provider.name}
</h3>
{presentation.chips.map((chip) => (
<CardChipBadge key={chip.key} chip={chip} />
))}
{presentation.showHealth && health && (
<HealthChip
consecutiveFailures={health.consecutive_failures}
isHealthy={health.is_healthy}
/>
)}
</div>
{isCodebuddyOfficial ? (
<CodebuddyOfficialAccountLine
provider={provider}
accountId={codebuddyAccountId}
manualNote={manualNote}
onEdit={onEdit}
/>
) : appId === "workbuddy" && isWorkBuddyOfficial(provider) ? (
<WorkBuddyOfficialAccountLine provider={provider} onEdit={onEdit} />
) : codexOfficialIdentity === "native_login" ? (
<div className="mt-0.5 flex min-w-0 items-center gap-2 text-caption text-fg-2">
<span className="min-w-0 truncate" title={manualNote}>
{manualNote ??
t("codex.followCodexLoginDescription", {
defaultValue: "账号会随 Codex CLI 当前登录变化",
})}
</span>
{planSuffix()}
</div>
) : isCodexOauth ? (
<CodexOauthAccountLine
provider={provider}
accountId={managedCodexAccountId}
manualNote={manualNote}
planSuffix={planSuffix()}
onEdit={onEdit}
/>
) : grokBoundAccountId ? (
<GrokBoundAccountLine
accountId={grokBoundAccountId}
providerName={provider.name}
note={manualNote}
plan={subtitlePlan}
/>
) : claudeBoundAccountId ? (
<ClaudeBoundAccountLine
accountId={claudeBoundAccountId}
providerName={provider.name}
note={manualNote}
showPlan={usageEnabled}
/>
) : canShowAgyAccount ? (
<AgyOfficialSubtitle
boundAccountId={agyBoundAccountId}
planSuffix={planSuffix("-ms-0.5")}
fallback={oauthSubtitle}
/>
) : copilotSummary ? (
<div className="mt-0.5 flex min-w-0 items-center gap-1.5 text-caption text-fg-2">
<span className="min-w-0 truncate" title={copilotSummary}>
{copilotSummary}
</span>
{planSuffix("-ms-0.5")}
</div>
) : (
oauthSubtitle
)}
</div>
<div className="flex shrink-0 items-center gap-3">
{/* 额度列宽度随密度变化(见 QuotaLines 与 --w-quota-*) */}
<div className="max-w-[calc(var(--w-quota-text,136px)+var(--w-quota-reset,52px)+20px)] text-end">
<div className="flex items-center justify-end gap-1">
{copilotCliQuotaEnabled ? (
<CopilotCliQuotaFooter
meta={provider.meta}
isCurrent={isCurrent}
/>
) : isCopilot ? (
<CopilotQuotaFooter
meta={provider.meta}
inline={true}
isCurrent={isCurrent}
/>
) : isCodexOauth ? (
!isBoundCodexOfficial || usageEnabled ? (
<CodexOauthQuotaFooter
meta={provider.meta}
inline={true}
isCurrent={isCurrent}
autoQueryInterval={
isBoundCodexOfficial
? (provider.meta?.usage_script?.autoQueryInterval ?? 5)
: undefined
}
/>
) : null
) : isXaiOauth ? (
!grokBoundAccountId || usageEnabled ? (
<XaiOauthQuotaFooter
meta={provider.meta}
inline={true}
isCurrent={isCurrent}
autoQueryInterval={
grokBoundAccountId
? (provider.meta?.usage_script?.autoQueryInterval ?? 5)
: undefined
}
/>
) : null
) : appId === "workbuddy" && isWorkBuddyOfficial(provider) ? (
// 官方登录卡的额度按卡上绑定的账号查(只有 WorkBuddy 运行时当前账号能刷新)
<WorkBuddyQuotaFooter provider={provider} />
) : isCodebuddyOfficial ? (
<CodebuddyOfficialQuota accountId={codebuddyAccountId} />
) : appId === "kimi" && isOfficial ? (
// 每张 Kimi 官方卡就是授权中心里的一个账号,额度按卡上那个号查
<KimiAccountQuotaFooter
accountId={provider.id}
name={provider.name}
inline={true}
isCurrent={isCurrent}
/>
) : claudeBoundAccountId ? (
usageEnabled ? (
<ClaudeAccountQuotaFooter
accountId={claudeBoundAccountId}
inline={true}
isCurrent={isCurrent}
autoQueryInterval={
provider.meta?.usage_script?.autoQueryInterval ?? 5
}
/>
) : null
) : isOfficial ? (
officialSubscriptionEnabled ? (
agyBoundAccountId ? (
<AgyAccountQuotaFooter
accountId={agyBoundAccountId}
inline={true}
isCurrent={isCurrent}
autoQueryInterval={
provider.meta?.usage_script?.autoQueryInterval ?? 0
}
/>
) : (
<SubscriptionQuotaFooter
appId={appId}
inline={true}
isCurrent={isCurrent}
autoQueryInterval={
provider.meta?.usage_script?.autoQueryInterval ?? 0
}
/>
)
) : null
) : hasMultiplePlans ? (
<span className="text-caption text-fg-2">
{t("usage.multiplePlans", {
count: usage?.data?.length || 0,
defaultValue: `${usage?.data?.length || 0} 个套餐`,
})}
</span>
) : (
<UsageFooter
provider={provider}
providerId={provider.id}
appId={appId}
usageEnabled={usageEnabled}
inline={true}
/>
)}
{hasMultiplePlans && (
<HoverTip content={expandLabel}>
<button
onClick={(e) => {
e.stopPropagation();
setIsExpanded(!isExpanded);
}}
className="shrink-0 rounded-control p-1 text-fg-3 transition-colors hover:bg-subtle hover:text-fg-1"
aria-label={expandLabel}
aria-expanded={isExpanded}
>
{isExpanded ? (
<ChevronUp size={14} />
) : (
<ChevronDown size={14} />
)}
</button>
</HoverTip>
)}
</div>
</div>
<ProviderCardActions
providerName={provider.name}
presentation={presentation}
onEdit={() => onEdit(provider)}
onDelete={() => onDelete(provider)}
onDuplicate={
// CodeBuddy 的卡片 ID 就是 models.json 里的模型 id(发给上游的模型名),副本只能换一个
// 不存在的 id 且编辑时改不了;官方登录卡另建即可,所以 CodeBuddy 不提供复制
onDuplicate &&
!((appId === "kimi" || appId === "qoder") && isOfficial) &&
appId !== "codebuddy"
? () => onDuplicate(provider)
: undefined
}
onTest={
onTest && supportsConnectivityCheck(appId, provider)
? () => onTest(provider)
: undefined
}
isTesting={isTesting}
onConfigureUsage={
(isOfficial &&
!supportsOfficialSubscription &&
!isCopilotCliOfficial) ||
isCopilot ||
(isCodexOauth && !isBoundCodexOfficial) ||
(isXaiOauth && !grokBoundAccountId)
? undefined
: onConfigureUsage
? () => onConfigureUsage(provider)
: undefined
}
onOpenTerminal={
onOpenTerminal && terminalAvailable(provider, appId, isCurrent)
? () => onOpenTerminal(provider)
: undefined
}
openTerminalIsolated={terminalIsIsolated(provider, appId)}
openTerminalDisabledReason={
terminalNeedsRoute(provider, appId)
? t("provider.openTerminalNeedsRoute")
: // Copilot 自带模型卡要先写进 providers.json,终端才能用 --model 选到它
appId === "copilot" &&
!isOfficial &&
provider.meta?.liveConfigManaged !== true
? t("copilot.terminalNeedsAdd")
: undefined
}
/>
</div>
</div>
{isExpanded && hasMultiplePlans && (
<div className="mx-4 mb-3 border-t border-border pt-3">
<UsageFooter
provider={provider}
providerId={provider.id}
appId={appId}
usageEnabled={usageEnabled}
inline={false}
/>
</div>
)}
</div>
);
}