This commit is contained in:
2026-08-23 13:39:56 +02:00
parent 89ae7e5fa8
commit 815e26d359
7 changed files with 283 additions and 8 deletions
@@ -160,3 +160,76 @@ func parseDescriptionFormula(template any) (DescriptionFormula, bool) {
return f, true
}
}
// EffectiveDescriptionFormula returns the stored description_template when it has
// sections; otherwise derives sections from the category enhance prompt Description
// role (legacy HTML <H2>{…}</H2><p>{…}</p> overlays). That is how A1 and tenants
// author HTML structure in /categories/.../prompt — without this, enhance accepts
// plain prose and never runs the formula quality gate.
func EffectiveDescriptionFormula(stored any, categoryPrompt string) DescriptionFormula {
if f, ok := parseDescriptionFormula(stored); ok && len(f.Sections) > 0 {
return f
}
body := ExtractEnhanceSectionBody(categoryPrompt, SectionDescriptionStart, SectionDescriptionEnd)
if body == "" {
body = strings.TrimSpace(categoryPrompt)
}
if body == "" || !reLegacyHTMLBlock.MatchString(body) {
if f, ok := parseDescriptionFormula(stored); ok {
return f
}
return DescriptionFormula{}
}
return DeriveDescriptionFormulaFromLegacyParts(LegacyEnhanceParts{
DescriptionRules: body,
WasLegacy: true,
})
}
// EffectiveDescriptionTemplateAny is EffectiveDescriptionFormula as a JSON object
// for processing.ProductInput.DescriptionTemplate (nil when empty).
func EffectiveDescriptionTemplateAny(stored any, categoryPrompt string) any {
f := EffectiveDescriptionFormula(stored, categoryPrompt)
if len(f.Sections) == 0 && strings.TrimSpace(f.MetaTitle) == "" && strings.TrimSpace(f.MetaDescription) == "" {
return nil
}
b, err := json.Marshal(f)
if err != nil {
return nil
}
var out map[string]any
if err := json.Unmarshal(b, &out); err != nil {
return nil
}
return out
}
// CategoryTitlePromptRequiresRewrite reports whether the Title role instructs a
// new retail name (not keep/echo supplier title). Used to reject "Matched" copy-paste.
func CategoryTitlePromptRequiresRewrite(categoryPrompt string) bool {
body := ExtractEnhanceSectionBody(categoryPrompt, SectionTitleStart, SectionTitleEnd)
if body == "" {
body = strings.TrimSpace(categoryPrompt)
}
if body == "" {
return false
}
lower := strings.ToLower(body)
cues := []string{
"napiši novo ime",
"napisi novo ime",
"novo ime izdelka",
"po formuli",
"write a new",
"new product name",
"rename",
"title formula",
"sentence case",
}
for _, c := range cues {
if strings.Contains(lower, c) {
return true
}
}
return false
}