{
  "name": "TestNeo \u2014 Ingest AgentRunSummary (Template 2)",
  "nodes": [
    {
      "id": "m2",
      "name": "When clicking Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        200
      ],
      "parameters": {}
    },
    {
      "id": "c2",
      "name": "Edit Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        200
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "b1",
              "name": "baseUrl",
              "value": "={{ $env.TESTNEO_BASE_URL || 'https://app.testneo.ai' }}",
              "type": "string"
            },
            {
              "id": "b2",
              "name": "apiKey",
              "value": "={{ $env.TESTNEO_API_KEY || '' }}",
              "type": "string"
            },
            {
              "id": "b3",
              "name": "projectId",
              "value": "={{ Number($env.TESTNEO_PROJECT_ID || $json.project_id || 0) }}",
              "type": "number"
            },
            {
              "id": "b4",
              "name": "summary",
              "value": "={{ $json.summary || $json.agent_run_summary || {} }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "code2",
      "name": "Ensure summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const cfg = items[0].json;\nlet summary = cfg.summary;\nif (!summary || !summary.contract_version) {\n  summary = {\n    contract_version: 'agent_run_summary.v1',\n    source: 'n8n',\n    agent_run_id: 'n8n-ingest-' + Date.now(),\n    goal: 'Imported agent run',\n    outcome: 'success',\n    agent_claim: 'Task completed',\n    touched: { urls: [], api: [], tools: ['custom'], ui_actions: [] },\n    errors: [],\n  };\n}\nif (!summary.agent_run_id) summary.agent_run_id = 'n8n-ingest-' + Date.now();\nreturn [{ json: { ...cfg, summary } }];\n"
      }
    },
    {
      "id": "http2",
      "name": "Ingest AgentRunSummary",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ ($json.baseUrl || '').replace(/\\/$/, '') }}/api/web/v1/projects/{{ $json.projectId }}/unified-contexts/ingest/agent-run",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.apiKey }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ summary: $json.summary, upsert: true, generate_tests: false, max_tests: 6, include_ui_tests: true, include_api_tests: true }) }}",
        "options": {
          "timeout": 120000
        }
      }
    },
    {
      "id": "out2",
      "name": "Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1040,
        200
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "r1",
              "name": "ok",
              "value": "={{ Boolean($json.context_id) }}",
              "type": "boolean"
            },
            {
              "id": "r2",
              "name": "context_id",
              "value": "={{ $json.context_id }}",
              "type": "number"
            },
            {
              "id": "r3",
              "name": "entity_count",
              "value": "={{ $json.entity_count }}",
              "type": "number"
            },
            {
              "id": "r4",
              "name": "agent_run_id",
              "value": "={{ $json.agent_run_id }}",
              "type": "string"
            },
            {
              "id": "r5",
              "name": "recommended_next",
              "value": "={{ $json.recommended_next }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      }
    }
  ],
  "connections": {
    "When clicking Test workflow": {
      "main": [
        [
          {
            "node": "Edit Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Config": {
      "main": [
        [
          {
            "node": "Ensure summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure summary": {
      "main": [
        [
          {
            "node": "Ingest AgentRunSummary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ingest AgentRunSummary": {
      "main": [
        [
          {
            "node": "Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "testneo"
    },
    {
      "name": "ai-agent-verification"
    }
  ],
  "pinData": {}
}
