feat(agent): 实现 Agent Runtime LLM 配置与消息元数据结构化支持

This commit is contained in:
qzl
2026-03-05 18:25:51 +08:00
parent c07d339a5f
commit db158de39c
26 changed files with 1215 additions and 2914 deletions
-116
View File
@@ -1,116 +0,0 @@
# 前后端 API 对比分析
**Date:** 2026-03-04
**Status:** Open
**Type:** 架构分析
---
## 一、后端已有、前端缺失的 API
### 1. Friendships API (`/api/v1/friends`)
| 方法 | 路径 | 功能 | 前端状态 |
|------|------|------|----------|
| POST | `/requests` | 发送好友请求 | **缺失** |
| GET | `/requests/inbox` | 获取收件箱 | **缺失** |
| GET | `/requests/outgoing` | 获取发出的请求 | **缺失** |
| POST | `/requests/{id}/accept` | 接受好友请求 | **缺失** |
| POST | `/requests/{id}/decline` | 拒绝好友请求 | **缺失** |
| DELETE | `/requests/{id}` | 取消好友请求 | **缺失** |
| GET | `` | 获取好友列表 | **缺失** |
| DELETE | `/{id}` | 删除好友 | **缺失** |
### 2. Inbox Messages API (`/api/v1/inbox/messages`)
| 方法 | 路径 | 功能 | 前端状态 |
|------|------|------|----------|
| GET | `` | 获取消息列表 | **缺失** |
| POST | `/{id}/accept` | 接受邀请 | **缺失** |
| POST | `/{id}/dismiss` | 忽略消息 | **缺失** |
### 3. Chat/AgUi 流式 API
| 功能 | 前端状态 |
|------|----------|
| 发送消息 SSE 流式 | **仅有 Mock** |
| 加载历史记录 | **仅有 Mock** |
> 前端 `AgUiService` 只有本地 mock (`throw UnimplementedError`),未实现真实 API 调用。
### 4. Infra API
| 方法 | 路径 | 功能 | 前端状态 |
|------|------|------|----------|
| GET | `/infra/health` | 基础设施健康检查 | **未使用** |
---
## 二、前端已有、后端已实现的 API
### Auth API (`/api/v1/auth`)
| 方法 | 路径 | 后端 | 前端 |
|------|------|------|------|
| POST | `/verifications` | ✅ | ✅ |
| POST | `/verifications/verify` | ✅ | ✅ |
| POST | `/verifications/resend` | ✅ | ✅ |
| POST | `/sessions` | ✅ | ✅ |
| POST | `/sessions/refresh` | ✅ | ✅ |
| DELETE | `/sessions` | ✅ | ✅ |
| POST | `/password-reset` | ✅ | ✅ |
| POST | `/password-reset/confirm` | ✅ | ✅ |
| GET | `/users` | ✅ | **未使用** |
### Users API (`/api/v1/users`)
| 方法 | 路径 | 后端 | 前端 |
|------|------|------|------|
| GET | `/me` | ✅ | ✅ |
| PATCH | `/me` | ✅ | ✅ |
| POST | `/search` | ✅ | ✅ |
### Schedule Items API (`/api/v1/schedule-items`)
| 方法 | 路径 | 后端 | 前端 |
|------|------|------|------|
| POST | `` | ✅ | **仅有 Mock** |
| GET | `` (range query) | ✅ | **仅有 Mock** |
| GET | `/{id}` | ✅ | **仅有 Mock** |
| PATCH | `/{id}` | ✅ | **仅有 Mock** |
| DELETE | `/{id}` | ✅ | **仅有 Mock** |
| POST | `/{id}/share` | ✅ | **缺失** |
---
## 三、待实现功能清单
| 优先级 | 功能 | 说明 |
|--------|------|------|
| **P0** | FriendsApi | 前端无 Friendships API 客户端 |
| **P0** | InboxMessagesApi | 前端无 Inbox Messages API 客户端 |
| **P0** | Chat/AgUi 后端连接 | 前端 AgUiService 未实现真实 API |
| **P1** | CalendarService 真实 API | MockCalendarService → 真实 API 调用 |
| **P1** | Schedule Share 接口 | 前端未调用 `POST /{id}/share` |
| **P2** | Infra Health 集成 | 可用于前端健康检查 |
---
## 四、相关文件位置
### 前端 API 客户端
- `apps/lib/features/auth/data/auth_api.dart` - Auth API
- `apps/lib/features/users/data/users_api.dart` - Users API
- `apps/lib/features/calendar/data/services/mock_calendar_service.dart` - Calendar Mock
- `apps/lib/features/chat/data/services/ag_ui_service.dart` - Chat/AgUi Mock
- `apps/lib/features/chat/data/services/mock_history_service.dart` - History Mock
### 后端 Router
- `backend/src/v1/auth/router.py` - Auth 路由
- `backend/src/v1/users/router.py` - Users 路由
- `backend/src/v1/friendships/router.py` - Friendships 路由
- `backend/src/v1/inbox_messages/router.py` - Inbox Messages 路由
- `backend/src/v1/schedule_items/router.py` - Schedule Items 路由
- `backend/src/v1/infra/router.py` - Infra 路由
-145
View File
@@ -1,145 +0,0 @@
# 前后端测试分析报告
**Date:** 2026-03-04
**Status:** Completed
---
## 测试统计
### 后端测试
| 类型 | 数量 | 状态 |
|------|------|------|
| Unit Tests | ~100+ | 可运行 |
| Integration Tests | ~70+ | 可运行 |
| E2E Tests | 5 | **无法运行** (缺少 playwright 依赖) |
### 前端测试
| 类型 | 数量 | 状态 |
|------|------|------|
| Flutter Tests | 140 | ✅ 全部通过 |
---
## 问题发现
### 1. 后端 E2E 测试无法运行 (HIGH)
**问题**: 5 个 E2E 测试文件需要 `playwright` 模块,但依赖未安装。
**影响文件**:
- `tests/e2e/test_auth_flow.py`
- `tests/e2e/test_infra_health_e2e.py`
- `tests/e2e/test_logging_e2e.py`
- `tests/e2e/test_mobile_health_e2e.py`
- `tests/e2e/test_profile_flow.py`
**错误**:
```
ModuleNotFoundError: No module named 'playwright'
```
**建议**:
- 安装 playwright: `uv add playwright && uv run playwright install`
- 或者移除这些无法运行的 E2E 测试文件
---
### 2. 测试文件命名冲突导致收集警告 (LOW)
**问题**: 存在多个同名 `test_schemas.py` 文件在不同目录,导致 pytest 收集时显示警告。
**影响文件**:
- `tests/unit/v1/schedule_items/test_schemas.py`
- `tests/unit/v1/profile/test_schemas.py`
- `tests/unit/v1/inbox_messages/test_schemas.py`
- `tests/unit/v1/friendships/test_schemas.py`
**状态**: 测试实际可以正常运行,只是有警告提示。
**建议**: 可保持现状(这是合理的代码组织方式),或重命名为 `test_*.py` 以消除警告。
---
### 3. 遗留测试验证旧字段 (INFO)
**文件**: `tests/unit/v1/profile/test_schemas.py`
**测试**: `test_profile_update_rejects_display_name_field`
**说明**: 此测试验证旧的 `display_name` 字段被正确拒绝。字段已在之前的重构中删除。
**状态**: **有效** - 这是一个回归测试,确保旧字段不被使用。
---
## 未发现的问题
### 冗余测试
经过检查,未发现明显冗余的测试:
- 每个模块的测试覆盖不同的功能
- Unit tests、Integration tests、E2E tests 有清晰的职责划分
### 死代码
未发现测试文件中有未使用的:
- imports
- mock 类
- helper 函数
### 缺失测试
未发现对应已实现功能但缺少测试的情况。
---
## 测试覆盖模块
### 后端
| 模块 | Unit | Integration | E2E |
|------|------|-------------|-----|
| Auth | ✅ | ✅ | ❌ |
| Users | - | ✅ | - |
| Profile | ✅ | - | ❌ |
| Friendships | ✅ | ✅ | - |
| Inbox Messages | ✅ | ✅ | - |
| Schedule Items | ✅ | ✅ | - |
| Logging | ✅ | ✅ | ✅ |
| Settings | ✅ | - | - |
### 前端
| 模块 | 测试数 |
|------|--------|
| Auth | ~20 |
| Chat | ~70 |
| Home | ~15 |
| Calendar | ~5 |
| Core (API, Storage) | ~30 |
---
## 建议
1. **立即**: 解决 E2E 测试依赖问题或移除无法运行的测试文件
2. **可选**: 清理 test_schemas.py 重名警告(低优先级)
3. **保持**: 现有的测试结构良好,无需重大重构
---
## 附: 测试代码质量问题
### 测试类未完全实现 Protocol (LSP 警告)
**文件**: `tests/unit/v1/auth/test_auth_service.py`
**问题**: `FakeGateway``LogoutAssertingGateway` 类没有实现 `AuthServiceGateway` Protocol 的全部方法:
- `request_password_reset`
- `confirm_password_reset`
**影响**: LSP 类型检查器报告错误,但运行时不受影响(因为这些方法在测试中不会被调用)。
**建议**: 可选择补充缺失的方法实现,或使用 `@pytest.mark.skip` 标记不需要的协议方法。
---
*报告生成时间: 2026-03-04*