fix: XML动作标签 + 意图分析上下文 + 图片file_id引用

- 动作消息改用 <action>...</action> XML 标签(注入器 + 解析器 + 测试)
- 括号解析保留为降级方案,确保向后兼容
- 意图分析传入最近对话历史,防止短追问误判为 iot_query
- 意图提示词强化:短追问明确归为 question,iot_query 需设备名词
- 图片附件支持 file_id 轻量引用(Gateway FileStore 解析 + 上传端点复用)
- API 文档更新:附件新格式 + 图片传递链路

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 19:27:25 +08:00
parent 3e15285065
commit c4de813629
9 changed files with 140 additions and 35 deletions
+15 -7
View File
@@ -175,8 +175,9 @@ ws://<gateway>/ws/chat?token=<jwt>&session_id=<optional>&client_id=<optional>&de
"attachments": [
{
"type": "image",
"url": "string",
"thumbnail_url": "string",
"url": "string (base64 data URI, 旧格式, 向后兼容)",
"file_id": "string (文件 UUID, 新格式推荐, 配合 POST /files/upload 使用)",
"thumbnail_url": "string (缩略图 URL, 跨设备同步友好)",
"filename": "string",
"width": 0,
"height": 0,
@@ -184,6 +185,12 @@ ws://<gateway>/ws/chat?token=<jwt>&session_id=<optional>&client_id=<optional>&de
"description": "string"
}
],
```
> **图片附件两种格式**
> - **旧格式** (`url`): base64 data URI,直接内嵌于 WebSocket 消息中,简单但不适合跨设备同步。
> - **新格式(推荐)** (`file_id`): 先通过 [`POST /api/v1/files/upload`](#post-filesupload) 上传图片获取 `file_id` 和 `thumbnail_url`,消息中只携带轻量引用。Gateway 自动解析为本地文件 URL 传给 AI-Core。
```
"timestamp": 1717000000000,
"client_id": "string",
"device_name": "string",
@@ -486,12 +493,13 @@ Content-Type: `multipart/form-data`。字段 `file`。最大 20MB。
错误: 400 `{"error":"文件大小超过限制 (最大 20MB)","errorType":"file_too_large"}`, 400 `{"error":"不支持的文件类型: ...","errorType":"unsupported_type"}`
> **文件在 AI 对话中的传递链路**:客户端上传文件后获得的 `url` 为相对路径(如 `/api/v1/files/{id}/download`)。当用户消息携带 `attachments` 时
> 1. **Gateway** 在转发前将相对路径补全为绝对 URL`http://127.0.0.1:{port}/api/v1/files/{id}/download`
> 2. **AI-Core** 的 LLM 适配器在调用外部模型 API 前,将非 `data:` 的图片 URL 下载并转为 base64 data URL
> 3. 最终以多模态格式(`[{type: "text", text: "..."}, {type: "image_url", image_url: {url: "data:..."}}]`)传递给 LLM
> **文件在 AI 对话中的传递链路(推荐新流程)**
> 1. **客户端**先调用 [`POST /api/v1/files/upload`](#post-filesupload) 上传图片,获得 `file_id` 和 `thumbnail_url`
> 2. **客户端**发送消息时,`attachments` 中携带 `file_id`(轻量引用,不再内嵌 base64)
> 3. **Gateway** 收到 `file_id` 后,从 `FileStore` 解析为本地下载 URL`http://127.0.0.1:{port}/api/v1/files/{id}/download`
> 4. **AI-Core** 下载该 URL 并转为 base64 data URL,以多模态格式传给外部 LLM API
>
> 即文件存储层对外部 LLM API 透明,无需暴露内网文件服务
> **向后兼容**`attachments[].url` 仍支持 base64 data URI或相对路径,Gateway 会将相对路径补全为绝对 URL
### GET /files — 列表