diff --git a/App.tsx b/App.tsx index beb5e76..a1ef771 100644 --- a/App.tsx +++ b/App.tsx @@ -55,6 +55,7 @@ const App: React.FC = () => { } if (key) { localStorage.setItem('api-key', key); + localStorage.setItem('last-api-key', key); } localStorage.setItem('ai-provider', newProvider); localStorage.setItem('model-' + newProvider, newModel); diff --git a/components/ApiKeySetup.tsx b/components/ApiKeySetup.tsx index 295ca75..be5f325 100644 --- a/components/ApiKeySetup.tsx +++ b/components/ApiKeySetup.tsx @@ -1,5 +1,5 @@ import React, { useState, useCallback, useEffect } from 'react'; -import { KeyIcon, SaveIcon, TestTubeIcon } from './Icons'; +import { KeyIcon, SaveIcon, TestTubeIcon, TrashIcon } from './Icons'; import { PROVIDERS, type AIProvider } from '../types/providers'; import { testApiKey, type ModelInfo } from '../services/apiTestService'; @@ -31,6 +31,12 @@ export const ApiKeySetup: React.FC = ({ onKeySave }) => { const providerConfig = PROVIDERS.find(p => p.id === savedProvider); setModel(savedModel || providerConfig?.defaultModel || ''); } + + const lastKey = localStorage.getItem('last-api-key'); + if (lastKey) { + setLocalApiKey(lastKey); + setIsValid(isValidApiKey(lastKey)); + } }, []); useEffect(() => { @@ -274,7 +280,23 @@ export const ApiKeySetup: React.FC = ({ onKeySave }) => { onKeyDown={(e) => e.key === 'Enter' && handleTestApi()} autoComplete="off" /> -
+
+ {localApiKey && ( + + )}