@@ -256,10 +325,21 @@ export function ChatgptLoginDialog({
取消
{phase.at === "form" && (
-
+ <>
+ {/* 次要的那条路先摆:主按钮留在最右边 */}
+
+
+ >
)}
>
)}
diff --git a/src/upstreams/UpstreamDialog.tsx b/src/upstreams/UpstreamDialog.tsx
index 3e1e1b2f..32923934 100644
--- a/src/upstreams/UpstreamDialog.tsx
+++ b/src/upstreams/UpstreamDialog.tsx
@@ -20,6 +20,7 @@ import type {
} from "@/types";
import { api } from "./api";
import { BillingSection } from "./BillingSection";
+import { ChatgptAccountSection } from "./ChatgptAccountSection";
import { ConnectionSection } from "./ConnectionSection";
import { errorText, protocolLabel, shortUrl } from "./labels";
import { ModelsSection, inScope, type ModelCatalog } from "./ModelsSection";
@@ -38,7 +39,7 @@ import {
type UpstreamForm,
} from "./upstreamForm";
-export type Section = "connection" | "models" | "billing" | "security";
+export type Section = "connection" | "account" | "models" | "billing" | "security";
const SECTIONS: { id: Section; label: string }[] = [
{ id: "connection", label: "连接" },
@@ -47,6 +48,18 @@ const SECTIONS: { id: Section; label: string }[] = [
{ id: "security", label: "安全" },
];
+/**
+ * ChatGPT 账号上游的分节。
+ *
+ * **没有「连接」也没有「计费」**:地址、协议、凭据由登录决定,计费方式是订阅制 ——
+ * 把这些摆成可填的表单,等于邀请用户去改一个改了就坏的东西。
+ */
+const ACCOUNT_SECTIONS: { id: Section; label: string }[] = [
+ { id: "account", label: "账号" },
+ { id: "models", label: "模型" },
+ { id: "security", label: "安全" },
+];
+
export type UpstreamDialogMode =
| { kind: "create" }
| { kind: "edit"; name: string; section?: Section };
@@ -79,8 +92,8 @@ export function UpstreamDialog({
/** 对话框里新建了代理或价目表:外面要重新读概览 */
onChanged: () => void;
onGoToGuard: () => void;
- /** 改用 ChatGPT 账号登录:这张表单让位给登录对话框 */
- onChatgptLogin: () => void;
+ /** 改用 ChatGPT 账号登录:这张表单让位给登录对话框。带上名字就是给它换一次凭据 */
+ onChatgptLogin: (relogin?: { name: string; proxy: string }) => void;
}) {
const editing: ProviderView | null =
mode.kind === "edit" ? (ov.providers.find((p) => p.name === mode.name) ?? null) : null;
@@ -89,8 +102,13 @@ export function UpstreamDialog({
editing ? formFromView(editing) : blankForm(),
);
const set = (patch: Partial) => setForm((f) => ({ ...f, ...patch }));
+ // ChatGPT 账号是登录来的,编辑它的那一套分节也不一样
+ const account = editing?.protocol === "chatgpt";
+ const sections = account ? ACCOUNT_SECTIONS : SECTIONS;
const [section, setSection] = useState(
- mode.kind === "edit" ? (mode.section ?? "connection") : "connection",
+ mode.kind === "edit"
+ ? (mode.section ?? (account ? "account" : "connection"))
+ : "connection",
);
const [visited, setVisited] = useState>(() => new Set(["connection"]));
@@ -274,7 +292,7 @@ export function UpstreamDialog({
// 新建时没检测过就到了模型这一步:替用户检测一次,这一步才有内容可选。检测不产生费用
if (to === "models" && !editing && catalog == null && !testing) void runTest();
}
- const index = SECTIONS.findIndex((s) => s.id === section);
+ const index = sections.findIndex((s) => s.id === section);
const autoBilling =
editing && !editing.billing
@@ -297,7 +315,9 @@ export function UpstreamDialog({
{editing ? (
{editing.name} ·{" "}
- {protocolLabel(editing.protocol)} · {shortUrl(editing.base_url)}
+ {protocolLabel(editing.protocol)}
+ {/* 账号上游的地址是登录给的,改不了,写出来只是噪声 */}
+ {!account && ` · ${shortUrl(editing.base_url)}`}
) : (
@@ -307,13 +327,22 @@ export function UpstreamDialog({
+ {section === "account" && editing && (
+
onChatgptLogin({ name: editing.name, proxy: editing.proxy })}
+ />
+ )}
{section === "connection" && (
{missing && {missing}}
{index > 0 && (
-