Compare commits
16 Commits
jpa
...
f6bd7e52e1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6bd7e52e1 | ||
|
|
6f7f7cea67 | ||
|
|
33df256863 | ||
|
|
3a51d1e33f | ||
|
|
d3c7457889 | ||
| 2d2eaafcd4 | |||
|
|
566dfef208 | ||
| 1cba0f4422 | |||
| ab56385c8a | |||
| b58c34443f | |||
| 53638a8a6d | |||
| dc55605c99 | |||
| 7345774258 | |||
| fcf5f8ad18 | |||
|
|
b53ee57dc3 | ||
|
|
b916acb1c3 |
@@ -155,6 +155,11 @@
|
|||||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||||
<version>2.13.2</version>
|
<version>2.13.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-el-builder</artifactId>
|
||||||
|
<version>2.13.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon-ai</artifactId>
|
<artifactId>solon-ai</artifactId>
|
||||||
|
|||||||
@@ -62,6 +62,10 @@
|
|||||||
<groupId>com.yomahub</groupId>
|
<groupId>com.yomahub</groupId>
|
||||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-el-builder</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.flow;
|
||||||
|
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250625
|
||||||
|
*/
|
||||||
|
public abstract class BaseNode extends NodeComponent {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.flow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250625
|
||||||
|
*/
|
||||||
|
public class EndNode extends BaseNode {
|
||||||
|
@Override
|
||||||
|
public void process() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.flow;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.yomahub.liteflow.builder.LiteFlowNodeBuilder;
|
||||||
|
import com.yomahub.liteflow.builder.el.ELBus;
|
||||||
|
import com.yomahub.liteflow.core.NodeComponent;
|
||||||
|
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250625
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class LiteFlowService {
|
||||||
|
public LiteFlowService() {
|
||||||
|
createNode("start-amis-node", NodeTypeEnum.COMMON, StartNode.class);
|
||||||
|
createNode("end-amis-node", NodeTypeEnum.COMMON, EndNode.class);
|
||||||
|
createNode("llm-amis-node", NodeTypeEnum.COMMON, LlmNode.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createNode(String name, NodeTypeEnum type, Class<? extends NodeComponent> clazz) {
|
||||||
|
LiteFlowNodeBuilder.createNode()
|
||||||
|
.setId(name)
|
||||||
|
.setName(name)
|
||||||
|
.setType(type)
|
||||||
|
.setClazz(clazz)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class FlowData {
|
||||||
|
private List<Node> nodes;
|
||||||
|
private List<Edge> edges;
|
||||||
|
private Map<String, Object> data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Node {
|
||||||
|
private String id;
|
||||||
|
private String type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Edge {
|
||||||
|
private String id;
|
||||||
|
private String source;
|
||||||
|
private String target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
// language=JSON
|
||||||
|
String source = """
|
||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"id": "BMFP3Eov94",
|
||||||
|
"type": "start-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 10,
|
||||||
|
"y": 100
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "PYK8LjduQ1",
|
||||||
|
"type": "end-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 654,
|
||||||
|
"y": 332
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": false,
|
||||||
|
"dragging": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "nCm-ij5I6o",
|
||||||
|
"type": "llm-amis-node",
|
||||||
|
"position": {
|
||||||
|
"x": 318,
|
||||||
|
"y": 208
|
||||||
|
},
|
||||||
|
"data": {},
|
||||||
|
"measured": {
|
||||||
|
"width": 256,
|
||||||
|
"height": 83
|
||||||
|
},
|
||||||
|
"selected": true,
|
||||||
|
"dragging": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"edges": [
|
||||||
|
{
|
||||||
|
"source": "BMFP3Eov94",
|
||||||
|
"target": "nCm-ij5I6o",
|
||||||
|
"id": "xy-edge__BMFP3Eov94-nCm-ij5I6o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "nCm-ij5I6o",
|
||||||
|
"target": "PYK8LjduQ1",
|
||||||
|
"id": "xy-edge__nCm-ij5I6o-PYK8LjduQ1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"data": {
|
||||||
|
"BMFP3Eov94": {
|
||||||
|
"inputs": {
|
||||||
|
"name": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "text",
|
||||||
|
"description": "文件描述"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nCm-ij5I6o": {
|
||||||
|
"model": "qwen3",
|
||||||
|
"outputs": {
|
||||||
|
"text": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systemPrompt": "你是个沙雕"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
FlowData root = mapper.readValue(StrUtil.trim(source), FlowData.class);
|
||||||
|
log.info("{}", root);
|
||||||
|
log.info(
|
||||||
|
"\n{}",
|
||||||
|
ELBus.ser(
|
||||||
|
"start-amis-node",
|
||||||
|
ELBus.ser("start-amis-node", "end-amis-node"),
|
||||||
|
"end-amis-node"
|
||||||
|
).toEL(true)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.flow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250625
|
||||||
|
*/
|
||||||
|
public class LlmNode extends BaseNode {
|
||||||
|
@Override
|
||||||
|
public void process() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.flow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250625
|
||||||
|
*/
|
||||||
|
public class StartNode extends BaseNode {
|
||||||
|
@Override
|
||||||
|
public void process() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,32 +15,31 @@
|
|||||||
"@echofly/fetch-event-source": "^3.0.2",
|
"@echofly/fetch-event-source": "^3.0.2",
|
||||||
"@fortawesome/fontawesome-free": "^6.7.2",
|
"@fortawesome/fontawesome-free": "^6.7.2",
|
||||||
"@lightenna/react-mermaid-diagram": "^1.0.20",
|
"@lightenna/react-mermaid-diagram": "^1.0.20",
|
||||||
"@tinyflow-ai/react": "^0.2.1",
|
"@xyflow/react": "^12.7.1",
|
||||||
"ahooks": "^3.8.5",
|
"ahooks": "^3.8.5",
|
||||||
"amis": "^6.12.0",
|
"amis": "^6.12.0",
|
||||||
"antd": "^5.26.1",
|
"antd": "^5.26.2",
|
||||||
"axios": "^1.10.0",
|
"axios": "^1.10.0",
|
||||||
"chart.js": "^4.5.0",
|
"chart.js": "^4.5.0",
|
||||||
"echarts-for-react": "^3.0.2",
|
"echarts-for-react": "^3.0.2",
|
||||||
"licia": "^1.48.0",
|
"licia": "^1.48.0",
|
||||||
"markdown-it": "^14.1.0",
|
"mermaid": "^11.7.0",
|
||||||
"mermaid": "^11.6.0",
|
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-chartjs-2": "^5.3.0",
|
"react-chartjs-2": "^5.3.0",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
"react-router": "^7.6.2",
|
"react-router": "^7.6.2",
|
||||||
"styled-components": "^6.1.18"
|
"styled-components": "^6.1.19",
|
||||||
|
"zustand": "^5.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/markdown-it": "^14.1.2",
|
|
||||||
"@types/react": "^18.3.23",
|
"@types/react": "^18.3.23",
|
||||||
"@types/react-dom": "^18.3.7",
|
"@types/react-dom": "^18.3.7",
|
||||||
"@vitejs/plugin-react-swc": "^3.10.2",
|
"@vitejs/plugin-react-swc": "^3.10.2",
|
||||||
"globals": "^16.2.0",
|
"globals": "^16.2.0",
|
||||||
"sass": "^1.89.2",
|
"sass": "^1.89.2",
|
||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"vite": "^6.3.5",
|
"vite": "^7.0.0",
|
||||||
"vite-plugin-javascript-obfuscator": "^3.1.0"
|
"vite-plugin-javascript-obfuscator": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
525
service-web/client/pnpm-lock.yaml
generated
525
service-web/client/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,26 @@
|
|||||||
import {ProLayout} from '@ant-design/pro-components'
|
import {ProLayout} from '@ant-design/pro-components'
|
||||||
|
import {ConfigProvider} from 'antd'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Outlet, useLocation, useNavigate} from 'react-router'
|
import {Outlet, useLocation, useNavigate} from 'react-router'
|
||||||
import {menus} from '../route.tsx'
|
import {menus} from '../route.tsx'
|
||||||
|
|
||||||
|
const apps: { title: string, desc: string, url: string, icon?: string }[] = [
|
||||||
|
{
|
||||||
|
icon: 'http://132.126.207.124:8686/udal-manager/static/favicon.ico',
|
||||||
|
title: 'CSV-HUDI处理平台',
|
||||||
|
desc: 'Hudi 批量割接、稽核任务管理平台',
|
||||||
|
url: 'http://132.126.207.124:8686/udal-manager/',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
return (
|
return (
|
||||||
<ProLayout
|
<ProLayout
|
||||||
token={{
|
token={{
|
||||||
|
colorTextAppListIcon: '#dfdfdf',
|
||||||
|
colorTextAppListIconHover: '#ffffff',
|
||||||
header: {
|
header: {
|
||||||
colorBgHeader: '#292f33',
|
colorBgHeader: '#292f33',
|
||||||
colorHeaderTitle: '#ffffff',
|
colorHeaderTitle: '#ffffff',
|
||||||
@@ -20,6 +32,8 @@ const App: React.FC = () => {
|
|||||||
colorTextRightActionsItem: '#dfdfdf',
|
colorTextRightActionsItem: '#dfdfdf',
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
appList={apps}
|
||||||
|
disableMobile={true}
|
||||||
logo={<img src="icon.png" alt="logo"/>}
|
logo={<img src="icon.png" alt="logo"/>}
|
||||||
title="Hudi 服务总台"
|
title="Hudi 服务总台"
|
||||||
route={menus}
|
route={menus}
|
||||||
@@ -33,8 +47,19 @@ const App: React.FC = () => {
|
|||||||
splitMenus={true}
|
splitMenus={true}
|
||||||
style={{minHeight: '100vh'}}
|
style={{minHeight: '100vh'}}
|
||||||
contentStyle={{backgroundColor: 'white', padding: '10px 10px 10px 20px'}}
|
contentStyle={{backgroundColor: 'white', padding: '10px 10px 10px 20px'}}
|
||||||
|
>
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
components: {
|
||||||
|
Card: {
|
||||||
|
bodyPadding: 0,
|
||||||
|
bodyPaddingSM: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Outlet/>
|
<Outlet/>
|
||||||
|
</ConfigProvider>
|
||||||
</ProLayout>
|
</ProLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,6 @@
|
|||||||
import {Tinyflow} from '@tinyflow-ai/react'
|
|
||||||
import '@tinyflow-ai/react/dist/index.css'
|
|
||||||
|
|
||||||
function Test() {
|
function Test() {
|
||||||
return (
|
return (
|
||||||
<div className="flowable">
|
<div>Test</div>
|
||||||
<Tinyflow
|
|
||||||
className="tinyflow-instance"
|
|
||||||
style={{height: '95vh'}}
|
|
||||||
onDataChange={(value) => {
|
|
||||||
console.log(value)
|
|
||||||
console.log(JSON.stringify(value))
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
336
service-web/client/src/pages/ai/flow/FlowEditor.tsx
Normal file
336
service-web/client/src/pages/ai/flow/FlowEditor.tsx
Normal file
@@ -0,0 +1,336 @@
|
|||||||
|
import {PlusCircleFilled, SaveFilled} from '@ant-design/icons'
|
||||||
|
import {
|
||||||
|
Background,
|
||||||
|
BackgroundVariant,
|
||||||
|
type Connection,
|
||||||
|
Controls,
|
||||||
|
getIncomers,
|
||||||
|
getOutgoers,
|
||||||
|
MiniMap,
|
||||||
|
type Node,
|
||||||
|
type NodeProps,
|
||||||
|
ReactFlow,
|
||||||
|
} from '@xyflow/react'
|
||||||
|
import {useMount} from 'ahooks'
|
||||||
|
import type {Schema} from 'amis'
|
||||||
|
import {Button, Drawer, Dropdown, message, Space} from 'antd'
|
||||||
|
import {arrToMap, find, findIdx, isEqual, isNil, randomId} from 'licia'
|
||||||
|
import {type JSX, useState} from 'react'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import '@xyflow/react/dist/style.css'
|
||||||
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
|
import CodeNode from './node/CodeNode.tsx'
|
||||||
|
import EndNode from './node/EndNode.tsx'
|
||||||
|
import KnowledgeNode from './node/KnowledgeNode.tsx'
|
||||||
|
import LlmNode from './node/LlmNode.tsx'
|
||||||
|
import StartNode from './node/StartNode.tsx'
|
||||||
|
import {useDataStore} from './store/DataStore.ts'
|
||||||
|
import {useFlowStore} from './store/FlowStore.ts'
|
||||||
|
|
||||||
|
const FlowableDiv = styled.div`
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.react-flow__node.selectable {
|
||||||
|
&:focus {
|
||||||
|
box-shadow: 0 0 20px 1px #e8e8e8;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__handle.connectionindicator {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: 1px solid #000000;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #e8e8e8;
|
||||||
|
border: 1px solid #c6c6c6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar {
|
||||||
|
position: absolute;
|
||||||
|
right: 20px;
|
||||||
|
top: 20px;
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-card {
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
|
.card-container {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
function FlowEditor() {
|
||||||
|
const [messageApi, contextHolder] = message.useMessage()
|
||||||
|
const [nodeDef] = useState<{
|
||||||
|
key: string,
|
||||||
|
name: string,
|
||||||
|
component: (props: NodeProps) => JSX.Element
|
||||||
|
}[]>([
|
||||||
|
{
|
||||||
|
key: 'start-amis-node',
|
||||||
|
name: '开始',
|
||||||
|
component: StartNode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'end-amis-node',
|
||||||
|
name: '结束',
|
||||||
|
component: EndNode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'llm-amis-node',
|
||||||
|
name: '大模型',
|
||||||
|
component: LlmNode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'knowledge-amis-node',
|
||||||
|
name: '知识库',
|
||||||
|
component: KnowledgeNode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'code-amis-node',
|
||||||
|
name: '代码执行',
|
||||||
|
component: CodeNode,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const {data, setData, getDataById, setDataById} = useDataStore()
|
||||||
|
const {
|
||||||
|
nodes,
|
||||||
|
getNodeById,
|
||||||
|
addNode,
|
||||||
|
removeNode,
|
||||||
|
setNodes,
|
||||||
|
onNodesChange,
|
||||||
|
edges,
|
||||||
|
setEdges,
|
||||||
|
onEdgesChange,
|
||||||
|
onConnect,
|
||||||
|
} = useFlowStore()
|
||||||
|
|
||||||
|
const [currentNodeForm, setCurrentNodeForm] = useState<JSX.Element>()
|
||||||
|
const editNode = (id: string, columnSchema?: Schema[]) => {
|
||||||
|
if (!isNil(columnSchema)) {
|
||||||
|
setCurrentNodeForm(
|
||||||
|
amisRender(
|
||||||
|
{
|
||||||
|
type: 'wrapper',
|
||||||
|
size: 'none',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
debug: commonInfo.debug,
|
||||||
|
type: 'form',
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
wrapWithPanel: false,
|
||||||
|
onEvent: {
|
||||||
|
submitSucc: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, action, event) => {
|
||||||
|
setDataById(id, context.props.data)
|
||||||
|
setOpen(false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
...(columnSchema ?? []),
|
||||||
|
{
|
||||||
|
type: 'wrapper',
|
||||||
|
size: 'none',
|
||||||
|
className: 'space-x-2 text-right',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '取消',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, action, event) => {
|
||||||
|
setOpen(false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'submit',
|
||||||
|
label: '保存',
|
||||||
|
level: 'primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
getDataById(id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
setOpen(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkNode = (type: string) => {
|
||||||
|
if (isEqual(type, 'start-amis-node') && findIdx(nodes, (node: Node) => isEqual(type, node.type)) > -1) {
|
||||||
|
throw new Error('只能存在1个开始节点')
|
||||||
|
}
|
||||||
|
if (isEqual(type, 'end-amis-node') && findIdx(nodes, (node: Node) => isEqual(type, node.type)) > -1) {
|
||||||
|
throw new Error('只能存在1个结束节点')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkConnection = (connection: Connection) => {
|
||||||
|
let sourceNode = getNodeById(connection.source)
|
||||||
|
if (!sourceNode) {
|
||||||
|
throw new Error('连线起始节点未找到')
|
||||||
|
}
|
||||||
|
let targetNode = getNodeById(connection.target)
|
||||||
|
if (!targetNode) {
|
||||||
|
throw new Error('连线目标节点未找到')
|
||||||
|
}
|
||||||
|
// 禁止短路整个流程
|
||||||
|
if (isEqual('start-amis-node', sourceNode.type) && isEqual('end-amis-node', targetNode.type)) {
|
||||||
|
throw new Error('开始节点不能直连结束节点')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 禁止流程出现环,必须是有向无环图
|
||||||
|
const hasCycle = (node: Node, visited = new Set()) => {
|
||||||
|
if (visited.has(node.id)) return false
|
||||||
|
visited.add(node.id)
|
||||||
|
for (const outgoer of getOutgoers(node, nodes, edges)) {
|
||||||
|
if (isEqual(outgoer.id, sourceNode?.id)) return true
|
||||||
|
if (hasCycle(outgoer, visited)) return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isEqual(sourceNode.id, targetNode.id)) {
|
||||||
|
throw new Error('节点不能直连自身')
|
||||||
|
} else if (hasCycle(targetNode)) {
|
||||||
|
throw new Error('禁止流程循环')
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasShortcut = (node: Node, visited = new Set()) => {
|
||||||
|
if (visited.has(node.id)) return false
|
||||||
|
visited.add(node.id)
|
||||||
|
for (const incomer of getIncomers(node, nodes, edges)) {
|
||||||
|
if (isEqual(incomer.id, sourceNode?.id)) return true
|
||||||
|
if (hasShortcut(incomer, visited)) return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(getIncomers(targetNode, nodes, edges))
|
||||||
|
}
|
||||||
|
|
||||||
|
useMount(() => {
|
||||||
|
// language=JSON
|
||||||
|
let initialData = JSON.parse('{\n "nodes": [\n {\n "id": "BMFP3Eov94",\n "type": "start-amis-node",\n "position": {\n "x": 8,\n "y": 272\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "PYK8LjduQ1",\n "type": "end-amis-node",\n "position": {\n "x": 1439.5556937134281,\n "y": 282.2797340760818\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "nCm-ij5I6o",\n "type": "llm-amis-node",\n "position": {\n "x": 902.6781018665707,\n "y": 115.31234529524048\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "9RIg65O0YQ",\n "type": "knowledge-amis-node",\n "position": {\n "x": 338,\n "y": 287\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "2vTyjP0Gu9",\n "type": "code-amis-node",\n "position": {\n "x": 1086.6322978498904,\n "y": 371.3061114283591\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": true,\n "dragging": false\n },\n {\n "id": "s9VfZpvb4P",\n "type": "llm-amis-node",\n "position": {\n "x": 700.0944461714178,\n "y": 369.84258971430364\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 75\n },\n "selected": false,\n "dragging": false\n }\n ],\n "edges": [\n {\n "source": "BMFP3Eov94",\n "target": "9RIg65O0YQ",\n "id": "xy-edge__BMFP3Eov94-9RIg65O0YQ"\n },\n {\n "source": "9RIg65O0YQ",\n "target": "nCm-ij5I6o",\n "id": "xy-edge__9RIg65O0YQ-nCm-ij5I6o"\n },\n {\n "source": "nCm-ij5I6o",\n "target": "PYK8LjduQ1",\n "id": "xy-edge__nCm-ij5I6o-PYK8LjduQ1"\n },\n {\n "source": "s9VfZpvb4P",\n "target": "2vTyjP0Gu9",\n "id": "xy-edge__s9VfZpvb4P-2vTyjP0Gu9"\n },\n {\n "source": "9RIg65O0YQ",\n "target": "s9VfZpvb4P",\n "id": "xy-edge__9RIg65O0YQ-s9VfZpvb4P"\n },\n {\n "source": "2vTyjP0Gu9",\n "target": "PYK8LjduQ1",\n "id": "xy-edge__2vTyjP0Gu9-PYK8LjduQ1"\n }\n ],\n "data": {\n "BMFP3Eov94": {\n "inputs": {\n "name": {\n "type": "text"\n },\n "description": {\n "type": "text",\n "description": "文件描述"\n }\n }\n },\n "nCm-ij5I6o": {\n "model": "qwen3",\n "outputs": {\n "text": {\n "type": "string"\n }\n },\n "systemPrompt": "你是个沙雕"\n },\n "9RIg65O0YQ": {\n "count": 3,\n "score": 0.75,\n "knowledgeId": 3585368238960640,\n "query": "hello world"\n },\n "2vTyjP0Gu9": {\n "type": "python",\n "content": "code=\'hello\'\\nprint(code)"\n },\n "s9VfZpvb4P": {\n "model": "qwen3",\n "outputs": {\n "text": {\n "type": "string"\n }\n },\n "systemPrompt": "你是个聪明人"\n }\n }\n}')
|
||||||
|
let initialNodes = initialData['nodes'] ?? []
|
||||||
|
let initialEdges = initialData['edges'] ?? []
|
||||||
|
|
||||||
|
let initialNodeData = initialData['data'] ?? {}
|
||||||
|
setData(initialNodeData)
|
||||||
|
|
||||||
|
for (let node of initialNodes) {
|
||||||
|
node.data = {
|
||||||
|
getDataById,
|
||||||
|
setDataById,
|
||||||
|
removeNode,
|
||||||
|
editNode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setNodes(initialNodes)
|
||||||
|
setEdges(initialEdges)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlowableDiv>
|
||||||
|
{contextHolder}
|
||||||
|
<Space className="toolbar">
|
||||||
|
<Dropdown
|
||||||
|
menu={{
|
||||||
|
items: nodeDef.map(def => ({key: def.key, label: def.name})),
|
||||||
|
onClick: ({key}) => {
|
||||||
|
try {
|
||||||
|
checkNode(key)
|
||||||
|
addNode({
|
||||||
|
id: randomId(10),
|
||||||
|
type: key,
|
||||||
|
position: {x: 100, y: 100},
|
||||||
|
data: {
|
||||||
|
getDataById,
|
||||||
|
setDataById,
|
||||||
|
removeNode,
|
||||||
|
editNode,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
messageApi.error(e.message)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button type="default">
|
||||||
|
<PlusCircleFilled/>
|
||||||
|
新增节点
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
|
<Button type="primary" onClick={() => {
|
||||||
|
let saveData = {nodes, edges, data}
|
||||||
|
console.log(JSON.stringify(saveData, null, 2))
|
||||||
|
}}>
|
||||||
|
<SaveFilled/>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
<Drawer
|
||||||
|
title="节点编辑"
|
||||||
|
open={open}
|
||||||
|
closeIcon={false}
|
||||||
|
maskClosable={false}
|
||||||
|
destroyOnHidden
|
||||||
|
size="large"
|
||||||
|
>
|
||||||
|
{currentNodeForm}
|
||||||
|
</Drawer>
|
||||||
|
<ReactFlow
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onEdgesChange={onEdgesChange}
|
||||||
|
onConnect={(connection) => {
|
||||||
|
try {
|
||||||
|
checkConnection(connection)
|
||||||
|
onConnect(connection)
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
messageApi.error(e.message)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
// @ts-ignore
|
||||||
|
nodeTypes={arrToMap(
|
||||||
|
nodeDef.map(def => def.key),
|
||||||
|
key => find(nodeDef, def => isEqual(key, def.key))!.component)
|
||||||
|
}
|
||||||
|
fitView
|
||||||
|
>
|
||||||
|
<Controls/>
|
||||||
|
<MiniMap/>
|
||||||
|
<Background variant={BackgroundVariant.Cross} gap={20} size={3}/>
|
||||||
|
</ReactFlow>
|
||||||
|
</FlowableDiv>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowEditor
|
||||||
143
service-web/client/src/pages/ai/flow/node/AmisNode.tsx
Normal file
143
service-web/client/src/pages/ai/flow/node/AmisNode.tsx
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
import {DeleteFilled, EditFilled} from '@ant-design/icons'
|
||||||
|
import {Handle, type NodeProps, Position} from '@xyflow/react'
|
||||||
|
import type {Schema} from 'amis'
|
||||||
|
import {Card, Dropdown} from 'antd'
|
||||||
|
import {isEmpty, isEqual} from 'licia'
|
||||||
|
import type {JSX} from 'react'
|
||||||
|
import {horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
|
export type AmisNodeType = 'normal' | 'start' | 'end'
|
||||||
|
|
||||||
|
export function outputsFormColumns(editable: boolean = false, required: boolean = false, preload?: any): Schema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
disabled: !editable,
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'outputs',
|
||||||
|
label: '输出变量',
|
||||||
|
value: preload,
|
||||||
|
addButtonText: '新增输出',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
label: '参数名称',
|
||||||
|
},
|
||||||
|
required: required,
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '参数',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '文本',
|
||||||
|
value: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数字',
|
||||||
|
value: 'number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文本数组',
|
||||||
|
value: 'array-string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '对象数组',
|
||||||
|
value: 'array-object',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const AmisNode = (
|
||||||
|
props: NodeProps,
|
||||||
|
type: AmisNodeType,
|
||||||
|
defaultNodeName: String,
|
||||||
|
defaultNodeDescription?: String,
|
||||||
|
extraNodeDescription?: (nodeData: any) => JSX.Element,
|
||||||
|
columnSchema?: Schema[],
|
||||||
|
) => {
|
||||||
|
const {id, data} = props
|
||||||
|
const {getDataById, removeNode, editNode} = data
|
||||||
|
// @ts-ignore
|
||||||
|
const nodeData = getDataById(id)
|
||||||
|
const nodeName = isEmpty(nodeData?.node?.name) ? defaultNodeName : nodeData.node.name
|
||||||
|
const nodeDescription = isEmpty(nodeData?.node?.description) ? defaultNodeDescription : nodeData.node?.description
|
||||||
|
return (
|
||||||
|
<div className="w-64">
|
||||||
|
<Dropdown
|
||||||
|
className="card-container"
|
||||||
|
trigger={['contextMenu']}
|
||||||
|
menu={{
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
key: 'edit',
|
||||||
|
label: '编辑',
|
||||||
|
icon: <EditFilled className="text-gray-600 hover:text-blue-500"/>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'remove',
|
||||||
|
label: '删除',
|
||||||
|
icon: <DeleteFilled className="text-red-500 hover:text-red-500"/>,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onClick: menu => {
|
||||||
|
switch (menu.key) {
|
||||||
|
case 'edit':
|
||||||
|
// @ts-ignore
|
||||||
|
editNode(
|
||||||
|
id,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'node.name',
|
||||||
|
label: '节点名称',
|
||||||
|
placeholder: nodeName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'node.description',
|
||||||
|
label: '节点描述',
|
||||||
|
placeholder: nodeDescription,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...(columnSchema ?? []),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
break
|
||||||
|
case 'remove':
|
||||||
|
// @ts-ignore
|
||||||
|
removeNode(id)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Card
|
||||||
|
className="node-card"
|
||||||
|
title={nodeName}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<div className="card-description p-2 text-secondary text-sm">
|
||||||
|
{nodeDescription}
|
||||||
|
{extraNodeDescription?.(nodeData)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Dropdown>
|
||||||
|
{isEqual(type, 'start') || isEqual(type, 'normal')
|
||||||
|
? <Handle type="source" position={Position.Right}/> : undefined}
|
||||||
|
{isEqual(type, 'end') || isEqual(type, 'normal')
|
||||||
|
? <Handle type="target" position={Position.Left}/> : undefined}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AmisNode
|
||||||
73
service-web/client/src/pages/ai/flow/node/CodeNode.tsx
Normal file
73
service-web/client/src/pages/ai/flow/node/CodeNode.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
import AmisNode, {outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const CodeNode = (props: NodeProps) => AmisNode(
|
||||||
|
props,
|
||||||
|
'normal',
|
||||||
|
'代码执行',
|
||||||
|
'执行自定义的处理代码',
|
||||||
|
undefined,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'inputs',
|
||||||
|
label: '输入变量',
|
||||||
|
addButtonText: '新增输入',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
label: '参数名称',
|
||||||
|
},
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '变量',
|
||||||
|
required: true,
|
||||||
|
options: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '代码类型',
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
value: 'javascript',
|
||||||
|
label: 'JavaScript',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'python',
|
||||||
|
label: 'Python',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'lua',
|
||||||
|
label: 'Lua',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'editor',
|
||||||
|
required: true,
|
||||||
|
label: '代码内容',
|
||||||
|
name: 'content',
|
||||||
|
language: '${type}',
|
||||||
|
options: {
|
||||||
|
wordWrap: 'bounded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(true, true, {result: {type: 'string'}}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
export default CodeNode
|
||||||
13
service-web/client/src/pages/ai/flow/node/EndNode.tsx
Normal file
13
service-web/client/src/pages/ai/flow/node/EndNode.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import AmisNode, {outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const EndNode = (props: NodeProps) => AmisNode(
|
||||||
|
props,
|
||||||
|
'end',
|
||||||
|
'结束节点',
|
||||||
|
'定义输出变量',
|
||||||
|
undefined,
|
||||||
|
outputsFormColumns(true),
|
||||||
|
)
|
||||||
|
|
||||||
|
export default EndNode
|
||||||
58
service-web/client/src/pages/ai/flow/node/KnowledgeNode.tsx
Normal file
58
service-web/client/src/pages/ai/flow/node/KnowledgeNode.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {commonInfo} from '../../../../util/amis.tsx'
|
||||||
|
import AmisNode from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const KnowledgeNode = (props: NodeProps) => AmisNode(
|
||||||
|
props,
|
||||||
|
'normal',
|
||||||
|
'知识库',
|
||||||
|
'查询知识库获取外部知识',
|
||||||
|
undefined,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'knowledgeId',
|
||||||
|
label: '知识库',
|
||||||
|
required: true,
|
||||||
|
options: [],
|
||||||
|
source: {
|
||||||
|
method: 'get',
|
||||||
|
url: `${commonInfo.baseAiUrl}/knowledge/list`,
|
||||||
|
// @ts-ignore
|
||||||
|
adaptor: (payload, response, api, context) => {
|
||||||
|
return {
|
||||||
|
...payload,
|
||||||
|
data: {
|
||||||
|
items: payload.data.items.map((item: any) => ({value: item['id'], label: item['name']})),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'query',
|
||||||
|
label: '查询文本',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input-range',
|
||||||
|
name: 'count',
|
||||||
|
label: '返回数量',
|
||||||
|
required: true,
|
||||||
|
value: 3,
|
||||||
|
max: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input-range',
|
||||||
|
name: 'score',
|
||||||
|
label: '匹配阀值',
|
||||||
|
required: true,
|
||||||
|
value: 0.6,
|
||||||
|
max: 1,
|
||||||
|
step: 0.05,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
export default KnowledgeNode
|
||||||
41
service-web/client/src/pages/ai/flow/node/LlmNode.tsx
Normal file
41
service-web/client/src/pages/ai/flow/node/LlmNode.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import AmisNode, {outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const LlmNode = (props: NodeProps) => AmisNode(
|
||||||
|
props,
|
||||||
|
'normal',
|
||||||
|
'大模型',
|
||||||
|
'使用大模型对话',
|
||||||
|
undefined,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'model',
|
||||||
|
label: '大模型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: 'Qwen3',
|
||||||
|
value: 'qwen3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Deepseek',
|
||||||
|
value: 'deepseek',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'systemPrompt',
|
||||||
|
label: '系统提示词',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, true, {text: {type: 'string'}}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
export default LlmNode
|
||||||
56
service-web/client/src/pages/ai/flow/node/StartNode.tsx
Normal file
56
service-web/client/src/pages/ai/flow/node/StartNode.tsx
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
import AmisNode from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const StartNode = (props: NodeProps) => AmisNode(
|
||||||
|
props,
|
||||||
|
'start',
|
||||||
|
'开始节点',
|
||||||
|
'定义输入变量',
|
||||||
|
undefined,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'inputs',
|
||||||
|
label: '输入变量',
|
||||||
|
addButtonText: '新增入参',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
label: '参数名称',
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
},
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'description',
|
||||||
|
label: '参数描述',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '参数类型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '文本',
|
||||||
|
value: 'text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '数字',
|
||||||
|
value: 'number',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '文件',
|
||||||
|
value: 'files',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
export default StartNode
|
||||||
23
service-web/client/src/pages/ai/flow/store/DataStore.ts
Normal file
23
service-web/client/src/pages/ai/flow/store/DataStore.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import {create} from 'zustand/react'
|
||||||
|
|
||||||
|
export const useDataStore = create<{
|
||||||
|
data: Record<string, any>,
|
||||||
|
getData: () => Record<string, any>,
|
||||||
|
setData: (data: Record<string, any>) => void,
|
||||||
|
getDataById: (id: string) => any,
|
||||||
|
setDataById: (id: string, data: any) => void,
|
||||||
|
}>((set, get) => ({
|
||||||
|
data: {},
|
||||||
|
getData: () => get().data,
|
||||||
|
setData: (data) => set({
|
||||||
|
data: data
|
||||||
|
}),
|
||||||
|
getDataById: id => get().data[id],
|
||||||
|
setDataById: (id, data) => {
|
||||||
|
let updateData = get().data
|
||||||
|
updateData[id] = data
|
||||||
|
set({
|
||||||
|
data: updateData,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}))
|
||||||
56
service-web/client/src/pages/ai/flow/store/FlowStore.ts
Normal file
56
service-web/client/src/pages/ai/flow/store/FlowStore.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import {
|
||||||
|
addEdge,
|
||||||
|
applyEdgeChanges,
|
||||||
|
applyNodeChanges,
|
||||||
|
type Edge,
|
||||||
|
type Node,
|
||||||
|
type OnConnect,
|
||||||
|
type OnEdgesChange,
|
||||||
|
type OnNodesChange,
|
||||||
|
} from '@xyflow/react'
|
||||||
|
import {filter, find, isEqual} from 'licia'
|
||||||
|
import {create} from 'zustand/react'
|
||||||
|
|
||||||
|
export const useFlowStore = create<{
|
||||||
|
nodes: Node[],
|
||||||
|
onNodesChange: OnNodesChange,
|
||||||
|
getNodeById: (id: string) => Node | undefined,
|
||||||
|
addNode: (node: Node) => void,
|
||||||
|
removeNode: (id: string) => void,
|
||||||
|
setNodes: (nodes: Node[]) => void,
|
||||||
|
|
||||||
|
edges: Edge[],
|
||||||
|
onEdgesChange: OnEdgesChange,
|
||||||
|
setEdges: (edges: Edge[]) => void,
|
||||||
|
|
||||||
|
onConnect: OnConnect,
|
||||||
|
}>((set, get) => ({
|
||||||
|
nodes: [],
|
||||||
|
onNodesChange: changes => {
|
||||||
|
set({
|
||||||
|
nodes: applyNodeChanges(changes, get().nodes),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getNodeById: (id: string) => find(get().nodes, node => isEqual(node.id, id)),
|
||||||
|
addNode: node => set({nodes: get().nodes.concat(node)}),
|
||||||
|
removeNode: id => {
|
||||||
|
set({
|
||||||
|
nodes: filter(get().nodes, node => !isEqual(node.id, id)),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setNodes: nodes => set({nodes}),
|
||||||
|
|
||||||
|
edges: [],
|
||||||
|
onEdgesChange: changes => {
|
||||||
|
set({
|
||||||
|
edges: applyEdgeChanges(changes, get().edges),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setEdges: edges => set({edges}),
|
||||||
|
|
||||||
|
onConnect: connection => {
|
||||||
|
set({
|
||||||
|
edges: addEdge(connection, get().edges),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}))
|
||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
ClusterOutlined,
|
ClusterOutlined,
|
||||||
CompressOutlined,
|
CompressOutlined,
|
||||||
DatabaseOutlined,
|
DatabaseOutlined,
|
||||||
|
GatewayOutlined,
|
||||||
InfoCircleOutlined,
|
InfoCircleOutlined,
|
||||||
OpenAIOutlined,
|
OpenAIOutlined,
|
||||||
QuestionOutlined,
|
QuestionOutlined,
|
||||||
@@ -32,6 +33,7 @@ import Yarn from './pages/overview/Yarn.tsx'
|
|||||||
import YarnCluster from './pages/overview/YarnCluster.tsx'
|
import YarnCluster from './pages/overview/YarnCluster.tsx'
|
||||||
import Test from './pages/Test.tsx'
|
import Test from './pages/Test.tsx'
|
||||||
import {commonInfo} from './util/amis.tsx'
|
import {commonInfo} from './util/amis.tsx'
|
||||||
|
import FlowEditor from './pages/ai/flow/FlowEditor.tsx'
|
||||||
|
|
||||||
export const routes: RouteObject[] = [
|
export const routes: RouteObject[] = [
|
||||||
{
|
{
|
||||||
@@ -109,6 +111,10 @@ export const routes: RouteObject[] = [
|
|||||||
path: 'knowledge/detail/:knowledge_id/segment/:group_id',
|
path: 'knowledge/detail/:knowledge_id/segment/:group_id',
|
||||||
Component: DataSegment,
|
Component: DataSegment,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'flowable',
|
||||||
|
Component: FlowEditor,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -211,6 +217,11 @@ export const menus = {
|
|||||||
name: '知识库',
|
name: '知识库',
|
||||||
icon: <DatabaseOutlined/>,
|
icon: <DatabaseOutlined/>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/ai/flowable',
|
||||||
|
name: '流程编排',
|
||||||
|
icon: <GatewayOutlined/>,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -274,6 +274,15 @@ export function serviceLogByAppNameAndHost(name: string, host: string) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function horizontalFormOptions() {
|
||||||
|
return {
|
||||||
|
mode: 'horizontal',
|
||||||
|
horizontal: {
|
||||||
|
leftFixed: 'sm'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function crudCommonOptions() {
|
export function crudCommonOptions() {
|
||||||
return {
|
return {
|
||||||
affixHeader: false,
|
affixHeader: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user