Feat google ai studio#189
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new "Google AI Studio" AI tool entry (UI + locale) and updates AI tools settings handling with a normalization function that merges, de-duplicates, and preserves ordering of persisted tool settings. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User
participant UI as UI (index.html)
participant Manager as AI Tools Manager (scripts/ai-tools.js)
participant Storage as localStorage
User->>UI: open settings / click AI tools
UI->>Manager: request showAIToolsSettings()
Manager->>Storage: read savedSettings
Storage-->>Manager: savedSettings
Manager->>Manager: mergeAIToolsSettings(savedSettings)
Manager-->>UI: generateAIToolsForm(normalizedSettings)
UI->>User: render AI tools form (includes Google AI Studio)
User->>UI: apply changes
UI->>Manager: applyAIToolsSettings(userChanges)
Manager->>Manager: mergeAIToolsSettings(userChanges)
Manager->>Storage: write normalized settings if changed
Storage-->>Manager: confirm write
Manager-->>UI: update UI state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
|
I reopened the PR from another branch |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@scripts/ai-tools.js`:
- Around line 29-59: mergeAIToolsSettings allows duplicate entries and can throw
when Object.keys(item) is called on null/non-object; update the loop that
handles savedSettings to first validate object items with a guard like item &&
typeof item === "object" && !Array.isArray(item") before using
Object.keys(item), compute toolId accordingly, and before pushing into
normalizedSettings check !seenToolIds.has(toolId) to avoid duplicates while
still adding seenToolIds.add(toolId); ensure this logic references
mergeAIToolsSettings, seenToolIds, normalizedSettings, aiTools and the
Object.keys(item) use so malformed savedSettings entries are ignored and
duplicates are deduplicated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ab0d1451-d11e-4de2-b19e-a30b2562d286
📒 Files selected for processing (3)
index.htmllocales/en.jsscripts/ai-tools.js
| function mergeAIToolsSettings(savedSettings) { | ||
| const normalizedSettings = []; | ||
| const seenToolIds = new Set(); | ||
|
|
||
| if (Array.isArray(savedSettings)) { | ||
| savedSettings.forEach((item) => { | ||
| let toolId; | ||
| let isVisible = true; | ||
|
|
||
| if (typeof item === "string") { | ||
| toolId = item; | ||
| } else { | ||
| toolId = Object.keys(item)[0]; | ||
| isVisible = false; | ||
| } | ||
|
|
||
| if (aiTools.some(tool => tool.id === toolId)) { | ||
| seenToolIds.add(toolId); | ||
| normalizedSettings.push(isVisible ? toolId : { [toolId]: false }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| aiTools.forEach((tool) => { | ||
| if (!seenToolIds.has(tool.id)) { | ||
| normalizedSettings.push(tool.visible ? tool.id : { [tool.id]: false }); | ||
| } | ||
| }); | ||
|
|
||
| return normalizedSettings; | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Demonstrate that the current normalization keeps duplicates and throws on null.
node <<'NODE'
const aiTools = [
{ id: "chatGPT", visible: true },
{ id: "gemini", visible: true },
];
function mergeAIToolsSettings(savedSettings) {
const normalizedSettings = [];
const seenToolIds = new Set();
if (Array.isArray(savedSettings)) {
savedSettings.forEach((item) => {
let toolId;
let isVisible = true;
if (typeof item === "string") {
toolId = item;
} else {
toolId = Object.keys(item)[0];
isVisible = false;
}
if (aiTools.some(tool => tool.id === toolId)) {
seenToolIds.add(toolId);
normalizedSettings.push(isVisible ? toolId : { [toolId]: false });
}
});
}
aiTools.forEach((tool) => {
if (!seenToolIds.has(tool.id)) {
normalizedSettings.push(tool.visible ? tool.id : { [tool.id]: false });
}
});
return normalizedSettings;
}
console.log("Duplicate case:", JSON.stringify(mergeAIToolsSettings(["chatGPT", "chatGPT"])));
try {
mergeAIToolsSettings([null]);
} catch (error) {
console.log("Null case throws:", error.name);
}
NODERepository: prem-k-r/MaterialYouNewTab
Length of output: 144
🏁 Script executed:
cat -n scripts/ai-tools.js | sed -n '25,65p'Repository: prem-k-r/MaterialYouNewTab
Length of output: 1613
Deduplicate and validate saved entries before normalizing them.
seenToolIds is populated but never checked before pushing to normalizedSettings, so duplicated entries survive normalization. Additionally, the code calls Object.keys(item) without validating that item is a valid object, which throws a TypeError if item is null or any non-object type—a malformed backup/localStorage value can break AI tools initialization.
The proposed fix adds:
- Deduplication check:
!seenToolIds.has(toolId)before pushing - Type validation:
item && typeof item === "object" && !Array.isArray(item)before callingObject.keys()
🐛 Proposed fix
function mergeAIToolsSettings(savedSettings) {
const normalizedSettings = [];
const seenToolIds = new Set();
+ const validToolIds = new Set(aiTools.map(tool => tool.id));
if (Array.isArray(savedSettings)) {
savedSettings.forEach((item) => {
let toolId;
let isVisible = true;
if (typeof item === "string") {
toolId = item;
- } else {
+ } else if (item && typeof item === "object" && !Array.isArray(item)) {
toolId = Object.keys(item)[0];
isVisible = false;
+ } else {
+ return;
}
- if (aiTools.some(tool => tool.id === toolId)) {
+ if (validToolIds.has(toolId) && !seenToolIds.has(toolId)) {
seenToolIds.add(toolId);
normalizedSettings.push(isVisible ? toolId : { [toolId]: false });
}
});
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/ai-tools.js` around lines 29 - 59, mergeAIToolsSettings allows
duplicate entries and can throw when Object.keys(item) is called on
null/non-object; update the loop that handles savedSettings to first validate
object items with a guard like item && typeof item === "object" &&
!Array.isArray(item") before using Object.keys(item), compute toolId
accordingly, and before pushing into normalizedSettings check
!seenToolIds.has(toolId) to avoid duplicates while still adding
seenToolIds.add(toolId); ensure this logic references mergeAIToolsSettings,
seenToolIds, normalizedSettings, aiTools and the Object.keys(item) use so
malformed savedSettings entries are ignored and duplicates are deduplicated.
📌 Description
This PR adds Google AI Studio as a quick-access AI tool in the dashboard
🎨 Visual Changes (Screenshots / Videos)
🔗 Related Issues
New Feature #177
✅ Checklist
Overview
Adds Google AI Studio as a new quick-access AI tool in the AI Tools navigation bar, alongside existing tools like ChatGPT, Gemini, and Claude.
Changes
index.html
https://ai.google/studio/with icon and label (id="googleAIStudio"), positioned after the existing Gemini entrylocales/en.js
googleAIStudio: "Google AI Studio"in the AI Tools sectionscripts/ai-tools.js
googleAIStudioatorder: 2, shifting subsequent tools' order values accordinglymergeAIToolsSettings(savedSettings)helper function to normalize persisted localStorage settings by filtering unknown tool IDs, deduplicating entries, and appending missing tools from current defaultsapplyAIToolsSettings()to use the new normalization helper and persist updated normalized arrays to localStorage with deep-compare validationshowAIToolsSettings()to usemergeAIToolsSettings()for initialization instead of prior fallback logicRelated Issue
Implements New Feature #177
Testing
Author verified changes across Chrome and Firefox browsers
Overview
This PR adds Google AI Studio as a new quick-access AI tool to the dashboard, implementing feature #177. Changes include a new UI shortcut, English localization, and updates to the AI tools registry with refactored settings management logic.
Changes
index.html
<a href="https://ai.google/studio/">entry in the AI Tools shortcuts section with a label elementid="googleAIStudio"and icon SVG, positioned after Gemini and before Copilot.locales/en.js
"googleAIStudio": "Google AI Studio"in the AI Tools section.scripts/ai-tools.js
{ id: "googleAIStudio", visible: true, order: 2 }, shifting order values for subsequent tools (copilot,claude,deepseek) and preserving other entries.mergeAIToolsSettings(savedSettings)to normalize persistedaiToolsSettingsby:applyAIToolsSettings()to compute normalized settings viamergeAIToolsSettings()and only persist to localStorage when the normalized result differs from stored data (deep-compare using JSON.stringify).showAIToolsSettings()to initialize the settings form usingmergeAIToolsSettings()instead of the prior fallback logic.applyAIToolsSettings()is invoked on DOMContentLoaded and after saving settings;showAIToolsSettings()is used by the AI Tools edit button.Testing
Author verified changes across Chrome and Firefox.
Checklist
Contributing guidelines, coding style, testing, browser compatibility, visuals, and CHANGELOG update items marked complete by author.