AI in your module
Call a model through the Disrex AI packages, with a purpose of your own, in the shop's voice, inside the shop's AI limits.
Light's AI is a thin screen layer on three Disrex packages that every Light shop runs:
| Package | Module | What it gives your module |
|---|---|---|
disrex/module-ai ^1.6 | Disrex_Ai | The client (Disrex\Ai\Api\LlmClientInterface), purposes and the engine per purpose, the monthly limits, the usage table and its report, the system-prompt composer, output checks, the cost profile and price book behind the cost calculator, background jobs and their search, the fixture provider for tests |
disrex/module-ai-shop-context ^0.3 | Disrex_AiShopContext | What the merchant tells the AI about the shop: what it sells, who it is, the tone of voice, the form of address and the word rules, as prompt layers every call gets for the fixed rules, while the rules with a term go in the user turn when their term occurs in the text |
disrex/module-ai-catalog ^0.9 || ^0.10 || ^0.11 | Disrex_AiCatalog | Translation, writing, detail suggestions and filling in a new product for products, categories, CMS pages and blocks, option names, the translation log and report, with their own stock-admin screens, CLI and REST |
Light adds no @api of its own for AI: the service contracts of these packages are the API, and they work in the
stock admin, on the CLI, in cron and over REST, with or without Light. Light's Mrx_Ai only puts buttons in the Light
editors and calls those services; Mrx_Settings edits their settings on Settings > AI. Each package's README.md is
its full guide.
When to use it
- A feature that writes or reads text for the merchant: a summary of a request, a draft reply, an FAQ answer.
- Show the result for review before you save it, in the smallest surface that fits: a button on the card that needs it (Built for Light, rule 2).
- Don't call a model on a page load, a save or once per product in a loop: every call counts against the month. For
many products, use a background job (
Disrex\Ai\Api\JobTypeInterface) or Disrex_AiCatalog's runs. - Translating or writing catalog and CMS texts is already there: call
Disrex\AiCatalog\Api\FieldTranslatorInterface,EntityTranslatorInterfaceorTextWriterInterfaceinstead of writing your own prompt.
Steps
1. Declare a purpose
A purpose is one kind of call your feature makes. It is the code your requests carry, the row of the usage report and
the row of the engine table on Settings > AI, where the merchant can give your feature its own engine and level.
Declare it once in your etc/di.xml, with a label and a default level, never a model:
<type name="Disrex\Ai\Model\Purpose\PurposePool">
<arguments>
<argument name="purposes" xsi:type="array">
<item name="acme_faq" xsi:type="array">
<item name="label" xsi:type="string" translatable="true">FAQ answers</item>
<item name="default_tier" xsi:type="string">fast</item>
<item name="sort_order" xsi:type="number">100</item>
</item>
</argument>
</arguments>
</type>Require disrex/module-ai ^1.6 in your composer.json and sequence Disrex_Ai in module.xml. A purpose nobody
declared still works (it resolves to the balanced level), but it is left out of the engine table and shows as "Other
features" in the usage.
Add the size of one call to the item, so the cost calculator can price your feature before anyone uses it
(disrex/module-ai 1.5): typical_input_tokens is the prompt with the shop profile and your facts, and
typical_output_tokens the answer (a text of 150 words is about 250 tokens). Without them the purpose counts as 1,500
in and 500 out. Once the purpose has 5 successful calls of its own in a store view, the estimate uses their average
instead, so a wrong guess corrects itself.
The two keys need disrex/module-ai ^1.5 or later; an older SDK ignores them and prices the purpose at 1,500 in and 500 out.
<item name="typical_input_tokens" xsi:type="number">1200</item>
<item name="typical_output_tokens" xsi:type="number">300</item>A purpose shows in Settings > AI's engine table with its label and level as soon as it is declared, also one Light has no screen for. disrex/module-ai-mago declares mago_assistant ("Admin assistant (chat)", requires tool use, Balanced by default, store id null): Mago's chat then runs through LlmClientInterface and counts against the shop's limits. While that bridge and Mago are on, and the admin may change Mago's settings (MagoAssistant_Mago::config), the AI card also shows "Show the admin assistant", Mago's own switch mago/general/enabled, for All channels only.
A purpose can ask for what the model must be able to do with requires, which takes Capability values; a model without them is never picked for it. The admin assistant's purpose (disrex/module-ai-mago) needs tool calls, and its calls are paid for by the whole install, so they carry store id null:
<item name="mago_assistant" xsi:type="array">
<item name="label" xsi:type="string" translatable="true">Admin assistant (chat)</item>
<item name="default_tier" xsi:type="string">balanced</item>
<item name="requires" xsi:type="array">
<item name="tool_use" xsi:type="string">tool_use</item>
</item>
<item name="sort_order" xsi:type="number">900</item>
<item name="effort" xsi:type="string">medium</item>
<item name="typical_input_tokens" xsi:type="number">9000</item>
<item name="typical_output_tokens" xsi:type="number">600</item>
</item>tool_use needs disrex/module-ai ^1.10.

