2025-10-16 21:40:42 +08:00
|
|
|
|
import { useTranslation } from "react-i18next";
|
2025-10-17 14:31:34 +08:00
|
|
|
|
import EndpointSpeedTest from "./EndpointSpeedTest";
|
|
|
|
|
|
import { ApiKeySection, EndpointField } from "./shared";
|
2025-10-16 21:40:42 +08:00
|
|
|
|
import type { ProviderCategory } from "@/types";
|
|
|
|
|
|
|
2025-10-16 22:41:36 +08:00
|
|
|
|
interface EndpointCandidate {
|
|
|
|
|
|
url: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 21:40:42 +08:00
|
|
|
|
interface CodexFormFieldsProps {
|
2025-11-04 15:30:54 +08:00
|
|
|
|
providerId?: string;
|
2025-10-16 21:40:42 +08:00
|
|
|
|
// API Key
|
|
|
|
|
|
codexApiKey: string;
|
|
|
|
|
|
onApiKeyChange: (key: string) => void;
|
|
|
|
|
|
category?: ProviderCategory;
|
|
|
|
|
|
shouldShowApiKeyLink: boolean;
|
|
|
|
|
|
websiteUrl: string;
|
2025-11-06 15:22:38 +08:00
|
|
|
|
isPartner?: boolean;
|
|
|
|
|
|
partnerPromotionKey?: string;
|
2025-10-16 21:40:42 +08:00
|
|
|
|
|
|
|
|
|
|
// Base URL
|
|
|
|
|
|
shouldShowSpeedTest: boolean;
|
|
|
|
|
|
codexBaseUrl: string;
|
|
|
|
|
|
onBaseUrlChange: (url: string) => void;
|
|
|
|
|
|
isEndpointModalOpen: boolean;
|
|
|
|
|
|
onEndpointModalToggle: (open: boolean) => void;
|
|
|
|
|
|
onCustomEndpointsChange: (endpoints: string[]) => void;
|
2025-10-16 22:41:36 +08:00
|
|
|
|
|
|
|
|
|
|
// Speed Test Endpoints
|
|
|
|
|
|
speedTestEndpoints: EndpointCandidate[];
|
2025-10-16 21:40:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function CodexFormFields({
|
2025-11-04 15:30:54 +08:00
|
|
|
|
providerId,
|
2025-10-16 21:40:42 +08:00
|
|
|
|
codexApiKey,
|
|
|
|
|
|
onApiKeyChange,
|
|
|
|
|
|
category,
|
|
|
|
|
|
shouldShowApiKeyLink,
|
|
|
|
|
|
websiteUrl,
|
2025-11-06 15:22:38 +08:00
|
|
|
|
isPartner,
|
|
|
|
|
|
partnerPromotionKey,
|
2025-10-16 21:40:42 +08:00
|
|
|
|
shouldShowSpeedTest,
|
|
|
|
|
|
codexBaseUrl,
|
|
|
|
|
|
onBaseUrlChange,
|
|
|
|
|
|
isEndpointModalOpen,
|
|
|
|
|
|
onEndpointModalToggle,
|
|
|
|
|
|
onCustomEndpointsChange,
|
2025-10-16 22:41:36 +08:00
|
|
|
|
speedTestEndpoints,
|
2025-10-16 21:40:42 +08:00
|
|
|
|
}: CodexFormFieldsProps) {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
|
|
|
|
|
{/* Codex API Key 输入框 */}
|
2025-10-17 14:31:34 +08:00
|
|
|
|
<ApiKeySection
|
|
|
|
|
|
id="codexApiKey"
|
|
|
|
|
|
label="API Key"
|
|
|
|
|
|
value={codexApiKey}
|
|
|
|
|
|
onChange={onApiKeyChange}
|
|
|
|
|
|
category={category}
|
|
|
|
|
|
shouldShowLink={shouldShowApiKeyLink}
|
|
|
|
|
|
websiteUrl={websiteUrl}
|
2025-11-06 15:22:38 +08:00
|
|
|
|
isPartner={isPartner}
|
|
|
|
|
|
partnerPromotionKey={partnerPromotionKey}
|
2025-10-17 14:31:34 +08:00
|
|
|
|
placeholder={{
|
|
|
|
|
|
official: t("providerForm.codexOfficialNoApiKey", {
|
|
|
|
|
|
defaultValue: "官方供应商无需 API Key",
|
|
|
|
|
|
}),
|
|
|
|
|
|
thirdParty: t("providerForm.codexApiKeyAutoFill", {
|
|
|
|
|
|
defaultValue: "输入 API Key,将自动填充到配置",
|
|
|
|
|
|
}),
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2025-10-16 21:40:42 +08:00
|
|
|
|
|
|
|
|
|
|
{/* Codex Base URL 输入框 */}
|
|
|
|
|
|
{shouldShowSpeedTest && (
|
2025-10-17 14:31:34 +08:00
|
|
|
|
<EndpointField
|
|
|
|
|
|
id="codexBaseUrl"
|
2025-10-19 11:55:46 +08:00
|
|
|
|
label={t("codexConfig.apiUrlLabel")}
|
2025-10-17 14:31:34 +08:00
|
|
|
|
value={codexBaseUrl}
|
|
|
|
|
|
onChange={onBaseUrlChange}
|
2025-10-19 11:55:46 +08:00
|
|
|
|
placeholder={t("providerForm.codexApiEndpointPlaceholder")}
|
|
|
|
|
|
hint={t("providerForm.codexApiHint")}
|
2025-10-17 14:31:34 +08:00
|
|
|
|
onManageClick={() => onEndpointModalToggle(true)}
|
|
|
|
|
|
/>
|
2025-10-16 21:40:42 +08:00
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 端点测速弹窗 - Codex */}
|
|
|
|
|
|
{shouldShowSpeedTest && isEndpointModalOpen && (
|
|
|
|
|
|
<EndpointSpeedTest
|
2025-10-30 14:59:15 +08:00
|
|
|
|
appId="codex"
|
2025-11-04 15:30:54 +08:00
|
|
|
|
providerId={providerId}
|
2025-10-16 21:40:42 +08:00
|
|
|
|
value={codexBaseUrl}
|
|
|
|
|
|
onChange={onBaseUrlChange}
|
2025-10-16 22:41:36 +08:00
|
|
|
|
initialEndpoints={speedTestEndpoints}
|
2025-10-16 21:40:42 +08:00
|
|
|
|
visible={isEndpointModalOpen}
|
|
|
|
|
|
onClose={() => onEndpointModalToggle(false)}
|
|
|
|
|
|
onCustomEndpointsChange={onCustomEndpointsChange}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|