Skip to content

Conversation

@jom
Copy link
Member

@jom jom commented Nov 18, 2025

  • Trying to move the sidebar and unified UI to Calypso to be deployed via a Calypso app (DOTCOM-15261)

Proposed Changes

  • Add a packages/ai-manager
  • Conditionally load the unified AI chat on Calypso pages
  • Conditionally load the unified AI chat on apps/helper-center

Why are these changes being made?

Testing Instructions

Preparation

Code Review

  • Spike any critical issues whenever possible (e.g., app crashes, Help Center impact, etc.)

Test Calypso Pages

  • On a Calypso page (e.g., /me), click the "?" icon, and the Odie chat should still load
  • Add flags=unified-agent to the URL — the unified AI chat will now appear in undocked mode instead
    • Please ignore any UI issues at this stage

Test Other Pages (e.g., WP Admin, CIAB Admin, etc.)

  • Sandbox widgets.wp.com
  • Run cd apps/help-center && yarn dev --sync
  • On a non-Calypso page (e.g., /wp-admin), click the "?" icon, and the Odie chat should still load
  • Add flags=unified-agent to the URL — the unified AI chat will now appear in undocked mode instead
    • Please ignore any UI issues at this stage

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you tested accessibility for your changes? Ensure the feature remains usable with various user agents (e.g., browsers), interfaces (e.g., keyboard navigation), and assistive technologies (e.g., screen readers) (PCYsg-S3g-p2).
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

jom and others added 12 commits November 18, 2025 09:48
Implements /me/preferences API persistence and context tree functionality:

- Add usePersistedAgentState hook for syncing state to /me/preferences API
  - Persists session ID, isOpen, and isDocked state
  - Debounced saves (1s default) to minimize API calls
  - Fallback to localStorage when API unavailable
  - Supports both wpcomRequest and apiFetch

- Enhance WordPressContextAdapter with contextEntries support
  - Add getContextEntries() method to resolve context data
  - Support for sitemap and entity context from next-admin store
  - Resolves getData closures to provide current context data
  - Backward compatibility with separate sitemap/entities fields

- Integrate persistence with AgentDock component
  - Sync sessionId, chatState, and isDocked to preferences
  - Add optional preference configuration props
  - Maintain localStorage fallback for offline support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add AI agent loader to Calypso following the help-center pattern:

- Create AIAgentLoader component for lazy loading with AsyncLoad
  - Similar pattern to HelpCenterLoader
  - Provides section name, current route, site, and user data
  - Positioned in main layout alongside HelpCenterLoader

- Add CalypsoAIAgent wrapper component
  - Default export for AsyncLoad integration
  - Configures AgentDock with Calypso-specific settings
  - Integrates CalypsoContextAdapter for environment context
  - Uses wpcomRequest for /me/preferences persistence
  - Provides default suggestions for getting started

- Update ai-agents package exports
  - Export CalypsoAIAgent as default for AsyncLoad
  - Export CalypsoAIAgentProps type for consumers

- Integrate into client/layout/index.jsx
  - Add AIAgentLoader to main logged-in layout
  - Renders alongside other layout components

This enables the AI agent to be loaded throughout Calypso
with proper context awareness and state persistence.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Integrate CalypsoChromeAdapter to provide visual frame around content when agent is docked and expanded.

- Add chromeAdapter to CalypsoAIAgent component
- Pass chrome adapter to AgentDock for DOM manipulation
- Applies CSS classes for docked/expanded states

Note: Additional CSS styling may be needed to properly display the frame.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fix two critical issues:

1. Chrome Framing & Background
   - Rewrite CalypsoChromeAdapter to inject CSS dynamically
   - Adapt big-sky-plugin chrome styles for Calypso's #wpcom container
   - Apply visual frame with border, spacing, and dark background
   - Target .masterbar and #wpcom for proper Calypso integration
   - Fix black background issue by applying chrome only when docked

2. Infinite Update Loop in usePersistedAgentState
   - Change saveTimeout from state to ref (saveTimeoutRef)
   - Remove saveTimeout from useCallback dependencies
   - Prevents infinite re-render loop when saving state
   - Fixes "Maximum update depth exceeded" error

