{
  "name": "ClaraAI - Pipeline V2 (Onboarding Call)",
  "nodes": [
    {
      "id": "v2-01",
      "name": "Form - Start V2",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        240,
        300
      ],
      "parameters": {
        "formTitle": "ClaraAI - Account Update (V2 Onboarding Call)",
        "formDescription": "Select the existing account and upload the onboarding call recording.",
        "path": "clara-pipeline-v2",
        "responseMode": "lastNode",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Account ID",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "bens-electric-solutions"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "Onboarding Video",
              "fieldType": "file",
              "requiredField": true,
              "acceptFileTypes": ".mp4,.mov,.avi,.webm,.m4v,.mkv,.m4a,.mp3"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "v2-02",
      "name": "Save Video",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const fs   = require('fs');\nconst path = require('path');\n\nconst ROOT        = 'C:/Users/Admin/OneDrive/Desktop/ClaraAi';\nconst PYTHON_EXE  = 'C:/Users/Admin/AppData/Local/Programs/Python/Python312/python.exe';\nconst SCRIPT_PATH = ROOT + '/scripts/pipeline.py';\n\nconst formJson    = $input.first().json;\nconst inputBinary = $input.first().binary || {};\n\nconst accountId = String(formJson['Account ID'] || '').trim();\nif (!accountId) throw new Error('Account ID is required.');\n\n// Validate v1 outputs exist before running v2\nconst v1Memo = path.join(ROOT, 'outputs', 'accounts', accountId, 'v1', 'memo.json');\nconst v1Spec = path.join(ROOT, 'outputs', 'accounts', accountId, 'v1', 'spec.json');\nif (!fs.existsSync(v1Memo)) throw new Error('v1 memo.json not found for: ' + accountId + '. Run V1 first.');\nif (!fs.existsSync(v1Spec)) throw new Error('v1 spec.json not found for: ' + accountId + '. Run V1 first.');\n\nconst videoKey = Object.keys(inputBinary)[0];\nif (!videoKey) throw new Error('No video file found. Please attach a video.');\n\nconst videoFile = inputBinary[videoKey];\nconst ext       = (path.extname(videoFile.fileName || 'onboarding.mp4').toLowerCase()) || '.mp4';\nconst videoPath = path.join(ROOT, 'dataset', accountId, 'onboarding' + ext);\n\nfs.mkdirSync(path.dirname(videoPath), { recursive: true });\nfs.writeFileSync(videoPath, Buffer.from(videoFile.data, 'base64'));\nconsole.log('Video saved: ' + videoPath);\n\nreturn [{ json: { accountId, ROOT, PYTHON_EXE, SCRIPT_PATH } }];"
      }
    },
    {
      "id": "v2-03",
      "name": "Run Pipeline V2",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        760,
        300
      ],
      "parameters": {
        "command": "={{ '\"' + $json.PYTHON_EXE + '\" \"' + $json.SCRIPT_PATH + '\" --account-id ' + $json.accountId + ' --version v2' }}"
      }
    },
    {
      "id": "v2-04",
      "name": "Done",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1020,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const c   = $('Save Video').first().json;\nconst out = $input.first().json;\nreturn [{ json: {\n  status:  'complete',\n  account: c.accountId,\n  message: 'V2 pipeline done for ' + c.accountId,\n  outputs: {\n    transcript: c.ROOT + '/outputs/accounts/' + c.accountId + '/v2/transcripts/onboarding.txt',\n    memo:       c.ROOT + '/outputs/accounts/' + c.accountId + '/v2/memo.json',\n    spec:       c.ROOT + '/outputs/accounts/' + c.accountId + '/v2/spec.json'\n  },\n  stdout: out.stdout || '',\n  stderr: out.stderr || ''\n} }];"
      }
    }
  ],
  "connections": {
    "Form - Start V2": {
      "main": [
        [
          {
            "node": "Save Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Video": {
      "main": [
        [
          {
            "node": "Run Pipeline V2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Pipeline V2": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "versionId": "clara-v2-simple"
}