From 36e34994ba86e8467474c872392287f41fb1fc46 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 24 Oct 2026 01:12:36 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A4=A9=E6=B0=94=E6=8F=92=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=87=AD=E6=8D=AE=E6=94=B9=E6=88=90=E8=87=AA=E5=B7=B1=E5=A1=AB?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E9=A2=84=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 模型提供方里内置的和风天气密钥和主机地址清空,字段名后面写清去哪儿申请。已有智能体参数里还等于内置值的那些也清掉,用户自己填的不动。 新增一条变更记录,没有改动以前那些,校验和不受影响。 --- docs/weather-integration.md | 2 + .../resources/db/changelog/202610241030.sql | 93 +++++++++++++++++++ .../db/changelog/db.changelog-master.yaml | 7 ++ 3 files changed, 102 insertions(+) create mode 100644 main/manager-api/src/main/resources/db/changelog/202610241030.sql diff --git a/docs/weather-integration.md b/docs/weather-integration.md index 3b6ca2b6a..9e7b2935c 100644 --- a/docs/weather-integration.md +++ b/docs/weather-integration.md @@ -46,6 +46,8 @@ 8. 将复制过来的第二个关键配置`API Host`,填入到`开发者 API Host`里 9. 保存配置,再保存智能体配置 +智控台不再预置和风天气的凭据,插件参数里的 API 密钥和 API Host 两栏默认是空的,得填自己申请的那一套。字段名后面括号里写了申请路径,照着本文件的「API Key 申请指南」走就行。 + ### 方式2. 如果你只是单模块xiaozhi-server部署 在 `data/.config.yaml` 中配置: diff --git a/main/manager-api/src/main/resources/db/changelog/202610241030.sql b/main/manager-api/src/main/resources/db/changelog/202610241030.sql new file mode 100644 index 000000000..c1fb0fb7b --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202610241030.sql @@ -0,0 +1,93 @@ +-- 天气插件不再内置和风天气凭据 +-- +-- 早期版本把一把和风天气的 API Key 和一个 API Host 写在模型提供方 +-- SYSTEM_PLUGIN_WEATHER 的字段默认值里。智控台的角色配置表单拿这个默认值预填, +-- 用户不填就等于沿用仓库里那一份。那把 key 已经失效,仓库里也不该带着凭据分发, +-- 用的人也不知道它从哪来、该不该用。 +-- +-- 这里清两处: +-- 1. 字段默认值置空,同时把申请路径写进字段名,用户在界面上就能看到去哪儿申请 +-- 2. 已有智能体的参数里还等于内置值的那些,值清空。用户自己填的 key 不动 +-- +-- 内置值从模型提供方那一行现读,不写死在脚本里,免得仓库里再留一份凭据 + +SET @weather_api_key = ( + SELECT jt.`def` + FROM `ai_model_provider` p, + JSON_TABLE(p.`fields`, '$[*]' COLUMNS ( + `field_key` VARCHAR(64) PATH '$.key', + `def` VARCHAR(255) PATH '$.default' + )) jt + WHERE p.`id` = 'SYSTEM_PLUGIN_WEATHER' + AND jt.`field_key` = 'api_key' + LIMIT 1 +); + +SET @weather_api_host = ( + SELECT jt.`def` + FROM `ai_model_provider` p, + JSON_TABLE(p.`fields`, '$[*]' COLUMNS ( + `field_key` VARCHAR(64) PATH '$.key', + `def` VARCHAR(255) PATH '$.default' + )) jt + WHERE p.`id` = 'SYSTEM_PLUGIN_WEATHER' + AND jt.`field_key` = 'api_host' + LIMIT 1 +); + +-- 字段在数组里的位置。数组下标从 0 起,JSON_TABLE 的序号从 1 起,两者差一 +SET @weather_api_key_pos = ( + SELECT jt.`ord` + FROM `ai_model_provider` p, + JSON_TABLE(p.`fields`, '$[*]' COLUMNS ( + `ord` FOR ORDINALITY, + `field_key` VARCHAR(64) PATH '$.key' + )) jt + WHERE p.`id` = 'SYSTEM_PLUGIN_WEATHER' + AND jt.`field_key` = 'api_key' + LIMIT 1 +); + +SET @weather_api_host_pos = ( + SELECT jt.`ord` + FROM `ai_model_provider` p, + JSON_TABLE(p.`fields`, '$[*]' COLUMNS ( + `ord` FOR ORDINALITY, + `field_key` VARCHAR(64) PATH '$.key' + )) jt + WHERE p.`id` = 'SYSTEM_PLUGIN_WEATHER' + AND jt.`field_key` = 'api_host' + LIMIT 1 +); + +-- 智能体参数里还等于内置值的项,清空。分两次更新,两项各自独立判断: +-- 用户自己填了 key 但没改 host 的,host 也要清掉,不然新 key 配旧 host 一样调不通 +UPDATE `ai_agent_plugin_mapping` +SET `param_info` = JSON_SET(`param_info`, '$.api_key', '') +WHERE `plugin_id` = 'SYSTEM_PLUGIN_WEATHER' + AND @weather_api_key IS NOT NULL + AND @weather_api_key <> '' + AND JSON_UNQUOTE(JSON_EXTRACT(`param_info`, '$.api_key')) = @weather_api_key; + +UPDATE `ai_agent_plugin_mapping` +SET `param_info` = JSON_SET(`param_info`, '$.api_host', '') +WHERE `plugin_id` = 'SYSTEM_PLUGIN_WEATHER' + AND @weather_api_host IS NOT NULL + AND @weather_api_host <> '' + AND JSON_UNQUOTE(JSON_EXTRACT(`param_info`, '$.api_host')) = @weather_api_host; + +-- 字段默认值置空,字段名里写清申请路径。默认值那一栏在界面上还带着提示, +-- 光把值清空没用,填表的人根本不知道该去哪儿拿 +UPDATE `ai_model_provider` +SET `fields` = JSON_SET( + `fields`, + CONCAT('$[', @weather_api_key_pos - 1, '].default'), '', + CONCAT('$[', @weather_api_key_pos - 1, '].label'), + '天气插件 API 密钥(自己到和风天气控制台申请,步骤见 docs/weather-integration.md 的「API Key 申请指南」)', + CONCAT('$[', @weather_api_host_pos - 1, '].default'), '', + CONCAT('$[', @weather_api_host_pos - 1, '].label'), + '开发者 API Host(和风天气控制台「设置」里查看,步骤见 docs/weather-integration.md 的「API Key 申请指南」)' +) +WHERE `id` = 'SYSTEM_PLUGIN_WEATHER' + AND @weather_api_key_pos IS NOT NULL + AND @weather_api_host_pos IS NOT NULL; 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 282fbaf48..3b699363b 100644 --- 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 @@ -753,3 +753,10 @@ databaseChangeLog: - sqlFile: encoding: utf8 path: classpath:db/changelog/202609172100.sql + - changeSet: + id: 202610241030 + author: hrz + changes: + - sqlFile: + encoding: utf8 + path: classpath:db/changelog/202610241030.sql