{
  "name": "Vorlux AI | KB Auto Indexer",
  "active": false,
  "nodes": [
    { "parameters": { "rule": { "interval": [{ "field": "hours", "hoursInterval": 3 }] } }, "id": "sched", "name": "Every 3 Hours", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [220, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/blog/posts", "method": "GET", "qs": { "status": "published", "limit": 20, "sort": "updatedAt" }, "options": { "timeout": 15000 } }, "id": "fetch-content", "name": "Fetch Recent Content", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 200] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/kb/index", "method": "GET", "options": { "timeout": 15000 } }, "id": "fetch-index", "name": "Fetch KB Index", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 400] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const content = $('Fetch Recent Content').first().json.data || [];\nconst indexed = $('Fetch KB Index').first().json.data || [];\nconst indexedIds = new Set(indexed.map(i => i.sourceId || i.id));\nconst toIndex = content.filter(c => !indexedIds.has(c.id));\nreturn [{ json: { newContent: toIndex.length, alreadyIndexed: indexed.length, toIndex: toIndex.map(c => ({ id: c.id, title: c.title, category: c.category || 'general' })) } }];" }, "id": "diff", "name": "Find Unindexed Content", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [720, 300] },
    { "parameters": { "url": "http://host.docker.internal:3010/api/kb/index", "method": "POST", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ articles: $json.toIndex }) }}", "options": { "timeout": 30000 } }, "id": "index", "name": "Index New Content", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 300] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_OPS_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '📚 **KB Auto-Indexer**\\nNew articles indexed: ' + $('Find Unindexed Content').first().json.newContent + '\\nTotal in index: ' + ($('Find Unindexed Content').first().json.alreadyIndexed + $('Find Unindexed Content').first().json.newContent) }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [1200, 300] }
  ],
  "connections": {
    "Every 3 Hours": { "main": [[{ "node": "Fetch Recent Content", "type": "main", "index": 0 }, { "node": "Fetch KB Index", "type": "main", "index": 0 }]] },
    "Fetch Recent Content": { "main": [[{ "node": "Find Unindexed Content", "type": "main", "index": 0 }]] },
    "Fetch KB Index": { "main": [[{ "node": "Find Unindexed Content", "type": "main", "index": 0 }]] },
    "Find Unindexed Content": { "main": [[{ "node": "Index New Content", "type": "main", "index": 0 }]] },
    "Index New Content": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
