feat: AI 场景路由、ASR 服务及前后端全链路同步
- 新增 AI 场景路由控制器和管理接口 - 新增 ASR 语音识别服务及前后端集成 - 同步 AI Runtime 客户端到 Web/小程序/Life-Script - 完善 AI 配置测试修复和管理后台路由配置 - 新增数据库迁移脚本 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
---
|
||||
author: 华钟民
|
||||
created_at: 2026-05-23
|
||||
purpose: 修复 AI 配置管理接口测试功能,确保 Dify/Coze 等多提供商在 web-admin 后台能正常测试,全局确认前后端调用链路一致
|
||||
---
|
||||
|
||||
# AI 配置管理接口测试修复设计
|
||||
|
||||
## 1. 问题背景
|
||||
|
||||
在 web-admin 后台的"AI 配置管理"页面,流式测试 Dify 接口时报错:
|
||||
`"message":"user_id is required in input form"`。
|
||||
|
||||
根因是存在两套 AI 配置系统:
|
||||
- **旧系统**:`t_ai_config` 表 + `AiConfigList.vue`(已被路由废弃但文件残留)
|
||||
- **新系统**:`t_ai_provider` / `t_ai_endpoint_config` / `t_ai_scene_binding` 三表 + `AiRoutingList.vue`(路由当前指向的页面)
|
||||
|
||||
## 2. 当前状态确认
|
||||
|
||||
### 前端调用链路(全部走新系统)
|
||||
|
||||
| 项目 | 调用方式 | 目标接口 | 状态 |
|
||||
|------|---------|---------|------|
|
||||
| web | `streamAiScene()` → `fetch('/ai/runtime/stream')` | AiRuntimeService.invokeStream() | ✅ |
|
||||
| web-admin | `streamAiRuntime()` → `fetch('/ai/runtime/stream')` | AiRoutingController.runtimeStream() | ✅ |
|
||||
| life-script | `streamAiScene()` → `fetch('/ai/runtime/stream')` | AiRuntimeService.invokeStream() | ✅ |
|
||||
| mini-program | `streamAiScene()` → `uni.request('/ai/runtime/stream')` | AiRuntimeService.invokeStream() | ✅ |
|
||||
|
||||
### 后端服务调用链路(全部走新系统)
|
||||
|
||||
| 服务 | 调用方式 | 目标方法 | 状态 |
|
||||
|------|---------|---------|------|
|
||||
| AiChatServiceImpl | `aiRuntimeService.test()` | AiRuntimeServiceImpl.test() | ✅ |
|
||||
| WebSocketServiceImpl | `aiRuntimeService.invokeStream()` | AiRuntimeServiceImpl.invokeStream() | ✅ |
|
||||
| EpicScriptServiceImpl | `aiRuntimeService.test()` | AiRuntimeServiceImpl.test() | ✅ |
|
||||
| LifeEventServiceImpl | `aiRuntimeService.test()` | AiRuntimeServiceImpl.test() | ✅ |
|
||||
|
||||
### 数据库配置现状
|
||||
|
||||
`t_ai_provider` 已有 `dify_default`(`http://49.232.138.53/v1`,api_key=`app-MqQOx09gCu9zzlKMpeLqHQHv`),`t_ai_endpoint_config` 已迁移 Dify 对话接口。但场景绑定需注意:
|
||||
|
||||
- `chat` → Coze endpoint(旧系统遗留绑定)
|
||||
- `script_generate` → **Dify endpoint** ✅
|
||||
- `short_story_generate` → **Dify endpoint** ✅
|
||||
- `diary_summary` → Coze endpoint
|
||||
- `emotion_summary` → Coze endpoint
|
||||
- `emotion_analysis` → Coze endpoint
|
||||
- `life_healing` → Coze endpoint
|
||||
|
||||
**结论**:在 web-admin 测试 `script_generate` 和 `short_story_generate` 场景时,会走 Dify;其他场景走 Coze。这是预期行为。
|
||||
|
||||
## 3. 设计方案
|
||||
|
||||
### 3.1 删除旧系统残留
|
||||
|
||||
删除 `web-admin/src/views/aiconfig/AiConfigList.vue`。该文件路由已不再指向它,保留只会引起混淆。对应的后端 `/aiConfig/*` 接口保持不变(以防有遗留数据查询需求)。
|
||||
|
||||
### 3.2 新系统测试对话框增强
|
||||
|
||||
在 `AiRoutingList.vue` 的流式测试对话框(当前标题"流式调用测试")中增加「非流式测试」按钮,并将对话框标题改为「接口测试」:
|
||||
|
||||
- 流式测试走 `/ai/runtime/stream` → `streamAiRuntime()`(已有)
|
||||
- 非流式测试走 `/ai/runtime/test` → `testAiRuntime()`(已有接口,但当前未 import)
|
||||
- 两个按钮共享 `testing` 加载状态,避免并发冲突
|
||||
- 非流式和流式测试结果各自独立展示,互不干扰
|
||||
- 打开对话框时同时清空两个结果
|
||||
|
||||
### 3.3 路由清理
|
||||
|
||||
路由配置 `/aiconfig/list` 已正确指向 `AiRoutingList.vue`,无需改动。
|
||||
|
||||
### 3.4 数据库配置检查
|
||||
|
||||
实施前需确认生产数据库中 Dify provider 和 Dify endpoints 处于 `is_enabled = 1` 状态。SQL 迁移脚本 `2026-05-22-ai-scene-routing.sql` 中已设置了 `is_enabled = 1`,但可能在实际部署时未执行。
|
||||
|
||||
## 4. 风险
|
||||
|
||||
- 删除 `AiConfigList.vue` 后如果用户需要查询旧 `t_ai_config` 数据,仍有后端 `/aiConfig/*` 接口可用
|
||||
- 非流式测试新增不影响已有功能
|
||||
- Dify provider 和 endpoint 需确保 `is_enabled = 1`,否则测试会返回 `AI_ENDPOINT_DISABLED` 或 `AI_PROVIDER_DISABLED`
|
||||
Reference in New Issue
Block a user