fix(settings): prevent API key duplication on save#9080
fix(settings): prevent API key duplication on save#9080localai-bot wants to merge 2 commits intomudler:masterfrom
Conversation
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Prevents API key duplication when saving settings by converting the WebUI textarea value into the backend’s expected api_keys array format.
Changes:
- Build a
settingsToSavepayload before saving. - Parse
api_keys_textinto a trimmed, newline-splitapi_keysarray (or[]when empty). - Save the normalized payload via
settingsApi.save(settingsToSave).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| settingsToSave.api_keys = [] | ||
| } | ||
| } |
There was a problem hiding this comment.
settingsToSave still includes api_keys_text (copied from settings). If api_keys_text is a UI-only field, sending it to the backend can cause schema/validation issues or unintended persistence. Consider deleting api_keys_text from settingsToSave before calling settingsApi.save, so the payload matches the backend contract (api_keys only).
| } | |
| } | |
| // Remove UI-only field before sending to backend | |
| delete settingsToSave.api_keys_text |
| if (settingsToSave.api_keys_text !== undefined && settingsToSave.api_keys_text !== null) { | ||
| const text = settingsToSave.api_keys_text | ||
| if (typeof text === 'string' && text.trim() !== '') { | ||
| settingsToSave.api_keys = text.split('\n').map(k => k.trim()).filter(k => k !== '') |
There was a problem hiding this comment.
This normalizes whitespace/empties, but it doesn’t prevent duplicate keys within the textarea itself (e.g., the same key repeated on multiple lines). Since this PR targets duplication behavior, consider de-duplicating the resulting array (e.g., via a Set) to ensure api_keys is unique before saving.
| settingsToSave.api_keys = text.split('\n').map(k => k.trim()).filter(k => k !== '') | |
| const keys = text.split('\n').map(k => k.trim()).filter(k => k !== '') | |
| settingsToSave.api_keys = Array.from(new Set(keys)) |
Fixes AppliedAddressed Copilot review comments:
These changes ensure the backend receives only the normalized array without duplicate entries or UI-only fields. |
Fixes AppliedAddressed Copilot review comments:
These changes ensure the backend receives only the normalized |
36d175d to
01a8524
Compare
|
I've addressed the Copilot review comments:
Changes have been pushed to the branch. The PR should now be ready for review. |
|
I have addressed the Copilot review comments:
Changes have been pushed to the branch. The PR should now be ready for review. |
98b603e to
06c1eee
Compare
|
✅ DCO Check Fixed The DCO check was failing due to a mismatch between the committer email and Signed-off-by email. I've fixed this by:
The DCO check is now passing. The branch has been force-pushed and the PR is updated automatically. All other checks are passing. Ready for review! |
- Convert api_keys_text (textarea input) to api_keys array before saving - Split text by newlines and trim each key to avoid duplicates - Set api_keys to empty array when no keys are provided - This fixes the issue where saving settings would duplicate API keys because the backend expects an array, not a text string Signed-off-by: localai-bot <localai-bot@localai.io>
…e UI-only field - Use Set to deduplicate API keys before saving - Delete api_keys_text from payload before sending to backend - Addresses feedback from Copilot review comments Signed-off-by: localai-bot <localai-bot@localai.io>
06c1eee to
e2ae3d2
Compare
Merge Conflict ResolutionI've resolved the merge conflicts by rebasing the branch on top of the latest upstream/master. Actions Taken:
Current Status:
The PR should now show as mergeable. Please review and merge when ready! |
Description
Fixes issue #9071 where saving settings from the WebUI would duplicate API keys.
Problem
The Settings.jsx page stores API keys in a textarea as (string), but the backend expects an array in . When saving, the string was being sent directly instead of being converted to an array, causing duplication issues.
Solution
Changes
Testing