瀏覽代碼

变量梳理

CzRger 4 天之前
父節點
當前提交
7289303fa4

+ 2 - 2
src/stores/modules/workflow.ts

@@ -100,11 +100,11 @@ export const useWorkflowStore = defineStore('workflow', {
           label: wd.desc || wd.title,
           key: wd.id,
           options: [
-            ...(wd.outVars?.map((v) => {
+            ...(wd.__outVars?.map((v) => {
               v.nodeId = wd.id
               return v
             }) || []),
-            ...(wd.sysVars?.map((v) => {
+            ...(wd.__sysVars?.map((v) => {
               v.nodeId = wd.id
               return v
             }) || []),

+ 19 - 3
src/views/workflow/handle.ts

@@ -119,7 +119,7 @@ export const handleNode = (no) => {
     ],
   }
   if (node.data.workflowData.type === NodeType.Start) {
-    node.data.workflowData.sysVars = [...systemVars]
+    node.data.workflowData.__sysVars = [...systemVars]
   } else {
     node.ports.items.push({
       id: `${node.id}_start`,
@@ -207,7 +207,15 @@ export const handleNodeSubmit = (no) => {
   switch (no.type) {
     case NodeType.Start:
       {
-        no.variables = no.outVars.map((v) => {
+        // if (no.outVars) {
+        //   no.__outVars = no.outVars
+        //   delete no.outVars
+        // }
+        // if (no.sysVars) {
+        //   no.__sysVars = no.sysVars
+        //   delete no.sysVars
+        // }
+        no.variables = no.__outVars.map((v) => {
           const obj = {
             variable: v.key,
             label: v.label,
@@ -225,7 +233,15 @@ export const handleNodeSubmit = (no) => {
       break
     case NodeType.LLM:
       {
-        if (!no.isMemory) {
+        // if (no.outVars) {
+        //   no.__outVars = no.outVars
+        //   delete no.outVars
+        // }
+        // if (no.isMemory) {
+        //   no.__isMemory = no.isMemory
+        //   delete no.memorisMemoryy
+        // }
+        if (!no.__isMemory) {
           delete no.memory
         }
       }

+ 9 - 0
src/views/workflow/instance/component/style.scss

@@ -14,3 +14,12 @@ $inputBg: #c8ceda40 !default;
   background-color: #10182814;
   margin: 0 4px;
 }
+
+._n_content {
+  width: 100%;
+  padding: 6px 8px;
+  background-color: rgb(242, 244, 247);
+  border-radius: 6px;
+  font-size: 12px;
+  color:#303133;
+}

+ 13 - 1
src/views/workflow/instance/component/vars/vars-select.vue

@@ -29,7 +29,7 @@ import { computed, getCurrentInstance, reactive, ref, watch } from 'vue'
 import varsValue from './vars-value.vue'
 import varsPopover from './vars-popover.vue'
 
-const emit = defineEmits(['setVars'])
+const emit = defineEmits(['setVars', 'update:vars'])
 const props = defineProps({
   node: {},
   vars: { default: null },
@@ -40,6 +40,18 @@ const state: any = reactive({
   vars: props.vars,
   hovering: false,
 })
+watch(
+  () => state.vars,
+  (n) => {
+    emit('update:vars', n)
+  },
+)
+watch(
+  () => props.vars,
+  (n) => {
+    state.vars = n
+  },
+)
 </script>
 
 <style lang="scss" scoped>

+ 1 - 1
src/views/workflow/instance/component/vars/vars-value.vue

@@ -19,7 +19,7 @@
       / <span class="text-[#155aef]">{{ vars.key }}</span> ·
       <span class="opacity-65">{{ vars.label }}</span>
     </div>
-    <span class="opacity-65">{{ vars.type }}</span>
+    <span class="ml-4 opacity-65">{{ vars.type }}</span>
     <span v-if="vars.required" class="text-red-500">*</span>
   </div>
   <div v-else class="opacity-65">{x}请选择变量</div>

+ 4 - 2
src/views/workflow/instance/llm/default.ts

@@ -9,11 +9,13 @@ const nodeDefault = {
       bizConfigs: {},
     },
     chatModelMessages: [{ role: 'system', text: '', id: v4() }],
+    __contextVars: null,
     context: {
       enabled: false,
       variable_selector: [],
     },
-    isMemory: false,
+    __isMemory: false,
+    // handle字段
     memory: {
       window: {
         enabled: false,
@@ -25,7 +27,7 @@ const nodeDefault = {
         assistant: '',
       },
     },
-    outVars: [{ label: '生成内容', key: 'text', type: 'String' }],
+    __outVars: [{ label: '生成内容', key: 'text', type: 'String' }],
   }),
 }
 

+ 4 - 2
src/views/workflow/instance/llm/node/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div class="">
     <div
-      class="mb-2 text-xs opacity-85"
+      class="_n_content mb-2"
       v-if="state.nodeData.modelConfig?.pluginInstanceName"
     >
       {{ state.nodeData.modelConfig.pluginInstanceName }}
@@ -32,4 +32,6 @@ onMounted(() => {
 })
 </script>
 
-<style lang="scss" scoped></style>
+<style lang="scss" scoped>
+@use '@/views/workflow/instance/component/style';
+</style>

+ 8 - 4
src/views/workflow/instance/llm/panel/index.vue

@@ -18,7 +18,11 @@
     <div class="_p-title">
       <div class="text-sm">上下文</div>
     </div>
-    <varsSelect :node="props.node" @setVars="setContent" />
+    <varsSelect
+      :node="props.node"
+      v-model:vars="state.nodeData.__contextVars"
+      @setVars="setContent"
+    />
     <template v-for="(item, index) in state.nodeData.chatModelMessages">
       <paramsTextarea
         v-model="item.text"
@@ -81,12 +85,12 @@
         <SvgIcon name="czr_tip" size="14" class="mr-auto ml-2" />
       </el-tooltip>
       <a-switch
-        v-model:checked="state.nodeData.isMemory"
+        v-model:checked="state.nodeData.__isMemory"
         size="small"
         @change="onSwitchMemory"
       ></a-switch>
     </div>
-    <template v-if="state.nodeData.isMemory && state.nodeData.memory">
+    <template v-if="state.nodeData.__isMemory && state.nodeData.memory">
       <paramsTextarea
         v-model="state.nodeData.memory.query_prompt_template"
         :node="node"
@@ -132,7 +136,7 @@
     <div class="_p-title">
       <div class="text-sm">输出变量</div>
     </div>
-    <varsOut :outVars="state.nodeData.outVars" />
+    <varsOut :outVars="state.nodeData.__outVars" />
   </div>
 </template>
 

+ 2 - 1
src/views/workflow/instance/start/default.ts

@@ -1,6 +1,7 @@
 const nodeDefault = {
   defaultValue: () => ({
-    outVars: [],
+    variables: [], // handle字段
+    __outVars: [],
   }),
 }
 

+ 5 - 5
src/views/workflow/instance/start/panel/index.vue

@@ -5,7 +5,7 @@
       <CzrButton type="add" title="添加参数" @click="onAddVars" />
     </div>
     <div class="vars">
-      <template v-for="(item, index) in state.nodeData.outVars">
+      <template v-for="(item, index) in state.nodeData.__outVars">
         <div class="item">
           <varsItem
             :item="item"
@@ -19,7 +19,7 @@
     </div>
     <div class="my-2 h-[1px] w-full bg-[#1018281f]" />
     <div class="vars">
-      <template v-for="item in state.nodeData.sysVars">
+      <template v-for="item in state.nodeData.__sysVars">
         <div class="item">
           <varsItem :item="item" />
         </div>
@@ -74,13 +74,13 @@ const onEditVars = (row, index) => {
   state.vars.show = true
 }
 const onDelVars = (row, index) => {
-  state.nodeData.outVars.splice(index, 1)
+  state.nodeData.__outVars.splice(index, 1)
 }
 const setVars = (val) => {
   if (state.vars.transfer.mode === 'add') {
-    state.nodeData.outVars.push(val)
+    state.nodeData.__outVars.push(val)
   } else {
-    state.nodeData.outVars[state.vars.transfer.index] = val
+    state.nodeData.__outVars[state.vars.transfer.index] = val
   }
 }
 </script>

+ 1 - 1
src/views/workflow/instance/test/default.ts

@@ -1,6 +1,6 @@
 const nodeDefault = {
   defaultValue: () => ({
-    outVars: [
+    __outVars: [
       { label: '参数1', key: 'param1', type: 'String' },
       { label: '参数2', key: 'param2', type: 'Number' },
     ],

+ 1 - 1
src/views/workflow/instance/test/panel/index.vue

@@ -7,7 +7,7 @@
     <div class="_p-title">
       <div class="text-sm">输出变量</div>
     </div>
-    <varsOut :outVars="state.nodeData.outVars" />
+    <varsOut :outVars="state.nodeData.__outVars" />
   </div>
 </template>
 

+ 29 - 29
src/views/workflow/mockJson.ts

@@ -43,7 +43,7 @@ export const data0 = {
           id: 'eeec6579-6214-4b26-8d53-a7a68abbb032',
           title: '开始',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '输入参数1',
               key: 'ppp1',
@@ -73,7 +73,7 @@ export const data0 = {
             },
           ],
           type: 'root',
-          sysVars: [
+          __sysVars: [
             {
               label: '查询内容',
               key: 'sys.query',
@@ -289,7 +289,7 @@ export const data0 = {
           id: '0948a3c4-76f6-4282-9a3a-e83fd7a3c957',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -312,7 +312,7 @@ export const data0 = {
           id: '01ce0ef3-13dd-41b4-9995-d40ee232801e',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -335,7 +335,7 @@ export const data0 = {
           id: '05f487b0-30e9-4c4a-92d1-bd24076bac04',
           title: '测试节点',
           desc: '副标题',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -360,7 +360,7 @@ export const data0 = {
           id: '7cd1a345-d326-4bde-bb9d-81eb8d884777',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -383,7 +383,7 @@ export const data0 = {
           id: '123',
           title: '测试节点123',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -406,7 +406,7 @@ export const data0 = {
           id: '06cf0d93-262e-488d-803b-c4e45cc50b2c',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -429,7 +429,7 @@ export const data0 = {
           id: '1402df48-f7af-4669-a105-9d649eab31e5',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -452,7 +452,7 @@ export const data0 = {
           id: '4c6c1fc8-61a9-440b-aae5-72d0520639cf',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -475,7 +475,7 @@ export const data0 = {
           id: '75619758-a5f1-4894-bb17-f2ffb9c7a4d8',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -498,7 +498,7 @@ export const data0 = {
           id: '2003fab1-4747-4424-ac30-a261971131f5',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -521,7 +521,7 @@ export const data0 = {
           id: 'f88b00f3-22e2-4712-b979-b03554ff1173',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -544,7 +544,7 @@ export const data0 = {
           id: '8746b00b-c1b3-41e0-9b1c-4c57f9e19b5b',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -567,7 +567,7 @@ export const data0 = {
           id: '3ae80188-4daf-4914-8b38-27786abe9031',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -592,7 +592,7 @@ export const data0 = {
           id: 'cf5e5e34-7bef-4dc8-a9bd-842d2f3bab70',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -615,7 +615,7 @@ export const data0 = {
           id: '8662c97f-615c-4a31-8de2-173dcfbce7e2',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -638,7 +638,7 @@ export const data0 = {
           id: 'ee9a4b52-3a9c-4127-84f2-ac5dadfd4876',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -661,7 +661,7 @@ export const data0 = {
           id: 'a84c8867-50a5-4494-b138-02e00e4ef50c',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -684,7 +684,7 @@ export const data0 = {
           id: 'ef197c14-1661-465a-a8c6-b9e184a9d2f6',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -707,7 +707,7 @@ export const data0 = {
           id: '7b96e828-053c-4515-985d-639bc692f1ba',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -730,7 +730,7 @@ export const data0 = {
           id: '260d696e-c8ef-4bd1-be21-b7e6d1c280e2',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -753,7 +753,7 @@ export const data0 = {
           id: '3d5addb1-ce96-4095-b7c9-e460ba7b21f1',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -776,7 +776,7 @@ export const data0 = {
           id: '85a8702c-1dd8-4c85-938f-73d4337c2ce0',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -799,7 +799,7 @@ export const data0 = {
           id: 'cb662c40-1794-4d17-9fa7-7313f60c1a0e',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -910,7 +910,7 @@ export const data0 = {
           id: '6bc7f1a1-efdd-4958-84c7-b31a60ee6796',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',
@@ -1117,7 +1117,7 @@ export const data1 = {
           id: 'eeec6579-6214-4b26-8d53-a7a68abbb032',
           title: '开始',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '输入参数1',
               key: 'ppp1',
@@ -1147,7 +1147,7 @@ export const data1 = {
             },
           ],
           type: 'root',
-          sysVars: [
+          __sysVars: [
             {
               label: '查询内容',
               key: 'sys.query',
@@ -1363,7 +1363,7 @@ export const data1 = {
           id: '483d0519-446b-4d4c-8f70-0f3c96329e7c',
           title: '测试节点',
           desc: '',
-          outVars: [
+          __outVars: [
             {
               label: '参数1',
               key: 'param1',