Merge branch 'main' into update-tts-voice-data

This commit is contained in:
wengzh
2026-03-02 16:50:19 +08:00
committed by GitHub
32 changed files with 867 additions and 27 deletions
@@ -245,4 +245,9 @@ public interface ErrorCode {
int DEVICE_NOT_EXIST = 10194; // 设备不存在
int OTA_UPLOAD_COUNT_EXCEED = 10195; // OTA上传次数超过限制
// 智能体标签相关错误码
int AGENT_TAG_NAME_DUPLICATE = 10196; // 标签名称已存在
int AGENT_TAG_NAME_EMPTY = 10197; // 标签名称不能为空
int AGENT_TAG_NOT_EXIST = 10198; // 标签不存在
}
@@ -42,6 +42,9 @@ import xiaozhi.modules.agent.dto.AgentMemoryDTO;
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
import xiaozhi.modules.agent.entity.AgentEntity;
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
import xiaozhi.modules.agent.dto.AgentTagDTO;
import xiaozhi.modules.agent.entity.AgentTagEntity;
import xiaozhi.modules.agent.service.AgentTagService;
import xiaozhi.modules.agent.service.AgentChatAudioService;
import xiaozhi.modules.agent.service.AgentChatHistoryService;
import xiaozhi.modules.agent.service.AgentChatSummaryService;
@@ -69,6 +72,7 @@ public class AgentController {
private final AgentContextProviderService agentContextProviderService;
private final AgentChatSummaryService agentChatSummaryService;
private final RedisUtils redisUtils;
private final AgentTagService agentTagService;
@GetMapping("/list")
@Operation(summary = "获取用户智能体列表")
@@ -77,7 +81,7 @@ public class AgentController {
@RequestParam(value = "keyword", required = false) String keyword,
@RequestParam(value = "searchType", defaultValue = "name") String searchType) {
UserDetail user = SecurityUser.getUser();
// 直接调用整合后的getUserAgents方法,无需再区分搜索和普通查询
List<AgentDTO> agents = agentService.getUserAgents(user.getId(), keyword, searchType);
return new Result<List<AgentDTO>>().ok(agents);
@@ -275,6 +279,50 @@ public class AgentController {
.body(audioData);
}
@PostMapping("/tag")
@Operation(summary = "创建标签")
@RequiresPermissions("sys:role:normal")
public Result<AgentTagEntity> createTag(@RequestBody Map<String, String> params) {
String tagName = params.get("tagName");
if (StringUtils.isBlank(tagName)) {
return new Result<AgentTagEntity>().error("标签名称不能为空");
}
AgentTagEntity tag = agentTagService.saveTag(tagName);
return new Result<AgentTagEntity>().ok(tag);
}
@GetMapping("/tag/list")
@Operation(summary = "获取所有标签列表")
@RequiresPermissions("sys:role:normal")
public Result<List<AgentTagDTO>> getAllTags() {
List<AgentTagDTO> tags = agentTagService.getAllTags();
return new Result<List<AgentTagDTO>>().ok(tags);
}
@DeleteMapping("/tag/{id}")
@Operation(summary = "删除标签")
@RequiresPermissions("sys:role:normal")
public Result<Void> deleteTag(@PathVariable String id) {
agentTagService.deleteTag(id);
return new Result<Void>().ok(null);
}
@GetMapping("/{id}/tags")
@Operation(summary = "获取智能体的标签")
@RequiresPermissions("sys:role:normal")
public Result<List<AgentTagDTO>> getAgentTags(@PathVariable String id) {
List<AgentTagDTO> tags = agentTagService.getTagsByAgentId(id);
return new Result<List<AgentTagDTO>>().ok(tags);
}
@PutMapping("/{id}/tags")
@Operation(summary = "保存智能体的标签")
@RequiresPermissions("sys:role:normal")
public Result<Void> saveAgentTags(@PathVariable String id, @RequestBody Map<String, Object> params) {
List<String> tagIds = (List<String>) params.get("tagIds");
List<String> tagNames = (List<String>) params.get("tagNames");
agentTagService.saveAgentTags(id, tagIds, tagNames);
return new Result<Void>().ok(null);
}
}
@@ -0,0 +1,24 @@
package xiaozhi.modules.agent.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import xiaozhi.common.dao.BaseDao;
import xiaozhi.modules.agent.entity.AgentTagEntity;
import java.util.List;
@Mapper
public interface AgentTagDao extends BaseDao<AgentTagEntity> {
List<AgentTagEntity> selectByAgentId(@Param("agentId") String agentId);
List<AgentTagEntity> selectByAgentIds(@Param("agentIds") List<String> agentIds);
List<AgentTagEntity> selectAll();
List<String> selectAgentIdsByTagName(@Param("tagName") String tagName);
List<AgentTagEntity> selectByTagNames(@Param("tagNames") List<String> tagNames);
int batchInsert(@Param("list") List<AgentTagEntity> tagList);
}
@@ -0,0 +1,18 @@
package xiaozhi.modules.agent.dao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import xiaozhi.common.dao.BaseDao;
import xiaozhi.modules.agent.entity.AgentTagRelationEntity;
import java.util.List;
@Mapper
public interface AgentTagRelationDao extends BaseDao<AgentTagRelationEntity> {
int deleteByAgentId(@Param("agentId") String agentId);
int insertRelation(AgentTagRelationEntity relation);
int batchInsertRelation(@Param("list") List<AgentTagRelationEntity> relations);
}
@@ -5,6 +5,7 @@ import java.util.List;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import xiaozhi.modules.agent.dto.AgentTagDTO;
/**
* 智能体数据传输对象
@@ -46,4 +47,7 @@ public class AgentDTO {
@Schema(description = "设备数量", example = "10")
private Integer deviceCount;
@Schema(description = "标签列表")
private List<AgentTagDTO> tags;
}
@@ -0,0 +1,20 @@
package xiaozhi.modules.agent.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "智能体标签DTO")
public class AgentTagDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "标签ID")
private String id;
@Schema(description = "标签名称")
private String tagName;
}
@@ -0,0 +1,41 @@
package xiaozhi.modules.agent.entity;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@TableName("ai_agent_tag")
@Schema(description = "智能体标签")
public class AgentTagEntity {
@TableId(type = IdType.ASSIGN_UUID)
@Schema(description = "主键")
private String id;
@Schema(description = "标签名称")
private String tagName;
@Schema(description = "排序")
private Integer sort;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建时间")
private Date createdAt;
@Schema(description = "更新者")
private Long updater;
@Schema(description = "更新时间")
private Date updatedAt;
@Schema(description = "删除标记")
private Integer deleted;
}
@@ -0,0 +1,38 @@
package xiaozhi.modules.agent.entity;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@TableName("ai_agent_tag_relation")
@Schema(description = "智能体标签关联")
public class AgentTagRelationEntity {
@TableId(type = IdType.ASSIGN_UUID)
@Schema(description = "主键")
private String id;
@Schema(description = "智能体ID")
private String agentId;
@Schema(description = "标签ID")
private String tagId;
@Schema(description = "创建者")
private Long creator;
@Schema(description = "创建时间")
private Date createdAt;
@Schema(description = "更新者")
private Long updater;
@Schema(description = "更新时间")
private Date updatedAt;
}
@@ -0,0 +1,25 @@
package xiaozhi.modules.agent.service;
import java.util.List;
import xiaozhi.modules.agent.dto.AgentTagDTO;
import xiaozhi.modules.agent.entity.AgentTagEntity;
public interface AgentTagService {
AgentTagEntity saveTag(String tagName);
void deleteTag(String tagId);
List<AgentTagDTO> getTagsByAgentId(String agentId);
void saveAgentTags(String agentId, List<String> tagIds, List<String> tagNames);
void deleteAgentTags(String agentId);
List<AgentTagDTO> getTagsByAgentIds(List<String> agentIds);
List<AgentTagDTO> getAllTags();
List<String> getAgentIdsByTagName(String tagName);
}
@@ -31,17 +31,21 @@ import xiaozhi.common.utils.ConvertUtils;
import xiaozhi.common.utils.JsonUtils;
import xiaozhi.common.utils.ToolUtil;
import xiaozhi.modules.agent.dao.AgentDao;
import xiaozhi.modules.agent.dao.AgentTagDao;
import xiaozhi.modules.agent.dto.AgentCreateDTO;
import xiaozhi.modules.agent.dto.AgentDTO;
import xiaozhi.modules.agent.dto.AgentTagDTO;
import xiaozhi.modules.agent.dto.AgentUpdateDTO;
import xiaozhi.modules.agent.entity.AgentContextProviderEntity;
import xiaozhi.modules.agent.entity.AgentEntity;
import xiaozhi.modules.agent.entity.AgentPluginMapping;
import xiaozhi.modules.agent.entity.AgentTagEntity;
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
import xiaozhi.modules.agent.service.AgentChatHistoryService;
import xiaozhi.modules.agent.service.AgentContextProviderService;
import xiaozhi.modules.agent.service.AgentPluginMappingService;
import xiaozhi.modules.agent.service.AgentService;
import xiaozhi.modules.agent.service.AgentTagService;
import xiaozhi.modules.agent.service.AgentTemplateService;
import xiaozhi.modules.agent.vo.AgentInfoVO;
import xiaozhi.modules.device.entity.DeviceEntity;
@@ -59,6 +63,7 @@ import xiaozhi.modules.timbre.service.TimbreService;
@AllArgsConstructor
public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> implements AgentService {
private final AgentDao agentDao;
private final AgentTagDao agentTagDao;
private final TimbreService timbreModelService;
private final ModelConfigService modelConfigService;
private final RedisUtils redisUtils;
@@ -68,6 +73,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
private final AgentTemplateService agentTemplateService;
private final ModelProviderService modelProviderService;
private final AgentContextProviderService agentContextProviderService;
private final AgentTagService agentTagService;
@Override
public PageData<AgentEntity> adminAgentList(Map<String, Object> params) {
@@ -151,8 +157,16 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
return new ArrayList<>();
}
} else {
// 按名称搜索
queryWrapper.like("agent_name", keyword);
// 按名称搜索(默认):同时搜索智能体名称和标签名
List<String> tagAgentIds = agentTagService.getAgentIdsByTagName(keyword);
if (ToolUtil.isNotEmpty(tagAgentIds)) {
queryWrapper.and(wrapper -> wrapper
.like("agent_name", keyword)
.or()
.in("id", tagAgentIds));
} else {
queryWrapper.like("agent_name", keyword);
}
}
}
@@ -193,6 +207,19 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
// 获取设备数量
dto.setDeviceCount(getDeviceCountByAgentId(agent.getId()));
// 获取标签列表
List<AgentTagEntity> tags = agentTagDao.selectByAgentId(agent.getId());
if (ToolUtil.isNotEmpty(tags)) {
dto.setTags(tags.stream().map(this::convertTagToDTO).collect(Collectors.toList()));
}
return dto;
}
private AgentTagDTO convertTagToDTO(AgentTagEntity entity) {
AgentTagDTO dto = new AgentTagDTO();
dto.setId(entity.getId());
dto.setTagName(entity.getTagName());
return dto;
}
@@ -0,0 +1,199 @@
package xiaozhi.modules.agent.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.AllArgsConstructor;
import xiaozhi.common.exception.ErrorCode;
import xiaozhi.common.exception.RenException;
import xiaozhi.common.service.impl.BaseServiceImpl;
import xiaozhi.modules.agent.dao.AgentTagDao;
import xiaozhi.modules.agent.dao.AgentTagRelationDao;
import xiaozhi.modules.agent.dto.AgentTagDTO;
import xiaozhi.modules.agent.entity.AgentTagEntity;
import xiaozhi.modules.agent.entity.AgentTagRelationEntity;
import xiaozhi.modules.agent.service.AgentTagService;
@Service
@AllArgsConstructor
public class AgentTagServiceImpl extends BaseServiceImpl<AgentTagDao, AgentTagEntity> implements AgentTagService {
private final AgentTagRelationDao agentTagRelationDao;
@Override
public AgentTagEntity saveTag(String tagName) {
if (tagName == null || tagName.trim().isEmpty()) {
throw new RenException(ErrorCode.AGENT_TAG_NAME_EMPTY);
}
QueryWrapper<AgentTagEntity> wrapper = new QueryWrapper<>();
wrapper.eq("tag_name", tagName);
wrapper.eq("deleted", 0);
AgentTagEntity existTag = baseDao.selectOne(wrapper);
if (existTag != null) {
return existTag;
}
AgentTagEntity tag = new AgentTagEntity();
tag.setId(UUID.randomUUID().toString().replace("-", ""));
tag.setTagName(tagName);
tag.setSort(0);
tag.setCreatedAt(new Date());
tag.setUpdatedAt(new Date());
tag.setDeleted(0);
baseDao.insert(tag);
return tag;
}
@Override
public void deleteTag(String tagId) {
AgentTagEntity tag = baseDao.selectById(tagId);
if (tag != null) {
tag.setDeleted(1);
tag.setUpdatedAt(new Date());
baseDao.updateById(tag);
}
}
@Override
public List<AgentTagDTO> getTagsByAgentId(String agentId) {
List<AgentTagEntity> tags = baseDao.selectByAgentId(agentId);
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveAgentTags(String agentId, List<String> tagIds, List<String> tagNames) {
agentTagRelationDao.deleteByAgentId(agentId);
List<AgentTagEntity> currentTags = baseDao.selectByAgentId(agentId);
List<String> currentTagNames = currentTags.stream()
.map(AgentTagEntity::getTagName)
.collect(Collectors.toList());
List<String> allTagIds = new ArrayList<>();
List<String> newTagNames = new ArrayList<>();
if (tagNames != null && !tagNames.isEmpty()) {
Set<String> addedTagNames = new HashSet<>();
for (String tagName : tagNames) {
if (tagName == null || tagName.trim().isEmpty()) {
throw new RenException(ErrorCode.AGENT_TAG_NAME_EMPTY);
}
if (currentTagNames.contains(tagName) || addedTagNames.contains(tagName)) {
throw new RenException(ErrorCode.AGENT_TAG_NAME_DUPLICATE);
}
addedTagNames.add(tagName);
newTagNames.add(tagName);
}
}
List<AgentTagEntity> existTags = new ArrayList<>();
if (!newTagNames.isEmpty()) {
existTags = baseDao.selectByTagNames(newTagNames);
}
List<String> existTagNames = existTags.stream()
.map(AgentTagEntity::getTagName)
.collect(Collectors.toList());
List<AgentTagEntity> tagsToInsert = new ArrayList<>();
for (String tagName : newTagNames) {
if (!existTagNames.contains(tagName)) {
AgentTagEntity tag = new AgentTagEntity();
tag.setId(UUID.randomUUID().toString().replace("-", ""));
tag.setTagName(tagName);
tag.setSort(0);
tag.setDeleted(0);
tag.setCreatedAt(new Date());
tag.setUpdatedAt(new Date());
tagsToInsert.add(tag);
}
}
if (!tagsToInsert.isEmpty()) {
baseDao.batchInsert(tagsToInsert);
for (AgentTagEntity tag : tagsToInsert) {
allTagIds.add(tag.getId());
}
}
for (AgentTagEntity existTag : existTags) {
if (!allTagIds.contains(existTag.getId())) {
allTagIds.add(existTag.getId());
}
}
if (tagIds != null && !tagIds.isEmpty()) {
List<AgentTagEntity> tagIdEntities = baseDao.selectBatchIds(tagIds);
for (AgentTagEntity tag : tagIdEntities) {
if (tag != null && (currentTagNames.contains(tag.getTagName()) ||
newTagNames.contains(tag.getTagName()))) {
throw new RenException(ErrorCode.AGENT_TAG_NAME_DUPLICATE);
}
}
allTagIds.addAll(tagIds);
}
if (allTagIds.isEmpty()) {
return;
}
List<AgentTagRelationEntity> relations = new ArrayList<>();
Date now = new Date();
for (String tagId : allTagIds) {
AgentTagRelationEntity relation = new AgentTagRelationEntity();
relation.setId(UUID.randomUUID().toString().replace("-", ""));
relation.setAgentId(agentId);
relation.setTagId(tagId);
relation.setCreatedAt(now);
relation.setUpdatedAt(now);
relations.add(relation);
}
agentTagRelationDao.batchInsertRelation(relations);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAgentTags(String agentId) {
agentTagRelationDao.deleteByAgentId(agentId);
}
@Override
public List<AgentTagDTO> getTagsByAgentIds(List<String> agentIds) {
if (agentIds == null || agentIds.isEmpty()) {
return List.of();
}
List<AgentTagEntity> tags = baseDao.selectByAgentIds(agentIds);
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
}
@Override
public List<AgentTagDTO> getAllTags() {
List<AgentTagEntity> tags = baseDao.selectAll();
return tags.stream().map(this::convertToDTO).collect(Collectors.toList());
}
@Override
public List<String> getAgentIdsByTagName(String tagName) {
return baseDao.selectAgentIdsByTagName(tagName);
}
private AgentTagDTO convertToDTO(AgentTagEntity entity) {
AgentTagDTO dto = new AgentTagDTO();
dto.setId(entity.getId());
dto.setTagName(entity.getTagName());
return dto;
}
}
@@ -0,0 +1,29 @@
-- 标签表
CREATE TABLE IF NOT EXISTS ai_agent_tag (
id VARCHAR(32) NOT NULL COMMENT '主键',
tag_name VARCHAR(64) NOT NULL COMMENT '标签名称',
sort INT UNSIGNED DEFAULT 0 COMMENT '排序',
creator BIGINT COMMENT '创建者',
created_at DATETIME COMMENT '创建时间',
updater BIGINT COMMENT '更新者',
updated_at DATETIME COMMENT '更新时间',
deleted TINYINT DEFAULT 0 COMMENT '删除标记',
PRIMARY KEY (id),
UNIQUE KEY uk_tag_name (tag_name),
INDEX idx_sort (sort)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='智能体标签表';
-- 智能体标签关联表
CREATE TABLE IF NOT EXISTS ai_agent_tag_relation (
id VARCHAR(32) NOT NULL COMMENT '主键',
agent_id VARCHAR(32) NOT NULL COMMENT '智能体ID',
tag_id VARCHAR(32) NOT NULL COMMENT '标签ID',
creator BIGINT COMMENT '创建者',
created_at DATETIME COMMENT '创建时间',
updater BIGINT COMMENT '更新者',
updated_at DATETIME COMMENT '更新时间',
PRIMARY KEY (id),
UNIQUE KEY uk_agent_tag (agent_id, tag_id),
INDEX idx_agent_id (agent_id),
INDEX idx_tag_id (tag_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='智能体标签关联表';
@@ -543,3 +543,9 @@ databaseChangeLog:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202602271137.sql
id: 202602281000
author: rainv123
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202602281000.sql
@@ -201,4 +201,7 @@
10192=\u9002\u914D\u5668\u7C7B\u578B\u672A\u627E\u5230
10193=\u8BBE\u5907ID\u4E0D\u80FD\u4E3A\u7A7A
10194=\u8BBE\u5907\u4E0D\u5B58\u5728\u6216\u4E0D\u5728\u7EBF
10195=OTA\u4E0A\u4F20\u6B21\u6570\u8D85\u8FC7\u9650\u5236
10195=OTA\u4E0A\u4F20\u6B21\u6570\u8D85\u8FC7\u9650\u5236
10196=\u6807\u7B7E\u540D\u79F0\u5DF2\u5B58\u5728
10197=\u6807\u7B7E\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A
10198=\u6807\u7B7E\u4E0D\u5B58\u5728
@@ -201,4 +201,7 @@
10192=Adaptertyp nicht gefunden
10193=Adapter-ID darf nicht leer sein
10194=Adapter nicht gefunden oder nicht online
10195=OTA-Upload-Anzahl \u00FCberschreitet das Limit
10195=OTA-Upload-Anzahl \u00FCberschreitet das Limit
10196=Tag-Name existiert bereits
10197=Tag-Name darf nicht leer sein
10198=Tag nicht gefunden
@@ -201,4 +201,7 @@
10192=Adapter type not found
10193=Device ID cannot be empty
10194=Device not found or not online
10195=OTA upload times exceed the limit
10195=OTA upload times exceed the limit
10196=Tag name already exists
10197=Tag name cannot be empty
10198=Tag not found
@@ -201,4 +201,7 @@
10192=Kh\u00F4ng t\u00ECm th\u1EA5y lo\u1EA1i b\u1ED9 chuy\u1EC3n \u0111\u1ED5i
10193=ID thi\u1EBFt b\u1ECB kh\u00F4ng th\u1EC3 tr\u1ED1ng
10194=Kh\u00F4ng t\u00ECm th\u1EA5y thi\u1EBFt b\u1ECB ho\u1EB7c thi\u1EBFt b\u1ECB kh\u00F4ng tr\u1EF1c tuy\u1EBFn
10195=S\u1ED1 l\u1EA7n t\u1EA3i l\u00EAn OTA v\u01B0\u1EE3t qu\u00E1 gi\u1EDBi h\u1EA1n
10195=S\u1ED1 l\u1EA7n t\u1EA3i l\u00EAn OTA v\u01B0\u1EE3t qu\u00E1 gi\u1EDBi h\u1EA1n
10196=T\u00EAn th\u1EB9 \u0111\u00E3 t\u1ED3n t\u1EA1i
10197=T\u00EAn th\u1EB9 kh\u00F4ng th\u1EC3 \u0111\u1EC3 tr\u1ED1ng
10198=Kh\u00F4ng t\u00ECm th\u1EA5y th\u1EB9
@@ -201,4 +201,7 @@
10192=\u9002\u914D\u5668\u985E\u578B\u672A\u627E\u5230
10193=\u8A2D\u5099ID\u4E0D\u80FD\u4E3A\u7A7A
10194=\u8A2D\u5099\u4E0D\u5B58\u5728\u6216\u672A\u5728\u7DDA
10195=OTA\u4E0A\u4F20\u6B21\u6578\u8D85\u904E\u9650\u5236
10195=OTA\u4E0A\u4F20\u6B21\u6578\u8D85\u904E\u9650\u5236
10196=\u6A19\u7C64\u540D\u7A31\u5DF2\u5B58\u5728
10197=\u6A19\u7C64\u540D\u7A31\u4E0D\u80FD\u4E3A\u7A7A
10198=\u6A19\u7C64\u4E0D\u5B58\u5728
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xiaozhi.modules.agent.dao.AgentTagDao">
<select id="selectByAgentId" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
SELECT t.id, t.tag_name AS tagName, t.sort
FROM ai_agent_tag t
INNER JOIN ai_agent_tag_relation r ON t.id = r.tag_id
WHERE r.agent_id = #{agentId} AND t.deleted = 0
ORDER BY t.sort ASC
</select>
<select id="selectByAgentIds" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
SELECT t.id, t.tag_name AS tagName, t.sort, r.agent_id AS agentId
FROM ai_agent_tag t
INNER JOIN ai_agent_tag_relation r ON t.id = r.tag_id
WHERE r.agent_id IN
<foreach collection="agentIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND t.deleted = 0
ORDER BY t.sort ASC
</select>
<select id="selectAll" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
SELECT id, tag_name AS tagName, sort
FROM ai_agent_tag
WHERE deleted = 0
ORDER BY sort ASC
</select>
<select id="selectAgentIdsByTagName" resultType="java.lang.String">
SELECT r.agent_id
FROM ai_agent_tag_relation r
INNER JOIN ai_agent_tag t ON r.tag_id = t.id
WHERE t.tag_name LIKE CONCAT('%', #{tagName}, '%') AND t.deleted = 0
</select>
<select id="selectByTagNames" resultType="xiaozhi.modules.agent.entity.AgentTagEntity">
SELECT id, tag_name AS tagName, sort
FROM ai_agent_tag
WHERE deleted = 0 AND tag_name IN
<foreach collection="tagNames" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO ai_agent_tag (id, tag_name, sort, deleted, creator, created_at, updater, updated_at)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.id}, #{item.tagName}, #{item.sort}, #{item.deleted}, #{item.creator}, #{item.createdAt}, #{item.updater}, #{item.updatedAt})
</foreach>
</insert>
</mapper>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xiaozhi.modules.agent.dao.AgentTagRelationDao">
<delete id="deleteByAgentId">
DELETE FROM ai_agent_tag_relation WHERE agent_id = #{agentId}
</delete>
<insert id="insertRelation" parameterType="xiaozhi.modules.agent.entity.AgentTagRelationEntity">
INSERT INTO ai_agent_tag_relation (id, agent_id, tag_id, creator, created_at, updater, updated_at)
VALUES (#{id}, #{agentId}, #{tagId}, #{creator}, #{createdAt}, #{updater}, #{updatedAt})
</insert>
<insert id="batchInsertRelation" parameterType="java.util.List">
INSERT INTO ai_agent_tag_relation (id, agent_id, tag_id, creator, created_at, updater, updated_at)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.id}, #{item.agentId}, #{item.tagId}, #{item.creator}, #{item.createdAt}, #{item.updater}, #{item.updatedAt})
</foreach>
</insert>
</mapper>
+31
View File
@@ -398,4 +398,35 @@ export default {
});
}).send();
},
// 获取智能体标签
getAgentTags(agentId, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/agent/${agentId}/tags`)
.method('GET')
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.getAgentTags(agentId, callback);
});
}).send();
},
// 保存智能体标签
saveAgentTags(agentId, tags, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/agent/${agentId}/tags`)
.method('PUT')
.data(tags)
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.saveAgentTags(agentId, tags, callback);
});
}).send();
},
}
@@ -14,7 +14,7 @@
<div style="color: red;display: inline-block;">*</div> {{ $t('addAgentDialog.agentName') }}
</div>
<div class="input-46" style="margin-top: 12px;">
<el-input ref="inputRef" :placeholder="$t('addAgentDialog.placeholder')" v-model="wisdomBodyName" @keyup.enter.native="confirm" />
<el-input maxLength="64" ref="inputRef" :placeholder="$t('addAgentDialog.placeholder')" v-model="wisdomBodyName" @keyup.enter.native="confirm" />
</div>
</div>
<div style="display: flex;margin: 15px 15px;gap: 7px;">
+80 -4
View File
@@ -1,13 +1,15 @@
<template>
<div class="device-item">
<div style="display: flex;justify-content: space-between;">
<div style="font-weight: 700;font-size: 18px;text-align: left;color: #3d4566;">
<el-tooltip :content="device.agentName" placement="top" effect="light">
<div class="device-item-title">
{{ device.agentName }}
</div>
</el-tooltip>
<div>
<img src="@/assets/home/delete.png" alt="" style="width: 18px;height: 18px;margin-right: 10px;"
@click.stop="handleDelete" />
<el-tooltip class="item" effect="dark" :content="device.systemPrompt" placement="top"
<el-tooltip class="item" effect="light" :content="device.systemPrompt" placement="top"
popper-class="custom-tooltip">
<img src="@/assets/home/info.png" alt="" style="width: 18px;height: 18px;" />
</el-tooltip>
@@ -39,6 +41,11 @@
</div>
<div class="version-info">
<div>{{ $t('home.lastConversation') }}{{ formattedLastConnectedTime }}</div>
<div ref="scrollRef" class="version-info-scroll">
<div ref="tagsRef" class="version-info-tags">
<el-tag v-for="(tag, index) in tags" :key="index" size="mini">{{ tag }}</el-tag>
</div>
</div>
</div>
</div>
</template>
@@ -81,6 +88,10 @@ export default {
} else {
return this.device.lastConnectedAt;
}
},
tags() {
if (!this.device.tags) return [];
return this.device.tags.map((tag) => tag.tagName);
}
},
methods: {
@@ -102,16 +113,45 @@ export default {
}
this.$emit('chat-history', { agentId: this.device.agentId, agentName: this.device.agentName })
}
},
watch: {
tags: {
handler(newTags) {
if (newTags.length === 0) return;
this.$nextTick(() => {
const scrollWidth = this.$refs.scrollRef.clientWidth;
const tagsWidth = this.$refs.tagsRef.clientWidth;
if (tagsWidth < scrollWidth) {
this.$refs.tagsRef.style.width = '100%';
this.$refs.tagsRef.style.justifyContent = 'flex-end';
} else {
this.$refs.tagsRef.style.width = 'fit-content';
this.$refs.tagsRef.style.justifyContent = 'flex-start';
}
})
},
immediate: true
}
}
}
</script>
<style scoped>
<style lang="scss" scoped>
.device-item {
width: 342px;
border-radius: 20px;
background: #fafcfe;
padding: 22px;
padding: 22px 22px 14px;
box-sizing: border-box;
&-title {
flex: 1;
font-weight: bold;
font-size: 18px;
color: #3d4566;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.device-name {
@@ -142,6 +182,42 @@ export default {
font-size: 12px;
color: #979db1;
font-weight: 400;
> div {
&:first-of-type {
margin-top: 5px;
}
}
&-scroll {
height: 26px;
margin-left: 20px;
flex: 1;
overflow-x: auto;
padding-bottom: 4px;
&::-webkit-scrollbar {
height: 6px;
background: #e6ebff;
}
&::-webkit-scrollbar-thumb {
background: #409EFF;
border-radius: 8px;
}
}
&-tags {
width: fit-content;
display: flex;
gap: 6px;
}
}
.more-tag {
cursor: pointer;
flex-shrink: 0;
}
.all-tags-popover {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.disabled-btn {
+19 -2
View File
@@ -71,8 +71,14 @@
{{ $t('ttsModel.delete') }}
</el-button>
</template>
<el-button v-else type="success" size="mini" @click="saveEdit(scope.row)" class="save-Tts">{{ $t('ttsModel.save') }}
<template v-else>
<el-button type="success" size="mini" @click="cancelEdit(scope.row)" class="save-Tts">
{{ $t('button.cancel') }}
</el-button>
<el-button type="success" size="mini" @click="saveEdit(scope.row)" class="save-Tts">
{{ $t('ttsModel.save') }}
</el-button>
</template>
</template>
</el-table-column>
</el-table>
@@ -340,6 +346,17 @@ export default {
this.$set(row, 'originalData', { ...row });
},
cancelEdit(row) {
// 通过新增创建的数据,取消编辑时,需要从数组中移除
if (!row.id) {
this.ttsModels.shift(row);
} else {
Object.assign(row, row.originalData);
delete row.originalData;
}
row.editing = false;
},
saveEdit(row) {
if (!row.voiceCode || !row.voiceName || !row.languageType) {
this.$message.error({
@@ -447,7 +464,7 @@ export default {
referenceText: '',
selected: false,
editing: true,
sort: maxSort + 1
sort: 0 // 新增数据默认排序在顶部
};
this.ttsModels.unshift(newRow);
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': 'Systemfunktionsverwaltung',
'header.changePassword': 'Passwort ändern',
'header.logout': 'Abmelden',
'header.searchPlaceholder': 'Namen oder MAC suchen',
'header.searchPlaceholder': 'Name, Tag oder Mac-Suche',
// McpToolCallDialog component text
'mcpToolCall.title': 'Werkzeugaufruf',
@@ -747,6 +747,7 @@ export default {
// Role configuration page text
'roleConfig.title': 'Rollenkonfiguration',
'roleConfig.addTag': 'Neues Label hinzufügen',
'roleConfig.restartNotice': 'Nach dem Speichern der Konfiguration müssen Sie das Gerät neu starten, damit die neue Konfiguration wirksam wird.',
'roleConfig.saveConfig': 'Konfiguration speichern',
'roleConfig.reset': 'Zurücksetzen',
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': 'System Feature Management',
'header.changePassword': 'Change Password',
'header.logout': 'Logout',
'header.searchPlaceholder': 'Search name or mac',
'header.searchPlaceholder': 'Name, tag or MAC search',
// McpToolCallDialog component text
'mcpToolCall.title': 'Tool Call',
@@ -747,6 +747,7 @@ export default {
// Role configuration page text
'roleConfig.title': 'Role Configuration',
'roleConfig.addTag': 'Add New Tag',
'roleConfig.restartNotice': 'After saving the configuration, you need to restart the device for the new configuration to take effect.',
'roleConfig.saveConfig': 'Save Configuration',
'roleConfig.reset': 'Reset',
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': 'Gerenciamento de Funcionalidades do Sistema',
'header.changePassword': 'Alterar Senha',
'header.logout': 'Sair',
'header.searchPlaceholder': 'Pesquisar nome ou MAC',
'header.searchPlaceholder': 'Nome, tag ou pesquisa no Mac',
// Texto do componente McpToolCallDialog
'mcpToolCall.title': 'Chamada de Ferramenta',
@@ -747,6 +747,7 @@ export default {
// Página de configuração de papel
'roleConfig.title': 'Configuração de Papel',
'roleConfig.addTag': 'Adicionar Novo Rótulo',
'roleConfig.restartNotice': 'Após salvar a configuração, é necessário reiniciar o dispositivo para que a nova configuração tenha efeito.',
'roleConfig.saveConfig': 'Salvar Configuração',
'roleConfig.reset': 'Redefinir',
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': 'Cấu hình chức năng hệ thống',
'header.changePassword': 'Đổi mật khẩu',
'header.logout': 'Đăng xuất',
'header.searchPlaceholder': 'Tìm tên hoặc MAC',
'header.searchPlaceholder': 'Tên, thẻ hoặc tìm kiếm mac',
// McpToolCallDialog component text
'mcpToolCall.title': 'Gọi công cụ',
@@ -747,6 +747,7 @@ export default {
// Role configuration page text
'roleConfig.title': 'Vai trò',
'roleConfig.addTag': 'Thêm mới nhãn',
'roleConfig.restartNotice': 'Sau khi lưu cấu hình, bạn cần khởi động lại thiết bị để cấu hình mới có hiệu lực.',
'roleConfig.saveConfig': 'Lưu cấu hình',
'roleConfig.reset': 'Đặt lại',
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': '系统功能配置',
'header.changePassword': '修改密码',
'header.logout': '退出登录',
'header.searchPlaceholder': '输入名称或mac搜索',
'header.searchPlaceholder': '名称、标签或mac搜索',
// McpToolCallDialog组件文本
'mcpToolCall.title': '工具调用',
@@ -747,6 +747,7 @@ export default {
// 角色配置页面文本
'roleConfig.title': '角色配置',
'roleConfig.addTag': '添加新标签',
'roleConfig.restartNotice': '保存配置后,需要重启设备,新的配置才会生效。',
'roleConfig.saveConfig': '保存配置',
'roleConfig.reset': '重置',
+2 -1
View File
@@ -25,7 +25,7 @@ export default {
'header.featureManagement': '系統功能配置',
'header.changePassword': '修改密碼',
'header.logout': '退出登錄',
'header.searchPlaceholder': '輸入名稱或mac搜索',
'header.searchPlaceholder': '名稱、標籤或mac搜索',
// McpToolCallDialog组件文本
'mcpToolCall.title': '工具調用',
@@ -747,6 +747,7 @@ export default {
// 角色配置頁面文本
'roleConfig.title': '角色配置',
'roleConfig.addTag': '添加新標籤',
'roleConfig.restartNotice': '保存配置後,需要重啟設備,新的配置才會生效。',
'roleConfig.saveConfig': '保存配置',
'roleConfig.reset': '重置',
+10
View File
@@ -19,4 +19,14 @@ select:-webkit-autofill:focus {
.el-icon-video-play, .el-icon-video-pause {
font-size: 18px !important;
}
.is-light {
border: 1px solid #e4e7ed !important;
color: #595959;
font-size: 14px;
background: #fafcfe !important;
.popper__arrow {
border-top-color: #e4e7ed !important;
}
}
+129 -6
View File
@@ -11,10 +11,34 @@
<div class="content-area">
<el-card class="config-card" shadow="never">
<div class="config-header">
<div class="header-icon">
<img loading="lazy" src="@/assets/home/setting-user.png" alt="" />
<div class="header-left">
<div class="header-icon">
<img loading="lazy" src="@/assets/home/setting-user.png" alt="" />
</div>
<span class="header-title">{{ form.agentName }}</span>
</div>
<div class="header-tags">
<el-tag
v-for="tag in dynamicTags"
:key="tag.id"
closable
:disable-transitions="false"
@close="handleClose(tag.id)">
{{tag.tagName}}
</el-tag>
<el-input
class="input-new-tag"
v-if="inputVisible"
v-model="inputValue"
ref="saveTagInput"
size="small"
maxLength="64"
@keyup.enter.native="handleInputConfirm"
@blur="handleInputConfirm"
>
</el-input>
<el-button v-else size="small" @click="showInput">+ {{ $t("roleConfig.addTag") }}</el-button>
</div>
<span class="header-title">{{ form.agentName }}</span>
<div class="header-actions">
<div class="hint-text">
<img loading="lazy" src="@/assets/home/info.png" alt="" />
@@ -39,7 +63,7 @@
<el-input
v-model="form.agentName"
class="form-input"
maxlength="10"
maxlength="64"
/>
</el-form-item>
<el-form-item :label="$t('roleConfig.roleTemplate') + ''">
@@ -411,13 +435,23 @@ export default {
vad: false, // 语言检测活动功能状态
asr: false, // 语音识别功能状态
},
dynamicTags: [],
inputVisible: false,
inputValue: ''
};
},
methods: {
goToHome() {
this.$router.push("/home");
},
saveConfig() {
async saveConfig() {
try {
await this.handleSaveAgentTags(this.$route.query.agentId);
} catch (error) {
console.error('保存标签失败:', error);
return;
}
const configData = {
agentCode: this.form.agentCode,
agentName: this.form.agentName,
@@ -468,6 +502,7 @@ export default {
});
}
});
},
resetConfig() {
this.$confirm(i18n.t("roleConfig.confirmReset"), i18n.t("message.info"), {
@@ -496,6 +531,7 @@ export default {
intentModelId: "",
},
};
this.dynamicTags = [];
this.currentFunctions = [];
this.$message.success({
message: i18n.t("roleConfig.resetSuccess"),
@@ -1148,6 +1184,45 @@ export default {
console.error("加载功能状态失败:", error);
}
},
handleClose(id) {
this.dynamicTags = this.dynamicTags.filter((item) => item.id !== id);
},
showInput() {
this.inputVisible = true;
this.$nextTick(_ => {
this.$refs.saveTagInput.$refs.input.focus();
});
},
handleInputConfirm() {
let inputValue = this.inputValue;
if (inputValue) {
const tag = { id: new Date().getTime(), tagName: inputValue };
this.dynamicTags.push(tag);
}
this.inputVisible = false;
this.inputValue = '';
},
getAgentTags(agentId) {
Api.agent.getAgentTags(agentId, ({ data }) => {
if (data.code === 0) {
this.dynamicTags = data.data || [];
}
});
},
handleSaveAgentTags(agentId) {
return new Promise((resolve, reject) => {
const tagNames = this.dynamicTags.map(tag => tag.tagName);
Api.agent.saveAgentTags(agentId, { tagNames }, ({ data }) => {
if (data.code === 0) {
resolve();
} else {
reject(data.msg);
}
});
});
}
},
watch: {
"form.model.ttsModelId": {
@@ -1174,6 +1249,7 @@ export default {
const agentId = this.$route.query.agentId;
if (agentId) {
this.fetchAgentConfig(agentId);
this.getAgentTags(agentId);
this.fetchAllFunctions();
}
this.fetchModelOptions();
@@ -1184,7 +1260,7 @@ export default {
};
</script>
<style scoped>
<style lang="scss" scoped>
.welcome {
min-width: 900px;
height: 100vh;
@@ -1261,6 +1337,48 @@ export default {
font-weight: 700;
font-size: 19px;
color: #3d4566;
justify-content: space-between;
}
.header-left {
display: flex;
align-items: center;
gap: 13px;
flex-shrink: 0;
}
.header-tags {
display: flex;
align-items: center;
gap: 8px;
flex: 1;
min-width: 0;
overflow-x: auto;
padding-bottom: 4px;
&::-webkit-scrollbar {
height: 6px;
background: #e6ebff;
}
&::-webkit-scrollbar-thumb {
background: #409EFF;
border-radius: 8px;
}
}
.header-tags .el-tag {
flex-shrink: 0;
}
.more-tag {
cursor: pointer;
flex-shrink: 0;
}
.all-tags-popover {
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 8px;
}
.header-icon {
@@ -1583,5 +1701,10 @@ export default {
.tts-slider ::v-deep .el-input__inner {
text-align: center;
padding: 0 8px;
.input-new-tag {
width: 90px;
&::v-deep(.el-input__inner) {
width: 90px !important;
}
}
</style>