{
  "name": "Vorlux AI | KB Stale Content Checker",
  "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/list", "method": "GET", "options": { "timeout": 15000 } }, "id": "fetch-kb", "name": "Fetch KB Articles", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [460, 300] },
    { "parameters": { "mode": "runOnceForAllItems", "jsCode": "const articles = $input.first().json.data || $input.first().json.articles || [];\nconst now = Date.now();\nconst staleThreshold = 90 * 86400000; // 90 days\nconst stale = articles.filter(a => {\n  const updated = new Date(a.updatedAt || a.updated_at || a.createdAt).getTime();\n  return (now - updated) > staleThreshold;\n}).map(a => ({ id: a.id, title: a.title, lastUpdated: a.updatedAt || a.updated_at, daysSinceUpdate: Math.floor((now - new Date(a.updatedAt || a.updated_at || 0).getTime()) / 86400000) }));\nreturn [{ json: { totalArticles: articles.length, staleCount: stale.length, staleArticles: stale.sort((a, b) => b.daysSinceUpdate - a.daysSinceUpdate).slice(0, 20) } }];" }, "id": "find-stale", "name": "Find Stale Articles", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [700, 300] },
    { "parameters": { "method": "POST", "url": "={{$env.DISCORD_OPS_WEBHOOK}}", "sendBody": true, "specifyBody": "json", "jsonBody": "={{ JSON.stringify({ content: '📝 **KB Stale Content Check**\\nTotal Articles: ' + $json.totalArticles + '\\nStale (>90 days): ' + $json.staleCount + ($json.staleCount > 0 ? '\\nTop stale:\\n' + $json.staleArticles.slice(0, 5).map(a => '• ' + a.title + ' (' + a.daysSinceUpdate + ' days)').join('\\n') : '') }) }}" }, "id": "notify", "name": "Discord Notify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [960, 300] }
  ],
  "connections": {
    "Weekly Schedule": { "main": [[{ "node": "Fetch KB Articles", "type": "main", "index": 0 }]] },
    "Fetch KB Articles": { "main": [[{ "node": "Find Stale Articles", "type": "main", "index": 0 }]] },
    "Find Stale Articles": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
