wujingjing
2024-12-16 10ab6a46af767c69c290e9baf07079910e282a4e
src/components/vue-flow/VueFlowHelper.ts
@@ -19,6 +19,10 @@
      };
      switch (type) {
         case NodeType.Start:
            data = {
               ...data,
               description: '工作流运行的起始节点。',
            };
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  [VueFlowConstant.PARAMS_KEY]: [
@@ -32,7 +36,17 @@
               },
            ];
            break;
         case NodeType.End:
            data = {
               ...data,
               description: '工作流运行到此结束。',
            };
            break;
         case NodeType.Condition:
            data = {
               ...data,
               description: '根据条件表达式执行不同的分支。',
            };
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  [VueFlowConstant.PARAMS_KEY]: [
@@ -40,13 +54,17 @@
                        key: 'condition',
                        label: '',
                        type: 'condition',
                        value: [ConditionHelper.getDefaultConditionGroup(),ConditionHelper.getDefaultConditionGroup(true)],
                        value: [ConditionHelper.getDefaultConditionGroup(), ConditionHelper.getDefaultConditionGroup(true)],
                     },
                  ],
               },
            ];
            break;
         case NodeType.LLM:
            data = {
               ...data,
               description: '调用大模型回答用户问题或者处理任务。',
            };
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  name: '模型设置',
@@ -65,29 +83,101 @@
               },
               {
                  name: '提示词',
                  [VueFlowConstant.PARAMS_KEY]: [{ key: 'prompt', label: '提示词', type: 'textarea', value: '' }],
                  [VueFlowConstant.PARAMS_KEY]: [{ key: 'prompt', label: '', type: 'textarea', value: '' }],
               },
            ];
            break;
         case NodeType.Code:
            data = {
               ...data,
               description: '自定义需要执行的代码。',
               [VueFlowConstant.GROUP_PARAMS_KEY]: [
                  {
                     name: '入参',
                     [VueFlowConstant.PARAMS_KEY]: [
                        {
                           key: 'code_input',
                           type: 'code_input',
                           required: true,
                           value: [
                              { key: 'arg1', type: 'input', label: '', value: '' },
                              { key: 'arg2', type: 'input', label: '', value: '' },
                           ],
                        },
                     ],
                  },
                  {
                     name: '执行代码',
                     [VueFlowConstant.PARAMS_KEY]: [
                        {
                           key: 'code',
                           type: 'code',
                           required: true,
                           value: 'const main = (arg1, arg2) =>{\n  return {\n    result1: arg1,\n    result2: arg2\n  }\n}',
                        },
                     ],
                  },
                  {
                     name: '出参',
                     [VueFlowConstant.PARAMS_KEY]: [
                        {
                           key: 'code_output',
                           type: 'code_output',
                           // global: 'code:value.map(el => ({ label: el.key, value: el.key }))',
                           required: true,
                           value: [
                              { key: 'result1', type: 'string' },
                              { key: 'result2', type: 'string' },
                           ],
                        },
                     ],
                  },
               ],
            };
            break;
         case NodeType.Agent:
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  name: '代理名称',
                  [VueFlowConstant.PARAMS_KEY]: [
                     {
                        key: 'agent',
                        label: '代理',
                        label: '',
                        type: 'agent_select',
                        value: '',
                        // value_label:'',
                        required: true,
                        placeholder: '代理',
                        placeholder: '代理名称',
                     },
                  ],
               },
            ];
            break;
         case NodeType.Func:
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  name: '函数名称',
                  [VueFlowConstant.PARAMS_KEY]: [
                     {
                        key: 'func_name',
                        label: '',
                        type: 'func_name_select',
                        value: '',
                        // value_label:'',
                        required: true,
                        placeholder: '函数名称',
                     },
                  ],
               },
            ];
            break;
         case NodeType.Output:
            data = {
               ...data,
               description:
                  '可向用户发送消息,并且支持进行更丰富的交互,例如请求用户批准进行某项敏感操作、允许用户在模型输出内容的基础上直接修改并提交。',
            };
            data[VueFlowConstant.GROUP_PARAMS_KEY] = [
               {
                  [VueFlowConstant.PARAMS_KEY]: [
@@ -117,6 +207,22 @@
            break;
      }
      return data;
   };
   /**
    * 强制写入到配置信息中,用于 patch 过去版本中没有的字段,或字段名称已经修改
    *
    * 版本稳定后可删除此方法
    * @param obj
    * @param key
    * @param val
    */
   static getConfigValue = (obj: any, key: string, val: string) => {
      const value = obj[key];
      if (!value || value !== val) {
         obj[key] = val;
      }
      return val;
   };
   static getHandleId = (node: any, handleType: HandleType, order?: number) => {
@@ -212,9 +318,7 @@
         : {
               id: VueFlowHelper.genId(),
               operator: ConditionOperator.And,
               conditions: [
                  ConditionHelper.getConditionItem()
               ],
               conditions: [ConditionHelper.getConditionItem()],
           };
   };
}