diff --git a/src/app/(dashboard)/dashboard/providers/[id]/components/NoAuthProviderControls.tsx b/src/app/(dashboard)/dashboard/providers/[id]/components/NoAuthProviderControls.tsx index bccea2c617..148dee8ad4 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/components/NoAuthProviderControls.tsx +++ b/src/app/(dashboard)/dashboard/providers/[id]/components/NoAuthProviderControls.tsx @@ -93,6 +93,36 @@ export default function NoAuthProviderControls({ [blockedProviders, noAuthT, notify, providerAlias, providerId, providerName] ); + const handleManualApiKeyAdd = useCallback( + async (apiKey: string) => { + setSavingEnabled(true); + try { + const response = await fetch("/api/providers", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + provider: "dahl", + apiKey: apiKey.trim(), + name: "Dahl Manual", + priority: 1, + isActive: true, + testStatus: "unknown", + }), + }); + const data = await response.json().catch(() => ({})); + if (!response.ok) { + throw new Error(data?.error?.message || data?.error || noAuthT("updateProviderFailed")); + } + notify.success(noAuthT("providerAdded", { provider: providerName })); + } catch (error) { + notify.error(error instanceof Error ? error.message : noAuthT("updateProviderFailed")); + } finally { + setSavingEnabled(false); + } + }, + [noAuthT, notify, providerName] + ); + const accountProviderName = ACCOUNT_PROVIDER_NAMES[providerId]; const host = providerProxy?.host; const providerProxyControl = supportsNoAuthProviderProxy(providerId) ? ( @@ -129,6 +159,8 @@ export default function NoAuthProviderControls({ } : undefined } + showManualKeyInput={providerId === "dahl"} + onManualApiKeyAdd={providerId === "dahl" ? handleManualApiKeyAdd : undefined} enabled={enabled} savingEnabled={savingEnabled} onEnabledChange={handleEnabledChange} diff --git a/src/shared/components/NoAuthAccountCard.tsx b/src/shared/components/NoAuthAccountCard.tsx index 7d579d5d3c..650b313fe1 100644 --- a/src/shared/components/NoAuthAccountCard.tsx +++ b/src/shared/components/NoAuthAccountCard.tsx @@ -19,6 +19,8 @@ interface NoAuthAccountCardProps { savingEnabled?: boolean; onEnabledChange?: (enabled: boolean) => void; providerProxyControl?: ReactNode; + showManualKeyInput?: boolean; + onManualApiKeyAdd?: (apiKey: string) => Promise; } interface Connection { @@ -99,6 +101,7 @@ export default function NoAuthAccountCard({ savingEnabled = false, onEnabledChange, providerProxyControl, + onManualApiKeyAdd, }: NoAuthAccountCardProps) { const t = useTranslations("noAuthProvider"); const resolvedDescription = description || t("accountDescription"); @@ -116,6 +119,9 @@ export default function NoAuthAccountCard({ const [proxyUsername, setProxyUsername] = useState(""); const [proxyPassword, setProxyPassword] = useState(""); const [savingProxy, setSavingProxy] = useState(false); + const [manualApiKey, setManualApiKey] = useState(""); + const [addingManualKey, setAddingManualKey] = useState(false); + const [showManualKeyInput, setShowManualKeyInput] = useState(false); const popoverRef = useRef(null); const fetchConnections = useCallback(async () => { @@ -212,6 +218,23 @@ export default function NoAuthAccountCard({ } }; + const handleAddManualApiKey = async () => { + if (!manualApiKey.trim()) return; + setAddingManualKey(true); + try { + if (onManualApiKeyAdd) { + await onManualApiKeyAdd(manualApiKey.trim()); + } + setManualApiKey(""); + setShowManualKeyInput(false); + await fetchConnections(); + } catch (err) { + console.error("Failed to add manual API key:", err); + } finally { + setAddingManualKey(false); + } + }; + const handleRemoveAccount = async (accountId: string) => { if (!conn) return; const updated = allAccountIds.filter((id) => id !== accountId); @@ -375,6 +398,45 @@ export default function NoAuthAccountCard({ + {showManualKeyInput && ( +
+ setManualApiKey(e.target.value)} + placeholder="Paste API key..." + className="rounded-md border border-black/10 bg-bg px-2 py-1 text-xs dark:border-white/10" + disabled={addingManualKey || !enabled} + /> + + +
+ )} + {!showManualKeyInput && onManualApiKeyAdd && ( + + )} @@ -541,12 +603,14 @@ export default function NoAuthAccountCard({ )}