Skip to content

feat: prompt rules engine with store, priority, and product conditions (#32)#63

Open
DavidLambauer wants to merge 10 commits into
mage-os-lab:mainfrom
DavidLambauer:feature/phase3-prompt-rules-engine-v2
Open

feat: prompt rules engine with store, priority, and product conditions (#32)#63
DavidLambauer wants to merge 10 commits into
mage-os-lab:mainfrom
DavidLambauer:feature/phase3-prompt-rules-engine-v2

Conversation

@DavidLambauer

Copy link
Copy Markdown
Contributor

Summary

Fixes #32. Supersedes #54 (which was a Phase 3 bundle of #32 + #43; #43's config migration was dropped in favor of a separate coordinated effort with the translation module).

Adds an admin-managed rules engine for per-attribute AI prompts, with store scope, priority, and Magento catalog-rule conditions. Replaces the direct Config::getProductPrompt() lookup in Enricher with a priority-sorted rule resolver that falls back to the default prompt from the dynamic-row config.

What's new

Data layer:

  • mageos_catalogai_prompt_rule table (10 columns, indexed on attribute_code + is_active)
  • PromptRule model extending Magento\Rule\Model\AbstractModel with catalog rule conditions support
  • Repository, collection, resource model

Service:

  • PromptResolver::resolve(string $attributeCode, Product $product): ?string — filters active rules, sorts by priority DESC, returns the prompt from the first rule that matches store scope and product conditions. Falls back to Config::getProductPrompt() when no rules match.
  • Enricher now delegates prompt lookup to PromptResolver

Admin UI:

  • New "AI Prompt Rules" menu entry under Catalog
  • Full CRUD: grid listing, edit form with collapsible fieldsets, mass-delete
  • Form fields: name, active toggle, target attribute (dropdown of configured attributes), store views (multiselect), priority, prompt template
  • Conditions fieldset using Magento's catalog rule conditions framework
  • Preview/test AJAX endpoint — enter a SKU, see the resolved prompt with variables substituted

What's NOT in this PR

The #43 config migration to ai_integration_enrichment was designed before #46 landed and no longer matches the current config surface. It'll return as a separately-scoped PR coordinated with the translation module's shared "AI Services" section. None of the rules-engine code depends on it.

Test plan

  • 149 unit tests, 314 assertions, green locally across PHP 8.2/8.3/8.4 (via CI)
  • Run setup:upgrade — creates mageos_catalogai_prompt_rule table
  • Navigate to Catalog → AI Prompt Rules — grid loads
  • Create a rule: name, attribute, prompt, priority, save — persists on reload
  • Two rules for the same attribute with different priorities — higher priority wins during enrichment
  • Store-scoped rule only matches in its assigned store
  • No rule matches — falls back to the default prompt from the dynamic-row config
  • Preview endpoint — enter a SKU, see substituted prompt
  • Mass-delete from the grid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Prompt rule system

1 participant