Merge branch 'manager-plugin-api' of https://github.com/xinnan-tech/xiaozhi-esp32-server into manager-plugin-api

This commit is contained in:
Sakura-RanChen
2025-05-12 16:49:46 +08:00
11 changed files with 124 additions and 63 deletions
@@ -111,6 +111,11 @@ public interface Constant {
*/ */
String FILE_EXTENSION_SEG = "."; String FILE_EXTENSION_SEG = ".";
/**
* 无记忆
*/
String MEMORY_NO_MEM = "Memory_nomem";
enum SysBaseParam { enum SysBaseParam {
/** /**
* 系统全称 * 系统全称
@@ -187,6 +187,15 @@ public class AgentController {
agentService.updateById(existingEntity); agentService.updateById(existingEntity);
// 更新记忆策略
if (existingEntity.getMemModelId() == null || existingEntity.getMemModelId().equals(Constant.MEMORY_NO_MEM)) {
// 删除所有记录
agentChatHistoryService.deleteByAgentId(existingEntity.getId(), true, true);
} else if (existingEntity.getChatHistoryConf() != null && existingEntity.getChatHistoryConf() == 1) {
// 删除音频数据
agentChatHistoryService.deleteByAgentId(existingEntity.getId(), true, false);
}
return new Result<>(); return new Result<>();
} }
@@ -197,7 +206,7 @@ public class AgentController {
// 先删除关联的设备 // 先删除关联的设备
deviceService.deleteByAgentId(id); deviceService.deleteByAgentId(id);
// 删除关联的聊天记录 // 删除关联的聊天记录
agentChatHistoryService.deleteByAgentId(id); agentChatHistoryService.deleteByAgentId(id, true, true);
// 再删除智能体 // 再删除智能体
agentService.deleteById(id); agentService.deleteById(id);
return new Result<>(); return new Result<>();
@@ -28,4 +28,11 @@ public interface AiAgentChatHistoryDao extends BaseMapper<AgentChatHistoryEntity
* @param agentId 智能体ID * @param agentId 智能体ID
*/ */
void deleteHistoryByAgentId(String agentId); void deleteHistoryByAgentId(String agentId);
/**
* 根据智能体ID删除音频ID
*
* @param agentId 智能体ID
*/
void deleteAudioIdByAgentId(String agentId);
} }
@@ -39,7 +39,9 @@ public interface AgentChatHistoryService extends IService<AgentChatHistoryEntity
/** /**
* 根据智能体ID删除聊天记录 * 根据智能体ID删除聊天记录
* *
* @param agentId 智能体ID * @param agentId 智能体ID
* @param deleteAudio 是否删除音频
* @param deleteText 是否删除文本
*/ */
void deleteByAgentId(String agentId); void deleteByAgentId(String agentId, Boolean deleteAudio, Boolean deleteText);
} }
@@ -78,8 +78,16 @@ public class AgentChatHistoryServiceImpl extends ServiceImpl<AiAgentChatHistoryD
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deleteByAgentId(String agentId) { public void deleteByAgentId(String agentId, Boolean deleteAudio, Boolean deleteText) {
baseMapper.deleteAudioByAgentId(agentId); if (deleteAudio) {
baseMapper.deleteHistoryByAgentId(agentId); baseMapper.deleteAudioByAgentId(agentId);
}
if (deleteAudio && !deleteText) {
baseMapper.deleteAudioIdByAgentId(agentId);
}
if (deleteText) {
baseMapper.deleteHistoryByAgentId(agentId);
}
} }
} }
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import xiaozhi.common.constant.Constant;
import xiaozhi.common.page.PageData; import xiaozhi.common.page.PageData;
import xiaozhi.common.redis.RedisKeys; import xiaozhi.common.redis.RedisKeys;
import xiaozhi.common.redis.RedisUtils; import xiaozhi.common.redis.RedisUtils;
@@ -46,7 +47,15 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
@Override @Override
public AgentEntity getAgentById(String id) { public AgentEntity getAgentById(String id) {
return agentDao.selectById(id); AgentEntity agent = agentDao.selectById(id);
if (agent != null && agent.getMemModelId() != null && agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)) {
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.IGNORE.getCode());
} else if (agent != null && agent.getMemModelId() != null
&& !agent.getMemModelId().equals(Constant.MEMORY_NO_MEM)
&& agent.getChatHistoryConf() == null) {
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.RECORD_TEXT_AUDIO.getCode());
}
return agent;
} }
@Override @Override
@@ -1,3 +0,0 @@
-- 添加聊天记录配置字段
ALTER TABLE `ai_agent`
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 2 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
@@ -0,0 +1,6 @@
-- 添加聊天记录配置字段
ALTER TABLE `ai_agent`
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
ALTER TABLE `ai_agent_template`
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
@@ -113,4 +113,11 @@ databaseChangeLog:
changes: changes:
- sqlFile: - sqlFile:
encoding: utf8 encoding: utf8
path: classpath:db/changelog/202505091409.sql path: classpath:db/changelog/202505091409.sql
- changeSet:
id: 202505111914
author: hrz
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202505111914.sql
@@ -28,11 +28,17 @@
SELECT audio_id SELECT audio_id
FROM ai_agent_chat_history FROM ai_agent_chat_history
WHERE agent_id = #{agentId} WHERE agent_id = #{agentId}
); )
</delete> </delete>
<update id="deleteAudioIdByAgentId">
UPDATE ai_agent_chat_history
SET audio_id = NULL
WHERE agent_id = #{agentId}
</update>
<delete id="deleteHistoryByAgentId"> <delete id="deleteHistoryByAgentId">
DELETE FROM ai_agent_chat_history DELETE FROM ai_agent_chat_history
WHERE agent_id = #{agentId}; WHERE agent_id = #{agentId}
</delete> </delete>
</mapper> </mapper>
+55 -50
View File
@@ -61,29 +61,40 @@
<el-form-item v-for="(model, index) in models" :key="`model-${index}`" :label="model.label" <el-form-item v-for="(model, index) in models" :key="`model-${index}`" :label="model.label"
class="model-item"> class="model-item">
<div class="model-select-wrapper"> <div class="model-select-wrapper">
<el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="form-select" @change="handleModelChange(model.type, $event)"> <el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="form-select"
<el-option v-for="(item, optionIndex) in modelOptions[model.type]" :key="`option-${index}-${optionIndex}`" :label="item.label" :value="item.value"/> @change="handleModelChange(model.type, $event)">
<el-option v-for="(item, optionIndex) in modelOptions[model.type]"
:key="`option-${index}-${optionIndex}`" :label="item.label" :value="item.value" />
</el-select> </el-select>
<div v-if="showFunctionIcons(model.type)" class="function-icons"> <div v-if="showFunctionIcons(model.type)" class="function-icons">
<el-tooltip v-for="func in currentFunctions" :key="func.name" effect="dark" placement="top" popper-class="custom-tooltip"> <el-tooltip v-for="func in currentFunctions" :key="func.name" effect="dark" placement="top"
<div slot="content"> popper-class="custom-tooltip">
<div><strong>功能名称:</strong> {{ func.name }}</div> <div slot="content">
<div v-if="Object.keys(func.params).length > 0"> <div><strong>功能名称:</strong> {{ func.name }}</div>
<strong>参数配置:</strong> <div v-if="Object.keys(func.params).length > 0">
<div v-for="(value, key) in func.params" :key="key"> <strong>参数配置:</strong>
{{ key }}: {{ value }} <div v-for="(value, key) in func.params" :key="key">
</div> {{ key }}: {{ value }}
</div> </div>
<div v-else>无参数配置</div>
</div> </div>
<div class="icon-dot" :style="{backgroundColor: getFunctionColor(func.name)}"> <div v-else>无参数配置</div>
{{ func.name.charAt(0) }} </div>
</div> <div class="icon-dot" :style="{ backgroundColor: getFunctionColor(func.name) }">
</el-tooltip> {{ func.name.charAt(0) }}
<el-button class="edit-function-btn" @click="showFunctionDialog = true" :class="{'active-btn': showFunctionDialog}"> </div>
编辑功能 </el-tooltip>
</el-button> <el-button class="edit-function-btn" @click="showFunctionDialog = true"
</div> :class="{ 'active-btn': showFunctionDialog }">
编辑功能
</el-button>
</div>
<div v-if="model.type === 'Memory' && form.model.memModelId !== 'Memory_nomem'"
class="chat-history-options">
<el-radio-group v-model="form.chatHistoryConf" @change="updateChatHistoryConf">
<el-radio-button :label="1">上报文字</el-radio-button>
<el-radio-button :label="2">上报文字+语音</el-radio-button>
</el-radio-group>
</div>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="角色音色"> <el-form-item label="角色音色">
@@ -92,12 +103,6 @@
:value="item.value" /> :value="item.value" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="聊天记录配置">
<el-select v-model="form.chatHistoryConf" placeholder="请选择" class="form-select">
<el-option v-for="(item, index) in chatHistoryOptions" :key="`chatHistoryConf-${index}`" :label="item.label"
:value="item.value" />
</el-select>
</el-form-item>
</div> </div>
</div> </div>
</div> </div>
@@ -107,14 +112,15 @@
</div> </div>
</div> </div>
<function-dialog v-model="showFunctionDialog" :functions="currentFunctions" @update-functions="handleUpdateFunctions" @dialog-closed="handleDialogClosed"/> <function-dialog v-model="showFunctionDialog" :functions="currentFunctions"
@update-functions="handleUpdateFunctions" @dialog-closed="handleDialogClosed" />
</div> </div>
</template> </template>
<script> <script>
import Api from '@/apis/api'; import Api from '@/apis/api';
import HeaderBar from "@/components/HeaderBar.vue";
import FunctionDialog from "@/components/FunctionDialog.vue"; import FunctionDialog from "@/components/FunctionDialog.vue";
import HeaderBar from "@/components/HeaderBar.vue";
export default { export default {
name: 'RoleConfigPage', name: 'RoleConfigPage',
@@ -125,7 +131,7 @@ export default {
agentCode: "", agentCode: "",
agentName: "", agentName: "",
ttsVoiceId: "", ttsVoiceId: "",
chatHistoryConf: "", chatHistoryConf: 0,
systemPrompt: "", systemPrompt: "",
langCode: "", langCode: "",
language: "", language: "",
@@ -163,24 +169,6 @@ export default {
{ name: '工具', params: {} }, { name: '工具', params: {} },
{ name: '退出', params: {} } { name: '退出', params: {} }
], ],
chatHistoryOptions: [
{
"value": 0,
"label": "不记录"
},
{
"value": 1,
"label": "仅记录文本"
},
{
"value": 2,
"label": "仅记录语音"
},
{
"value": 3,
"label": "文本音频都记录"
}
],
} }
}, },
methods: { methods: {
@@ -229,7 +217,7 @@ export default {
agentCode: "", agentCode: "",
agentName: "", agentName: "",
ttsVoiceId: "", ttsVoiceId: "",
chatHistoryConf: "", chatHistoryConf: 0,
systemPrompt: "", systemPrompt: "",
langCode: "", langCode: "",
language: "", language: "",
@@ -248,7 +236,7 @@ export default {
message: '配置已重置', message: '配置已重置',
showClose: true showClose: true
}) })
}).catch(() => {}); }).catch(() => { });
}, },
fetchTemplates() { fetchTemplates() {
Api.agent.getAgentTemplate(({ data }) => { Api.agent.getAgentTemplate(({ data }) => {
@@ -359,6 +347,12 @@ export default {
if (type === 'Intent' && value !== 'Intent_nointent') { if (type === 'Intent' && value !== 'Intent_nointent') {
this.fetchFunctionList(); this.fetchFunctionList();
} }
if (type === 'Memory' && value === 'Memory_nomem') {
this.form.chatHistoryConf = 0;
}
if (type === 'Memory' && value !== 'Memory_nomem' && (this.form.chatHistoryConf === 0 || this.form.chatHistoryConf === null)) {
this.form.chatHistoryConf = 2;
}
}, },
fetchFunctionList() { fetchFunctionList() {
// 使用假数据代替API调用 // 使用假数据代替API调用
@@ -383,6 +377,11 @@ export default {
this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions)); this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions));
} }
}, },
updateChatHistoryConf() {
if (this.form.model.memModelId === 'Memory_nomem') {
this.form.chatHistoryConf = 0;
}
},
}, },
watch: { watch: {
'form.model.ttsModelId': { 'form.model.ttsModelId': {
@@ -641,7 +640,7 @@ export default {
} }
::v-deep .el-form-item__label { ::v-deep .el-form-item__label {
font-size: 10px !important; font-size: 12px !important;
color: #3d4566 !important; color: #3d4566 !important;
font-weight: 400; font-weight: 400;
line-height: 22px; line-height: 22px;
@@ -697,4 +696,10 @@ export default {
color: white; color: white;
} }
.chat-history-options {
display: flex;
gap: 10px;
min-width: 250px;
justify-content: flex-end;
}
</style> </style>