Compare commits
104 Commits
jpa
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2a8c39145 | ||
|
|
82ad3e7854 | ||
| 1e3e14c590 | |||
| 267eecbf45 | |||
| a5282762ed | |||
|
|
77a09472aa | ||
|
|
4cfa110f2f | ||
|
|
ad9dade6a1 | ||
|
|
3a61da054e | ||
| fbc6144d82 | |||
| 72a9d58f4c | |||
|
|
a3c2250285 | ||
| 91e6f49342 | |||
|
|
35c5150a1f | ||
|
|
a7b245a670 | ||
|
|
df8270676a | ||
|
|
b0e4f5853e | ||
| 0efb041c71 | |||
| fa06207af8 | |||
| c7e0b56850 | |||
|
|
04bc9a2c16 | ||
|
|
c77395fec4 | ||
| 21f02660e9 | |||
| f6e9c9bc70 | |||
|
|
e798332828 | ||
|
|
b0d41e0d88 | ||
|
|
02b2d44ccc | ||
|
|
47de3cc376 | ||
|
|
5b9920449d | ||
|
|
60f6b79167 | ||
|
|
528e66c497 | ||
|
|
707f538213 | ||
|
|
eae0d8dacd | ||
|
|
bf37c163fb | ||
|
|
ac2b6b1611 | ||
|
|
863638deaa | ||
|
|
fad190567b | ||
|
|
333da7ef88 | ||
|
|
d0ca36e9d7 | ||
|
|
f70b3b2a32 | ||
|
|
f707a0d2b5 | ||
|
|
5e763637da | ||
|
|
898e20d5d7 | ||
| 605cfb7182 | |||
|
|
3afdff0a05 | ||
|
|
f523fc7638 | ||
| 03d0d9d85b | |||
| 187c565da4 | |||
| f3dfff5075 | |||
| 69420094ec | |||
|
|
051b3dbad2 | ||
|
|
64ef5514b4 | ||
|
|
4f1dc84405 | ||
| d979b3941d | |||
| abdbb5ed03 | |||
|
|
8ebaf5de8e | ||
|
|
5f7eeb3596 | ||
|
|
064443f740 | ||
|
|
6809750cfa | ||
|
|
49cb62b287 | ||
|
|
5cbda28594 | ||
|
|
11c5481287 | ||
|
|
67e0cada00 | ||
|
|
cdf51cc85f | ||
|
|
9277d1690c | ||
|
|
24ac681cb3 | ||
|
|
c46da52942 | ||
|
|
7209b52e3d | ||
|
|
959d6fb5c7 | ||
|
|
c5c62ab713 | ||
| e59e89a5ad | |||
| b7626180c1 | |||
|
|
68e54d5110 | ||
|
|
5f133fbfc3 | ||
|
|
d28fbbbba8 | ||
|
|
67f41c08a0 | ||
| 111ca49815 | |||
| 779fd0eb18 | |||
| 8884495a89 | |||
| d08a6babbe | |||
| 9a3375bd03 | |||
|
|
2c808a5bc9 | ||
|
|
6e667c45e1 | ||
|
|
635c6537ed | ||
|
|
d6b70b1750 | ||
|
|
c92a374591 | ||
|
|
a2aba82b6e | ||
| 873c1a1d20 | |||
|
|
f6bd7e52e1 | ||
|
|
6f7f7cea67 | ||
|
|
33df256863 | ||
|
|
3a51d1e33f | ||
|
|
d3c7457889 | ||
| 2d2eaafcd4 | |||
|
|
566dfef208 | ||
| 1cba0f4422 | |||
| ab56385c8a | |||
| b58c34443f | |||
| 53638a8a6d | |||
| dc55605c99 | |||
| 7345774258 | |||
| fcf5f8ad18 | |||
|
|
b53ee57dc3 | ||
|
|
b916acb1c3 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -110,3 +110,4 @@ Network Trash Folder
|
|||||||
Temporary Items
|
Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
**/temp/
|
**/temp/
|
||||||
|
.build
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
|
import {$, fetch, fs, glob, os, path, spinner, syncProcessCwd, usePowerShell} from 'zx'
|
||||||
import {isEqual, trim, fileSize} from "licia";
|
import {fileSize, isEqual, trim} from "licia";
|
||||||
import md5file from 'md5-file'
|
import md5file from 'md5-file'
|
||||||
|
|
||||||
syncProcessCwd(true)
|
syncProcessCwd(true)
|
||||||
@@ -41,20 +41,70 @@ const millisecondToString = (timestamp) => {
|
|||||||
return parts.join('')
|
return parts.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dotBuildPath = () => `.build`
|
||||||
|
const modifiedDataPath = () => `${dotBuildPath()}/modified_time.json`
|
||||||
|
|
||||||
|
const readModifiedTimeData = async () => {
|
||||||
|
if (!fs.existsSync(dotBuildPath())) {
|
||||||
|
fs.mkdirSync(dotBuildPath(), {recursive: true})
|
||||||
|
}
|
||||||
|
if (!(await fs.exists(modifiedDataPath()))) {
|
||||||
|
fs.writeFileSync(modifiedDataPath(), '{}')
|
||||||
|
}
|
||||||
|
return JSON.parse(await fs.readFile(modifiedDataPath(), 'utf-8'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateModifiedTimeData = (data) => {
|
||||||
|
fs.writeFileSync(modifiedDataPath(), JSON.stringify(data, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
const isModified = async (target) => {
|
||||||
|
if (!target || !(await fs.exists(target))) {
|
||||||
|
throw new Error("Target 不存在")
|
||||||
|
}
|
||||||
|
let stat = fs.statSync(target)
|
||||||
|
let currentModifiedTime = stat.mtimeMs
|
||||||
|
|
||||||
|
let lastModifiedTime = (await readModifiedTimeData())[target]
|
||||||
|
return !(lastModifiedTime && isEqual(currentModifiedTime, lastModifiedTime));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateModifiedTime = async (target) => {
|
||||||
|
if (!target || !(await fs.exists(target))) {
|
||||||
|
throw new Error("Target 不存在")
|
||||||
|
}
|
||||||
|
let stat = fs.statSync(target)
|
||||||
|
let currentModifiedTime = stat.mtimeMs
|
||||||
|
let modifiedTimeData = await readModifiedTimeData()
|
||||||
|
modifiedTimeData[target] = currentModifiedTime
|
||||||
|
updateModifiedTimeData(modifiedTimeData)
|
||||||
|
}
|
||||||
|
|
||||||
export const run_deploy = async (project) => {
|
export const run_deploy = async (project) => {
|
||||||
|
if (!(await isModified(project))) {
|
||||||
|
console.log(`✅ Skip deploy ${project}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
let output = await spinner(
|
let output = await spinner(
|
||||||
`Deploying project ${project}`,
|
`Deploying project ${project}`,
|
||||||
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
|
() => $`mvn -pl ${project} clean deploy -D skipTests -s ${maven_setting}`
|
||||||
)
|
)
|
||||||
console.log(`✅ Finished deploy ${project} (${millisecondToString(output['duration'])})`)
|
console.log(`✅ Finished deploy ${project} (${millisecondToString(output['duration'])})`)
|
||||||
|
await updateModifiedTime(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const run_deploy_root = async () => {
|
export const run_deploy_root = async () => {
|
||||||
|
if (!(await isModified('pom.xml'))) {
|
||||||
|
console.log(`✅ Skip deploy root`)
|
||||||
|
return
|
||||||
|
}
|
||||||
let output = await spinner(
|
let output = await spinner(
|
||||||
`Deploying root`,
|
`Deploying root`,
|
||||||
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
|
() => $`mvn clean deploy -N -D skipTests -s ${maven_setting}`
|
||||||
)
|
)
|
||||||
console.log(`✅ Finished deploy root (${millisecondToString(output['duration'])})`)
|
console.log(`✅ Finished deploy root (${millisecondToString(output['duration'])})`)
|
||||||
|
await updateModifiedTime('pom.xml')
|
||||||
}
|
}
|
||||||
|
|
||||||
export const run_deploy_batch = async (projects) => {
|
export const run_deploy_batch = async (projects) => {
|
||||||
|
|||||||
3
bin/test.js
Normal file
3
bin/test.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import {isModified} from './library.js'
|
||||||
|
|
||||||
|
console.log(await isModified('/Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/pom.xml'))
|
||||||
86
service-ai/database/20250702.sql
Normal file
86
service-ai/database/20250702.sql
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
create table hudi_collect_build_b12.service_ai_feedback
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
analysis longtext comment 'AI的分析结果',
|
||||||
|
conclusion longtext comment 'AI的解决方案',
|
||||||
|
source longtext not null comment '原始报障说明',
|
||||||
|
status enum ('ANALYSIS_PROCESSING','ANALYSIS_SUCCESS','FINISHED') not null comment '报障处理状态',
|
||||||
|
primary key (id)
|
||||||
|
) comment ='报障信息记录' charset = utf8mb4;
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_feedback_pictures
|
||||||
|
(
|
||||||
|
feedback_id bigint not null,
|
||||||
|
pictures_id bigint not null,
|
||||||
|
primary key (feedback_id, pictures_id)
|
||||||
|
) comment ='报障相关截图' charset = utf8mb4;
|
||||||
|
|
||||||
|
alter table hudi_collect_build_b12.service_ai_feedback_pictures
|
||||||
|
add constraint UK3npjcyjyqfbdlf2v5tj64j2g3 unique (pictures_id);
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_file
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
filename varchar(255) comment '文件名称',
|
||||||
|
md5 varchar(255) comment '文件的md5编码,用于校验文件的完整性',
|
||||||
|
path varchar(255) comment '文件在主机上存储的实际路径',
|
||||||
|
size bigint comment '文件大小,单位是byte',
|
||||||
|
type varchar(255) comment '文件类型,通常记录的是文件的后缀名',
|
||||||
|
primary key (id)
|
||||||
|
) comment ='记录上传的文件存储信息' charset = utf8mb4;
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_flow_task
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
comment text comment '任务注释,用于额外说明',
|
||||||
|
error longtext comment '任务运行产生的报错',
|
||||||
|
input longtext comment '任务输入',
|
||||||
|
result longtext comment '任务运行结果',
|
||||||
|
status enum ('ERROR','FINISHED','RUNNING') not null comment '任务运行状态',
|
||||||
|
template_description varchar(255) comment '任务对应的模板功能、内容说明',
|
||||||
|
template_flow_graph longtext not null comment '任务对应的模板前端流程图数据',
|
||||||
|
template_input_schema longtext comment '任务对应的模板入参Schema',
|
||||||
|
template_name varchar(255) not null comment '任务对应的模板名称',
|
||||||
|
primary key (id)
|
||||||
|
) comment ='流程任务记录' charset = utf8mb4;
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_flow_task_template
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
description varchar(255) comment '模板功能、内容说明',
|
||||||
|
flow_graph longtext not null comment '前端流程图数据',
|
||||||
|
input_schema longtext comment '模板入参Schema',
|
||||||
|
name varchar(255) not null comment '模板名称',
|
||||||
|
primary key (id)
|
||||||
|
) comment ='流程任务模板' charset = utf8mb4;
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_group
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
name varchar(255) not null comment '分组名称',
|
||||||
|
status enum ('FINISHED','RUNNING') not null comment '分组处理状态',
|
||||||
|
knowledge_id bigint not null,
|
||||||
|
primary key (id)
|
||||||
|
) comment ='知识库下包含的分组' charset = utf8mb4;
|
||||||
|
|
||||||
|
create table hudi_collect_build_b12.service_ai_knowledge
|
||||||
|
(
|
||||||
|
id bigint not null comment '记录唯一标记',
|
||||||
|
created_time datetime(6) comment '记录创建时间',
|
||||||
|
modified_time datetime(6) comment '记录更新时间',
|
||||||
|
description longtext not null comment '知识库说明',
|
||||||
|
name varchar(255) not null comment '知识库名称',
|
||||||
|
strategy enum ('Cosine','Euclid') not null comment '知识库策略',
|
||||||
|
vector_source_id bigint not null comment '知识库对应的向量库名',
|
||||||
|
primary key (id)
|
||||||
|
) comment ='知识库' charset = utf8mb4;
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
CREATE TABLE `service_ai_feedback`
|
|
||||||
(
|
|
||||||
`id` bigint NOT NULL,
|
|
||||||
`created_time` datetime(6) DEFAULT NULL,
|
|
||||||
`modified_time` datetime(6) DEFAULT NULL,
|
|
||||||
`analysis` longtext,
|
|
||||||
`conclusion` longtext,
|
|
||||||
`source` longtext NOT NULL,
|
|
||||||
`status` tinyint NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARSET = utf8mb4;
|
|
||||||
|
|
||||||
CREATE TABLE `service_ai_feedback_pictures`
|
|
||||||
(
|
|
||||||
`feedback_id` bigint NOT NULL,
|
|
||||||
`pictures_id` bigint NOT NULL,
|
|
||||||
PRIMARY KEY (`feedback_id`, `pictures_id`)
|
|
||||||
) DEFAULT CHARSET = utf8mb4;
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
CREATE TABLE `service_ai_file`
|
|
||||||
(
|
|
||||||
`id` bigint NOT NULL,
|
|
||||||
`created_time` datetime(6) DEFAULT NULL,
|
|
||||||
`modified_time` datetime(6) DEFAULT NULL,
|
|
||||||
`filename` varchar(255) DEFAULT NULL,
|
|
||||||
`md5` varchar(255) DEFAULT NULL,
|
|
||||||
`path` varchar(255) DEFAULT NULL,
|
|
||||||
`size` bigint DEFAULT NULL,
|
|
||||||
`type` varchar(255) DEFAULT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARSET = utf8mb4;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
CREATE TABLE `service_ai_group`
|
|
||||||
(
|
|
||||||
`id` bigint NOT NULL,
|
|
||||||
`created_time` datetime(6) DEFAULT NULL,
|
|
||||||
`modified_time` datetime(6) DEFAULT NULL,
|
|
||||||
`name` varchar(255) NOT NULL,
|
|
||||||
`status` tinyint NOT NULL,
|
|
||||||
`knowledge_id` bigint NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARSET=utf8mb4;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
CREATE TABLE `service_ai_knowledge`
|
|
||||||
(
|
|
||||||
`id` bigint NOT NULL,
|
|
||||||
`created_time` datetime(6) DEFAULT NULL,
|
|
||||||
`modified_time` datetime(6) DEFAULT NULL,
|
|
||||||
`description` longtext NOT NULL,
|
|
||||||
`name` varchar(255) NOT NULL,
|
|
||||||
`strategy` tinyint NOT NULL,
|
|
||||||
`vector_source_id` bigint NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) DEFAULT CHARSET = utf8mb4;
|
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
<curator.version>5.1.0</curator.version>
|
<curator.version>5.1.0</curator.version>
|
||||||
<hutool.version>5.8.27</hutool.version>
|
<hutool.version>5.8.27</hutool.version>
|
||||||
<mapstruct.version>1.6.3</mapstruct.version>
|
<mapstruct.version>1.6.3</mapstruct.version>
|
||||||
|
<liteflow.version>2.13.2</liteflow.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -153,7 +154,27 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.yomahub</groupId>
|
<groupId>com.yomahub</groupId>
|
||||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||||
<version>2.13.2</version>
|
<version>${liteflow.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-el-builder</artifactId>
|
||||||
|
<version>${liteflow.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-script-graaljs</artifactId>
|
||||||
|
<version>${liteflow.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-script-python</artifactId>
|
||||||
|
<version>${liteflow.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-script-lua</artifactId>
|
||||||
|
<version>${liteflow.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.lanyuanxiaoyao.service.configuration;
|
package com.lanyuanxiaoyao.service.configuration;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
@@ -13,6 +11,9 @@ import org.springframework.security.core.userdetails.User;
|
|||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
@@ -21,17 +22,30 @@ import org.springframework.security.web.SecurityFilterChain;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
|
configuration.setAllowCredentials(true);
|
||||||
|
configuration.addAllowedOriginPattern("*");
|
||||||
|
configuration.addAllowedHeader("*");
|
||||||
|
configuration.addAllowedMethod("*");
|
||||||
|
configuration.setMaxAge(7200L);
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
return http.authorizeHttpRequests(
|
return http.authorizeHttpRequests(
|
||||||
registry -> registry
|
registry -> registry
|
||||||
.requestMatchers(HttpMethod.OPTIONS, "/**")
|
.requestMatchers(HttpMethod.OPTIONS, "/**")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
.authenticated()
|
.authenticated()
|
||||||
)
|
)
|
||||||
.httpBasic(Customizer.withDefaults())
|
.httpBasic(Customizer.withDefaults())
|
||||||
.cors(AbstractHttpConfigurer::disable)
|
.cors(Customizer.withDefaults())
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.formLogin(AbstractHttpConfigurer::disable)
|
.formLogin(AbstractHttpConfigurer::disable)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -50,6 +50,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.freemarker</groupId>
|
||||||
|
<artifactId>freemarker</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.blinkfox</groupId>
|
<groupId>com.blinkfox</groupId>
|
||||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||||
@@ -62,6 +66,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>
|
||||||
@@ -78,6 +86,21 @@
|
|||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon-ai-dialect-openai</artifactId>
|
<artifactId>solon-ai-dialect-openai</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-script-graaljs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yomahub</groupId>
|
||||||
|
<artifactId>liteflow-script-python</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.orm</groupId>
|
||||||
|
<artifactId>hibernate-ant</artifactId>
|
||||||
|
<version>6.6.8.Final</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -2,15 +2,12 @@ package com.lanyuanxiaoyao.service.ai.web;
|
|||||||
|
|
||||||
import com.blinkfox.fenix.EnableFenix;
|
import com.blinkfox.fenix.EnableFenix;
|
||||||
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
|
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextAware;
|
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
import org.springframework.retry.annotation.EnableRetry;
|
import org.springframework.retry.annotation.EnableRetry;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
@@ -27,27 +24,15 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableFenix
|
@EnableFenix
|
||||||
@EnableJpaAuditing
|
@EnableJpaAuditing
|
||||||
public class WebApplication implements ApplicationRunner, ApplicationContextAware {
|
public class WebApplication implements ApplicationRunner {
|
||||||
private static ApplicationContext context;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
System.setProperty("polyglot.engine.WarnInterpreterOnly", "false");
|
||||||
|
|
||||||
SpringApplication.run(WebApplication.class, args);
|
SpringApplication.run(WebApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getBean(Class<T> clazz) {
|
|
||||||
return context.getBean(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T getBean(String name, Class<T> clazz) {
|
|
||||||
return context.getBean(name, clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
|
||||||
WebApplication.context = context;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import jakarta.persistence.MappedSuperclass;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class IdOnlyEntity {
|
public class IdOnlyEntity {
|
||||||
|
@Comment("记录唯一标记")
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(generator = "snowflake")
|
@GeneratedValue(generator = "snowflake")
|
||||||
@GenericGenerator(name = "snowflake", strategy = "com.lanyuanxiaoyao.service.ai.web.configuration.SnowflakeIdGenerator")
|
@GenericGenerator(name = "snowflake", strategy = "com.lanyuanxiaoyao.service.ai.web.configuration.SnowflakeIdGenerator")
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.time.LocalDateTime;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
@@ -22,8 +23,10 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class SimpleEntity extends IdOnlyEntity {
|
public class SimpleEntity extends IdOnlyEntity {
|
||||||
|
@Comment("记录创建时间")
|
||||||
@CreatedDate
|
@CreatedDate
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
|
@Comment("记录更新时间")
|
||||||
@LastModifiedDate
|
@LastModifiedDate
|
||||||
private LocalDateTime modifiedTime;
|
private LocalDateTime modifiedTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.configuration;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringBeanGetter implements ApplicationContextAware {
|
||||||
|
private static ApplicationContext context;
|
||||||
|
|
||||||
|
public static <T> T getBean(Class<T> clazz) {
|
||||||
|
return context.getBean(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T getBean(String name, Class<T> clazz) {
|
||||||
|
return context.getBean(name, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext context) throws BeansException {
|
||||||
|
SpringBeanGetter.context = context;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,10 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Sets;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -56,6 +59,26 @@ public class DataFileController {
|
|||||||
this.sliceFolderPath = StrUtil.format("{}/slice", uploadFolderPath);
|
this.sliceFolderPath = StrUtil.format("{}/slice", uploadFolderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/detail")
|
||||||
|
public AmisResponse<?> detail(@RequestBody DetailRequest request) {
|
||||||
|
var mapper = Mappers.getMapper(DetailResponse.Mapper.class);
|
||||||
|
return AmisResponse.responseCrudData(dataFileService.downloadFile(request.ids).collect(mapper::from));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detail")
|
||||||
|
public AmisResponse<?> detail(@RequestParam("ids") String ids) {
|
||||||
|
if (StrUtil.isBlank(ids)) {
|
||||||
|
return AmisResponse.responseCrudData(Sets.immutable.empty());
|
||||||
|
}
|
||||||
|
var mapper = Mappers.getMapper(DetailResponse.Mapper.class);
|
||||||
|
return AmisResponse.responseCrudData(
|
||||||
|
dataFileService.downloadFile(
|
||||||
|
Sets.immutable.ofAll(StrUtil.split(ids, ","))
|
||||||
|
.collect(Long::parseLong)
|
||||||
|
).collect(mapper::from)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public AmisResponse<FinishResponse> upload(@RequestParam("file") MultipartFile file) throws IOException {
|
public AmisResponse<FinishResponse> upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||||
String filename = file.getOriginalFilename();
|
String filename = file.getOriginalFilename();
|
||||||
@@ -170,6 +193,24 @@ public class DataFileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static final class DetailRequest {
|
||||||
|
private ImmutableSet<Long> ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static final class DetailResponse {
|
||||||
|
private Long id;
|
||||||
|
private String filename;
|
||||||
|
private Long size;
|
||||||
|
private String md5;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper
|
||||||
|
public interface Mapper {
|
||||||
|
DetailResponse from(DataFile file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static final class StartRequest {
|
public static final class StartRequest {
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskService;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("flow_task")
|
||||||
|
public class TaskController extends SimpleControllerSupport<FlowTask, TaskController.SaveItem, TaskController.ListItem, TaskController.DetailItem> {
|
||||||
|
private final FlowTaskService flowTaskService;
|
||||||
|
private final FlowTaskTemplateService flowTaskTemplateService;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public TaskController(FlowTaskService flowTaskService, FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
||||||
|
super(flowTaskService);
|
||||||
|
this.flowTaskService = flowTaskService;
|
||||||
|
this.flowTaskTemplateService = flowTaskTemplateService;
|
||||||
|
this.mapper = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("input_data/{id}")
|
||||||
|
public AmisResponse<?> getInputData(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||||
|
var task = flowTaskService.detailOrThrow(id);
|
||||||
|
if (ObjectUtil.isEmpty(task.getInput())) {
|
||||||
|
return AmisResponse.responseSuccess();
|
||||||
|
}
|
||||||
|
return AmisResponse.responseSuccess(mapper.readValue(task.getInput(), Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("input_schema/{id}")
|
||||||
|
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||||
|
var task = flowTaskService.detailOrThrow(id);
|
||||||
|
if (ObjectUtil.isEmpty(task.getTemplateInputSchema())) {
|
||||||
|
return AmisResponse.responseSuccess();
|
||||||
|
}
|
||||||
|
return AmisResponse.responseSuccess(mapper.readValue(task.getTemplateInputSchema(), Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("execute/{id}")
|
||||||
|
public AmisResponse<?> execute(@PathVariable("id") Long id) throws JsonProcessingException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
|
flowTaskService.execute(id);
|
||||||
|
return AmisResponse.responseSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SaveItemMapper<FlowTask, SaveItem> saveItemMapper() {
|
||||||
|
return item -> {
|
||||||
|
FlowTask task = new FlowTask();
|
||||||
|
FlowTaskTemplate template = flowTaskTemplateService.detailOrThrow(item.getTemplateId());
|
||||||
|
task.setTemplateName(template.getName());
|
||||||
|
task.setTemplateDescription(template.getDescription());
|
||||||
|
task.setTemplateInputSchema(template.getInputSchema());
|
||||||
|
task.setTemplateFlowGraph(template.getFlowGraph());
|
||||||
|
task.setInput(ObjectUtil.isEmpty(item.getInput()) ? null : mapper.writeValueAsString(item.getInput()));
|
||||||
|
return task;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ListItemMapper<FlowTask, ListItem> listItemMapper() {
|
||||||
|
ListItem.Mapper map = Mappers.getMapper(ListItem.Mapper.class);
|
||||||
|
return map::from;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DetailItemMapper<FlowTask, DetailItem> detailItemMapper() {
|
||||||
|
DetailItem.Mapper map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||||
|
return map::from;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static final class SaveItem {
|
||||||
|
private Long templateId;
|
||||||
|
private Object input;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class ListItem extends SimpleItem {
|
||||||
|
private String templateName;
|
||||||
|
private FlowTask.Status status;
|
||||||
|
private Boolean hasInput;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper(imports = {
|
||||||
|
StrUtil.class
|
||||||
|
})
|
||||||
|
public static abstract class Mapper {
|
||||||
|
@Mapping(target = "hasInput", expression = "java(StrUtil.isNotBlank(task.getInput()))")
|
||||||
|
public abstract ListItem from(FlowTask task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class DetailItem extends ListItem {
|
||||||
|
private String error;
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper(imports = {
|
||||||
|
StrUtil.class
|
||||||
|
})
|
||||||
|
public static abstract class Mapper extends ListItem.Mapper {
|
||||||
|
@Mapping(target = "hasInput", expression = "java(StrUtil.isNotBlank(task.getInput()))")
|
||||||
|
public abstract DetailItem from(FlowTask task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.mapstruct.Context;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("flow_task/template")
|
||||||
|
public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemplate, TaskTemplateController.SaveItem, TaskTemplateController.ListItem, TaskTemplateController.DetailItem> {
|
||||||
|
private final FlowTaskTemplateService flowTaskTemplateService;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public TaskTemplateController(FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
||||||
|
super(flowTaskTemplateService);
|
||||||
|
this.flowTaskTemplateService = flowTaskTemplateService;
|
||||||
|
this.mapper = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("input_schema/{id}")
|
||||||
|
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||||
|
var template = flowTaskTemplateService.detailOrThrow(id);
|
||||||
|
if (ObjectUtil.isEmpty(template.getInputSchema())) {
|
||||||
|
return AmisResponse.responseSuccess();
|
||||||
|
}
|
||||||
|
return AmisResponse.responseSuccess(mapper.readValue(template.getInputSchema(), Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("flow_graph/{id}")
|
||||||
|
public AmisResponse<?> getFlowGraph(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||||
|
var template = flowTaskTemplateService.detailOrThrow(id);
|
||||||
|
return AmisResponse.responseSuccess(mapper.readValue(template.getFlowGraph(), Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("update_flow_graph")
|
||||||
|
public AmisResponse<?> updateFlowGraph(@RequestBody UpdateGraphItem item) throws JsonProcessingException {
|
||||||
|
flowTaskTemplateService.updateFlowGraph(item.getId(), mapper.writeValueAsString(item.getGraph()));
|
||||||
|
return AmisResponse.responseSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SaveItemMapper<FlowTaskTemplate, SaveItem> saveItemMapper() {
|
||||||
|
return Mappers.getMapper(SaveItem.Mapper.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ListItemMapper<FlowTaskTemplate, ListItem> listItemMapper() {
|
||||||
|
return Mappers.getMapper(ListItem.Mapper.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DetailItemMapper<FlowTaskTemplate, DetailItem> detailItemMapper() {
|
||||||
|
var map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||||
|
return template -> map.from(template, mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static final class SaveItem {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper
|
||||||
|
public interface Mapper extends SaveItemMapper<FlowTaskTemplate, SaveItem> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class ListItem extends SimpleItem {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper
|
||||||
|
public interface Mapper extends ListItemMapper<FlowTaskTemplate, ListItem> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class DetailItem extends SimpleItem {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private Map<String, Object> inputSchema;
|
||||||
|
private Map<String, Object> flowGraph;
|
||||||
|
|
||||||
|
@org.mapstruct.Mapper
|
||||||
|
public static abstract class Mapper {
|
||||||
|
public abstract DetailItem from(FlowTaskTemplate template, @Context ObjectMapper mapper) throws Exception;
|
||||||
|
|
||||||
|
public Map<String, Object> mapJson(String source, @Context ObjectMapper mapper) throws Exception {
|
||||||
|
if (ObjectUtil.isNull(source)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return mapper.readValue(source, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class UpdateGraphItem {
|
||||||
|
private Long id;
|
||||||
|
private Map<String, Object> graph;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.store.FlowStore;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程执行器
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250630
|
||||||
|
*/
|
||||||
|
public class FlowExecutor {
|
||||||
|
private final FlowStore flowStore;
|
||||||
|
private final ImmutableMap<String, Class<? extends FlowNodeRunner>> runnerMap;
|
||||||
|
|
||||||
|
public FlowExecutor(FlowStore flowStore, ImmutableMap<String, Class<? extends FlowNodeRunner>> runnerMap) {
|
||||||
|
this.flowStore = flowStore;
|
||||||
|
this.runnerMap = runnerMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(FlowGraph graph) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
|
execute(graph, new FlowContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(FlowGraph graph, FlowContext context) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
|
var runner = new FlowGraphRunner(graph, context, flowStore, runnerMap);
|
||||||
|
runner.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.store.FlowStore;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
import org.eclipse.collections.api.multimap.set.ImmutableSetMultimap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Graph执行器
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250701
|
||||||
|
*/
|
||||||
|
public final class FlowGraphRunner {
|
||||||
|
private final FlowGraph flowGraph;
|
||||||
|
private final FlowContext flowContext;
|
||||||
|
private final FlowStore flowStore;
|
||||||
|
private final ImmutableMap<String, Class<? extends FlowNodeRunner>> nodeRunnerClass;
|
||||||
|
private final Queue<FlowNode> executionQueue = new LinkedList<>();
|
||||||
|
private final ImmutableSetMultimap<String, FlowEdge> nodeInputMap;
|
||||||
|
private final ImmutableSetMultimap<String, FlowEdge> nodeOutputMap;
|
||||||
|
private final ImmutableMap<String, FlowNode> nodeMap;
|
||||||
|
|
||||||
|
public FlowGraphRunner(FlowGraph flowGraph, FlowContext flowContext, FlowStore flowStore, ImmutableMap<String, Class<? extends FlowNodeRunner>> nodeRunnerClass) {
|
||||||
|
this.flowGraph = flowGraph;
|
||||||
|
this.flowContext = flowContext;
|
||||||
|
this.flowStore = flowStore;
|
||||||
|
this.nodeRunnerClass = nodeRunnerClass;
|
||||||
|
|
||||||
|
nodeInputMap = flowGraph.edges().groupBy(FlowEdge::target);
|
||||||
|
nodeOutputMap = flowGraph.edges().groupBy(FlowEdge::source);
|
||||||
|
nodeMap = flowGraph.nodes().toImmutableMap(FlowNode::id, node -> node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||||
|
flowStore.init(flowGraph);
|
||||||
|
|
||||||
|
for (FlowNode node : flowGraph.nodes()) {
|
||||||
|
if (ObjectUtil.isNull(node.parentId())) {
|
||||||
|
executionQueue.offer(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!executionQueue.isEmpty()) {
|
||||||
|
var node = executionQueue.poll();
|
||||||
|
if (ObjectUtil.isNull(node)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
process(node, flowContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void process(FlowNode node, FlowContext context) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
// 没有入节点,即开始节点
|
||||||
|
!nodeInputMap.containsKey(node.id())
|
||||||
|
// 或者所有入的边状态都已经完成
|
||||||
|
|| nodeInputMap.get(node.id()).allSatisfy(edge -> flowStore.checkEdgeStatus(flowGraph.id(), edge.id(), FlowEdge.Status.EXECUTE, FlowEdge.Status.SKIP))
|
||||||
|
)
|
||||||
|
// 当前节点还未执行
|
||||||
|
&& flowStore.checkNodeStatus(flowGraph.id(), node.id(), FlowNode.Status.INITIAL)
|
||||||
|
) {
|
||||||
|
// 是开始节点或入的边有至少一条是「执行」
|
||||||
|
if (
|
||||||
|
!nodeInputMap.containsKey(node.id())
|
||||||
|
|| nodeInputMap.get(node.id()).anySatisfy(edge -> flowStore.checkEdgeStatus(flowGraph.id(), edge.id(), FlowEdge.Status.EXECUTE))
|
||||||
|
) {
|
||||||
|
flowStore.updateNodeToRunning(flowGraph.id(), node.id());
|
||||||
|
|
||||||
|
var runnerClazz = nodeRunnerClass.get(node.type());
|
||||||
|
var runner = runnerClazz.getDeclaredConstructor().newInstance();
|
||||||
|
runner.setNodeId(node.id());
|
||||||
|
runner.setContext(context);
|
||||||
|
|
||||||
|
// 处理子流程节点的逻辑
|
||||||
|
if (runner instanceof FlowNodeSubflowRunner subflowRunner) {
|
||||||
|
var subflowNodes = flowGraph.nodes().select(n -> StrUtil.equals(n.parentId(), node.id()));
|
||||||
|
var subGraph = new FlowGraph(IdUtil.fastUUID(), subflowNodes, flowGraph.edges());
|
||||||
|
subflowRunner.setSubGraph(subGraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
runner.run();
|
||||||
|
|
||||||
|
// 处理选择节点的逻辑
|
||||||
|
if (runner instanceof FlowNodeOptionalRunner) {
|
||||||
|
var targetPoint = ((FlowNodeOptionalRunner) runner).getTargetPoint();
|
||||||
|
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||||
|
if (StrUtil.equals(targetPoint, edge.sourcePoint())) {
|
||||||
|
flowStore.updateEdgeToExecute(flowGraph.id(), edge.id());
|
||||||
|
} else {
|
||||||
|
flowStore.updateEdgeToSkip(flowGraph.id(), edge.id());
|
||||||
|
}
|
||||||
|
executionQueue.offer(nodeMap.get(edge.target()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||||
|
flowStore.updateEdgeToExecute(flowGraph.id(), edge.id());
|
||||||
|
executionQueue.offer(nodeMap.get(edge.target()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flowStore.updateNodeToFinished(flowGraph.id(), node.id());
|
||||||
|
}
|
||||||
|
// 所有入的边都是跳过,当前节点就跳过
|
||||||
|
else {
|
||||||
|
flowStore.updateNodeToSkipped(flowGraph.id(), node.id());
|
||||||
|
|
||||||
|
for (FlowEdge edge : nodeOutputMap.get(node.id())) {
|
||||||
|
flowStore.updateEdgeToSkip(flowGraph.id(), edge.id());
|
||||||
|
executionQueue.offer(nodeMap.get(edge.target()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250711
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FlowHelper {
|
||||||
|
private static final TemplateEngine TEMPLATE_ENGINE = TemplateUtil.createEngine();
|
||||||
|
|
||||||
|
public static ImmutableMap<String, Object> generateInputVariablesMap(String nodeId, FlowContext context) {
|
||||||
|
var variableMap = Maps.mutable.<String, Object>empty();
|
||||||
|
var currentNodeData = context.get(nodeId);
|
||||||
|
if (currentNodeData.containsKey("inputs")) {
|
||||||
|
var inputsMap = (Map<String, Map<String, String>>) currentNodeData.get("inputs");
|
||||||
|
for (String variableName : inputsMap.keySet()) {
|
||||||
|
var expression = inputsMap.get(variableName).get("variable");
|
||||||
|
var targetVariable = generateVariable(expression, context);
|
||||||
|
if (ObjectUtil.isNotNull(targetVariable)) {
|
||||||
|
variableMap.put(variableName, targetVariable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return variableMap.toImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object generateVariable(String expression, FlowContext context) {
|
||||||
|
if (StrUtil.contains(expression, ".")) {
|
||||||
|
var splits = StrUtil.splitTrim(expression, ".", 2);
|
||||||
|
var targetNodeId = splits.get(0);
|
||||||
|
var targetVariableName = splits.get(1);
|
||||||
|
if (!context.getData().containsKey(targetNodeId)) {
|
||||||
|
throw new RuntimeException(StrUtil.format("Target node id not found: {}", targetNodeId));
|
||||||
|
}
|
||||||
|
var targetNodeData = context.getData().get(targetNodeId);
|
||||||
|
if (!targetNodeData.containsKey(targetVariableName)) {
|
||||||
|
throw new RuntimeException(StrUtil.format("Target node variable not found: {}.{}", targetNodeId, targetVariableName));
|
||||||
|
}
|
||||||
|
return targetNodeData.get(targetVariableName);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String renderTemplateText(String templateText, Map<?, ?> data) {
|
||||||
|
var template = TEMPLATE_ENGINE.getTemplate(templateText);
|
||||||
|
return template.render(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public abstract class FlowNodeOptionalRunner extends FlowNodeRunner {
|
||||||
|
@Getter
|
||||||
|
private String targetPoint;
|
||||||
|
|
||||||
|
public abstract String runOptional();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
this.targetPoint = runOptional();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.eclipse.collections.api.map.MutableMap;
|
||||||
|
|
||||||
|
public abstract class FlowNodeRunner {
|
||||||
|
@Getter
|
||||||
|
private String nodeId;
|
||||||
|
@Getter
|
||||||
|
private FlowContext context;
|
||||||
|
|
||||||
|
public abstract void run();
|
||||||
|
|
||||||
|
void setNodeId(String nodeId) {
|
||||||
|
this.nodeId = nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setContext(FlowContext context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected MutableMap<String, Object> getData() {
|
||||||
|
return context.get(nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> T getData(String key) {
|
||||||
|
var data = context.get(nodeId);
|
||||||
|
return (T) data.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> void setData(String key, T value) {
|
||||||
|
var data = context.get(nodeId);
|
||||||
|
data.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包含子流程的流程
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
public abstract class FlowNodeSubflowRunner extends FlowNodeRunner {
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private FlowGraph subGraph;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.eclipse.collections.api.map.MutableMap;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FlowContext {
|
||||||
|
private MutableMap<String, MutableMap<String, Object>> data = Maps.mutable.<String, MutableMap<String, Object>>empty().asSynchronized();
|
||||||
|
|
||||||
|
public MutableMap<String, Object> get(String key) {
|
||||||
|
if (!data.containsKey(key)) {
|
||||||
|
data.put(key, Maps.mutable.<String, Object>empty().asSynchronized());
|
||||||
|
}
|
||||||
|
return data.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程图中的边
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250630
|
||||||
|
*/
|
||||||
|
public record FlowEdge(
|
||||||
|
String id,
|
||||||
|
String source,
|
||||||
|
String target,
|
||||||
|
@JsonProperty("sourceHandle")
|
||||||
|
String sourcePoint,
|
||||||
|
@JsonProperty("targetHandle")
|
||||||
|
String targetPoint
|
||||||
|
) {
|
||||||
|
public enum Status {
|
||||||
|
INITIAL, EXECUTE, SKIP
|
||||||
|
}
|
||||||
|
|
||||||
|
public record State(
|
||||||
|
String id,
|
||||||
|
Status status,
|
||||||
|
LocalDateTime startingTime,
|
||||||
|
LocalDateTime finishedTime
|
||||||
|
) {
|
||||||
|
public State(String edgeId) {
|
||||||
|
this(edgeId, Status.INITIAL, LocalDateTime.now(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public State(String edgeId, Status status) {
|
||||||
|
this(edgeId, status, LocalDateTime.now(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程图
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250630
|
||||||
|
*/
|
||||||
|
public record FlowGraph(
|
||||||
|
String id,
|
||||||
|
ImmutableSet<FlowNode> nodes,
|
||||||
|
ImmutableSet<FlowEdge> edges
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.entity;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程图中的节点
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250630
|
||||||
|
*/
|
||||||
|
public record FlowNode(
|
||||||
|
String id,
|
||||||
|
String type,
|
||||||
|
String parentId
|
||||||
|
) {
|
||||||
|
public enum Status {
|
||||||
|
INITIAL, RUNNING, FINISHED, SKIPPED
|
||||||
|
}
|
||||||
|
|
||||||
|
public record State(
|
||||||
|
String id,
|
||||||
|
Status status,
|
||||||
|
LocalDateTime startingTime,
|
||||||
|
LocalDateTime finishedTime
|
||||||
|
) {
|
||||||
|
public State(String nodeId) {
|
||||||
|
this(nodeId, Status.INITIAL, LocalDateTime.now(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public State(String nodeId, Status status) {
|
||||||
|
this(nodeId, status, LocalDateTime.now(), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.CodeExecutor;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.JavaScriptCodeExecutor;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.PythonCodeExecutor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class CodeNode extends FlowNodeRunner {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
var mapper = SpringBeanGetter.getBean(ObjectMapper.class);
|
||||||
|
var inputVariablesMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||||
|
var type = this.<String>getData("type");
|
||||||
|
var script = this.<String>getData("content");
|
||||||
|
CodeExecutor executor = switch (type) {
|
||||||
|
case "javascript" -> new JavaScriptCodeExecutor(mapper);
|
||||||
|
case "python" -> new PythonCodeExecutor(mapper);
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (ObjectUtil.isNull(executor)) {
|
||||||
|
throw new RuntimeException(StrUtil.format("Unsupported type: {}", type));
|
||||||
|
}
|
||||||
|
var result = executor.execute(script, inputVariablesMap);
|
||||||
|
result.forEachKeyValue(this::setData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250711
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class InputNode extends FlowNodeRunner {
|
||||||
|
public static final String KEY = "flow_inputs";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
var inputData = getContext().getData().get(KEY);
|
||||||
|
var inputs = this.<Map<String, Object>>getData("inputs");
|
||||||
|
for (String variable : inputs.keySet()) {
|
||||||
|
if (inputData.containsKey(variable)) {
|
||||||
|
setData(variable, inputData.get(variable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250711
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class LlmNode extends FlowNodeRunner {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
var variableMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||||
|
var sourcePrompt = (String) getData("systemPrompt");
|
||||||
|
if (StrUtil.isNotBlank(sourcePrompt)) {
|
||||||
|
var prompt = FlowHelper.renderTemplateText(sourcePrompt, variableMap.toMap());
|
||||||
|
var builder = SpringBeanGetter.getBean("chat", ChatClient.Builder.class);
|
||||||
|
var client = builder.build();
|
||||||
|
var content = client.prompt()
|
||||||
|
.user(prompt)
|
||||||
|
.call()
|
||||||
|
.content();
|
||||||
|
setData("text", content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeSubflowRunner;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 循环节点
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class LoopNode extends FlowNodeSubflowRunner {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info("{}", getSubGraph());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250711
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class OutputNode extends FlowNodeRunner {
|
||||||
|
private static final String KEY = "flow_outputs";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
var variableMap = FlowHelper.generateInputVariablesMap(getNodeId(), getContext());
|
||||||
|
getContext().getData().put(KEY, variableMap.toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowHelper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeOptionalRunner;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Slf4j
|
||||||
|
public class SwitchNode extends FlowNodeOptionalRunner {
|
||||||
|
@Override
|
||||||
|
public String runOptional() {
|
||||||
|
var conditions = this.<List<Map<String, Object>>>getData("conditions");
|
||||||
|
for (Map<String, Object> item : conditions) {
|
||||||
|
var condition = (Map<String, Object>) item.getOrDefault("condition", Map.of());
|
||||||
|
var id = (String) condition.getOrDefault("id", "");
|
||||||
|
var conjunction = (String) condition.getOrDefault("conjunction", "and");
|
||||||
|
var conditionChildren = ((List<Map<String, Object>>) condition.getOrDefault("children", List.<Map<String, Object>>of()));
|
||||||
|
if (
|
||||||
|
StrUtil.equals(conjunction, "and")
|
||||||
|
&& conditionChildren.stream().allMatch(this::check)
|
||||||
|
) {
|
||||||
|
return id;
|
||||||
|
} else if (
|
||||||
|
StrUtil.equals(conjunction, "or")
|
||||||
|
&& conditionChildren.stream().anyMatch(this::check)
|
||||||
|
) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean check(Map<String, Object> condition) {
|
||||||
|
var leftVariable = (String) BeanUtil.getProperty(condition, "left.field");
|
||||||
|
var left = FlowHelper.generateVariable(leftVariable, getContext());
|
||||||
|
var operator = (String) condition.get("op");
|
||||||
|
var right = condition.get("right");
|
||||||
|
if (left instanceof CharSequence || left instanceof Boolean) {
|
||||||
|
String source = StrUtil.toStringOrNull(left);
|
||||||
|
String target = StrUtil.toStringOrNull(right);
|
||||||
|
return switch (operator) {
|
||||||
|
case "equal" -> StrUtil.equals(source, target);
|
||||||
|
case "not_equal" -> !StrUtil.equals(source, target);
|
||||||
|
case "is_empty" -> StrUtil.isBlank(source);
|
||||||
|
case "is_not_empty" -> StrUtil.isNotBlank(source);
|
||||||
|
case "like" -> StrUtil.contains(source, target);
|
||||||
|
case "not_like" -> !StrUtil.contains(source, target);
|
||||||
|
case "starts_with" -> StrUtil.startWith(source, target);
|
||||||
|
case "ends_with" -> StrUtil.endWith(source, target);
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
} else if (left instanceof Number source) {
|
||||||
|
var sourceNumber = new BigDecimal(StrUtil.toString(source));
|
||||||
|
var targetNumber = new BigDecimal(StrUtil.toString(right));
|
||||||
|
return switch (operator) {
|
||||||
|
case "equal" -> NumberUtil.equals(sourceNumber, targetNumber);
|
||||||
|
case "not_equal" -> !NumberUtil.equals(sourceNumber, targetNumber);
|
||||||
|
case "greater" -> NumberUtil.isGreater(sourceNumber, targetNumber);
|
||||||
|
case "greater_equal" -> NumberUtil.isGreaterOrEqual(sourceNumber, targetNumber);
|
||||||
|
case "less" -> NumberUtil.isLess(sourceNumber, targetNumber);
|
||||||
|
case "less_equal" -> NumberUtil.isLessOrEqual(sourceNumber, targetNumber);
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
} else if (left instanceof Collection<?> source) {
|
||||||
|
return switch (operator) {
|
||||||
|
case "is_empty" -> CollectionUtil.isEmpty(source);
|
||||||
|
case "is_not_empty" -> CollectionUtil.isNotEmpty(source);
|
||||||
|
case "contain" -> CollectionUtil.safeContains(source, right);
|
||||||
|
case "not_contain" -> !CollectionUtil.safeContains(source, right);
|
||||||
|
default -> false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
public interface CodeExecutor {
|
||||||
|
ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap);
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
import org.graalvm.polyglot.Context;
|
||||||
|
import org.graalvm.polyglot.Engine;
|
||||||
|
import org.graalvm.polyglot.Source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class JavaScriptCodeExecutor implements CodeExecutor {
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public JavaScriptCodeExecutor(ObjectMapper mapper) {
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap) {
|
||||||
|
if (StrUtil.isBlank(script)) {
|
||||||
|
return Maps.immutable.empty();
|
||||||
|
}
|
||||||
|
try (var engin = Engine.create()) {
|
||||||
|
try (
|
||||||
|
var context = Context.newBuilder()
|
||||||
|
.allowAllAccess(true)
|
||||||
|
.engine(engin)
|
||||||
|
.build()
|
||||||
|
) {
|
||||||
|
var bindings = context.getBindings("js");
|
||||||
|
bindings.putMember("context", inputVariablesMap);
|
||||||
|
var result = context.eval(
|
||||||
|
Source.create(
|
||||||
|
"js",
|
||||||
|
"""
|
||||||
|
function process() {
|
||||||
|
%s
|
||||||
|
}
|
||||||
|
var result = process();
|
||||||
|
JSON.stringify(result? result: {})
|
||||||
|
""".formatted(script)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return mapper.readValue(result.asString(), new TypeReference<>() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.node.code;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.map.ImmutableMap;
|
||||||
|
import org.python.core.PySystemState;
|
||||||
|
import org.python.util.PythonInterpreter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250718
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class PythonCodeExecutor implements CodeExecutor {
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public PythonCodeExecutor(ObjectMapper mapper) {
|
||||||
|
this.mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public ImmutableMap<String, Object> execute(String script, ImmutableMap<String, Object> inputVariablesMap) {
|
||||||
|
try (var systemState = new PySystemState()) {
|
||||||
|
systemState.setdefaultencoding("UTF-8");
|
||||||
|
var interpreter = new PythonInterpreter(null, systemState);
|
||||||
|
script = Arrays.stream(script.split("\n"))
|
||||||
|
.map(line -> " " + line)
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
interpreter.set("context", inputVariablesMap);
|
||||||
|
var pythonScript = interpreter.compile(
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
|
def process():
|
||||||
|
%s
|
||||||
|
|
||||||
|
result = json.dumps(process())
|
||||||
|
""".formatted(script)
|
||||||
|
);
|
||||||
|
interpreter.exec(pythonScript);
|
||||||
|
var result = interpreter.get("result");
|
||||||
|
return mapper.readValue((String) result.__tojava__(String.class), new TypeReference<>() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.store;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储状态
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250701
|
||||||
|
*/
|
||||||
|
public interface FlowStore {
|
||||||
|
void init(FlowGraph flowGraph);
|
||||||
|
|
||||||
|
void updateNodeToRunning(String graphId, String nodeId);
|
||||||
|
|
||||||
|
void updateNodeToSkipped(String graphId, String nodeId);
|
||||||
|
|
||||||
|
void updateNodeToFinished(String graphId, String nodeId);
|
||||||
|
|
||||||
|
void updateEdgeToExecute(String graphId, String edgeId);
|
||||||
|
|
||||||
|
void updateEdgeToSkip(String graphId, String edgeId);
|
||||||
|
|
||||||
|
boolean checkNodeStatus(String graphId, String nodeId, FlowNode.Status... statuses);
|
||||||
|
|
||||||
|
boolean checkEdgeStatus(String graphId, String edgeId, FlowEdge.Status... statuses);
|
||||||
|
|
||||||
|
void print();
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.engine.store;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.eclipse.collections.api.map.MutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于内存的流程状态存储
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250701
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class InMemoryFlowStore implements FlowStore {
|
||||||
|
private static final MutableMap<String, FlowNode.State> flowNodeStateMap = Maps.mutable.<String, FlowNode.State>empty().asSynchronized();
|
||||||
|
private static final MutableMap<String, FlowEdge.State> flowEdgeStateMap = Maps.mutable.<String, FlowEdge.State>empty().asSynchronized();
|
||||||
|
|
||||||
|
private String multiKey(String... key) {
|
||||||
|
return String.join("-", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(FlowGraph flowGraph) {
|
||||||
|
for (FlowNode node : flowGraph.nodes()) {
|
||||||
|
flowNodeStateMap.put(multiKey(flowGraph.id(), node.id()), new FlowNode.State(node.id()));
|
||||||
|
}
|
||||||
|
for (FlowEdge edge : flowGraph.edges()) {
|
||||||
|
flowEdgeStateMap.put(multiKey(flowGraph.id(), edge.id()), new FlowEdge.State(edge.id()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateNodeToRunning(String graphId, String nodeId) {
|
||||||
|
flowNodeStateMap.updateValue(
|
||||||
|
multiKey(graphId, nodeId),
|
||||||
|
() -> new FlowNode.State(nodeId, FlowNode.Status.RUNNING),
|
||||||
|
old -> new FlowNode.State(nodeId, FlowNode.Status.RUNNING, old.startingTime(), old.finishedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateNodeToSkipped(String graphId, String nodeId) {
|
||||||
|
flowNodeStateMap.updateValue(
|
||||||
|
multiKey(graphId, nodeId),
|
||||||
|
() -> new FlowNode.State(nodeId, FlowNode.Status.SKIPPED),
|
||||||
|
old -> new FlowNode.State(nodeId, FlowNode.Status.SKIPPED, old.startingTime(), old.finishedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateNodeToFinished(String graphId, String nodeId) {
|
||||||
|
flowNodeStateMap.updateValue(
|
||||||
|
multiKey(graphId, nodeId),
|
||||||
|
() -> new FlowNode.State(nodeId, FlowNode.Status.FINISHED),
|
||||||
|
old -> new FlowNode.State(nodeId, FlowNode.Status.FINISHED, old.startingTime(), old.finishedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEdgeToExecute(String graphId, String edgeId) {
|
||||||
|
flowEdgeStateMap.updateValue(
|
||||||
|
multiKey(graphId, edgeId),
|
||||||
|
() -> new FlowEdge.State(edgeId, FlowEdge.Status.EXECUTE),
|
||||||
|
old -> new FlowEdge.State(edgeId, FlowEdge.Status.EXECUTE, old.startingTime(), old.finishedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEdgeToSkip(String graphId, String edgeId) {
|
||||||
|
flowEdgeStateMap.updateValue(
|
||||||
|
multiKey(graphId, edgeId),
|
||||||
|
() -> new FlowEdge.State(edgeId, FlowEdge.Status.SKIP),
|
||||||
|
old -> new FlowEdge.State(edgeId, FlowEdge.Status.SKIP, old.startingTime(), old.finishedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkNodeStatus(String graphId, String nodeId, FlowNode.Status... statuses) {
|
||||||
|
String key = multiKey(graphId, nodeId);
|
||||||
|
if (flowNodeStateMap.containsKey(key)) {
|
||||||
|
return ArrayUtil.contains(statuses, flowNodeStateMap.get(key).status());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean checkEdgeStatus(String graphId, String edgeId, FlowEdge.Status... statuses) {
|
||||||
|
String key = multiKey(graphId, edgeId);
|
||||||
|
if (flowEdgeStateMap.containsKey(key)) {
|
||||||
|
return ArrayUtil.contains(statuses, flowEdgeStateMap.get(key).status());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print() {
|
||||||
|
log.info("====== Flow Store ======");
|
||||||
|
log.info("====== Flow Node ======");
|
||||||
|
flowNodeStateMap.forEachKeyValue((key, value) -> log.info("{}: {}", key, value.status()));
|
||||||
|
log.info("====== Flow Edge ======");
|
||||||
|
flowEdgeStateMap.forEachKeyValue((key, value) -> log.info("{}: {}", key, value.status()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import lombok.Getter;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,11 +24,17 @@ import org.hibernate.annotations.DynamicUpdate;
|
|||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_file")
|
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_file")
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@Comment("记录上传的文件存储信息")
|
||||||
public class DataFile extends SimpleEntity {
|
public class DataFile extends SimpleEntity {
|
||||||
|
@Comment("文件名称")
|
||||||
private String filename;
|
private String filename;
|
||||||
|
@Comment("文件大小,单位是byte")
|
||||||
private Long size;
|
private Long size;
|
||||||
|
@Comment("文件的md5编码,用于校验文件的完整性")
|
||||||
private String md5;
|
private String md5;
|
||||||
|
@Comment("文件在主机上存储的实际路径")
|
||||||
private String path;
|
private String path;
|
||||||
|
@Comment("文件类型,通常记录的是文件的后缀名")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
public DataFile(String filename) {
|
public DataFile(String filename) {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.ConstraintMode;
|
import jakarta.persistence.ConstraintMode;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.ForeignKey;
|
import jakarta.persistence.ForeignKey;
|
||||||
import jakarta.persistence.JoinTable;
|
import jakarta.persistence.JoinTable;
|
||||||
@@ -17,6 +19,7 @@ import java.util.Set;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@@ -30,18 +33,25 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
@NamedEntityGraph(name = "feedback.detail", attributeNodes = {
|
@NamedEntityGraph(name = "feedback.detail", attributeNodes = {
|
||||||
@NamedAttributeNode("pictures")
|
@NamedAttributeNode("pictures")
|
||||||
})
|
})
|
||||||
|
@Comment("报障信息记录")
|
||||||
public class Feedback extends SimpleEntity {
|
public class Feedback extends SimpleEntity {
|
||||||
|
@Comment("原始报障说明")
|
||||||
@Column(nullable = false, columnDefinition = "longtext")
|
@Column(nullable = false, columnDefinition = "longtext")
|
||||||
private String source;
|
private String source;
|
||||||
|
@Comment("报障相关截图")
|
||||||
@OneToMany(fetch = FetchType.EAGER)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
@JoinTable(catalog = Constants.DATABASE_NAME, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
@JoinTable(catalog = Constants.DATABASE_NAME, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private Set<DataFile> pictures;
|
private Set<DataFile> pictures;
|
||||||
|
@Comment("AI的分析结果")
|
||||||
@Column(columnDefinition = "longtext")
|
@Column(columnDefinition = "longtext")
|
||||||
private String analysis;
|
private String analysis;
|
||||||
|
@Comment("AI的解决方案")
|
||||||
@Column(columnDefinition = "longtext")
|
@Column(columnDefinition = "longtext")
|
||||||
private String conclusion;
|
private String conclusion;
|
||||||
|
@Comment("报障处理状态")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
private Status status = Status.ANALYSIS_PROCESSING;
|
private Status status = Status.ANALYSIS_PROCESSING;
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||||
|
import com.lanyuanxiaoyao.service.common.Constants;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@DynamicUpdate
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_flow_task")
|
||||||
|
@Comment("流程任务记录")
|
||||||
|
public class FlowTask extends SimpleEntity {
|
||||||
|
// 每个任务对应的模板都是唯一,避免模板修改之后任务的状态、运行等状态都无法展示
|
||||||
|
// 不管允许不允许任务重跑,这些都要保存下来
|
||||||
|
@Comment("任务对应的模板名称")
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String templateName;
|
||||||
|
@Comment("任务对应的模板功能、内容说明")
|
||||||
|
private String templateDescription;
|
||||||
|
@Comment("任务对应的模板入参Schema")
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String templateInputSchema;
|
||||||
|
@Comment("任务对应的模板前端流程图数据")
|
||||||
|
@Column(nullable = false, columnDefinition = "longtext")
|
||||||
|
private String templateFlowGraph = "{}";
|
||||||
|
|
||||||
|
@Comment("任务注释,用于额外说明")
|
||||||
|
@Column(columnDefinition = "text")
|
||||||
|
private String comment;
|
||||||
|
@Comment("任务输入")
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String input;
|
||||||
|
@Comment("任务运行状态")
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Status status = Status.RUNNING;
|
||||||
|
@Comment("任务运行产生的报错")
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String error;
|
||||||
|
@Comment("任务运行结果")
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String result;
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
RUNNING,
|
||||||
|
ERROR,
|
||||||
|
FINISHED,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.entity;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
|
||||||
|
import com.lanyuanxiaoyao.service.common.Constants;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@DynamicUpdate
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
|
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_flow_task_template")
|
||||||
|
@Comment("流程任务模板")
|
||||||
|
public class FlowTaskTemplate extends SimpleEntity {
|
||||||
|
@Comment("模板名称")
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String name;
|
||||||
|
@Comment("模板功能、内容说明")
|
||||||
|
private String description;
|
||||||
|
@Comment("模板入参Schema")
|
||||||
|
@Column(columnDefinition = "longtext")
|
||||||
|
private String inputSchema;
|
||||||
|
@Comment("前端流程图数据")
|
||||||
|
@Column(nullable = false, columnDefinition = "longtext")
|
||||||
|
private String flowGraph = "{}";
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.ConstraintMode;
|
import jakarta.persistence.ConstraintMode;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.ForeignKey;
|
import jakarta.persistence.ForeignKey;
|
||||||
import jakarta.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
@@ -14,6 +16,7 @@ import jakarta.persistence.Table;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@@ -28,10 +31,14 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_group")
|
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_group")
|
||||||
|
@Comment("知识库内的逻辑分组,比如一个文件是一个分组或一次上传的所有文本是一个分组,可以自由使用而不是限于文件范畴")
|
||||||
public class Group extends SimpleEntity {
|
public class Group extends SimpleEntity {
|
||||||
|
@Comment("分组名称")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
@Comment("分组处理状态")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
private Status status = Status.RUNNING;
|
private Status status = Status.RUNNING;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import jakarta.persistence.CascadeType;
|
|||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
import jakarta.persistence.EntityListeners;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
@@ -13,6 +15,7 @@ import java.util.Set;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.Comment;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@@ -27,16 +30,23 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|||||||
@DynamicUpdate
|
@DynamicUpdate
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_knowledge")
|
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_knowledge")
|
||||||
|
@Comment("知识库")
|
||||||
public class Knowledge extends SimpleEntity {
|
public class Knowledge extends SimpleEntity {
|
||||||
|
@Comment("知识库对应的向量库名")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Long vectorSourceId;
|
private Long vectorSourceId;
|
||||||
|
@Comment("知识库名称")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
@Comment("知识库说明")
|
||||||
@Column(nullable = false, columnDefinition = "longtext")
|
@Column(nullable = false, columnDefinition = "longtext")
|
||||||
private String description;
|
private String description;
|
||||||
|
@Comment("知识库策略")
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
private Strategy strategy = Strategy.Cosine;
|
private Strategy strategy = Strategy.Cosine;
|
||||||
|
|
||||||
|
@Comment("知识库下包含的分组")
|
||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "knowledge", cascade = CascadeType.ALL)
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "knowledge", cascade = CascadeType.ALL)
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private Set<Group> groups;
|
private Set<Group> groups;
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.entity.vo;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.eclipse.collections.api.map.MutableMap;
|
||||||
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FlowGraphVo {
|
||||||
|
private ImmutableSet<FlowNode> nodes;
|
||||||
|
private ImmutableSet<FlowEdge> edges;
|
||||||
|
private MutableMap<String, MutableMap<String, Object>> data;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface FlowTaskRepository extends SimpleRepository<FlowTask, Long> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.repository;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.repository.SimpleRepository;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface FlowTaskTemplateRepository extends SimpleRepository<FlowTaskTemplate, Long> {
|
||||||
|
}
|
||||||
@@ -7,15 +7,13 @@ import com.lanyuanxiaoyao.service.ai.web.entity.context.FeedbackContext;
|
|||||||
import com.lanyuanxiaoyao.service.ai.web.repository.FeedbackRepository;
|
import com.lanyuanxiaoyao.service.ai.web.repository.FeedbackRepository;
|
||||||
import com.yomahub.liteflow.core.FlowExecutor;
|
import com.yomahub.liteflow.core.FlowExecutor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class FeedbackService extends SimpleServiceSupport<Feedback> {
|
public class FeedbackService extends SimpleServiceSupport<Feedback> {
|
||||||
private final FlowExecutor executor;
|
private final FlowExecutor executor;
|
||||||
|
|
||||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||||
@@ -24,7 +22,7 @@ public class FeedbackService extends SimpleServiceSupport<Feedback> {
|
|||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(initialDelay = 1, fixedDelay = 1, timeUnit = TimeUnit.MINUTES)
|
// @Scheduled(initialDelay = 1, fixedDelay = 1, timeUnit = TimeUnit.MINUTES)
|
||||||
public void analysis() {
|
public void analysis() {
|
||||||
List<Feedback> feedbacks = repository.findAll(
|
List<Feedback> feedbacks = repository.findAll(
|
||||||
builder -> builder
|
builder -> builder
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.service.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowExecutor;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowContext;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.CodeNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.InputNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.LlmNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.LoopNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.OutputNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.SwitchNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.store.InMemoryFlowStore;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.vo.FlowGraphVo;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.repository.FlowTaskRepository;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class FlowTaskService extends SimpleServiceSupport<FlowTask> {
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public FlowTaskService(FlowTaskRepository flowTaskRepository, Jackson2ObjectMapperBuilder builder) {
|
||||||
|
super(flowTaskRepository);
|
||||||
|
this.mapper = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(Long id) throws JsonProcessingException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
|
var flowTask = detailOrThrow(id);
|
||||||
|
var graphVo = mapper.readValue(flowTask.getTemplateFlowGraph(), FlowGraphVo.class);
|
||||||
|
var flowGraph = new FlowGraph(IdUtil.fastUUID(), graphVo.getNodes(), graphVo.getEdges());
|
||||||
|
|
||||||
|
var store = new InMemoryFlowStore();
|
||||||
|
var executor = new FlowExecutor(
|
||||||
|
store,
|
||||||
|
Maps.immutable.ofAll(Map.of(
|
||||||
|
"loop-node", LoopNode.class,
|
||||||
|
"switch-node", SwitchNode.class,
|
||||||
|
"code-node", CodeNode.class,
|
||||||
|
"llm-node", LlmNode.class,
|
||||||
|
"input-node", InputNode.class,
|
||||||
|
"output-node", OutputNode.class
|
||||||
|
))
|
||||||
|
);
|
||||||
|
FlowContext context = new FlowContext();
|
||||||
|
context.setData(graphVo.getData());
|
||||||
|
|
||||||
|
if (ObjectUtil.isNotEmpty(flowTask.getInput())) {
|
||||||
|
context.getData().put(InputNode.KEY, mapper.readValue(flowTask.getInput(), new TypeReference<>() {
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
executor.execute(flowGraph, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web.service.task;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.base.service.SimpleServiceSupport;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.entity.vo.FlowGraphVo;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.repository.FlowTaskTemplateRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class FlowTaskTemplateService extends SimpleServiceSupport<FlowTaskTemplate> {
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
|
public FlowTaskTemplateService(FlowTaskTemplateRepository flowTaskTemplateRepository, Jackson2ObjectMapperBuilder builder) {
|
||||||
|
super(flowTaskTemplateRepository);
|
||||||
|
this.mapper = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void updateFlowGraph(Long id, String flowGraph) throws JsonProcessingException {
|
||||||
|
var template = detailOrThrow(id);
|
||||||
|
|
||||||
|
var graph = mapper.readValue(flowGraph, FlowGraphVo.class);
|
||||||
|
// 如果发现输入节点,就单独提取出来
|
||||||
|
var inputNode = graph.getNodes()
|
||||||
|
.detectOptional(node -> StrUtil.equals(node.type(), "input-node") && ObjectUtil.isEmpty(node.parentId()))
|
||||||
|
.orElse(null);
|
||||||
|
if (ObjectUtil.isNotNull(inputNode)) {
|
||||||
|
var nodeId = inputNode.id();
|
||||||
|
var nodeData = graph.getData().getOrDefault(nodeId, null);
|
||||||
|
if (ObjectUtil.isNotNull(nodeData) && nodeData.containsKey("inputs")) {
|
||||||
|
template.setInputSchema(mapper.writeValueAsString(nodeData.get("inputs")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template.setFlowGraph(flowGraph);
|
||||||
|
save(template);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.ai.chat.client.ChatClient;
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
import org.springframework.ai.tool.annotation.Tool;
|
import org.springframework.ai.tool.annotation.Tool;
|
||||||
@@ -44,7 +44,7 @@ public class ChartTool {
|
|||||||
""") String request
|
""") String request
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: mermaid[request]. request:{}", request);
|
log.info("Enter method: mermaid[request]. request:{}", request);
|
||||||
ChatClient.Builder builder = WebApplication.getBean("chat", ChatClient.Builder.class);
|
ChatClient.Builder builder = SpringBeanGetter.getBean("chat", ChatClient.Builder.class);
|
||||||
ChatClient client = builder.build();
|
ChatClient client = builder.build();
|
||||||
return client.prompt()
|
return client.prompt()
|
||||||
// language=TEXT
|
// language=TEXT
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.lanyuanxiaoyao.service.ai.web.tools;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
import com.lanyuanxiaoyao.service.forest.service.KnowledgeService;
|
import com.lanyuanxiaoyao.service.forest.service.KnowledgeService;
|
||||||
import org.springframework.ai.tool.annotation.Tool;
|
import org.springframework.ai.tool.annotation.Tool;
|
||||||
import org.springframework.ai.tool.annotation.ToolParam;
|
import org.springframework.ai.tool.annotation.ToolParam;
|
||||||
@@ -27,7 +27,7 @@ public class KnowledgeTool {
|
|||||||
""")
|
""")
|
||||||
String query
|
String query
|
||||||
) {
|
) {
|
||||||
KnowledgeService knowledgeService = WebApplication.getBean(KnowledgeService.class);
|
KnowledgeService knowledgeService = SpringBeanGetter.getBean(KnowledgeService.class);
|
||||||
var documents = knowledgeService.query(knowledgeId, query, 10, 0.5);
|
var documents = knowledgeService.query(knowledgeId, query, 10, 0.5);
|
||||||
if (ObjectUtil.isNotEmpty(documents)) {
|
if (ObjectUtil.isNotEmpty(documents)) {
|
||||||
return StrUtil.format("""
|
return StrUtil.format("""
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
import com.lanyuanxiaoyao.service.forest.service.InfoService;
|
import com.lanyuanxiaoyao.service.forest.service.InfoService;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -27,7 +27,7 @@ public class TableTool {
|
|||||||
""") String sql
|
""") String sql
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: executeJdbc[sql]. sql:{}", sql);
|
log.info("Enter method: executeJdbc[sql]. sql:{}", sql);
|
||||||
InfoService infoService = WebApplication.getBean(InfoService.class);
|
InfoService infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||||
String result = infoService.jdbc(sql)
|
String result = infoService.jdbc(sql)
|
||||||
.collect(map -> map.valuesView().makeString(","))
|
.collect(map -> map.valuesView().makeString(","))
|
||||||
.makeString("\n");
|
.makeString("\n");
|
||||||
@@ -48,7 +48,7 @@ public class TableTool {
|
|||||||
""") String type
|
""") String type
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: tableCount[type]. type:{}", type);
|
log.info("Enter method: tableCount[type]. type:{}", type);
|
||||||
var infoService = WebApplication.getBean(InfoService.class);
|
var infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case "logic" -> StrUtil.format("""
|
case "logic" -> StrUtil.format("""
|
||||||
逻辑表共{}张,其中重点表{}张
|
逻辑表共{}张,其中重点表{}张
|
||||||
@@ -83,7 +83,7 @@ public class TableTool {
|
|||||||
String type
|
String type
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: version[date, type]. date:{},type:{}", date, type);
|
log.info("Enter method: version[date, type]. date:{},type:{}", date, type);
|
||||||
InfoService infoService = WebApplication.getBean(InfoService.class);
|
InfoService infoService = SpringBeanGetter.getBean(InfoService.class);
|
||||||
String version = date;
|
String version = date;
|
||||||
if (StrUtil.isBlank(version)) {
|
if (StrUtil.isBlank(version)) {
|
||||||
version = LocalDateTime.now().minusDays(1).format(FORMATTER);
|
version = LocalDateTime.now().minusDays(1).format(FORMATTER);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.service.ai.web.tools;
|
package com.lanyuanxiaoyao.service.ai.web.tools;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.lanyuanxiaoyao.service.ai.web.WebApplication;
|
import com.lanyuanxiaoyao.service.ai.web.configuration.SpringBeanGetter;
|
||||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
|
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnApplication;
|
||||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
|
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnQueue;
|
||||||
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
|
import com.lanyuanxiaoyao.service.configuration.entity.yarn.YarnRootQueue;
|
||||||
@@ -27,7 +27,7 @@ public class YarnTool {
|
|||||||
""") String cluster
|
""") String cluster
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: yarnStatus[cluster]. cluster:{}", cluster);
|
log.info("Enter method: yarnStatus[cluster]. cluster:{}", cluster);
|
||||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||||
YarnRootQueue status = yarnService.cluster(cluster);
|
YarnRootQueue status = yarnService.cluster(cluster);
|
||||||
return (status.getUsedCapacity() * 100.0) / status.getCapacity();
|
return (status.getUsedCapacity() * 100.0) / status.getCapacity();
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ public class YarnTool {
|
|||||||
""") String queue
|
""") String queue
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: yarnQueueStatus[cluster, queue]. cluster:{},queue:{}", cluster, queue);
|
log.info("Enter method: yarnQueueStatus[cluster, queue]. cluster:{},queue:{}", cluster, queue);
|
||||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||||
YarnQueue status = yarnService.queueDetail(cluster, queue);
|
YarnQueue status = yarnService.queueDetail(cluster, queue);
|
||||||
return (status.getAbsoluteCapacity() * 100.0) / status.getAbsoluteMaxCapacity();
|
return (status.getAbsoluteCapacity() * 100.0) / status.getAbsoluteMaxCapacity();
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public class YarnTool {
|
|||||||
""") String type
|
""") String type
|
||||||
) {
|
) {
|
||||||
log.info("Enter method: yarnTaskStatus[cluster, type]. cluster:{},type:{}", cluster, type);
|
log.info("Enter method: yarnTaskStatus[cluster, type]. cluster:{},type:{}", cluster, type);
|
||||||
YarnService yarnService = WebApplication.getBean(YarnService.class);
|
YarnService yarnService = SpringBeanGetter.getBean(YarnService.class);
|
||||||
ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> StrUtil.isNotBlank(type) && StrUtil.contains(app.getName(), type));
|
ImmutableList<YarnApplication> applications = yarnService.jobList(cluster).select(app -> StrUtil.isNotBlank(type) && StrUtil.contains(app.getName(), type));
|
||||||
return StrUtil.format(
|
return StrUtil.format(
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.ClassUtil;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
import org.hibernate.tool.schema.TargetType;
|
||||||
|
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JPA直接生成建表语句
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250702
|
||||||
|
*/
|
||||||
|
public class GenerateDDL {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String root = "/Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-ai/target/sql";
|
||||||
|
FileUtil.mkdir(root);
|
||||||
|
/* ClassUtil.scanPackageBySuper("org.hibernate.dialect", Dialect.class)
|
||||||
|
.stream()
|
||||||
|
.filter(clazz -> StrUtil.startWith(clazz.getSimpleName(), "MySQL"))
|
||||||
|
.filter(clazz -> !StrUtil.startWith(clazz.getSimpleName(), "Abstract"))
|
||||||
|
.filter(clazz -> !StrUtil.startWith(clazz.getSimpleName(), "Dialect"))
|
||||||
|
.forEach(dialectClazz -> generateDDL(root, dialectClazz)); */
|
||||||
|
generateDDL(root, MySQLDialect.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateDDL(String path, Class<?> dialect) {
|
||||||
|
var metadataSources = new MetadataSources(
|
||||||
|
new StandardServiceRegistryBuilder()
|
||||||
|
.applySetting("hibernate.dialect", dialect.getName())
|
||||||
|
.applySetting("hibernate.physical_naming_strategy", CamelCaseToUnderscoresNamingStrategy.class.getName())
|
||||||
|
.applySetting("hibernate.implicit_naming_strategy", SpringImplicitNamingStrategy.class.getName())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
var classes = ClassUtil.scanPackageByAnnotation("com.lanyuanxiaoyao.service.ai.web.entity", Entity.class);
|
||||||
|
classes.forEach(metadataSources::addAnnotatedClass);
|
||||||
|
var export = new SchemaExport();
|
||||||
|
export.setFormat(true);
|
||||||
|
export.setDelimiter(";");
|
||||||
|
export.setOutputFile(path + "/" + dialect.getSimpleName() + ".sql");
|
||||||
|
export.setOverrideOutputFileContent();
|
||||||
|
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadataSources.buildMetadata());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.eclipsecollections.EclipseCollectionsModule;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.node.code.JavaScriptCodeExecutor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250717
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TestCodeExecutor {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
var mapper = new ObjectMapper();
|
||||||
|
mapper.registerModule(new EclipseCollectionsModule());
|
||||||
|
var executor = new JavaScriptCodeExecutor(mapper);
|
||||||
|
var result = executor.execute(
|
||||||
|
"""
|
||||||
|
return {'code': 1, 'text': context.get('text')}
|
||||||
|
""",
|
||||||
|
Maps.immutable.of(
|
||||||
|
"text", "hello world"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
log.info("Result: {}", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.lanyuanxiaoyao.service.ai.web;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowExecutor;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeOptionalRunner;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.FlowNodeRunner;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowEdge;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowGraph;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.entity.FlowNode;
|
||||||
|
import com.lanyuanxiaoyao.service.ai.web.engine.store.InMemoryFlowStore;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Maps;
|
||||||
|
import org.eclipse.collections.api.factory.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @version 20250701
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TestFlow {
|
||||||
|
public static void main(String[] args) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
|
||||||
|
var store = new InMemoryFlowStore();
|
||||||
|
var executor = new FlowExecutor(
|
||||||
|
store,
|
||||||
|
Maps.immutable.of(
|
||||||
|
"plain-node", PlainNode.class,
|
||||||
|
"option-node", PlainOptionNode.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
/*
|
||||||
|
* 4 6 7
|
||||||
|
* 1 2 5 8---3
|
||||||
|
* \9/
|
||||||
|
*/
|
||||||
|
var graph = new FlowGraph(
|
||||||
|
"graph-1",
|
||||||
|
Sets.immutable.of(
|
||||||
|
new FlowNode("node-1", "plain-node", null),
|
||||||
|
new FlowNode("node-2", "plain-node", null),
|
||||||
|
new FlowNode("node-4", "plain-node", null),
|
||||||
|
new FlowNode("node-6", "plain-node", null),
|
||||||
|
new FlowNode("node-7", "plain-node", null),
|
||||||
|
new FlowNode("node-5", "plain-node", null),
|
||||||
|
new FlowNode("node-8", "option-node", null),
|
||||||
|
new FlowNode("node-9", "plain-node", null),
|
||||||
|
new FlowNode("node-3", "plain-node", null)
|
||||||
|
),
|
||||||
|
Sets.immutable.of(
|
||||||
|
new FlowEdge("edge-1", "node-1", "node-2", null, null),
|
||||||
|
new FlowEdge("edge-2", "node-2", "node-4", null, null),
|
||||||
|
new FlowEdge("edge-3", "node-2", "node-5", null, null),
|
||||||
|
new FlowEdge("edge-4", "node-5", "node-8", null, null),
|
||||||
|
new FlowEdge("edge-5", "node-8", "node-9", "yes", null),
|
||||||
|
new FlowEdge("edge-6", "node-8", "node-3", "no", null),
|
||||||
|
new FlowEdge("edge-7", "node-9", "node-3", null, null),
|
||||||
|
new FlowEdge("edge-8", "node-4", "node-6", null, null),
|
||||||
|
new FlowEdge("edge-9", "node-6", "node-7", null, null),
|
||||||
|
new FlowEdge("edge-10", "node-7", "node-3", null, null)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
executor.execute(graph);
|
||||||
|
store.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlainNode extends FlowNodeRunner {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
log.info("run node id: {}", getNodeId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlainOptionNode extends FlowNodeOptionalRunner {
|
||||||
|
@Override
|
||||||
|
public String runOptional() {
|
||||||
|
log.info("run node id: {}", getNodeId());
|
||||||
|
// yes / no
|
||||||
|
return "no";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,15 @@ package com.lanyuanxiaoyao.service.configuration;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring Security Config
|
* Spring Security Config
|
||||||
@@ -25,6 +29,19 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
this.securityProperties = securityProperties;
|
this.securityProperties = securityProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
CorsConfiguration configuration = new CorsConfiguration();
|
||||||
|
configuration.setAllowCredentials(true);
|
||||||
|
configuration.addAllowedOriginPattern("*");
|
||||||
|
configuration.addAllowedHeader("*");
|
||||||
|
configuration.addAllowedMethod("*");
|
||||||
|
configuration.setMaxAge(7200L);
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", configuration);
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
http.authorizeHttpRequests()
|
http.authorizeHttpRequests()
|
||||||
@@ -36,7 +53,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.csrf()
|
.csrf()
|
||||||
.disable()
|
.disable()
|
||||||
.cors()
|
.cors()
|
||||||
.disable()
|
.and()
|
||||||
.formLogin()
|
.formLogin()
|
||||||
.disable();
|
.disable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.springframework.security.core.userdetails.User;
|
|||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.cors.reactive.CorsConfigurationSource;
|
import org.springframework.web.cors.reactive.CorsWebFilter;
|
||||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,24 +33,12 @@ public class SecurityConfiguration {
|
|||||||
.httpBasic()
|
.httpBasic()
|
||||||
.disable()
|
.disable()
|
||||||
.cors()
|
.cors()
|
||||||
.configurationSource(corsConfigurationSource())
|
.disable()
|
||||||
.and()
|
|
||||||
.csrf()
|
.csrf()
|
||||||
.disable()
|
.disable()
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CorsConfigurationSource corsConfigurationSource() {
|
|
||||||
CorsConfiguration configuration = new CorsConfiguration();
|
|
||||||
configuration.setAllowCredentials(true);
|
|
||||||
configuration.addAllowedHeader("*");
|
|
||||||
configuration.addAllowedMethod("*");
|
|
||||||
configuration.addAllowedOriginPattern("*");
|
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
||||||
source.registerCorsConfiguration("/**", configuration);
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MapReactiveUserDetailsService userDetailsService(SecurityProperties securityProperties) {
|
public MapReactiveUserDetailsService userDetailsService(SecurityProperties securityProperties) {
|
||||||
UserDetails user = User.builder()
|
UserDetails user = User.builder()
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"test": "vitest run"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^6.0.0",
|
"@ant-design/icons": "^6.0.0",
|
||||||
@@ -14,33 +15,34 @@
|
|||||||
"@ant-design/x": "^1.4.0",
|
"@ant-design/x": "^1.4.0",
|
||||||
"@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.21",
|
||||||
"@tinyflow-ai/react": "^0.2.1",
|
"@xyflow/react": "^12.8.2",
|
||||||
"ahooks": "^3.8.5",
|
"ahooks": "^3.9.0",
|
||||||
"amis": "^6.12.0",
|
"amis": "^6.12.0",
|
||||||
"antd": "^5.26.1",
|
"antd": "^5.26.4",
|
||||||
"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.8.1",
|
||||||
"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.3",
|
||||||
"styled-components": "^6.1.18"
|
"styled-components": "^6.1.19",
|
||||||
|
"yocto-queue": "^1.2.1",
|
||||||
|
"zustand": "^5.0.6"
|
||||||
},
|
},
|
||||||
"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.3.0",
|
||||||
"sass": "^1.89.2",
|
"sass": "^1.89.2",
|
||||||
"typescript": "~5.8.3",
|
"typescript": "~5.8.3",
|
||||||
"vite": "^6.3.5",
|
"vite": "^7.0.4",
|
||||||
"vite-plugin-javascript-obfuscator": "^3.1.0"
|
"vite-plugin-javascript-obfuscator": "^3.1.0",
|
||||||
|
"vitest": "^3.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1210
service-web/client/pnpm-lock.yaml
generated
1210
service-web/client/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
62
service-web/client/src/components/flow/FlowChecker.test.tsx
Normal file
62
service-web/client/src/components/flow/FlowChecker.test.tsx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import {type Connection, type Node} from '@xyflow/react'
|
||||||
|
import {expect, test} from 'vitest'
|
||||||
|
import {
|
||||||
|
checkAddConnection,
|
||||||
|
hasCycleError,
|
||||||
|
nodeToSelfError,
|
||||||
|
sourceNodeNotFoundError,
|
||||||
|
targetNodeNotFoundError,
|
||||||
|
} from './FlowChecker.tsx'
|
||||||
|
|
||||||
|
const createNode = (id: string, type: string): Node => {
|
||||||
|
return {
|
||||||
|
data: {},
|
||||||
|
position: {
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
},
|
||||||
|
id,
|
||||||
|
type,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createConnection = function (source: string, target: string, sourceHandle: string | null = null, targetHandle: string | null = null): Connection {
|
||||||
|
return {
|
||||||
|
source,
|
||||||
|
target,
|
||||||
|
sourceHandle,
|
||||||
|
targetHandle,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check add connection */
|
||||||
|
test(sourceNodeNotFoundError().message, () => {
|
||||||
|
expect(() => checkAddConnection(createConnection('a', 'b'), [], []))
|
||||||
|
})
|
||||||
|
|
||||||
|
test(targetNodeNotFoundError().message, () => {
|
||||||
|
expect(() => checkAddConnection(createConnection('a', 'b'), [createNode('a', 'normal-node')], []))
|
||||||
|
})
|
||||||
|
|
||||||
|
test(nodeToSelfError().message, () => {
|
||||||
|
expect(() => {
|
||||||
|
// language=JSON
|
||||||
|
const {
|
||||||
|
nodes,
|
||||||
|
edges
|
||||||
|
} = JSON.parse('{\n "nodes": [\n {\n "id": "P14abHl4uY",\n "type": "start-node",\n "position": {\n "x": 100,\n "y": 100\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 82\n }\n },\n {\n "id": "3YDRebKqCX",\n "type": "end-node",\n "position": {\n "x": 773.3027344262372,\n "y": 101.42648884412338\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 74\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "YXJ91nHVaz",\n "type": "llm-node",\n "position": {\n "x": 430.94541183662506,\n "y": 101.42648884412338\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 74\n },\n "selected": true,\n "dragging": false\n }\n ],\n "edges": [\n {\n "source": "P14abHl4uY",\n "target": "YXJ91nHVaz",\n "id": "xy-edge__P14abHl4uY-YXJ91nHVaz"\n },\n {\n "source": "YXJ91nHVaz",\n "target": "3YDRebKqCX",\n "id": "xy-edge__YXJ91nHVaz-3YDRebKqCX"\n }\n ],\n "data": {}\n}')
|
||||||
|
checkAddConnection(createConnection('YXJ91nHVaz', 'YXJ91nHVaz'), nodes, edges)
|
||||||
|
}).toThrowError(nodeToSelfError())
|
||||||
|
})
|
||||||
|
|
||||||
|
test(hasCycleError().message, () => {
|
||||||
|
expect(() => {
|
||||||
|
// language=JSON
|
||||||
|
const {
|
||||||
|
nodes,
|
||||||
|
edges,
|
||||||
|
} = JSON.parse('{\n "nodes": [\n {\n "id": "-DKfXm7r3f",\n "type": "start-node",\n "position": {\n "x": -75.45812782717618,\n "y": 14.410669352596976\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 82\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "2uL3Hw2CAW",\n "type": "end-node",\n "position": {\n "x": 734.7875356349059,\n "y": -1.2807079327602473\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 74\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "yp-yYfKUzC",\n "type": "llm-node",\n "position": {\n "x": 338.2236369686051,\n "y": -92.5759939566568\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 74\n },\n "selected": false,\n "dragging": false\n },\n {\n "id": "N4HQPN-NYZ",\n "type": "llm-node",\n "position": {\n "x": 332.51768159211156,\n "y": 114.26488844123382\n },\n "data": {},\n "measured": {\n "width": 256,\n "height": 74\n },\n "selected": true,\n "dragging": false\n }\n ],\n "edges": [\n {\n "source": "-DKfXm7r3f",\n "target": "yp-yYfKUzC",\n "id": "xy-edge__-DKfXm7r3f-yp-yYfKUzC"\n },\n {\n "source": "yp-yYfKUzC",\n "target": "2uL3Hw2CAW",\n "id": "xy-edge__yp-yYfKUzC-2uL3Hw2CAW"\n },\n {\n "source": "-DKfXm7r3f",\n "target": "N4HQPN-NYZ",\n "id": "xy-edge__-DKfXm7r3f-N4HQPN-NYZ"\n },\n {\n "source": "N4HQPN-NYZ",\n "target": "yp-yYfKUzC",\n "id": "xy-edge__N4HQPN-NYZ-yp-yYfKUzC"\n }\n ],\n "data": {}\n}')
|
||||||
|
// language=JSON
|
||||||
|
checkAddConnection(JSON.parse('{\n "source": "yp-yYfKUzC",\n "sourceHandle": null,\n "target": "N4HQPN-NYZ",\n "targetHandle": null\n}'), nodes, edges)
|
||||||
|
}).toThrowError(hasCycleError())
|
||||||
|
})
|
||||||
111
service-web/client/src/components/flow/FlowChecker.tsx
Normal file
111
service-web/client/src/components/flow/FlowChecker.tsx
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import {type Connection, type Edge, getOutgoers, type Node} from '@xyflow/react'
|
||||||
|
import {find, has, isEmpty, isEqual, lpad, toStr} from 'licia'
|
||||||
|
import {NodeRegistryMap} from './NodeRegistry.tsx'
|
||||||
|
|
||||||
|
export class CheckError extends Error {
|
||||||
|
readonly id: string
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
id: number,
|
||||||
|
message: string,
|
||||||
|
) {
|
||||||
|
super(message)
|
||||||
|
this.id = `E${lpad(toStr(id), 6, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
public toString(): string {
|
||||||
|
return `${this.id}: ${this.message}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getNodeById = (id: string, nodes: Node[]) => find(nodes, (n: Node) => isEqual(n.id, id))
|
||||||
|
|
||||||
|
export const typeNotFound = (type: string) => new CheckError(100, `类型 ${type} 不存在`)
|
||||||
|
export const addNodeError = (message?: string) => new CheckError(101, message ?? '无法添加节点')
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
export const checkAddNode: (type: string, parentId: string | undefined, nodes: Node[], edges: Edge[]) => void = (type, parentId, nodes, edges) => {
|
||||||
|
let nodeDefine = NodeRegistryMap[type]
|
||||||
|
if (!nodeDefine) {
|
||||||
|
throw typeNotFound(type)
|
||||||
|
}
|
||||||
|
for (const checker of nodeDefine.checkers.add) {
|
||||||
|
let checkResult = checker(type, parentId, nodes, edges, undefined)
|
||||||
|
if (checkResult.error) {
|
||||||
|
throw addNodeError(checkResult.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const sourceNodeNotFoundError = () => new CheckError(200, '连线起始节点未找到')
|
||||||
|
export const targetNodeNotFoundError = () => new CheckError(201, '连线目标节点未找到')
|
||||||
|
export const nodeToSelfError = () => new CheckError(203, '节点不能直连自身')
|
||||||
|
export const hasCycleError = () => new CheckError(204, '禁止流程循环')
|
||||||
|
export const differentParent = () => new CheckError(205, '子流程禁止连接外部节点')
|
||||||
|
|
||||||
|
const hasCycle = (sourceNode: Node, targetNode: Node, nodes: Node[], edges: Edge[], visited = new Set<string>()) => {
|
||||||
|
if (visited.has(targetNode.id)) return false
|
||||||
|
visited.add(targetNode.id)
|
||||||
|
for (const outgoer of getOutgoers(targetNode, nodes, edges)) {
|
||||||
|
if (isEqual(outgoer.id, sourceNode.id)) return true
|
||||||
|
if (hasCycle(sourceNode, outgoer, nodes, edges, visited)) return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const checkAddConnection: (connection: Connection, nodes: Node[], edges: Edge[]) => void = (connection, nodes, edges) => {
|
||||||
|
let sourceNode = getNodeById(connection.source, nodes)
|
||||||
|
if (!sourceNode) {
|
||||||
|
throw sourceNodeNotFoundError()
|
||||||
|
}
|
||||||
|
let targetNode = getNodeById(connection.target, nodes)
|
||||||
|
if (!targetNode) {
|
||||||
|
throw targetNodeNotFoundError()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEqual(sourceNode.parentId, targetNode.parentId)) {
|
||||||
|
throw differentParent()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 禁止流程出现环,必须是有向无环图
|
||||||
|
if (isEqual(sourceNode.id, targetNode.id)) {
|
||||||
|
throw nodeToSelfError()
|
||||||
|
} else if (hasCycle(sourceNode, targetNode, nodes, edges)) {
|
||||||
|
throw hasCycleError()
|
||||||
|
}
|
||||||
|
|
||||||
|
// let newEdges = [...clone(edges), {...connection, id: uuid()}]
|
||||||
|
// let {hasAbnormalEdges} = getParallelInfo(nodes, newEdges)
|
||||||
|
// if (hasAbnormalEdges) {
|
||||||
|
// throw hasRedundantEdgeError()
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
export const atLeastOneNode = () => new CheckError(300, '至少包含一个节点')
|
||||||
|
export const hasUnfinishedNode = (nodeId: string) => new CheckError(301, `存在尚未配置完成的节点: ${nodeId}`)
|
||||||
|
export const nodeTypeNotFound = () => new CheckError(302, '节点类型不存在')
|
||||||
|
export const saveNodeError = (nodeId: string, reason?: string) => new CheckError(303, reason ?? `节点配置存在错误:${nodeId}`)
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
export const checkSave: (nodes: Node[], edges: Edge[], data: any) => void = (nodes, edges, data) => {
|
||||||
|
if (isEmpty(nodes)) {
|
||||||
|
throw atLeastOneNode()
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let node of nodes) {
|
||||||
|
if (!has(data, node.id) || !data[node.id]?.finished) {
|
||||||
|
throw hasUnfinishedNode(node.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has(node, 'type')) {
|
||||||
|
throw nodeTypeNotFound()
|
||||||
|
}
|
||||||
|
let nodeType = node.type!
|
||||||
|
let nodeDefine = NodeRegistryMap[nodeType]
|
||||||
|
for (let checker of nodeDefine.checkers.save) {
|
||||||
|
let checkResult = checker(node.id, node.parentId, nodes, edges, data)
|
||||||
|
if (checkResult.error) {
|
||||||
|
throw saveNodeError(node.id, checkResult.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
151
service-web/client/src/components/flow/FlowEditor.tsx
Normal file
151
service-web/client/src/components/flow/FlowEditor.tsx
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
import {RollbackOutlined, SaveFilled} from '@ant-design/icons'
|
||||||
|
import {Background, BackgroundVariant, Controls, MiniMap, Panel, ReactFlow} from '@xyflow/react'
|
||||||
|
import {Button, message, Popconfirm, Space} from 'antd'
|
||||||
|
import {arrToMap} from 'licia'
|
||||||
|
import {useEffect} from 'react'
|
||||||
|
import {useNavigate} from 'react-router'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import '@xyflow/react/dist/style.css'
|
||||||
|
import {commonInfo} from '../../util/amis.tsx'
|
||||||
|
import AddNodeButton from './component/AddNodeButton.tsx'
|
||||||
|
import {checkAddConnection, checkSave} from './FlowChecker.tsx'
|
||||||
|
import {useNodeDrag} from './Helper.tsx'
|
||||||
|
import {NodeRegistryMap} from './NodeRegistry.tsx'
|
||||||
|
import {useDataStore} from './store/DataStore.ts'
|
||||||
|
import {useFlowStore} from './store/FlowStore.ts'
|
||||||
|
import {flowDotColor, type FlowEditorProps} from './types.ts'
|
||||||
|
|
||||||
|
const FlowableDiv = styled.div`
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.node-card {
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
|
.card-container {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
function FlowEditor(props: FlowEditorProps) {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
const {data, setData} = useDataStore()
|
||||||
|
const {
|
||||||
|
nodes,
|
||||||
|
setNodes,
|
||||||
|
onNodesChange,
|
||||||
|
edges,
|
||||||
|
setEdges,
|
||||||
|
onEdgesChange,
|
||||||
|
onConnect,
|
||||||
|
} = useFlowStore()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// language=JSON
|
||||||
|
// let initialData = JSON.parse('{"nodes":[{"id":"TCxPixrdkI","type":"start-node","position":{"x":-256,"y":109.5},"data":{},"measured":{"width":256,"height":83},"selected":false,"dragging":false},{"id":"tGs78_ietp","type":"llm-node","position":{"x":108,"y":-2.5},"data":{},"measured":{"width":256,"height":105},"selected":false,"dragging":false},{"id":"OeZdaU7LpY","type":"llm-node","position":{"x":111,"y":196},"data":{},"measured":{"width":256,"height":105},"selected":false,"dragging":false},{"id":"LjfoCYZo-E","type":"knowledge-node","position":{"x":497.62196259607214,"y":-10.792497317791003},"data":{},"measured":{"width":256,"height":75},"selected":false,"dragging":false},{"id":"sQM_22GYB5","type":"end-node","position":{"x":874.3164534765615,"y":151.70316541496913},"data":{},"measured":{"width":256,"height":75},"selected":false,"dragging":false},{"id":"KpMH_xc3ZZ","type":"llm-node","position":{"x":529.6286840434341,"y":150.4721376669937},"data":{},"measured":{"width":256,"height":75},"selected":false,"dragging":false},{"id":"pOrR6EMVbe","type":"switch-node","position":{"x":110.33793030183864,"y":373.9551529987239},"data":{},"measured":{"width":256,"height":157},"selected":false,"dragging":false}],"edges":[{"source":"TCxPixrdkI","sourceHandle":"source","target":"tGs78_ietp","targetHandle":"target","id":"xy-edge__TCxPixrdkIsource-tGs78_ietptarget"},{"source":"TCxPixrdkI","sourceHandle":"source","target":"OeZdaU7LpY","targetHandle":"target","id":"xy-edge__TCxPixrdkIsource-OeZdaU7LpYtarget"},{"source":"tGs78_ietp","sourceHandle":"source","target":"LjfoCYZo-E","targetHandle":"target","id":"xy-edge__tGs78_ietpsource-LjfoCYZo-Etarget"},{"source":"LjfoCYZo-E","sourceHandle":"source","target":"KpMH_xc3ZZ","targetHandle":"target","id":"xy-edge__LjfoCYZo-Esource-KpMH_xc3ZZtarget"},{"source":"OeZdaU7LpY","sourceHandle":"source","target":"KpMH_xc3ZZ","targetHandle":"target","id":"xy-edge__OeZdaU7LpYsource-KpMH_xc3ZZtarget"},{"source":"KpMH_xc3ZZ","sourceHandle":"source","target":"sQM_22GYB5","targetHandle":"target","id":"xy-edge__KpMH_xc3ZZsource-sQM_22GYB5target"},{"source":"TCxPixrdkI","sourceHandle":"source","target":"pOrR6EMVbe","id":"xy-edge__TCxPixrdkIsource-pOrR6EMVbe"},{"source":"pOrR6EMVbe","sourceHandle":"3","target":"sQM_22GYB5","targetHandle":"target","id":"xy-edge__pOrR6EMVbe3-sQM_22GYB5target"},{"source":"pOrR6EMVbe","sourceHandle":"1","target":"KpMH_xc3ZZ","targetHandle":"target","id":"xy-edge__pOrR6EMVbe1-KpMH_xc3ZZtarget"}],"data":{"tGs78_ietp":{"model":"qwen3","outputs":{"text":{"type":"string"}},"systemPrompt":"你是个聪明人"},"OeZdaU7LpY":{"model":"qwen3","outputs":{"text":{"type":"string"}},"systemPrompt":"你也是个聪明人"}}}')
|
||||||
|
// let initialData: any = {}
|
||||||
|
let initialNodes = props.graphData?.nodes ?? []
|
||||||
|
let initialEdges = props.graphData?.edges ?? []
|
||||||
|
|
||||||
|
let initialNodeData = props.graphData?.data ?? {}
|
||||||
|
setData(initialNodeData)
|
||||||
|
setNodes(initialNodes)
|
||||||
|
setEdges(initialEdges)
|
||||||
|
|
||||||
|
}, [props.graphData])
|
||||||
|
|
||||||
|
const {
|
||||||
|
onNodeDragStart,
|
||||||
|
onNodeDrag,
|
||||||
|
onNodeDragEnd,
|
||||||
|
} = useNodeDrag([props.graphData])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlowableDiv className="h-full w-full">
|
||||||
|
<ReactFlow
|
||||||
|
className="rounded-xl"
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onEdgesChange={onEdgesChange}
|
||||||
|
onConnect={(connection) => {
|
||||||
|
try {
|
||||||
|
if (commonInfo.debug) {
|
||||||
|
console.info('Connection', JSON.stringify(connection), JSON.stringify({nodes, edges, data}))
|
||||||
|
}
|
||||||
|
checkAddConnection(connection, nodes, edges)
|
||||||
|
onConnect(connection)
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
message.error(e.toString())
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
// @ts-ignore
|
||||||
|
nodeTypes={arrToMap(Object.keys(NodeRegistryMap), key => NodeRegistryMap[key]!.component)}
|
||||||
|
onNodeDragStart={onNodeDragStart}
|
||||||
|
onNodeDrag={onNodeDrag}
|
||||||
|
onNodeDragStop={onNodeDragEnd}
|
||||||
|
onEdgesDelete={() => console.info('delete')}
|
||||||
|
fitView
|
||||||
|
>
|
||||||
|
<Panel position="top-right">
|
||||||
|
<Space className="toolbar">
|
||||||
|
<AddNodeButton/>
|
||||||
|
<Popconfirm
|
||||||
|
title="返回上一页"
|
||||||
|
description="未保存的流程图将会被丢弃,确认是否返回"
|
||||||
|
onConfirm={() => navigate(-1)}
|
||||||
|
>
|
||||||
|
<Button type="default">
|
||||||
|
<RollbackOutlined/>
|
||||||
|
返回
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
<Button type="primary" onClick={() => {
|
||||||
|
try {
|
||||||
|
if (commonInfo.debug) {
|
||||||
|
console.info('Save', JSON.stringify({nodes, edges, data}))
|
||||||
|
}
|
||||||
|
checkSave(nodes, edges, data)
|
||||||
|
props.onGraphDataChange({nodes, edges, data})
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
message.error(e.toString())
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<SaveFilled/>
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
</Panel>
|
||||||
|
<Controls/>
|
||||||
|
<MiniMap/>
|
||||||
|
<Background
|
||||||
|
variant={BackgroundVariant.Cross}
|
||||||
|
gap={20}
|
||||||
|
size={3}
|
||||||
|
color={flowDotColor}
|
||||||
|
/>
|
||||||
|
</ReactFlow>
|
||||||
|
</FlowableDiv>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowEditor
|
||||||
206
service-web/client/src/components/flow/Helper.tsx
Normal file
206
service-web/client/src/components/flow/Helper.tsx
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
import {type Edge, getIncomers, type Node} from '@xyflow/react'
|
||||||
|
import type {Option} from 'amis/lib/Schema'
|
||||||
|
import {contain, find, has, isEqual, max, min, unique} from 'licia'
|
||||||
|
import {type DependencyList, type MouseEvent as ReactMouseEvent, useCallback, useRef} from 'react'
|
||||||
|
import Queue from 'yocto-queue'
|
||||||
|
import {useFlowStore} from './store/FlowStore.ts'
|
||||||
|
import {type OutputVariable, type OutputVariableType} from './types.ts'
|
||||||
|
|
||||||
|
export const getAllIncomerNodeById: (id: string, nodes: Node[], edges: Edge[]) => string[] = (id, nodes, edges) => {
|
||||||
|
let queue = new Queue<Node>()
|
||||||
|
queue.enqueue(find(nodes, node => isEqual(node.id, id))!)
|
||||||
|
let result: string[] = []
|
||||||
|
while (queue.size !== 0) {
|
||||||
|
let currentNode = queue.dequeue()!
|
||||||
|
for (const incomer of getIncomers(currentNode, nodes, edges)) {
|
||||||
|
result.push(incomer.id)
|
||||||
|
queue.enqueue(incomer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unique(result, (a, b) => isEqual(a, b))
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAllIncomerNodeOutputVariables: (id: string, nodes: Node[], edges: Edge[], data: any) => OutputVariable[] = (id, nodes, edges, data) => {
|
||||||
|
let currentNode = find(nodes, n => isEqual(id, n.id))
|
||||||
|
if (!currentNode) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
let incomerIds = getAllIncomerNodeById(id, nodes, edges)
|
||||||
|
if (currentNode.parentId) {
|
||||||
|
incomerIds = [
|
||||||
|
...incomerIds,
|
||||||
|
...getAllIncomerNodeById(currentNode.parentId, nodes, edges),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
let incomerVariables: OutputVariable[] = []
|
||||||
|
for (const incomerId of incomerIds) {
|
||||||
|
let nodeData = data[incomerId] ?? {}
|
||||||
|
let group = incomerId
|
||||||
|
if (has(nodeData, 'node') && has(nodeData.node, 'name')) {
|
||||||
|
group = `${nodeData.node.name} ${incomerId}`
|
||||||
|
}
|
||||||
|
if (has(nodeData, 'outputs')) {
|
||||||
|
let outputs = nodeData?.outputs ?? {}
|
||||||
|
for (const key of Object.keys(outputs)) {
|
||||||
|
incomerVariables.push({
|
||||||
|
group: group,
|
||||||
|
name: key,
|
||||||
|
type: outputs[key].type,
|
||||||
|
variable: `${incomerId}.${key}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
...(currentNode.parentId ? [
|
||||||
|
{
|
||||||
|
group: '循环入参',
|
||||||
|
name: 'loopIndex (当前迭代索引)',
|
||||||
|
type: 'number',
|
||||||
|
variable: 'loopIndex',
|
||||||
|
} as OutputVariable,
|
||||||
|
{
|
||||||
|
group: '循环入参',
|
||||||
|
name: 'loopItem (当前迭代对象)',
|
||||||
|
type: 'object',
|
||||||
|
variable: 'loopItem',
|
||||||
|
} as OutputVariable,
|
||||||
|
] : []),
|
||||||
|
...incomerVariables,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateAllIncomerOutputVariablesFormOptions: (id: string, nodes: Node[], edges: Edge[], data: any, targetTypes?: OutputVariableType[]) => Option[] = (id, nodes, edges, data, targetTypes) => {
|
||||||
|
let optionMap: Record<string, Option[]> = {}
|
||||||
|
for (const item of getAllIncomerNodeOutputVariables(id, nodes, edges, data)) {
|
||||||
|
if (targetTypes && !contain(targetTypes, item.type)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (!optionMap[item.group]) {
|
||||||
|
optionMap[item.group] = []
|
||||||
|
}
|
||||||
|
optionMap[item.group].push({
|
||||||
|
label: item.name,
|
||||||
|
value: item.variable,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Object.keys(optionMap)
|
||||||
|
.map(key => ({
|
||||||
|
label: key,
|
||||||
|
children: optionMap[key],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConditionOperator = string | { label: string, value: string }
|
||||||
|
const textOperators: ConditionOperator[] = ['equal', 'not_equal', 'is_empty', 'is_not_empty', 'like', 'not_like', 'starts_with', 'ends_with']
|
||||||
|
const textDefaultOperator: string = 'equal'
|
||||||
|
const booleanOperators: ConditionOperator[] = ['equal', 'not_equal']
|
||||||
|
const booleanDefaultOperator: string = 'equal'
|
||||||
|
const numberOperators: ConditionOperator[] = [
|
||||||
|
'equal',
|
||||||
|
'not_equal',
|
||||||
|
{label: '大于', value: 'greater'},
|
||||||
|
{label: '大于或等于', value: 'greater_equal'},
|
||||||
|
{label: '小于', value: 'less'},
|
||||||
|
{label: '小于或等于', value: 'less_equal'},
|
||||||
|
]
|
||||||
|
const numberDefaultOperator: string = 'equal'
|
||||||
|
const arrayOperators: ConditionOperator[] = ['is_empty', 'is_not_empty']
|
||||||
|
const arrayDefaultOperator: string = 'is_empty'
|
||||||
|
|
||||||
|
export const generateAllIncomerOutputVariablesConditions: (id: string, nodes: Node[], edges: Edge[], data: any) => Option[] = (id, nodes, edges, data) => {
|
||||||
|
let optionMap: Record<string, Option[]> = {}
|
||||||
|
for (const item of getAllIncomerNodeOutputVariables(id, nodes, edges, data)) {
|
||||||
|
if (!optionMap[item.group]) {
|
||||||
|
optionMap[item.group] = []
|
||||||
|
}
|
||||||
|
optionMap[item.group].push({
|
||||||
|
label: item.name,
|
||||||
|
type: 'custom',
|
||||||
|
name: item.variable,
|
||||||
|
...(item.type === 'text' ? {
|
||||||
|
value: {
|
||||||
|
type: 'input-text',
|
||||||
|
required: true,
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
defaultOp: textDefaultOperator,
|
||||||
|
operators: textOperators,
|
||||||
|
} : {}),
|
||||||
|
...(item.type === 'boolean' ? {
|
||||||
|
value: {
|
||||||
|
type: 'select',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: [
|
||||||
|
{label: '真', value: true},
|
||||||
|
{label: '假', value: false},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
defaultOp: booleanDefaultOperator,
|
||||||
|
operators: booleanOperators,
|
||||||
|
} : {}),
|
||||||
|
...(item.type === 'number' ? {
|
||||||
|
value: {
|
||||||
|
type: 'input-number',
|
||||||
|
required: true,
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
defaultOp: numberDefaultOperator,
|
||||||
|
operators: numberOperators,
|
||||||
|
} : {}),
|
||||||
|
...((item.type === 'array-text' || item.type === 'array-object') ? {
|
||||||
|
defaultOp: arrayDefaultOperator,
|
||||||
|
operators: arrayOperators,
|
||||||
|
} : {}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return Object.keys(optionMap)
|
||||||
|
.map(key => ({
|
||||||
|
label: key,
|
||||||
|
children: optionMap[key],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理循环节点的边界问题
|
||||||
|
export const useNodeDrag = (deps: DependencyList) => {
|
||||||
|
const currentPosition = useRef({x: 0, y: 0} as { x: number, y: number })
|
||||||
|
const {setNode, getNodeById} = useFlowStore()
|
||||||
|
|
||||||
|
const onNodeDragStart = useCallback(() => {
|
||||||
|
}, deps)
|
||||||
|
const onNodeDrag = useCallback((event: ReactMouseEvent, node: Node) => {
|
||||||
|
event.stopPropagation()
|
||||||
|
if (node.parentId) {
|
||||||
|
let parentNode = getNodeById(node.parentId)
|
||||||
|
if (parentNode) {
|
||||||
|
let newPosition = {
|
||||||
|
x: max(min(node.position.x, (parentNode.measured?.width ?? 0) - (node.measured?.width ?? 0) - 28), 28),
|
||||||
|
y: max(min(node.position.y, (parentNode.measured?.height ?? 0) - (node.measured?.height ?? 0) - 28), 130),
|
||||||
|
}
|
||||||
|
setNode({
|
||||||
|
...node,
|
||||||
|
position: newPosition,
|
||||||
|
})
|
||||||
|
currentPosition.current = newPosition
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, deps)
|
||||||
|
const onNodeDragEnd = useCallback((_event: ReactMouseEvent, node: Node) => {
|
||||||
|
if (node.parentId) {
|
||||||
|
setNode({
|
||||||
|
...node,
|
||||||
|
position: currentPosition.current,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, deps)
|
||||||
|
|
||||||
|
return {
|
||||||
|
onNodeDragStart,
|
||||||
|
onNodeDrag,
|
||||||
|
onNodeDragEnd,
|
||||||
|
}
|
||||||
|
}
|
||||||
159
service-web/client/src/components/flow/NodeRegistry.tsx
Normal file
159
service-web/client/src/components/flow/NodeRegistry.tsx
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
import {has, isEmpty, isEqual} from 'licia'
|
||||||
|
import {getAllIncomerNodeOutputVariables} from './Helper.tsx'
|
||||||
|
import CodeNode from './node/CodeNode.tsx'
|
||||||
|
import KnowledgeNode from './node/KnowledgeNode.tsx'
|
||||||
|
import LlmNode from './node/LlmNode.tsx'
|
||||||
|
import LoopNode from './node/LoopNode.tsx'
|
||||||
|
import OutputNode from './node/OutputNode.tsx'
|
||||||
|
import SwitchNode from './node/SwitchNode.tsx'
|
||||||
|
import TemplateNode from './node/TemplateNode.tsx'
|
||||||
|
import type {AddNodeChecker, NodeDefine, SaveNodeChecker} from './types.ts'
|
||||||
|
import InputNode from './node/InputNode.tsx'
|
||||||
|
|
||||||
|
const inputSingleVariableChecker: (field: string) => SaveNodeChecker = field => {
|
||||||
|
return (id, _parentId, nodes, edges, data) => {
|
||||||
|
let nodeData = data[id] ?? {}
|
||||||
|
if (has(nodeData, field)) {
|
||||||
|
let expression = nodeData?.[field] ?? ''
|
||||||
|
if (!isEmpty(expression)) {
|
||||||
|
let outputVariables = new Set(getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => i.variable))
|
||||||
|
if (!outputVariables.has(expression)) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: `节点 ${id} 存在错误:变量 ${expression} 不存在`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {error: false}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputMultiVariableChecker: SaveNodeChecker = (id, _parentId, nodes, edges, data) => {
|
||||||
|
let nodeData = data[id] ?? {}
|
||||||
|
if (has(nodeData, 'inputs')) {
|
||||||
|
let inputs = nodeData?.inputs ?? {}
|
||||||
|
if (!isEmpty(inputs)) {
|
||||||
|
let outputVariables = new Set(getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => i.variable))
|
||||||
|
for (const key of Object.keys(inputs)) {
|
||||||
|
let variable = inputs[key]?.variable ?? ''
|
||||||
|
if (!outputVariables.has(variable)) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: `节点 ${id} 存在错误:变量 ${variable} 不存在`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {error: false}
|
||||||
|
}
|
||||||
|
|
||||||
|
const noMoreThanOneNodeType: AddNodeChecker = (type, parentId, nodes) => {
|
||||||
|
return {
|
||||||
|
error: nodes.filter(n => isEqual(n.parentId, parentId) && isEqual(n.type, type)).length > 0,
|
||||||
|
message: `同一个流程(子流程)中类型为 ${type} 的节点至多有一个`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NodeRegistry: NodeDefine[] = [
|
||||||
|
{
|
||||||
|
key: 'llm-node',
|
||||||
|
group: '普通节点',
|
||||||
|
name: '大模型',
|
||||||
|
icon: <i className="fa fa-message"/>,
|
||||||
|
description: '使用大模型对话',
|
||||||
|
component: LlmNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [inputMultiVariableChecker]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'knowledge-node',
|
||||||
|
group: '普通节点',
|
||||||
|
name: '知识库',
|
||||||
|
icon: <i className="fa fa-book-bookmark"/>,
|
||||||
|
description: '',
|
||||||
|
component: KnowledgeNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [inputMultiVariableChecker]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'code-node',
|
||||||
|
group: '普通节点',
|
||||||
|
name: '代码执行',
|
||||||
|
icon: <i className="fa fa-code"/>,
|
||||||
|
description: '执行自定义的处理代码',
|
||||||
|
component: CodeNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [inputMultiVariableChecker]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'template-node',
|
||||||
|
group: '普通节点',
|
||||||
|
name: '模板替换',
|
||||||
|
icon: <i className="fa fa-pen-nib"/>,
|
||||||
|
description: '使用模板聚合转换变量表示',
|
||||||
|
component: TemplateNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [inputMultiVariableChecker]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'switch-node',
|
||||||
|
group: '逻辑节点',
|
||||||
|
name: '分支',
|
||||||
|
icon: <i className="fa fa-code-fork"/>,
|
||||||
|
description: '根据不同的情况前往不同的分支',
|
||||||
|
component: SwitchNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'loop-node',
|
||||||
|
group: '逻辑节点',
|
||||||
|
name: '循环',
|
||||||
|
icon: <i className="fa fa-repeat"/>,
|
||||||
|
description: '实现循环执行流程',
|
||||||
|
component: LoopNode,
|
||||||
|
checkers: {
|
||||||
|
add: [],
|
||||||
|
save: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// 特殊节点特殊判断
|
||||||
|
{
|
||||||
|
key: 'input-node',
|
||||||
|
group: '数据节点',
|
||||||
|
name: '输入',
|
||||||
|
icon: <i className="fa fa-file"/>,
|
||||||
|
description: '定义流程输入变量',
|
||||||
|
component: InputNode,
|
||||||
|
checkers: {
|
||||||
|
add: [noMoreThanOneNodeType],
|
||||||
|
save: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'output-node',
|
||||||
|
group: '数据节点',
|
||||||
|
name: '输出',
|
||||||
|
icon: <i className="fa fa-file"/>,
|
||||||
|
description: '定义流程输出变量',
|
||||||
|
component: OutputNode,
|
||||||
|
checkers: {
|
||||||
|
add: [noMoreThanOneNodeType],
|
||||||
|
save: [inputSingleVariableChecker('output')]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const NodeRegistryMap: Record<string, NodeDefine> = NodeRegistry.reduce((a, v) => ({...a, [v.key]: v}), {})
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import {PlusCircleFilled} from '@ant-design/icons'
|
||||||
|
import {Button, Dropdown, message} from 'antd'
|
||||||
|
import type {ButtonProps} from 'antd/lib'
|
||||||
|
import {isEqual, randomId, unique} from 'licia'
|
||||||
|
import {commonInfo} from '../../../util/amis.tsx'
|
||||||
|
import {checkAddNode} from '../FlowChecker.tsx'
|
||||||
|
import {NodeRegistry, NodeRegistryMap} from '../NodeRegistry.tsx'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
|
||||||
|
export type AddNodeButtonProps = ButtonProps & {
|
||||||
|
parent?: string
|
||||||
|
onlyIcon?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const AddNodeButton = (props: AddNodeButtonProps) => {
|
||||||
|
const {data, setDataById} = useDataStore()
|
||||||
|
const {nodes, addNode, edges} = useFlowStore()
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
menu={{
|
||||||
|
items: unique(NodeRegistry.map(i => i.group))
|
||||||
|
.map(group => ({
|
||||||
|
type: 'group',
|
||||||
|
label: group,
|
||||||
|
children: NodeRegistry
|
||||||
|
.filter(i => isEqual(group, i.group))
|
||||||
|
// 循环节点里不能再嵌套循环节点
|
||||||
|
.filter(i => !props.parent || (props.parent && !isEqual(i.key, 'loop-node')))
|
||||||
|
.map(i => ({key: i.key, label: i.name, icon: i.icon})),
|
||||||
|
})),
|
||||||
|
onClick: ({key}) => {
|
||||||
|
try {
|
||||||
|
if (commonInfo.debug) {
|
||||||
|
console.info('Add', key, JSON.stringify({nodes, edges, data}))
|
||||||
|
}
|
||||||
|
checkAddNode(key, props.parent, nodes, edges)
|
||||||
|
|
||||||
|
let nodeId = randomId(10, 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM')
|
||||||
|
let define = NodeRegistryMap[key]
|
||||||
|
|
||||||
|
setDataById(
|
||||||
|
nodeId,
|
||||||
|
{
|
||||||
|
node: {
|
||||||
|
name: define.name,
|
||||||
|
description: define.description,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
addNode({
|
||||||
|
id: nodeId,
|
||||||
|
type: key,
|
||||||
|
position: {x: 50, y: 130},
|
||||||
|
data: {},
|
||||||
|
// 如果是循环节点就将节点加入到循环节点中
|
||||||
|
...(props.parent ? {
|
||||||
|
parentId: props.parent,
|
||||||
|
extent: 'parent',
|
||||||
|
} : {}),
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
message.error(e.toString())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button {...props}>
|
||||||
|
<PlusCircleFilled/>
|
||||||
|
{props.onlyIcon ? undefined : '新增节点'}
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AddNodeButton
|
||||||
298
service-web/client/src/components/flow/node/AmisNode.tsx
Normal file
298
service-web/client/src/components/flow/node/AmisNode.tsx
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
import {CopyFilled, DeleteFilled, EditFilled} from '@ant-design/icons'
|
||||||
|
import {type Edge, Handle, type Node, type NodeProps, NodeResizeControl, NodeToolbar, Position} from '@xyflow/react'
|
||||||
|
import {type ClassName, classnames, type Schema} from 'amis'
|
||||||
|
import {Button, Drawer, Space, Tooltip} from 'antd'
|
||||||
|
import {type CSSProperties, type JSX, useCallback, useState} from 'react'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
|
import {generateAllIncomerOutputVariablesFormOptions} from '../Helper.tsx'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import {type FormSchema, OutputVariableTypeMap} from '../types.ts'
|
||||||
|
|
||||||
|
export function inputsFormColumns(
|
||||||
|
nodeId: string,
|
||||||
|
nodes: Node[],
|
||||||
|
edges: Edge[],
|
||||||
|
data: any,
|
||||||
|
): Schema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'inputs',
|
||||||
|
label: '输入变量',
|
||||||
|
addButtonText: '新增输入',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
label: '参数名称',
|
||||||
|
},
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'variable',
|
||||||
|
label: '变量',
|
||||||
|
required: true,
|
||||||
|
selectMode: 'group',
|
||||||
|
options: generateAllIncomerOutputVariablesFormOptions(
|
||||||
|
nodeId,
|
||||||
|
nodes,
|
||||||
|
edges,
|
||||||
|
data,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function outputsFormColumns(editable: boolean = false, required: boolean = false): Schema[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
disabled: !editable,
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'outputs',
|
||||||
|
label: '输出变量',
|
||||||
|
addButtonText: '新增输出',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
label: '参数名称',
|
||||||
|
},
|
||||||
|
required: required,
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '参数',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(OutputVariableTypeMap).map(key => ({
|
||||||
|
// @ts-ignore
|
||||||
|
label: OutputVariableTypeMap[key],
|
||||||
|
value: key,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
type AmisNodeProps = {
|
||||||
|
className: ClassName,
|
||||||
|
style?: CSSProperties,
|
||||||
|
nodeProps: NodeProps
|
||||||
|
extraNodeDescription?: JSX.Element
|
||||||
|
handler: JSX.Element
|
||||||
|
formSchema?: () => FormSchema,
|
||||||
|
resize?: { minWidth: number, minHeight: number }
|
||||||
|
}
|
||||||
|
|
||||||
|
const AmisNodeContainerDiv = styled.div`
|
||||||
|
`
|
||||||
|
|
||||||
|
export const StartNodeHandler = () => {
|
||||||
|
return <Handle type="source" position={Position.Right} id="source"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EndNodeHandler = () => {
|
||||||
|
return <Handle type="target" position={Position.Left} id="target"/>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NormalNodeHandler = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<StartNodeHandler/>
|
||||||
|
<EndNodeHandler/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const nodeClassName = (name: string) => {
|
||||||
|
return `flow-node flow-node-${name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
nodeProps,
|
||||||
|
extraNodeDescription,
|
||||||
|
handler,
|
||||||
|
formSchema,
|
||||||
|
resize,
|
||||||
|
}) => {
|
||||||
|
const {removeNode} = useFlowStore()
|
||||||
|
const {getDataById, setDataById, removeDataById} = useDataStore()
|
||||||
|
const {id} = nodeProps
|
||||||
|
// @ts-ignore
|
||||||
|
const nodeData = getDataById(id)
|
||||||
|
const nodeName = nodeData?.node?.name ?? ''
|
||||||
|
const nodeDescription = nodeData?.node?.description ?? ''
|
||||||
|
|
||||||
|
const [editDrawerOpen, setEditDrawerOpen] = useState(false)
|
||||||
|
const [editDrawerForm, setEditDrawerForm] = useState<JSX.Element>(<></>)
|
||||||
|
const onOpenEditDrawerClick = useCallback(() => {
|
||||||
|
const schema = formSchema?.()
|
||||||
|
setEditDrawerForm(
|
||||||
|
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,
|
||||||
|
finished: true,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
setEditDrawerOpen(false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
...(schema?.events ?? {})
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'node.name',
|
||||||
|
label: '节点名称',
|
||||||
|
placeholder: nodeName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'node.description',
|
||||||
|
label: '节点描述',
|
||||||
|
placeholder: nodeDescription,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...(schema?.columns ?? []),
|
||||||
|
{
|
||||||
|
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) => {
|
||||||
|
setEditDrawerOpen(false)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'submit',
|
||||||
|
label: '保存',
|
||||||
|
level: 'primary',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
getDataById(id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
setEditDrawerOpen(true)
|
||||||
|
}, [id])
|
||||||
|
const onRemoveClick = useCallback(() => {
|
||||||
|
removeNode(id)
|
||||||
|
removeDataById(id)
|
||||||
|
}, [])
|
||||||
|
return (
|
||||||
|
<AmisNodeContainerDiv className={classnames(className, 'w-64')} style={style}>
|
||||||
|
<Drawer
|
||||||
|
title="节点编辑"
|
||||||
|
open={editDrawerOpen}
|
||||||
|
closeIcon={false}
|
||||||
|
maskClosable={false}
|
||||||
|
destroyOnHidden
|
||||||
|
size="large"
|
||||||
|
>
|
||||||
|
{editDrawerForm}
|
||||||
|
</Drawer>
|
||||||
|
<NodeToolbar>
|
||||||
|
<Space>
|
||||||
|
<Tooltip title="复制节点">
|
||||||
|
<Button
|
||||||
|
className="text-secondary"
|
||||||
|
disabled
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<CopyFilled/>}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="编辑节点">
|
||||||
|
<Button
|
||||||
|
className="text-secondary"
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<EditFilled/>}
|
||||||
|
onClick={() => onOpenEditDrawerClick()}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="删除节点">
|
||||||
|
<Button
|
||||||
|
className="text-secondary"
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<DeleteFilled/>}
|
||||||
|
onClick={() => onRemoveClick()}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
</NodeToolbar>
|
||||||
|
<div className="node-card h-full flex flex-col bg-white rounded-md border border-gray-100 border-solid">
|
||||||
|
<div
|
||||||
|
className="node-card-header items-center flex justify-between p-2 border-t-0 border-l-0 border-r-0 border-b border-gray-100 border-solid">
|
||||||
|
<span className="font-bold">{nodeName}</span>
|
||||||
|
<span className="text-gray-300 text-sm">{id}</span>
|
||||||
|
</div>
|
||||||
|
<div className="node-card-description flex flex-col flex-1 p-2 text-secondary text-sm">
|
||||||
|
<div className="node-card-description-node">
|
||||||
|
{nodeDescription}
|
||||||
|
</div>
|
||||||
|
<div className="node-card-description-extra flex-1 mt-1">
|
||||||
|
{extraNodeDescription}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{resize ? <>
|
||||||
|
<NodeResizeControl
|
||||||
|
minWidth={resize.minWidth}
|
||||||
|
minHeight={resize.minHeight}
|
||||||
|
/>
|
||||||
|
</> : undefined}
|
||||||
|
{handler}
|
||||||
|
</AmisNodeContainerDiv>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AmisNode
|
||||||
72
service-web/client/src/components/flow/node/CodeNode.tsx
Normal file
72
service-web/client/src/components/flow/node/CodeNode.tsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {Tag} from 'antd'
|
||||||
|
import React, {useCallback, useMemo} from 'react'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import AmisNode, {inputsFormColumns, nodeClassName, NormalNodeHandler, outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
|
||||||
|
const languageMap: Record<string, string> = {
|
||||||
|
'javascript': 'Javascript',
|
||||||
|
'python': 'Python',
|
||||||
|
'Lua': 'lua',
|
||||||
|
}
|
||||||
|
|
||||||
|
const CodeNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData, getDataById} = useDataStore()
|
||||||
|
|
||||||
|
const nodeData = getDataById(props.id)
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
...inputsFormColumns(props.id, getNodes(), getEdges(), getData()),
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '代码类型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(languageMap).map(key => ({label: languageMap[key], value: key})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'editor',
|
||||||
|
required: true,
|
||||||
|
label: '代码内容',
|
||||||
|
name: 'content',
|
||||||
|
language: '${type}',
|
||||||
|
options: {
|
||||||
|
wordWrap: 'bounded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(true, false),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
const extraNodeDescription = useMemo(() => {
|
||||||
|
return nodeData?.type
|
||||||
|
? <div className="mt-2 flex justify-between">
|
||||||
|
<span>代码类型</span>
|
||||||
|
<Tag className="m-0" color="blue">{languageMap[nodeData.type]}</Tag>
|
||||||
|
</div>
|
||||||
|
: <></>
|
||||||
|
}, [nodeData])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('code')}
|
||||||
|
nodeProps={props}
|
||||||
|
extraNodeDescription={extraNodeDescription}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<NormalNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(CodeNode)
|
||||||
123
service-web/client/src/components/flow/node/InputNode.tsx
Normal file
123
service-web/client/src/components/flow/node/InputNode.tsx
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import React, {useCallback} from 'react'
|
||||||
|
import AmisNode, {nodeClassName, outputsFormColumns, StartNodeHandler} from './AmisNode.tsx'
|
||||||
|
import {horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
|
import {typeMap} from '../../../pages/ai/task/InputSchema.tsx'
|
||||||
|
import type {FormSchema, OutputVariableType} from '../types.ts'
|
||||||
|
import {isEmpty} from 'licia'
|
||||||
|
|
||||||
|
const originTypeMap: Record<string, OutputVariableType> = {
|
||||||
|
text: 'text',
|
||||||
|
textarea: 'text',
|
||||||
|
number: 'number',
|
||||||
|
files: 'array-text',
|
||||||
|
}
|
||||||
|
|
||||||
|
const InputNode = (props: NodeProps) => {
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
events: {
|
||||||
|
change: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'validate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, doAction, event) => {
|
||||||
|
let data = event?.data
|
||||||
|
console.log(data)
|
||||||
|
if (data && isEmpty(data?.validateResult?.error ?? undefined)) {
|
||||||
|
let inputs = data.validateResult?.payload?.inputs ?? {}
|
||||||
|
if (inputs) {
|
||||||
|
let outputs: Record<string, { type: OutputVariableType }> = {}
|
||||||
|
for (let key of Object.keys(inputs)) {
|
||||||
|
outputs[key] = {
|
||||||
|
type: originTypeMap[inputs[key].type],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
doAction({
|
||||||
|
actionType: 'setValue',
|
||||||
|
args: {
|
||||||
|
value: {
|
||||||
|
outputs
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'input-kvs',
|
||||||
|
name: 'inputs',
|
||||||
|
label: '输入变量',
|
||||||
|
required: true,
|
||||||
|
addButtonText: '新增入参',
|
||||||
|
draggable: false,
|
||||||
|
keyItem: {
|
||||||
|
label: '参数名称',
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
validations: {
|
||||||
|
isAlphanumeric: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
valueItems: [
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'label',
|
||||||
|
required: true,
|
||||||
|
label: '中文名称',
|
||||||
|
clearValueOnEmpty: true,
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'description',
|
||||||
|
label: '参数描述',
|
||||||
|
clearValueOnEmpty: true,
|
||||||
|
clearable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '参数类型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(typeMap).map(key => ({label: typeMap[key], value: key})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
type: 'switch',
|
||||||
|
name: 'required',
|
||||||
|
label: '是否必填',
|
||||||
|
required: true,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, false),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('input')}
|
||||||
|
nodeProps={props}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<StartNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(InputNode)
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import React, {useCallback, useEffect} from 'react'
|
||||||
|
import {commonInfo} from '../../../util/amis.tsx'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import AmisNode, {inputsFormColumns, nodeClassName, NormalNodeHandler, outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
|
||||||
|
const KnowledgeNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData, mergeDataById} = useDataStore()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mergeDataById(
|
||||||
|
props.id,
|
||||||
|
{
|
||||||
|
outputs: {
|
||||||
|
result: {
|
||||||
|
type: 'array-string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}, [props.id])
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
...inputsFormColumns(props.id, getNodes(), getEdges(), getData()),
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, true),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('knowledge')}
|
||||||
|
nodeProps={props}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<NormalNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(KnowledgeNode)
|
||||||
80
service-web/client/src/components/flow/node/LlmNode.tsx
Normal file
80
service-web/client/src/components/flow/node/LlmNode.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {Tag} from 'antd'
|
||||||
|
import React, {useCallback, useEffect, useMemo} from 'react'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import AmisNode, {inputsFormColumns, nodeClassName, NormalNodeHandler, outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
|
||||||
|
const modelMap: Record<string, string> = {
|
||||||
|
qwen3: 'Qwen3',
|
||||||
|
deepseek: 'Deepseek',
|
||||||
|
}
|
||||||
|
|
||||||
|
const LlmNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData, mergeDataById, getDataById} = useDataStore()
|
||||||
|
|
||||||
|
const nodeData = getDataById(props.id)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mergeDataById(
|
||||||
|
props.id,
|
||||||
|
{
|
||||||
|
outputs: {
|
||||||
|
text: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}, [props.id])
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
...inputsFormColumns(props.id, getNodes(), getEdges(), getData()),
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'model',
|
||||||
|
label: '大模型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(modelMap).map(key => ({label: modelMap[key], value: key})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'systemPrompt',
|
||||||
|
label: '系统提示词',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, true),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
const extraNodeDescription = useMemo(() => {
|
||||||
|
return nodeData?.model
|
||||||
|
? <div className="mt-2 flex justify-between">
|
||||||
|
<span>模型名称</span>
|
||||||
|
<Tag className="m-0" color="blue">{modelMap[nodeData.model]}</Tag>
|
||||||
|
</div>
|
||||||
|
: <></>
|
||||||
|
}, [nodeData])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('llm')}
|
||||||
|
nodeProps={props}
|
||||||
|
extraNodeDescription={extraNodeDescription}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<NormalNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(LlmNode)
|
||||||
153
service-web/client/src/components/flow/node/LoopNode.tsx
Normal file
153
service-web/client/src/components/flow/node/LoopNode.tsx
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import {Background, BackgroundVariant, type NodeProps} from '@xyflow/react'
|
||||||
|
import {classnames} from 'amis'
|
||||||
|
import React, {useCallback, useEffect, useMemo} from 'react'
|
||||||
|
import AddNodeButton from '../component/AddNodeButton.tsx'
|
||||||
|
import {generateAllIncomerOutputVariablesFormOptions} from '../Helper.tsx'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import {flowBackgroundColor, flowDotColor, type FormSchema} from '../types.ts'
|
||||||
|
import AmisNode, {nodeClassName, NormalNodeHandler, outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const LoopNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData, mergeDataById} = useDataStore()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mergeDataById(
|
||||||
|
props.id,
|
||||||
|
{
|
||||||
|
failFast: true,
|
||||||
|
parallel: false,
|
||||||
|
type: 'for',
|
||||||
|
count: 1,
|
||||||
|
outputs: {
|
||||||
|
output: {
|
||||||
|
type: 'array-object',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}, [props.id])
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'switch',
|
||||||
|
name: 'failFast',
|
||||||
|
label: '快速失败',
|
||||||
|
required: true,
|
||||||
|
description: '执行过程中一旦出现错误,及时中断循环任务的执行',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
disabled: true,
|
||||||
|
type: 'switch',
|
||||||
|
name: 'parallel',
|
||||||
|
label: '并行执行',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '循环模式',
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '次数循环',
|
||||||
|
value: 'for',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '次数循环 (引用变量)',
|
||||||
|
value: 'for-variable',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '对象循环',
|
||||||
|
value: 'for-object',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: '${type === \'for\'}',
|
||||||
|
type: 'input-number',
|
||||||
|
name: 'count',
|
||||||
|
label: '循环次数',
|
||||||
|
required: true,
|
||||||
|
min: 1,
|
||||||
|
precision: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: '${type === \'for-variable\'}',
|
||||||
|
type: 'select',
|
||||||
|
name: 'countVariable',
|
||||||
|
label: '循环次数',
|
||||||
|
required: true,
|
||||||
|
selectMode: 'group',
|
||||||
|
options: generateAllIncomerOutputVariablesFormOptions(
|
||||||
|
props.id,
|
||||||
|
getNodes(),
|
||||||
|
getEdges(),
|
||||||
|
getData(),
|
||||||
|
['number'],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: '${type === \'for-object\'}',
|
||||||
|
type: 'select',
|
||||||
|
name: 'countObject',
|
||||||
|
label: '循环对象',
|
||||||
|
required: true,
|
||||||
|
selectMode: 'group',
|
||||||
|
options: generateAllIncomerOutputVariablesFormOptions(
|
||||||
|
props.id,
|
||||||
|
getNodes(),
|
||||||
|
getEdges(),
|
||||||
|
getData(),
|
||||||
|
['array-text', 'array-object'],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, true),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
const extraNodeDescription = useMemo(() => {
|
||||||
|
return (
|
||||||
|
<div className="nodrag relative w-full h-full" style={{minHeight: '211px'}}>
|
||||||
|
<Background
|
||||||
|
id={`loop-background-${props.id}`}
|
||||||
|
className="rounded-xl"
|
||||||
|
variant={BackgroundVariant.Cross}
|
||||||
|
gap={20}
|
||||||
|
size={3}
|
||||||
|
style={{
|
||||||
|
zIndex: 0,
|
||||||
|
}}
|
||||||
|
color={flowDotColor}
|
||||||
|
bgColor={flowBackgroundColor}
|
||||||
|
/>
|
||||||
|
<AddNodeButton className="mt-2 ml-2" parent={props.id} onlyIcon/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}, [props.id])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={classnames('w-full', 'h-full', nodeClassName('loop'))}
|
||||||
|
style={{
|
||||||
|
minWidth: '350px',
|
||||||
|
minHeight: '290px',
|
||||||
|
}}
|
||||||
|
nodeProps={props}
|
||||||
|
extraNodeDescription={extraNodeDescription}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<NormalNodeHandler/>}
|
||||||
|
resize={{
|
||||||
|
minWidth: 350,
|
||||||
|
minHeight: 290,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(LoopNode)
|
||||||
26
service-web/client/src/components/flow/node/OutputNode.tsx
Normal file
26
service-web/client/src/components/flow/node/OutputNode.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import React, {useCallback} from 'react'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
import AmisNode, {EndNodeHandler, inputsFormColumns, nodeClassName} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const OutputNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData} = useDataStore()
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: inputsFormColumns(props.id, getNodes(), getEdges(), getData()),
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('output')}
|
||||||
|
nodeProps={props}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<EndNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(OutputNode)
|
||||||
97
service-web/client/src/components/flow/node/SwitchNode.tsx
Normal file
97
service-web/client/src/components/flow/node/SwitchNode.tsx
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import {Handle, type NodeProps, Position} from '@xyflow/react'
|
||||||
|
import type {ConditionValue} from 'amis'
|
||||||
|
import {Tag} from 'antd'
|
||||||
|
import {contain, isEqual} from 'licia'
|
||||||
|
import React, {useCallback, useMemo} from 'react'
|
||||||
|
import {generateAllIncomerOutputVariablesConditions} from '../Helper.tsx'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import AmisNode, {nodeClassName} from './AmisNode.tsx'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
|
||||||
|
const SwitchNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges, removeEdges} = useFlowStore()
|
||||||
|
const {getData, getDataById} = useDataStore()
|
||||||
|
|
||||||
|
const nodeData = getDataById(props.id)
|
||||||
|
// @ts-ignore
|
||||||
|
const conditions: ConditionValue[] = nodeData?.conditions?.map(c => c.condition) ?? []
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
type: 'combo',
|
||||||
|
name: 'conditions',
|
||||||
|
label: '分支',
|
||||||
|
multiple: true,
|
||||||
|
required: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
type: 'condition-builder',
|
||||||
|
name: 'condition',
|
||||||
|
label: '条件',
|
||||||
|
required: true,
|
||||||
|
builderMode: 'simple',
|
||||||
|
showANDOR: true,
|
||||||
|
fields: generateAllIncomerOutputVariablesConditions(
|
||||||
|
props.id,
|
||||||
|
getNodes(),
|
||||||
|
getEdges(),
|
||||||
|
getData(),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
const extraNodeDescription = useMemo(() => {
|
||||||
|
return (
|
||||||
|
<div className="mt-2">
|
||||||
|
{conditions.map((item, index) => (
|
||||||
|
<div key={item.id} className="mt-1">
|
||||||
|
<Tag className="m-0" color="blue">分支 {index + 1}</Tag>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}, [nodeData])
|
||||||
|
|
||||||
|
const handler = useMemo(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
const conditions: ConditionValue[] = nodeData?.conditions?.map(c => c.condition) ?? []
|
||||||
|
|
||||||
|
// 移除不该存在的边
|
||||||
|
const conditionIds = conditions.map(c => c.id)
|
||||||
|
const removeEdgeIds = getEdges()
|
||||||
|
.filter(edge => isEqual(edge.source, props.id) && !contain(conditionIds, edge.sourceHandle))
|
||||||
|
.map(edge => edge.id)
|
||||||
|
removeEdges(removeEdgeIds)
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Handle type="target" position={Position.Left}/>
|
||||||
|
{conditions.map((item, index) => (
|
||||||
|
<Handle
|
||||||
|
type="source"
|
||||||
|
position={Position.Right}
|
||||||
|
key={item.id}
|
||||||
|
id={item.id}
|
||||||
|
style={{top: 91 + (26 * index)}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}, [nodeData])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('switch')}
|
||||||
|
nodeProps={props}
|
||||||
|
extraNodeDescription={extraNodeDescription}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={handler}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(SwitchNode)
|
||||||
94
service-web/client/src/components/flow/node/TemplateNode.tsx
Normal file
94
service-web/client/src/components/flow/node/TemplateNode.tsx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {Tag} from 'antd'
|
||||||
|
import React, {useCallback, useEffect, useMemo} from 'react'
|
||||||
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
|
import AmisNode, {inputsFormColumns, nodeClassName, NormalNodeHandler, outputsFormColumns} from './AmisNode.tsx'
|
||||||
|
import type {FormSchema} from '../types.ts'
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
default: '默认',
|
||||||
|
json: 'JSON',
|
||||||
|
'template-markdown': 'Markdown',
|
||||||
|
'template-rich-text': '富文本',
|
||||||
|
}
|
||||||
|
|
||||||
|
const TemplateNode = (props: NodeProps) => {
|
||||||
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
|
const {getData, getDataById, mergeDataById} = useDataStore()
|
||||||
|
|
||||||
|
const nodeData = getDataById(props.id)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
mergeDataById(
|
||||||
|
props.id,
|
||||||
|
{
|
||||||
|
outputs: {
|
||||||
|
text: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}, [props.id])
|
||||||
|
|
||||||
|
const formSchema: () => FormSchema = useCallback(() => ({
|
||||||
|
columns: [
|
||||||
|
...inputsFormColumns(props.id, getNodes(), getEdges(), getData()),
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '模板类型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(typeMap).map(key => ({label: typeMap[key], value: key})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: 'type === \'template-markdown\'',
|
||||||
|
type: 'editor',
|
||||||
|
required: true,
|
||||||
|
label: '模板内容',
|
||||||
|
name: 'template',
|
||||||
|
language: 'markdown',
|
||||||
|
options: {
|
||||||
|
wordWrap: 'bounded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: 'type === \'template-rich-text\'',
|
||||||
|
type: 'input-rich-text',
|
||||||
|
required: true,
|
||||||
|
name: 'template',
|
||||||
|
label: '模板内容',
|
||||||
|
options: {
|
||||||
|
min_height: 500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...outputsFormColumns(false, true),
|
||||||
|
]
|
||||||
|
}), [props.id])
|
||||||
|
|
||||||
|
const extraNodeDescription = useMemo(() => {
|
||||||
|
return nodeData?.type
|
||||||
|
? <div className="mt-2 flex justify-between">
|
||||||
|
<span>模板类型</span>
|
||||||
|
<Tag className="m-0" color="blue">{typeMap[nodeData.type]}</Tag>
|
||||||
|
</div>
|
||||||
|
: <></>
|
||||||
|
}, [nodeData])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AmisNode
|
||||||
|
className={nodeClassName('template')}
|
||||||
|
nodeProps={props}
|
||||||
|
extraNodeDescription={extraNodeDescription}
|
||||||
|
formSchema={formSchema}
|
||||||
|
handler={<NormalNodeHandler/>}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(TemplateNode)
|
||||||
42
service-web/client/src/components/flow/store/DataStore.ts
Normal file
42
service-web/client/src/components/flow/store/DataStore.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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,
|
||||||
|
mergeDataById: (id: string, data: any) => void,
|
||||||
|
removeDataById: (id: string) => 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,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
mergeDataById: (id, data) => {
|
||||||
|
let updateData = get().data
|
||||||
|
updateData[id] = {
|
||||||
|
...(updateData[id] ?? {}),
|
||||||
|
...data,
|
||||||
|
}
|
||||||
|
set({
|
||||||
|
data: updateData,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
removeDataById: (id) => {
|
||||||
|
let data = get().data
|
||||||
|
delete data[id]
|
||||||
|
set({
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}))
|
||||||
83
service-web/client/src/components/flow/store/FlowStore.ts
Normal file
83
service-web/client/src/components/flow/store/FlowStore.ts
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import {
|
||||||
|
addEdge,
|
||||||
|
applyEdgeChanges,
|
||||||
|
applyNodeChanges,
|
||||||
|
type Edge,
|
||||||
|
type Node,
|
||||||
|
type OnConnect,
|
||||||
|
type OnEdgesChange,
|
||||||
|
type OnNodesChange,
|
||||||
|
} from '@xyflow/react'
|
||||||
|
import {contain, filter, find, isEqual} from 'licia'
|
||||||
|
import {create} from 'zustand/react'
|
||||||
|
|
||||||
|
export const useFlowStore = create<{
|
||||||
|
nodes: Node[],
|
||||||
|
getNodes: () => Node[],
|
||||||
|
onNodesChange: OnNodesChange,
|
||||||
|
getNodeById: (id: string) => Node | undefined,
|
||||||
|
addNode: (node: Node) => void,
|
||||||
|
removeNode: (id: string) => void,
|
||||||
|
setNodes: (nodes: Node[]) => void,
|
||||||
|
setNode: (node: Node) => void,
|
||||||
|
|
||||||
|
edges: Edge[],
|
||||||
|
getEdges: () => Edge[],
|
||||||
|
onEdgesChange: OnEdgesChange,
|
||||||
|
removeEdge: (id: string) => void,
|
||||||
|
removeEdges: (ids: string[]) => void,
|
||||||
|
setEdges: (edges: Edge[]) => void,
|
||||||
|
|
||||||
|
onConnect: OnConnect,
|
||||||
|
}>((set, get) => ({
|
||||||
|
nodes: [],
|
||||||
|
getNodes: () => 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}),
|
||||||
|
setNode: node => {
|
||||||
|
set({
|
||||||
|
nodes: get().nodes.map(n => {
|
||||||
|
if (isEqual(node.id, n.id)) {
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
edges: [],
|
||||||
|
getEdges: () => get().edges,
|
||||||
|
onEdgesChange: changes => {
|
||||||
|
set({
|
||||||
|
edges: applyEdgeChanges(changes, get().edges),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
removeEdge: id => {
|
||||||
|
set({
|
||||||
|
edges: filter(get().edges, edge => !isEqual(edge.id, id)),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
removeEdges: ids => {
|
||||||
|
set({
|
||||||
|
edges: filter(get().edges, edge => !contain(ids, edge.id)),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
setEdges: edges => set({edges}),
|
||||||
|
|
||||||
|
onConnect: connection => {
|
||||||
|
set({
|
||||||
|
edges: addEdge(connection, get().edges),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}))
|
||||||
67
service-web/client/src/components/flow/types.ts
Normal file
67
service-web/client/src/components/flow/types.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import type {Edge, Node} from '@xyflow/react'
|
||||||
|
import type {JSX} from 'react'
|
||||||
|
import type {ListenerAction, Schema} from 'amis'
|
||||||
|
|
||||||
|
export const flowBackgroundColor = '#fafafa'
|
||||||
|
export const flowDotColor = '#dedede'
|
||||||
|
|
||||||
|
export type InputFormOptions = {
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InputFormOptionsGroup = {
|
||||||
|
group: string,
|
||||||
|
variables: InputFormOptions[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NodeError = {
|
||||||
|
error: boolean,
|
||||||
|
message?: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AddNodeChecker = (type: string, parentId: string | undefined, nodes: Node[], edges: Edge[], data: any) => NodeError
|
||||||
|
export type SaveNodeChecker = (id: string, parentId: string | undefined, nodes: Node[], edges: Edge[], data: any) => NodeError
|
||||||
|
|
||||||
|
export type GraphData = { nodes: Node[], edges: Edge[], data: any }
|
||||||
|
|
||||||
|
export type FlowEditorProps = {
|
||||||
|
graphData: GraphData,
|
||||||
|
onGraphDataChange: (graphData: GraphData) => void,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OutputVariableType = 'text' | 'boolean' | 'number' | 'object' | 'array-text' | 'array-object'
|
||||||
|
|
||||||
|
export const OutputVariableTypeMap: Record<OutputVariableType, string> = {
|
||||||
|
'text': '文本',
|
||||||
|
'boolean': '布尔值',
|
||||||
|
'number': '数字',
|
||||||
|
'object': '对象',
|
||||||
|
'array-text': '文本数组',
|
||||||
|
'array-object': '对象数组',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NodeDefine = {
|
||||||
|
key: string,
|
||||||
|
group: string,
|
||||||
|
name: string,
|
||||||
|
icon: JSX.Element,
|
||||||
|
description: string,
|
||||||
|
component: any,
|
||||||
|
checkers: {
|
||||||
|
add: AddNodeChecker[],
|
||||||
|
save: SaveNodeChecker[],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OutputVariable = {
|
||||||
|
group: string,
|
||||||
|
name: string | undefined,
|
||||||
|
type: OutputVariableType,
|
||||||
|
variable: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FormSchema = {
|
||||||
|
events?: Record<string, { actions: ListenerAction[] }>
|
||||||
|
columns: Schema[]
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {createRoot} from 'react-dom/client'
|
import {createRoot} from 'react-dom/client'
|
||||||
import {createHashRouter, RouterProvider} from 'react-router'
|
import {createHashRouter, RouterProvider} from 'react-router'
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
import './components/Registry.ts'
|
import './components/amis/Registry.ts'
|
||||||
|
|
||||||
import {routes} from './route.tsx'
|
import {routes} from './route.tsx'
|
||||||
|
|
||||||
|
|||||||
@@ -1,41 +1,132 @@
|
|||||||
import {ProLayout} from '@ant-design/pro-components'
|
import {type AppItemProps, ProLayout} from '@ant-design/pro-components'
|
||||||
import React from 'react'
|
import {ConfigProvider} from 'antd'
|
||||||
|
import {dateFormat} from 'licia'
|
||||||
|
import React, {useMemo, useState} from 'react'
|
||||||
import {Outlet, useLocation, useNavigate} from 'react-router'
|
import {Outlet, useLocation, useNavigate} from 'react-router'
|
||||||
|
import styled from 'styled-components'
|
||||||
import {menus} from '../route.tsx'
|
import {menus} from '../route.tsx'
|
||||||
|
|
||||||
|
const ProLayoutDiv = styled.div`
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
.ant-menu-sub > .ant-menu-item {
|
||||||
|
//padding-left: 28px !important;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const defaultAppIcon =
|
||||||
|
<img
|
||||||
|
src={'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAMAUExURUdwTBR20EyHx1iq5EWJ1hNyy0mR1EhzwnbB/8P5/Fx/vVuj5zyO4lCY102P0L3u/3K88dz4/8v1/0fW/jLh/013ujN4wBliuEuEy0FrqT13wFmCvkaH0GSLyBVVqe38/0il4FKu7crr/eL3/7Ls/zd3t1WN1TZcnTloojx6whpYpTdfoDVwtVeS1WeOyiNhsTFyuy50wHCPxDFgqLjK5G2Ow2Gy5ylpvB9uxA5x03W/71Wh4E2U2tr2/i6C3G7J+Gex7KTI8eb9/cbz/yC+/srl++P7/Znf+MPv/cn3/rz6/dL8/2fe/8v+/s/6/knN87f5/jx5uRZtwjRppU6I1liM2Bhcrmyl2kZ5uA9vzjd0wj95yjVstqze9hiD2zOH1kqv7Wqv5K7S7LLn/YfT+sfp/bPf+4jb/YbX+735/SjQ/T7J+VjV9rTs+0ns/6Dk/mPJ7eD9/b/8/Q9YxA5Zxw5Zwg5dwg5byhdn0kSO2xFezg5gwg1XwRBjwkqW4EeT3kuY20mV2BBVtg5avxFoxQ9Yu0+g3xJYslWi5h2q9SKA4AtTwAxjzUGN2UiN0VOm4yKj8NX7/0WQ3RFtyUaR1h95zSOc706J0Bt34VCi5yqw9F6s6SOI5Bx02h2M6Rh13SCX7k2c3E6a4lCd5EeQ2iVtyCJ54BVt3ROV8x+0+jS9+hGq+Ra0/WK37sPy/iOR6R1w2A5p0y9nrjJ/1EaO1yV1yDt+zBaJ4hF83FuJyg5nyhei9hJ96BN35ByV5ymq8S151muu5UCr6hzE/xS+/47h/3/r/xyG5SKV6yJ43BlswBJivA5z2A9duw5s1C590CZXpDVvuhec9BGM7xJQrxKE61yo4DOF4DeZ64jG8bbp/h/Q/j2F0xpr1xliyROA4CRst1mc10d8whNQqDqb3Sig5qrh/qLW9iZ/5UeY5pDU9UWf6J7O9oju/mDV/aXp/orj/6P7/4z3/2Pr/iLa/kaDxnuw57rf9ZfW+2Sd5G3X/7LW9zyR51TI+Dao7Zno//A+0MwAAADpdFJOUwD7Lv/+/v4CAQIK/v7+/P7+b/7+/iKh/f5LjBv8z/4d/v5cNf6A5piF/Pts9PST/tP+Qd0Oc/72Pf5B/Pv0/vv7zqD6/4qU+5JjlCv7ff79/lz628SK/pmm+/5cnh/+/vPht/r+pPKX44z7+/z7/P7+wNL////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+///////////////////////+1awirQAAA+BJREFUOMtjYCAXcMIAAVW4OKjKgJjDW8nXyytT0NOKCyjAgUudt29RwMdPb48dO/b2aEa6MkQvpjrlQqCqz3ki/j4+2VnCv44+S5XHVAm0xHPixHXuOSIiX4TfHeo87OJin/IjTYmBgwNdndvEibkF/sIiX26/+7f6yJo1K/fPtL/53BXDPKeJQkLvPx87Knz79qzOI2tWr959acFaAYE3rii2cwDVOQutU8k/+uHv4cNrQMpWrFgxTXHtWoc3gkgqORkEJzqvW3fr/f8Paye4rFzZufvSisuXr95QVJw9W+C3MlwlB4O87Tp+fn6VV2sVgOo6wequ7tkz4zWP3QHrm45IBroJJd/if37w0CygaZ0Tpi1YMO/qnr17b7yeMePFAZufSlAjQQbeyle5qbBq1apZIGUn1s87DlS3/DrPsj8vr/McdES48Lv7q4NPVq3avx+sbP2cOV0zZsxfftfuZcdsbm6Bb1YM7BATk64pPHk6C6hqGljVnK6uZSfnzl2+bObMmR3csx0OhkIUMpgkHgKatW/fvO3HjwMVdXWdPHly7oYNd3mA6jo6uLm5Q0ABDcSxCU/37du+/f79HfPnz507dwNQ0Ya7dyuudyzu6Fi8eNGiOjUukEp2BqZDcXE7dpw5c+bcuY0bK+CgbtEioLK6+kmVLKIQhRZP4iwtgWp6gKCqpwoCyivqQACorLeXhQnkSKDC83a7dgEVlfeUw0BJScm9SfVAAFTHwjIdqpBpafyuspISIEICxSWV9ZMmLQGr0wVbzcEgbb518+YDFcWlxUAAUgMGNXfqKisrl1QCFaqZgL3NwGkgzsbb2LC5u7sYAUprWu/UL2HZto1FZrosJGbYGWIMbdjYpjRuvtddU1MDVAMB3U3bljZdubJNZqceJMDZGSQv8vX1TZnS2HCguwaqqrS5ubm1CQiuRE3faQSNGQYu469glVMalnZ315SBAUghUGX7Y/3psrD0yM6gvQmoEGh5Y0Pv+Xs1pdUQlUCF7e2PzXeawgwEGQm0nI2tsaFhYdvC3qVl1WClZ1vb2+XkHskisgLQlRc0IeoWtrUxn2+urT5dXVt99ixQ4UWEC8EqNS5o8jaClLX191bXQsDps+1hWo+QLAYnIfULMrxAdf39s6dWt4BB7enT4lqb9Bg40DK2+iZea2tmZub+qbsmA0HLqZZT4vqbpBgYMIoKbZ2H166Z1U9mhYKgUw+CJdHVgd0pGvHwmllvJCMYsJ56oKPBheI+hEoGpnDdrVungsBWQwNVaQas6oCWAIWlo6WkxMTEVAOZQFo5cJW57Mgm4FYGMRUGyK0tAGzv0vrmaa6xAAAAAElFTkSuQmCC'}
|
||||||
|
alt=""
|
||||||
|
/>
|
||||||
|
const apps: AppItemProps[] = [
|
||||||
|
{
|
||||||
|
icon: 'http://132.121.223.12:7001/static/webssh/favicon2.ico',
|
||||||
|
title: '运营数据汇聚平台',
|
||||||
|
desc: '企业全融合数字化平台',
|
||||||
|
url: 'http://132.121.223.12:7001/index.html/#/login',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: defaultAppIcon,
|
||||||
|
title: '汇聚平台辅助工具',
|
||||||
|
desc: '辅助工具,用于帮助运营工作,不断改进中',
|
||||||
|
url: 'http://132.121.204.100:38080/tools/#/',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: defaultAppIcon,
|
||||||
|
title: 'B12-Yarn',
|
||||||
|
desc: 'B12集群Yarn页面',
|
||||||
|
url: 'http://132.126.207.125:8088/cluster/scheduler',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
const [collapsed, setCollapsed] = useState<boolean>(false)
|
||||||
|
const currentYear = useMemo(() => dateFormat(new Date(), 'yyyy'), [])
|
||||||
return (
|
return (
|
||||||
<ProLayout
|
<ProLayoutDiv>
|
||||||
token={{
|
<ProLayout
|
||||||
header: {
|
collapsed={collapsed}
|
||||||
colorBgHeader: '#292f33',
|
onCollapse={setCollapsed}
|
||||||
colorHeaderTitle: '#ffffff',
|
siderWidth={180}
|
||||||
colorTextMenu: '#dfdfdf',
|
token={{
|
||||||
colorTextMenuSecondary: '#dfdfdf',
|
colorTextAppListIcon: '#dfdfdf',
|
||||||
colorTextMenuSelected: '#ffffff',
|
colorTextAppListIconHover: '#ffffff',
|
||||||
colorTextMenuActive: '#ffffff',
|
header: {
|
||||||
colorBgMenuItemSelected: '#22272b',
|
colorBgHeader: '#292f33',
|
||||||
colorTextRightActionsItem: '#dfdfdf',
|
colorHeaderTitle: '#ffffff',
|
||||||
},
|
colorTextMenu: '#dfdfdf',
|
||||||
}}
|
colorTextMenuSecondary: '#dfdfdf',
|
||||||
logo={<img src="icon.png" alt="logo"/>}
|
colorTextMenuSelected: '#ffffff',
|
||||||
title="Hudi 服务总台"
|
colorTextMenuActive: '#ffffff',
|
||||||
route={menus}
|
colorBgMenuItemSelected: '#22272b',
|
||||||
location={{pathname: location.pathname}}
|
colorTextRightActionsItem: '#dfdfdf',
|
||||||
menu={{type: 'sub'}}
|
},
|
||||||
menuItemRender={(item, dom) => {
|
pageContainer: {
|
||||||
return <div onClick={() => navigate(item.path || '/')}>{dom}</div>
|
paddingBlockPageContainerContent: 0,
|
||||||
}}
|
paddingInlinePageContainerContent: 0,
|
||||||
fixSiderbar={true}
|
marginBlockPageContainerContent: 0,
|
||||||
layout="mix"
|
marginInlinePageContainerContent: 0,
|
||||||
splitMenus={true}
|
},
|
||||||
style={{minHeight: '100vh'}}
|
}}
|
||||||
contentStyle={{backgroundColor: 'white', padding: '10px 10px 10px 20px'}}
|
appList={apps}
|
||||||
>
|
breakpoint={false}
|
||||||
<Outlet/>
|
disableMobile={true}
|
||||||
</ProLayout>
|
logo={<img src="icon.png" alt="logo"/>}
|
||||||
|
title="Hudi 服务总台"
|
||||||
|
route={menus}
|
||||||
|
location={{pathname: location.pathname}}
|
||||||
|
menu={{type: 'sub'}}
|
||||||
|
menuItemRender={(item, defaultDom) => {
|
||||||
|
return (
|
||||||
|
<div onClick={() => navigate(item.path || '/')}>
|
||||||
|
{/*<span className="align-center">{item.icon}</span>*/}
|
||||||
|
{/*<span className="ml-2">{item.name}</span>*/}
|
||||||
|
{defaultDom}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
fixSiderbar={true}
|
||||||
|
layout="mix"
|
||||||
|
splitMenus={true}
|
||||||
|
style={{minHeight: '100vh'}}
|
||||||
|
contentStyle={{backgroundColor: 'white', padding: '10px 10px 10px 20px'}}
|
||||||
|
menuFooterRender={props => {
|
||||||
|
return (
|
||||||
|
<div className="text-sm text-center" style={{userSelect: 'none', msUserSelect: 'none'}}>
|
||||||
|
{props?.collapsed
|
||||||
|
? undefined
|
||||||
|
: <div>© 2023-{currentYear} 汇聚平台</div>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ConfigProvider
|
||||||
|
theme={{
|
||||||
|
components: {
|
||||||
|
Card: {
|
||||||
|
bodyPadding: 0,
|
||||||
|
bodyPaddingSM: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Outlet/>
|
||||||
|
</ConfigProvider>
|
||||||
|
</ProLayout>
|
||||||
|
</ProLayoutDiv>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -42,7 +42,6 @@ function Conversation() {
|
|||||||
const [input, setInput] = useState<string>('')
|
const [input, setInput] = useState<string>('')
|
||||||
|
|
||||||
useUnmount(() => {
|
useUnmount(() => {
|
||||||
console.log('Page Unmount')
|
|
||||||
abortController.current?.abort()
|
abortController.current?.abort()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
166
service-web/client/src/pages/ai/task/FlowTask.tsx
Normal file
166
service-web/client/src/pages/ai/task/FlowTask.tsx
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import {useNavigate} from 'react-router'
|
||||||
|
import {
|
||||||
|
amisRender,
|
||||||
|
commonInfo,
|
||||||
|
crudCommonOptions,
|
||||||
|
mappingField,
|
||||||
|
mappingItem,
|
||||||
|
paginationTemplate,
|
||||||
|
readOnlyDialogOptions,
|
||||||
|
} from '../../../util/amis.tsx'
|
||||||
|
import {generateInputForm} from './InputSchema.tsx'
|
||||||
|
|
||||||
|
const statusMapping = [
|
||||||
|
mappingItem('完成', 'FINISHED', 'label-success'),
|
||||||
|
mappingItem('执行中', 'RUNNING', 'label-warning'),
|
||||||
|
mappingItem('错误', 'ERROR', 'label-danger'),
|
||||||
|
]
|
||||||
|
|
||||||
|
const FlowTask: React.FC = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
return (
|
||||||
|
<div className="task-template">
|
||||||
|
{amisRender(
|
||||||
|
{
|
||||||
|
type: 'page',
|
||||||
|
title: '任务记录',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'crud',
|
||||||
|
api: {
|
||||||
|
method: 'post',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/list`,
|
||||||
|
data: {
|
||||||
|
page: {
|
||||||
|
index: '${page}',
|
||||||
|
size: '${perPage}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...crudCommonOptions(),
|
||||||
|
...paginationTemplate(
|
||||||
|
10,
|
||||||
|
5,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '',
|
||||||
|
icon: 'fa fa-plus',
|
||||||
|
size: 'sm',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, action, event) => {
|
||||||
|
navigate(`/ai/flow_task/add`)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
label: '任务ID',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'templateName',
|
||||||
|
label: '模板',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'status',
|
||||||
|
label: '状态',
|
||||||
|
width: 50,
|
||||||
|
align: 'center',
|
||||||
|
...mappingField('status', statusMapping),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'operation',
|
||||||
|
label: '操作',
|
||||||
|
width: 200,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
visibleOn: 'hasInput',
|
||||||
|
type: 'action',
|
||||||
|
label: '查看',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
actionType: 'dialog',
|
||||||
|
dialog: {
|
||||||
|
title: '查看',
|
||||||
|
size: 'md',
|
||||||
|
...readOnlyDialogOptions(),
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'service',
|
||||||
|
schemaApi: {
|
||||||
|
method: 'get',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/input_schema/\${id}`,
|
||||||
|
// @ts-ignore
|
||||||
|
adaptor: (payload, response, api, context) => {
|
||||||
|
return {
|
||||||
|
...payload,
|
||||||
|
data: {
|
||||||
|
...generateInputForm(payload.data ?? {}, undefined, false, true),
|
||||||
|
id: 'db8a4d10-0c47-4e27-b1a4-d0f2e1c15992',
|
||||||
|
initApi: {
|
||||||
|
method: 'get',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/input_data/\${id}`,
|
||||||
|
// @ts-ignore
|
||||||
|
adaptor: (payload, response, api, context) => {
|
||||||
|
console.log(payload)
|
||||||
|
return {
|
||||||
|
...payload,
|
||||||
|
data: {
|
||||||
|
inputData: payload.data ?? {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
static: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '执行',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: `get:${commonInfo.baseAiUrl}/flow_task/execute/\${id}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '删除',
|
||||||
|
className: 'text-danger btn-deleted',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: `get:${commonInfo.baseAiUrl}/flow_task/remove/\${id}`,
|
||||||
|
confirmText: '确认删除任务记录:${name}',
|
||||||
|
confirmTitle: '删除',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowTask
|
||||||
178
service-web/client/src/pages/ai/task/FlowTaskAdd.tsx
Normal file
178
service-web/client/src/pages/ai/task/FlowTaskAdd.tsx
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
import {isEmpty} from 'licia'
|
||||||
|
import React from 'react'
|
||||||
|
import {amisRender, commonInfo} from '../../../util/amis.tsx'
|
||||||
|
import {generateInputForm} from './InputSchema.tsx'
|
||||||
|
|
||||||
|
const FlowTaskAdd: React.FC = () => {
|
||||||
|
// const navigate = useNavigate()
|
||||||
|
return (
|
||||||
|
<div className="task-template">
|
||||||
|
{amisRender(
|
||||||
|
{
|
||||||
|
id: 'e81515a4-8a73-457a-974d-7e9196eeb524',
|
||||||
|
type: 'page',
|
||||||
|
title: '发起任务',
|
||||||
|
body: {
|
||||||
|
id: '74a1a3e5-41a6-4979-88e7-65f15bce4d4c',
|
||||||
|
type: 'wizard',
|
||||||
|
wrapWithPanel: false,
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
title: '选择任务模板',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
level: 'primary',
|
||||||
|
actionType: 'next',
|
||||||
|
label: '下一步',
|
||||||
|
disabledOn: '${templateId === undefined}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'service',
|
||||||
|
api: `get:${commonInfo.baseAiUrl}/flow_task/template/list`,
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'table2',
|
||||||
|
source: '$items',
|
||||||
|
rowSelection: {
|
||||||
|
type: 'radio',
|
||||||
|
keyField: 'id',
|
||||||
|
rowClick: true,
|
||||||
|
fixed: true,
|
||||||
|
},
|
||||||
|
onEvent: {
|
||||||
|
selectedChange: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, doAction, event) => {
|
||||||
|
let selectedIds = (event?.data?.selectedItems ?? []).map((item: any) => item.id)
|
||||||
|
if (!isEmpty(selectedIds)) {
|
||||||
|
doAction({
|
||||||
|
actionType: 'setValue',
|
||||||
|
componentId: 'e81515a4-8a73-457a-974d-7e9196eeb524',
|
||||||
|
args: {
|
||||||
|
value: {
|
||||||
|
templateId: selectedIds[0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
doAction({
|
||||||
|
actionType: 'setValue',
|
||||||
|
componentId: 'e81515a4-8a73-457a-974d-7e9196eeb524',
|
||||||
|
args: {
|
||||||
|
value: {
|
||||||
|
templateId: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
title: '名称',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
title: '模板描述',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '填写任务信息',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
actionType: 'prev',
|
||||||
|
label: '上一步',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'setValue',
|
||||||
|
componentId: 'e81515a4-8a73-457a-974d-7e9196eeb524',
|
||||||
|
args: {
|
||||||
|
value: {
|
||||||
|
templateId: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
level: 'primary',
|
||||||
|
label: '提交',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'validate',
|
||||||
|
componentId: 'db8a4d10-0c47-4e27-b1a4-d0f2e1c15992',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionType: 'stopPropagation',
|
||||||
|
expression: '${event.data.validateResult.error !== \'\'}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionType: 'submit',
|
||||||
|
componentId: 'db8a4d10-0c47-4e27-b1a4-d0f2e1c15992',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'service',
|
||||||
|
schemaApi: {
|
||||||
|
method: 'get',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/template/input_schema/\${templateId}`,
|
||||||
|
// @ts-ignore
|
||||||
|
adaptor: (payload, response, api, context) => {
|
||||||
|
return {
|
||||||
|
...payload,
|
||||||
|
data: {
|
||||||
|
id: 'db8a4d10-0c47-4e27-b1a4-d0f2e1c15992',
|
||||||
|
api: {
|
||||||
|
method: 'post',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/save`,
|
||||||
|
data: {
|
||||||
|
templateId: '${templateId|default:undefined}',
|
||||||
|
input: '${inputData|default:undefined}',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
...generateInputForm(payload.data ?? {}, undefined, false),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowTaskAdd
|
||||||
80
service-web/client/src/pages/ai/task/InputSchema.tsx
Normal file
80
service-web/client/src/pages/ai/task/InputSchema.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import type {Schema} from 'amis'
|
||||||
|
import {commonInfo, formInputFileStaticColumns} from '../../../util/amis.tsx'
|
||||||
|
|
||||||
|
export const typeMap: Record<string, string> = {
|
||||||
|
text: '文本',
|
||||||
|
textarea: '文本段',
|
||||||
|
number: '数字',
|
||||||
|
files: '文件',
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InputField = {
|
||||||
|
type: string
|
||||||
|
label: string
|
||||||
|
description?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateInputForm: (inputSchema: Record<string, InputField>, title?: string, border?: boolean, staticView?: boolean) => Schema = (inputSchema, title, border, staticView) => {
|
||||||
|
let items: Schema[] = []
|
||||||
|
for (const name of Object.keys(inputSchema)) {
|
||||||
|
let field = inputSchema[name]
|
||||||
|
// @ts-ignore
|
||||||
|
let commonMeta: Schema = {
|
||||||
|
name: `inputData.${name}`,
|
||||||
|
...field,
|
||||||
|
}
|
||||||
|
switch (field.type) {
|
||||||
|
case 'text':
|
||||||
|
items.push({
|
||||||
|
...commonMeta,
|
||||||
|
type: 'input-text',
|
||||||
|
clearValueOnEmpty: true,
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'textarea':
|
||||||
|
items.push({
|
||||||
|
...commonMeta,
|
||||||
|
type: 'textarea',
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case 'number':
|
||||||
|
commonMeta.type = 'input-number'
|
||||||
|
break
|
||||||
|
case 'files':
|
||||||
|
if (staticView) {
|
||||||
|
items.push({
|
||||||
|
...commonMeta,
|
||||||
|
type: 'control',
|
||||||
|
body: {
|
||||||
|
type: 'crud',
|
||||||
|
api: `${commonInfo.baseAiUrl}/upload/detail?ids=\${JOIN(inputData.${name}, ',')}`,
|
||||||
|
columns: formInputFileStaticColumns,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
items.push({
|
||||||
|
...commonMeta,
|
||||||
|
type: 'input-file',
|
||||||
|
autoUpload: false,
|
||||||
|
drag: true,
|
||||||
|
multiple: true,
|
||||||
|
joinValues: false,
|
||||||
|
extractValue: true,
|
||||||
|
accept: '*',
|
||||||
|
maxSize: 104857600,
|
||||||
|
receiver: `${commonInfo.baseAiUrl}/upload`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
debug: commonInfo.debug,
|
||||||
|
type: 'form',
|
||||||
|
title: title,
|
||||||
|
wrapWithPanel: border,
|
||||||
|
canAccessSuperData: false,
|
||||||
|
actions: [],
|
||||||
|
body: items,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import {useNavigate} from 'react-router'
|
||||||
|
import {amisRender, commonInfo, crudCommonOptions, paginationTemplate} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
|
const FlowTaskTemplate: React.FC = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
return (
|
||||||
|
<div className="task-template">
|
||||||
|
{amisRender(
|
||||||
|
{
|
||||||
|
type: 'page',
|
||||||
|
title: '任务模板',
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'crud',
|
||||||
|
api: {
|
||||||
|
method: 'post',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/template/list`,
|
||||||
|
data: {
|
||||||
|
page: {
|
||||||
|
index: '${page}',
|
||||||
|
size: '${perPage}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...crudCommonOptions(),
|
||||||
|
...paginationTemplate(
|
||||||
|
10,
|
||||||
|
5,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '',
|
||||||
|
icon: 'fa fa-plus',
|
||||||
|
tooltip: '新增',
|
||||||
|
tooltipPlacement: 'top',
|
||||||
|
size: 'sm',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, action, event) => {
|
||||||
|
navigate(`/ai/flow_task_template/edit/-1`)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
),
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
label: '名称',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
label: '描述',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'operation',
|
||||||
|
label: '操作',
|
||||||
|
width: 200,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '编辑',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, action, event) => {
|
||||||
|
navigate(`/ai/flow_task_template/edit/${context.props.data['id']}`)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '编辑流程',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
onEvent: {
|
||||||
|
click: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, doAction, event) => {
|
||||||
|
navigate(`/ai/flow_task_template/flow/edit/${context.props.data['id']}`)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '删除',
|
||||||
|
className: 'text-danger btn-deleted',
|
||||||
|
level: 'link',
|
||||||
|
size: 'sm',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: `get:${commonInfo.baseAiUrl}/flow_task/template/remove/\${id}`,
|
||||||
|
confirmText: '确认删除任务模板:${name}',
|
||||||
|
confirmTitle: '删除',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowTaskTemplate
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import {isEqual} from 'licia'
|
||||||
|
import React from 'react'
|
||||||
|
import {useNavigate, useParams} from 'react-router'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
|
const TemplateEditDiv = styled.div`
|
||||||
|
.antd-EditorControl {
|
||||||
|
min-height: 500px !important;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const FlowTaskTemplateEdit: React.FC = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const {template_id} = useParams()
|
||||||
|
const preloadTemplateId = isEqual(template_id, '-1') ? undefined : template_id
|
||||||
|
return (
|
||||||
|
<TemplateEditDiv className="task-template-edit h-full">
|
||||||
|
{amisRender({
|
||||||
|
type: 'page',
|
||||||
|
title: '模板编辑',
|
||||||
|
body: {
|
||||||
|
debug: commonInfo.debug,
|
||||||
|
type: 'form',
|
||||||
|
api: {
|
||||||
|
method: 'POST',
|
||||||
|
url: `${commonInfo.baseAiUrl}/flow_task/template/save`,
|
||||||
|
data: {
|
||||||
|
id: '${id|default:undefined}',
|
||||||
|
name: '${name}',
|
||||||
|
description: '${description}',
|
||||||
|
inputSchema: '${inputSchema|default:undefined}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
initApi: preloadTemplateId
|
||||||
|
? `get:${commonInfo.baseAiUrl}/flow_task/template/detail/${preloadTemplateId}`
|
||||||
|
: undefined,
|
||||||
|
wrapWithPanel: false,
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
onEvent: {
|
||||||
|
submitSucc: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'custom',
|
||||||
|
// @ts-ignore
|
||||||
|
script: (context, doAction, event) => {
|
||||||
|
navigate(-1)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'hidden',
|
||||||
|
name: 'id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'name',
|
||||||
|
label: '名称',
|
||||||
|
required: true,
|
||||||
|
clearable: true,
|
||||||
|
maxLength: 10,
|
||||||
|
showCounter: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'description',
|
||||||
|
label: '描述',
|
||||||
|
required: true,
|
||||||
|
clearable: true,
|
||||||
|
maxLength: 500,
|
||||||
|
showCounter: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button-toolbar',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'submit',
|
||||||
|
label: '提交',
|
||||||
|
level: 'primary',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'reset',
|
||||||
|
label: '重置',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
</TemplateEditDiv>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowTaskTemplateEdit
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import {useMount} from 'ahooks'
|
||||||
|
import axios from 'axios'
|
||||||
|
import React, {useState} from 'react'
|
||||||
|
import {useNavigate, useParams} from 'react-router'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import FlowEditor from '../../../../components/flow/FlowEditor.tsx'
|
||||||
|
import type {GraphData} from '../../../../components/flow/types.ts'
|
||||||
|
import {commonInfo} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
|
const FlowTaskTemplateFlowEditDiv = styled.div`
|
||||||
|
`
|
||||||
|
|
||||||
|
const FlowTaskTemplateFlowEdit: React.FC = () => {
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const {template_id} = useParams()
|
||||||
|
const [graphData, setGraphData] = useState<GraphData>({nodes: [], edges: [], data: {}})
|
||||||
|
|
||||||
|
useMount(async () => {
|
||||||
|
let {data} = await axios.get(
|
||||||
|
`${commonInfo.baseAiUrl}/flow_task/template/detail/${template_id}`,
|
||||||
|
{
|
||||||
|
headers: commonInfo.authorizationHeaders,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
setGraphData(data?.data?.flowGraph)
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FlowTaskTemplateFlowEditDiv className="h-full w-full">
|
||||||
|
<FlowEditor
|
||||||
|
graphData={graphData}
|
||||||
|
onGraphDataChange={async data => {
|
||||||
|
await axios.post(
|
||||||
|
`${commonInfo.baseAiUrl}/flow_task/template/update_flow_graph`,
|
||||||
|
{
|
||||||
|
id: template_id,
|
||||||
|
graph: data,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: commonInfo.authorizationHeaders,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
navigate(-1)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</FlowTaskTemplateFlowEditDiv>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowTaskTemplateFlowEdit
|
||||||
@@ -31,7 +31,7 @@ const queueCrud = (name: string) => {
|
|||||||
{
|
{
|
||||||
name: 'data.flinkJobId',
|
name: 'data.flinkJobId',
|
||||||
label: '任务 ID',
|
label: '任务 ID',
|
||||||
width: 190,
|
width: 200,
|
||||||
...copyField('data.flinkJobId'),
|
...copyField('data.flinkJobId'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import {
|
|||||||
ClusterOutlined,
|
ClusterOutlined,
|
||||||
CompressOutlined,
|
CompressOutlined,
|
||||||
DatabaseOutlined,
|
DatabaseOutlined,
|
||||||
|
FileTextOutlined,
|
||||||
|
GatewayOutlined,
|
||||||
InfoCircleOutlined,
|
InfoCircleOutlined,
|
||||||
OpenAIOutlined,
|
OpenAIOutlined,
|
||||||
QuestionOutlined,
|
QuestionOutlined,
|
||||||
@@ -20,6 +22,10 @@ import DataDetail from './pages/ai/knowledge/DataDetail.tsx'
|
|||||||
import DataImport from './pages/ai/knowledge/DataImport.tsx'
|
import DataImport from './pages/ai/knowledge/DataImport.tsx'
|
||||||
import DataSegment from './pages/ai/knowledge/DataSegment.tsx'
|
import DataSegment from './pages/ai/knowledge/DataSegment.tsx'
|
||||||
import Knowledge from './pages/ai/knowledge/Knowledge.tsx'
|
import Knowledge from './pages/ai/knowledge/Knowledge.tsx'
|
||||||
|
import FlowTask from './pages/ai/task/FlowTask.tsx'
|
||||||
|
import FlowTaskAdd from './pages/ai/task/FlowTaskAdd.tsx'
|
||||||
|
import FlowTaskTemplate from './pages/ai/task/template/FlowTaskTemplate.tsx'
|
||||||
|
import FlowTaskTemplateEdit from './pages/ai/task/template/FlowTaskTemplateEdit.tsx'
|
||||||
import App from './pages/App.tsx'
|
import App from './pages/App.tsx'
|
||||||
import Cloud from './pages/overview/Cloud.tsx'
|
import Cloud from './pages/overview/Cloud.tsx'
|
||||||
import Overview from './pages/overview/Overview.tsx'
|
import Overview from './pages/overview/Overview.tsx'
|
||||||
@@ -32,6 +38,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 FlowTaskTemplateFlowEdit from './pages/ai/task/template/FlowTaskTemplateFlowEdit.tsx'
|
||||||
|
|
||||||
export const routes: RouteObject[] = [
|
export const routes: RouteObject[] = [
|
||||||
{
|
{
|
||||||
@@ -109,6 +116,26 @@ 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: 'flow_task',
|
||||||
|
Component: FlowTask,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'flow_task/add',
|
||||||
|
Component: FlowTaskAdd,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'flow_task_template',
|
||||||
|
Component: FlowTaskTemplate,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'flow_task_template/edit/:template_id',
|
||||||
|
Component: FlowTaskTemplateEdit,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'flow_task_template/flow/edit/:template_id',
|
||||||
|
Component: FlowTaskTemplateFlowEdit,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -152,7 +179,7 @@ export const menus = {
|
|||||||
icon: <SyncOutlined/>,
|
icon: <SyncOutlined/>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: `/yarn/${commonInfo.clusters.compaction_names()}/${values(commonInfo.clusters.compaction).join(",")}/Compaction`,
|
path: `/yarn/${commonInfo.clusters.compaction_names()}/${values(commonInfo.clusters.compaction).join(',')}/Compaction`,
|
||||||
name: '压缩集群',
|
name: '压缩集群',
|
||||||
icon: <SyncOutlined/>,
|
icon: <SyncOutlined/>,
|
||||||
},
|
},
|
||||||
@@ -211,6 +238,23 @@ export const menus = {
|
|||||||
name: '知识库',
|
name: '知识库',
|
||||||
icon: <DatabaseOutlined/>,
|
icon: <DatabaseOutlined/>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '1089caa6-9477-44a5-99f1-a9c179f6cfd3',
|
||||||
|
name: '流程任务',
|
||||||
|
icon: <GatewayOutlined/>,
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
path: '/ai/flow_task',
|
||||||
|
name: '任务列表',
|
||||||
|
icon: <FileTextOutlined/>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/ai/flow_task_template',
|
||||||
|
name: '流程模板',
|
||||||
|
icon: <FileTextOutlined/>,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -2508,4 +2517,61 @@ export function time(field: string) {
|
|||||||
|
|
||||||
export function pictureFromIds(field: string) {
|
export function pictureFromIds(field: string) {
|
||||||
return `\${ARRAYMAP(${field},id => '${commonInfo.baseAiUrl}/upload/download/' + id)}`
|
return `\${ARRAYMAP(${field},id => '${commonInfo.baseAiUrl}/upload/download/' + id)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export const formInputFileStaticColumns = [
|
||||||
|
{
|
||||||
|
name: 'filename',
|
||||||
|
label: '文件名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'operation',
|
||||||
|
label: '操作',
|
||||||
|
width: 140,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '预览',
|
||||||
|
level: 'link',
|
||||||
|
icon: 'fas fa-eye',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '下载',
|
||||||
|
level: 'link',
|
||||||
|
icon: 'fa fa-download',
|
||||||
|
actionType: 'ajax',
|
||||||
|
// api: {
|
||||||
|
// ...apiGet('${base}/upload/download/${id}'),
|
||||||
|
// responseType: 'blob',
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export function formInputSingleFileStatic(field: string, label: string) {
|
||||||
|
return {
|
||||||
|
visibleOn: '${static}',
|
||||||
|
type: 'control',
|
||||||
|
label: label,
|
||||||
|
required: true,
|
||||||
|
body: {
|
||||||
|
type: 'table',
|
||||||
|
source: `\${${field}|asArray}`,
|
||||||
|
columns: formInputFileStaticColumns,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formInputMultiFileStatic(field: string, label: string) {
|
||||||
|
return {
|
||||||
|
visibleOn: '${static}',
|
||||||
|
type: 'input-table',
|
||||||
|
label: label,
|
||||||
|
name: field,
|
||||||
|
required: true,
|
||||||
|
resizable: false,
|
||||||
|
columns: formInputFileStaticColumns,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
2
service-web/client/src/vite-env.d.ts
vendored
2
service-web/client/src/vite-env.d.ts
vendored
@@ -1 +1,3 @@
|
|||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare const __APP_VERSION__: string
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import react from '@vitejs/plugin-react-swc'
|
import react from '@vitejs/plugin-react-swc'
|
||||||
import {defineConfig, type UserConfig} from 'vite'
|
import {defineConfig, type UserConfig} from 'vite'
|
||||||
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
|
import obfuscatorPlugin from 'vite-plugin-javascript-obfuscator'
|
||||||
|
import packageJson from './package.json'
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig(({mode}) => {
|
export default defineConfig(({mode}) => {
|
||||||
let config: UserConfig = {
|
let config: UserConfig = {
|
||||||
|
define: {
|
||||||
|
__APP_VERSION__: JSON.stringify(packageJson.version) ?? '0.0.0',
|
||||||
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
obfuscatorPlugin({
|
obfuscatorPlugin({
|
||||||
|
|||||||
Reference in New Issue
Block a user