Chrome CSS features:
- Dark background (#1e1e1e) when agent is docked
- Fixed positioning for masterbar and #wpcom
- Border and border-radius for framed appearance
- Proper spacing (16px) and sidebar width (350px)
- Automatically injected/removed on dock/undock

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add ChatHeader component with dropdown menu functionality:

- Create ChatHeader component
  - Displays menu dropdown and close button
  - Adapted from big-sky-plugin chat header
  - Uses WordPress DropdownMenu component
  - Responsive button sizes based on dock state

- Add menu items to AgentDock
  - Dock/Undock toggle (drawerRight/login icons)
  - Reset chat (rotateRight icon)
  - Menu items created dynamically based on dock state
  - Integrate ChatHeader into AgentUI.ConversationView

- Update agent configuration
  - Use wp-orchestrator agent ID
  - Use production agent URL (public-api.wordpress.com)
  - Match big-sky-plugin constants

Menu features:
- Pop out/Move to sidebar - toggles dock/undock
- Reset chat - clears conversation and creates new session
- Close button - closes/collapses the agent
- Icons from @wordpress/icons for consistency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
… to follow conventions

- Fix chrome application logic by removing redundant manual calls in handlers
- Fix sidebar breaking CSS issue by simplifying body container styles
- Add animated Big Sky icon component using @rive-app/react-canvas
- Rename all files and folders to follow lowercase-with-dashes convention:
  - Component folders: AgentDock → agent-dock, AgentsManager → agents-manager, etc.
  - Adapter files: ChromeAdapter.ts → chrome-adapter.ts, etc.
  - Hook files: useAgentSession.ts → use-agent-session.ts, etc.
  - Config files: createAgentConfig.ts → create-agent-config.ts
  - Abilities files: AbilityRegistry.ts → ability-registry.ts
- Update all import paths across the package to reflect new file names

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements OAuth-based authentication for AI agent requests to public-api.wordpress.com using Calypso's @automattic/oauth-token package. The authentication provider retrieves the OAuth token from wpcom_token cookie/localStorage and adds it to the Authorization header as a Bearer token, matching the pattern used by wpcom-xhr-request.

Changes:
- Created calypso-auth-provider.ts with OAuth token integration
- Updated CalypsoAIAgent to use authProvider and enable streaming
- Added @automattic/oauth-token dependency
- Exported authentication utilities and types

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fixes chrome frame border issues with Calypso sidebar and improves UX by disabling reset chat when no messages or during processing.

Changes:
- Updated CalypsoChromeAdapter to properly position and constrain sidebar within chrome frame
- Added left/bottom spacing to sidebar for proper border alignment
- Added height/max-height constraints to both #wpcom and .layout__secondary to prevent overflow
- Disabled reset chat menu item when no messages or when agent is processing (matching big-sky-plugin behavior)
- Added isDisabled property to ChatHeaderMenuItem interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add conditional loading to help-center package that allows switching between
the legacy HelpCenterGPT and the new unified CalypsoAIAgent based on feature flags.

**Implementation:**

1. Created `useShouldUseUnifiedAgent` hook that checks:
   - Config flag: `config.isEnabled('unified-agent')`
   - URL flag: `?flags=unified-agent` for testing
   - API eligibility: `supportStatus.eligibility.unified_agent_enabled`
     (requires backend support-status endpoint update)

2. Created `HelpCenterAIAssistant` wrapper component that:
   - Renders CalypsoAIAgent when feature flag is enabled
   - Falls back to legacy HelpCenterGPT when disabled
   - Passes currentUser, site, and sectionName from help-center context

3. Updated `help-center-contact-form.tsx` to use HelpCenterAIAssistant
   instead of HelpCenterGPT directly

4. Added `@automattic/ai-agents` as workspace dependency

5. Exported new component and hook from package index

**Testing:**
- Add `?flags=unified-agent` to URL to test the new unified agent
- Or enable via config flag in calypso-config

**Future work:**
- Backend needs to add `unified_agent_enabled` field to /help/support-status
- Consider lazy-loading CalypsoAIAgent to reduce bundle size when flag is off

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add unified-agent flag to help-center widget config.js.
This allows the config.isEnabled('unified-agent') check to work
in the help-center widget deployed to widgets.wp.com.

Set to false by default. Can be enabled to test unified AI agent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link

github-actions bot commented Nov 18, 2025

jom and others added 5 commits November 18, 2025 13:30
Enable /me/preferences persistence for help-center widget by:

1. Adding optional savePreference/loadPreference props to CalypsoAIAgent
   - Falls back to window.wpcomRequest if not provided (Calypso context)
   - Allows external implementations to be passed in

2. Implementing preference callbacks in HelpCenterAIAssistant using wpcom-proxy-request
   - Uses canAccessWpcomApis() to check availability
   - Saves/loads from /me/preferences endpoint
   - Persists agent dock state (docked/undocked, chat state)

This ensures the agent's state is persisted across sessions in both
Calypso and help-center widget contexts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Set unified-agent feature flag to true in help-center config
to enable testing of the new unified AI agent in dev environment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add console logs to trace:
- Which feature flag checks are passing/failing
- Whether CalypsoAIAgent or HelpCenterGPT is rendered
- Current config data and support status
- User and site context

This will help debug why the unified UI might not be showing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements proper authentication for AI agents in both Calypso and non-Calypso
environments, with improved chrome styling for wp-admin.

Authentication Changes:
- Add JWT token authentication via apiFetch for non-Calypso environments
- Detect environment (Calypso vs wp-admin/widgets.wp.com) using origin
- Use OAuth Bearer tokens in Calypso (wordpress.com, *.calypso.live)
- Use JWT tokens from REST API in wp-admin (simple & Jetpack sites)
- Support both simple sites (/wpcom/v2/sites/{id}/jetpack-openai-query/jwt)
  and Jetpack sites (/jetpack/v4/jetpack-ai-jwt)
- Cache JWT tokens in localStorage for 30 minutes
- Pass site ID from CalypsoAIAgent props to auth provider

Chrome Adapter Improvements:
- Add wp-admin specific chrome styles when container is #wpbody
- Fix #adminmenuback and #adminmenuwrap fixed positioning
- Adjust #wpcontent margins for admin menu + AI sidebar
- Position #wpadminbar with proper spacing and borders
- Prevent admin menu from overlapping with AI agent sidebar

Help Center Integration:
- Fix TypeScript types for wpcomRequest responses
- Fix import order and linting issues
- Use defaultOpen prop correctly (boolean attribute)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@wellyshen wellyshen mentioned this pull request Nov 19, 2025
9 tasks
@matticbot
Copy link
Contributor

matticbot commented Nov 19, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • help-center
  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug try/ai-agents on your sandbox.

@wellyshen wellyshen force-pushed the try/ai-agents branch 2 times, most recently from 500cba7 to a65aae5 Compare November 20, 2025 09:51
@matticbot
Copy link
Contributor

matticbot commented Nov 20, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~145 bytes added 📈 [gzipped])

