- 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>
28 lines
1003 B
JavaScript
28 lines
1003 B
JavaScript
// @requires fallback.js
|
|
return $input.all().map((item) => {
|
|
const data = item.json;
|
|
if (data.resolucao === 'cache' && data.memory) {
|
|
const m = data.memory;
|
|
return {
|
|
json: {
|
|
...data,
|
|
aiClassification: {
|
|
classification: m.ai_classification,
|
|
actionable_today: m.ai_classification === 'ACTIONABLE_NOW' || m.ai_classification === 'UNASSIGNED_ACTIONABLE',
|
|
confidence: Number(m.ai_confidence || 0),
|
|
blocker_type: m.blocker_type || null,
|
|
waiting_for: m.waiting_for || null,
|
|
next_action: m.next_action || 'Revisar chamado',
|
|
suggested_action_type: 'technical_action',
|
|
business_risk: 'medium',
|
|
reason: m.last_ai_reason || 'Classificacao reaproveitada do cache.',
|
|
evidence: [],
|
|
is_fallback: false,
|
|
fallback_reason: null,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
return { json: { ...data, aiClassification: buildFallbackClassification('ai_max_candidates_cap') } };
|
|
});
|