In-context "Generate with AI" button
A button injected into the SEO fieldset on product / category / CMS edit forms. Click it → modal pops up with a Claude-generated suggestion → click Insert → the form's meta_title and meta_description fields get populated. Editor still has to save the form for the values to persist.
What makes this different from the queue
- No DB write — it's a generate-and-discard preview. The suggestion isn't queued, isn't persisted, isn't tracked in the AI Meta Suggestions grid.
- Editor stays in flow — they're already on the product edit form; one click drafts copy, one click inserts it, save as normal.
- Per-store via the edit URL's
storeparameter — the modifier reads?store=<id>from the request and passes it to the preview controller. Switching the scope selector at the top of the form gives the AI the right per-store context for that generation
Where it appears
- Product edit page — top of the "Search Engine Optimization" section. Injected via
Byte8\SeoSuite\Ui\DataProvider\Product\Form\Modifier\AiMetaButton. - Category edit page — top of the "Search Engine Optimization" fieldset. Via the form XML override in
view/adminhtml/ui_component/category_form.xml. - CMS Page edit — top of the "Search Engine Optimisation" fieldset. Via
view/adminhtml/ui_component/cms_page_form.xml.
The button only renders when byte8_seosuite/ai/is_active = 1. Otherwise the SEO fieldset looks unchanged.
What the editor sees
- Generate with AI button next to a one-line hint
- Click → button label changes to Generating… and disables itself
- Modal appears with:
- Editable Suggested Meta Title input
- Editable Suggested Meta Description textarea
- Rationale (Claude's explanation of why it picked that copy)
- Model + token usage line for cost transparency
- Insert into form writes the (possibly edited) values into the form fields and closes the modal
- Cancel discards everything
Behind the scenes
- The button HTML is rendered server-side by
Byte8\SeoSuite\Ui\DataProvider\Product\Form\Modifier\AiMetaButtonand delivered to the form as thecontentconfig of aMagento_Ui/js/form/components/htmlcontainer. The custom JS atByte8_SeoSuite/js/form/element/ai-meta-buttononly attaches behaviour (click delegation, modal, AJAX), no Knockout templates. - Triggers an authenticated POST to
/admin/byte8/metasuggestion/previewwithentity_type,id,store_id,form_key - Server calls
Byte8\SeoSuite\Model\Ai\PreviewService::preview()which:- Loads the entity from the relevant repository
- Builds the prompt via the same
PromptBuilderthe queue uses (so output format/voice is consistent) - Calls Claude with the same cached system blocks (so even single-shot previews benefit from cache if you use the button repeatedly in a session)
- Parses + enforces char limits
- Response is a JSON
{success: true, meta_title, meta_description, rationale, model, input_tokens, cached_tokens, output_tokens} - Insert writes via uiRegistry filter syntax —
registry.get('index = meta_title', cb)— rather than a hardcoded form path, so the JS works on product / category / CMS forms identically and survives Magento upgrades that re-name the form hierarchy. - Failures surface in a styled
Magento_Ui/js/modal/alertdialog with the API's reason; no native browser alerts.
Requirements
- Entity must be saved at least once (so the edit URL carries
?id=N) before the button can be used. If clicked on a brand-new unsaved entity, a Magento modal alert says "Save the entity once before generating — we need its ID." - Editor needs the
Byte8_SeoSuite::meta_suggestion_manageACL resource (the same one the queue uses).
Hyvä admin
The component is built with Magento_Ui/js/form/components/html + standard jQuery + Magento_Ui/js/modal/modal + Magento_Ui/js/modal/alert — all of which Hyvä admin themes preserve. The button works identically there.
Common workflow
Editor's normal flow with the button:
- Open product edit page
- Fill in name, price, description, images, etc.
- Save (so the product gets an ID)
- Click Generate with AI in the SEO section
- Review modal → tweak title slightly, leave description
- Insert into form
- Save again
This is faster than going through the queue when you're working on one product at a time.
Bulk vs in-context
| Scenario | Best path |
|---|---|
| New SKU just imported, want quick meta now | In-context button |
| Quarterly refresh of 500 products' meta | CLI seosuite:meta:generate → review queue |
| Hands-off ongoing | Cron auto-generate + auto-approve |
| Re-write meta for a hero product with editorial care | In-context button + manual edit |