{
    "name": "n8n Workflow Analyzer and Vector Storage System",
    "nodes": [
        {
            "parameters": {
                "operation": "executeQuery",
                "query": "SELECT file_id, last_processed_time FROM processed_workflows WHERE file_id = '{{ $json.id }}'",
                "options": []
            },
            "type": "n8n-nodes-base.postgres",
            "typeVersion": 2.5,
            "position": [
                448,
                224
            ],
            "id": "b2c3d4e5-f6a7-8901-bcde-f23456789012",
            "name": "Check Last Processing",
            "alwaysOutputData": false,
            "credentials": {
                "postgres": {
                    "id": "VrRSp705gu0IHQy1",
                    "name": "Postgres account"
                }
            }
        },
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": true,
                        "leftValue": "",
                        "typeValidation": "strict",
                        "version": 1
                    },
                    "conditions": [
                        {
                            "leftValue": "={{ $json.last_processed_time }}",
                            "rightValue": "={{ $('Monitor Google Drive Folder').item.json.modifiedTime }}",
                            "operator": {
                                "type": "dateTime",
                                "operation": "before"
                            },
                            "id": "81e60ef5-0b4c-4914-a116-f22c875597f3"
                        },
                        {
                            "leftValue": "={{ $json.file_id }}",
                            "rightValue": "",
                            "operator": {
                                "type": "string",
                                "operation": "isEmpty"
                            },
                            "id": "2c7a184e-0de9-4a07-af5d-1ff73c3d0e25"
                        }
                    ],
                    "combinator": "or"
                },
                "options": []
            },
            "type": "n8n-nodes-base.if",
            "typeVersion": 2,
            "position": [
                672,
                224
            ],
            "id": "c3d4e5f6-a7b8-9012-cdef-345678901234",
            "name": "Is New or Updated?"
        },
        {
            "parameters": {
                "operation": "download",
                "fileId": {
                    "__rl": true,
                    "value": "={{ $('Monitor Google Drive Folder').item.json.id }}",
                    "mode": "id"
                },
                "options": {
                    "googleFileConversion": {
                        "conversion": {
                            "docsToFormat": "text\/plain"
                        }
                    }
                }
            },
            "type": "n8n-nodes-base.googleDrive",
            "typeVersion": 3,
            "position": [
                896,
                224
            ],
            "id": "d4e5f6a7-b8c9-0123-defa-456789012345",
            "name": "Download Workflow File",
            "credentials": {
                "googleDriveOAuth2Api": {
                    "id": "nKh5LI6YI2OZjJaw",
                    "name": "Google Drive account"
                }
            }
        },
        {
            "parameters": {
                "jsCode": "\/\/ تحليل محتوى workflow JSON\nconst workflowContent = JSON.parse($input.first().json.data);\n\n\/\/ استخراج metadata\nconst metadata = {\n  fileId: $('Monitor Google Drive Folder').item.json.id,\n  fileName: $('Monitor Google Drive Folder').item.json.name,\n  modifiedTime: $('Monitor Google Drive Folder').item.json.modifiedTime,\n  workflowName: workflowContent.name || 'Unnamed Workflow',\n  nodeCount: workflowContent.nodes?.length || 0,\n  nodes: [],\n  connections: workflowContent.connections || {},\n  categories: [],\n  applications: new Set(),\n  workflowType: ''\n};\n\n\/\/ تحليل العقد\nif (workflowContent.nodes) {\n  workflowContent.nodes.forEach(node => {\n    const nodeInfo = {\n      name: node.name,\n      type: node.type,\n      parameters: node.parameters\n    };\n    metadata.nodes.push(nodeInfo);\n    \n    \/\/ استخراج التطبيقات المستخدمة\n    if (node.type.includes('gmail')) metadata.applications.add('Gmail');\n    if (node.type.includes('webhook')) metadata.applications.add('Webhook');\n    if (node.type.includes('httpRequest')) metadata.applications.add('HTTP Request');\n    if (node.type.includes('googleDrive')) metadata.applications.add('Google Drive');\n    if (node.type.includes('postgres')) metadata.applications.add('PostgreSQL');\n    if (node.type.includes('agent')) metadata.applications.add('AI Agent');\n    if (node.type.includes('pinecone')) metadata.applications.add('Pinecone');\n  });\n}\n\n\/\/ تصنيف workflow\nconst nodeTypes = metadata.nodes.map(n => n.type).join(' ');\n\nif (nodeTypes.includes('trigger')) {\n  metadata.categories.push('Triggered Automations');\n}\nif (nodeTypes.includes('agent') || nodeTypes.includes('ai')) {\n  metadata.categories.push('AI Workflows');\n}\nif (nodeTypes.includes('database') || nodeTypes.includes('postgres')) {\n  metadata.categories.push('Data Pipelines');\n}\nif (nodeTypes.includes('email') || nodeTypes.includes('gmail')) {\n  metadata.categories.push('Email Automations');\n}\nif (nodeTypes.includes('webhook')) {\n  metadata.categories.push('API Integrations');\n}\n\n\/\/ تحديد نوع العمل الرئيسي\nif (metadata.categories.length > 0) {\n  metadata.workflowType = metadata.categories[0];\n} else {\n  metadata.workflowType = 'General Automation';\n}\n\nmetadata.applications = Array.from(metadata.applications);\n\nreturn {\n  metadata: metadata,\n  fullWorkflow: workflowContent\n};"
            },
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                1120,
                224
            ],
            "id": "e5f6a7b8-c9d0-1234-efab-567890123456",
            "name": "Analyze Workflow Structure"
        },
        {
            "parameters": {
                "model": "text-embedding-3-large",
                "options": []
            },
            "type": "@n8n\/n8n-nodes-langchain.embeddingsOpenAi",
            "typeVersion": 1,
            "position": [
                1344,
                240
            ],
            "id": "f6a7b8c9-d0e1-2345-fabc-678901234567",
            "name": "Create Embeddings",
            "credentials": {
                "openAiApi": {
                    "id": "XMEsLBYvPf9TQsy0",
                    "name": "OpenAi account"
                }
            }
        },
        {
            "parameters": {
                "jsCode": "\/\/ إعداد البيانات لـ Pinecone\nconst metadata = $input.first().json.metadata;\nconst fullWorkflow = $input.first().json.fullWorkflow;\n\n\/\/ إنشاء نص وصفي للـ embedding\nconst descriptionText = `\nWorkflow Name: ${metadata.workflowName}\nType: ${metadata.workflowType}\nCategories: ${metadata.categories.join(', ')}\nApplications: ${metadata.applications.join(', ')}\nNodes: ${metadata.nodes.map(n => `${n.name} (${n.type})`).join(', ')}\nNode Count: ${metadata.nodeCount}\n`;\n\n\/\/ إعداد البيانات للتخزين\nconst vectorData = {\n  id: metadata.fileId,\n  text: descriptionText,\n  metadata: {\n    fileId: metadata.fileId,\n    fileName: metadata.fileName,\n    workflowName: metadata.workflowName,\n    workflowType: metadata.workflowType,\n    categories: metadata.categories,\n    applications: metadata.applications,\n    nodeCount: metadata.nodeCount,\n    modifiedTime: metadata.modifiedTime,\n    nodeTypes: metadata.nodes.map(n => n.type),\n    workflowJson: JSON.stringify(fullWorkflow)\n  }\n};\n\nreturn vectorData;"
            },
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                1552,
                224
            ],
            "id": "a7b8c9d0-e1f2-3456-abcd-789012345678",
            "name": "Prepare Vector Data"
        },
        {
            "parameters": {
                "pineconeIndex": {
                    "__rl": true,
                    "mode": "list",
                    "value": ""
                },
                "options": []
            },
            "type": "@n8n\/n8n-nodes-langchain.vectorStorePinecone",
            "typeVersion": 1,
            "position": [
                1776,
                240
            ],
            "id": "b8c9d0e1-f2a3-4567-bcde-890123456789",
            "name": "Store in Pinecone",
            "credentials": {
                "pineconeApi": {
                    "id": "4",
                    "name": "Pinecone Account"
                }
            }
        },
        {
            "parameters": {
                "operation": "executeQuery",
                "query": "INSERT INTO processed_workflows (file_id, file_name, workflow_name, workflow_type, categories, last_processed_time, node_count)\nVALUES (\n  '{{ $json.metadata.fileId }}',\n  '{{ $json.metadata.fileName }}',\n  '{{ $json.metadata.workflowName }}',\n  '{{ $json.metadata.workflowType }}',\n  '{{ $json.metadata.categories.join(\",\") }}',\n  '{{ $json.metadata.modifiedTime }}',\n  {{ $json.metadata.nodeCount }}\n)\nON CONFLICT (file_id) DO UPDATE SET\n  file_name = EXCLUDED.file_name,\n  workflow_name = EXCLUDED.workflow_name,\n  workflow_type = EXCLUDED.workflow_type,\n  categories = EXCLUDED.categories,\n  last_processed_time = EXCLUDED.last_processed_time,\n  node_count = EXCLUDED.node_count;",
                "options": []
            },
            "type": "n8n-nodes-base.postgres",
            "typeVersion": 2.5,
            "position": [
                2144,
                224
            ],
            "id": "c9d0e1f2-a3b4-5678-cdef-901234567890",
            "name": "Update Processing Record",
            "credentials": {
                "postgres": {
                    "id": "VrRSp705gu0IHQy1",
                    "name": "Postgres account"
                }
            }
        },
        {
            "parameters": {
                "operation": "sendPlainText"
            },
            "type": "n8n-nodes-base.telegram",
            "typeVersion": 1.2,
            "position": [
                2368,
                224
            ],
            "id": "d0e1f2a3-b4c5-6789-defa-012345678901",
            "name": "Send Success Notification",
            "webhookId": "22aad1d2-4c07-4bbe-b102-a456a90f7fbb",
            "credentials": {
                "telegramApi": {
                    "id": "5",
                    "name": "Telegram Bot"
                }
            }
        },
        {
            "parameters": {
                "resource": "fileFolder",
                "returnAll": true,
                "filter": {
                    "folderId": {
                        "__rl": true,
                        "value": "1VElyeAJkNuQgp4D7nHJRPSsuGT2YxnKy",
                        "mode": "list",
                        "cachedResultName": "n8n workflow",
                        "cachedResultUrl": "https:\/\/drive.google.com\/drive\/folders\/1VElyeAJkNuQgp4D7nHJRPSsuGT2YxnKy"
                    }
                },
                "options": []
            },
            "type": "n8n-nodes-base.googleDrive",
            "typeVersion": 3,
            "position": [
                192,
                224
            ],
            "id": "a2d51ed6-f54e-4612-8c75-6916fad23a56",
            "name": "Search files and folders",
            "credentials": {
                "googleDriveOAuth2Api": {
                    "id": "nKh5LI6YI2OZjJaw",
                    "name": "Google Drive account"
                }
            }
        }
    ],
    "pinData": [],
    "connections": {
        "Check Last Processing": {
            "main": [
                [
                    {
                        "node": "Is New or Updated?",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Is New or Updated?": {
            "main": [
                [
                    {
                        "node": "Download Workflow File",
                        "type": "main",
                        "index": 0
                    }
                ],
                []
            ]
        },
        "Download Workflow File": {
            "main": [
                [
                    {
                        "node": "Analyze Workflow Structure",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Analyze Workflow Structure": {
            "main": [
                [
                    {
                        "node": "Create Embeddings",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Create Embeddings": {
            "main": [
                [
                    {
                        "node": "Prepare Vector Data",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Prepare Vector Data": {
            "main": [
                [
                    {
                        "node": "Store in Pinecone",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Store in Pinecone": {
            "main": [
                [
                    {
                        "node": "Update Processing Record",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Update Processing Record": {
            "main": [
                [
                    {
                        "node": "Send Success Notification",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Search files and folders": {
            "main": [
                [
                    {
                        "node": "Check Last Processing",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "active": false,
    "settings": {
        "executionOrder": "v1",
        "saveManualExecutions": true,
        "saveDataSuccessExecution": "all",
        "saveExecutionProgress": true,
        "saveDataErrorExecution": "all",
        "errorWorkflow": "",
        "timezone": "Asia\/Riyadh"
    },
    "versionId": "d9112801-7be0-4f27-b416-7eed830c004e",
    "meta": {
        "templateCredsSetupCompleted": true,
        "instanceId": "a85fc6519b374e86e01063acbb733de8f006266ec78aa34c0f3dbebd8434a16e"
    },
    "id": "5Zc25JTudhZVKqIc",
    "tags": []
}