Skip to content

Jetpack AI: allow site editors to use Jetpack AI features #43181

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

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from

Conversation

vianasw
Copy link
Contributor

@vianasw vianasw commented Apr 21, 2025

Build upon #42750 to allow site editors to use Jetpack AI features.

Proposed changes:

  • In this approach, I'm relying on has_connected_admin method to check if the site has an admin with a connected account.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

Since we're changing the way we block/allow things, we need to review all our features and test them with both admin and non-admin users (like editors).

Below is a list of our current features:

  • AI Assistant Block
  • Voice to Content
  • Excerpt
  • Post Feedback
  • Write Brief
  • SEO Enhancer
  • Title Generation
  • AI Image
  • Text Block Extension
  • Image Block Extension

Please go through all these features and play with admin, non-admin users, and not connected site.

@vianasw vianasw requested a review from Copilot April 21, 2025 21:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR builds on a previous implementation to allow site editors to use Jetpack AI features by switching the connection check from user-based to admin-based.

  • Updated the import and usage from isUserConnected to isAdminConnected in both the block enabling logic and the block editor.
  • Introduced a new utility module (isAdminConnected) and updated type exports in the ai-client package.

Reviewed Changes

Copilot reviewed 8 out of 23 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/lib/can-ai-assistant-be-enabled.ts Replaced isUserConnected with isAdminConnected to validate admin connection status.
projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js Updated connection checks in the editor from user to admin.
projects/js-packages/shared-extension-utils/src/is-admin-connected.js New module to determine if an admin is connected.
projects/js-packages/shared-extension-utils/index.js Export update to include the new isAdminConnected module.
projects/js-packages/ai-client/src/types.ts Updated type export references from .js to .ts for consistency.
Files not reviewed (15)
  • projects/js-packages/ai-client/changelog/ai-assistant-for-site-editors: Language not supported
  • projects/js-packages/shared-extension-utils/changelog/ai-assistant-for-site-editors: Language not supported
  • projects/packages/my-jetpack/changelog/feature-ai-assistant-editor: Language not supported
  • projects/packages/my-jetpack/src/class-rest-ai.php: Language not supported
  • projects/plugins/backup/changelog/is-admin-connected: Language not supported
  • projects/plugins/boost/changelog/is-admin-connected: Language not supported
  • projects/plugins/classic-theme-helper-plugin/changelog/is-admin-connected: Language not supported
  • projects/plugins/crm/changelog/is-admin-connected: Language not supported
  • projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php: Language not supported
  • projects/plugins/jetpack/changelog/feature-ai-assistant-editor: Language not supported
  • projects/plugins/jetpack/extensions/plugins/ai-content-lens/ai-content-lens.php: Language not supported
  • projects/plugins/mu-wpcom-plugin/changelog/is-admin-connected: Language not supported
  • projects/plugins/protect/changelog/is-admin-connected: Language not supported
  • projects/plugins/search/changelog/is-admin-connected: Language not supported
  • projects/plugins/social/changelog/is-admin-connected: Language not supported

Copy link
Contributor

