{
  "version": 2,
  "nodes": [
    {
      "id": "start",
      "type": "start",
      "name": "开始",
      "position": {
        "x": 0,
        "y": 0
      },
      "config": {
        "inputs": [
          {
            "key": "message",
            "label": "咨询主题",
            "dataType": "string",
            "required": true
          }
        ]
      }
    },
    {
      "id": "code",
      "type": "code",
      "name": "整理咨询主题",
      "position": {
        "x": 290,
        "y": 0
      },
      "config": {
        "language": "javascript",
        "code": "function main(params) {\n  const items = params.message.split(/[,，]/).map(item => item.trim()).filter(Boolean);\n  return { items: items, total: items.length, summary: \"青禾咨询：\" + items.length + \"项\" };\n}"
      },
      "inputs": [
        {
          "key": "message",
          "dataType": "string",
          "value": "{{start.message}}"
        }
      ],
      "outputs": [
        {
          "key": "items",
          "dataType": "array"
        },
        {
          "key": "total",
          "dataType": "number"
        },
        {
          "key": "summary",
          "dataType": "string"
        }
      ]
    },
    {
      "id": "assign",
      "type": "assign",
      "name": "更新咨询摘要",
      "position": {
        "x": 580,
        "y": 0
      },
      "config": {
        "items": [
          {
            "target": "start.message",
            "valueType": "reference",
            "value": "code.summary"
          }
        ]
      }
    },
    {
      "id": "loop_batch",
      "type": "loop",
      "name": "逐项生成记录",
      "position": {
        "x": 870,
        "y": 0
      },
      "config": {
        "source": "{{code.items}}",
        "maxIterations": 10,
        "breakCondition": "",
        "body": {
          "nodes": [
            {
              "id": "render_item",
              "type": "template",
              "name": "主题记录",
              "position": {
                "x": 0,
                "y": 0
              },
              "config": {
                "template": "{{loop.item}}（索引 {{loop.index}}）"
              }
            }
          ],
          "edges": []
        }
      }
    },
    {
      "id": "call_receipt",
      "type": "subflow",
      "name": "生成受理回执",
      "position": {
        "x": 1160,
        "y": 0
      },
      "config": {
        "appId": "咨询受理流程主键",
        "mappings": [
          {
            "source": "{{start.message}}",
            "target": "message"
          }
        ]
      },
      "outputs": [
        {
          "key": "answer",
          "dataType": "string"
        },
        {
          "key": "result",
          "dataType": "object"
        },
        {
          "key": "tokens",
          "dataType": "number"
        }
      ]
    },
    {
      "id": "end",
      "type": "end",
      "name": "结束",
      "position": {
        "x": 1450,
        "y": 0
      },
      "config": {
        "output": {
          "mode": "variables"
        }
      },
      "inputs": [
        {
          "key": "topics",
          "dataType": "array",
          "value": "{{loop_batch.results}}"
        },
        {
          "key": "count",
          "dataType": "number",
          "value": "{{loop_batch.count}}"
        },
        {
          "key": "message",
          "dataType": "string",
          "value": "{{start.message}}"
        },
        {
          "key": "answer",
          "dataType": "string",
          "value": "{{call_receipt.answer}}"
        }
      ]
    }
  ],
  "edges": [
    {
      "id": "start-code",
      "source": "start",
      "target": "code",
      "sourceHandle": "out",
      "targetHandle": "in"
    },
    {
      "id": "code-assign",
      "source": "code",
      "target": "assign",
      "sourceHandle": "out",
      "targetHandle": "in"
    },
    {
      "id": "assign-loop_batch",
      "source": "assign",
      "target": "loop_batch",
      "sourceHandle": "out",
      "targetHandle": "in"
    },
    {
      "id": "loop_batch-call_receipt",
      "source": "loop_batch",
      "target": "call_receipt",
      "sourceHandle": "out",
      "targetHandle": "in"
    },
    {
      "id": "call_receipt-end",
      "source": "call_receipt",
      "target": "end",
      "sourceHandle": "out",
      "targetHandle": "in"
    }
  ]
}
