Add: AI-assisted payload generation to the Ability Explorer - Test Ability Screen#695
Add: AI-assisted payload generation to the Ability Explorer - Test Ability Screen#695Arkenon wants to merge 3 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Any feedback or suggestions on this PR? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #695 +/- ##
=============================================
- Coverage 76.41% 75.66% -0.75%
- Complexity 1828 1840 +12
=============================================
Files 87 87
Lines 7764 7842 +78
=============================================
+ Hits 5933 5934 +1
- Misses 1831 1908 +77
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
dkotter
left a comment
There was a problem hiding this comment.
I've not tested yet but a number of things that need cleaned up here. In addition, would be great to get test coverage here, unit tests potentially but definitely E2E tests.
While the overall idea is neat here, the overall flow I think could be improved a bit. For instance, the modal itself has a title of Generate Payload with AI but then in the textarea, you add a prompt that says Generate payload for ....
We've been trying to remove the use of with AI, so I think just Generate Payload both in the modal and the button that triggers the modal will be better. I'm also not sure about requiring a user to enter details about their desired payload. Could the generate function not just generate it's own payload without user input? I understand that gets trickier if a post is required, for example, but seems solvable. Just seems to make it less user friendly to click a generate button but then be required to manually enter in a bunch of information first
| /** | ||
| * AJAX handler for AI-assisted payload generation. | ||
| * | ||
| * @since 1.0.1 |
There was a problem hiding this comment.
All @since statements should be set to x.x.x
| <ol> | ||
| <li><?php esc_html_e( 'Edit the JSON input below with your test data', 'ai' ); ?></li> | ||
| <li><?php esc_html_e( 'Click "Validate Input" to check your JSON is correct', 'ai' ); ?></li> | ||
| <li><?php esc_html_e( 'Click "Invoke Ability" to execute the ability with your input', 'ai' ); ?></li> | ||
| <li><?php esc_html_e( 'View the results below', 'ai' ); ?></li> | ||
| </ol> |
There was a problem hiding this comment.
Why was spacing changed here?
| @@ -1,4 +1,5 @@ | |||
| <?php | |||
|
|
|||
There was a problem hiding this comment.
There's quite a few of these spacing changes in this PR. Any particular reason for those? If not, reverting those keeps the diff here cleaner and easier to review
| ); | ||
| } | ||
|
|
||
| if ( ! function_exists( 'wp_ai_client_prompt' ) ) { |
There was a problem hiding this comment.
This function should always exist as WP 7.0 is our minimum
| if ( ! $prompt_builder->is_supported_for_text_generation() ) { | ||
| wp_send_json_error( | ||
| array( | ||
| 'message' => __( 'No AI provider available. Please connect one in the plugin settings.', 'ai' ), |
There was a problem hiding this comment.
| 'message' => __( 'No AI provider available. Please connect one in the plugin settings.', 'ai' ), | |
| 'message' => __( 'Generation failed. Please ensure you have a connected provider that supports text generation.', 'ai' ), |
| 'title' => __( 'Overview', 'ai' ), | ||
| 'content' => | ||
| '<p>' . esc_html__( 'Abilities are a standardized way for WordPress core, plugins, and themes to expose discrete units of functionality. Each ability has a name, optional input/output schemas, and can be invoked programmatically.', 'ai' ) . '</p>' . | ||
| '<p>' . esc_html__( 'Abilities are a standardized way for WordPress core, plugins, and themes to expose discrete units of functionality. Each ability has a name, optional input/output schemas, and can be invoked programmatically.', 'ai' ) . '</p>' . |
| '<p>' . esc_html__( 'Every ability is associated with a provider that indicates where it comes from:', 'ai' ) . '</p>' . | ||
| '<ul>' . | ||
| '<li>' . wp_kses( __( '<strong>Core</strong>: Built into WordPress itself.', 'ai' ), $provider_tags ) . '</li>' . | ||
| '<li>' . wp_kses( __( '<strong>Plugin</strong>: Registered by an active plugin.', 'ai' ), $provider_tags ) . '</li>' . | ||
| '<li>' . wp_kses( __( '<strong>Theme</strong>: Registered by the active theme.', 'ai' ), $provider_tags ) . '</li>' . | ||
| '<li>' . wp_kses( __( '<strong>Core</strong>: Built into WordPress itself.', 'ai' ), $provider_tags ) . '</li>' . | ||
| '<li>' . wp_kses( __( '<strong>Plugin</strong>: Registered by an active plugin.', 'ai' ), $provider_tags ) . '</li>' . | ||
| '<li>' . wp_kses( __( '<strong>Theme</strong>: Registered by the active theme.', 'ai' ), $provider_tags ) . '</li>' . |
| '<p>' . esc_html__( 'You can test any ability directly from this screen:', 'ai' ) . '</p>' . | ||
| '<ol>' . | ||
| '<li>' . __( 'Click "Test" next to an ability in the list.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Edit the pre-filled Input Data if the ability accepts JSON parameters.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Use "Validate Input" to check your JSON against the schema.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Click "Invoke Ability" to execute it and see the result.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Click "Test" next to an ability in the list.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Edit the pre-filled Input Data if the ability accepts JSON parameters.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Use "Validate Input" to check your JSON against the schema.', 'ai' ) . '</li>' . | ||
| '<li>' . __( 'Click "Invoke Ability" to execute it and see the result.', 'ai' ) . '</li>' . |
| $screen->set_help_sidebar( | ||
| '<p><strong>' . esc_html__( 'For more information:', 'ai' ) . '</strong></p>' . | ||
| '<p><a href="https://developer.wordpress.org/apis/abilities/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Abilities API Documentation', 'ai' ) . '</a></p>' | ||
| '<p><a href="https://developer.wordpress.org/apis/abilities/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Abilities API Documentation', 'ai' ) . '</a></p>' |
There was a problem hiding this comment.
Spacing addition that can be removed
| onClose: close, | ||
| onSuccess: handleSuccess, | ||
| abilitySlug, | ||
| strings: aiAbilityExplorer.strings, |
There was a problem hiding this comment.
We can use the client-side __ functions instead of passing in strings from the server-side
What?
Adds AI-assisted payload generation to the Ability Test Runner. Users can describe a test scenario in natural language and automatically generate a valid JSON payload based on the selected ability's input schema.
Why?
Some abilities expose complex or deeply nested input schemas that are difficult to populate manually. Creating valid test payloads often requires understanding schema structures, enum values, nested objects, and validation constraints.
This makes testing abilities slower and more error-prone, especially for contributors who are unfamiliar with a specific ability's schema.
How?
ability_test_generate_with_ai.mp4
This PR introduces a new Generate with AI workflow in the Ability Test Runner:
wp_ai_client_prompt().Implementation Details
ajax_generate_payload()AJAX handler.wp_ai_client_prompt().generateNonce(ai_ability_explorer_generate_payload) for AJAX authentication.Use of AI Tools
AI assistance: Yes
Tool(s): ChatGPT
Model(s): GPT-5.5
Used for: Brainstorming the feature design, refining prompts, and drafting portions of documentation. Final implementation, review, testing, and code decisions were completed by me.
Testing Instructions
Note: An AI provider must be connected in the plugin settings for this feature to be available.
Screenshots or screencast
Before | After -- | -- N/A | Generate with AI button and payload generation modalChangelog Entry