{
  "nodes": [
    {
      "parameters": {
        "public": true,
        "initialMessages": "Merhaba! 👋 FikoYT Üretim Yönetim Sistemi'ne hoş geldiniz.\n\n✨ YAPABILECEĞIM İŞLEMLER:\n• 📋 Proje ve sipariş yönetimi\n• 📦 Stok takibi (Strafor malzeme)\n• ⚙️ Üretim aşamaları planlaması\n• 🔧 CNC kuyruk yönetimi\n• 👥 Müşteri yönetimi\n• 📊 Kapasite ve kota takibi\n\n⚙️ KOMUTLAR: EKLE | GÜNCELLE | SIL | SORGULA\nℹ️ YARDIM: Komut yazarken 'pipe' (|) ile alanları ayırın.\n\nSizin için 7/24 buradayız! 🚀",
        "options": {
          "allowedOrigins": "*",
          "allowFileUploads": false,
          "inputPlaceholder": "Örn: EKLE sipariş | müşteri: M001 | ürün: Model",
          "showWelcomeScreen": true,
          "getStarted": "Başlayalım",
          "subtitle": "Akıllı Üretim Yönetim Asistanı",
          "title": "FikoYT Üretim Yönetim",
          "responseMode": "responseNodes"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.3,
      "position": [
        -784,
        -80
      ],
      "id": "756b2c2e-10f3-4871-a97a-8802b5540168",
      "name": "Chat Trigger",
      "webhookId": "b95e4bc4-159d-4eea-98a8-944843f71ae7"
    },
    {
      "parameters": {
        "modelId": "claude-3-5-sonnet-20241022",
        "messages": {
          "values": [
            {
              "content": "Sen FikoYT Üretim Yönetim Sistemi'nin yapay zeka asistanısın. Kullanıcı sorularına cevap ver, MongoDB işlemlerini yönet, sohbet tarzında konuş.\n\n📋 VERİ TABANINDA BULUNAN KOLEKSİYONLAR:\n- uyar_taslak_isler: Proje taslakları, iş planlaması\n- uyar_siparisler: Müşteri siparişleri, satış\n- uyar_stok_strafor: Strafor malzeme envanteri\n- uyar_uretim_adimlari: Üretim aşamaları, makine tahsisi\n- uyar_cnc_kuyruk: CNC makinesi kuyruk yönetimi\n- uyar_musteriler: Müşteri bilgileri\n- uyar_kota_bilgileri: Makine kapasitesi, hedef yönetimi\n- uyar_dosyalar: Proje dosyaları\n\n💬 KULLANICIYLA SOHBET ETME ŞEKLİ:\n- Normal ve samimi Türkçe konuş\n- Soruların varsa açıkla, rehberlik et\n- Komut yazmasını gerekirse örnekle\n\n⚡ KOMUT ÖRNEKLERİ:\n- EKLE uyar_siparisler | musteri_id: 123 | urun: \"Model A\" | adet: 5\n- SORGULA uyar_musteriler | sehir: \"İstanbul\"\n- GÜNCELLE uyar_siparisler | _id: 507f1f77bcf86cd799439011 | durum: \"üretimde\"\n- SIL uyar_siparisler | _id: 507f1f77bcf86cd799439011\n\n📤 YANIT FORMATI (KESIN JSON):\nEğer komut işleme gerekiyorsa:\n{\n  \"action\": \"insert|update|delete|find|aggregate|response\",\n  \"collection\": \"koleksiyon_adi\",\n  \"query\": {\"alan\": \"değer\"},\n  \"data\": {\"alan\": \"yeni_değer\"},\n  \"message\": \"Türkçe mesaj: İşlem açıklaması\"\n}\n\nEğer sadece sohbet ise:\n{\n  \"action\": \"response\",\n  \"collection\": \"\",\n  \"query\": {},\n  \"data\": {},\n  \"message\": \"Kullanıcıya samimi Türkçe cevap\"\n}\n\n🚨 ÖNEMLİ KURALLAR:\n- Komut tanımaya çalış, değilse sohbet tarzında cevap ver\n- Silme işlemi: soft delete yap (status: \"silindi\" ekle)\n- Eksik veri varsa uyar, işlem yapma\n- JSON'u her zaman kendi satırında başlat ve bitir\n- Hatalar veya bilmediğin şeyler için açık ol\n\nKullanıcı: {{ $json.chatInput }}"
            }
          ]
        },
        "simplify": "",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.anthropic",
      "typeVersion": 1,
      "position": [
        -176,
        -80
      ],
      "id": "16d7cede-f40f-4917-a32d-97c88906ba83",
      "name": "Claude AI - Komut İşleyici",
      "credentials": {
        "anthropicApi": {
          "id": "ZK13BlRtHBAO0eqz",
          "name": "Z.Ai Antrophic"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "MongoDB INSERT - Yeni kayıt ekle",
        "operation": "insert",
        "collection": "={{ $json.collection }}"
      },
      "type": "n8n-nodes-base.mongoDbTool",
      "typeVersion": 1.2,
      "position": [-720, 304],
      "id": "a2a22783-3762-4416-86f9-da6e2e5d034b",
      "name": "MongoDB - INSERT",
      "credentials": {
        "mongoDb": {"id": "WG6KsyXksE9VYndz", "name": "MongoDB account"}
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "MongoDB UPDATE - Kayıt güncelle",
        "operation": "update",
        "collection": "={{ $json.collection }}",
        "updateKey": "={{ Object.keys($json.query || {})[0] || '_id' }}",
        "updateKey2": "={{ Object.values($json.query || {})[0] }}"
      },
      "type": "n8n-nodes-base.mongoDbTool",
      "typeVersion": 1.2,
      "position": [-512, 288],
      "id": "5a2ea42d-a9fe-4e61-a809-b28f4f608eb3",
      "name": "MongoDB - UPDATE",
      "credentials": {
        "mongoDb": {"id": "WG6KsyXksE9VYndz", "name": "MongoDB account"}
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "MongoDB DELETE - Kayıt sil (soft delete)",
        "operation": "delete",
        "collection": "={{ $json.collection }}",
        "deleteKey": "={{ Object.keys($json.query || {})[0] || '_id' }}",
        "deleteKey2": "={{ Object.values($json.query || {})[0] }}"
      },
      "type": "n8n-nodes-base.mongoDbTool",
      "typeVersion": 1.2,
      "position": [-288, 288],
      "id": "e5f3a366-3d3f-4a54-8b1d-cdc20fae7544",
      "name": "MongoDB - DELETE",
      "credentials": {
        "mongoDb": {"id": "WG6KsyXksE9VYndz", "name": "MongoDB account"}
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "MongoDB FIND - Veri sorgula",
        "operation": "find",
        "collection": "={{ $json.collection }}",
        "query": "={{ $json.query || {} }}",
        "limit": 100
      },
      "type": "n8n-nodes-base.mongoDbTool",
      "typeVersion": 1.2,
      "position": [-112, 288],
      "id": "ea50517a-14c4-4365-a624-095c4c6b7593",
      "name": "MongoDB - FIND",
      "credentials": {
        "mongoDb": {"id": "WG6KsyXksE9VYndz", "name": "MongoDB account"}
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "MongoDB AGGREGATE - Rapor ve istatistik",
        "operation": "aggregate",
        "collection": "={{ $json.collection }}",
        "aggregationPipeline": "={{ [$json.query || {}] }}"
      },
      "type": "n8n-nodes-base.mongoDbTool",
      "typeVersion": 1.2,
      "position": [80, 288],
      "id": "52b1174a-25f8-4284-b1c5-274807da0068",
      "name": "MongoDB - AGGREGATE",
      "credentials": {
        "mongoDb": {"id": "WG6KsyXksE9VYndz", "name": "MongoDB account"}
      }
    },
    {
      "parameters": {
        "functionCode": "const result = $json;\nlet formatted = '';\n\n// AI'dan gelen JSON'u parse et\nlet parsed = null;\nlet aiText = '';\n\n// Eğer content[0].text varsa (Anthropic response)\nif (result.content && Array.isArray(result.content) && result.content[0]) {\n  aiText = result.content[0].text || '';\n} else if (typeof result === 'string') {\n  aiText = result;\n}\n\n// JSON bul ve parse et\nif (aiText) {\n  const jsonMatch = aiText.match(/\\{[\\s\\S]*\\}/);\n  if (jsonMatch) {\n    try {\n      parsed = JSON.parse(jsonMatch[0]);\n    } catch (e) {\n      parsed = null;\n    }\n  }\n}\n\n// Eğer parse başarısız olduysa, direkt mesaj gönder\nif (!parsed) {\n  return { message: aiText, status: 'success' };\n}\n\nconst action = parsed.action || 'response';\nconst msg = parsed.message || '';\n\n// Eğer action=\"response\" ise, direkt mesajı gönder\nif (action === 'response') {\n  return { message: msg, status: 'success' };\n}\n\n// Database işlemleri için emoji ekle\nif (action === 'insert') {\n  formatted = `✅ ${msg}\\n📌 Yeni kayıt eklendi.`;\n} else if (action === 'update') {\n  formatted = `✅ ${msg}\\n📊 Kayıt güncellendi.`;\n} else if (action === 'delete') {\n  formatted = `✅ ${msg}\\n🗑️ Kayıt silindi.`;\n} else if (action === 'find') {\n  formatted = `✅ ${msg}\\n📋 Sorgu sonuçlandı.`;\n} else if (action === 'aggregate') {\n  formatted = `✅ ${msg}\\n📊 Rapor hazırlandı.`;\n} else if (action === 'uyari') {\n  formatted = `⚠️ ${msg}`;\n} else {\n  formatted = msg;\n}\n\nreturn { message: formatted, status: 'success' };"
      },
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        304,
        -64
      ],
      "id": "9b302349-bc92-41d6-80ac-6a5bd531f50d",
      "name": "Yanıt Formatla"
    },
    {
      "parameters": {
        "message": "={{ $json.message || 'İşlem tamamlandı' }}",
        "waitUserReply": false,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chat",
      "typeVersion": 1,
      "position": [
        688,
        -128
      ],
      "id": "47007e62-5727-494a-8809-d2bcba1e8517",
      "name": "Yanıt Gönder"
    }
  ],
  "connections": {
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude AI - Komut İşleyici": {
      "main": [
        [
          {
            "node": "Yanıt Formatla",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB - INSERT": {
      "ai_tool": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB - UPDATE": {
      "ai_tool": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB - DELETE": {
      "ai_tool": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB - FIND": {
      "ai_tool": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB - AGGREGATE": {
      "ai_tool": [
        [
          {
            "node": "Claude AI - Komut İşleyici",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Yanıt Formatla": {
      "main": [
        [
          {
            "node": "Yanıt Gönder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "cf59b2e3a13e7cbbe4124cf8b1e8a4d09040d532706ee4198e7e3501e8cc3a79"
  }
}