diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 000000000..135cfbd65
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,66 @@
+name: Tests
+
+on:
+ push:
+ branches: [main]
+ pull_request:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ python:
+ name: Python (xiaozhi-server)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.10'
+ cache: 'pip'
+ cache-dependency-path: 'main/xiaozhi-server/requirements.txt'
+ - name: Install dependencies
+ working-directory: main/xiaozhi-server
+ run: |
+ pip install -r requirements.txt
+ pip install pytest pytest-asyncio freezegun
+ - name: Run smoke test
+ working-directory: main/xiaozhi-server
+ run: |
+ if [ -f tests/test_smoke.py ]; then
+ pytest tests/test_smoke.py -x -q
+ else
+ echo "::warning::Slice 2 not done yet — tests/test_smoke.py missing"
+ exit 0
+ fi
+
+ java:
+ name: Java (manager-api)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-java@v4
+ with:
+ distribution: 'temurin'
+ java-version: '21'
+ cache: 'maven'
+ - name: Run tests
+ working-directory: main/manager-api
+ run: mvn -B -q test -DfailIfNoTests=false
+
+ web:
+ name: Vue (manager-web)
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version: '20'
+ cache: 'npm'
+ cache-dependency-path: main/manager-web/package-lock.json
+ - name: Run tests
+ working-directory: main/manager-web
+ run: |
+ npm ci --no-audit --no-fund
+ npm run test:unit
diff --git a/.gitignore b/.gitignore
index 8b393385c..1c0c024ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -110,12 +110,17 @@ celerybeat.pid
# Environments
.env
.venv
+/.venv-*/
env/
venv/
ENV/
env.bak/
venv.bak/
+# Repository-local runtimes and package-manager caches
+/.runtime/
+/main/manager-web/.npm-cache/
+
# Spyder project settings
.spyderproject
.spyproject
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..3362dcb74
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+.PHONY: test test-fast test-python test-java test-web help
+
+help:
+ @echo "make test-fast - run all fast unit tests (default)"
+ @echo "make test - alias for test-fast"
+ @echo "make test-python - pytest in main/xiaozhi-server"
+ @echo "make test-java - mvn test in main/manager-api"
+ @echo "make test-web - npm run test:unit in main/manager-web"
+
+test: test-fast
+
+test-fast: test-python test-java test-web
+
+test-python:
+ cd main/xiaozhi-server && python -m pytest -x -q
+
+test-java:
+ cd main/manager-api && mvn -B -q test -DfailIfNoTests=false
+
+test-web:
+ cd main/manager-web && npm ci --no-audit --no-fund && npm test
diff --git a/docs/web-search-integration.md b/docs/web-search-integration.md
index 25dd546a1..cb694e912 100644
--- a/docs/web-search-integration.md
+++ b/docs/web-search-integration.md
@@ -2,13 +2,14 @@
## 功能简介
-联网搜索插件 `web_search` 支持在对话过程中实时联网搜索信息并返回结果。插件支持两个搜索源:秘塔(Metaso)和Tavily,用户可根据需要选择其中一个。
+联网搜索插件 `web_search` 支持在对话过程中实时联网搜索信息并返回结果。插件支持三个搜索源:秘塔(Metaso)、Tavily和Serply,用户可根据需要选择其中一个。
## API Key申请指南
-目前我们适配了`秘塔搜索`和`Tavily搜索`。
+目前我们适配了`秘塔搜索`、`Tavily搜索`和`Serply搜索`。
- Tavily搜索:每个月1000次免费额度。
- 秘塔搜索:拥有较为优质的国内数据源。
+- Serply搜索:返回谷歌搜索结果,注册赠送2500次免费额度,额度用完后需要付费。
## API Key申请指南
@@ -24,6 +25,13 @@
- 在控制台中创建API Key
- 复制生成的API Key(以 `tvly-` 为前缀),这是配置所需的关键信息
+### 方式三:使用Serply搜索
+
+- 访问 [Serply](https://serply.io),注册并登录账号
+- 在控制台中创建API Key
+- 复制生成的API Key,这是配置所需的关键信息
+- 接口说明见 [Serply文档](https://serply.io/docs)
+
## 配置方式
### 方式1. 使用智控台部署(推荐)
@@ -32,14 +40,14 @@
- 进入"配置角色"页面,选择要配置的智能体
- 点击"编辑功能"按钮,在右侧参数配置区域找到"联网搜索"插件
- 勾选"联网搜索"
-- 填入搜索源(`metaso`或`tavily`),并将对应的`API Key`填入配置项
+- 填入搜索源(`metaso`、`tavily`或`serply`),并将对应的`API Key`填入配置项
- 保存配置,再保存智能体配置
### 方式2. 单模块xiaozhi-server部署
在 `data/.config.yaml` 中配置:
-- 将搜索源填入 `provider`,可选值为 `metaso` 或 `tavily`
+- 将搜索源填入 `provider`,可选值为 `metaso`、`tavily` 或 `serply`
- 将申请到的API Key填入 `api_key`
```yaml
diff --git a/main/manager-api/pom.xml b/main/manager-api/pom.xml
index 7bb9016ca..0b0e90a9e 100644
--- a/main/manager-api/pom.xml
+++ b/main/manager-api/pom.xml
@@ -20,15 +20,15 @@
21
5.10.1
1.2.20
- 3.5.5
- 5.8.24
- 1.19.1
+ 3.5.17
+ 5.8.46
+ 1.22.2
4.6.0
2.8.8
- 3.18.0
+ 3.20.0
2.0.2
1.6.2
- 33.0.0-jre
+ 33.6.0-jre
4.20.0
8.31.1
@@ -174,13 +174,13 @@
com.baomidou
- mybatis-plus-boot-starter
+ mybatis-plus-spring-boot3-starter
${mybatisplus.version}
- org.mybatis
- mybatis-spring
- 3.0.3
+ com.baomidou
+ mybatis-plus-jsqlparser-4.9
+ ${mybatisplus.version}
cn.hutool
@@ -295,6 +295,16 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ full
+
+ -Xlint:deprecation,unchecked
+
+
+
org.apache.maven.plugins
maven-surefire-plugin
diff --git a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java
index 55965e476..664cb9b48 100644
--- a/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java
+++ b/main/manager-api/src/main/java/xiaozhi/common/constant/Constant.java
@@ -324,7 +324,7 @@ public interface Constant {
/**
* 版本号
*/
- public static final String VERSION = "0.9.4";
+ public static final String VERSION = "0.9.7";
/**
* 无效固件URL
diff --git a/main/manager-api/src/main/java/xiaozhi/common/interceptor/DataFilterInterceptor.java b/main/manager-api/src/main/java/xiaozhi/common/interceptor/DataFilterInterceptor.java
index b1bae90e5..7a34fa80f 100644
--- a/main/manager-api/src/main/java/xiaozhi/common/interceptor/DataFilterInterceptor.java
+++ b/main/manager-api/src/main/java/xiaozhi/common/interceptor/DataFilterInterceptor.java
@@ -67,7 +67,7 @@ public class DataFilterInterceptor implements InnerInterceptor {
private String getSelect(String buildSql, DataScope scope) {
try {
Select select = (Select) CCJSqlParserUtil.parse(buildSql);
- PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
+ PlainSelect plainSelect = select.getPlainSelect();
Expression expression = plainSelect.getWhere();
if (expression == null) {
@@ -82,4 +82,4 @@ public class DataFilterInterceptor implements InnerInterceptor {
return buildSql;
}
}
-}
\ No newline at end of file
+}
diff --git a/main/manager-api/src/main/java/xiaozhi/common/service/impl/BaseServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/common/service/impl/BaseServiceImpl.java
index 33d0f5d35..4dec94356 100644
--- a/main/manager-api/src/main/java/xiaozhi/common/service/impl/BaseServiceImpl.java
+++ b/main/manager-api/src/main/java/xiaozhi/common/service/impl/BaseServiceImpl.java
@@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.function.BiConsumer;
+import java.util.function.BiFunction;
import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.logging.Log;
@@ -81,8 +81,8 @@ public abstract class BaseServiceImpl, T> implements Bas
// Process sort fields
if (orderField instanceof String) {
orderFields.add((String) orderField);
- } else if (orderField instanceof List) {
- orderFields.addAll((List) orderField);
+ } else if (orderField instanceof List> fields) {
+ fields.forEach(field -> orderFields.add(String.class.cast(field)));
}
// Sort if there are sort fields
@@ -142,11 +142,12 @@ public abstract class BaseServiceImpl, T> implements Bas
return SqlHelper.retBool(result);
}
- protected Class currentMapperClass() {
- return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseServiceImpl.class, 0);
+ protected Class> currentMapperClass() {
+ return ReflectionKit.getSuperClassGenericType(this.getClass(), BaseServiceImpl.class, 0);
}
@Override
+ @SuppressWarnings("unchecked")
public Class currentModelClass() {
return (Class) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseServiceImpl.class, 1);
}
@@ -181,8 +182,9 @@ public abstract class BaseServiceImpl, T> implements Bas
* Execute batch operations
*/
@SuppressWarnings("deprecation")
- protected boolean executeBatch(Collection list, int batchSize, BiConsumer consumer) {
- return SqlHelper.executeBatch(this.currentModelClass(), this.log, list, batchSize, consumer);
+ protected boolean executeBatch(Collection list, int batchSize, BiFunction operation) {
+ return SqlHelper.executeBatch(SqlHelper.sqlSessionFactory(this.currentModelClass()), this.log, list, batchSize,
+ operation);
}
@Override
@@ -209,7 +211,7 @@ public abstract class BaseServiceImpl, T> implements Bas
return executeBatch(entityList, batchSize, (sqlSession, entity) -> {
MapperMethod.ParamMap param = new MapperMethod.ParamMap<>();
param.put(Constants.ENTITY, entity);
- sqlSession.update(sqlStatement, param);
+ return sqlSession.update(sqlStatement, param);
});
}
@@ -225,6 +227,6 @@ public abstract class BaseServiceImpl, T> implements Bas
@Override
public boolean deleteBatchIds(Collection extends Serializable> idList) {
- return SqlHelper.retBool(baseDao.deleteBatchIds(idList));
+ return SqlHelper.retBool(baseDao.deleteByIds(idList));
}
}
diff --git a/main/manager-api/src/main/java/xiaozhi/common/service/impl/CrudServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/common/service/impl/CrudServiceImpl.java
index 3b9d0fe97..d6e37d13d 100644
--- a/main/manager-api/src/main/java/xiaozhi/common/service/impl/CrudServiceImpl.java
+++ b/main/manager-api/src/main/java/xiaozhi/common/service/impl/CrudServiceImpl.java
@@ -24,6 +24,7 @@ import xiaozhi.common.utils.ConvertUtils;
public abstract class CrudServiceImpl, T, D> extends BaseServiceImpl
implements CrudService {
+ @SuppressWarnings("unchecked")
protected Class currentDtoClass() {
return (Class) ReflectionKit.getSuperClassGenericType(getClass(), CrudServiceImpl.class, 2);
}
@@ -70,6 +71,6 @@ public abstract class CrudServiceImpl, T, D> extends Bas
@Override
public void delete(Serializable[] ids) {
- baseDao.deleteBatchIds(Arrays.asList(ids));
+ baseDao.deleteByIds(Arrays.asList(ids));
}
}
diff --git a/main/manager-api/src/main/java/xiaozhi/common/utils/HashEncryptionUtil.java b/main/manager-api/src/main/java/xiaozhi/common/utils/HashEncryptionUtil.java
deleted file mode 100644
index dd0c26305..000000000
--- a/main/manager-api/src/main/java/xiaozhi/common/utils/HashEncryptionUtil.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package xiaozhi.common.utils;
-
-import lombok.extern.slf4j.Slf4j;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * Hash encryption algorithm utility class
- * @author zjy
- */
-@Slf4j
-public class HashEncryptionUtil {
- /**
- * Encrypt using md5
- * @param context Content to be encrypted
- * @return Hash value
- */
- public static String Md5hexDigest(String context){
- return hexDigest(context,"MD5");
- }
-
- /**
- * Encrypt using specified hash algorithm
- * @param context Content to be encrypted
- * @param algorithm Hash algorithm
- * @return Hash value
- */
- public static String hexDigest(String context,String algorithm ){
- // Get MD5 algorithm instance
- MessageDigest md = null;
- try {
- md = MessageDigest.getInstance(algorithm);
- } catch (NoSuchAlgorithmException e) {
- log.error("Encryption failed algorithm: {}",algorithm);
- throw new RuntimeException("Encryption failed, system does not support "+ algorithm +" hash algorithm");
- }
- // Calculate MD5 value of agent id
- byte[] messageDigest = md.digest(context.getBytes());
- // Convert byte array to hexadecimal string
- StringBuilder hexString = new StringBuilder();
- for (byte b : messageDigest) {
- String hex = Integer.toHexString(0xFF & b);
- if (hex.length() == 1) {
- hexString.append('0');
- }
- hexString.append(hex);
- }
- return hexString.toString();
- }
-
-}
diff --git a/main/manager-api/src/main/java/xiaozhi/common/utils/JsonUtils.java b/main/manager-api/src/main/java/xiaozhi/common/utils/JsonUtils.java
index 21d1bf211..cf0ef663b 100644
--- a/main/manager-api/src/main/java/xiaozhi/common/utils/JsonUtils.java
+++ b/main/manager-api/src/main/java/xiaozhi/common/utils/JsonUtils.java
@@ -1,7 +1,9 @@
package xiaozhi.common.utils;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -16,6 +18,10 @@ import cn.hutool.core.util.StrUtil;
*/
public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper();
+ private static final TypeReference