mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 02:05:57 +08:00
15d5dbe065
Add SuperGrok subscription usage display, following the existing Claude Code / Codex official-subscription pattern (protocol ported from steipete/CodexBar): - New subscription_grok service: reads Grok CLI credentials from ~/.grok/auth.json, calls the grok.com GrokBuildBilling gRPC-web endpoint, and parses the response via heuristic protobuf scanning (used percent, reset time, zero-usage special case) - Transient failures (network errors, HTTP 408, gRPC deadline/ cancelled) propagate as Err so the frontend retries and keeps the last good value; auth failures map to Expired with a re-login hint - Tier naming by reset distance: weekly limit, monthly, or a new "credits" tier (i18n added for zh/en/ja/zh-TW; tray shows "c") - New get_xai_oauth_quota command: xai_oauth providers (managed SuperGrok OAuth accounts) query the same billing endpoint with their bound account token; ProviderCard auto-renders the quota footer for them and hides the usage-script entry, and the tray / usage-script path routes xai_oauth providers to the managed account instead of the host app's CLI credentials - UsageScriptModal: drop the config-content heuristic for official detection; category === "official" is the single source of truth Claude-Session: https://claude.ai/code/session_01LSNvhEfuoJHaQLZcYQgBU5
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import React from "react";
|
||
import type { ProviderMeta } from "@/types";
|
||
import { useXaiOauthQuota } from "@/lib/query/subscription";
|
||
import { SubscriptionQuotaView } from "@/components/SubscriptionQuotaFooter";
|
||
|
||
interface XaiOauthQuotaFooterProps {
|
||
meta?: ProviderMeta;
|
||
inline?: boolean;
|
||
/** 是否为当前激活的供应商 */
|
||
isCurrent?: boolean;
|
||
}
|
||
|
||
/**
|
||
* xAI OAuth (SuperGrok 反代) 订阅额度 footer
|
||
*
|
||
* 复用 SubscriptionQuotaView 的全部渲染逻辑(5 状态 × inline/expanded)。
|
||
* 数据源为 cc-switch 自管的 xAI OAuth token,与 Grok Build 分区读 Grok CLI
|
||
* 凭据的路径查同一个 grok.com 账单端点,展示同一份订阅额度。
|
||
*/
|
||
const XaiOauthQuotaFooter: React.FC<XaiOauthQuotaFooterProps> = ({
|
||
meta,
|
||
inline = false,
|
||
isCurrent = false,
|
||
}) => {
|
||
const {
|
||
data: quota,
|
||
isFetching: loading,
|
||
refetch,
|
||
} = useXaiOauthQuota(meta, { enabled: true, autoQuery: isCurrent });
|
||
|
||
return (
|
||
<SubscriptionQuotaView
|
||
quota={quota}
|
||
loading={loading}
|
||
refetch={refetch}
|
||
appIdForExpiredHint="xai_oauth"
|
||
inline={inline}
|
||
/>
|
||
);
|
||
};
|
||
|
||
export default XaiOauthQuotaFooter;
|