chore: import coordenador (subtree)
git-subtree-dir: coordenador git-subtree-mainline:facbe2e340git-subtree-split:ce7af94d55
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
// @requires config.js cache.js classification.js
|
||||
// Instancia bloqueia $env em Code nodes -- config vem do node "Config - Coordenador GLPI v2".
|
||||
const config = parseConfig($('Config - Coordenador GLPI v2').first().json);
|
||||
const now = Date.now();
|
||||
|
||||
// $input vem do Merge - Aguardar Memoria (so existe para GARANTIR que os candidatos e a
|
||||
// memoria ja foram buscados antes deste node rodar); os dados de verdade sao lidos por nome.
|
||||
const items = $('Code - Mesclar Contexto e Calcular Hash').all().map((item) => item.json); // { ticket, contextHash }
|
||||
const memoryRows = $('Data Table - Buscar Memoria').all().map((item) => item.json);
|
||||
const memoryByTicket = {};
|
||||
for (const row of memoryRows) memoryByTicket[String(row.ticket_id)] = row;
|
||||
|
||||
const withDecision = items.map((item) => {
|
||||
const memory = memoryByTicket[String(item.ticket.id)] || null;
|
||||
// Chave de cache = conteudo do chamado + versao do classificador (logic/cache.js). Bump de
|
||||
// AI_CLASSIFIER_VERSION forca cache miss em TODO chamado, mesmo sem nenhuma mudanca real no
|
||||
// GLPI -- sem precisar apagar a Data Table na mao (missao "finalizacao para producao", secao 12).
|
||||
const cacheKey = buildCacheKey(item.contextHash, AI_CLASSIFIER_VERSION);
|
||||
const analysis = needsReanalysis({ memory, currentHash: cacheKey, now });
|
||||
return {
|
||||
ticket: item.ticket, contextHash: item.contextHash, cacheKey, memory, needsAiReason: analysis.reason, needsAiRaw: analysis.needsAi,
|
||||
};
|
||||
});
|
||||
|
||||
const needingAi = withDecision
|
||||
.filter((item) => item.needsAiRaw)
|
||||
.sort((a, b) => (Number(b.ticket.score_criticidade) || 0) - (Number(a.ticket.score_criticidade) || 0));
|
||||
|
||||
const allowedIds = new Set(needingAi.slice(0, config.aiMaxCandidates).map((item) => item.ticket.id));
|
||||
|
||||
return withDecision.map((item) => {
|
||||
let resolucao;
|
||||
if (!item.needsAiRaw) {
|
||||
resolucao = 'cache';
|
||||
} else if (allowedIds.has(item.ticket.id)) {
|
||||
resolucao = 'ia';
|
||||
} else {
|
||||
resolucao = 'fallback_cap';
|
||||
}
|
||||
return {
|
||||
json: {
|
||||
ticket: item.ticket,
|
||||
contextHash: item.contextHash,
|
||||
cacheKey: item.cacheKey,
|
||||
memory: item.memory,
|
||||
needsAiReason: item.needsAiReason,
|
||||
resolucao,
|
||||
precisa_ia: resolucao === 'ia',
|
||||
config,
|
||||
now,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user