| | |
| | | <template> |
| | | <NodeBasicLayout v-model:title="data.title" :type="NodeType.Output" :description="VueFlowHelper.getConfigValue(data, 'description', '可向用户发送消息,并且支持进行更丰富的交互,例如请求用户批准进行某项敏感操作、允许用户在模型输出内容的基础上直接修改并提交。')"> |
| | | <NodeBasicLayout |
| | | v-model:title="data.title" |
| | | :type="NodeType.Output" |
| | | :description="VueFlowHelper.getConfigValue(data, 'description', '可向用户发送消息...')" |
| | | :isViewMode="isViewMode" |
| | | > |
| | | <Handle :id="targetHandleId" type="target" :position="Position.Left" /> |
| | | <FieldLayout level="2" :title="VueFlowHelper.getParams(outputParams, 'output_msg').label"> |
| | | <el-input |
| | | v-model="VueFlowHelper.getParams(outputParams, 'output_msg').value.msg" |
| | | type="textarea" |
| | | :rows="4" |
| | | :placeholder="VueFlowHelper.getParams(outputParams, 'output_msg').placeholder" |
| | | autocomplete="off" |
| | | > |
| | | </el-input> |
| | | </FieldLayout> |
| | | <FieldLayout level="2" :title="VueFlowHelper.getParams(outputParams, 'output_result').label"> |
| | | <el-radio-group v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.type" @change="interactionTypeChange"> |
| | | <el-radio v-for="item in Object.keys(interactionTypeMap)" :key="item" :value="item">{{ interactionTypeMap[item] }}</el-radio> |
| | | </el-radio-group> |
| | | <el-input |
| | | v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.value" |
| | | type="textarea" |
| | | :rows="4" |
| | | v-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input" |
| | | > |
| | | </el-input> |
| | | <el-form ref="formRef" :model="data" :rules="formRules" label-position="right" label-width="60px" :show-message="false"> |
| | | <FieldLayout required level="2" :title="VueFlowHelper.getParams(outputParams, 'output_msg').label"> |
| | | <el-form-item labelWidth="0" prop="group_params.0.params.0.value.msg"> |
| | | <CodeEditor |
| | | class="w-full" |
| | | :title="VueFlowHelper.getParams(outputParams, 'output_msg').label" |
| | | v-model:editValue="VueFlowHelper.getParams(outputParams, 'output_msg').value.msg" |
| | | :maxHeight="180" |
| | | :disabled="isViewMode" |
| | | :placeholder="VueFlowHelper.getParams(outputParams, 'output_msg').placeholder" |
| | | /> |
| | | </el-form-item> |
| | | </FieldLayout> |
| | | <FieldLayout level="2" :title="VueFlowHelper.getParams(outputParams, 'output_result').label"> |
| | | <el-radio-group |
| | | v-model="VueFlowHelper.getParams(outputParams, 'output_result').value.type" |
| | | @change="interactionTypeChange" |
| | | :disabled="isViewMode" |
| | | class="flex-items-center justify-between interaction-radio-group" |
| | | > |
| | | <el-radio v-for="item in Object.keys(interactionTypeMap)" :key="item" :value="item"> |
| | | {{ interactionTypeMap[item] }} |
| | | </el-radio> |
| | | </el-radio-group> |
| | | |
| | | <div |
| | | class="self-start w-full flex-col flex items-start gap-2" |
| | | v-else-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Select" |
| | | > |
| | | <div class="flex-column gap-2"> |
| | | <div |
| | | class="text-gray-400 cursor-not-allowed border border-solid rounded-lg border-gray-300 py-3 pl-3 pr-2 items-center justify-between flex group/option relative mr-6" |
| | | :key="item.id" |
| | | v-for="(item, index) in VueFlowHelper.getParams(outputParams, 'output_result').options" |
| | | > |
| | | <span>{{ item.label }}</span> |
| | | <span |
| | | @click="delOption(index)" |
| | | class="cursor-pointer group-hover/option:visible invisible ywifont ywicon-shanchu text-red-500" |
| | | ></span> |
| | | <Handle class="absolute !-right-4" :id="item.id" type="source" :position="Position.Right" /> |
| | | <CodeEditor |
| | | title="输入型交互" |
| | | :disabled="isViewMode" |
| | | v-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input" |
| | | v-model:editValue="VueFlowHelper.getParams(outputParams, 'output_result').value.value" |
| | | :maxHeight="150" |
| | | /> |
| | | |
| | | <div |
| | | class="self-start w-full flex-col flex items-start gap-2" |
| | | v-else-if="VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Select" |
| | | > |
| | | <div class="flex-column gap-2"> |
| | | <div |
| | | class="text-gray-400 cursor-not-allowed border border-solid rounded-lg border-gray-300 py-3 pl-3 pr-2 items-center justify-between flex group/option relative mr-6" |
| | | :key="item.id" |
| | | v-for="(item, index) in VueFlowHelper.getParams(outputParams, 'output_result').options" |
| | | > |
| | | <span>{{ item.label }}</span> |
| | | <span |
| | | @click="delOption(index)" |
| | | class="cursor-pointer group-hover/option:visible invisible ywifont ywicon-shanchu text-red-500" |
| | | ></span> |
| | | <Handle class="absolute !-right-4" :id="item.id" type="source" :position="Position.Right" /> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | |
| | | <div v-if="isEditStatus" class="flex-items-center w-full"> |
| | | <el-input class="flex-auto" v-model="tmpEditValue"></el-input> |
| | | <el-button class="flex-0 ml-2" type="success" @click="confirmClick">确定 </el-button> |
| | | <div v-if="isEditStatus" class="flex-items-center w-full"> |
| | | <el-input class="flex-auto" v-model="tmpEditValue"></el-input> |
| | | <el-button class="flex-0 ml-2" type="success" @click="confirmClick">确定 </el-button> |
| | | </div> |
| | | <el-button v-else type="primary" @click="addOptionClick">添加选项</el-button> |
| | | </div> |
| | | <el-button v-else type="primary" @click="addOptionClick">添加选项</el-button> |
| | | </div> |
| | | <Handle |
| | | v-if=" |
| | | VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input || |
| | | VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.None |
| | | " |
| | | :id="sourceHandleId" |
| | | type="source" |
| | | :position="Position.Right" |
| | | /> |
| | | </FieldLayout> |
| | | <Handle |
| | | v-if=" |
| | | VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.Input || |
| | | VueFlowHelper.getParams(outputParams, 'output_result').value.type === InteractionType.None |
| | | " |
| | | :id="sourceHandleId" |
| | | type="source" |
| | | :position="Position.Right" |
| | | /> |
| | | </FieldLayout> |
| | | </el-form> |
| | | </NodeBasicLayout> |
| | | </template> |
| | | |
| | | <script lang="ts" setup> |
| | | import { Handle, Position, useNode, useVueFlow } from '@vue-flow/core'; |
| | | import { ref } from 'vue'; |
| | | import { onMounted, ref } from 'vue'; |
| | | import { NodeType } from '../../vueFlowEnum'; |
| | | |
| | | import type { NodeProps } from '@vue-flow/core'; |
| | | import { nextTick } from 'vue'; |
| | | import { VueFlowHelper } from '../../VueFlowHelper'; |
| | | import { InteractionType, interactionTypeMap } from '../../vueFlowEnum'; |
| | | import { LLMNodeData, LLMNodeEvents } from './index'; |
| | | |
| | | import NodeBasicLayout from './components/NodeBasicLayout.vue'; |
| | | import FieldLayout from './components/FieldLayout.vue'; |
| | | defineProps<NodeProps<LLMNodeData, LLMNodeEvents>>(); |
| | | import NodeBasicLayout from './components/NodeBasicLayout.vue'; |
| | | import type { LLMNodeData, LLMNodeEvents } from './index'; |
| | | import CodeEditor from '/@/components/input/codeEditor/index.vue'; |
| | | import { validateForm } from './utils'; |
| | | |
| | | defineProps< |
| | | NodeProps<LLMNodeData, LLMNodeEvents> & { |
| | | isViewMode?: boolean; |
| | | } |
| | | >(); |
| | | const emit = defineEmits<{ |
| | | (e: 'register', data: { validateForm: () => Promise<{ isValid: boolean; invalidFields?: any }> }): void; |
| | | }>(); |
| | | const node = useNode(); |
| | | const sourceHandleId = ref(VueFlowHelper.getHandleId(node.node, 'source')); |
| | | const targetHandleId = ref(VueFlowHelper.getHandleId(node.node, 'target')); |
| | | |
| | | const data = ref(node.node.data); |
| | | |
| | | const outputParams = ref(VueFlowHelper.getGroupParam(data.value, 0)); |
| | | |
| | | const { removeEdges } = useVueFlow(); |
| | |
| | | |
| | | const isEditStatus = ref(false); |
| | | const tmpEditValue = ref(''); |
| | | const formRef = ref(); |
| | | const formRules = ref({ |
| | | 'group_params.0.params.0.value.msg': [{ required: true, message: '请输入消息内容', trigger: 'blur' }], |
| | | }); |
| | | |
| | | // 注册节点实例 |
| | | onMounted(() => { |
| | | emit('register', { |
| | | validateForm: validateForm(formRef) as any, |
| | | }); |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"> |
| | | .interaction-radio-group { |
| | | :deep(.el-radio) { |
| | | margin-right: 0; |
| | | } |
| | | } |
| | | </style> |