github-actions bot commented Apr 21, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the feature/ai-assistant-editor branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack feature/ai-assistant-editor
bin/jetpack-downloader test jetpack-mu-wpcom-plugin feature/ai-assistant-editor

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Block] AI Assistant [Extension] AI Content Lens [JS Package] AI Client [JS Package] Shared Extension Utils [Package] My Jetpack [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh RNA labels Apr 21, 2025
Copy link
Contributor

github-actions bot commented Apr 21, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: May 6, 2025
    • Code freeze: May 5, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Apr 21, 2025
@vianasw vianasw requested a review from a team April 21, 2025 21:58
Copy link

jp-launch-control bot commented Apr 21, 2025

Code Coverage Summary

1 file is newly checked for coverage.

File Coverage
projects/js-packages/shared-extension-utils/src/is-admin-connected.js 0/3 (0.00%) 💔

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@vianasw vianasw force-pushed the feature/ai-assistant-editor branch from 9453f37 to ad63467 Compare April 21, 2025 22:27
@vianasw vianasw changed the title Feature/ai assistant editor Jetpack AI: allow site editors to use Jetpack AI features Apr 21, 2025
@vianasw vianasw added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Apr 21, 2025
@vianasw vianasw force-pushed the feature/ai-assistant-editor branch from 85a8628 to 88f87d4 Compare April 22, 2025 20:55
In order to allow non-admin users to use Jetpack AI we need to make the
request as blog instead of user because the editor won't have connection
token. Luckily, we don't need the user_id in any of the Jetpack AI
endpoints as we're only relying on the blog_id.
@vianasw vianasw requested a review from Copilot April 23, 2025 13:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR builds on #42750 by allowing site editors to use Jetpack AI features, adjusting the connection check from general user to admin status.

  • Replaces calls to isUserConnected with isAdminConnected in the AI Assistant block files.
  • Introduces a new isAdminConnected utility in the shared-extension-utils package and updates its export.

Reviewed Changes

Copilot reviewed 4 out of 11 changed files in this pull request and generated no comments.

File Description
projects/plugins/jetpack/extensions/blocks/ai-assistant/extensions/lib/can-ai-assistant-be-enabled.ts Replaces isUserConnected with isAdminConnected to check for a connected admin.
projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js Updates import and connection check to leverage isAdminConnected.
projects/js-packages/shared-extension-utils/src/is-admin-connected.js Adds a new function to determine admin connection status.
projects/js-packages/shared-extension-utils/index.js Exports the new isAdminConnected function.
Files not reviewed (7)
  • projects/js-packages/shared-extension-utils/changelog/is-admin-connected: Language not supported
  • projects/packages/my-jetpack/changelog/feature-ai-assistant-editor: Language not supported
  • projects/packages/my-jetpack/src/class-rest-ai.php: Language not supported
  • projects/plugins/jetpack/_inc/lib/class-jetpack-ai-helper.php: Language not supported
  • projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php: Language not supported
  • projects/plugins/jetpack/changelog/feature-ai-assistant-editor: Language not supported
  • projects/plugins/jetpack/extensions/plugins/ai-content-lens/ai-content-lens.php: Language not supported

@vianasw vianasw removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Package] My Jetpack [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Plugin] Classic Theme Helper Plugin labels Apr 23, 2025
This is the only request to an AI endpoint that is made as a user and it
should stay that way because we check if the current user has edit
rights to the site in that endpoint.
@github-actions github-actions bot added [Package] My Jetpack [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Apr 23, 2025
@vianasw vianasw added [Status] Needs Review This PR is ready for review. [Type] Bug When a feature is broken and / or not performing as intended and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Apr 23, 2025
Copy link
Contributor

@CGastrell CGastrell left a comment

Choose a reason for hiding this comment

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

AI Assistant: works

Though, weirdly enough, ai-assistant-feature endpoint seems not to be working

image

Featured Image

Dropdown on the sidebar is not available to my editor user. I used the AI panel button to generate a featured image. It seems to be counting free requests and charging 10 requests per image (though the site has an AI plan).
image

Generate title

Worked both from the AI Assistant block and from the sidebar panel.

Generate feedback: works

Generate excerpt: works

Write Brief: works

Image generation:

As with featured image, I see no button to generate with AI and the toolbar button is greyed out:
image

NOTE: at this point I purchased a JP Complete plan, to test the SEO features. I now see 19 requests available. This doesn't make much sense, but also as ai-assistant-feature endpoint is not working, maybe we're getting some default values there.
image

Generating another featured image got me again the not-enough-requests notice.

SEO Enhancer:
Manual trigger works on all features. Toggle to enable auto-generation can't be switched with the editor user (403 - Forbidden response)

Overall the AI features work. The request counter is a bit odd but I think we didn't get to test how we were gonna count requests on these cases. But (maybe) it all comes down to the ai-assistant-feature endpoint not working. IDK.

The SEO toggle is a different beast, being something only admins can switch, it might get tricky to figure out what to do with it (maybe disable it with an info popover?)

@vianasw
Copy link
Contributor Author

vianasw commented Apr 24, 2025

@CGastrell I think that what happened is that my last commit didn't get in because the build failed, and you tested the previous build. My bad for not realizing it. I've tested again, and I don't see those issues.

@vianasw vianasw requested a review from a team April 24, 2025 15:14
Copy link
Contributor

@dhasilva dhasilva left a comment

Choose a reason for hiding this comment

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

Most issues are solved, though the image generation button is not visible for editors

@vianasw
Copy link
Contributor Author

vianasw commented Apr 25, 2025

Most issues are solved, though the image generation button is not visible for editors

The code that replaces the Media Library original button in the image block checks if there is a user connection, and it appears that a user connection is indeed necessary. The problem is that the Generate with AI button is intertwined with the Select Image button, and separating that would require a surgical refactor.

<MediaButtonMenu
				{ ...props }
				setSelectedSource={ setSelectedSource }
				isReplace={ isReplaceMenu( mediaProps ) }
				isFeatured={ isFeatured }
				hasImage={ mediaProps.value > 0 }
			/>
			{ isGeneralPurposeImageGeneratorBetaEnabled() && ! isFeatured && hasAiButtonSupport && (
				<MediaAiButton setSelectedSource={ setSelectedSource } />
			) }

			{ ExternalLibrary && (
				<ExternalLibrary
					{ ...mediaProps }
					externalSource={ externalSource }
					onClose={ closeLibrary }
				/>
			) }

I think it would be better to address it in a different PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] AI Assistant [Extension] AI Content Lens I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [JS Package] AI Client [JS Package] Shared Extension Utils [Package] My Jetpack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ RNA [Status] Needs Review This PR is ready for review. [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants