From c6cf46f3e11e60f692e0b8d12188458ad1b6120e Mon Sep 17 00:00:00 2001 From: yangyin <18723093654@163.com> Date: 星期五, 13 十二月 2024 17:09:44 +0800 Subject: [PATCH] Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.Admin.V1.0 into test --- src/components/vue-flow/VueFlowHelper.ts | 262 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 261 insertions(+), 1 deletions(-) diff --git a/src/components/vue-flow/VueFlowHelper.ts b/src/components/vue-flow/VueFlowHelper.ts index e76fd7e..bda2965 100644 --- a/src/components/vue-flow/VueFlowHelper.ts +++ b/src/components/vue-flow/VueFlowHelper.ts @@ -1,17 +1,277 @@ -import { NodeType, nodeTypeMap } from './vueFlowEnum'; +import { HandleType, useNode, useVueFlow } 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'; export class VueFlowHelper { + static genId() { + return uuid().slice(0, 8); + } + + static genGeometryId() { + return uuid().slice(0, 12); + } + static getDefaultData = (type: NodeType) => { let data: any = { title: nodeTypeMap[type], }; switch (type) { case NodeType.Start: + data = { + ...data, + description: '宸ヤ綔娴佽繍琛岀殑璧峰鑺傜偣銆�', + }; + data[VueFlowConstant.GROUP_PARAMS_KEY] = [ + { + [VueFlowConstant.PARAMS_KEY]: [ + { + key: 'var_list', + label: '', + type: 'var_list', + value: [], + }, + ], + }, + ]; break; + case NodeType.End: + data = { + ...data, + description: '宸ヤ綔娴佽繍琛屽埌姝ょ粨鏉熴��', + }; + break; + case NodeType.Condition: + data = { + ...data, + description: '鏍规嵁鏉′欢琛ㄨ揪寮忔墽琛屼笉鍚岀殑鍒嗘敮銆�', + }; + data[VueFlowConstant.GROUP_PARAMS_KEY] = [ + { + [VueFlowConstant.PARAMS_KEY]: [ + { + key: 'condition', + label: '', + type: 'condition', + value: [ConditionHelper.getDefaultConditionGroup(), ConditionHelper.getDefaultConditionGroup(true)], + }, + ], + }, + ]; + break; + case NodeType.LLM: + 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.Agent: + data[VueFlowConstant.GROUP_PARAMS_KEY] = [ + { + name: '浠g悊鍚嶇О', + [VueFlowConstant.PARAMS_KEY]: [ + { + key: 'agent', + label: '', + type: 'agent_select', + value: '', + // value_label:'', + required: true, + placeholder: '浠g悊鍚嶇О', + }, + ], + }, + ]; + 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]: [ + { + key: 'output_msg', + label: '娑堟伅鍐呭', + type: 'var_textarea_file', + required: true, + placeholder: + '杈撳叆闇�瑕佸彂閫佺粰鐢ㄦ埛鐨勬秷鎭紝渚嬪鈥滄帴涓嬫潵鎴戝皢鎵ц XX 鎿嶄綔锛岃鎮ㄧ‘璁も�濓紝鈥滀互涓嬫槸鎴戠殑鍒濈増鑽夌锛屾偍鍙互鍦ㄥ叾鍩虹涓婅繘琛屼慨鏀光��', + value: { msg: '', files: [] }, + }, + { + key: 'output_result', + label: '浜や簰绫诲瀷', + global: 'value.type=input', + type: 'output_form', + required: true, + value: { type: 'none', value: '' }, + options: [], + }, + ], + }, + ]; default: 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) => { + const orderSuffix = order == undefined ? '' : `__${order + ''}`; + return `${node.id}__handle-${handleType}${orderSuffix}`; + }; + + static getFieldValue = (data, key, index = 0) => { + let varList = []; + const group = data?.[VueFlowConstant.GROUP_PARAMS_KEY]; + if (group && group.length > 0) { + if (index !== null) { + const val = group?.[index]?.[VueFlowConstant.PARAMS_KEY]?.find((item) => item.key === key)?.value; + if (val) { + varList.push(val); + } + } else { + for (const item of group) { + if (item[VueFlowConstant.PARAMS_KEY].key === key) { + varList.push(item[VueFlowConstant.PARAMS_KEY].value); + } + } + } + } + if (varList.length === 0) { + return null; + } else if (varList.length === 1) { + return varList[0]; + } else { + return varList; + } + }; + + static getGroupParam = (data, index = 0) => { + const group = data?.[VueFlowConstant.GROUP_PARAMS_KEY]?.[index]; + return group; + }; + + static getParams = (group, key) => { + return group?.[VueFlowConstant.PARAMS_KEY]?.find((item) => item.key === key); + }; +} + +export class StartNodeHelper { + // static getDefaultData = () => { + // return { + // title: nodeTypeMap[NodeType.Start], + // }; + // }; + + static getVarList = (data) => { + const varList = data[VueFlowConstant.GROUP_PARAMS_KEY][0][VueFlowConstant.PARAMS_KEY].find( + (item) => item.key === 'condition' + ).value; + return varList; + }; +} + +export class ConditionHelper { + static getConditionItem = ( + left?: { + var: string; + label: string; + value: string; + }, + right?: { + type: VarType; + value: string; + label: string; + }, + operation?: CompareOperation + ) => { + return { + id: VueFlowHelper.genId(), + left_var: left?.var ?? '', + left_label: left?.label ?? '', + left_value: left?.var ?? '', + comparison_operation: operation ?? '', + // right_value_type: right?.type ?? VarType.Input, + // 鍥哄畾閫夋嫨 input + right_value_type: VarType.Input, + + right_value: right?.value ?? '', + right_label: right?.label ?? '', + }; + }; + + static getDefaultConditionGroup = (isElse = false) => { + return isElse + ? { + id: VueFlowHelper.genId(), + } + : { + id: VueFlowHelper.genId(), + operator: ConditionOperator.And, + conditions: [ConditionHelper.getConditionItem()], + }; + }; } -- Gitblit v1.9.3