UnisKB/ui/src/workflow/common/data.ts

412 lines
11 KiB
TypeScript
Raw Normal View History

2024-07-01 01:45:59 +00:00
import { WorkflowType } from '@/enums/workflow'
2024-09-18 09:59:11 +00:00
import { t } from '@/locales'
2024-07-01 01:45:59 +00:00
export const startNode = {
id: WorkflowType.Start,
type: WorkflowType.Start,
x: 180,
y: 720,
properties: {
height: 200,
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.startNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.startNode.question'),
2024-07-01 01:45:59 +00:00
value: 'question'
}
],
globalFields: [
{
value: 'time',
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.startNode.currentTime')
2024-07-01 01:45:59 +00:00
}
]
}
}
}
export const baseNode = {
id: WorkflowType.Base,
type: WorkflowType.Base,
x: 200,
y: 270,
2024-09-14 06:51:49 +00:00
text: '',
2024-07-01 01:45:59 +00:00
properties: {
2024-09-23 02:01:22 +00:00
width: 420,
2024-07-01 01:45:59 +00:00
height: 200,
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.baseNode.label'),
2024-09-14 06:51:49 +00:00
input_field_list: [],
2024-07-01 01:45:59 +00:00
node_data: {
name: '',
desc: '',
// @ts-ignore
2025-01-13 03:15:51 +00:00
prologue: t('views.application.applicationForm.form.defaultPrologue')
2024-07-01 01:45:59 +00:00
},
config: {}
}
}
/**
*
* type nodes
*/
export const baseNodes = [baseNode, startNode]
/**
* ai
*/
export const aiChatNode = {
type: WorkflowType.AiChat,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.aiChatNode.text'),
label: t('views.applicationWorkflow.nodes.aiChatNode.label'),
2024-09-14 06:51:49 +00:00
height: 340,
2024-07-01 01:45:59 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.aiChatNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.aiChatNode.answer'),
2024-07-01 01:45:59 +00:00
value: 'answer'
}
]
}
}
}
/**
*
*/
export const searchDatasetNode = {
type: WorkflowType.SearchDataset,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.searchDatasetNode.text'),
label: t('views.applicationWorkflow.nodes.searchDatasetNode.label'),
2024-09-14 06:51:49 +00:00
height: 355,
2024-07-01 01:45:59 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.searchDatasetNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.searchDatasetNode.paragraph_list'),
value: 'paragraph_list'
},
{
label: t('views.applicationWorkflow.nodes.searchDatasetNode.is_hit_handling_method_list'),
value: 'is_hit_handling_method_list'
},
{
label: t('views.applicationWorkflow.nodes.searchDatasetNode.result'),
2024-07-01 01:45:59 +00:00
value: 'data'
},
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.searchDatasetNode.directly_return'),
2024-07-01 01:45:59 +00:00
value: 'directly_return'
}
]
}
}
}
export const questionNode = {
type: WorkflowType.Question,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.searchDatasetNode.text'),
label: t('views.applicationWorkflow.nodes.searchDatasetNode.label'),
2024-09-14 06:51:49 +00:00
height: 345,
2024-07-01 01:45:59 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.searchDatasetNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.searchDatasetNode.result'),
2024-07-01 01:45:59 +00:00
value: 'answer'
}
]
}
}
}
export const conditionNode = {
type: WorkflowType.Condition,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.conditionNode.text'),
label: t('views.applicationWorkflow.nodes.conditionNode.label'),
2024-09-14 06:51:49 +00:00
height: 175,
2024-07-01 01:45:59 +00:00
properties: {
width: 600,
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.conditionNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.conditionNode.branch_name'),
2024-07-01 01:45:59 +00:00
value: 'branch_name'
}
]
}
}
}
export const replyNode = {
type: WorkflowType.Reply,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.replyNode.text'),
label: t('views.applicationWorkflow.nodes.replyNode.label'),
2024-09-14 06:51:49 +00:00
height: 210,
2024-07-01 01:45:59 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.replyNode.label'),
2024-07-01 01:45:59 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.replyNode.content'),
2024-07-01 01:45:59 +00:00
value: 'answer'
}
]
}
}
}
2024-09-05 03:28:21 +00:00
export const rerankerNode = {
type: WorkflowType.RrerankerNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.rerankerNode.text'),
label: t('views.applicationWorkflow.nodes.rerankerNode.label'),
2024-09-14 06:51:49 +00:00
height: 252,
2024-09-05 03:28:21 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.rerankerNode.label'),
2024-09-05 03:28:21 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.rerankerNode.result_list'),
value: 'result_list'
},
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.rerankerNode.result'),
2024-09-05 03:28:21 +00:00
value: 'result'
}
]
}
}
}
2024-11-13 02:37:16 +00:00
export const formNode = {
type: WorkflowType.FormNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.formNode.text'),
label: t('views.applicationWorkflow.nodes.formNode.label'),
2024-11-13 02:37:16 +00:00
height: 252,
properties: {
width: 600,
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.formNode.label'),
2024-11-13 02:37:16 +00:00
node_data: {
is_result: true,
form_field_list: [],
2025-01-18 09:15:31 +00:00
form_content_format: t('views.applicationWorkflow.nodes.formNode.form_content_format')
2024-11-13 02:37:16 +00:00
},
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.formNode.form_data'),
2024-11-13 02:37:16 +00:00
value: 'form_data'
}
]
}
}
}
export const documentExtractNode = {
type: WorkflowType.DocumentExtractNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.documentExtractNode.text'),
label: t('views.applicationWorkflow.nodes.documentExtractNode.label'),
height: 252,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.documentExtractNode.label'),
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.documentExtractNode.content'),
value: 'content'
2024-11-13 02:37:16 +00:00
}
]
}
}
}
export const imageUnderstandNode = {
type: WorkflowType.ImageUnderstandNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.imageUnderstandNode.text'),
label: t('views.applicationWorkflow.nodes.imageUnderstandNode.label'),
height: 252,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.imageUnderstandNode.label'),
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.imageUnderstandNode.answer'),
value: 'answer'
2024-11-13 02:37:16 +00:00
}
]
}
}
}
2024-12-09 03:00:51 +00:00
export const imageGenerateNode = {
type: WorkflowType.ImageGenerateNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.imageGenerateNode.text'),
label: t('views.applicationWorkflow.nodes.imageGenerateNode.label'),
2024-12-09 03:00:51 +00:00
height: 252,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.imageGenerateNode.label'),
2024-12-09 03:00:51 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.imageGenerateNode.answer'),
2024-12-09 03:00:51 +00:00
value: 'answer'
},
{
2025-01-18 09:15:31 +00:00
label: t('views.applicationWorkflow.nodes.imageGenerateNode.image'),
2024-12-09 03:00:51 +00:00
value: 'image'
}
]
}
}
}
export const speechToTextNode = {
type: WorkflowType.SpeechToTextNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.speechToTextNode.text'),
label: t('views.applicationWorkflow.nodes.speechToTextNode.label'),
height: 252,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.speechToTextNode.label'),
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('common.result'),
value: 'result'
}
]
}
}
}
export const textToSpeechNode = {
type: WorkflowType.TextToSpeechNode,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.textToSpeechNode.text'),
label: t('views.applicationWorkflow.nodes.textToSpeechNode.label'),
height: 252,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.textToSpeechNode.label'),
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('common.result'),
value: 'result'
}
]
}
}
}
2024-09-05 03:28:21 +00:00
export const menuNodes = [
aiChatNode,
2024-12-17 06:51:45 +00:00
imageUnderstandNode,
imageGenerateNode,
2024-09-05 03:28:21 +00:00
searchDatasetNode,
2024-12-17 06:51:45 +00:00
rerankerNode,
2024-09-05 03:28:21 +00:00
conditionNode,
replyNode,
formNode,
2024-12-17 06:51:45 +00:00
questionNode,
documentExtractNode,
speechToTextNode,
2024-12-17 06:51:45 +00:00
textToSpeechNode
2024-09-05 03:28:21 +00:00
]
2024-07-01 01:45:59 +00:00
2024-08-15 09:17:25 +00:00
/**
*
*/
export const functionNode = {
type: WorkflowType.FunctionLibCustom,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.functionNode.text'),
label: t('views.applicationWorkflow.nodes.functionNode.label'),
2024-09-14 06:51:49 +00:00
height: 260,
2024-08-15 09:17:25 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.functionNode.label'),
2024-08-15 09:17:25 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('common.result'),
2024-08-15 09:17:25 +00:00
value: 'result'
}
]
}
}
}
export const functionLibNode = {
type: WorkflowType.FunctionLib,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.functionNode.text'),
label: t('views.applicationWorkflow.nodes.functionNode.label'),
2024-09-14 06:51:49 +00:00
height: 170,
2024-08-15 09:17:25 +00:00
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.functionNode.label'),
2024-08-15 09:17:25 +00:00
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('common.result'),
2024-08-15 09:17:25 +00:00
value: 'result'
}
]
}
}
}
export const applicationNode = {
type: WorkflowType.Application,
2025-01-18 09:15:31 +00:00
text: t('views.applicationWorkflow.nodes.applicationNode.label'),
label: t('views.applicationWorkflow.nodes.applicationNode.label'),
height: 260,
properties: {
2025-01-18 09:15:31 +00:00
stepName: t('views.applicationWorkflow.nodes.applicationNode.label'),
config: {
fields: [
{
2025-01-18 09:15:31 +00:00
label: t('common.result'),
value: 'result'
}
]
}
}
}
2024-07-01 01:45:59 +00:00
export const compareList = [
2025-01-18 09:15:31 +00:00
{ value: 'is_null', label: t('views.applicationWorkflow.compare.is_null') },
{ value: 'is_not_null', label: t('views.applicationWorkflow.compare.is_not_null') },
{ value: 'contain', label: t('views.applicationWorkflow.compare.contain') },
{ value: 'not_contain', label: t('views.applicationWorkflow.compare.not_contain') },
{ value: 'eq', label: t('views.applicationWorkflow.compare.eq') },
{ value: 'ge', label: t('views.applicationWorkflow.compare.ge') },
{ value: 'gt', label:t('views.applicationWorkflow.compare.gt') },
{ value: 'le', label: t('views.applicationWorkflow.compare.le') },
{ value: 'lt', label: t('views.applicationWorkflow.compare.lt') },
{ value: 'len_eq', label: t('views.applicationWorkflow.compare.len_eq')},
{ value: 'len_ge', label: t('views.applicationWorkflow.compare.len_ge') },
{ value: 'len_gt', label:t('views.applicationWorkflow.compare.len_gt') },
{ value: 'len_le', label: t('views.applicationWorkflow.compare.len_le') },
{ value: 'len_lt', label: t('views.applicationWorkflow.compare.len_lt') }
2024-07-01 01:45:59 +00:00
]
export const nodeDict: any = {
[WorkflowType.AiChat]: aiChatNode,
[WorkflowType.SearchDataset]: searchDatasetNode,
[WorkflowType.Question]: questionNode,
[WorkflowType.Condition]: conditionNode,
[WorkflowType.Base]: baseNode,
[WorkflowType.Start]: startNode,
2024-08-15 09:17:25 +00:00
[WorkflowType.Reply]: replyNode,
[WorkflowType.FunctionLib]: functionLibNode,
2024-09-05 03:28:21 +00:00
[WorkflowType.FunctionLibCustom]: functionNode,
[WorkflowType.RrerankerNode]: rerankerNode,
2024-11-13 02:37:16 +00:00
[WorkflowType.FormNode]: formNode,
[WorkflowType.Application]: applicationNode,
[WorkflowType.DocumentExtractNode]: documentExtractNode,
2024-12-09 03:00:51 +00:00
[WorkflowType.ImageUnderstandNode]: imageUnderstandNode,
[WorkflowType.TextToSpeechNode]: textToSpeechNode,
[WorkflowType.SpeechToTextNode]: speechToTextNode,
2024-12-17 06:51:45 +00:00
[WorkflowType.ImageGenerateNode]: imageGenerateNode
2024-07-01 01:45:59 +00:00
}
export function isWorkFlow(type: string | undefined) {
return type === 'WORK_FLOW'
}
export function isLastNode(nodeModel: any) {
const incoming = nodeModel.graphModel.getNodeIncomingNode(nodeModel.id)
const outcomming = nodeModel.graphModel.getNodeOutgoingNode(nodeModel.id)
if (incoming.length > 0 && outcomming.length === 0) {
return true
} else {
return false
}
}