Skip to content

Commit

Permalink
feat:1.新增nodewidgets自定义节点配置 2.内置switch条件节点
Browse files Browse the repository at this point in the history
  • Loading branch information
昔梦 committed Dec 3, 2024
1 parent 04bda84 commit 6c07d3e
Show file tree
Hide file tree
Showing 22 changed files with 527 additions and 80 deletions.
21 changes: 11 additions & 10 deletions docs/xflow/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ title: API

单个节点配置

| 属性 | 描述 | 类型 | 默认值 |
| ------------------ | ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| title | 节点名称 | `string` | |
| type | 节点类型 | `string` | |
| hidden | 是否在配置面板中显示节点 | `boolean` | false |
| targetHandleHidden | 是否隐藏左侧输入连接头 | `boolean` | false |
| sourceHandleHidden | 是否隐藏右侧输出连接头 | `boolean` | false |
| icon | 节点的图标配置 | `{type:string;bgColor:string}` | |
| settingSchema | 节点的业务配置信息,详见[form-render 文档](/form-render/api-schema) | <a target="_blank" href="https://github.com/alibaba/x-render/blob/e2feff8fdb3bef5537b92a2157dbbf40b9d4eb17/packages/form-render/src/type.ts#L32">SchemaBase</a> | |
| settingWidget | 自定义节点的业务配置组件 | `string` | |
| 属性 | 描述 | 类型 | 默认值 |
| ------------------ | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| title | 节点名称 | `string` | |
| type | 节点类型 | `string` | |
| hidden | 是否在配置面板中显示节点 | `boolean` | false |
| targetHandleHidden | 是否隐藏左侧输入连接头 | `boolean` | false |
| sourceHandleHidden | 是否隐藏右侧输出连接头 | `boolean` | false |
| icon | 节点的图标配置 | `{type:string;bgColor:string}` | |
| settingSchema | 节点的业务配置信息,详见[form-render 文档](/form-render/api-schema)。同时设置`settingSchema``settingWidget`只生效`settingWidget` | <a target="_blank" href="https://github.com/alibaba/x-render/blob/e2feff8fdb3bef5537b92a2157dbbf40b9d4eb17/packages/form-render/src/type.ts#L32">SchemaBase</a> | |
| settingWidget | 自定义节点的业务配置组件,在弹窗中展示。同时设置`settingSchema``settingWidget`只生效`settingWidget`。定义之后需要在`widgets`中引入自定义组件。 | `string` | |
| nodeWidget | 自定义节点的业务配置信息展示组件,在节点内部展示业务配置信息。定义之后需要在`widgets`中引入自定义组件。 | `string` | |

## TNodeSelector

Expand Down
9 changes: 7 additions & 2 deletions docs/xflow/custom-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ group:

使用`settingWidget`自定义业务配置组件

<code src="./demo/custom-flow/index.tsx"></code>
<code src="./demo/custom-flow/index.tsx"></code>


## 在schema中自定义组件
Expand Down Expand Up @@ -70,4 +70,9 @@ export default () => {
}


```
```

## 自定义业务配置信息展示组件
使用`nodeWidget`自定义节点的业务配置信息展示组件,在节点内部展示业务配置信息

<code src="./demo/nodeWidget"></code>
53 changes: 53 additions & 0 deletions docs/xflow/demo/nodeWidget/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import XFlow from '@xrenders/xflow';
import settings from './setting';
import { Space, Tag, Typography } from 'antd';


const customNodeWidget = ({ data }) => {
return <div style={{ wordWrap: "break-word" }}>
<p>变量一:{data?.input}</p>
<p>变量二:{data?.select}</p>
</div>
}


const endNodeWidget = ({ data }) => {
return <div style={{ wordWrap: "break-word" }}>
{data?.input}
</div>
}


const LLMNodeWidget = ({ data }) => {
const labels = Object.keys(data) || [];
return <Space direction='vertical'>
{labels?.map(item => <Tag color='geekblue' ><Typography.Text style={{ maxWidth: 216 }} ellipsis={true}>{data[item]}</Typography.Text></Tag>)}
</Space>
}

