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 17 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 79.68% 79.14% -0.55%
- Complexity 2460 2478 +18
=============================================
Files 104 104
Lines 9955 10025 +70
=============================================
+ Hits 7933 7934 +1
- Misses 2022 2091 +69
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
| 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
|
@dkotter Thanks for your review. I just linted the PHP files, and I'm not sure why that extra spacing was added, but I'll fix it throughout the codebase. I'm currently working on the feature. I'll also look into generating the payload automatically instead of using a prompt. I'll submit an updated PR as soon as possible. |
…dPress Abilities API registrations
add: Auto create payload with button
…specified in iterable type array.
|
I have completed the changes. The Test Ability screen now only has a Generate Payload button. The AI agent generates the payload based on the input schema. ScreenRecorderProject3.mp4 |
dkotter
left a comment
There was a problem hiding this comment.
This is looking better but still have a few things that need addressed before we proceed.
In addition to the things flagged, we need to ensure we get some E2E tests added and ideally let's get the PR description updated to match latest changes
| "Ability description: %s\n" . | ||
| "The payload must be a JSON object that conforms to the following JSON schema:\n%s\n" . | ||
| 'Use plausible, realistic example values for every required property. If post id needed set id as 1.' . | ||
| 'Include optional properties only when they help demonstrate the ability.', |
There was a problem hiding this comment.
The instruction here around optional properties contradicts what we do in normalize_schema_for_response, which forces all properties to be required. Ideally we should determine which approach we want to take and ensure we aren't providing conflicting instructions
| "Generate a realistic example test payload for the WordPress ability \"%s\".\n" . | ||
| "Ability description: %s\n" . | ||
| "The payload must be a JSON object that conforms to the following JSON schema:\n%s\n" . | ||
| 'Use plausible, realistic example values for every required property. If post id needed set id as 1.' . |
There was a problem hiding this comment.
There's a couple issues here:
- Some sites may not have a post ID of 1. We could find a real post and pass the ID in
- What if the input schema wants a post ID but doesn't want it in an
idfield? For instance, if it asks forpost_idinstead? I think we need to be a little more generic on this instruction
There was a problem hiding this comment.
Also need a newline break after this line otherwise it runs into the next line
| <button type="button" id="ability-test-clear" class="button"> | ||
| <?php esc_html_e( 'Clear Result', 'ai' ); ?> | ||
| </button> | ||
| <?php if ( ! empty( $ability['input_schema'] ) ) : ?> |
There was a problem hiding this comment.
Would we want a check here to ensure we have an AI connector in place before we output this button? Or if not, we should ensure we output a better error message in that situation so users know what went wrong
| if ( ! button.dataset.originalText ) { | ||
| button.dataset.originalText = originalText; | ||
| } | ||
| button.innerHTML = |
There was a problem hiding this comment.
Can we avoid using innerHTML here? We should be able to build the span node and assign textContent to it
There was a problem hiding this comment.
Seems like a bunch of unnecessary reformatting on this file. Ideally we revert that to keep the changes here focused
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