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
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:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 客户端路由
|
||||
updated: 2026-04-19
|
||||
updated: 2026-04-21
|
||||
status: active
|
||||
tags: [module, routing, connection]
|
||||
---
|
||||
@@ -19,6 +19,20 @@ tags: [module, routing, connection]
|
||||
3. **模型白名单** — Admin 配置哪些模型可用,`listModels()` 返回白名单
|
||||
4. **降级保障** — SaaS 挂了自动切本地 Kernel,桌面端不变砖
|
||||
|
||||
## 功能清单
|
||||
|
||||
| 功能 | 描述 | 入口文件 | 状态 |
|
||||
|------|------|----------|------|
|
||||
| 连接管理 | 5 分支路由决策 + 自动降级 | connectionStore.ts | ✅ |
|
||||
| SaaS Relay 中转 | Tauri 通过 SaaS Token Pool 中转 LLM | connectionStore.ts | ✅ |
|
||||
| 浏览器模式 | SSE 连接 SaaS relay | saas-relay-client.ts | ✅ |
|
||||
| 本地 Kernel | Tauri 内置 Kernel 直连 LLM | kernel-client.ts | ✅ |
|
||||
| 外部 Gateway | WebSocket 独立进程 | gateway-client.ts | ✅ |
|
||||
| Gateway 进程管理 | 启动/停止/重启/状态/诊断 | gateway/commands.rs | ✅ |
|
||||
| 健康检查 | 端口检测 + 完整诊断 | health_check.rs | ✅ |
|
||||
| 设备配对 | 设备审批 + 公钥交换 | gateway/commands.rs | ✅ |
|
||||
| 模型路由 | 白名单验证 + fallback + 别名解析 | connectionStore.ts | ✅ |
|
||||
|
||||
## 代码逻辑
|
||||
|
||||
### 5 分支 + 降级决策树
|
||||
@@ -232,6 +246,61 @@ chatStream() → saasClient.chatCompletion({ model: getModel() })
|
||||
POST /api/v1/relay/chat/completions → SSE 流
|
||||
```
|
||||
|
||||
## API 接口
|
||||
|
||||
### Tauri 命令
|
||||
|
||||
**Gateway 管理** (`desktop/src-tauri/src/gateway/commands.rs`):
|
||||
|
||||
| 命令 | 参数 | 返回值 | 说明 |
|
||||
|------|------|--------|------|
|
||||
| `zclaw_status` | — | `LocalGatewayStatus` | Kernel 运行状态 |
|
||||
| `zclaw_start` | — | `LocalGatewayStatus` | 启动 Kernel |
|
||||
| `zclaw_stop` | — | `LocalGatewayStatus` | 停止 Kernel |
|
||||
| `zclaw_restart` | — | `LocalGatewayStatus` | 重启 Kernel |
|
||||
| `zclaw_local_auth` | — | `LocalGatewayAuth` | 获取本地认证 token |
|
||||
| `zclaw_prepare_for_tauri` | — | `LocalGatewayPrepareResult` | 更新 Tauri allowed origins |
|
||||
| `zclaw_approve_device_pairing` | device_id, public_key_base64, url? | `PairingApprovalResult` | 设备配对审批 |
|
||||
| `zclaw_doctor` | — | `String` | 诊断报告 |
|
||||
| `zclaw_process_list` | — | `ProcessListResponse` | 进程列表 |
|
||||
| `zclaw_process_logs` | pid?, lines? | `ProcessLogsResponse` | 进程日志 |
|
||||
| `zclaw_version` | — | `VersionResponse` | 版本信息 |
|
||||
|
||||
**健康检查** (`desktop/src-tauri/src/health_check.rs`):
|
||||
|
||||
| 命令 | 参数 | 返回值 | 说明 |
|
||||
|------|------|--------|------|
|
||||
| `zclaw_health_check` | port?, timeout_ms? | `HealthCheckResponse` | 完整健康检查 |
|
||||
| `zclaw_ping` | — | `bool` | 快速端口检测 |
|
||||
|
||||
### SaaS Relay 路由 (`crates/zclaw-saas/src/relay/`)
|
||||
|
||||
| 方法 | 路径 | 权限 | 说明 |
|
||||
|------|------|------|------|
|
||||
| POST | `/api/v1/relay/chat/completions` | 认证+配额 | 主聊天中转 |
|
||||
| GET | `/api/v1/relay/models` | 认证 | 可用模型列表 |
|
||||
| GET | `/api/v1/relay/tasks` | 认证 | 任务列表 |
|
||||
| GET | `/api/v1/relay/tasks/:id` | 认证 | 任务详情 |
|
||||
| POST | `/api/v1/relay/tasks/:id/retry` | admin | 重试失败任务 |
|
||||
|
||||
### Provider Key 管理 (`crates/zclaw-saas/src/relay/handlers.rs`)
|
||||
|
||||
| 方法 | 路径 | 权限 | 说明 |
|
||||
|------|------|------|------|
|
||||
| GET | `/api/v1/providers/:id/keys` | admin | 列出 Provider Key |
|
||||
| POST | `/api/v1/providers/:id/keys` | admin | 添加加密 Key |
|
||||
| PUT | `/api/v1/providers/:id/keys/:kid/toggle` | admin | 启停 Key |
|
||||
| DELETE | `/api/v1/providers/:id/keys/:kid` | admin | 删除 Key |
|
||||
|
||||
## 测试链路
|
||||
|
||||
| 功能 | 测试文件 | 测试数 | 覆盖状态 |
|
||||
|------|---------|--------|---------|
|
||||
| Admin 路由解析 | `tests/desktop/connectionStore.adminRouting.test.ts` | — | ✅ parseAdminRouting() 纯函数 |
|
||||
| 连接流程 | `tests/desktop/gatewayStore.test.ts` | — | ✅ connect() + 数据加载 |
|
||||
| GatewayClient | `tests/gateway/ws-client.test.ts` | — | ✅ WS 连接/事件/断连 |
|
||||
| Mock Server | `tests/fixtures/zclaw-mock-server.ts` | — | ✅ HTTP+WS 模拟 |
|
||||
|
||||
## 关联模块
|
||||
|
||||
- [[chat]] — 路由决定使用哪种 ChatStream
|
||||
@@ -250,3 +319,8 @@ POST /api/v1/relay/chat/completions → SSE 流
|
||||
| `desktop/src/lib/saas-relay-client.ts` | SaaS SSE 中继 |
|
||||
| `desktop/src/lib/saas-client.ts` | SaaS API 客户端 |
|
||||
| `desktop/src/store/index.ts` | Store 协调器 + client 注入 |
|
||||
|
||||
## 已知问题
|
||||
|
||||
- ✅ **Tauri invoke 参数名 snake_case vs camelCase** — P1 已修复 (commit f6c5dd2)。Tauri 2.x 默认 `rename_all = "camelCase"`,所有 invoke 调用必须用 camelCase
|
||||
- ✅ **Provider Key 解密失败导致 relay 500** — P1 已修复 (commit b69dc61)。`key_pool.rs` 现在 decrypt 失败时 warn+skip 到下一个 key,启动时 `heal_provider_keys()` 自动重新加密有效 key
|
||||
|
||||
Reference in New Issue
Block a user