{
  "name": "\uc138\uc885 OS WF3 \u2014 AI \ud3ec\ub7fc \uc790\ub3d9\ud654",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "sejong-ai-forum",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "1. Webhook \uc218\uc2e0",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true
          },
          "conditions": [
            {
              "leftValue": "={{ $json.body.level }}",
              "rightValue": 2,
              "operator": {
                "type": "number",
                "operation": "lte"
              }
            }
          ]
        }
      },
      "id": "level-check",
      "name": "2. LEVEL \ub77c\uc6b0\ud130",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer ${OPENAI_API_KEY}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'gpt-4o', messages: [{ role: 'system', content: '\ub2f9\uc2e0\uc740 \uc138\uc885 OS AI \ud3ec\ub7fc \ucc38\uc5ec\uc790 GPT\uc785\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \uc548\uac74\uc5d0 \ub300\ud574 \ubd84\uc11d, \ucd94\ub860, \ub9ac\uc2a4\ud06c \ud3c9\uac00\ub97c \uc81c\uacf5\ud558\uace0 stance(AGREE/DISAGREE/NEUTRAL/CONDITIONAL) \uc911 \ud558\ub098\ub97c \uc120\ud0dd\ud558\uc138\uc694. JSON \ud615\uc2dd\uc73c\ub85c \uc751\ub2f5: {\"opinion\": \"...\", \"stance\": \"...\", \"confidence\": 0.0~1.0, \"risk_flags\": []}' }, { role: 'user', content: '\uc548\uac74: ' + $json.body.title + '\\n\ub0b4\uc6a9: ' + $json.body.content + '\\nAI\ucf54\ub4dc: ' + $json.body.ai_code + '\\n\ub808\ubca8: L' + $json.body.level }], temperature: 0.7, max_tokens: 500 }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "gpt-call",
      "name": "3a. GPT \uc758\uacac",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        100
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${GEMINI_API_KEY}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ contents: [{ parts: [{ text: '\ub2f9\uc2e0\uc740 \uc138\uc885 OS AI \ud3ec\ub7fc \ucc38\uc5ec\uc790 GEM\uc785\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \uc548\uac74\uc5d0 \ub300\ud574 \ubd84\uc11d, \ucd94\ub860, \ub9ac\uc2a4\ud06c \ud3c9\uac00\ub97c \uc81c\uacf5\ud558\uace0 stance(AGREE/DISAGREE/NEUTRAL/CONDITIONAL) \uc911 \ud558\ub098\ub97c \uc120\ud0dd\ud558\uc138\uc694. JSON \ud615\uc2dd\uc73c\ub85c \uc751\ub2f5: {\"opinion\": \"...\", \"stance\": \"...\", \"confidence\": 0.0~1.0, \"risk_flags\": []}\\n\\n\uc548\uac74: ' + $json.body.title + '\\n\ub0b4\uc6a9: ' + $json.body.content + '\\nAI\ucf54\ub4dc: ' + $json.body.ai_code + '\\n\ub808\ubca8: L' + $json.body.level }] }] }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "gem-call",
      "name": "3b. GEM \uc758\uacac",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        300
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "${ANTHROPIC_API_KEY}"
            },
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-sonnet-4-20250514', max_tokens: 500, messages: [{ role: 'user', content: '\ub2f9\uc2e0\uc740 \uc138\uc885 OS AI \ud3ec\ub7fc \ucc38\uc5ec\uc790 CLD\uc785\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \uc548\uac74\uc5d0 \ub300\ud574 \ubd84\uc11d, \ucd94\ub860, \ub9ac\uc2a4\ud06c \ud3c9\uac00\ub97c \uc81c\uacf5\ud558\uace0 stance(AGREE/DISAGREE/NEUTRAL/CONDITIONAL) \uc911 \ud558\ub098\ub97c \uc120\ud0dd\ud558\uc138\uc694. JSON \ud615\uc2dd\uc73c\ub85c \uc751\ub2f5: {\"opinion\": \"...\", \"stance\": \"...\", \"confidence\": 0.0~1.0, \"risk_flags\": []}\\n\\n\uc548\uac74: ' + $json.body.title + '\\n\ub0b4\uc6a9: ' + $json.body.content + '\\nAI\ucf54\ub4dc: ' + $json.body.ai_code + '\\n\ub808\ubca8: L' + $json.body.level }] }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "cld-call",
      "name": "3c. CLD \uc758\uacac",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        500
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "url": "https://api.x.ai/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer ${XAI_API_KEY}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'grok-3-mini', messages: [{ role: 'system', content: '\ub2f9\uc2e0\uc740 \uc138\uc885 OS AI \ud3ec\ub7fc \ucc38\uc5ec\uc790 GRK\uc785\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \uc548\uac74\uc5d0 \ub300\ud574 \ubd84\uc11d, \ucd94\ub860, \ub9ac\uc2a4\ud06c \ud3c9\uac00\ub97c \uc81c\uacf5\ud558\uace0 stance(AGREE/DISAGREE/NEUTRAL/CONDITIONAL) \uc911 \ud558\ub098\ub97c \uc120\ud0dd\ud558\uc138\uc694. JSON \ud615\uc2dd\uc73c\ub85c \uc751\ub2f5: {\"opinion\": \"...\", \"stance\": \"...\", \"confidence\": 0.0~1.0, \"risk_flags\": []}' }, { role: 'user', content: '\uc548\uac74: ' + $json.body.title + '\\n\ub0b4\uc6a9: ' + $json.body.content + '\\nAI\ucf54\ub4dc: ' + $json.body.ai_code + '\\n\ub808\ubca8: L' + $json.body.level }], temperature: 0.7, max_tokens: 500 }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "grk-call",
      "name": "3d. GRK \uc758\uacac",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        700
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "mode": "chooseBranch",
        "output": "waitAll"
      },
      "id": "merge-l1",
      "name": "4. \uc758\uacac \uc218\uc9d1 (L1-L2)",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        960,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.anthropic.com/v1/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-api-key",
              "value": "${ANTHROPIC_API_KEY}"
            },
            {
              "name": "anthropic-version",
              "value": "2023-06-01"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'claude-sonnet-4-20250514', max_tokens: 500, messages: [{ role: 'user', content: '\ub2f9\uc2e0\uc740 \uc138\uc885 OS AI \ud3ec\ub7fc \ucc38\uc5ec\uc790 CLD\uc785\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \uc548\uac74\uc5d0 \ub300\ud574 \ubd84\uc11d\ud558\uace0 stance\ub97c \uc120\ud0dd\ud558\uc138\uc694. JSON: {\"opinion\": \"...\", \"stance\": \"AGREE|DISAGREE|NEUTRAL|CONDITIONAL\", \"confidence\": 0.0~1.0, \"risk_flags\": []}\\n\\n\uc548\uac74: ' + $json.body.title + '\\n\ub0b4\uc6a9: ' + $json.body.content }] }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "cld-call-l3",
      "name": "3e. CLD \uc758\uacac (L3)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        900
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "url": "={{ $json.supabase_url }}/rest/v1/ai_opinions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{ $json.supabase_service_key }}"
            },
            {
              "name": "Authorization",
              "value": "Bearer {{ $json.supabase_service_key }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Prefer",
              "value": "return=representation"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.opinions_to_insert) }}",
        "options": {}
      },
      "id": "supabase-insert",
      "name": "5. Supabase INSERT",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://discord.com/api/webhooks/1497505700849647757/umhLsNYTt-axm06vaaZLZINsNZI1JKVbMGtzptmmCu52pmVrU7Gl7gVgaejhG_K1-CCq",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ embeds: [{ title: '\ud83c\udfdb\ufe0f AI \ud3ec\ub7fc \uc644\ub8cc \u2014 ' + $json.body.title, description: '**Record:** ' + $json.body.record_id + '\\n**Level:** L' + $json.body.level + '\\n**\ucc38\uc5ec AI:** ' + $json.forum_participants.join(', ') + '\\n**\ud569\uc758\ub3c4:** ' + $json.consensus_level + '/3\\n\\n\ud83d\udd17 [HMN \uc2b9\uc778 \ud398\uc774\uc9c0](https://unidlabs.ai/approve)', color: 6570239 }] }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "discord-forum",
      "name": "6a. Discord \ud3ec\ub7fc \uc54c\ub9bc",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        100
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "sendTo": "msm7949@gmail.com",
        "subject": "=\uc138\uc885 OS AI \ud3ec\ub7fc \uc644\ub8cc \u2014 {{ $json.body.title }}",
        "emailType": "text",
        "message": "=AI \ud3ec\ub7fc \uacb0\uacfc \ubcf4\uace0\n\nRecord: {{ $json.body.record_id }}\nLevel: L{{ $json.body.level }}\n\ucc38\uc5ec AI: {{ $json.forum_participants.join(', ') }}\n\ud569\uc758\ub3c4: {{ $json.consensus_level }}/3\n\nHMN \uc2b9\uc778 \ud398\uc774\uc9c0: https://unidlabs.ai/approve"
      },
      "id": "gmail-forum",
      "name": "6b. Gmail \ud3ec\ub7fc \uc54c\ub9bc",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1440,
        300
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.kakaowork.com/v1/messages.send",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer ${KAKAOWORK_APP_KEY}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ conversation_id: $json.kakao_conversation_id || 0, text: '\ud83c\udfdb\ufe0f AI \ud3ec\ub7fc \uc644\ub8cc\\n\\nRecord: ' + $json.body.record_id + '\\nLevel: L' + $json.body.level + '\\n\ucc38\uc5ec AI: ' + $json.forum_participants.join(', ') + '\\n\ud569\uc758\ub3c4: ' + $json.consensus_level + '/3\\n\\n\ud83d\udc49 https://unidlabs.ai/approve' }) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "kakao-forum",
      "name": "6c. \uce74\uce74\uc624\uc6cc\ud06c \ud3ec\ub7fc \uc54c\ub9bc",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1440,
        500
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, record_id: $json.body.record_id, forum_complete: true, participants: $json.forum_participants, consensus_level: $json.consensus_level }) }}"
      },
      "id": "respond",
      "name": "7. \uc751\ub2f5 \ubc18\ud658",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1700,
        300
      ]
    }
  ],
  "connections": {
    "1. Webhook \uc218\uc2e0": {
      "main": [
        [
          {
            "node": "2. LEVEL \ub77c\uc6b0\ud130",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. LEVEL \ub77c\uc6b0\ud130": {
      "main": [
        [
          {
            "node": "3a. GPT \uc758\uacac",
            "type": "main",
            "index": 0
          },
          {
            "node": "3b. GEM \uc758\uacac",
            "type": "main",
            "index": 0
          },
          {
            "node": "3c. CLD \uc758\uacac",
            "type": "main",
            "index": 0
          },
          {
            "node": "3d. GRK \uc758\uacac",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "3e. CLD \uc758\uacac (L3)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3a. GPT \uc758\uacac": {
      "main": [
        [
          {
            "node": "4. \uc758\uacac \uc218\uc9d1 (L1-L2)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3b. GEM \uc758\uacac": {
      "main": [
        [
          {
            "node": "4. \uc758\uacac \uc218\uc9d1 (L1-L2)",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "3c. CLD \uc758\uacac": {
      "main": [
        [
          {
            "node": "4. \uc758\uacac \uc218\uc9d1 (L1-L2)",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "3d. GRK \uc758\uacac": {
      "main": [
        [
          {
            "node": "4. \uc758\uacac \uc218\uc9d1 (L1-L2)",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "4. \uc758\uacac \uc218\uc9d1 (L1-L2)": {
      "main": [
        [
          {
            "node": "5. Supabase INSERT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3e. CLD \uc758\uacac (L3)": {
      "main": [
        [
          {
            "node": "5. Supabase INSERT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Supabase INSERT": {
      "main": [
        [
          {
            "node": "6a. Discord \ud3ec\ub7fc \uc54c\ub9bc",
            "type": "main",
            "index": 0
          },
          {
            "node": "6b. Gmail \ud3ec\ub7fc \uc54c\ub9bc",
            "type": "main",
            "index": 0
          },
          {
            "node": "6c. \uce74\uce74\uc624\uc6cc\ud06c \ud3ec\ub7fc \uc54c\ub9bc",
            "type": "main",
            "index": 0
          },
          {
            "node": "7. \uc751\ub2f5 \ubc18\ud658",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Seoul"
  },
  "tags": [
    {
      "name": "\uc138\uc885OS"
    },
    {
      "name": "AI\ud3ec\ub7fc"
    }
  ]
}