({
open,
existingVendorIds,
vendors,
onClose,
onAdd,
onValidateKey,
devModeUnlocked,
}: AddProviderDialogProps)
| 937 | } |
| 938 | |
| 939 | function AddProviderDialog({ |
| 940 | open, |
| 941 | existingVendorIds, |
| 942 | vendors, |
| 943 | onClose, |
| 944 | onAdd, |
| 945 | onValidateKey, |
| 946 | devModeUnlocked, |
| 947 | }: AddProviderDialogProps) { |
| 948 | const { t, i18n } = useTranslation('settings'); |
| 949 | const [selectedType, setSelectedType] = useState<ProviderType | null>(null); |
| 950 | const [name, setName] = useState(''); |
| 951 | const [apiKey, setApiKey] = useState(''); |
| 952 | const [baseUrl, setBaseUrl] = useState(''); |
| 953 | const [modelId, setModelId] = useState(''); |
| 954 | const [apiProtocol, setApiProtocol] = useState<ProviderAccount['apiProtocol']>('openai-completions'); |
| 955 | const [showAdvancedConfig, setShowAdvancedConfig] = useState(false); |
| 956 | const [userAgent, setUserAgent] = useState(''); |
| 957 | const [arkMode, setArkMode] = useState<ArkMode>('apikey'); |
| 958 | const [showKey, setShowKey] = useState(false); |
| 959 | const [saving, setSaving] = useState(false); |
| 960 | const [validationError, setValidationError] = useState<string | null>(null); |
| 961 | |
| 962 | // OAuth Flow State |
| 963 | const [oauthFlowing, setOauthFlowing] = useState(false); |
| 964 | const [oauthData, setOauthData] = useState<{ |
| 965 | mode: 'device'; |
| 966 | verificationUri: string; |
| 967 | userCode: string; |
| 968 | expiresIn: number; |
| 969 | } | { |
| 970 | mode: 'manual'; |
| 971 | authorizationUrl: string; |
| 972 | message?: string; |
| 973 | } | null>(null); |
| 974 | const [manualCodeInput, setManualCodeInput] = useState(''); |
| 975 | const [oauthError, setOauthError] = useState<string | null>(null); |
| 976 | // For providers that support both OAuth and API key, let the user choose. |
| 977 | // Default to the vendor's declared auth mode instead of hard-coding OAuth. |
| 978 | const [authMode, setAuthMode] = useState<'oauth' | 'apikey'>('apikey'); |
| 979 | const [prevOpen, setPrevOpen] = useState(open); |
| 980 | const pendingOAuthRef = React.useRef<{ accountId: string; label: string } | null>(null); |
| 981 | |
| 982 | if (prevOpen !== open) { |
| 983 | setPrevOpen(open); |
| 984 | if (open) { |
| 985 | setSelectedType(null); |
| 986 | setName(''); |
| 987 | setApiKey(''); |
| 988 | setBaseUrl(''); |
| 989 | setModelId(''); |
| 990 | setApiProtocol('openai-completions'); |
| 991 | setShowAdvancedConfig(false); |
| 992 | setUserAgent(''); |
| 993 | setArkMode('apikey'); |
| 994 | setShowKey(false); |
| 995 | setSaving(false); |
| 996 | setValidationError(null); |
nothing calls this directly
no test coverage detected