diff --git a/docs/newsnow_plugin_config.md b/docs/newsnow_plugin_config.md new file mode 100644 index 00000000..88744423 --- /dev/null +++ b/docs/newsnow_plugin_config.md @@ -0,0 +1,84 @@ +# get_news_from_newsnow 插件新闻源配置指南 + +## 概述 + +`get_news_from_newsnow` 插件现在支持通过Web管理界面动态配置新闻源,不再需要修改代码。用户可以在智控台中为每个智能体配置不同的新闻源。 + +## 配置方式 + +### 1. 通过Web管理界面配置(推荐) + +1. 登录智控台 +2. 进入"角色配置"页面 +3. 选择要配置的智能体 +4. 点击"编辑功能"按钮 +5. 在右侧参数配置区域找到"newsnow新闻聚合"插件 +6. 在"新闻源配置"字段中输入JSON格式的新闻源配置 + +### 2. 配置文件方式 + +在 `config.yaml` 中配置: + +```yaml +plugins: + get_news_from_newsnow: + url: "https://newsnow.busiyi.world/api/s?id=" + news_sources: + thepaper: "澎湃新闻" + baidu: "百度热搜" + cls-depth: "财联社" + # 可以添加更多新闻源 + weibo: "微博头条" + douyin: "抖音热搜" + solidot: "奇客Solidot" +``` + +## 新闻源配置格式 + +新闻源配置使用JSON格式,格式为: + +```json +{ + "source_id": "显示名称", + "source_id2": "显示名称2" +} +``` + +### 配置示例 + +```json +{ + "thepaper": "澎湃新闻", + "baidu": "百度热搜", + "cls-depth": "财联社", + "weibo": "微博头条", + "douyin": "抖音热搜", + "solidot": "奇客Solidot" +} +``` + +## 默认配置 + +如果未配置新闻源,插件将使用以下默认配置: + +```json +{ + "thepaper": "澎湃新闻", + "baidu": "百度热搜", + "cls-depth": "财联社" +} +``` + +## 使用说明 + +1. **配置新闻源**:在Web界面或配置文件中设置新闻源 +2. **调用插件**:用户可以说"播报新闻"或"获取新闻" +3. **指定新闻源**:用户可以说"播报澎湃新闻"或"获取百度热搜" +4. **获取详情**:用户可以说"详细介绍这条新闻" + +## 注意事项 + +1. 新闻源的 `source_id` 必须与API接口支持的ID一致 +2. 配置更改后需要重启服务或重新加载配置 +3. 如果配置的新闻源无效,插件会自动使用默认新闻源 +4. JSON格式必须正确,否则会使用默认配置 \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/biz/impl/AgentChatHistoryBizServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/biz/impl/AgentChatHistoryBizServiceImpl.java index 087c1b9d..36b59993 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/biz/impl/AgentChatHistoryBizServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/biz/impl/AgentChatHistoryBizServiceImpl.java @@ -19,6 +19,8 @@ import xiaozhi.modules.agent.service.AgentChatAudioService; import xiaozhi.modules.agent.service.AgentChatHistoryService; import xiaozhi.modules.agent.service.AgentService; import xiaozhi.modules.agent.service.biz.AgentChatHistoryBizService; +import xiaozhi.modules.device.entity.DeviceEntity; +import xiaozhi.modules.device.service.DeviceService; /** * {@link AgentChatHistoryBizService} impl @@ -35,6 +37,7 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic private final AgentChatHistoryService agentChatHistoryService; private final AgentChatAudioService agentChatAudioService; private final RedisUtils redisUtils; + private final DeviceService deviceService; /** * 处理聊天记录上报,包括文件上传和相关信息记录 @@ -68,6 +71,15 @@ public class AgentChatHistoryBizServiceImpl implements AgentChatHistoryBizServic // 更新设备最后对话时间 redisUtils.set(RedisKeys.getAgentDeviceLastConnectedAtById(agentId), new Date()); + + // 更新设备最后连接时间 + DeviceEntity device = deviceService.getDeviceByMacAddress(macAddress); + if (device != null) { + deviceService.updateDeviceConnectionInfo(agentId, device.getId(), null); + } else { + log.warn("聊天记录上报时,未找到mac地址为 {} 的设备", macAddress); + } + return Boolean.TRUE; } diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java index eaf3636f..b0320e3c 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/controller/DeviceController.java @@ -25,6 +25,7 @@ import xiaozhi.common.utils.Result; import xiaozhi.modules.device.dto.DeviceRegisterDTO; import xiaozhi.modules.device.dto.DeviceUnBindDTO; import xiaozhi.modules.device.dto.DeviceUpdateDTO; +import xiaozhi.modules.device.dto.DeviceManualAddDTO; import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.service.DeviceService; import xiaozhi.modules.security.user.SecurityUser; @@ -99,4 +100,13 @@ public class DeviceController { deviceService.updateById(entity); return new Result(); } + + @PostMapping("/manual-add") + @Operation(summary = "手动添加设备") + @RequiresPermissions("sys:role:normal") + public Result manualAddDevice(@RequestBody @Valid DeviceManualAddDTO dto) { + UserDetail user = SecurityUser.getUser(); + deviceService.manualAddDevice(user.getId(), dto); + return new Result<>(); + } } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceManualAddDTO.java b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceManualAddDTO.java new file mode 100644 index 00000000..369726b0 --- /dev/null +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/dto/DeviceManualAddDTO.java @@ -0,0 +1,11 @@ +package xiaozhi.modules.device.dto; + +import lombok.Data; + +@Data +public class DeviceManualAddDTO { + private String agentId; + private String board; // 设备型号 + private String appVersion; // 固件版本 + private String macAddress; // Mac地址 +} \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java index fb91ff89..3392c96f 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/DeviceService.java @@ -8,6 +8,7 @@ import xiaozhi.common.service.BaseService; import xiaozhi.modules.device.dto.DevicePageUserDTO; import xiaozhi.modules.device.dto.DeviceReportReqDTO; import xiaozhi.modules.device.dto.DeviceReportRespDTO; +import xiaozhi.modules.device.dto.DeviceManualAddDTO; import xiaozhi.modules.device.entity.DeviceEntity; import xiaozhi.modules.device.vo.UserShowDeviceListVO; @@ -87,5 +88,14 @@ public interface DeviceService extends BaseService { */ Date getLatestLastConnectionTime(String agentId); + /** + * 手动添加设备 + */ + void manualAddDevice(Long userId, DeviceManualAddDTO dto); + + /** + * 更新设备连接信息 + */ + void updateDeviceConnectionInfo(String agentId, String deviceId, String appVersion); } \ No newline at end of file diff --git a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java index ee31c41f..3cff111d 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java @@ -44,6 +44,7 @@ import xiaozhi.modules.device.vo.UserShowDeviceListVO; import xiaozhi.modules.security.user.SecurityUser; import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysUserUtilService; +import xiaozhi.modules.device.dto.DeviceManualAddDTO; @Slf4j @Service @@ -410,4 +411,30 @@ public class DeviceServiceImpl extends BaseServiceImpl } return 0; } + + @Override + public void manualAddDevice(Long userId, DeviceManualAddDTO dto) { + // 检查mac是否已存在 + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("mac_address", dto.getMacAddress()); + DeviceEntity exist = baseDao.selectOne(wrapper); + if (exist != null) { + throw new RenException("该Mac地址已存在"); + } + Date now = new Date(); + DeviceEntity entity = new DeviceEntity(); + entity.setId(dto.getMacAddress()); + entity.setUserId(userId); + entity.setAgentId(dto.getAgentId()); + entity.setBoard(dto.getBoard()); + entity.setAppVersion(dto.getAppVersion()); + entity.setMacAddress(dto.getMacAddress()); + entity.setCreateDate(now); + entity.setUpdateDate(now); + entity.setLastConnectedAt(now); + entity.setCreator(userId); + entity.setUpdater(userId); + entity.setAutoUpdate(1); + baseDao.insert(entity); + } } diff --git a/main/manager-api/src/main/resources/db/changelog/202506251619.sql b/main/manager-api/src/main/resources/db/changelog/202506251619.sql new file mode 100644 index 00000000..a458daea --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202506251619.sql @@ -0,0 +1,21 @@ +-- 更新 get_news_from_newsnow 插件配置,添加新闻源配置字段 +-- 执行时间:2025-06-25 + +-- 更新现有的 get_news_from_newsnow 插件配置 +UPDATE ai_model_provider +SET fields = JSON_ARRAY( + JSON_OBJECT( + 'key', 'url', + 'type', 'string', + 'label', '接口地址', + 'default', 'https://newsnow.busiyi.world/api/s?id=' + ), + JSON_OBJECT( + 'key', 'news_sources', + 'type', 'json', + 'label', '新闻源配置', + 'default', '{"thepaper":"澎湃新闻","baidu":"百度热搜","cls-depth":"财联社"}' + ) +) +WHERE provider_code = 'get_news_from_newsnow' +AND model_type = 'Plugin'; \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index b60094ef..63a08e11 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -219,10 +219,17 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202506191643.sql + - changeSet: + id: 202506251619 + author: Tink + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202506251619.sql - changeSet: id: 202506261637 author: hrz changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202506261637.sql \ No newline at end of file + path: classpath:db/changelog/202506261637.sql diff --git a/main/manager-web/src/apis/api.js b/main/manager-web/src/apis/api.js index 0a3e8d18..4d1d7d7d 100755 --- a/main/manager-web/src/apis/api.js +++ b/main/manager-web/src/apis/api.js @@ -7,6 +7,7 @@ import model from './module/model.js' import ota from './module/ota.js' import timbre from "./module/timbre.js" import user from './module/user.js' + /** * 接口地址 * 开发时自动读取使用.env.development文件 @@ -22,7 +23,6 @@ export function getServiceUrl() { return DEV_API_SERVICE } - /** request服务封装 */ export default { getServiceUrl, diff --git a/main/manager-web/src/apis/module/device.js b/main/manager-web/src/apis/module/device.js index e6d61353..233c764b 100644 --- a/main/manager-web/src/apis/module/device.js +++ b/main/manager-web/src/apis/module/device.js @@ -68,4 +68,21 @@ export default { }) }).send() }, + // 手动添加设备 + manualAddDevice(params, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/device/manual-add`) + .method('POST') + .data(params) + .success((res) => { + RequestService.clearRequestTime(); + callback(res); + }) + .networkFail((err) => { + console.error('手动添加设备失败:', err); + RequestService.reAjaxFun(() => { + this.manualAddDevice(params, callback); + }); + }).send(); + }, } \ No newline at end of file diff --git a/main/manager-web/src/components/ManualAddDeviceDialog.vue b/main/manager-web/src/components/ManualAddDeviceDialog.vue new file mode 100644 index 00000000..b6060ff5 --- /dev/null +++ b/main/manager-web/src/components/ManualAddDeviceDialog.vue @@ -0,0 +1,158 @@ + + + + + \ No newline at end of file diff --git a/main/manager-web/src/views/DeviceManagement.vue b/main/manager-web/src/views/DeviceManagement.vue index 25cd5a68..35238371 100644 --- a/main/manager-web/src/views/DeviceManagement.vue +++ b/main/manager-web/src/views/DeviceManagement.vue @@ -77,7 +77,10 @@ {{ isAllSelected ? '取消全选' : '全选' }} - 新增 + 验证码绑定 + + + 手动添加 解绑 @@ -103,6 +106,8 @@ + @@ -110,13 +115,19 @@