export default () => {
const nodes = [
{ id: '1', type: 'Start', data: { input: '开始节点', select: "b" }, position: { x: 40, y: 240 } },
{ id: '2', type: 'LLM', data: { input1: 'input1' }, position: { x: 400, y: 240 } },
{ id: '3', type: 'End', data: { input: '通过nodeWidget自定义配置展示' }, position: { x: 800, y: 240 } }
];

const edges = [
{ source: '1', target: '2', id: '234123' },
{ source: '2', target: '3', id: '56891' }
]

return (
<div style={{ height: '600px' }}>
<XFlow
initialValues={{ nodes, edges }}
settings={settings}
nodeSelector={{
showSearch: true,
}}
widgets={{ customNodeWidget, endNodeWidget, LLMNodeWidget }}
/>
</div>
);
}
90 changes: 90 additions & 0 deletions docs/xflow/demo/nodeWidget/setting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
export default [
{
title: '开始',
type: 'Start',
hidden: true,
targetHandleHidden: true,
icon: {
type: 'icon-start',
bgColor: '#17B26A',
},
settingSchema: {
type: "object",
properties: {
input: {
title: '变量一',
type: 'string',
widget: 'input',
},
select: {
title: '变量二',
type: 'string',
widget: 'select',
props: {
options: [
{ label: 'a', value: 'a' },
{ label: 'b', value: 'b' },
{ label: 'c', value: 'c' },
],
},
},
}
},
nodeWidget:'customNodeWidget'
},
{
title: '结束',
type: 'End',
hidden: true,
sourceHandleHidden: true,
icon: {
type: 'icon-end',
bgColor: '#F79009',
},
settingSchema: {
type: "object",
properties: {
input: {
title: '结束原因',
type: 'string',
widget: 'textArea',
},
}
},
nodeWidget: 'endNodeWidget',
},
{
title: 'LLM',
type: 'LLM',
description: '调用大语言模型回答问题或者对自然语言进行处理',
icon: {
type: 'icon-model',
bgColor: '#6172F3',
},
settingSchema: {
type: 'object',
displayType: 'row',
labelCol: 6,
fieldCol:18,
properties: {
input1: {
title: 'Field A',
type: 'string',
},
input2: {
title: 'Field B',
type: 'string'
},
input3: {
title: 'Field C',
type: 'string'
},
input4: {
title: 'Field D',
type: 'string'
}
}
},
nodeWidget: 'LLMNodeWidget',
},
];
23 changes: 23 additions & 0 deletions docs/xflow/demo/switchNode/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import XFlow from '@xrenders/xflow';
import settings from './setting';

export default () => {
const nodes = [
{ id: '1', type: 'Switch', data: { input: '开始节点', select: "b" }, position: { x: 40, y: 240 } },
];

const edges = []

return (
<div style={{ height: '600px' }}>
<XFlow
initialValues={{ nodes, edges }}
settings={settings}
nodeSelector={{
showSearch: true,
}}
/>
</div>
);
}
29 changes: 29 additions & 0 deletions docs/xflow/demo/switchNode/setting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default [
{
title: 'Switch',
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
bgColor: '#06AED4',
},
},
{
title: 'Prompt',
type: 'Prompt',
description: '通过精心设计提示词,提升大语言模型回答效果',
icon: {
type: 'icon-prompt',
bgColor: '#17B26A',
},
},
{
title: '知识库',
type: 'knowledge',
description: '允许你从知识库中查询与用户问题相关的文本内容',
icon: {
type: 'icon-knowledge',
bgColor: '#6172F3',
},
},
];
13 changes: 13 additions & 0 deletions docs/xflow/nodeBuildIn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
order: 4
title: '内置节点'
mobile: false
group:
title: 最佳展示
order: 2
---
# 内置节点

## 条件内置节点
SwitchNode
<code src="./demo/switchNode/index.tsx"></code>
9 changes: 9 additions & 0 deletions packages/x-flow/src/components/CustomNode/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
pointer-events: none;
transition: all 0.3s;
}

.xflow-node-switch-title{
position: absolute;
left: -45px;
top: 6px;
font-weight: 600;
text-align: right;
width: 35px;
}
}

.xflow-node-container-tb {
Expand Down
Loading

0 comments on commit 6c07d3e

Please sign in to comment.