| | |
| | | import { HandleType, useNode, useVueFlow } from '@vue-flow/core'; |
| | | import type { HandleType } from '@vue-flow/core'; |
| | | import { v4 as uuid } from 'uuid'; |
| | | import { VueFlowConstant } from './VueFlowConstant'; |
| | | import { CompareOperation, ConditionOperator, NodeType, VarType, nodeTypeMap } from './vueFlowEnum'; |
| | | import { get } from 'lodash'; |
| | | import type { CompareOperation } from './vueFlowEnum'; |
| | | import { ConditionOperator, NodeType, VarType, nodeTypeMap } from './vueFlowEnum'; |
| | | |
| | | export class VueFlowHelper { |
| | | static genId() { |
| | |
| | | description: '调用大模型回答用户问题或者处理任务。', |
| | | }; |
| | | data[VueFlowConstant.GROUP_PARAMS_KEY] = [ |
| | | |
| | | { |
| | | name: '模型设置', |
| | | |
| | |
| | | name: '提示词', |
| | | [VueFlowConstant.PARAMS_KEY]: [{ key: 'prompt', label: '', type: 'textarea', value: '' }], |
| | | }, |
| | | { |
| | | name: '输出参数名', |
| | | [VueFlowConstant.PARAMS_KEY]: [{ key: 'key', type: 'input', value: '' }], |
| | | }, |
| | | ]; |
| | | break; |
| | | |
| | | case NodeType.Analysis: |
| | | data = { |
| | | ...data, |
| | | description: '', |
| | | }; |
| | | data[VueFlowConstant.GROUP_PARAMS_KEY] = [ |
| | | { |
| | | name: '分析设置', |
| | | |
| | | [VueFlowConstant.PARAMS_KEY]: [ |
| | | { |
| | | key: 'llm_model', |
| | | label: '模型', |
| | | type: 'llm_model', |
| | | value: '', |
| | | required: true, |
| | | placeholder: '请选择模型', |
| | | }, |
| | | { key: 'temperature', label: '温度', type: 'slide', scope: [0, 2], step: 0.1, value: 0.6 }, |
| | | ], |
| | | }, |
| | | { |
| | | name: '提示词', |
| | | [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}', |
| | | language: ['text', 'javascript'], |
| | | defaultLanguage: 'javascript', |
| | | }, |
| | | ], |
| | | }, |
| | | { |
| | | 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.TextResource: |
| | | data = { |
| | | ...data, |
| | | // description: '自定义需要执行的代码。', |
| | | [VueFlowConstant.GROUP_PARAMS_KEY]: [ |
| | | { |
| | | name: '参数名', |
| | | [VueFlowConstant.PARAMS_KEY]: [ |
| | | { |
| | | key: 'key', |
| | | type: 'input', |
| | | required: true, |
| | | value: '', |
| | | }, |
| | | ], |
| | | }, |
| | | { |
| | | name: '参数值', |
| | | [VueFlowConstant.PARAMS_KEY]: [ |
| | | { |
| | | key: 'resource_value', |
| | | type: 'resource_value', |
| | | required: true, |
| | | value: '', |
| | | language: ['text', 'javascript'], |
| | | defaultLanguage: 'text', |
| | | }, |
| | | ], |
| | | }, |
| | | ], |
| | | }; |
| | | break; |
| | | case NodeType.Agent: |
| | | data[VueFlowConstant.GROUP_PARAMS_KEY] = [ |
| | | { |
| | |
| | | * @param key |
| | | * @param val |
| | | */ |
| | | static getConfigValue = (obj: any, key: string, val: string) => { |
| | | static getConfigValue = (obj: any, key: string, val: any) => { |
| | | const value = obj[key]; |
| | | if (!value || value !== val) { |
| | | obj[key] = val; |
| | | } |
| | | |
| | | return val; |
| | | }; |
| | | |
| | | |
| | | |
| | | static getHandleId = (node: any, handleType: HandleType, order?: number) => { |
| | | const orderSuffix = order == undefined ? '' : `__${order + ''}`; |
| | |
| | | }; |
| | | |
| | | static getFieldValue = (data, key, index = 0) => { |
| | | let varList = []; |
| | | const varList = []; |
| | | const group = data?.[VueFlowConstant.GROUP_PARAMS_KEY]; |
| | | if (group && group.length > 0) { |
| | | if (index !== null) { |