-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathindex.vue
More file actions
232 lines (215 loc) · 7.59 KB
/
index.vue
File metadata and controls
232 lines (215 loc) · 7.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<template>
<NodeContainer :nodeModel="nodeModel">
<h5 class="title-decoration-1 mb-16">{{ $t('workflow.nodeSetting') }}</h5>
<div class="flex-between">
<h5 class="lighter mb-8">{{ $t('common.param.inputParam') }}</h5>
<el-button link type="primary" @click="openAddDialog()">
<AppIcon iconName="app-add-outlined" class="mr-4"></AppIcon> {{ $t('common.add') }}
</el-button>
</div>
<el-form
@submit.prevent
ref="ToolNodeFormRef"
:model="chat_data"
label-position="top"
require-asterisk-position="right"
hide-required-asterisk
>
<el-card shadow="never" class="card-never mb-16" style="--el-card-padding: 12px">
<div v-if="chat_data.input_field_list?.length > 0">
<template v-for="(item, index) in chat_data.input_field_list" :key="index">
<el-form-item
:label="item.name"
:prop="'input_field_list.' + index + '.value'"
:rules="{
required: item.is_required,
message:
item.source === 'reference'
? $t('views.tool.form.param.selectPlaceholder')
: $t('views.tool.form.param.inputPlaceholder'),
trigger: 'blur',
}"
>
<template #label>
<div class="flex-between">
<div class="flex align-center">
<div class="mr-4">
<auto-tooltip :content="item.name" style="max-width: 130px">
{{ item.name }}
</auto-tooltip>
</div>
<el-tooltip
v-if="item.desc"
effect="dark"
placement="right"
popper-class="max-w-200"
>
<template #content>
{{ item.desc }}
</template>
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
</el-tooltip>
<span class="color-danger" v-if="item.is_required">*</span>
<el-tag size="small" type="info" class="info-tag ml-4">{{ item.type }}</el-tag>
</div>
<div>
<el-button text @click.stop="openAddDialog(item, index)">
<AppIcon iconName="app-edit"></AppIcon>
</el-button>
<el-button text @click="deleteField(index)" style="margin-left: 4px !important">
<AppIcon iconName="app-delete"></AppIcon>
</el-button>
</div>
</div>
</template>
<NodeCascader
v-if="item.source === 'reference'"
ref="nodeCascaderRef"
:nodeModel="nodeModel"
class="w-full"
:placeholder="$t('views.tool.form.param.selectPlaceholder')"
v-model="item.value"
:width="100"
/>
<el-input
v-else
v-model="item.value"
:placeholder="$t('views.tool.form.param.inputPlaceholder')"
/>
</el-form-item>
</template>
</div>
<el-text type="info" v-else> {{ $t('common.noData') }} </el-text>
</el-card>
<h5 class="lighter mb-8">
{{ $t('views.tool.form.param.code') }}
</h5>
<div class="mb-8" v-if="showEditor">
<CodemirrorEditor
:title="$t('views.tool.form.param.code')"
v-model="chat_data.code"
@wheel="wheel"
style="height: 130px !important"
@submitDialog="submitCodemirrorEditor"
/>
</div>
<el-form-item
:label="$t('workflow.nodes.aiChatNode.returnContent.label')"
@click.prevent
v-if="
[
WorkflowMode.Application,
WorkflowMode.ApplicationLoop,
WorkflowMode.Tool,
WorkflowMode.ToolLoop,
].includes(workflowMode)
"
>
<template #label>
<div class="flex align-center">
<div class="mr-4">
<span>{{ $t('workflow.nodes.aiChatNode.returnContent.label') }}</span>
</div>
<el-tooltip effect="dark" placement="right" popper-class="max-w-200">
<template #content>
{{ $t('workflow.nodes.aiChatNode.returnContent.tooltip') }}
</template>
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
</el-tooltip>
</div>
</template>
<el-switch size="small" v-model="chat_data.is_result" />
</el-form-item>
</el-form>
<FieldFormDialog ref="FieldFormDialogRef" @refresh="refreshFieldList" />
</NodeContainer>
</template>
<script setup lang="ts">
import { cloneDeep, set } from 'lodash'
import NodeContainer from '@/workflow/common/NodeContainer.vue'
import NodeCascader from '@/workflow/common/NodeCascader.vue'
import type { FormInstance } from 'element-plus'
import { ref, computed, onMounted, inject } from 'vue'
import FieldFormDialog from '@/views/tool/component/FieldFormDialog.vue'
import { isLastNode } from '@/workflow/common/data'
import { WorkflowMode } from '@/enums/application'
const workflowMode = (inject('workflowMode') as WorkflowMode) || WorkflowMode.Application
const props = defineProps<{ nodeModel: any }>()
const wheel = (e: any) => {
if (e.ctrlKey === true) {
e.preventDefault()
return true
} else {
e.stopPropagation()
return true
}
}
const FieldFormDialogRef = ref()
const nodeCascaderRef = ref()
const form = {
code: '',
input_field_list: [],
is_result: false,
}
const currentIndex = ref<any>(null)
const showEditor = ref(false)
const chat_data = computed({
get: () => {
if (props.nodeModel.properties.node_data) {
return props.nodeModel.properties.node_data
} else {
set(props.nodeModel.properties, 'node_data', form)
}
return props.nodeModel.properties.node_data
},
set: (value) => {
set(props.nodeModel.properties, 'node_data', value)
},
})
const ToolNodeFormRef = ref<FormInstance>()
const validate = () => {
return ToolNodeFormRef.value?.validate().catch((err) => {
return Promise.reject({ node: props.nodeModel, errMessage: err })
})
}
function submitCodemirrorEditor(val: string) {
set(props.nodeModel.properties.node_data, 'code', val)
}
function openAddDialog(data?: any, index?: any) {
if (typeof index !== 'undefined') {
currentIndex.value = index
}
FieldFormDialogRef.value.open(data)
}
function deleteField(index: any) {
const list: any = cloneDeep(props.nodeModel.properties.node_data.input_field_list)
list.splice(index, 1)
set(props.nodeModel.properties.node_data, 'input_field_list', list)
}
function refreshFieldList(data: any) {
const list = cloneDeep(props.nodeModel.properties.node_data.input_field_list)
const obj = {
...data,
value: data.source === 'reference' ? [] : '',
}
if (currentIndex.value !== null) {
list.splice(currentIndex.value, 1, obj)
} else {
list.push(obj)
}
set(props.nodeModel.properties.node_data, 'input_field_list', list)
currentIndex.value = null
}
onMounted(() => {
if (typeof props.nodeModel.properties.node_data?.is_result === 'undefined') {
if (isLastNode(props.nodeModel)) {
set(props.nodeModel.properties.node_data, 'is_result', true)
}
}
set(props.nodeModel, 'validate', validate)
setTimeout(() => {
showEditor.value = true
}, 100)
})
</script>
<style lang="scss"></style>