feat(v2): complete n8n workflow template (36 nodes) covering full V2 pipeline + shadow branch

- 14 new Code node drivers implementing the pipeline stages: normalize
  candidates, build context SQL, merge context + hash, decide AI need,
  prepare AI prompt, validate AI response, AI-disabled fallback, reuse
  cached classification, compute score, select top 10, prepare memory/
  envio records, build message/digest, compare legacy x V2, debug panel.
- Consolidated the two context queries (followups/tasks) into a single
  UNION ALL query tagged by tipo, and added a "Merge - Unir Shadow"
  synchronization node before comparing legacy x V2: n8n does not
  guarantee relative execution order between sibling branches that only
  share an early common ancestor, so cross-branch data was only safe to
  read by name once a real Merge node forced both to complete first.
- Reordered score calculation before the memory upsert (score is needed
  in the persisted row) and turned both Data Table writes into
  side-effect branches that fan out from the main path instead of
  gating it, so the Data Table node's own output shape never needs to
  carry the full pipeline state forward.
- Fixed a duplicate-identifier bug in the build script: score.js's
  require('./cooldown') survived inlining and collided with
  cooldown.js's own computeCooldown function in the same Code node
  scope. build-workflow.js now strips inter-module requires when
  inlining, and a new test syntax-checks every generated jsCode string
  plus asserts no leftover require() calls.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gustavo
2026-08-24 15:31:44 -03:00
co-authored by Claude Sonnet 5
parent ec596a29a8
commit a99a25cb1a
24 changed files with 1818 additions and 76 deletions
-5
View File
@@ -1,5 +0,0 @@
-- Followups publicos dos candidatos (IDs interpolados pelo node, validados como inteiros).
SELECT items_id AS tickets_id, id, date, content AS texto
FROM glpi_itilfollowups
WHERE itemtype = 'Ticket' AND is_private = 0 AND items_id IN ({IDS})
ORDER BY items_id, date ASC;
+17
View File
@@ -0,0 +1,17 @@
-- Contexto (followups publicos + tarefas) dos candidatos, numa unica query
-- para garantir que o node de merge so roda depois que os dois tipos ja chegaram.
-- IDs interpolados pelo node como lista de inteiros (nunca string crua do GLPI).
-- Coluna de status de glpi_tickettasks (state) a confirmar via DESCRIBE quando a
-- credencial MySQL estiver disponivel (Task 14) -- ver nota no plano.
SELECT 'followup' AS tipo, items_id AS tickets_id, id, date, content AS texto, NULL AS status
FROM glpi_itilfollowups
WHERE itemtype = 'Ticket' AND is_private = 0 AND items_id IN ({IDS})
UNION ALL
SELECT 'task' AS tipo, tickets_id, id, date, content AS texto, state AS status
FROM glpi_tickettasks
WHERE tickets_id IN ({IDS})
ORDER BY tickets_id, date ASC;
-6
View File
@@ -1,6 +0,0 @@
-- Tarefas dos candidatos. Coluna de status a confirmar via DESCRIBE glpi_tickettasks
-- quando a credencial MySQL estiver disponivel (Task 14) -- ver nota no plano.
SELECT tickets_id, id, date, state AS status, content AS texto
FROM glpi_tickettasks
WHERE tickets_id IN ({IDS})
ORDER BY tickets_id, date ASC;