-
- {broken ? "登录已失效" : "已登录"}
- {plan && !broken && ` · ${plan}`}
+
+ {broken ? "登录已失效" : (email ?? "已登录")}
+ {planLabel(plan) && !broken && ` · ${planLabel(plan)}`}
{broken
diff --git a/src/upstreams/UpstreamTable.tsx b/src/upstreams/UpstreamTable.tsx
index ef215604..cad473a1 100644
--- a/src/upstreams/UpstreamTable.tsx
+++ b/src/upstreams/UpstreamTable.tsx
@@ -1,4 +1,6 @@
+import { useEffect, useState } from "react";
import { Badge } from "@/ui/badge";
+import { Popover, PopoverContent, PopoverTrigger } from "@/ui/popover";
import { Progress } from "@/ui/progress";
import { RowMenu, RowMenuButton, type MenuItems } from "@/ui/row-menu";
import {
@@ -10,9 +12,17 @@ import {
TableRow,
} from "@/ui/table";
import { resetIn } from "@/format";
-import { usd, type Overview, type ProviderView } from "@/types";
-import type { UpstreamStats } from "./api";
-import { billingLabel, egressLabel, protocolLabel, quotaWindowLabel, shortUrl } from "./labels";
+import { usd, type ChatgptUsage, type Overview, type ProviderModelsView, type ProviderView } from "@/types";
+import { api, type UpstreamStats } from "./api";
+import {
+ billingLabel,
+ egressLabel,
+ modelSourceNote,
+ planLabel,
+ protocolLabel,
+ quotaWindowLabel,
+ shortUrl,
+} from "./labels";
export interface UpstreamActions {
edit: (name: string) => void;
@@ -35,10 +45,13 @@ export interface UpstreamActions {
export function UpstreamTable({
ov,
stats,
+ accounts,
actions,
}: {
ov: Overview;
stats: UpstreamStats | null;
+ /** 账号类上游问来的账号信息,按上游名。还没问到的就没有 */
+ accounts: Record;
actions: UpstreamActions;
}) {
return (
@@ -74,6 +87,10 @@ export function UpstreamTable({
{p.name}
{p.trust === "official" && 官方端点}
+ {/* 订阅类账号:套餐决定了额度有多大,和名字放在一起看 */}
+ {planLabel(accounts[p.name]?.plan) && (
+ {planLabel(accounts[p.name]?.plan)}
+ )}
{p.disabled ? (
已停用
) : p.health === "open" ? (
@@ -84,16 +101,7 @@ export function UpstreamTable({
协议、地址、出站方式是同一件事的三个部分:这一家在哪、怎么连。
地址可能很长(带路径的中转):截断,悬停看全
*/}
-
- {protocolLabel(p.protocol)} · {shortUrl(p.base_url)}
- {/* 直连是默认,不用说 */}
- {p.proxy !== "direct" && ` · 经 ${egressLabel(p.proxy)}`}
-
+
@@ -129,19 +137,107 @@ function menu(p: ProviderView, a: UpstreamActions): MenuItems {
];
}
+/**
+ * 这一家在哪、怎么连。
+ *
+ * 账号类上游的地址永远是同一个,**写出来一行废话** —— 那一格
+ * 留给邮箱:登了两个账号时,它是唯一能分辨哪行是哪个的东西。
+ */
+function Where({ p, account }: { p: ProviderView; account?: ChatgptUsage }) {
+ // 账号类上游的地址永远是同一个,名字后面的「官方端点」已经说了它在哪
+ const isAccount = p.protocol === "chatgpt";
+ const where = isAccount ? (account?.email ?? null) : shortUrl(p.base_url);
+ const egress = p.proxy === "direct" ? "" : ` · 经 ${egressLabel(p.proxy)}`;
+ const full = [protocolLabel(p.protocol), isAccount ? account?.email : p.base_url]
+ .filter(Boolean)
+ .join(" · ");
+ return (
+
+ {protocolLabel(p.protocol)}
+ {where && ` · ${where}`}
+ {/* 直连是默认,不用说 */}
+ {egress}
+
+ );
+}
+
+/**
+ * 有多少个模型,以及都有哪些。
+ *
+ * 数目单独回答不了「我要的那个模型在不在里面」,而一个二十几项的清单
+ * 又放不进一格。**点数字就展开**,不用为了看一眼进编辑对话框。
+ */
function ModelsCell({ p }: { p: ProviderView }) {
- const sub =
- p.model_source === "manual"
- ? "手动清单"
- : p.model_source === "none"
- ? "未获取"
- : p.models_only
- ? "指定范围"
- : null;
+ const [open, setOpen] = useState(false);
+ const [list, setList] = useState(null);
+ const [failed, setFailed] = useState(false);
+ const none = p.disabled || p.model_source === "none";
+ const sub = modelSourceNote(p);
+
+ // 展开才去读:一页上十几家上游,没人看的清单不该占着一次调用
+ useEffect(() => {
+ if (!open || list || failed) return;
+ let alive = true;
+ api
+ .providerModels(p.name)
+ .then((v) => alive && setList(v))
+ .catch(() => alive && setFailed(true));
+ return () => {
+ alive = false;
+ };
+ }, [open, list, failed, p.name]);
+
+ if (none) {
+ return (
+
+ {/* 停用时 core 报 0 —— 那不是「没有模型」,状态一栏已经说了停用 */}
+ —{sub && {sub}
}
+
+ );
+ }
+
+ const models = list?.models ?? [];
+ const shown = models.filter((m) => m.enabled);
+ const hidden = models.length - shown.length;
return (
- {/* 停用时 core 报 0 —— 那不是「没有模型」,状态一栏已经说了停用 */}
- {p.disabled || p.model_source === "none" ? "—" : p.model_count}
+
+ {/*
+ 悬停时变成一个块,不画下划线 —— 鼠标正好压在字的下方,
+ 一条紧贴基线的线它自己就把它挡了
+ */}
+
+ {p.model_count}
+
+
+
+ 模型清单
+ {sub && {sub}}
+
+ {failed ? (
+ 暂时读不到模型清单。
+ ) : !list ? (
+ 正在读取
+ ) : (
+ <>
+
+ {shown.map((m) => (
+ -
+ {m.id}
+
+ ))}
+
+ {/* 范围外的不列,但要说有——否则这份清单看起来就是它全部的模型 */}
+ {hidden > 0 && (
+
+ 另有 {hidden} 个不在启用范围内
+
+ )}
+ {list.error && {list.error}
}
+ >
+ )}
+
+
{sub && {sub}
}
);
@@ -166,7 +262,8 @@ function QuotaCell({ p, stats }: { p: ProviderView; stats: UpstreamStats | null
return (
- {Math.round(tight.used_percent)}%
+ {/* **要说清楚这个数是用掉的还是剩下的**:一根填了一半的条,两种读法都成立 */}
+ 已用 {Math.round(tight.used_percent)}%
{reset ? `${quotaWindowLabel(tight.window)} · ${reset}` : quotaWindowLabel(tight.window)}
diff --git a/src/upstreams/UpstreamsPage.tsx b/src/upstreams/UpstreamsPage.tsx
index 466152f8..9e0c1e79 100644
--- a/src/upstreams/UpstreamsPage.tsx
+++ b/src/upstreams/UpstreamsPage.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import { ActivityIcon, CircleAlertIcon, PlusIcon, RefreshCwIcon, ServerIcon, ZapIcon } from "lucide-react";
import { toast } from "sonner";
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/ui/alert";
@@ -14,7 +14,7 @@ import {
import { Spinner } from "@/ui/spinner";
import { Switch } from "@/ui/switch";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/ui/tabs";
-import type { Overview, PricingStatus } from "@/types";
+import type { ChatgptUsage, Overview, PricingStatus } from "@/types";
import { api, type UpstreamStats } from "./api";
import { ChatgptLoginDialog } from "./ChatgptLoginDialog";
import { DeleteDialog, type Referrer } from "./DeleteDialog";
@@ -100,6 +100,40 @@ export default function UpstreamsPage({
const t = setInterval(loadStats, 30_000);
return () => clearInterval(t);
}, [loadStats]);
+
+ /**
+ * 账号类上游:**打开这一页时问一次它自己。**
+ *
+ * 一次问答同时回答三件事:登的是哪个账号、什么套餐、额度还剩多少。
+ * 这三件都不在配置里 —— 额度平时是跟着真实流量白捡的,所以刚启动、
+ * 或者这个账号今天还没被用过时,不问就什么都没有。
+ *
+ * **每个上游只问一次。**问一次是一次真实调用;失败了也不再问 —— 连不上时
+ * 三十秒重试一轮,只会把错误刷满日志。
+ */
+ const [accounts, setAccounts] = useState>({});
+ const askedUsage = useRef(new Set());
+ useEffect(() => {
+ const fresh = ov.providers.filter(
+ (p) => p.protocol === "chatgpt" && !p.disabled && !askedUsage.current.has(p.name),
+ );
+ if (fresh.length === 0) return;
+ fresh.forEach((p) => askedUsage.current.add(p.name));
+ void Promise.all(
+ fresh.map((p) =>
+ api
+ .chatgptUsage(p.name)
+ .then((u) => [p.name, u] as const)
+ .catch(() => null),
+ ),
+ ).then((rs) => {
+ const got = rs.filter((r) => r !== null);
+ if (got.length === 0) return;
+ setAccounts((a) => ({ ...a, ...Object.fromEntries(got) }));
+ // 额度 core 那边也记下了,从它再读一遍,免得这里和它各存一份
+ loadStats();
+ });
+ }, [ov.providers, loadStats]);
useEffect(() => {
loadStatus();
}, [loadStatus, configVersion]);
@@ -277,6 +311,7 @@ export default function UpstreamsPage({
setDialog({ kind: "upstream", mode: { kind: "edit", name } }),
test: (name) => setDialog({ kind: "test", name }),
diff --git a/src/upstreams/labels.ts b/src/upstreams/labels.ts
index a65eb39c..5708e71a 100644
--- a/src/upstreams/labels.ts
+++ b/src/upstreams/labels.ts
@@ -89,6 +89,31 @@ export function modelSourceLabel(source: string): string {
}
/** 订阅额度窗口:`5h` / `7d` / `weekly` */
+/** 模型清单是怎么来的。自动获取、范围也没限制时不用说 */
+export function modelSourceNote(p: ProviderView): string | null {
+ if (p.model_source === "manual") return "手动清单";
+ if (p.model_source === "none") return "未获取";
+ return p.models_only ? "指定范围" : null;
+}
+
+/**
+ * 订阅类型。**认不出来的原样显示** —— OpenAI 随时会多出一个
+ * 新名字,把它显示成「未知」比直接写出那个词更差。
+ */
+export function planLabel(plan: string | null | undefined): string | null {
+ if (!plan) return null;
+ const known: Record = {
+ free: "Free",
+ plus: "Plus",
+ pro: "Pro",
+ team: "Team",
+ business: "Business",
+ enterprise: "Enterprise",
+ edu: "Edu",
+ };
+ return known[plan.toLowerCase()] ?? plan;
+}
+
export function quotaWindowLabel(window: string): string {
switch (window) {
case "5h":