name                    parsed_size           gzip_size
entry-main                  -4845 B  (-0.2%)     +120 B  (+0.0%)
entry-stepper               -1036 B  (-0.1%)     +112 B  (+0.0%)
entry-dashboard-dotcom       -435 B  (-0.0%)      +33 B  (+0.0%)
entry-dashboard-ciab         -435 B  (-0.0%)      +31 B  (+0.0%)
entry-domains-landing        +322 B  (+0.0%)     +175 B  (+0.1%)
entry-browsehappy            +322 B  (+0.1%)     +175 B  (+0.2%)
entry-reauth-required        +144 B  (+0.0%)     +124 B  (+0.0%)
entry-login                   +67 B  (+0.0%)     +123 B  (+0.0%)
entry-subscriptions           +48 B  (+0.0%)      +26 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~53269 bytes added 📈 [gzipped])

name                                parsed_size           gzip_size
site-performance                         -747 B  (-0.0%)     +803 B  (+0.1%)
staging-site                             -669 B  (-0.0%)     -637 B  (-0.1%)
sites-dashboard                          -669 B  (-0.0%)     -637 B  (-0.1%)
site-settings                            -669 B  (-0.0%)     -637 B  (-0.1%)
site-logs                                -669 B  (-0.0%)     -637 B  (-0.1%)
plans                                    -669 B  (-0.0%)     -637 B  (-0.1%)
overview                                 -669 B  (-0.0%)     -637 B  (-0.1%)
hosting                                  -669 B  (-0.0%)     -637 B  (-0.1%)
github-deployments                       -669 B  (-0.0%)     -637 B  (-0.1%)
domains                                  -669 B  (-0.0%)     -637 B  (-0.1%)
a8c-for-agencies-client                  -653 B  (-0.0%)     -282 B  (-0.0%)
site-monitoring                          -566 B  (-0.0%)     -614 B  (-0.1%)
account                                  -462 B  (-0.1%)     +212 B  (+0.1%)
a8c-for-agencies-sites                   -346 B  (-0.0%)     +886 B  (+0.1%)
performance-profiler                     -336 B  (-0.1%)     -833 B  (-0.6%)
signup                                   -280 B  (-0.1%)       -9 B  (-0.0%)
async-step-unified-plans                 -280 B  (-0.0%)       -8 B  (-0.0%)
reader                                   -268 B  (-0.0%)     -610 B  (-0.1%)
patterns                                 -268 B  (-0.0%)     -627 B  (-0.1%)
a8c-for-agencies-woopayments             -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-team                    -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-reports                 -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-referrals               -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-overview                -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-migrations              -268 B  (-0.0%)     -610 B  (-0.1%)
a8c-for-agencies-agency-tier             -268 B  (-0.0%)     -610 B  (-0.1%)
devdocs                                  -258 B  (-0.1%)      -29 B  (-0.0%)
subscribers                              -237 B  (-0.0%)     -594 B  (-0.1%)
site-purchases                           -237 B  (-0.0%)     -594 B  (-0.1%)
purchases                                -237 B  (-0.0%)     -594 B  (-0.1%)
jetpack-cloud-plugin-management          -237 B  (-0.0%)     -593 B  (-0.1%)
a8c-for-agencies-plugins                 -237 B  (-0.0%)     -593 B  (-0.1%)
a8c-for-agencies-marketplace             -203 B  (-0.0%)     -347 B  (-0.1%)
async-step-use-my-domain                 -175 B  (-0.0%)     -130 B  (-0.0%)
marketing                                -165 B  (-0.0%)     -434 B  (-0.2%)
a8c-for-agencies-landing                 -165 B  (-0.1%)     -600 B  (-0.7%)
a8c-for-agencies                         -165 B  (-0.1%)     -594 B  (-0.8%)
security                                 -160 B  (-0.0%)     -638 B  (-0.3%)
notification-settings                    -160 B  (-0.0%)     -686 B  (-0.3%)
a8c-for-agencies-partner-directory       -160 B  (-0.0%)     -501 B  (-0.3%)
google-my-business                       -155 B  (-0.0%)     -539 B  (-0.3%)
marketplace                              +151 B  (+0.0%)     +383 B  (+0.2%)
promote-post-i2                          -134 B  (-0.0%)     -471 B  (-0.2%)
plugins                                  -134 B  (-0.0%)     -567 B  (-0.1%)
migrate                                  -134 B  (-0.0%)     -324 B  (-0.2%)
earn                                     -134 B  (-0.0%)     -642 B  (-0.2%)
checkout                                 -134 B  (-0.0%)     -389 B  (-0.1%)
switch-site                              -114 B  (-0.1%)     -372 B  (-0.6%)
site-blocks                              -114 B  (-0.0%)     -536 B  (-0.3%)
privacy                                  -114 B  (-0.0%)     -531 B  (-0.3%)
me                                       -114 B  (-0.0%)     -531 B  (-0.3%)
jetpack-cloud-agency-dashboard           -114 B  (-0.0%)     -428 B  (-0.1%)
developer                                -114 B  (-0.0%)     -531 B  (-0.3%)
account-close                            -114 B  (-0.0%)     -547 B  (-0.3%)
a8c-for-agencies-signup                  -114 B  (-0.0%)     -475 B  (-0.7%)
a8c-for-agencies-settings                -114 B  (-0.0%)     -564 B  (-0.5%)
a8c-for-agencies-feedback                -114 B  (-0.0%)     -551 B  (-0.6%)
stats                                     -97 B  (-0.0%)     -420 B  (-0.1%)
settings-podcast                          +93 B  (+0.0%)      +45 B  (+0.0%)
home                                      +93 B  (+0.0%)      +65 B  (+0.0%)
settings                                  -83 B  (-0.0%)     -466 B  (-0.2%)
jetpack-connect                           -83 B  (-0.0%)     -465 B  (-0.1%)
email                                     -83 B  (-0.0%)     -690 B  (-0.2%)
backup                                    -83 B  (-0.0%)     -440 B  (-0.1%)
jetpack-cloud-overview                    +62 B  (+0.0%)     +472 B  (+0.3%)
import                                    -61 B  (-0.0%)     -502 B  (-0.2%)
theme                                     -59 B  (-0.0%)     -117 B  (-0.0%)
jetpack-cloud-partner-portal              +56 B  (+0.0%)     +250 B  (+0.1%)
themes                                    +49 B  (+0.0%)      +99 B  (+0.0%)
a8c-for-agencies-purchases                -47 B  (-0.0%)     +168 B  (+0.1%)
woocommerce-installation                  +31 B  (+0.0%)      +16 B  (+0.0%)
woocommerce                               +31 B  (+0.0%)      +15 B  (+0.0%)
settings-writing                          +31 B  (+0.0%)      +16 B  (+0.0%)
settings-security                         +31 B  (+0.0%)      +16 B  (+0.0%)
settings-reading                          +31 B  (+0.0%)      +16 B  (+0.0%)
settings-performance                      +31 B  (+0.0%)      +16 B  (+0.0%)
settings-newsletter                       +31 B  (+0.0%)      +16 B  (+0.0%)
settings-jetpack                          +31 B  (+0.0%)      +16 B  (+0.0%)
settings-discussion                       +31 B  (+0.0%)      +16 B  (+0.0%)
scan                                      +31 B  (+0.0%)      +16 B  (+0.0%)
posts-custom                              +31 B  (+0.0%)      +16 B  (+0.0%)
posts                                     +31 B  (+0.0%)      +16 B  (+0.0%)
pages                                     +31 B  (+0.0%)      +16 B  (+0.0%)
media                                     +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-social                            +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-search                            +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-cloud-settings                    +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-cloud-pricing                     +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-cloud-features-comparison         +31 B  (+0.0%)      +16 B  (+0.0%)
jetpack-cloud                             -31 B  (-0.0%)     -300 B  (-0.2%)
gutenberg-editor                          +31 B  (+0.0%)      +16 B  (+0.0%)
export                                    +31 B  (+0.0%)      +16 B  (+0.0%)
customize                                 +31 B  (+0.0%)      +16 B  (+0.0%)
concierge                                 +31 B  (+0.0%)      +16 B  (+0.0%)
comments                                  +31 B  (+0.0%)      +16 B  (+0.0%)
add-ons                                   +31 B  (+0.0%)      +16 B  (+0.0%)
activity                                  +31 B  (+0.0%)      +16 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~137961 bytes added 📈 [gzipped])