2. Send a request in the shop's voice
Compose the system prompt through Disrex\Ai\Api\SystemPromptComposerInterface with a PromptContext for the store
view the text is for. The composer adds every layer of the context pool: the shop profile, the tone, the form of
address and the fixed word rules of that store view (the rules without a term, and the rules with "Never write"
words). The rules with a term, such as a glossary, are not in the system prompt, which would then change with every
text and miss the provider's cache. They go in the user turn, before the data, and only when their term occurs in the
text. Wrap merchant text with PromptEscaperInterface::wrap(): it is data, never an instruction.
$context = new PromptContext(purpose: 'acme_faq', storeId: $storeId, kind: PromptContext::KIND_WRITE, targetLocale: $locale);
$response = $this->llm->complete(new CompletionRequest(
content: [new TextPart($this->escaper->wrap('page', $pageText))],
system: $this->composer->compose($context, 'You write FAQ answers for the shop.', 'At most five questions.'),
cacheSystemPrompt: true,
purpose: 'acme_faq',
storeId: $storeId
));
$findings = $this->checker->check($response->text, $context);For a write or translate call, put the rules that match the text in front of the data. WordRulesForTextInterface
(@since 0.3.0 of Disrex_AiShopContext) finds them, and builds the <word_rules> block, with <source_word_rules>
for a translation, from PromptContext::$storeId and $sourceStoreId:
$block = $this->wordRules->turnBlock($context, $pageText);
$content = array_filter([$block !== '' ? new TextPart($block) : null, new TextPart($this->escaper->wrap('page', $pageText))]);A call sends at most 60 matching rows, the longest term first. turn() returns the same text with dropped, the number
left out; say so in the result, as Disrex_AiCatalog does with its word_rules_capped warning. The never-write check
still runs on every rule. A term matches at the start of a word, in any case, so "touw" finds "touwtje" and not
"liertouw", and a term under four characters has to be a whole word. Disrex_AiCatalog's calls build the block inside
their request, so the cost sample prices it.
Always pass the store view. One install can run different shops on its websites, each with its own profile, word
rules, key and engine, and a call without a store id reads the admin's default scope. Light's translate button sends a
product or category with an id to EntityTranslatorInterface, which reads the source itself. For a CMS copy it passes
both store views (the source is TranslationConfig::sourceStoreId() of the target, the store view bulk runs read),
the item's title as context, reuse: false for "Try again", and onlyChosen, so Disrex_AiCatalog leaves out what the
language's settings don't translate and names it in the result's skipped:
$answer = $this->translator->translate(new FieldTranslationRequest(
entityType: $entity,
title: $title,
fields: $fields,
sourceStoreId: $sourceStoreId,
targetStoreId: $targetStoreId,
entityId: $entityId > 0 ? $entityId : null,
reuse: $this->scalar('reuse') !== '0',
deriveUrlKey: $this->derivesUrlKey($entity),
onlyChosen: true
));3. Write or rewrite a text, and stream it
A description, a short description or a category description is Disrex\AiCatalog\Api\TextWriterInterface: one
request, four actions (write, improve, shorter, spelling), the shop profile, the tone and the word rules of the
store view included. Nothing is loaded and nothing is saved; your screen fills the field and the merchant saves.
write() returns the whole text. stream() hands the text to a closure while the model writes, so a screen can show
it at once:
$result = $this->writer->stream($request, function (string $piece) use ($response): bool {
// The writer's first call has no text: the model is about to be asked, so "app" is final.
$this->output->open($response, $this->timing);
return $piece === '' || $this->output->write(['d' => $piece]);
});- The closure is first called with an empty string, when everything before the model call is done. Send your headers
and
Server-Timingthen, so the browser sees the time your own code took (app) and not the model's. - What streams is the model's raw text. Show it as plain text, and put only
TextResult::$textin the field: the allowlist (and the Page Builder wrapper) is applied to the finished text. Fix spelling answers at once and never calls the closure. - Return
falsefrom the closure when the browser has gone away (Cancel closes the connection): the SDK stops the call, prices what was produced, records it ascancelledand throwsDisrex\Ai\Exception\CancelledException. Say nothing more to the browser. Close the session before the first line (session_write_close()): a stream that runs for seconds would hold up every other request of the same admin. - A failure before the first line is an ordinary status code with the editor's JSON; one later is an error line.
TextRequesttakes the store view the text is for (0, an editor's default scope, reads as the default store view), the tone for this run (''is the shop's own tone), the merchant's wishes for this one text andreuse: falsefor "Try again". Light's product editor shows the actions as the AI menu on the description and the short description, and the wishes and the tone in a window that opens on the first click.
The search listing and a text from a photo are SearchListingWriterInterface::write() and
ImageCopyWriterInterface::fromImage(). They answer whole; Light's routes light/ai/seo and light/ai/fromimage
pass their findings on the same way. A photo must be one of the product's own, or an upload in the media tmp folder,
and the engine chosen for the feature must see photos: ask PurposeModelResolverInterface::resolveFor() with the
purpose (Purposes::FROM_IMAGE) before you show a button, as Light does.
4. Show the findings
The output checks run after every answer. The word rules' check returns an OutputFinding when the answer holds a word
the merchant said never to write (it found "kanker" in a text about the star sign Cancer, say). A finding is a
warning: the answer is never blocked or rewritten. A background translation run is the one place that acts on it: an
item whose text holds an avoided word waits in To check even when the run has review off, because the model was told
the replacement and what slips through is an inflected form or a wrong ending that a person should see. Fill the field, show the warning, and offer "Try again", which asks
the model anew instead of returning the kept answer. Light's editors show it as a toast with that action, and on a
description as a line in the note under the field, next to Undo.
5. Add a prompt layer, if your module knows something the AI should
A module that holds context of its own (a B2B module: "prices exclude VAT") adds a layer to the pool instead of
changing a prompt. Implement Disrex\Ai\Api\PromptContextProviderInterface and register it:
<type name="Disrex\Ai\Model\Prompt\ContextProviderPool">
<arguments>
<argument name="promptContextProviders" xsi:type="array">
<item name="acme_b2b_prices" xsi:type="array">
<item name="provider" xsi:type="object">Acme\B2b\Model\Ai\PricesLayer</item>
<item name="sortOrder" xsi:type="number">350</item>
<item name="kinds" xsi:type="array">
<item name="write" xsi:type="string">write</item>
</item>
</item>
</argument>
</arguments>
</type>The layer reads cached config only, for the store view of the context, and its getCacheKeyPart() holds that store id
and every value it read: the composed prompt is cached per store view, so a layer that leaves something out of its key
sends one shop's text to another.
A line the merchant fills in. When what the AI should know is something the merchant writes ("Ordered before
22:00, delivered tomorrow"), add a field to the shop profile instead of a layer. One di.xml item in the
profileFields pool of Disrex_AiShopContext, and no template, system.xml or layer of your own:
<type name="Disrex\AiShopContext\Model\ProfileFields">
<arguments>
<argument name="fields" xsi:type="array">
<item name="delivery_promise" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Delivery promise</item>
<item name="comment" xsi:type="string" translate="true">What customers can count on.</item>
<item name="maxLength" xsi:type="number">200</item>
<item name="type" xsi:type="string">text</item>
<item name="sortOrder" xsi:type="number">60</item>
</item>
</argument>
</arguments>
</type>"Delivery promise","Leverbelofte"
"What customers can count on.","Waar klanten op kunnen rekenen."Prop
Type
What you get:
- Settings > AI shows the field in About your shop, after "In your own words", with "Use the all-channels
value" in a channel. A save posts it as
profile_<code>and writesdisrex_ai/shop_profile/<code>for All channels or the channel (the website scope); an emptied field deletes its row there, so the channel follows All channels again. - Stores > Configuration > Disrex > AI > Shop profile shows it at default, website and store view, by
sortOrder. - Every AI call that gets the shop profile (write, translate, extract) gets the field inside
<shop_profile>as<delivery_promise>...</delivery_promise>, for the store view of the call, escaped like the merchant's other text. The layer's cache key holds the value, so two websites never share it. Read it yourself withShopProfileInterface::get($storeId)->extra['delivery_promise']. bin/magento disrex:ai:profile:show --store=<code>lists it with where its value comes from.- "Write a draft with AI" leaves it alone: the draft writes the built-in texts only.
A code that breaks the rules throws a \LogicException naming the field, on the first page or call that reads the
pool. After you add or change a field, clean the config cache (bin/magento cache:clean config): Magento reads the pool
through its cached di.xml.
A module that keeps its own setting for something the shop context reads replaces that source by preference. Light keeps one je/u setting per language, so the AI follows it:
<preference for="Disrex\AiShopContext\Api\FormOfAddressSourceInterface"
type="Mrx\Ai\Model\ShopContext\LightFormOfAddress"/>6. Handle the limits
Disrex_Ai checks the monthly call and spend limits before every call, so a reached limit costs nothing, and throws
Disrex\Ai\Exception\BudgetExceededException. Catch Disrex\Ai\Exception\AiException, which covers it, and say where
the merchant raises the limit (Settings > AI). Light's own screens end such a message with a "Set up AI" link to
light/settings/ai only for an admin who may open it (Magento_Config::config and Disrex_Ai::config), and tell any
other admin "Ask the shop owner to check Settings > AI."; do the same, so nobody gets a link to a page they can't open.
On a shop with several channels a failure about the key, the AI quality or the switch opens the channel of the store
view the call was for (light/settings/ai/channel/<id>), because a channel can hold its own; the monthly limit is the
shop's, so its link opens All channels.
Light counts the limits the way Settings > AI says: the calendar month, for the whole shop. Mrx_Ai sets that once with
a data patch:
public const VALUES = [
LimitsInterface::PATH_WINDOW => LimitsInterface::WINDOW_CALENDAR_MONTH,
LimitsInterface::PATH_SCOPE => LimitsInterface::SCOPE_SHOP,
];The request limit counts the answers, refusals and stopped requests; a request that ended in an error is not counted.
7. Translate many products in the background
One product is FieldTranslatorInterface. Many are a run: Disrex\AiCatalog\Api\TranslationJobInterface plans it
(estimate(), the dry run: aggregate queries, no paid call, no write) and starts it (start()), and Disrex_Ai's worker
translates outside any web request, one job per target language with its own cursor, progress and revert. Light's
bulk translation screen is a form on those two calls:
return new Plan(
new TranslationJobRequest(
entityType: $entity,
storeIds: $stores,
fields: $fields,
selection: $selection,
categoryId: $selection === 'category' ? $category : null,
entityIds: $ids,
updateOutdated: $this->flag($request, 'update_outdated'),
replaceUntracked: $this->flag($request, 'replace_untracked'),
altTexts: $products && $this->flag($request, 'alt_texts'),
urlKey: $products ? $this->optionalFlag($request, 'url_key') : false,
budgetUsd: $this->budget($request),
sourceStoreId: $channel['source']['id'],
quality: $quality,
review: $this->review($request, $stores),
fillMissing: $this->optionalFlag($request, 'fill_missing')
),- Send every option explicitly. A request that leaves one
nullreads it from each store view's own setting, which the screen did not show; the merchant gets what was ticked. "Also replace translations not made by AI" is off unless ticked. Three options are the exception, becausenullmeans something there:url_keyis absent unless the merchant picks a choice under More options, so Disrex follows each store view's setting, which the screen shows (below);fill_missingis absent (null) from the bulk screen's own runs and0or1only from a Translations drill-down; andreviewis only evertrueor absent. - The same screen translates categories (
entity=category, from the categories list's bulk actionai_translate): the title, the field list and the counts follow the entity, a category has no alt texts and no web address line, and "products in one category" is left out. - Review. A language whose settings say "I check AI translations first myself" (Settings > AI, the card "Which texts does AI translate?"), or a run
started with "Let me check this run first", writes nothing to the shop: every translation waits in the review tab until
the merchant approves it. Light posts
review[<store view>], whichPlanFactorymaps toTranslationJobRequest::$review; a request can add review but never remove it. - The screen is for one channel (spec 15a): the source is that channel's default language (
sourceStoreId), the targets are its other languages. A language without AI, or with the language of its source, is listed with the reason and cannot be ticked. selectionisids,category(withcategoryId: the category's products, frozen by the catalog module when the run starts),enabledorall. The Translations drill-down usesenabledandallwith no id list, and then the screen is pinned: it shows only the fields of the list it came from and posts thereplace_untracked,alt_textsandurl_keyvalues thatTranslationReportInterface::runSelection()gave, so its dry run and its run cover the list and nothing the store view's settings would add. The ids are frozen when the run starts, so products added later are not swept in. Post a long list as one comma separated value: PHP drops form lists pastmax_input_vars.- Which product details to tick. A shop can have hundreds of per-language text details, and ticking every one the
resolver offers makes a run (and its dry run) translate details the products don't even fill. Ask
Disrex\AiCatalog\Api\DetailUsageInterface::withText($entityType, $selection, $categoryId, $entityIds, $sourceStoreId)which details the selection holds text in (the most filled first; one cached statement over the newest 500 products of the selection). Light ticks those of the resolver's defaults, 60 at most, shows a longer list behind "Show all" with a search, and says in the dry run and on the run page which filled details ticked by default the run leaves out (Mrx\Ai\Model\Bulk\DetailDefaults). A detail the resolver offers unticked, such as the image label attributes (Image Label, Small Image Label, Thumbnail Label), is never named there. Post the fields as one comma separated value too (Light'sfieldlist). - The budget is in US dollars for Disrex_Ai; Light shows and takes the shop's currency (
Mrx\Ai\Model\Money, the conversion Settings > AI uses) and converts once, inPlanFactory.start()refuses a budget of 0, which Disrex_Ai would read as no cap at all.
Start answers with the run and Light remembers it for the top bar chip:
$plan = $this->plans->fromRequest($this->getRequest());
$run = $this->jobs->start($plan->request);
$this->cookie->set($run->id);Watch and steer the run with Disrex_Ai's JobManagementInterface. progress($runId) reads the counters on the job
rows, so a poll is one small query; Light polls every 4 seconds, and only while the tab is visible. The buttons follow
the state of each language, and a run only ever steers translation jobs (Mrx\Ai\Model\Bulk\Runs):
$actions = [
RunPresenter::ACTION_PAUSE => $this->jobs->pause(...),
RunPresenter::ACTION_RESUME => $this->jobs->resume(...),
RunPresenter::ACTION_CANCEL => $this->jobs->cancel(...),
RunPresenter::ACTION_REVERT => $this->jobs->revert(...),
];- Pause and Cancel stop the job after the batch that is running; Resume continues from its cursor. A job
paused on its budget resumes only when the budget allows another call, so the run page offers Raise budget
(
setRunBudget()) next to it. - Revert gives back the previous text of every field the job wrote, but only where the field still holds what the job wrote: a text the merchant edited since stays. A revert does not clear the "Skip translation" flag that Mage-OS's automatic translation reads: the products and store view the run wrote stay flagged. To translate them again, untick "Skip translation" on the product in that store view.
- A run never overwrites the merchant: it fills a store view's field only when that field inherits the default. "Also update AI translations whose source changed" refreshes only texts AI wrote; "Also replace translations not made by AI" is the one switch that replaces a text that was there before AI was used.
- The worker is Disrex_Ai's cron group
disrex_ai_jobs, orbin/magento disrex:ai:jobs:workwhen the host keeps a consumer alive. In a test,bin/magento disrex:ai:jobs:run --seconds=30runs one tick now. - The list's bulk action is a table extension (
Mrx\Light\Api\IndexTable\ProviderExtensionInterface) on theproductslist, withmodedownload: Light's table posts the tickedids[]and the list they came from (list[tab],list[q],list[channel],list[filter][key],list[total],list[total_capped],list[total_known]), so the screen offers "All N in this list" and askslight/products/matchingidsfor their ids on that choice only. The list page loads no AI script. Copy it to put your own AI action on a list. The top bar chip needs no slot: while this browser follows a run the page carries a small script, otherwise nothing. - Run lists (the Translations page's "Runs" tab and the Home line) read through
JobSearchInterface(search()andcount()), never throughJobManagementInterface::list(): one statement per page, one row per language of a run. - The run page's log is
JobManagementInterface::items(), a page of 50 at a time for one language, read when the merchant opens it (light/ai/runitems), never by the poll. Light words each outcome itself (translated, skipped and why, failed, a word the word rules avoid) and links the product in that language. - When a run finishes, pauses on its budget or the monthly limit, or fails, Light adds a notice to the admin's
notifications (Light's bell, Magento's inbox) that links the run page, from an observer on Disrex_Ai's
disrex_ai_job_finished,disrex_ai_job_pausedanddisrex_ai_job_failed; for a translation run it sets the transport'snotifyto false, so Disrex_Ai's own notice doesn't come too. Observe those events the same way to tell your own users, or to sync a finished run to a PIM.
8. Suggest values for the empty details
Disrex\AiCatalog\Api\DetailSuggestionInterface::suggest() takes what the editor form holds (the attribute set, the
product type, the codes of the empty details, the title, the texts, the categories and the filled details as
label: value) and answers a value per detail it could fill, never from a saved product, so unsaved text counts and a
new product works. The service reads the set's details, their labels and their options itself; nothing the browser says
about them is trusted. Light's route ranks the empty codes the way the service picks them (filterable, required, then
the template's order), cuts them to what one call can use, and passes the form's facts on:
$result = $this->suggester->suggest(new DetailSuggestionRequest(
attributeSetId: $setId,
typeId: $typeId,
emptyCodes: array_slice($codes, 0, self::MAX_CODES),- Each
DetailSuggestioncarriesvalues(option ids for a dropdown,"1"for a yes/no, a number, a text),displayValuesfor the merchant, acertainty(sureorlikely) andevidencefor "Why?".missinglists facts no detail of the set can hold; the AI never creates an attribute or an option. - The suggestions are for the default values, so the card has no Suggest button in a language view.
- The review is the script
Mrx_Catalog/js/product-details-ai, loaded on the first click. It fills a field only if it is still empty when Use is pressed, dispatchesinputandchangeso the save bar sees it, and saves nothing. - Findings from the word rules are a warning in the banner; they never block a suggestion.
9. Add to the AI screens, and react to what the AI fills in
Light's AI screens have named slots and events, so a module adds a button, a card or a field and reacts to a fill without editing Light:
Prop
Type
Light dispatches the first one on the field and reads detail.text back, so a listener on the document (a RequireJS
module your layout loads on the editor) can change the text or call preventDefault():
if (!field.input.dispatchEvent(new CustomEvent('mrx:ai:result', {bubbles: true, cancelable: true, detail: detail}))) {
return false;
}
value = typeof detail.text === 'string' ? detail.text : value;The first two events fire for the product editor's AI menu, the search listing and Fill in from photo (field is the form field,
or image_label for the main photo's alt text), for "Translate from" in the product, category, CMS page and block
editors, and for Write a draft with AI on Settings > AI (action draft, entity shop_profile, field the form
field what_we_sell, about or tone, store the channel on screen; a draft that waits under a filled field is
announced when the merchant presses Use this). They fire too for each field "Fill in with AI" puts into a new product
(action draft, entity product), for an option name filled from the Product options page (entity
attribute_option), and for a translation approved in the review tab (action review). Like mrx:product-saved, they
are contract (Events); the slots are in the extension targets.
10. Show your feature in the cost calculator
Settings > AI has a Cost calculator card: the merchant enters a number of products, presses Work it out, ticks
the jobs and sees the cost per product and in total on the model each feature runs on now. A model, level or engine the
merchant is still choosing shows its price before anything is saved, and each row has a model select of its own. The
numbers come from Disrex_Ai's CostProfileInterface (forPurposes(), one call for all rows done by hand) and, for the
translation row, from CatalogCostEstimateInterface::translatePerProduct(), the code the bulk dry run uses, so the
calculator and a dry run over every product agree. The page renders the closed rows and makes no request and no
query; light/settings/aicalculator supplies the figures once, on the press, and the browser multiplies.
A job is an item of the pool ai_calculator_jobs (Mrx\Settings\Model\Ai\Calculator, argument jobs, adminhtml).
Add one for your purpose:
<type name="Mrx\Settings\Model\Ai\Calculator">
<arguments>
<argument name="jobs" xsi:type="array">
<item name="acme_faq" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Write FAQ answers</item>
<item name="purpose" xsi:type="string">acme_faq</item>
<item name="sort_order" xsi:type="number">60</item>
<item name="module" xsi:type="string">Acme_Faq</item>
</item>
</argument>
</arguments>
</type>| Key | Meaning |
|---|---|
label | The row's name, in the merchant's words. |
purpose | A purpose declared to Disrex_Ai. A job whose purpose nobody declared, or that resolves to no model, is left out. |
per_language | true for a job that runs once per language, such as translating: the card prices it for the channel's target languages, never for its default language. Default false. |
sort_order | Position in the list. Light's own are 5 to 60. |
module | The module the item needs; the row is left out while it is off. |
unit | What the row counts: product (default) or option_call. |
counter | An object that implements Mrx\Settings\Model\Ai\UnitCounterInterface (count(int $websiteId): int, @api since 0.7.0). Light multiplies; your module counts. Register it as a \Proxy. Without a counter a row with unit option_call says "Not counted yet". |
bulk | true for a row that is a background run (the translation row): its calls follow each other, so it costs first + (n - 1) * next. Every other row is an editor click, minutes after the last, and costs first per product. |
Each row of the answer has, per model, basis ("Based on your own use (12 times)", "Counted with 10 of your own
products" or "Estimate: between 0,004 and 0,009"), sampleSize, first, next, low, high and a breakdown
that "Where does this amount come from?" opens. Measure with your own products (light/settings/aicostsample,
which needs Disrex_Ai::cost_manage) asks CostSamplingInterface to send one real call per purpose, for every target
language of the channel, because the target's word rules and form of address are part of the prompt. That is the one
button of the card that spends money, and it says so. The footer names where the prices come from and when they were last
checked.
Light's rows are Write descriptions, Write short descriptions, Write search listings, Suggest product
details, Fill in from a photo, Fill in new products, Translate products (the bulk path, purpose
ai_catalog_translate_job) and Translate product options (unit option_call, counted by Mrx_Ai's pass-through
OptionLabelEstimate, which asks Disrex_AiCatalog's dry run for the number of calls and counts nothing itself). Amounts
show in the shop's currency; below one cent they get two significant digits and at most five decimals.
11. Fill in a new product
On a new product the editor offers the card Let AI fill in your product (not on a new bundle or group page, which are made of other products): a photo, a few words, the language to write in (shown only when the ticked channels write in different languages),
the languages to translate into after the save, and one button. light/ai/productdraft streams the answer from ProductDrafterInterface::stream() (progress lines
as it reaches each field, then one done line with every value by its key), and product-draft.js puts it into the
form. Nothing is saved: the merchant checks and presses Save, and the draft only fills fields that are still empty.
Price, stock, SKU, weight and tax are never filled. A sure detail goes into its field, an unsure one waits as a chip
("Check this"), a category is a suggestion with Add and Not needed, and Undo all takes every fill back.
Light's route has the same rule as the other streaming routes: it closes the session, checks connection_aborted() and
treats CancelledException as "nothing more to say".
Before the click the card shows what the fill and the translations will cost, from light/ai/draftcost (GET, with source, stores[] and fill). That is one call to Disrex_AiCatalog's NewProductEstimateInterface::estimate(): Light only formats and adds up Disrex's numbers. The translation part and the limit line need Mrx_Ai::bulk_translate; without it the card shows the fill only.
A module adds a text of its own to the draft in two steps. First Disrex_AiCatalog's draftFields pool names the field,
so the model writes it (kind, max and rule say how); then Light's pool ai_draft_inputs (adminhtml) says which
input of a form-extension card receives it:
<type name="Disrex\AiCatalog\Model\Draft\DraftFieldPool">
<arguments>
<argument name="draftFields" xsi:type="array">
<item name="acme_kit_note" xsi:type="array">
<item name="label" xsi:type="string" translatable="true">Note</item>
<item name="kind" xsi:type="string">line</item>
<item name="max" xsi:type="number">80</item>
<item name="rule" xsi:type="string">A short note about the product, at most {{max}} characters.</item>
<item name="sortOrder" xsi:type="number">900</item>
</item>
</argument>
</arguments>
</type>
<type name="Mrx\Ai\Model\DraftInputs">
<arguments>
<argument name="inputs" xsi:type="array">
<item name="acme_kit_note" xsi:type="array">
<item name="draft_key" xsi:type="string">acme_kit_note</item>
<item name="extension" xsi:type="string">acme_kit_note</item>
<item name="field" xsi:type="string">note</item>
</item>
</argument>
</arguments>
</type>Key of an ai_draft_inputs item | Meaning |
|---|---|
draft_key | The draftFields key the model fills. Lowercase letters, digits and _, starting with a letter. |
extension and field | The form-extension card and its field: the input is ext[<extension>][<field>] (Fields on a Light editor). |
form | The editor. Only product (the default) has a draft. |
module | The module the item needs; the input is left out while it is off. |
Put the draftFields item in the global etc/di.xml: Magento replaces an argument array that an area file names again,
so an adminhtml item would leave Disrex's own fields out of the pool and every draft would answer "This field can't be
filled in with AI." The ai_draft_inputs item belongs in etc/adminhtml/di.xml, the area of Light's pool. A key the
pool doesn't hold is refused with a 422 before anything is sent, and the codes the drafter never writes (price, SKU and
the like) are no pool keys, so a module cannot add them.
A module that draws its own field, with no form-extension card, uses the two events of step 9. It pushes its
draftFields key into params.empty_fields when mrx:ai:draft-request fires, then reads values[<key>] from
mrx:ai:drafted, fills its field and calls claim(key, undo), so the note under the card counts it and Undo all
calls its undo. The claim stays through a later fill, which only writes the fields that are still empty, so Undo all
and Try again put back every fill. A field that offers its own Undo calls release(key) from it, so the key leaves the record and a text
the merchant writes next is never logged as the AI's. Another AI action on a claimed field (Write new, Improve, Shorter, Fix spelling, search listing, Fill in from photo) releases its claim, so the receipt no longer lists a text the merchant changed afterwards. form-hooks.js itself is unchanged: the contract is the two events and the pool. A module that
adds a button next to the fields uses the slot mrx.ai.draft.fields.
The save records what the AI filled in. The next save after a draft posts ext[ai_draft][receipt] (Disrex's signed
record of the draft) and ext[ai_draft][fields][] (the keys still filled by the AI; "Undo all" leaves none, and Undo on a field's note takes that key out), plus the receipt and keys of each earlier fill when the merchant filled in twice, and Light
hands the texts the saved product holds to Disrex_AiCatalog's ProductDraftLogInterface. They show in Products >
Translate > Log as "Filled in by AI", edited where the merchant changed the text, and can't be reverted from there. The
saved text is read on the server: a pool item's attribute on the product, or, for an ai_draft_inputs key, the
value your card posted as ext[<extension>][<field>] (Light can't read back what your extension stored, so a value
your save() cleans is logged as posted), so your field is recorded with no code of yours. A key you only
fill through mrx:ai:drafted is recorded when its draftFields item's key is a product attribute. ext[ai_draft] is
Light's own namespace: don't post it.
The save starts the translation. When the card was used, the save of the new product also posts ext[ai_translate]: source, the store view the texts are in, and stores[]. Once the product is committed and reindexed, Light keeps the posted store views that are languages of the product's channels (not a channel's main language, not the texts' own language, not one without AI) and starts one background run with TranslationJobInterface::submit($request, false): selection ids, the pinned sourceStoreId, and every other option null, so each language follows its own settings and the run takes the dry run's default budget. It needs Mrx_Ai::bulk_translate as well as Magento_Catalog::products, runs only on the save that created the product, and never fails the save. The save answer carries ext.ai_translate: {run, stores, refused, dropped, waitsForReview}, or {run: null} with skipped or error; refused holds Disrex's reasons (JobSubmission::$refused, disrex/module-ai-catalog 0.5.0). ext[ai_translate] is Light's own namespace too: don't post it.
The edit band. After that save, the product edit page shows a band above the cards. It reads the ext.ai_translate answer from the tab's sessionStorage (mrx-ai-translate-<product id>) and polls light/ai/runstatus while a run is open: queued, running, done, the languages that wait for a check (with a link per language), what was left out and why, and a start that failed, with Translate now. A tab without that answer (the product reopened from the list, or in another tab) makes one request to light/ai/productrun, which finds the product's newest run of the last 24 hours in Disrex_AiCatalog's translation log (TranslationLogInterface::search() with a LogQuery for the product and origin bulk) and answers it as runstatus does. The log holds a run's rows once a language finished, so a run that is still queued shows only in the tab that saved. Undo the translations reverts the run through light/ai/runaction; a run that also translated other products (one started from the products list) shows no Undo, because its revert would put those back too. See what AI wrote opens the product's History, and each finished language gets See <language>, which opens the product in that language, next to a quiet line that points to the Language switch at the top. That switch says under each language Translated by AI, Own text or Not translated: Mrx_Ai's ViewModel\LanguageStatus makes one call to Disrex_AiCatalog's EntityCoverageInterface::forEntity('product', $id) with no store list, one statement for every store view the translation report counts, and words the status Disrex decided (EntityCoverage::STATUS_AI when any text is AI's, current or outdated; else STATUS_OWN when any is the merchant's own, an AI text the merchant changed included; else STATUS_MISSING). It reads nothing for a new product, and a store view the answer leaves out (no coverage yet, or counted for another field selection) shows no status. The coverage follows the report's indexer (cron, within a minute), so a text just saved shows its old status until the view has caught up. In a language view the banner says when AI translated it (Translated by AI on <date>, with the History of that product and language) or that its translation is still running, and the Translate from buttons wait for it. A translation that is paused (on the run's budget, on the monthly limit or by hand) is not running: the banner says so, with Open the run for an admin who may open products, and the buttons stay, since a pause can last days. Closing the band keeps that run closed in the tab. The band writes no Disrex data, reads it only through Disrex's @api, and extensions add nothing to it.
Translate into all languages. On an existing product's default values, an admin with Mrx_Ai::bulk_translate also gets a quiet line under the band: Translate into all languages, with "AI translates the texts that are missing or out of date in each language. Texts you wrote yourself stay as they are." It shows once the band's lookup answered and while no run of the product is queued, running, paused or being undone (closing the band hides its notice, not this line, and the band goes on polling a busy run so the line comes back when it ends), and the page asks nothing for it: ViewModel\ProductBand offers it from configuration (translateAll). The click opens a panel in the band that posts light/ai/productrunestimate once with the product's id. The server works out the languages from the channels saved on the product, and Disrex's dry run prices them: each language with something to translate as "Deutsch: about €0.02", the total, the limit line, and the languages left out with their reason. Start translating posts light/ai/productrunstart, which answers what a new product's save answers (or, while a translation job of the product is still queued, running, paused or being undone, busy with a message the panel shows instead of Start); the band keeps it under the same sessionStorage key and follows that run from queued to done, with See <language> and Undo the translations. When every language is up to date the panel says so and offers no Start. Each language translates from its own source, updates outdated AI translations, fills missing texts and keeps the merchant's own (ProductRunRequest::forExisting()).
12. Translatable texts, alt texts and option names
One product or category is EntityTranslatorInterface, which reads the source, the target's texts and the settings
itself; Light posts the codes the editor holds and nothing else. What it translates follows the language's settings
(Settings > AI > "Which texts does AI translate?") and Disrex_AiCatalog names what it left out in the result's skipped
(not_chosen or never), which Light's toast turns into "Not translated (your settings): ..." and "Never translated:
barcode (gtin)". Light filters no field itself. Four things changed in 0.7.0:
- Alt texts are fields
image_label:<value_id>. The editor's language view has an alt-text card with one row per image; "Translate from" fills them, and the save writes them throughDisrex\AiCatalog\Api\WritableEntityAdapterInterface::writeStoreValues()in the save's own transaction. The gallery table has no unique key, so one writer owns it: a module that writes a store view's alt texts calls that interface too. A value ofnullmeans "use the default". - Details with one value for all languages and codes that are never translated (barcode, SKU) are skipped by name. Details a merchant adds later are translated when the setting "Also details I add later" is on.
- URL keys. The product URL key is Disrex's: translated from the translated name, free in the target store view, and
formatted by
UrlKeyFormatInterface. The old address keeps working with a 301 once the finish job has run, and a revert of a name brings the old address back the same way. A category's key, which Disrex leaves alone, is formatted from the translated name when the editor postsurl_key=1. - The source is the one bulk runs use:
TranslationConfig::sourceStoreId()of the target, which is its own "Source store view" setting, else its website's default store view. When that is not the install's default store view the toast names it ("Translated from Outlet NL"), and so do the button and the confirmation. "Use default" still shows the default text: that is what the language shows on the storefront. When the source store view has its own text for a field, the product editor's language view adds a line under the field ("Source (Nederlands · Outlet): ...", only where the buttons show; the title, descriptions, SEO texts, alt texts and text details) and puts that text indata-source-value, whichtranslate.jsreads as the source. A category's language panel prints the same line under its title, description, SEO title and meta description, and the category editor's script reads the source store view's own field,store[<id>][<code>], wherever it sits on the form. A field withoutdata-source-valuehas the default text as its source.
Option names (the label of a swatch or a dropdown value, and the attribute's own name) are
OptionLabelTranslatorInterface for one form and OptionLabelJobInterface for a run (estimate() is the dry run,
start() the run, purpose ai_catalog_option_labels). Light's routes light/ai/optionlabels,
light/ai/optionlabelsestimate and light/ai/optionlabelsstart need the attribute permission in place of the product
permission, and starting a run needs Mrx_Ai::bulk_translate as well. Select and multiselect attributes are both on
Products > Product options (a multiselect row is marked "Multiple choice" and has no variant settings). A name that equals
another option's comes back as held: it is never filled and the form says "Check this". The page carries no script of
this module until the merchant clicks "Translate missing names".
13. The Translations page: report, review and log
Disrex_AiCatalog keeps three records and Light shows them on one page, light/ai/translations, in the navigation under
Products as Translations (only where a channel has a language to translate into):
| Tab | What it shows | Source |
|---|---|---|
| Overview | Per channel language and per type (products, categories, pages, blocks, option names, attribute names): translated, not yet translated, outdated, translated by AI, changed by you, your own text, to check. A number opens the list behind it. | TranslationReportInterface |
| To check | The translations that wait for approval, source and translation side by side, with the words the word rules flagged, and the items a translation run held for a never-write word, also in runs without review. Edit and approve, Reject and Approve per row, Approve all N and Reject all N for the list, and the lists' own pager (page numbers, First and Last). | TranslationReviewInterface |
| Log | Every translation, whoever made it (editor, bulk run, option run, REST, CLI), with the text before and after and Revert for the text from before. | TranslationLogInterface |
| Runs | The runs of the last weeks with their state, cost against estimate and the number of translations to check. | JobSearchInterface |
Rules for anything you build on these screens:
- Light counts and decides nothing. Totals, the selection a list stands for and what a revert or an approval may touch
are Disrex's; Light words the result. Run lists read through
JobSearchInterface(search()and one cappedcount()), one statement per page. - History for one product.
light/ai/translations?tab=log&entity=product&id=<id>narrows the log to that product throughLogQuery::$entityTypeand$entityId(Disrex filters; Light filters nothing), and shows a chip "This product: %1" that takes the filter off. Onlyproductis accepted, and only for an admin who may open products; any other type, or an id that isn't digits above 0, is ignored. The product editor's "See what AI wrote" link opens it. - A drill-down posts a selection, not ids. "Translate the selected" posts the ticked ids; "Translate everything in this list (N)"
posts
runSelection()'s selection mode with its pins to the bulk screen (step 7), so the dry run and the run cover the list and nothing else. From the "Outdated" list the run translates only the outdated fields, not every field that is missing in the store view. Option and attribute-name rows start the option run instead; page and block rows only open the editor. - Review. With I check AI translations first myself on for a language, a background translation (a bulk run, or the run for a new product) writes nothing live:
each translation waits in the log until it is approved (
review_bulk, andoption_labels/reviewfor option names). Editor translations never wait, because the merchant already sees and saves them. "Automatic translations" means every translation that goes live without the merchant's own click in an editor: bulk runs, option runs and any later automatic path. Such a path must start acatalog_translateorcatalog_option_labelsjob to follow the review switch and the log. The existing compatibility note shows where Mage-OS automatic translation is on: it writes outside Disrex's code, so those texts are not logged or reviewed and the report counts them as "Your own text". - A name that equals another option's waits with a note that the name is already used by another option, and offers only Edit and approve and Reject. Approving a page or Approve all leaves it waiting and says how many it left.
- Rights. Seeing the report and the log needs
Mrx_Ai::translations_view, which every product editor holds (the Staff preset included); approving, rejecting, reverting and starting a run needMrx_Ai::bulk_translate, which Staff doesn't hold. A decision is checked against the editor's permission for the type of each item. Approve all N on a list without a kind of text decides the rows that admin sees: every type for an admin who may open every editor, else the types they may open (ReviewQuery::$entityTypes, which Disrex_AiCatalog keeps in thecatalog_review_applyjob asentity_types). Pausing, resuming or stopping that decision needs the right for every type it covers, so a products editor can't steer a CMS editor's decision. - A list that is counting again. After the merchant changes what is translated, the overview says "The overview is being recounted." and shows no numbers and no run buttons until the recount job is done.
- Coverage sources. A type shows up in the overview without a template edit: implement
Disrex\AiCatalog\Api\CoverageSourceInterface, add it to thecoverageSourcespool ofModel\Coverage\CoverageSourcePool, and give it its own view in youretc/mview.xmland its own indexer inetc/indexer.xml. The indexers run on "Update by schedule": the overview follows a saved text within a couple of minutes, and on "Update on save" it only follows the nightly recount, which the page says. See the Disrex_AiCatalog README ("A type in the translation report") for the interface. Light shows the type's rows fromdescribe(); an unknown type shows only its id, and cannot be searched.
How a call runs
What the admin sees
On Mage-OS 4.0 with disrex/module-ai-mago, the engine table has the row Admin assistant (chat), and Settings > AI has the switch Show the admin assistant (mago/general/enabled, All channels only). Mago's own Statistics page stays and counts tokens; the money is in the usage report.

-
Simple mode. Settings > AI shows, per channel: the switch Use AI to write and translate and the quality ("Fast" lets every feature use its own default level, "Best quality" the powerful one for all), About your shop (what you sell, about your company, the tone of voice, in your own words, and how customers are addressed per language), Word rules (language, word or meaning, write it as, never write; up to 500 rules and 48 KB per list, with the count per language, a language filter, a search box, Import a CSV file and Download as CSV), the Engines per feature (shop-wide, read-only in a channel; the model under each row follows its engine, its level and the quality before they are saved) and this month's requests and spend per feature, with your purpose's label. The privacy line says the profile is sent with every AI request. While the profile of a store view is empty, the AI windows say "The AI writes better when it knows your shop."


-
Word rules per channel. The list of a channel adds to the list of All channels: a rule of the channel wins for the same language and word, and the rules of All channels show read-only and collapsed under the channel's own. Tick Only this channel's rules and the channel uses its own list alone (
disrex_ai/word_rules/inheritisreplaceat its website; Use the word rules of All channels removes the list and the setting). The rows are posted as one field,word_rules[json], so 500 rules stay far below PHP'smax_input_vars. -
Import and export word rules. Import a CSV file opens a dialog with the file (at most 512 KB), the language, what the two columns mean ("Word ; Write it as" or "Never write ; Write it as") and what to do (add and update, replace the rules of the language, or remove the words in the file). Check the file runs the dry run of
WordRulesImportInterfaceand shows what would be added, changed, unchanged and removed, with the problems per line; Import N rules then sends the same file again and writes the whole list or nothing. A file that holds two different values for one word is refused. The routes arelight/settings/aiwordrulesimport(POST,check=1is the dry run; the file is the fieldfile) andlight/settings/aiwordrulesexport(POST, answerscsvandfilename), both behindDisrex_Ai::config, and part of the Light contract. Download as CSV is the file the import reads back, UTF-8 with a byte-order mark and;. The same service runs on the CLI asdisrex:ai:word-rules:importanddisrex:ai:word-rules:export.
-
Write a draft with AI. On the About your shop card, Write a draft with AI (
light/settings/aiprofiledraft, on Disrex_AiShopContext'sProfileDrafterInterface) writes "What do you sell?", "About your company" and the tone from the shop's own name, categories, products, prices and product details, for the channel on screen. It shows only while AI is set up and on. An empty field is filled at once; a field that already has text keeps it, with the draft under it and Use this and Keep mine; the tone changes only while it is on the default. Each filled field has the note "Filled in by AI. Check it before you save." with Undo, and a line says what the AI read ("Based on: shop name, 20 categories, 30 product names"). Every fill is announced withmrx:ai:resultandmrx:ai:applied(step 9). Nothing is saved before Save. A module adds what the AI reads about the shop through the facts pool of Disrex_AiShopContext (its README, "Extending"), not through Light.
-
Cost calculator. A card after "This month": the number of products (the channel's own count) and of languages to translate into (the channel's languages whose language differs from its default), one row per job with its cost per product and in total, "Based on your use" or "Based on averages", and, when a monthly limit is set, whether the total fits what is left of it. Amounts show in the shop's currency; below one cent they read "less than". The page renders the card closed; the numbers load once, from
light/settings/aiCalculator, when it is first opened, and a channel is priced over the calls of all its languages.
-
Advanced mode. Stores > Configuration > Disrex > AI holds the same settings, per website and store view, and
Disrex AI catalogthe catalog features' own. -
The product editor. The description and the short description each have an AI menu: Write new, Improve, Shorter and Fix spelling and grammar, and on the description also Longer (up to 800 words; it is Disrex_AiCatalog's action
longer, from 0.8.0). Everything but Write new shows only when the field has text, and Improve, Longer and Shorter are off for a description with images or a short description with HTML codes. Write new, Improve, Longer and Shorter open a window with the tone (the shop's own first, then every preset) and extra wishes, and the text appears in it as the model writes; Cancel stops it. The text fills the field with a note: "Filled in by AI", Undo, and, when the answer holds a word the word rules avoid, the word and Try again. Nothing is saved before Save.

-
Product details. With empty details and AI set up, the card has Suggest with AI. One request, then a banner ("AI suggests 4 details. Use the sure ones. Dismiss") and under each empty detail a chip with the value, Use, Dismiss, Why? and, for a guess, Check this. A fact the template has no detail for is a line with a link to the advanced view. Filled details are never touched; nothing is saved before Save. A saved product has Change next to its template, and a template with more than 60 details shows the filled, required and commonly used ones, with Find a detail and Show all above them.

-
Fill in a new product. A new product has the card Let AI fill in your product under the title: "Describe it once. AI fills in the texts, suggests details and categories, and translates it after you save." (without the right to translate, or with no language to translate into, the line stops after categories), a photo, the text box Describe your product, the language to write in (shown only when the ticked channels write in different languages), the languages it is translated into after the save (they follow the Channels card, with the cost and the review line) and Fill in with AI. The answer streams in step by step; every field it fills carries the note "Filled in by AI" with Undo, a sure detail is filled, an unsure one is a chip marked Check this, categories are suggestions, and Undo all and Try again sit in the summary. A first Add product in a browser asks How do you want to start? with Let AI fill it in and Fill it in yourself; the browser remembers the last choice (cookie
mrx_ai_draft_start), so the page opens in that mode, and the card's header switches at any time. In Fill it in yourself the card stays out of the way until you choose a language under Your texts are in; a hand-typed product is then translated after the save. In Let AI fill it in the only language question is Writes in (Write in when the ticked channels write in different languages), and the translation follows a fill. The photo slot shows the product's main image, the one AI reads: a photo chosen or dropped there uploads as the main image, with a spinner meanwhile, Replace and Remove, and the reason in the slot when it is refused. Several files dropped at once go to the Media card. Fill in with AI clicked during an upload waits for it and does not start when it failed. The button shows busy from the first click, the cost line reads Working out the cost… while the price loads, and the field AI is writing has a spinner. Nothing is saved before Save.





-
Which texts AI translates. Settings > AI has the card Which texts does AI translate? per channel: the texts and details to translate (with "Also details I add later"), image descriptions, new web addresses from the translated name, option names and the attribute names, and I check AI translations first myself. A language that has an own value for one of these in the advanced view shows it under the field, with a button to remove it. After a save that changes what is translated, the overview counts again, which takes a few minutes.

-
A language in the product editor. "Translate from" in a language view fills the texts the settings allow, the details, the web address and the alt text of each image, and the toast names what it left out and why. The alt-text card shows each image with its text in this language and Use default. Where the language's source store view has a text of its own, a line under the field shows it ("Source (Nederlands · Nörda Outlet): ...").


-
Translate into all languages, and the language status. On an existing product's default values the band has a quiet line, Translate into all languages. Its panel lists each language with "about" and its cost, the total and the limit line, and it names the languages it leaves out with the reason. Nothing starts until the merchant presses Start translating. The Language switch says under each language Translated by AI, Own text or Not translated. While a run is paused, a language view says "The translation into Deutsch is paused" with Open the run and keeps Translate from.




-
Option names. Products > Product options lists selects and multiselects with the number of suggestions to check; an option page has Translate missing names per language, and the list's bulk action Translate missing names with AI opens a cost dialog whose button reads Start translating, as on the run page, and lands on that page, which ends on Check <language> and See what AI wrote. When AI suggested names, the page shows a band "AI: ..." with Use, Edit and Reject and "Use all for <language>".

-
Products > Translations. The overview per language and type, the list behind each number, the review tab, the log of every translation with Revert, and the runs. The badge on the nav item counts what waits for the admins who may decide, and Home adds "translations wait for your check" and the to-dos below for translation rounds that need attention.
Mrx_Ai registers four items in the pool
todos(etc/adminhtml/di.xml). All four link tolight/ai/translationsand needMrx_Ai::bulk_translate; the three round items open the Runs tab filtered withneeds:Key of a todositemShows Links to Sort order ai_translations_waitingTranslations that wait for a check. the review tab 45 ai_translation_runsTranslation rounds that are paused. the Runs tab, needs=paused46 ai_translation_runs_waitingTranslation rounds that wait for a moment because the AI service asks for it. They go on by themselves. the Runs tab, needs=waiting47 ai_translation_runs_failedTranslation rounds that stopped with an error. A stopped round shows for 7 days. the Runs tab, needs=failed48 An extension that wants its own to-do for a round copies one of these items and gives it its own counter; the format is in Home: a to-do.



-
Translate many products. Ticking products on the products list offers Translate with AI; when the list holds more products than were ticked, the screen offers "All N in this list" next to the ticked ones: everything the list's search, tab and filters match (up to 10,000). It also offers the products of one category. Settings > Channels has Translate with AI per language. The screen shows the languages (with the reason when one can't be chosen), the texts, how (fill, update, replace), the web addresses, the engine for this run, the dry run per language (what will be translated, what you changed, the cost and the time) and a budget. Of the product details only those the chosen products fill are ticked (up to 60); a longer list shows the ticked ones with "Show all" and a search, and the dry run and the run page name the filled details ticked by default that the run leaves out. Start translating opens the page of the run: a bar per language with the texts done, what was spent against the budget, the speed and the time left, Pause, Resume, Cancel and Revert, and a log per language that opens on request. While a run is going, a small chip in the top bar ("Translating 61%") links back to it; when it finishes, pauses on its budget or fails, a notice in the bell does. Under the bar the page ends on the same two links as the product edit band, for every start that leads to it (this screen, the option names dialog and the Translations drill-downs): Check <language> for each language that waits for a check (To check, filtered to the run) and See what AI wrote (History, filtered to the run). See what AI wrote needs
Mrx_Ai::translations_view, and so does Check; without it neither shows. The web addresses are not a box on this screen. The "How" card says in one line whether the ticked languages' store views give translated names a new web address (Settings > AI, "Web address";disrex_ai_catalog/translation/url_key, read per store view, so a second website can differ), with the link "Change it in Settings > AI" for an admin who may open Settings. On a shop with several channels the link opens the screen's channel in Settings > AI, since a channel can hold a value of its own. When the ticked languages differ, the line names the ones that get new addresses. The screen posts nourl_keyfor "As set in Settings > AI" (null, each store view's own setting), so a second website keeps its own value. More options holds this run's own choice (as set in Settings > AI, new web addresses, or keep the web addresses), which is then posted as1or0for all the languages of the run. A category run and a Translations drill-down show neither. The screen and the run page set the estimate against what the run actually cost ("Estimated 1,20 to 1,60 · So far 0,84", then "Actual 1,34 (within the estimate)" or "(18 % over the estimate)").


ACL
Settings > AI needs Disrex_Ai::config. Its Write a draft with AI route (light/settings/aiprofiledraft) needs that and
Disrex_AiShopContext's Disrex_AiShopContext::profile_draft ("Draft the shop profile with AI"): it reads the shop's data and
spends AI budget, so only an admin who may change the AI settings and draft gets the button. Starting a bulk translation run and steering one (Pause, Resume, Cancel,
Revert, a bigger budget) spend the AI budget, so they need Light's own Mrx_Ai::bulk_translate ("Translate products
in bulk with AI"), which is also what the list's bulk action and the Settings > Channels link ask for. In simple mode it
is the role area Translate with AI; the Staff preset leaves it out and the owner has it. The bulk screen, its dry run,
the run page, its poll and its log need Magento_Catalog::products only: watching costs nothing. Seeing the translation
report, the review list and the log of Products > Translations needs Mrx_Ai::translations_view, a sibling of
bulk_translate that sits in the role area Products of simple mode, so every product editor holds it and the Staff
preset keeps it; approving, rejecting, reverting and starting an option-name run need Mrx_Ai::bulk_translate. The
option-name routes ask for Magento_Catalog::attributes_attributes in place of the products permission, and so do
the Product options band (light/ai/reviewitems?attribute=<id>) and the page, poll, log and buttons of an option-name
run; a decision is checked against the editor of each row it touches, not against the products permission. Measuring
the cost with your own products needs Disrex_Ai::cost_manage. Suggesting details
needs Magento_Catalog::products, like the other AI buttons of the product editor. Disrex's own resources for them
(Disrex_AiCatalog::jobs, Disrex_Ai::jobs_manage, ::details) sit below System in the ACL tree, and a Light role area
that held them would bring Magento_Backend::system with it, which opens admin/system/*; so Light has its own, and
the stock admin keeps the Disrex ones. An AI button needs the ACL resource of the screen it sits on, as Light's own do:
the product editor's buttons need Magento_Catalog::products, the translate buttons the editor's resource of the entity
they translate.
Check it
bin/magento disrex:ai:engines:show --store=<code>: per purpose the engine and model it resolves to, and why.bin/magento disrex:ai:prompt:show acme_faq --store=<code>: the composed system prompt, without a model call.bin/magento disrex:ai:profile:show --store=<code>anddisrex:ai:word-rules:check "<text>" --locale=nl_NL.bin/magento disrex:ai:cost:estimate --store=<code> [--purpose=<code>]: what one call of each purpose costs on each level, with the level in use marked and whether the size comes from history or from the purpose's typical tokens: the numbers of the cost calculator.bin/magento disrex:ai:profile:draft --store=<code>: the shop profile draft the Settings > AI button writes, on the command line; it saves nothing.bin/magento disrex:ai:pingsends one small request;disrex:ai:usagelists the recorded calls.bin/magento disrex:ai:catalog:coverage:refreshcounts the translation report inline, andindexer:statuslists its six indexers ("Translation report: ...") on "Update by schedule".- Tests and browser specs never call a model: switch on Disrex_Ai's fixture provider (developer mode,
disrex_ai/fixture/enabledanddisrex_ai/fixture/purposeswith your purposes, never*; a flow that drafts a product needsai_catalog_product_draft, option namesai_catalog_option_labels, a run or a reviewai_catalog_translate_job: a purpose left out goes to the real engine on a shop that holds a key), which answers[fixture] <text>at zero cost.disrex_ai/fixture/chunk_chars,first_token_delay_msandchunk_delay_msmake a streamed answer slow enough to see that the first piece reaches the page before the last one is written, and that Cancel stops the request.
Pitfalls
- A call without
purposecan't be told apart in the usage, and the merchant can't give it an engine. - Light's own purpose codes changed in 0.6.0: translation is Disrex_AiCatalog's
ai_catalog_translate, no longermrx_translate, and the product copy carriesai_catalog_description,ai_catalog_short_description,ai_catalog_proofread,ai_catalog_shorten,ai_catalog_seoandai_catalog_from_image, no longermrx_product_*(Upgrading). The old codes stay in the usage history under their own labels. - 0.7.0 adds the purposes
ai_catalog_product_draft(fill in a new product),ai_catalog_option_labels(option names) and usesai_catalog_translate_jobfor the translation row of the calculator and for review. A purpose list you pinned in a test withfixture/purposesneeds them too, or the call goes to the real engine. - A
draftFieldsitem in an adminhtmldi.xmlreplaces Disrex's own items instead of adding to them, and every draft answers "This field can't be filled in with AI." Put it in the globaletc/di.xml(step 11). - Don't write a store view's alt text, a product URL key or a translated text with SQL or your own code: the gallery table has no unique key and the log, the coverage tables and the URL rewrites expect Disrex_AiCatalog's writers.
- A stream that is never read to the end, or a route that doesn't check
connection_aborted(), keeps the model running after Cancel: you pay for text nobody sees. - Word rules add up since Disrex_AiShopContext 0.3.0: the list of a website or store view adds to the one above it, and
the lower scope wins for the same language and word. A module that read the list of a scope and assumed it replaced
the inherited one reads
WordRulesInterface::forLanguage()now, or asksdisrex_ai/word_rules/inherit. The data patchKeepReplacedWordRulessetsreplacewhere a shop had a list of its own, so what it sent does not change on update. - The word rules don't reach Mage-OS automatic translation's own engines, names the merchant types, or imports. The model can still ignore an instruction: the check flags a forbidden word but never blocks or rewrites it.
disrex/module-ai2.x may change the client. The^1.6range keeps it out until Light is tested with it (Versioning).
Last updated on
A share image for your page
Give the pages of your module an og:image: an image source for your page kind, your own card, a new card kind and the Share image field in your editor.
Make your module's notifications count as System
How the notification bell sorts notices into System and Extensions, and how your module's notices stay in System.