{
  "name": "AHF 02 - AI Exception Analysis",
  "nodes": [
    {
      "parameters": {"httpMethod":"POST","path":"ahf-ai-analysis","responseMode":"responseNode","options":{}},
      "id": "916fd777-59a3-4bd0-8c11-76ab6f9bf550",
      "name": "Validated Exceptions Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-540, 0],
      "webhookId": "ahf-ai-exception-analysis"
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body ?? $json;\nif (!Array.isArray(body.exceptions) || !body.exceptions.length) throw new Error('Validated exceptions are required');\nreturn [{ json: { mode: body.mode === 'live' ? 'live' : 'demo', exceptions: body.exceptions.slice(0, 30) } }];"
      },
      "id": "62e86d2c-a796-41f1-b735-c3327c008e42",
      "name": "Prepare API Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-300, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.AHF_AI_API_URL }}",
        "sendHeaders": true,
        "headerParameters": {"parameters":[{"name":"Content-Type","value":"application/json"}]},
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify($json) }}",
        "options": {"timeout": 30000}
      },
      "id": "a2031022-1631-413f-b74e-df8d00d60d5b",
      "name": "Call AHF Portfolio API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-40, 0]
    },
    {
      "parameters": {
        "jsCode": "const analysis = $json.analysis ?? {};\nreturn [{ json: {\n  ...$json,\n  workflow_status: 'review_required',\n  outbound_action_blocked: analysis.approval_required !== false,\n  next_step: 'Send payload to approval workflow'\n} }];"
      },
      "id": "f341605f-4a12-411a-895b-74f8aa0aad34",
      "name": "Create Review Queue Item",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [220, 0]
    },
    {
      "parameters": {"respondWith":"json","responseBody":"={{ $json }}","options":{}},
      "id": "879cbfab-d11a-4763-a8b0-c68a9d9f89a2",
      "name": "Return Analysis",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [480, 0]
    }
  ],
  "pinData": {},
  "connections": {
    "Validated Exceptions Webhook": {"main":[[{"node":"Prepare API Payload","type":"main","index":0}]]},
    "Prepare API Payload": {"main":[[{"node":"Call AHF Portfolio API","type":"main","index":0}]]},
    "Call AHF Portfolio API": {"main":[[{"node":"Create Review Queue Item","type":"main","index":0}]]},
    "Create Review Queue Item": {"main":[[{"node":"Return Analysis","type":"main","index":0}]]}
  },
  "active": false,
  "settings": {"executionOrder":"v1"},
  "versionId": "b099328a-8a79-4235-8b4f-950b9fa0b3dd",
  "meta": {"templateCredsSetupCompleted": true},
  "tags": []
}