name                                                                              parsed_size            gzip_size
async-load-automattic-help-center                                                   +379895 B  (+10.6%)  +115312 B  (+16.5%)
async-load-help-center-app                                                          +379657 B  (+10.4%)  +113567 B  (+15.7%)
async-load-design-blocks                                                              +1003 B   (+0.0%)     -426 B   (-0.1%)
async-load-signup-steps-domains                                                        -268 B   (-0.0%)     -552 B   (-0.1%)
async-load-design-playground                                                           -192 B   (-0.0%)     -450 B   (-0.1%)
async-load-design                                                                      -192 B   (-0.0%)     -450 B   (-0.1%)
async-load-quick-language-switcher                                                     -165 B   (-0.1%)     -498 B   (-1.1%)
async-load-design-wordpress-components-gallery                                         -165 B   (-0.0%)     -622 B   (-0.3%)
async-load-automattic-global-styles-src-components-global-styles-variations            -144 B   (-0.0%)     -629 B   (-0.1%)
async-load-calypso-lib-account-settings-helper                                         -114 B   (-0.0%)     -536 B   (-0.3%)
async-load-calypso-layout-command-palette                                              -114 B   (-0.0%)     -372 B   (-0.5%)
async-load-calypso-my-sites-stats-pages-subscribers                                    -108 B   (-0.1%)      -44 B   (-0.1%)
async-load-calypso-my-sites-stats-pages-realtime                                       -108 B   (-2.9%)      -35 B   (-2.4%)
async-load-store-app-store-stats                                                       +102 B   (+0.0%)      +30 B   (+0.0%)
async-load-calypso-my-sites-stats-pages-realtime-chart                                  -66 B   (-0.0%)     -716 B   (-0.6%)
async-load-calypso-my-sites-stats-components-line-chart                                 -66 B   (-0.0%)     -716 B   (-0.6%)
async-load-calypso-post-editor-media-modal                                              +31 B   (+0.0%)     -267 B   (-0.1%)
async-load-calypso-jetpack-cloud-sections-sidebar-navigation-manage-selected-...        +31 B   (+0.0%)     +195 B   (+0.6%)
async-load-calypso-blocks-jitm-templates-modal                                          +31 B   (+0.1%)      -77 B   (-0.8%)
async-load-calypso-blocks-jitm                                                          +31 B   (+0.2%)       +6 B   (+0.1%)
async-load-signup-steps-site-picker                                                     -12 B   (-0.0%)     -106 B   (-0.2%)
async-load-signup-steps-difm-site-picker                                                -12 B   (-0.0%)      -95 B   (-0.2%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@wellyshen wellyshen self-assigned this Nov 20, 2025
@wellyshen wellyshen marked this pull request as ready for review November 21, 2025 10:00
@wellyshen wellyshen requested a review from a team as a code owner November 21, 2025 10:00
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 21, 2025
@wellyshen wellyshen requested review from a team, alshakero and emdashcodes November 21, 2025 11:06
Copy link
Member

@alshakero alshakero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! I left 2 comments only. Nothing blocking, just trying to help.

currentRoute: string;
};

