From 9cac8dc011c2129344acf44af57fb4121dbf2158 Mon Sep 17 00:00:00 2001 From: "zhanbo.lh" Date: Wed, 4 Dec 2024 01:30:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20xflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../9af73f40ad414c73-turbo.log.2024-12-03 | 10 + docs/xflow/layout.md | 2 +- docs/xflow/nodeSetting.md | 6 +- packages/x-flow/src/constants/index.ts | 261 ------------------ .../src/nodes/node-common/setting/index.tsx | 130 --------- .../src/nodes/node-end/setting/index.tsx | 130 --------- .../src/nodes/node-start/setting/index.tsx | 106 ------- packages/x-flow/src/withProvider.tsx | 2 +- 8 files changed, 15 insertions(+), 632 deletions(-) create mode 100644 .turbo/daemon/9af73f40ad414c73-turbo.log.2024-12-03 delete mode 100644 packages/x-flow/src/constants/index.ts delete mode 100644 packages/x-flow/src/nodes/node-common/setting/index.tsx delete mode 100644 packages/x-flow/src/nodes/node-end/setting/index.tsx delete mode 100644 packages/x-flow/src/nodes/node-start/setting/index.tsx diff --git a/.turbo/daemon/9af73f40ad414c73-turbo.log.2024-12-03 b/.turbo/daemon/9af73f40ad414c73-turbo.log.2024-12-03 new file mode 100644 index 000000000..a2ece7970 --- /dev/null +++ b/.turbo/daemon/9af73f40ad414c73-turbo.log.2024-12-03 @@ -0,0 +1,10 @@ +2024-12-03T17:26:27.588772Z WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/x-flow/src/types.ts")} +2024-12-03T17:26:27.588794Z WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("@xrenders/xflow"), path: AnchoredSystemPathBuf("packages/x-flow") }})) +2024-12-03T17:27:03.185223Z WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/x-flow/src/types.ts")} +2024-12-03T17:27:03.185237Z WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("@xrenders/xflow"), path: AnchoredSystemPathBuf("packages/x-flow") }})) +2024-12-03T17:27:46.488909Z WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/x-flow/src/withProvider.tsx")} +2024-12-03T17:27:46.488931Z WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("@xrenders/xflow"), path: AnchoredSystemPathBuf("packages/x-flow") }})) +2024-12-03T17:27:51.584147Z WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/x-flow/src/types.ts")} +2024-12-03T17:27:51.584179Z WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("@xrenders/xflow"), path: AnchoredSystemPathBuf("packages/x-flow") }})) +2024-12-03T17:29:05.583324Z WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/x-flow/src/withProvider.tsx")} +2024-12-03T17:29:05.583342Z WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("@xrenders/xflow"), path: AnchoredSystemPathBuf("packages/x-flow") }})) diff --git a/docs/xflow/layout.md b/docs/xflow/layout.md index c3bb48e7a..937ef17e7 100644 --- a/docs/xflow/layout.md +++ b/docs/xflow/layout.md @@ -1,5 +1,5 @@ --- -order: 1 +order: 5 title: '画布布局' mobile: false group: diff --git a/docs/xflow/nodeSetting.md b/docs/xflow/nodeSetting.md index 38e2930e2..ac9e72810 100644 --- a/docs/xflow/nodeSetting.md +++ b/docs/xflow/nodeSetting.md @@ -1,10 +1,10 @@ --- -order: 4 -title: '节点配置' +order: 1 +title: '节点菜单配置' mobile: false group: title: 最佳展示 - order: 2 + order: 1 --- # 节点配置 diff --git a/packages/x-flow/src/constants/index.ts b/packages/x-flow/src/constants/index.ts deleted file mode 100644 index c33d923f7..000000000 --- a/packages/x-flow/src/constants/index.ts +++ /dev/null @@ -1,261 +0,0 @@ -import type { Var } from '../types' -import { BlockEnum, VarType } from '../types'; - -export const CUSTOM_ITERATION_START_NODE = 'custom-iteration-start' - - -export const NODE_WIDTH = 240 -export const X_OFFSET = 60 -export const NODE_WIDTH_X_OFFSET = NODE_WIDTH + X_OFFSET -export const Y_OFFSET = 39 -export const MAX_TREE_DEPTH = 50 -export const START_INITIAL_POSITION = { x: 80, y: 282 } -export const AUTO_LAYOUT_OFFSET = { - x: -42, - y: 243, -} -export const ITERATION_NODE_Z_INDEX = 1 -export const ITERATION_CHILDREN_Z_INDEX = 1002 -export const ITERATION_PADDING = { - top: 65, - right: 16, - bottom: 20, - left: 16, -} -export const PARALLEL_LIMIT = 10 -export const PARALLEL_DEPTH_LIMIT = 3 - -export const RETRIEVAL_OUTPUT_STRUCT = `{ - "content": "", - "title": "", - "url": "", - "icon": "", - "metadata": { - "dataset_id": "", - "dataset_name": "", - "document_id": [], - "document_name": "", - "document_data_source_type": "", - "segment_id": "", - "segment_position": "", - "segment_word_count": "", - "segment_hit_count": "", - "segment_index_node_hash": "", - "score": "" - } -}` - -export const SUPPORT_OUTPUT_VARS_NODE = [ - BlockEnum.Start, BlockEnum.LLM, BlockEnum.KnowledgeRetrieval, BlockEnum.Code, BlockEnum.TemplateTransform, - BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner, BlockEnum.VariableAggregator, BlockEnum.QuestionClassifier, - BlockEnum.ParameterExtractor, BlockEnum.Iteration, -] - -export const LLM_OUTPUT_STRUCT: Var[] = [ - { - variable: 'text', - type: VarType.string, - }, -] - -export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [ - { - variable: 'result', - type: VarType.arrayObject, - }, -] - -export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [ - { - variable: 'output', - type: VarType.string, - }, -] - -export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [ - { - variable: 'class_name', - type: VarType.string, - }, -] - -export const HTTP_REQUEST_OUTPUT_STRUCT: Var[] = [ - { - variable: 'body', - type: VarType.string, - }, - { - variable: 'status_code', - type: VarType.number, - }, - { - variable: 'headers', - type: VarType.object, - }, - { - variable: 'files', - type: VarType.arrayFile, - }, -] - -export const TOOL_OUTPUT_STRUCT: Var[] = [ - { - variable: 'text', - type: VarType.string, - }, - { - variable: 'files', - type: VarType.arrayFile, - }, - { - variable: 'json', - type: VarType.arrayObject, - }, -] - -export const PARAMETER_EXTRACTOR_COMMON_STRUCT: Var[] = [ - { - variable: '__is_success', - type: VarType.number, - }, - { - variable: '__reason', - type: VarType.string, - }, -] - -export const WORKFLOW_DATA_UPDATE = 'WORKFLOW_DATA_UPDATE' -export const CUSTOM_NODE = 'custom' -export const CUSTOM_EDGE = 'custom' -export const DSL_EXPORT_CHECK = 'DSL_EXPORT_CHECK' - - - - -export const iconSettingMap: Record = { - Start: { - icon: { - type: 'icon-start', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#17B26A' - } - }, - End: { - icon: { - type: 'icon-end', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#F79009' - } - }, - Code: { - title: '代码执行', - icon: { - type: 'icon-code', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#2E90FA' - } - }, - Prompt: { - borderColor: '#3b82f6', - bgColor: '#f0f6fe', - icon: 'icon-prompt', - }, - LLM: { - borderColor: '#15afb3', - bgColor: '#e7f7f7', - icon: 'icon-model', - }, - Knowledge: { - borderColor: '#e7365d', - bgColor: '#fad4d7', - icon: 'icon-knowledge', - }, - Switch: { - title: '条件分支', - icon: { - type: 'icon-switch', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#06AED4' - } - }, - HSF: { - title: 'HSF 请求', - icon: { - type: 'icon-hsf', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#875BF7' - } - }, - Http: { - title: 'Http 请求', - icon: { - type: 'icon-http', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#875BF7' - } - }, - Tool: { - title: '工具', - icon: { - type: 'icon-gongju', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#2E90FA' - } - }, -}; - - -export const nodeConfigList = [ - { - title: 'Prompt', - type: 'prompt' - - }, - { - title: 'LLM', - type: 'llm' - }, - { - title: '知识库', - icon: 'icon-knowledge', - type: 'knowledge' - - - }, - { - title: 'Switch', - type: 'switch', - icon: { - type: 'icon-switch', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#06AED4' - } - }, - { - title: 'HSF', - type: 'hsf', - icon: { - type: 'icon-hsf', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#875BF7' - } - }, - { - title: 'Http', - type: 'http', - icon: { - type: 'icon-http', - style: { fontSize: 14, color: '#fff' }, - bgColor: '#875BF7' - } - }, - { - title: '脚步语言', - type: 'group', - items: [ - { title: 'Groovy', icon: 'icon-groovy', type: 'groovy' }, - { title: 'Javascript', icon: 'icon-js', type: 'javascript' }, - { title: 'Pathon', icon: 'icon-pathon', type: 'pathon' }, - ]} -]; - diff --git a/packages/x-flow/src/nodes/node-common/setting/index.tsx b/packages/x-flow/src/nodes/node-common/setting/index.tsx deleted file mode 100644 index ab584a305..000000000 --- a/packages/x-flow/src/nodes/node-common/setting/index.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { useEffect, useRef } from 'react'; -import { AnyObject } from 'antd/lib/_util/type'; -import FormRender, { useForm } from 'form-render'; -import { ICard, TYPES } from '../../constant'; -import FAutoComplete from '../../../components/FAutoComplete'; - -export interface GlobalOutputProps { - data?: AnyObject; - onChange: (data: AnyObject) => void; - flowList: ICard[]; - inputItem: ICard; - readonly?: boolean; -} - -const getSchema = (request: any) => ({ - type: 'object', - displayType: 'row', - properties: { - list: { - type: 'array', - widget: 'tableList', - props: { - hideMove: true, - hideCopy: true, - size: 'small', - addBtnProps: { - type: 'dashed', - }, - actionColumnProps: { - width: 60, - }, - }, - items: { - type: 'object', - properties: { - name: { - title: '名称', - type: 'string', - width: 200, - placeholder: '请输入', - rules: [ - { - pattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/, - message: '只能包含字母、数字和下划线且以字母或划线开头', - }, - ], - }, - dataType: { - title: '类型', - type: 'string', - enum: TYPES.map((el) => el.toUpperCase()), - enumNames: TYPES, - width: 120, - widget: 'select', - placeholder: '请选择', - }, - value: { - title: '值', - type: 'string', - widget: 'FAutoComplete', - props: { - placeholder: '${组件名.output}', - request, - }, - }, - }, - }, - }, - }, -}); - -export default (props: GlobalOutputProps) => { - const { data, onChange, inputItem, flowList, readonly } = props; - - const form = useForm(); - const flowListRef = useRef(); - const inputRef = useRef(); - - useEffect(() => { - flowListRef.current = flowList; - inputRef.current = inputItem; - }, [flowList, inputItem]); - - const watch = { - '#': (allValues: any) => { - onChange({ ...data, ...allValues }); - } - }; - - const request = (val: string) => { - return new Promise((resolve) => { - setTimeout(() => { - const inputValue = inputRef.current?.data; - const inputText = 'inputs'; - const options = (inputValue?.list || []) - .filter((el: any) => !!el.name) - .map((item: any) => '${#' + `${inputText}.${item.name}` + `}`); - const nodes = (flowListRef?.current || []) - .filter((el: any) => el.code !== 'Output') - .map((item: any) => { - return '${#' + `${item.code}.output` + `}`; - }); - - resolve( - [...options, ...nodes] - .filter((el: string) => val && el.includes(val)) - .map((el: string) => { - return { - value: el, - }; - }), - ); - }, 10); - }); - }; - const schema = getSchema(request); - - return ( - { - form.setValues({ list: data?.list }); - }} - /> - ); -} diff --git a/packages/x-flow/src/nodes/node-end/setting/index.tsx b/packages/x-flow/src/nodes/node-end/setting/index.tsx deleted file mode 100644 index ab584a305..000000000 --- a/packages/x-flow/src/nodes/node-end/setting/index.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { useEffect, useRef } from 'react'; -import { AnyObject } from 'antd/lib/_util/type'; -import FormRender, { useForm } from 'form-render'; -import { ICard, TYPES } from '../../constant'; -import FAutoComplete from '../../../components/FAutoComplete'; - -export interface GlobalOutputProps { - data?: AnyObject; - onChange: (data: AnyObject) => void; - flowList: ICard[]; - inputItem: ICard; - readonly?: boolean; -} - -const getSchema = (request: any) => ({ - type: 'object', - displayType: 'row', - properties: { - list: { - type: 'array', - widget: 'tableList', - props: { - hideMove: true, - hideCopy: true, - size: 'small', - addBtnProps: { - type: 'dashed', - }, - actionColumnProps: { - width: 60, - }, - }, - items: { - type: 'object', - properties: { - name: { - title: '名称', - type: 'string', - width: 200, - placeholder: '请输入', - rules: [ - { - pattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/, - message: '只能包含字母、数字和下划线且以字母或划线开头', - }, - ], - }, - dataType: { - title: '类型', - type: 'string', - enum: TYPES.map((el) => el.toUpperCase()), - enumNames: TYPES, - width: 120, - widget: 'select', - placeholder: '请选择', - }, - value: { - title: '值', - type: 'string', - widget: 'FAutoComplete', - props: { - placeholder: '${组件名.output}', - request, - }, - }, - }, - }, - }, - }, -}); - -export default (props: GlobalOutputProps) => { - const { data, onChange, inputItem, flowList, readonly } = props; - - const form = useForm(); - const flowListRef = useRef(); - const inputRef = useRef(); - - useEffect(() => { - flowListRef.current = flowList; - inputRef.current = inputItem; - }, [flowList, inputItem]); - - const watch = { - '#': (allValues: any) => { - onChange({ ...data, ...allValues }); - } - }; - - const request = (val: string) => { - return new Promise((resolve) => { - setTimeout(() => { - const inputValue = inputRef.current?.data; - const inputText = 'inputs'; - const options = (inputValue?.list || []) - .filter((el: any) => !!el.name) - .map((item: any) => '${#' + `${inputText}.${item.name}` + `}`); - const nodes = (flowListRef?.current || []) - .filter((el: any) => el.code !== 'Output') - .map((item: any) => { - return '${#' + `${item.code}.output` + `}`; - }); - - resolve( - [...options, ...nodes] - .filter((el: string) => val && el.includes(val)) - .map((el: string) => { - return { - value: el, - }; - }), - ); - }, 10); - }); - }; - const schema = getSchema(request); - - return ( - { - form.setValues({ list: data?.list }); - }} - /> - ); -} diff --git a/packages/x-flow/src/nodes/node-start/setting/index.tsx b/packages/x-flow/src/nodes/node-start/setting/index.tsx deleted file mode 100644 index 4754e202b..000000000 --- a/packages/x-flow/src/nodes/node-start/setting/index.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import FormRender, { useForm } from 'form-render'; -import ExpandInput from '@/components/ExpandInput'; -import { TYPES } from '../../constant'; - -const schema = { - type: 'object', - displayType: 'row', - properties: { - list: { - type: 'array', - widget: 'tableList', - props: { - hideMove: true, - hideCopy: true, - onRemove: 'onRemove', - size: 'small', - addBtnProps: { - type: 'dashed' - }, - pagination: { - pageSize: 15 - }, - actionColumnProps: { - width: 55 - } - }, - items: { - type: 'object', - properties: { - name: { - title: '参数名称', - type: 'string', - width: 200, - placeholder: '请输入', - disabled: `{{ rootValue.name === 'session_id' }}`, - rules: [ - { - pattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/, - message: '只能包含字母、数字和下划线且以字母或划线开头' - } - ] - }, - dataType: { - title: '参数类型', - type: 'string', - enum: TYPES.map((el) => el.toUpperCase()), - enumNames: TYPES, - widget: 'select', - width: 120, - placeholder: '请选择', - disabled: `{{ rootValue.name === 'session_id' }}` - }, - value: { - title: '参数值', - type: 'string', - widget: 'ExpandInput', - placeholder: '变量:${变量名称}', - disabled: `{{ rootValue.name === 'session_id' }}` - } - } - } - } - } -}; - - - - -/** - * - * 全局输入参数配置 - * - */ -export default (props: any) => { - const { data, onChange, readonly } = props; - const form = useForm(); - - const onRemove = (deleteFn: any, params: any) => { - if (params.data?.name === 'session_id') { - props.setIsChatFlow(false); - } - deleteFn(); - }; - - const watch = { - '#': (allValues: any) => { - onChange({ ...data, ...allValues }); - }, - }; - - return ( -
- { - form.setValues({list: data?.list || []}); - }} - /> -
- ); -} diff --git a/packages/x-flow/src/withProvider.tsx b/packages/x-flow/src/withProvider.tsx index 4cd8ef796..6d3436256 100644 --- a/packages/x-flow/src/withProvider.tsx +++ b/packages/x-flow/src/withProvider.tsx @@ -13,7 +13,7 @@ interface ProviderProps { } export default function withProvider( - Element: React.ComponentType, + Element: any, defaultWidgets?: any ): React.ComponentType { return (props: ProviderProps) => {