[FIX] ARIA: mappa navigazione reale + contesto pagina (ticket #424)

ARIA citava voci di menu inesistenti (es. 'A4 - Analisi e Valutazione
del Rischio' / 'Fase 4.1 - Inventario') non corrispondenti alla barra
laterale, e non sapeva da quale pagina scrivesse l'utente.

- AIService::askWithRag: iniettata la mappa REALE della sidebar
  (navigationMapBlock, sincronizzata con common-bi.js) con regole che
  vietano di inventare menu/fasi/codici; aggiunto contesto pagina utente.
- AiController::ask: accetta e passa il campo 'page' dal frontend.
- common.js (ARIA FAB): invia la pagina corrente in /api/ai/ask.
- Cache-buster common.js 20260623->20260623h su tutte le pagine.

NB: questo commit include anche il fix #419 gia' applicato e live in
common.js (email bug-reporter recuperata via api.getMe quando assente
nelle claims JWT), finora non committato — incluso come backup.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
DevEnv nis2-agile
2026-06-23 21:12:36 +02:00
co-authored by Claude Opus 4.8
parent d45bd472cd
commit ea5966eaee
43 changed files with 112 additions and 59 deletions
+31 -17
View File
@@ -952,22 +952,33 @@ function switchLang(lang) {
// ── 1. Inietta il bug-reporter Nexus ────────────────────────────────────
if (!window.__nexusWidgetLoaded) {
window.__nexusWidgetLoaded = true;
var s = document.createElement('script');
s.src = 'js/bug-reporter.js?v=20260613';
s.async = true;
s.dataset.product = 'NIS2';
s.dataset.tenantId = '7';
s.dataset.apiUrl = 'https://agilehub.agile.software';
// X-API-Key per il gateway ticket AgileHub. Senza, il widget riceve 401
// "Header X-API-Key o Authorization: Bearer richiesto". Valorizzare con la
// chiave NIS2 emessa da AgileHub (prodotto NIS2, tenant 7). Inietta via
// window.NEXUS_WIDGET_API_KEY oppure hardcoda qui quando disponibile.
s.dataset.apiKey = (window.NEXUS_WIDGET_API_KEY || 'nis2_ak_dev_109b4bb54557c4ab3bdbed45');
s.dataset.userName = userName;
s.dataset.userEmail = userEmail;
s.dataset.userRole = userRole;
s.dataset.lang = 'it';
document.body.appendChild(s);
// [#419 fix] L'email NON e' nelle claims del JWT NIS2 (claims.email vuoto) → se manca,
// recuperala dal profilo via api.getMe() PRIMA di iniettare. Senza email il widget crea
// ticket con richiedente vuoto → invisibili in "Le mie segnalazioni". Fallback safe = prec.
var _injectBugReporter = function (email, name) {
var s = document.createElement('script');
s.src = 'js/bug-reporter.js?v=20260623';
s.async = true;
s.dataset.product = 'NIS2';
s.dataset.tenantId = '7';
s.dataset.apiUrl = 'https://agilehub.agile.software';
s.dataset.apiKey = (window.NEXUS_WIDGET_API_KEY || 'nis2_ak_dev_109b4bb54557c4ab3bdbed45');
s.dataset.userName = name || userName || '';
s.dataset.userEmail = email || userEmail || '';
s.dataset.userRole = userRole;
s.dataset.lang = 'it';
document.body.appendChild(s);
};
if (userEmail) {
_injectBugReporter(userEmail, userName);
} else if (typeof api !== 'undefined' && typeof api.getMe === 'function') {
api.getMe().then(function (r) {
var u = (r && r.data) || {};
_injectBugReporter(u.email || '', u.full_name || u.name || '');
}).catch(function () { _injectBugReporter('', ''); });
} else {
_injectBugReporter('', '');
}
}
// ── 2. AI Chat FAB viola "ARIA" ─────────────────────────────────────────
@@ -1118,6 +1129,9 @@ function switchLang(lang) {
// AI nativa NIS2 (RAG con KB Multi-Livello già attivo)
var t = localStorage.getItem('nis2_access_token') || '';
var orgId = localStorage.getItem('nis2_org_id') || '';
// Pagina corrente: aiuta ARIA a dare indicazioni contestuali (ticket #424).
var pageName = (document.title || '').replace(/\s*[—|·-]\s*NIS2.*$/i, '').trim()
|| (location.pathname.split('/').pop() || '');
var r = await fetch('/api/ai/ask', {
method: 'POST',
headers: {
@@ -1125,7 +1139,7 @@ function switchLang(lang) {
'Authorization': t ? ('Bearer ' + t) : '',
'X-Organization-Id': orgId
},
body: JSON.stringify({ question: text, history: history })
body: JSON.stringify({ question: text, history: history, page: pageName })
});
var resp = await r.json();
var answer = (resp && resp.success && resp.data