Add AI feature toggles and summary UI#301
Add AI feature toggles and summary UI#301arifulhoque7 wants to merge 7 commits intoweDevsOfficial:developfrom
Conversation
Sanitize AI feature toggles server-side and add client UI for AI Doc Summary. SettingsApi: validate and normalize ai_settings.features (allowed features list), coerce enabled flags and whitelist ai_summaries.display_mode to allowed values. AiSettings.js: import Switch and Overlay, add handlers (handleFeatureToggle, handleSummaryModeChange), isPro/hasApiKey checks, and state for a pro-only overlay. Add a new settings block with a switch to enable AI Doc Summary (API-key and pro gated), radio-like controls for default display mode (summary/highlights), and update settings state when changes are made.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughAdds server-side sanitization for AI feature toggles and a frontend overhaul introducing PRO-gated AI Doc Summary controls, provider/model selection, API key handling, and summary display-mode options (summary or highlights). Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 57 minutes and 58 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/components/Settings/AiSettings.js (1)
604-608: Make PRO overlay trigger keyboard-accessible too.The overlay is currently hover-only (
onMouseEnter/onMouseLeave), so keyboard users won’t get the same upgrade prompt.Suggested refinement
<div className="col-span-4 relative" onMouseEnter={ () => ! isPro && setShowSummaryOverlay( true ) } onMouseLeave={ () => setShowSummaryOverlay( false ) } + onFocusCapture={ () => ! isPro && setShowSummaryOverlay( true ) } + onBlurCapture={ (e) => { + if ( ! e.currentTarget.contains( e.relatedTarget ) ) { + setShowSummaryOverlay( false ); + } + } } >Also applies to: 726-726
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Settings/AiSettings.js` around lines 604 - 608, The PRO overlay is triggered only by mouse events (onMouseEnter/onMouseLeave) so keyboard users miss it; make the same element keyboard-accessible by also handling focus and blur (add onFocus and onBlur to call setShowSummaryOverlay(true/false)) and handle activation via keyboard (add onKeyDown handler on the same element to toggle or open the upgrade prompt when Enter/Space is pressed, respecting isPro and using setShowSummaryOverlay/open-upgrade logic). Update the element that currently uses onMouseEnter/onMouseLeave and the other similar occurrence (the one referencing setShowSummaryOverlay and isPro) to include these keyboard handlers and appropriate aria attributes (e.g., tabIndex and aria-haspopup/aria-expanded) so screen reader and keyboard users receive the same prompt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@includes/API/SettingsApi.php`:
- Around line 259-279: When persisting $ai_settings['features'] ensure
server-side PRO enforcement for the 'ai_summaries' feature: inside the foreach
over $allowed_features (where $feature === 'ai_summaries') check the plugin's
PRO status (call the existing PRO-check helper — e.g. is_pro_active() or
$this->is_pro_active()) and if the site is not PRO force
$sanitized['features']['ai_summaries']['enabled'] = false and set a safe default
for $sanitized['features']['ai_summaries']['display_mode'] (e.g. 'summary')
instead of trusting the incoming $ai_settings values; keep using
sanitize_text_field for display_mode but only accept it when PRO is active.
In `@src/components/Settings/AiSettings.js`:
- Around line 694-712: The label and the input both call handleSummaryModeChange
(label onClick and input onChange), causing duplicate updates; remove the
onClick from the label and rely on the radio input's onChange (input name
"ai_summaries_display_mode", value opt.value, checked isSelected) to perform the
change, keeping the disabled logic (disabled={!isPro}) on the input and
preserving the visual/conditional classes on the label so clicks on the label
still activate the input without invoking handleSummaryModeChange twice.
---
Nitpick comments:
In `@src/components/Settings/AiSettings.js`:
- Around line 604-608: The PRO overlay is triggered only by mouse events
(onMouseEnter/onMouseLeave) so keyboard users miss it; make the same element
keyboard-accessible by also handling focus and blur (add onFocus and onBlur to
call setShowSummaryOverlay(true/false)) and handle activation via keyboard (add
onKeyDown handler on the same element to toggle or open the upgrade prompt when
Enter/Space is pressed, respecting isPro and using
setShowSummaryOverlay/open-upgrade logic). Update the element that currently
uses onMouseEnter/onMouseLeave and the other similar occurrence (the one
referencing setShowSummaryOverlay and isPro) to include these keyboard handlers
and appropriate aria attributes (e.g., tabIndex and aria-haspopup/aria-expanded)
so screen reader and keyboard users receive the same prompt.
Server-side: enforce that ai_summaries is a PRO-only feature — if pro is inactive the feature is disabled and display_mode forced to 'summary'; when pro is active the display_mode is sanitized. Frontend: large refactor of the AiSettings component — centralize provider config retrieval, apply wp filter for provider configs, normalize state initialization and handlers (setAiSettings + setSettings), update/move AiProviderSelect and AiModelSelect to improved Listbox components, add API key presence checks, improved maskApiKey logic, disable summary controls when no API key or not PRO, and add overlay UX for PRO preview. Misc: various formatting and small UI/UX tweaks.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/Settings/AiSettings.js`:
- Around line 780-806: The radio inputs and label styling are only gated by
isPro but need to also be disabled when the API key is missing; update the label
class and the input's disabled prop to include the API-key presence check (e.g.,
disabled={!isPro || !hasApiKey}) and adjust the label conditional that adds
'opacity-50 pointer-events-none' to use the same combined condition so the
visual and interactive gating matches the summary toggle (affecting the label
wrapper, the <input> radio, and the handleSummaryModeChange usage).
- Around line 34-37: The code assumes provider.models exists when iterating
configs and choosing a default model; update the logic that uses
Object.keys(provider.models) (inside the configs forEach using
providerKey/provider) and the later access that sets firstModel to first element
to first defensively validate provider?.models is an object, e.g. treat
provider.models as (typeof provider?.models === 'object' ? provider.models :
{}), then call Object.keys(...) on that safe object and set firstModel to the
first key or '' when none exist; apply the same defensive fallback at both
places where provider.models is accessed.
- Around line 684-712: The Switch for ai_summaries has no programmatic label;
update the Switch component (the element using
checked={!!aiSettings.features?.ai_summaries?.enabled} and onChange={val =>
handleFeatureToggle('ai_summaries', val)}) to include an accessible name by
adding an aria-label (e.g., aria-label="AI document summary toggle" or similar
descriptive text) so screen readers can identify the control; ensure the
aria-label accurately reflects the feature being toggled.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
includes/API/SettingsApi.phpsrc/components/Settings/AiSettings.js
🚧 Files skipped from review as they are similar to previous changes (1)
- includes/API/SettingsApi.php
Make AiSettings robust to missing or non-object provider.models by introducing a safeModels fallback and defaulting firstModel to an empty string. Use safeModels when building model option lists and labels to avoid runtime errors. Add an aria-label to the AI summaries toggle and ensure summary mode options/inputs are disabled when there is no API key as well as when not Pro, with corresponding opacity/pointer-events styling to indicate disabled state. These changes improve stability and accessibility in the AI settings UI.
Replace the ESM import and createRequire usage with a CommonJS require destructuring to import scopedPreflightStyles and isolateInsideOfContainer from 'tailwindcss-scoped-preflight'. No functional changes to rootClass; this simplifies the import and removes the need for createRequire.
PR Description — Free plugin (
wedocs)Summary
Adds the AI Doc Summary settings section to the AI Control Settings panel. The section is gated behind a PRO upgrade overlay for free users. Includes a "Default Display Mode" option to force all docs into either Summary or Highlights mode.
What's new
Removed duplicate
ai-summaryendpoint fromincludes/API/API.phpGET /wp/v2/docs/{id}/ai-summary— this is PRO-onlyAI Doc Summary settings section (
AiSettings.js)onMouseEnterwhen!isProSettings sanitization (
includes/API/SettingsApi.php)sanitize_ai_settings()now savesdisplay_modeforai_summaries['summary', 'highlights'], defaults tosummaryFiles changed
Related PRO PR
Close 171
Summary by CodeRabbit
New Features
Improvements