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

479 lines
14 KiB
TypeScript
Raw Normal View History

2025-06-03 09:29:33 +00:00
import { WorkflowType } from '@/enums/application'
2025-06-03 08:08:49 +00:00
import { t } from '@/locales'
export const startNode = {
id: WorkflowType.Start,
type: WorkflowType.Start,
x: 480,
y: 3340,
properties: {
height: 364,
stepName: t('views.applicationWorkflow.nodes.startNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.startNode.question'),
2025-07-07 08:08:37 +00:00
value: 'question',
},
2025-06-03 08:08:49 +00:00
],
globalFields: [
{ label: t('views.applicationWorkflow.nodes.startNode.currentTime'), value: 'time' },
{
2025-06-05 09:28:07 +00:00
label: t('views.application.form.historyRecord.label'),
2025-07-07 08:08:37 +00:00
value: 'history_context',
2025-06-03 08:08:49 +00:00
},
{
label: t('chat.chatId'),
2025-07-07 08:08:37 +00:00
value: 'chat_id',
},
],
2025-06-03 08:08:49 +00:00
},
fields: [{ label: t('views.applicationWorkflow.nodes.startNode.question'), value: 'question' }],
globalFields: [
2025-07-07 08:08:37 +00:00
{ label: t('views.applicationWorkflow.nodes.startNode.currentTime'), value: 'time' },
2025-06-03 08:08:49 +00:00
],
2025-07-07 08:08:37 +00:00
showNode: true,
},
2025-06-03 08:08:49 +00:00
}
export const baseNode = {
id: WorkflowType.Base,
type: WorkflowType.Base,
x: 360,
y: 2761.3875,
text: '',
properties: {
height: 728.375,
stepName: t('views.applicationWorkflow.nodes.baseNode.label'),
input_field_list: [],
node_data: {
name: '',
desc: '',
// @ts-ignore
2025-06-05 09:28:07 +00:00
prologue: t('views.application.form.defaultPrologue'),
2025-07-07 08:08:37 +00:00
tts_type: 'BROWSER',
2025-06-03 08:08:49 +00:00
},
config: {},
showNode: true,
user_input_config: { title: t('chat.userInput') },
2025-07-07 08:08:37 +00:00
user_input_field_list: [],
},
2025-06-03 08:08:49 +00:00
}
/**
*
* type nodes
*/
export const baseNodes = [baseNode, startNode]
/**
* ai
*/
export const aiChatNode = {
type: WorkflowType.AiChat,
text: t('views.applicationWorkflow.nodes.aiChatNode.text'),
label: t('views.applicationWorkflow.nodes.aiChatNode.label'),
height: 340,
properties: {
stepName: t('views.applicationWorkflow.nodes.aiChatNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.aiChatNode.answer'),
2025-07-07 08:08:37 +00:00
value: 'answer',
2025-06-03 08:08:49 +00:00
},
{
label: t('views.applicationWorkflow.nodes.aiChatNode.think'),
2025-07-07 08:08:37 +00:00
value: 'reasoning_content',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
/**
*
*/
2025-06-13 09:17:01 +00:00
export const searchKnowledgeNode = {
type: WorkflowType.SearchKnowledge,
text: t('views.applicationWorkflow.nodes.searchKnowledgeNode.text'),
label: t('views.applicationWorkflow.nodes.searchKnowledgeNode.label'),
2025-06-03 08:08:49 +00:00
height: 355,
properties: {
2025-06-13 09:17:01 +00:00
stepName: t('views.applicationWorkflow.nodes.searchKnowledgeNode.label'),
2025-06-03 08:08:49 +00:00
config: {
fields: [
{
2025-06-13 09:17:01 +00:00
label: t('views.applicationWorkflow.nodes.searchKnowledgeNode.paragraph_list'),
2025-07-07 08:08:37 +00:00
value: 'paragraph_list',
2025-06-03 08:08:49 +00:00
},
{
2025-07-07 08:08:37 +00:00
label: t(
'views.applicationWorkflow.nodes.searchKnowledgeNode.is_hit_handling_method_list',
),
value: 'is_hit_handling_method_list',
2025-06-03 08:08:49 +00:00
},
{
2025-06-13 09:17:01 +00:00
label: t('views.applicationWorkflow.nodes.searchKnowledgeNode.result'),
2025-07-07 08:08:37 +00:00
value: 'data',
2025-06-03 08:08:49 +00:00
},
{
2025-06-13 09:17:01 +00:00
label: t('views.applicationWorkflow.nodes.searchKnowledgeNode.directly_return'),
2025-07-07 08:08:37 +00:00
value: 'directly_return',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const questionNode = {
type: WorkflowType.Question,
text: t('views.applicationWorkflow.nodes.questionNode.text'),
label: t('views.applicationWorkflow.nodes.questionNode.label'),
height: 345,
properties: {
stepName: t('views.applicationWorkflow.nodes.questionNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.questionNode.result'),
2025-07-07 08:08:37 +00:00
value: 'answer',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const conditionNode = {
type: WorkflowType.Condition,
text: t('views.applicationWorkflow.nodes.conditionNode.text'),
label: t('views.applicationWorkflow.nodes.conditionNode.label'),
height: 175,
properties: {
width: 600,
stepName: t('views.applicationWorkflow.nodes.conditionNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.conditionNode.branch_name'),
2025-07-07 08:08:37 +00:00
value: 'branch_name',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const replyNode = {
type: WorkflowType.Reply,
text: t('views.applicationWorkflow.nodes.replyNode.text'),
label: t('views.applicationWorkflow.nodes.replyNode.label'),
height: 210,
properties: {
stepName: t('views.applicationWorkflow.nodes.replyNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.replyNode.content'),
2025-07-07 08:08:37 +00:00
value: 'answer',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const rerankerNode = {
type: WorkflowType.RrerankerNode,
text: t('views.applicationWorkflow.nodes.rerankerNode.text'),
label: t('views.applicationWorkflow.nodes.rerankerNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.rerankerNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.rerankerNode.result_list'),
2025-07-07 08:08:37 +00:00
value: 'result_list',
2025-06-03 08:08:49 +00:00
},
{
label: t('views.applicationWorkflow.nodes.rerankerNode.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const formNode = {
type: WorkflowType.FormNode,
text: t('views.applicationWorkflow.nodes.formNode.text'),
label: t('views.applicationWorkflow.nodes.formNode.label'),
height: 252,
properties: {
width: 600,
stepName: t('views.applicationWorkflow.nodes.formNode.label'),
node_data: {
is_result: true,
form_field_list: [],
form_content_format: `${t('views.applicationWorkflow.nodes.formNode.form_content_format1')}
{{form}}
2025-07-07 08:08:37 +00:00
${t('views.applicationWorkflow.nodes.formNode.form_content_format2')}`,
2025-06-03 08:08:49 +00:00
},
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.formNode.form_data'),
2025-07-07 08:08:37 +00:00
value: 'form_data',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const documentExtractNode = {
type: WorkflowType.DocumentExtractNode,
text: t('views.applicationWorkflow.nodes.documentExtractNode.text'),
label: t('views.applicationWorkflow.nodes.documentExtractNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.documentExtractNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.documentExtractNode.content'),
2025-07-07 08:08:37 +00:00
value: 'content',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const imageUnderstandNode = {
type: WorkflowType.ImageUnderstandNode,
text: t('views.applicationWorkflow.nodes.imageUnderstandNode.text'),
label: t('views.applicationWorkflow.nodes.imageUnderstandNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.imageUnderstandNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.imageUnderstandNode.answer'),
2025-07-07 08:08:37 +00:00
value: 'answer',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const variableAssignNode = {
type: WorkflowType.VariableAssignNode,
text: t('views.applicationWorkflow.nodes.variableAssignNode.text'),
label: t('views.applicationWorkflow.nodes.variableAssignNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.variableAssignNode.label'),
2025-07-07 08:08:37 +00:00
config: {},
},
2025-06-03 08:08:49 +00:00
}
export const mcpNode = {
type: WorkflowType.McpNode,
text: t('views.applicationWorkflow.nodes.mcpNode.text'),
label: t('views.applicationWorkflow.nodes.mcpNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.mcpNode.label'),
config: {
fields: [
{
label: t('common.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const imageGenerateNode = {
type: WorkflowType.ImageGenerateNode,
text: t('views.applicationWorkflow.nodes.imageGenerateNode.text'),
label: t('views.applicationWorkflow.nodes.imageGenerateNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.imageGenerateNode.label'),
config: {
fields: [
{
label: t('views.applicationWorkflow.nodes.imageGenerateNode.answer'),
2025-07-07 08:08:37 +00:00
value: 'answer',
2025-06-03 08:08:49 +00:00
},
{
label: t('common.fileUpload.image'),
2025-07-07 08:08:37 +00:00
value: 'image',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const speechToTextNode = {
type: WorkflowType.SpeechToTextNode,
text: t('views.applicationWorkflow.nodes.speechToTextNode.text'),
label: t('views.applicationWorkflow.nodes.speechToTextNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.speechToTextNode.label'),
config: {
fields: [
{
label: t('common.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const textToSpeechNode = {
type: WorkflowType.TextToSpeechNode,
text: t('views.applicationWorkflow.nodes.textToSpeechNode.text'),
label: t('views.applicationWorkflow.nodes.textToSpeechNode.label'),
height: 252,
properties: {
stepName: t('views.applicationWorkflow.nodes.textToSpeechNode.label'),
config: {
fields: [
{
label: t('common.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
2025-07-08 18:58:16 +00:00
/**
*
*/
export const toolNode = {
type: WorkflowType.ToolLibCustom,
text: t('views.applicationWorkflow.nodes.toolNode.text'),
label: t('views.applicationWorkflow.nodes.toolNode.label'),
height: 260,
properties: {
stepName: t('views.applicationWorkflow.nodes.toolNode.label'),
config: {
fields: [
{
label: t('common.result'),
value: 'result',
},
],
},
},
}
2025-06-03 08:08:49 +00:00
export const menuNodes = [
2025-07-07 08:08:37 +00:00
{
label: t('views.applicationWorkflow.nodes.classify.aiCapability'),
list: [
aiChatNode,
questionNode,
imageGenerateNode,
imageUnderstandNode,
textToSpeechNode,
speechToTextNode,
],
},
2025-06-30 10:06:18 +00:00
{ label: t('views.knowledge.title'), list: [searchKnowledgeNode, rerankerNode] },
2025-07-07 08:08:37 +00:00
{
label: t('views.applicationWorkflow.nodes.classify.businessLogic'),
list: [conditionNode, formNode, variableAssignNode, replyNode],
},
{
label: t('views.applicationWorkflow.nodes.classify.other'),
2025-07-08 18:58:16 +00:00
list: [mcpNode, documentExtractNode, toolNode],
2025-07-07 08:08:37 +00:00
},
2025-06-03 08:08:49 +00:00
]
2025-07-08 18:58:16 +00:00
2025-06-03 08:08:49 +00:00
/**
2025-07-08 18:58:16 +00:00
*
2025-06-03 08:08:49 +00:00
*/
2025-06-26 13:13:43 +00:00
export const toolLibNode = {
2025-06-26 12:25:24 +00:00
type: WorkflowType.ToolLib,
text: t('views.applicationWorkflow.nodes.toolNode.text'),
label: t('views.applicationWorkflow.nodes.toolNode.label'),
2025-06-03 08:08:49 +00:00
height: 170,
properties: {
2025-06-26 12:25:24 +00:00
stepName: t('views.applicationWorkflow.nodes.toolNode.label'),
2025-06-03 08:08:49 +00:00
config: {
fields: [
{
label: t('common.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const applicationNode = {
type: WorkflowType.Application,
text: t('views.applicationWorkflow.nodes.applicationNode.label'),
label: t('views.applicationWorkflow.nodes.applicationNode.label'),
height: 260,
properties: {
stepName: t('views.applicationWorkflow.nodes.applicationNode.label'),
config: {
fields: [
{
label: t('common.result'),
2025-07-07 08:08:37 +00:00
value: 'result',
},
],
},
},
2025-06-03 08:08:49 +00:00
}
export const compareList = [
{ 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') },
{ value: 'is_true', label: t('views.applicationWorkflow.compare.is_true') },
2025-07-07 08:08:37 +00:00
{ value: 'is_not_true', label: t('views.applicationWorkflow.compare.is_not_true') },
2025-06-03 08:08:49 +00:00
]
export const nodeDict: any = {
[WorkflowType.AiChat]: aiChatNode,
2025-06-13 09:17:01 +00:00
[WorkflowType.SearchKnowledge]: searchKnowledgeNode,
2025-06-03 08:08:49 +00:00
[WorkflowType.Question]: questionNode,
[WorkflowType.Condition]: conditionNode,
[WorkflowType.Base]: baseNode,
[WorkflowType.Start]: startNode,
[WorkflowType.Reply]: replyNode,
2025-06-26 12:25:24 +00:00
[WorkflowType.ToolLib]: toolNode,
[WorkflowType.ToolLibCustom]: toolNode,
2025-06-03 08:08:49 +00:00
[WorkflowType.RrerankerNode]: rerankerNode,
[WorkflowType.FormNode]: formNode,
[WorkflowType.Application]: applicationNode,
[WorkflowType.DocumentExtractNode]: documentExtractNode,
[WorkflowType.ImageUnderstandNode]: imageUnderstandNode,
[WorkflowType.TextToSpeechNode]: textToSpeechNode,
[WorkflowType.SpeechToTextNode]: speechToTextNode,
[WorkflowType.ImageGenerateNode]: imageGenerateNode,
[WorkflowType.VariableAssignNode]: variableAssignNode,
2025-07-07 08:08:37 +00:00
[WorkflowType.McpNode]: mcpNode,
2025-06-03 08:08:49 +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
}
}