{
  "name": "SoftGlaze: daily health report (Beta)",
  "nodes": [
    {
      "parameters": {
        "content": "## SoftGlaze daily health report (Beta)\n\nEvery morning at 8:00 this reads your SoftGlaze workspace and sends a short report.\n\n1. In SoftGlaze, open SoftGlaze AI, switch on AI server and create a **Read only** token. Read-only tools don't ask for approval by default.\n2. In each **SoftGlaze** HTTP Request node, choose a **Bearer Auth** credential with that token. Change `8080` if your port is different.\n3. Set the Telegram chat id (or switch on the Slack node and set its channel instead). Replace every `CHANGE_ME`.\n4. Run it once by hand before you activate it.\n\nBeta: not yet run against a live SoftGlaze. Guide: browser.softglaze.com/docs/ai-agents#n8n",
        "height": 320,
        "width": 520
      },
      "id": "f40a3dc2-212a-4729-b944-58324851789d",
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -340
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 8
            }
          ]
        }
      },
      "id": "f7bb3366-6503-4ded-9ec1-220c7e00084f",
      "name": "Every morning at 8:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:8080/api/v1/tools/workspace_summary",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{}",
        "options": {
          "timeout": 130000
        }
      },
      "id": "2d2539c0-4cac-486b-9f4a-e6c4d556d913",
      "name": "Workspace summary",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:8080/api/v1/tools/list_sessions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{}",
        "options": {
          "timeout": 130000
        }
      },
      "id": "7b5c8abe-f363-43d9-8a4a-e3e907ab9b77",
      "name": "Running profiles",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:8080/api/v1/tools/list_proxies",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{ \"status\": \"fail\", \"pageSize\": 25 }",
        "options": {
          "timeout": 130000
        }
      },
      "id": "25261732-693c-4936-a77c-242847f7e3a9",
      "name": "Failing proxies",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://127.0.0.1:8080/api/v1/tools/get_proxy_health",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{}",
        "options": {
          "timeout": 130000
        }
      },
      "id": "b5f30dcb-9cc2-4c23-9cde-00bee773e10e",
      "name": "Pool health",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Builds one short report from the four SoftGlaze calls before this node.\n// Each call answers { ok, summary, data } (see browser.softglaze.com/docs/ai-tools).\nconst ws = $('Workspace summary').first().json.data || {};\nconst running = $('Running profiles').first().json.data || {};\nconst failing = $('Failing proxies').first().json.data || {};\nconst pool = $('Pool health').first().json.data || {};\n\nconst counts = ws.counts || {};\nconst plan = ws.plan || {};\nconst sessions = running.sessions || [];\nconst bad = failing.proxies || [];\nconst newlyFailing = (pool.proxies || []).filter((p) => p.regressed);\n\nconst lines = ['SoftGlaze daily health report'];\nlines.push('Profiles: ' + (counts.profiles ?? '?') + ', running now: ' + (counts.runningProfiles ?? 0) + ', groups: ' + (counts.groups ?? '?'));\nlines.push('Proxies: ' + (counts.proxies ?? '?') + ', failing: ' + (counts.failingProxies ?? 0));\nif (plan.tier) lines.push('Plan: ' + plan.tier + (plan.daysLeft != null ? ', ' + plan.daysLeft + ' days left' : ''));\nif (sessions.length) {\n  lines.push('');\n  lines.push('Running: ' + sessions.slice(0, 10).map((s) => s.name || ('#' + s.profileId)).join(', ') + (sessions.length > 10 ? ' and ' + (sessions.length - 10) + ' more' : ''));\n}\nif (bad.length) {\n  lines.push('');\n  lines.push('Failing proxies (' + (failing.total ?? bad.length) + '):');\n  for (const p of bad.slice(0, 10)) lines.push('- ' + (p.name || (p.host + ':' + p.port)) + (p.country ? ' (' + p.country + ')' : '') + (p.usedByProfiles ? ', used by ' + p.usedByProfiles + ' profile(s)' : '') + (p.error ? ': ' + p.error : ''));\n}\nif (newlyFailing.length) {\n  lines.push('');\n  lines.push('Newly failing since their last good check: ' + newlyFailing.slice(0, 10).map((p) => p.name || ('#' + p.proxyId)).join(', '));\n}\nif (!bad.length && !newlyFailing.length) lines.push('', 'No failing proxies.');\n\nreturn [{ json: { text: lines.join('\\n') } }];"
      },
      "id": "5ed71b09-dfca-483f-b13d-c1173bcdfa86",
      "name": "Build the report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "chatId": "CHANGE_ME",
        "text": "={{ $json.text }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "113e3e61-bbd1-4901-a5f8-972e8da475f5",
      "name": "Send to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1320,
        -100
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#CHANGE_ME",
          "mode": "name"
        },
        "text": "={{ $json.text }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "id": "43e7f968-837e-45fd-8c8e-4b70f15cb0d3",
      "name": "Send to Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [
        1320,
        100
      ],
      "disabled": true
    }
  ],
  "connections": {
    "Every morning at 8:00": {
      "main": [
        [
          {
            "node": "Workspace summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workspace summary": {
      "main": [
        [
          {
            "node": "Running profiles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Running profiles": {
      "main": [
        [
          {
            "node": "Failing proxies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Failing proxies": {
      "main": [
        [
          {
            "node": "Pool health",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pool health": {
      "main": [
        [
          {
            "node": "Build the report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build the report": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send to Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
