docs(wiki): 同步知识库 — 04-21 经验积累+Skill工具调用修复
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
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: 客户端路由
|
||||
updated: 2026-04-17
|
||||
updated: 2026-04-19
|
||||
status: active
|
||||
tags: [module, routing, connection]
|
||||
---
|
||||
@@ -21,29 +21,31 @@ tags: [module, routing, connection]
|
||||
|
||||
## 代码逻辑
|
||||
|
||||
### 4 分支决策树
|
||||
### 5 分支 + 降级决策树
|
||||
|
||||
入口: `connectionStore.ts:349` → `connect(url?, token?)`
|
||||
入口: `connectionStore.ts` → `connect(url?, token?)`
|
||||
|
||||
```
|
||||
connect()
|
||||
│
|
||||
├── [1] Admin 强制路由: localStorage llm_routing
|
||||
│ ├── "relay" → 强制 SaaS Relay 模式
|
||||
│ └── "local" → 强制本地 Kernel (adminForceLocal=true)
|
||||
├── [1] Admin 强制本地: adminRouting === 'local' && isTauri()
|
||||
│ → 直接走 Kernel 模式,跳过 SaaS
|
||||
│
|
||||
├── [2] SaaS Relay 模式: localStorage('zclaw-connection-mode') === 'saas'
|
||||
│ ├── Tauri: KernelClient + baseUrl = saasUrl/api/v1/relay
|
||||
│ │ apiKey = SaaS JWT (不是 LLM Key!)
|
||||
│ ├── Browser: SaaSRelayGatewayClient (SSE)
|
||||
│ └── SaaS 不可达 → 降级到本地 Kernel
|
||||
├── [2] SaaS Relay (Tauri 路径): savedMode === 'saas' && isTauri()
|
||||
│ → KernelClient + baseUrl = saasUrl/api/v1/relay
|
||||
│ → apiKey = SaaS JWT (不是 LLM Key!)
|
||||
│ → SaaS 不可达 → 降级到本地 Kernel
|
||||
│
|
||||
├── [3] 本地 Kernel: isTauriRuntime() === true
|
||||
│ KernelClient + 用户自定义模型配置
|
||||
│ 用户需要自己的 API Key
|
||||
├── [3] SaaS Relay (Browser 路径): savedMode === 'saas' && !isTauri()
|
||||
│ → SaaSRelayGatewayClient (SSE)
|
||||
│ → SaaS 不可达 → 降级到本地 Kernel
|
||||
│
|
||||
└── [4] External Gateway (fallback)
|
||||
GatewayClient via WebSocket/REST
|
||||
├── [4] 本地 Kernel: isTauriRuntime() && 非 SaaS 模式
|
||||
│ → KernelClient + 用户自定义模型配置
|
||||
│ → 用户需要自己的 API Key
|
||||
│
|
||||
└── [5] External Gateway (fallback): !isTauri()
|
||||
→ GatewayClient via WebSocket/REST
|
||||
```
|
||||
|
||||
### SaaS Relay 主路径 (Tauri 桌面端)
|
||||
@@ -86,7 +88,7 @@ listModels() 失败
|
||||
`getClient()` 定义: `connectionStore.ts:844`
|
||||
所有 Store 通过 `initializeStores()` (store/index.ts:94) 获取共享 client。
|
||||
|
||||
### Store 层 (17 文件 + chat/4 = 21)
|
||||
### Store 层 (16 根文件 + chat/4 + saas/5 = 25)
|
||||
|
||||
```
|
||||
desktop/src/store/
|
||||
@@ -98,34 +100,43 @@ desktop/src/store/
|
||||
├── configStore.ts 配置读写
|
||||
├── connectionStore.ts 路由决策核心
|
||||
├── handStore.ts Hand 状态管理
|
||||
├── industryStore.ts 行业配置 (V13 新增,已接通 ButlerPanel)
|
||||
├── industryStore.ts 行业配置 (已接通 ButlerPanel)
|
||||
├── memoryGraphStore.ts 记忆图谱
|
||||
├── offlineStore.ts 离线队列
|
||||
├── saasStore.ts SaaS 认证
|
||||
├── saasStore.ts SaaS 认证 (re-export barrel)
|
||||
├── securityStore.ts 安全状态
|
||||
├── sessionStore.ts 会话管理
|
||||
├── uiModeStore.ts 双模式 UI
|
||||
├── workflowBuilderStore.ts 工作流构建器
|
||||
├── workflowStore.ts 工作流状态
|
||||
└── chat/
|
||||
├── artifactStore.ts 聊天产物
|
||||
├── conversationStore.ts 会话管理
|
||||
├── messageStore.ts 消息持久化
|
||||
└── streamStore.ts 流式编排
|
||||
├── chat/
|
||||
│ ├── artifactStore.ts 聊天产物
|
||||
│ ├── conversationStore.ts 会话管理
|
||||
│ ├── messageStore.ts 消息持久化
|
||||
│ └── streamStore.ts 流式编排
|
||||
└── saas/ (拆分子模块, 04-17 refactor)
|
||||
├── index.ts 子模块入口
|
||||
├── auth.ts 认证逻辑
|
||||
├── billing.ts 计费逻辑
|
||||
├── shared.ts 共享状态/工具
|
||||
└── types.ts 类型定义
|
||||
```
|
||||
|
||||
### lib/ 工具层 (76 个文件)
|
||||
### lib/ 工具层 (75 个 .ts 文件)
|
||||
|
||||
关键分类:
|
||||
|
||||
| 类别 | 文件 | 数量 |
|
||||
|------|------|------|
|
||||
| Kernel 通信 | kernel-chat/kernel-client/kernel-agent/... | 7 |
|
||||
| SaaS 通信 | saas-client/saas-auth/saas-billing/saas-relay/... | 12 |
|
||||
| Gateway | gateway-client/gateway-api/gateway-auth/... | 6 |
|
||||
| Intelligence | intelligence-backend/intelligence-client | 2 |
|
||||
| 工具 | config-parser/crypto-utils/logger/utils | 10+ |
|
||||
| Tauri 集成 | safe-tauri/tauri-gateway/secure-storage | 3 |
|
||||
| Kernel 通信 | kernel-client/kernel-chat/kernel-agent/kernel-skills/kernel-triggers/kernel-hands/... | 8 |
|
||||
| SaaS 通信 | saas-client/saas-auth/saas-billing/saas-relay/saas-industry/saas-knowledge/... | 12 |
|
||||
| Gateway | gateway-client/gateway-api/gateway-auth/gateway-config/... | 9 |
|
||||
| Intelligence | intelligence-backend/intelligence-client/embedding-client/memory-extractor | 4 |
|
||||
| Viking | viking-client | 1 |
|
||||
| Pipeline | pipeline-client/pipeline-recommender | 2 |
|
||||
| Security | crypto-utils/secure-storage/security-audit/security-index/api-key-storage | 5 |
|
||||
| 工具 | config-parser/logger/utils/error-types/error-utils/json-utils/... | 10+ |
|
||||
| Tauri 集成 | safe-tauri/tauri-gateway | 2 |
|
||||
| 工作流 | workflow-builder/ (index + types + yaml-converter) | 3 |
|
||||
|
||||
## 模型路由
|
||||
|
||||
|
||||
Reference in New Issue
Block a user