Skip to content

Commit 14f3512

Browse files
authored
feat(semantic): add domain crud (#8)
* feat: add domain * feat: add frontend * fix: ci * fix: add check in domain * fix: add check in domain * fix: remove impl * fix: frontend bug * Update DomainController.java
1 parent 82aa1e6 commit 14f3512

25 files changed

Lines changed: 1140 additions & 12 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.agent.tools;
19+
20+
import io.agentscope.core.tool.Tool;
21+
import io.github.malonetalk.service.DomainService;
22+
import java.util.List;
23+
import lombok.AllArgsConstructor;
24+
import lombok.extern.slf4j.Slf4j;
25+
import org.springframework.stereotype.Component;
26+
27+
@Slf4j
28+
@Component
29+
@AllArgsConstructor
30+
public class GetDomainsTool implements MarkAgentTool {
31+
32+
private final DomainService domainService;
33+
34+
@Tool(
35+
name = "get_domains",
36+
description =
37+
"Get available data domains in the datasource. Call this tool first to discover"
38+
+ " what domains are available before querying tables.")
39+
public List<String> getDomains() {
40+
return domainService.listDomainNames();
41+
}
42+
}

‎data-agent-backend/src/main/java/io/github/malonetalk/agent/tools/GetTablesTool.java‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package io.github.malonetalk.agent.tools;
1919

2020
import io.agentscope.core.tool.Tool;
21+
import io.agentscope.core.tool.ToolParam;
2122
import io.github.malonetalk.entity.Datasource;
2223
import io.github.malonetalk.entity.TableInfo;
2324
import io.github.malonetalk.enums.Status;
@@ -37,8 +38,22 @@ public class GetTablesTool implements MarkAgentTool {
3738
private final DatasourceService dataSourceService;
3839
private final TableSemanticService tableSemanticService;
3940

40-
@Tool(name = "get_tables", description = "获取数据库中的表信息,包括表名和表描述")
41-
public List<TableInfo> getTables() {
41+
@Tool(
42+
name = "get_tables",
43+
description =
44+
"Get table information from the database, including table name and description."
45+
+ " Optionally filter by domains; returns all tables if domains is not"
46+
+ " provided. It is recommended to call get_domains first to discover"
47+
+ " available domains.")
48+
public List<TableInfo> getTables(
49+
@ToolParam(
50+
name = "domains",
51+
description =
52+
"Optional list of domain names. Only tables belonging to these"
53+
+ " domains will be returned. If not provided or empty,"
54+
+ " returns all tables.",
55+
required = false)
56+
List<String> domains) {
4257
List<Datasource> activeDataSources =
4358
dataSourceService.findByStatus(Status.ACTIVE.getCode());
4459

@@ -54,6 +69,6 @@ public List<TableInfo> getTables() {
5469
}
5570

5671
Datasource dataSource = activeDataSources.get(0);
57-
return tableSemanticService.listTableInfosByDatasourceId(dataSource.getId());
72+
return tableSemanticService.listTableInfosByDomains(dataSource.getId(), domains);
5873
}
5974
}

‎data-agent-backend/src/main/java/io/github/malonetalk/common/SemanticConstants.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public final class SemanticConstants {
2222
public static final String RELATION_KEY_SEPARATOR = "|";
2323
public static final String SORT_ORDER_ASC = "asc";
2424
public static final String SORT_ORDER_DESC = "desc";
25+
public static final String DEFAULT_DOMAIN = "default";
2526

2627
private SemanticConstants() {}
2728
}

‎data-agent-backend/src/main/java/io/github/malonetalk/config/DataSourceConfig.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package io.github.malonetalk.config;
1919

20+
import com.fasterxml.jackson.databind.ObjectMapper;
2021
import com.zaxxer.hikari.HikariConfig;
2122
import com.zaxxer.hikari.HikariDataSource;
2223
import javax.sql.DataSource;
@@ -66,4 +67,9 @@ public DataSource dataSource() {
6667

6768
return new HikariDataSource(config);
6869
}
70+
71+
@Bean
72+
public ObjectMapper objectMapper() {
73+
return new ObjectMapper();
74+
}
6975
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.controller;
19+
20+
import io.github.malonetalk.common.Result;
21+
import io.github.malonetalk.dto.DomainCreateRequest;
22+
import io.github.malonetalk.dto.DomainPageQuery;
23+
import io.github.malonetalk.dto.DomainUpdateRequest;
24+
import io.github.malonetalk.dto.pagination.PageResponse;
25+
import io.github.malonetalk.entity.DomainInfo;
26+
import io.github.malonetalk.service.DomainService;
27+
import jakarta.validation.Valid;
28+
import lombok.RequiredArgsConstructor;
29+
import org.springframework.web.bind.annotation.DeleteMapping;
30+
import org.springframework.web.bind.annotation.GetMapping;
31+
import org.springframework.web.bind.annotation.PathVariable;
32+
import org.springframework.web.bind.annotation.PostMapping;
33+
import org.springframework.web.bind.annotation.PutMapping;
34+
import org.springframework.web.bind.annotation.RequestBody;
35+
import org.springframework.web.bind.annotation.RequestMapping;
36+
import org.springframework.web.bind.annotation.RestController;
37+
38+
@RestController
39+
@RequestMapping("/api/domains")
40+
@RequiredArgsConstructor
41+
public class DomainController {
42+
43+
private final DomainService domainService;
44+
45+
@GetMapping
46+
public Result<PageResponse<DomainInfo>> findDomains(@Valid DomainPageQuery query) {
47+
return Result.success(domainService.getDomainPage(query));
48+
}
49+
50+
@GetMapping("/{id}")
51+
public Result<DomainInfo> findById(@PathVariable Integer id) {
52+
if (id == null || id < 0) {
53+
return Result.error(400, "ID必须为非负数");
54+
}
55+
DomainInfo domain = domainService.findById(id);
56+
if (domain == null) {
57+
return Result.error(404, "领域不存在");
58+
}
59+
return Result.success(domain);
60+
}
61+
62+
@PostMapping
63+
public Result<DomainInfo> create(@Valid @RequestBody DomainCreateRequest request) {
64+
return Result.success(domainService.create(request));
65+
}
66+
67+
@PutMapping("/{id}")
68+
public Result<DomainInfo> update(
69+
@PathVariable Integer id, @Valid @RequestBody DomainUpdateRequest request) {
70+
if (id == null || id < 0) {
71+
return Result.error(400, "ID必须为非负数");
72+
}
73+
return Result.success(domainService.update(id, request));
74+
}
75+
76+
@DeleteMapping("/{id}")
77+
public Result<Boolean> delete(@PathVariable Integer id) {
78+
if (id == null || id < 0) {
79+
return Result.error(400, "ID必须为非负数");
80+
}
81+
domainService.delete(id);
82+
return Result.success(true);
83+
}
84+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.dto;
19+
20+
import jakarta.validation.constraints.NotBlank;
21+
22+
public record DomainCreateRequest(
23+
@NotBlank(message = "领域名称不能为空") String name, String description) {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.dto;
19+
20+
import jakarta.validation.constraints.Min;
21+
import jakarta.validation.constraints.Pattern;
22+
23+
public record DomainPageQuery(
24+
@Min(1) Integer page,
25+
@Min(1) Integer pageSize,
26+
String keyword,
27+
@Pattern(regexp = "^(?i)(asc|desc)$", message = "sortOrder must be asc or desc.")
28+
String sortOrder) {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.dto;
19+
20+
import jakarta.validation.constraints.NotBlank;
21+
22+
public record DomainUpdateRequest(
23+
@NotBlank(message = "领域名称不能为空") String name, String description) {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.entity;
19+
20+
import java.time.LocalDateTime;
21+
import lombok.Data;
22+
23+
@Data
24+
public class DomainInfo {
25+
26+
private Integer id;
27+
private String name;
28+
private String description;
29+
private LocalDateTime createTime;
30+
private LocalDateTime updateTime;
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2026 github.com/MaloneTalk
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
* limitations under the License.
17+
*/
18+
package io.github.malonetalk.mapper;
19+
20+
import io.github.malonetalk.dto.DomainPageQuery;
21+
import io.github.malonetalk.entity.DomainInfo;
22+
import java.util.List;
23+
import org.apache.ibatis.annotations.Mapper;
24+
import org.apache.ibatis.annotations.Param;
25+
26+
@Mapper
27+
public interface DomainInfoMapper {
28+
29+
int insert(DomainInfo domainInfo);
30+
31+
int update(DomainInfo domainInfo);
32+
33+
int deleteByIds(@Param("ids") List<Integer> ids);
34+
35+
List<DomainInfo> selectAll();
36+
37+
List<DomainInfo> selectPage(
38+
@Param("query") DomainPageQuery query, @Param("sortDescending") boolean sortDescending);
39+
40+
DomainInfo selectById(@Param("id") Integer id);
41+
42+
DomainInfo selectByName(@Param("name") String name);
43+
}

0 commit comments

Comments
 (0)