{
  "name": "Vorlux AI | KB Search Analytics",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "weeks", "weeksInterval": 1 }] } }, "id": "sched", "name": "Weekly Schedule", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/kb/analytics", "method": "GET", "options": { "timeout": 15000 } }, "id": "fetch-analytics", "name": "Fetch KB Analytics", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const analytics = $input.first().json;\nconst searches = analytics.searches || analytics.data?.searches || [];\nconst noResults = searches.filter(s => s.results === 0 || s.resultCount === 0);\nconst topQueries = searches.sort((a, b) => (b.count || 0) - (a.count || 0)).slice(0, 10);\nreturn [{ json: { totalSearches: searches.length, noResultSearches: noResults.length, topQueries: topQueries.map(q => ({ query: q.query || q.term, count: q.count || 1 })), gaps: noResults.map(n => n.query || n.term).slice(0, 10) } }];" }, "id": "analyze", "name": "Analyze Patterns", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [700, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/reports", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ type: 'kb-search', title: 'KB Search Analytics', data: $json }) }}", "options": { "timeout": 15000 } }, "id": "save", "name": "Save Report", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 200] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_OPS_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '🔎 **KB Search Analytics**\\nTotal Searches: ' + $json.totalSearches + '\\nNo Results: ' + $json.noResultSearches + '\\nContent Gaps: ' + $json.gaps.slice(0, 5).join(', ') }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 400] }
  ],
  "connections": {
    "Weekly Schedule": { "main": [[{ "node": "Fetch KB Analytics", "type": "main", "index": 0 }]] },
    "Fetch KB Analytics": { "main": [[{ "node": "Analyze Patterns", "type": "main", "index": 0 }]] },
    "Analyze Patterns": { "main": [[{ "node": "Save Report", "type": "main", "index": 0 }, { "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
