docs(wiki): 系统性更新 — L0速览+L1模块标准化+L2功能链路映射(33条)
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

三层架构增强:
- L0 index.md: 用户功能清单+跨模块数据流全景图+导航树增强 (92→143行)
- L1 8个模块页标准化: 功能清单/API接口/测试链路/已知问题
  routing(252→326) chat(101→157) saas(153→230) memory(182→333)
  butler(137→179) middleware(121→159) hands-skills(218→257) pipeline(111→156)
- L1 新增2页: security.md(157行) data-model.md(180行)
- L2 feature-map.md: 33条端到端功能链路映射(408行)

维护机制: CLAUDE.md §8.3 wiki触发规则 5→9条
设计文档: docs/superpowers/specs/2026-04-21-wiki-systematic-overhaul-design.md
This commit is contained in:
iven
2026-04-21 23:48:19 +08:00
parent 58ff0bdde7
commit ed77095a37
15 changed files with 1672 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
---
title: 聊天系统
updated: 2026-04-17
updated: 2026-04-21
status: active
tags: [module, chat, stream]
---
@@ -26,6 +26,20 @@ tags: [module, chat, stream]
{ onDelta, onThinkingDelta, onTool, onHand, onComplete, onError }
```
## 功能清单
| 功能 | 描述 | 入口文件 | 状态 |
|------|------|----------|------|
| 发送消息 | 流式/非流式,支持 thinking | streamStore.ts | ✅ |
| 流式响应 | SSE/Tauri Event 实时推送 | streamStore.ts | ✅ |
| 模型切换 | 运行时切换 LLM 模型 | conversationStore.ts | ✅ |
| 上下文管理 | 会话持久化 + 跨会话恢复 | conversationStore.ts | ✅ |
| 取消流式 | 原子标志位中断 | kernel-chat.ts | ✅ |
| Agent 聊天 | 指定 agent_id 独立对话 | streamStore.ts | ✅ |
| 课堂聊天 | 教育场景专用 | classroomStore.ts | ✅ |
| 消息持久化 | IndexedDB 存储 | messageStore.ts | ✅ |
| 聊天产物 | 附件/代码块管理 | artifactStore.ts | ✅ |
## 代码逻辑
### 发送消息流
@@ -79,6 +93,41 @@ UI 选择模型 → conversationStore.currentModel = newModel
→ 本地模式: 直接使用用户配置的模型
```
## API 接口
### Tauri 命令
**聊天核心** (`desktop/src-tauri/src/kernel_commands/chat.rs`):
| 命令 | 参数 | 返回值 | 说明 |
|------|------|--------|------|
| `agent_chat` | ChatRequest { agent_id, message, thinking_enabled?, model? } | `ChatResponse` | 非流式聊天 |
| `agent_chat_stream` | StreamChatRequest { +session_id } | Tauri Event 流 | 流式聊天(主路径) |
| `cancel_stream` | session_id | `()` | 取消当前流式 |
**课堂聊天** (`desktop/src-tauri/src/classroom_commands/chat.rs`):
| 命令 | 参数 | 返回值 | 说明 |
|------|------|--------|------|
| `classroom_chat` | { classroom_id, user_message, scene_context? } | `Vec<ClassroomChatMessage>` | 课堂对话 |
| `classroom_chat_history` | classroom_id | `Vec<ClassroomChatMessage>` | 历史消息 |
**流式事件类型** (agent_chat_stream emit):
`Delta` / `ThinkingDelta` / `ToolStart` / `ToolEnd` / `HandStart` / `HandEnd` / `SubtaskStatus` / `IterationStart` / `Complete` / `Error`
### SaaS Relay 路由
| 方法 | 路径 | 说明 |
|------|------|------|
| POST | `/api/v1/relay/chat/completions` | OpenAI 兼容格式,支持 session_key/agent_id 透传 |
## 测试链路
| 功能 | 测试文件 | 测试数 | 覆盖状态 |
|------|---------|--------|---------|
| ChatStore 完整流程 | `tests/desktop/chatStore.test.ts` | 11 | ✅ sendMessage/sessionKey/agent隔离/stream相关 |
| 类型契约测试 | `tests/seam/chat-seam.test.ts` | 8 | ✅ StreamChatRequest/ChatResponse camelCase/Event tagged union |
## 关联模块
- [[routing]] — 路由决定使用哪种 client
@@ -99,3 +148,10 @@ UI 选择模型 → conversationStore.currentModel = newModel
| `desktop/src/lib/gateway-client.ts` | Gateway ChatStream (WS) |
| `desktop/src/components/ChatArea.tsx` | 聊天区域 UI |
| `crates/zclaw-runtime/src/loop_runner.rs` | Rust 主聊天循环 |
## 已知问题
- ⚠️ **B-CHAT-07: 混合域截断** — P2 Open。跨域消息时可能截断上下文
-**SSE Token 统计为 0** — P2 已修复 (SseUsageCapture stream_done flag)
-**Tauri invoke 参数名 snake_case** — P1 已修复 (commit f6c5dd2)
-**Provider Key 解密致 relay 500** — P1 已修复 (commit b69dc61)