-
-
Notifications
You must be signed in to change notification settings - Fork 95
setup basic key validation #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@mihirpenugonda is attempting to deploy a commit to the Harsh's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce asynchronous API key validation for multiple providers within the APIKeyForm UI. A new service module handles provider-specific validation logic. The store and form components are updated to support real-time validation feedback, blocking submission if any key is invalid and displaying appropriate UI indicators and error messages. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant APIKeyForm
participant APIKeyStore
participant apiValidationService
User->>APIKeyForm: Submit form
APIKeyForm->>APIKeyStore: validateAllKeysAPI()
APIKeyStore->>apiValidationService: validateAPIKey(provider, key) (for each provider)
apiValidationService-->>APIKeyStore: APIValidationResult(s)
APIKeyStore-->>APIKeyForm: Validation results
alt Any key invalid
APIKeyForm-->>User: Show error toast, block save
else All keys valid
APIKeyForm->>APIKeyStore: Save keys
APIKeyForm-->>User: Show success toast
end
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
frontend/components/APIKeyForm.tsxOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.2_eslint@9.28.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. frontend/stores/APIKeyStore.tsOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.2_eslint@9.28.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. lib/apiValidationService.tsOops! Something went wrong! :( ESLint: 9.28.0 ESLint couldn't find the plugin "eslint-plugin-react-hooks". (The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following: The plugin "eslint-plugin-react-hooks" was referenced from the config file in " » eslint-config-next/core-web-vitals » /node_modules/.pnpm/eslint-config-next@15.3.2_eslint@9.28.0_jiti@2.4.2__typescript@5.8.3/node_modules/eslint-config-next/index.js". If you still can't figure out the problem, please see https://eslint.org/docs/latest/use/troubleshooting. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
♻️ Duplicate comments (1)
lib/apiValidationService.ts (1)
46-65: 🛠️ Refactor suggestionApply same timeout and error handling improvements as OpenAI validator.
This function has the same issues as
validateOpenAI- needs timeout handling and better error messages.
🧹 Nitpick comments (1)
frontend/components/APIKeyForm.tsx (1)
73-83: Good UX: Clearing stale validation results on input change.The effect correctly clears validation results when inputs change. Consider using a more functional approach:
- useEffect(() => { - Object.keys(watchedValues).forEach(provider => { - if (apiValidationResults[provider]) { - setApiValidationResults(prev => { - const newResults = { ...prev }; - delete newResults[provider]; - return newResults; - }); - } - }); - }, [watchedValues, apiValidationResults]); + useEffect(() => { + const providersWithResults = Object.keys(watchedValues).filter( + provider => apiValidationResults[provider] + ); + + if (providersWithResults.length > 0) { + setApiValidationResults(prev => + Object.fromEntries( + Object.entries(prev).filter(([key]) => !providersWithResults.includes(key)) + ) + ); + } + }, [watchedValues]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
frontend/components/APIKeyForm.tsx(10 hunks)frontend/stores/APIKeyStore.ts(3 hunks)lib/apiValidationService.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
frontend/stores/APIKeyStore.ts (1)
lib/apiValidationService.ts (1)
APIValidationResult(3-6)
lib/apiValidationService.ts (1)
frontend/stores/APIKeyStore.ts (1)
Provider(6-6)
frontend/components/APIKeyForm.tsx (3)
lib/apiValidationService.ts (1)
APIValidationResult(3-6)frontend/stores/APIKeyStore.ts (1)
Provider(6-6)frontend/components/ui/input.tsx (1)
Input(21-21)
🔇 Additional comments (7)
frontend/stores/APIKeyStore.ts (3)
3-3: Good aliasing of the imported validation function.The alias
validateAPIKeyServiceclearly distinguishes the imported function from the store methods, preventing naming conflicts.
62-68: Well-implemented single key validation with proper edge case handling.The method correctly validates empty keys before delegating to the service, providing clear error messages.
70-85:⚠️ Potential issueFix race condition in concurrent validation results collection.
The current implementation assigns results within the map callback before
Promise.allcompletes, which could lead to partial results if interrupted. Results should be collected after all promises resolve.Apply this diff to fix the race condition:
- validateAllKeysAPI: async () => { - const keys = get().keys; - const results: Record<Provider, APIValidationResult> = {} as Record<Provider, APIValidationResult>; - - const validationPromises = PROVIDERS.map(async (provider) => { - const key = keys[provider]; - if (key && key.trim().length > 0) { - results[provider] = await validateAPIKeyService(provider, key); - } else { - results[provider] = { isValid: false, error: `${provider} API key is required` }; - } - }); - - await Promise.all(validationPromises); - return results; - }, + validateAllKeysAPI: async () => { + const keys = get().keys; + + const validationPromises = PROVIDERS.map(async (provider) => { + const key = keys[provider]; + if (key && key.trim().length > 0) { + return { provider, result: await validateAPIKeyService(provider, key) }; + } else { + return { provider, result: { isValid: false, error: `${provider} API key is required` } }; + } + }); + + const validationResults = await Promise.all(validationPromises); + + const results: Record<Provider, APIValidationResult> = {} as Record<Provider, APIValidationResult>; + validationResults.forEach(({ provider, result }) => { + results[provider] = result; + }); + + return results; + },Likely an incorrect or invalid review comment.
lib/apiValidationService.ts (1)
67-85: Well-structured validation dispatcher with proper edge case handling.The function correctly validates empty keys and uses an exhaustive switch statement with a default case for unknown providers.
frontend/components/APIKeyForm.tsx (3)
1-1: Appropriate imports for validation functionality.The added imports correctly bring in state management hooks and validation-related components.
Also applies to: 19-20
53-54: Efficient state management for validation tracking.Good use of
Setfor O(1) lookups when checking validation status. The state structure clearly separates results from loading states.
202-247: Excellent UI feedback implementation for validation states.The dynamic styling with border colors (red/green) and validation icons (spinner/check/cross) provides clear visual feedback. The absolute positioning of icons ensures they don't affect input layout.
Summary
A complete API key validation system that tests keys against real provider APIs before saving them.
Summary by CodeRabbit
New Features
Bug Fixes