Skip to content

Re organize ai code #22440

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 22 commits into
base: trunk
Choose a base branch
from
Open

Re organize ai code #22440

wants to merge 22 commits into from

Conversation

pls78
Copy link
Member

@pls78 pls78 commented Jul 16, 2025

Context

  • We want to tidy up the AI-related code.
  • ⚠️ Merge this and the corresponding Premium PR only after discussing with Lingo about the AI Optimize and AI Summarize features.

Summary

This PR can be summarized in the following changelog entry:

  • Re-organizes AI-related code by collecting all modules into an ai parent directory and consequently losing the AI_ namespace/class prefix
  • Exposes the REST endpoints in the window object.

Relevant technical choices:

  • All the AI-related modules dropped the AI_ prefix and are now under an ai parent directory.
  • Endpoint_List and Endpoints_Repository classes have been moved to src/routes/endpoint directory, so that they can be re-used throughout the codebase and not being re-declared each time.
  • Consent_Endpoint_Interface, Free_Sparks_Endpoint_Interface, Generator_Endpoint_Interface have been introduced to let our DI container know which endpoints need to be gathered by the respective repository. As a result, they are attached to the respective integration window object in the endpoint property (exception made for the Free Sparks one, which is bundled in thewpseoAiGenerator window object.
  • This means we can now fetch routes URLs from the backend, avoiding hard-coding it in JavaScript ( like we already do in the Dashboard)

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Smoke test the AI Generate and AI Optimize features

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite
  • Please check no errors or warnings are issued in the console
  • Please test this PR in each of the supported editors
  • Please test this PR for posts, pages and product pages

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • N/A

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #632

@coveralls
Copy link

coveralls commented Jul 16, 2025

Pull Request Test Coverage Report for Build 44881b69ddc2a6cdc14ba46e26e0e855153f4d93

Details

  • 1 of 40 (2.5%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 52.167%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ai/consent/application/consent-endpoints-repository.php 0 3 0.0%
src/ai/free-sparks/application/free-sparks-endpoints-repository.php 0 3 0.0%
src/ai/generate/application/generator-endpoints-repository.php 0 3 0.0%
src/routes/endpoint/endpoint-list.php 0 4 0.0%
src/ai/consent/user-interface/consent-integration.php 0 5 0.0%
src/routes/endpoint/endpoints-repository.php 0 7 0.0%
src/ai/generate/user-interface/generator-integration.php 0 14 0.0%
Totals Coverage Status
Change from base Build a4399526a0f41512e42b20af9a464fa1eccb85c3: -0.02%
Covered Lines: 30508
Relevant Lines: 59171

💛 - Coveralls

@pls78 pls78 added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Jul 21, 2025
Copy link

A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch.

@pls78 pls78 force-pushed the re-organize-ai-code branch from 77469ce to b982687 Compare July 24, 2025 12:33
@pls78 pls78 marked this pull request as ready for review July 25, 2025 10:08
Copy link

A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch.

@@ -1,8 +1,9 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

We disable this rules in many files.

can we consider to extend maxSegments in phpcs.xml?

<rule ref="Yoast.NamingConventions.NamespaceName.TooLong">
    <properties>
        <property name="maxSegments" value="5"/>
    </properties>
</rule>

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, there's a discussion about this here.

*
* @var array<Consent_Endpoint_Interface>
*/
private $endpoints;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this filed be removed taking into account the the same filed is present in Endpoints_Repository and DI will take into account constructor definition but not the internal implementation ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here.

*
* @var array<Free_Sparks_Endpoint_Interface>
*/
private $endpoints;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this field ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here.

*
* @var array<Generator_Endpoint_Interface>
*/
private $endpoints;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this field ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed here.

@mykola
Copy link
Contributor

mykola commented Jul 31, 2025

@pls78 please resolve merge conflicts.

@pls78 pls78 force-pushed the re-organize-ai-code branch from b982687 to 2d5c5ad Compare August 14, 2025 07:46
Copy link

A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants