From 92f046b54267df2395d3525c6f254e4b991892c4 Mon Sep 17 00:00:00 2001 From: GreenEclipse Date: Sun, 16 Aug 2026 23:42:00 +0200 Subject: [PATCH] fix --- apps/api/cmd/seed-a1/category_prompts.go | 5 +- apps/api/internal/aiprompts/kinds.go | 74 ++++-- apps/api/internal/aiprompts/kinds_test.go | 10 +- apps/api/internal/aiprompts/roles.go | 51 ++++ apps/api/internal/aiprompts/roles_test.go | 79 ++++++ apps/api/internal/catalog/fix_catalog_test.go | 3 + apps/api/internal/catalog/prompt_repair.go | 7 +- apps/api/internal/httpapi/v1_openapi.go | 13 +- apps/api/internal/processing/ai.go | 4 +- .../internal/processing/attrs_enhance_test.go | 120 +++++++++ apps/api/internal/processing/catalog_fix.go | 28 +- apps/api/internal/processing/categorize_ai.go | 3 +- .../internal/processing/enhance_log_test.go | 3 + .../api/internal/processing/formula_prompt.go | 249 +++++++++++++++++- .../processing/formula_prompt_test.go | 145 +++++++++- .../api/internal/processing/legacy_convert.go | 46 +++- .../processing/legacy_convert_test.go | 23 +- apps/api/internal/processing/llm_json.go | 2 +- apps/api/internal/processing/meta.go | 56 ++++ apps/api/internal/processing/meta_test.go | 61 +++++ apps/api/internal/processing/openai.go | 14 +- apps/api/internal/processing/pipeline.go | 28 +- .../processing/prompt_fallback_test.go | 12 +- apps/api/internal/processing/prompt_render.go | 47 +++- .../internal/processing/prompt_render_test.go | 78 +++++- apps/api/internal/processing/sanitize.go | 9 +- apps/api/internal/processing/steps.go | 226 +++++++++++++++- apps/api/internal/processing/steps_test.go | 20 +- apps/api/internal/processing/v1_legacy.go | 58 +++- .../internal/processing/v1_process_item.go | 42 ++- .../processing/v1_process_item_test.go | 30 +++ apps/api/internal/seo/templates.go | 2 +- 32 files changed, 1443 insertions(+), 105 deletions(-) create mode 100644 apps/api/internal/aiprompts/roles.go create mode 100644 apps/api/internal/aiprompts/roles_test.go create mode 100644 apps/api/internal/processing/attrs_enhance_test.go diff --git a/apps/api/cmd/seed-a1/category_prompts.go b/apps/api/cmd/seed-a1/category_prompts.go index f241827..dc625fe 100644 --- a/apps/api/cmd/seed-a1/category_prompts.go +++ b/apps/api/cmd/seed-a1/category_prompts.go @@ -148,9 +148,10 @@ func applyCategoryPrompts(ctx context.Context, pg *pgxpool.Pool, companyID uuid. byNorm := make(map[string]string, len(file.Entries)) byUnique := make(map[string]string, len(file.Entries)) - // Overlay sets the shared JSON-compatible enhance user template (not legacy HTML). + // Overlay sets the shared role-sectioned enhance user template + // (aiprompts.CategoryEnhanceUserTemplate — title/description/meta/attributes). // Seed JSON selects which categories get a prompt (prefer unique_id, else name). - // Unique title/description formulas stay in title_template / description_template. + // Unique title/description/meta formulas stay in title_template / description_template. // Stored under "sl" + "*" so prompt->>'sl' and LangPromptAny both resolve; // language stays via {{language}}. canonical := prepareCategoryPrompt(aiprompts.CategoryEnhanceUserTemplate) diff --git a/apps/api/internal/aiprompts/kinds.go b/apps/api/internal/aiprompts/kinds.go index 92d2980..bdae133 100644 --- a/apps/api/internal/aiprompts/kinds.go +++ b/apps/api/internal/aiprompts/kinds.go @@ -26,7 +26,9 @@ type Variable struct { // Catalog of supported {{variables}} (only these are substituted; unknown tokens stay literal). var VariableCatalog = []Variable{ {Name: "name", Label: "Product name", Description: "Current product title", Keys: []string{KeyProductEnhance, KeySEOMeta}}, - {Name: "description", Label: "Description", Description: "Current product description", Keys: []string{KeyProductEnhance, KeySEOMeta}}, + // description = product HTML body input (not SEO meta_description). Template key + // stays "description" so stored tenant prompts keep working (renaming would be BREAKING). + {Name: "description", Label: "Product description", Description: "Current product description (HTML body). Not SEO meta_description.", Keys: []string{KeyProductEnhance, KeySEOMeta}}, {Name: "category", Label: "Category", Description: "Resolved category name", Keys: []string{KeyProductEnhance, KeySEOMeta}}, {Name: "attrs", Label: "Attributes", Description: "Compact JSON of product attributes", Keys: []string{KeyProductEnhance}}, {Name: "gtin", Label: "GTIN", Description: "Product GTIN / barcode when present", Keys: []string{KeyProductEnhance}}, @@ -48,20 +50,38 @@ type DefaultTemplate struct { } // CategoryEnhanceUserTemplate is the shared per-category (and built-in) enhance USER -// message. Includes {{name}} {{description}} {{attrs}} {{category}} {{language}}. -// Compatible with the enhance system JSON schema {"name","description"} — not a -// competing HTML marketing document. Title/description formulas stay in -// title_template / description_template and are appended at render time as plain -// text instructions (see processing.AppendFormulaConstraints). -// Used by local A1/Demo prompt repair and seed-a1 overlays. -const CategoryEnhanceUserTemplate = `Your reply is parsed as JSON {"name":"string","description":"string"} only (system schema). Write name and description in {{language}} (do not hardcode a language). -- name: short retail title; follow any Title formula constraints that follow; use Attrs -- description: when a Description formula follows, emit ONE HTML string covering each section in order (tags matching type: h1/h2/h3/h4, p, ul); otherwise prefer 1-3 factual paragraphs as ONE string with limited HTML (