export default function AIAgentLoader( { sectionName, currentRoute }: Props ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: AIAgentLoader can access these values directly. No need for the props.

Comment on lines +6 to +9
const currentUrl = window.location.href;
const urlParams = new URLSearchParams( new URL( currentUrl ).search );
const flags = urlParams.get( 'flags' );
return flags?.split( ',' ).includes( 'unified-agent' ) ?? false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be replaced with isEnabled( 'unified-agent' )

Comment on lines +115 to +133
const defaultLoadPreference = async ( key: string ): Promise< PersistedAgentState | null > => {
// Try to use wpcom API if available
if ( typeof window !== 'undefined' && ( window as any ).wpcomRequest ) {
const wpcomRequest = ( window as any ).wpcomRequest;
try {
const response = await wpcomRequest( {
path: '/me/preferences',
apiNamespace: 'wpcom/v2',
method: 'GET',
} );
return response?.calypso_preferences?.[ key ] || null;
} catch ( error ) {
// eslint-disable-next-line no-console
console.warn( '[usePersistedAgentState] Failed to load from wpcom:', error );
}
}

return null;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@wellyshen wellyshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's 🚀

@jom jom merged commit 3cc2bb4 into trunk Nov 21, 2025
12 checks passed
@jom jom deleted the try/ai-agents branch November 21, 2025 14:17
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 21, 2025
@a8ci18n
Copy link

a8ci18n commented Nov 21, 2025

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/30864743

Some locales (Hebrew) have been temporarily machine-translated due to translator availability. All other translations are usually ready within a few days. Untranslated and machine-translated strings will be sent for translation next Monday and are expected to be completed by the following Friday.

Hi @jom, could you please edit the description of this PR and add a screenshot for our translators? Ideally it'd include all of the following strings:

  • How can I help you today?
  • Pop out sidebar
  • Move to sidebar
  • Reset chat
  • Open Chat

Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants