{
  "name": "DEEPP AUTO P1 V3 - Worker (Back)",
  "nodes": [
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "chat_id"
            },
            {
              "name": "bot_id"
            },
            {
              "name": "image_paths"
            },
            {
              "name": "old_items"
            },
            {
              "name": "user_message"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.2,
      "position": [
        -1632,
        400
      ],
      "id": "105b8bcb-a83c-4731-9c9e-2661bfd4a9cd",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "jsCode": "// image_paths\u662fJSON\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u8def\u5f84\u9635\u5217,\u62c6\u6210\u4e2a\u522bitem,\n// \u8ba9Read/Write Files from Disk\u80fd\u9010\u4e00\u8bfb\u56de\u6bcf\u5f20\u539f\u56fe\nconst paths = JSON.parse($json.image_paths);\nreturn paths.map(p => ({ json: { path: p } }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1200,
        560
      ],
      "id": "a697a45c-1950-46c7-836a-5d5a85df4698",
      "name": "\u62c6\u89e3image_paths"
    },
    {
      "parameters": {
        "fileSelector": "={{ $json.path }}",
        "options": {}
      },
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        -960,
        560
      ],
      "id": "958db884-e77b-4ab4-ad46-cbc2400933d4",
      "name": "\u8bfb\u56de\u539f\u56fe"
    },
    {
      "parameters": {
        "jsCode": "const trigger = $('When Executed by Another Workflow').first().json;\nconst oldItems = JSON.parse(trigger.old_items);\nconst items = $input.all();\nconst parts = [];\n\nfor (let i = 0; i < items.length; i++) {\n  if (!items[i].binary || !items[i].binary.data) continue; // \u6ca1\u6709\u56fe\u7247\u53ef\u8bfb\u7684\u60c5\u51b5(\u7eaf\u6587\u5b57/Excel\u8d77\u70b9),\u8df3\u8fc7\n  const buffer = await this.helpers.getBinaryDataBuffer(i, 'data');\n  const base64Data = buffer.toString('base64');\n  const mimeType = items[i].binary.data.mimeType || 'image/jpeg';\n  parts.push({ inline_data: { mime_type: mimeType, data: base64Data } });\n}\n\nconst hasImages = parts.length > 0;\n\nconst promptText = `\u4f60\u662f\"Heng_MenuTransfer_bot\",\u4e13\u95e8\u5e2e\u52a9\u9910\u996e\u5546\u5bb6\u628a\u83dc\u5355\u8f6c\u6362\u6210POS\u7cfb\u7edf\u53ef\u5bfc\u5165\u7684Excel\u6587\u4ef6\u3002\n\n\u8fd9\u662f\u4e4b\u524d\u5df2\u7ecf\u8bc6\u522b\u51fa\u7684\u5546\u54c1\u6e05\u5355(\u53ef\u80fd\u8fd8\u4e0d\u5b8c\u6574,\u6216\u8005\u5546\u5bb6\u60f3\u8981\u8c03\u6574):\n${JSON.stringify(oldItems)}\n\n\u5546\u5bb6\u73b0\u5728\u8865\u5145/\u4fee\u6539\u7684\u5185\u5bb9\u662f:\n${trigger.user_message}\n\n${hasImages ? '\u8bf7\u7ed3\u5408\u4ee5\u4e0a\u539f\u59cb\u83dc\u5355\u56fe\u7247,\u91cd\u65b0\u5224\u65ad\u5e76\u8f93\u51fa\u5b8c\u6574\u3001\u66f4\u65b0\u540e\u7684\u5546\u54c1\u6e05\u5355\u3002' : '\u8bf7\u7ed3\u5408\u4ee5\u4e0a\u5df2\u8bc6\u522b\u7684\u5546\u54c1\u6e05\u5355\u548c\u5546\u5bb6\u7684\u8865\u5145\u5185\u5bb9,\u91cd\u65b0\u5224\u65ad\u5e76\u8f93\u51fa\u5b8c\u6574\u3001\u66f4\u65b0\u540e\u7684\u5546\u54c1\u6e05\u5355\u3002'}\n\u5224\u65adname\u3001category\u3001sell_price\u8fd9\u4e09\u4e2a\u680f\u4f4d,\u662f\u5426\u6bcf\u4e2a\u54c1\u9879\u90fd\u586b\u5f97\u51fa\u6765\u3002\n\n\u8bf7\u4e25\u683c\u53ea\u8f93\u51fa\u4ee5\u4e0bJSON\u683c\u5f0f,\u4e0d\u8981\u4efb\u4f55\u89e3\u91ca\u6587\u5b57\u3001\u4e0d\u8981markdown\u4ee3\u7801\u5757\u6807\u8bb0:\n{\n  \"status\": \"complete \u6216 incomplete\",\n  \"items\": [{\"name\":\"\u5546\u54c1\u540d\",\"category\":\"\u5206\u7c7b\",\"spec\":\"\u89c4\u683c\",\"stock_qty\":0,\"cost_price\":0,\"sell_price\":0.00}],\n  \"question\": \"\u53ea\u6709status\u662fincomplete\u65f6\u624d\u9700\u8981\u8fd9\u4e2a\u680f\u4f4d,\u9488\u5bf9\u6027\u5730\u95ee\u5546\u5bb6\u7f3a\u7684\u662f\u4ec0\u4e48\"\n}`;\n\nconst geminiRequest = { contents: [{ parts: [{ text: promptText }, ...parts] }] };\n\nreturn [{\n  json: { chat_id: trigger.chat_id, bot_id: trigger.bot_id, geminiRequest: geminiRequest }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -720,
        400
      ],
      "id": "7c69a424-2765-47ed-8cb0-bd7abe4c74df",
      "name": "\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpQueryAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.geminiRequest }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        400
      ],
      "id": "05885219-c78a-4b4e-befe-e5e6e2304d8a",
      "name": "HTTP Request \u76f4\u8fdeGemini",
      "credentials": {
        "httpQueryAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst chatId = $('\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42').first().json.chat_id;\nconst botId = $('\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42').first().json.bot_id;\n\nconst notifyFailure = async (reason) => {\n  await this.helpers.httpRequest({\n    method: 'POST',\n    url: `https://api.telegram.org/bot${$env.TELEGRAM_BOT_TOKEN}/sendMessage`,\n    headers: { 'Content-Type': 'application/json' },\n    body: { chat_id: chatId, text: `\u274c \u5904\u7406\u5931\u8d25:${reason}` },\n    json: true\n  });\n};\n\nif (item.error || !item.candidates || item.candidates.length === 0) {\n  const errMsg = item.error?.message || '';\n  let reason = 'AI \u670d\u52a1\u6682\u65f6\u51fa\u73b0\u95ee\u9898,\u8bf7\u7a0d\u540e\u91cd\u8bd5\u3002';\n  if (errMsg.includes('quota') || errMsg.includes('rate') || errMsg.includes('429')) {\n    reason = 'AI \u8bf7\u6c42\u6b21\u6570\u5df2\u8fbe\u4e0a\u9650,\u8bf7\u7b49\u5f85\u7ea61\u5206\u949f\u540e\u91cd\u65b0\u53d1\u9001\u3002';\n  } else if (errMsg.includes('unavailable') || errMsg.includes('overload') || errMsg.includes('high demand') || errMsg.includes('503')) {\n    reason = 'AI \u670d\u52a1\u5668\u76ee\u524d\u6d41\u91cf\u8fc7\u9ad8,\u8bf7\u7b49\u5f85\u7ea61\u5206\u949f\u540e\u91cd\u65b0\u53d1\u9001\u3002';\n  }\n  await notifyFailure(reason);\n  return [];\n}\n\nlet parsed;\ntry {\n  const rawText = item.candidates[0].content.parts[0].text;\n  const cleaned = rawText.replace(/```json\\n?/g, '').replace(/```\\n?/g, '').trim();\n  parsed = JSON.parse(cleaned);\n} catch (err) {\n  // Gemini\u5076\u5c14\u4f1a\u5939\u5e26\u89e3\u91ca\u6587\u5b57\u3001\u6216\u56de\u5e94\u7ed3\u6784\u8ddf\u9884\u671f\u4e0d\u4e00\u6837,JSON.parse\u4f1a\u76f4\u63a5throw,\n  // \u4e00\u5f8b\u63a5\u4f4f,\u4e0d\u8ba9\u6574\u4e2anode\u5d29\u6389\u3001\u5546\u5bb6\u6536\u4e0d\u5230\u4efb\u4f55\u56de\u5e94\n  await notifyFailure('AI\u56de\u5e94\u683c\u5f0f\u5f02\u5e38,\u8bf7\u91cd\u65b0\u53d1\u9001\u4e00\u6b21\u3002');\n  return [];\n}\n\nreturn [{\n  json: { chat_id: chatId, bot_id: botId, status: parsed.status, items: parsed.items || [], question: parsed.question || '' }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -240,
        400
      ],
      "id": "b73aa8c8-34ce-4848-a48d-82d6126ddacc",
      "name": "\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "1de3e9a9-4129-4e0f-ae7c-a2a0200d5f89",
              "leftValue": "={{ $json.status }}",
              "rightValue": "complete",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        0,
        400
      ],
      "id": "cd0ea9fb-6678-4a2a-a3bd-34716b8bfcee",
      "name": "\u662f\u5426\u4fe1\u606f\u5b8c\u6574(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "jsCode": "const decision = $('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json;\nconst imagePaths = $('When Executed by Another Workflow').first().json.image_paths; // \u56fe\u7247\u6ca1\u53d8,\u539f\u6837\u6cbf\u7528\n\nreturn [{\n  json: {\n    chat_id: decision.chat_id,\n    bot_id: decision.bot_id,\n    items: JSON.stringify(decision.items),\n    image_paths: imagePaths,\n    awaiting_modification: false // \u4fee\u6539\u662f\u4e00\u6b21\u6027\u7684,\u4e0d\u505aloop,\u5904\u7406\u5b8c\u5c31\u5f52\u96f6\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        208
      ],
      "id": "82926f10-1a8a-4269-80cc-1b7d31317075",
      "name": "\u7ec4\u88c5\u7eed\u7b54last_generation\u8d44\u6599"
    },
    {
      "parameters": {
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "value": "F8XZDNOad3tXgoQJ",
          "mode": "list",
          "cachedResultName": "last_generation"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "chat_id",
              "keyValue": "={{ $json.chat_id }}"
            },
            {
              "keyName": "bot_id",
              "keyValue": "={{ $json.bot_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "chat_id": "={{ $json.chat_id }}",
            "bot_id": "={{ $json.bot_id }}",
            "items": "={{ $json.items }}",
            "image_paths": "={{ $json.image_paths }}",
            "awaiting_modification": true,
            "flagged_at": "={{ new Date().toISOString() }}"
          },
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        480,
        208
      ],
      "id": "24848cb0-91be-4d57-b835-7f256c474d21",
      "name": "\u5199\u5165last_generation(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "value": "CZYbTzwR1b6Hn3fr",
          "mode": "id"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "=session_key",
              "keyValue": "={{ $('\u7ec4\u88c5\u7eed\u7b54last_generation\u8d44\u6599').first().json.bot_id }}_{{ $('\u7ec4\u88c5\u7eed\u7b54last_generation\u8d44\u6599').first().json.chat_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "awaiting_clarification": false
          },
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        720,
        208
      ],
      "id": "488d2dda-2311-4749-b7d7-6bfffadc2a69",
      "name": "\u6e05\u9664agent_sessions\u6807\u8bb0"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "5m7xS062vlea0Cv3",
          "mode": "list",
          "cachedResultName": "Tool - generate_excel_summary (V3)"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "chat_id": "={{ $('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.chat_id }}",
            "items": "={{ JSON.stringify($('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.items) }}",
            "usage_count": "={{ $('\u8fd8\u539f\u7eed\u7b54\u5224\u65ad\u7ed3\u679c').item.json.usage_count }}",
            "usage_limit": "={{ $('\u8fd8\u539f\u7eed\u7b54\u5224\u65ad\u7ed3\u679c').item.json.usage_limit }}"
          },
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {
          "waitForSubWorkflow": false
        }
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        960,
        208
      ],
      "id": "9533895c-e466-47dc-bbfa-7af8cc582f8d",
      "name": "Call 'Tool - generate_excel_summary'(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "YRTFbyL20UDGMdPX",
          "mode": "list",
          "cachedResultName": "Tool - ask_clarifying_question (V3)"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "chat_id": "={{ $('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.chat_id }}",
            "question": "={{ $('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.question }}",
            "context": "={{ JSON.stringify($('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.items) }}",
            "bot_id": "={{ $('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').first().json.bot_id }}",
            "image_paths": "={{ $('When Executed by Another Workflow').first().json.image_paths }}"
          },
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {
          "waitForSubWorkflow": false
        }
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.3,
      "position": [
        240,
        576
      ],
      "id": "37326a70-4059-419f-a531-a72ae0fff435",
      "name": "Call 'Tool - ask_clarifying_question'(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "5f19c648-f225-4d7f-84af-8fb28739c1c4",
              "leftValue": "={{ JSON.parse($json.image_paths).length }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -1440,
        400
      ],
      "id": "a077884a-05b3-401c-bd5d-3fdde0452b79",
      "name": "\u662f\u5426\u6709\u539f\u56fe"
    },
    {
      "parameters": {
        "jsCode": "// \u8ddfWorker(Front)\u7528\u540c\u4e00\u5957usage_key\u7b97\u6cd5,\u786e\u4fdd\u8bfb\u5199\u7684\u662f\u540c\u4e00\u4e2adaily_usage row\nconst now = new Date();\nconst malaysiaDate = new Intl.DateTimeFormat('en-CA', {\n  timeZone: 'Asia/Kuala_Lumpur',\n  year: 'numeric', month: '2-digit', day: '2-digit'\n}).format(now);\n\nconst trigger = $input.first().json;\nconst usageKey = `${trigger.bot_id}_${malaysiaDate}`;\n\nreturn [{\n  json: {\n    ...trigger,\n    usage_date: malaysiaDate,\n    usage_key: usageKey\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1632,
        160
      ],
      "id": "8af00be8-2bd4-4e93-b146-e1ba79b7f9b7",
      "name": "\u7b97\u51fausage_key(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "xe1tWUcTzVf19IBn",
          "mode": "list",
          "cachedResultName": "daily_usage"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "usage_key",
              "keyValue": "={{ $json.usage_key }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        -1412,
        160
      ],
      "id": "c59b88de-a520-4fa8-8942-b54e14e3a10b",
      "name": "\u67e5\u770busage_key(\u7eed\u7b54)",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "const usageRows = $input.all();\nconst currentCount = usageRows.length > 0 ? (usageRows[0].json.count || 0) : 0;\n\nconst THRESHOLD = 15; // \u8ddfWorker(Front)\u7528\u540c\u4e00\u4e2a\u4e0a\u9650\n\nconst sourceItems = $('\u7b97\u51fausage_key(\u7eed\u7b54)').all();\n\nfor (const item of sourceItems) {\n  item.json.current_count = currentCount;\n  item.json.over_limit = currentCount >= THRESHOLD;\n}\n\nreturn sourceItems;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1192,
        160
      ],
      "id": "6a9ae903-6e0e-432c-8c83-c3e561417616",
      "name": "\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "83782bab-28cf-4036-b9e2-29a672afc06d",
              "leftValue": "={{ $json.over_limit }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -972,
        160
      ],
      "id": "505e4141-580e-4856-85ea-bc582f79e426",
      "name": "\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/sendMessage",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "chat_id",
              "value": "={{ $json.chat_id }}"
            },
            {
              "name": "text",
              "value": "\u300c\u4eca\u65e5\u5904\u7406\u91cf\u5df2\u8fbe\u4e0a\u9650\uff0c\u8bf7\u660e\u5929\u518d\u8bd5 \ud83d\ude4f\u300d"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -972,
        340
      ],
      "id": "05689441-8987-421d-9434-e7b2fa1df09a",
      "name": "\u53d1\u9001\u7eed\u7b54\u989d\u5ea6\u5df2\u6ee1\u8baf\u606f"
    },
    {
      "parameters": {
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "value": "xe1tWUcTzVf19IBn",
          "mode": "list",
          "cachedResultName": "daily_usage"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "usage_key",
              "keyValue": "={{ $('\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)').first().json.usage_key }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "usage_key": "={{ $('\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)').first().json.usage_key }}",
            "bot_id": "={{ $('\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)').first().json.bot_id }}",
            "date": "={{ $('\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)').first().json.usage_date }}",
            "count": "={{ $('\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)').first().json.current_count + 1 }}"
          },
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        -20,
        400
      ],
      "id": "5ddd856a-d909-4122-9a76-4f5cc2e5bc11",
      "name": "\u589e\u52a0\u4eca\u65e5\u6b21\u6570(\u7eed\u7b54)"
    },
    {
      "parameters": {
        "jsCode": "return [{ json: { ...$('\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94').item.json, usage_count: $json.count, usage_limit: 15 } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        200,
        400
      ],
      "id": "8c8f3c11-6cb6-4338-ad04-99de8ea11a84",
      "name": "\u8fd8\u539f\u7eed\u7b54\u5224\u65ad\u7ed3\u679c"
    }
  ],
  "connections": {
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "\u7b97\u51fausage_key(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u62c6\u89e3image_paths": {
      "main": [
        [
          {
            "node": "\u8bfb\u56de\u539f\u56fe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u8bfb\u56de\u539f\u56fe": {
      "main": [
        [
          {
            "node": "\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42": {
      "main": [
        [
          {
            "node": "HTTP Request \u76f4\u8fdeGemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request \u76f4\u8fdeGemini": {
      "main": [
        [
          {
            "node": "\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u89e3\u6790\u7eed\u7b54Gemini\u56de\u5e94": {
      "main": [
        [
          {
            "node": "\u589e\u52a0\u4eca\u65e5\u6b21\u6570(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u662f\u5426\u4fe1\u606f\u5b8c\u6574(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u7ec4\u88c5\u7eed\u7b54last_generation\u8d44\u6599",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Call 'Tool - ask_clarifying_question'(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u7ec4\u88c5\u7eed\u7b54last_generation\u8d44\u6599": {
      "main": [
        [
          {
            "node": "\u5199\u5165last_generation(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u5199\u5165last_generation(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u6e05\u9664agent_sessions\u6807\u8bb0",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u6e05\u9664agent_sessions\u6807\u8bb0": {
      "main": [
        [
          {
            "node": "Call 'Tool - generate_excel_summary'(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u662f\u5426\u6709\u539f\u56fe": {
      "main": [
        [
          {
            "node": "\u62c6\u89e3image_paths",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u7ec4\u88c5\u7eed\u7b54Gemini\u8bf7\u6c42",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u7b97\u51fausage_key(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u67e5\u770busage_key(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u67e5\u770busage_key(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u5224\u65ad\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u662f\u5426\u591f\u6b21\u6570(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u662f\u5426\u6709\u539f\u56fe",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u53d1\u9001\u7eed\u7b54\u989d\u5ea6\u5df2\u6ee1\u8baf\u606f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u589e\u52a0\u4eca\u65e5\u6b21\u6570(\u7eed\u7b54)": {
      "main": [
        [
          {
            "node": "\u8fd8\u539f\u7eed\u7b54\u5224\u65ad\u7ed3\u679c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u8fd8\u539f\u7eed\u7b54\u5224\u65ad\u7ed3\u679c": {
      "main": [
        [
          {
            "node": "\u662f\u5426\u4fe1\u606f\u5b8c\u6574(\u7eed\u7b54)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "738f6f6a-27a6-4ad4-8266-ae4f1f4b0121",
  "nodeGroups": [],
  "id": "D8ZieXbOG7PGZDE2",
  "tags": [
    {
      "updatedAt": "2026-07-27T07:50:01.682Z",
      "createdAt": "2026-07-27T07:50:01.682Z",
      "id": "oulTjbe8ViVdh1V7",
      "name": "AUTO-P1-V3"
    },
    {
      "updatedAt": "2026-07-20T07:40:54.445Z",
      "createdAt": "2026-07-20T07:40:54.445Z",
      "id": "sBao71AvdSJ3hx2O",
      "name": "3FS"
    }
  ]
}