docs: add architecture plan for OpenClaw mobile app

This commit is contained in:
OpenClaw committed 2026-03-07 00:26:13 +08:00
1 parent 403a538fda
commit a017533b96
2 files changed
+546 -51

No files matched your search

+48 -51
View File
@@ -1,63 +1,60 @@
This is a Kotlin Multiplatform project targeting Android, iOS, Web. # OpenClawApp
* [/composeApp](./composeApp/src) is for code that will be shared across your Compose Multiplatform applications. OpenClawApp 是一个面向 **Android / iOS / Web** 的 OpenClaw 客户端,使用 **Kotlin Multiplatform + Compose Multiplatform** 构建。
It contains several subfolders:
- [commonMain](./composeApp/src/commonMain/kotlin) is for code that’s common for all targets.
- Other folders are for Kotlin code that will be compiled for only the platform indicated in the folder name.
For example, if you want to use Apple’s CoreCrypto for the iOS part of your Kotlin app,
the [iosMain](./composeApp/src/iosMain/kotlin) folder would be the right place for such calls.
Similarly, if you want to edit the Desktop (JVM) specific part, the [jvmMain](./composeApp/src/jvmMain/kotlin)
folder is the appropriate location.
* [/iosApp](./iosApp/iosApp) contains iOS applications. Even if you’re sharing your UI with Compose Multiplatform, 目标不是把 OpenClaw 整体搬到手机运行,而是提供一个稳定、好用的移动端入口:
you need this entry point for your iOS app. This is also where you should add SwiftUI code for your project.
### Build and Run Android Application - 查看会话列表
- 与 OpenClaw 聊天
- 查看状态与默认 agent
- 后续接入推送通知
- 通过中转层(BFF)安全地连接 OpenClaw
To build and run the development version of the Android app, use the run configuration from the run widget ## 当前架构方向
in your IDE’s toolbar or build it directly from the terminal:
- on macOS/Linux 采用三层架构:
```shell
```text
OpenClawApp
↓
BFF / Mobile Gateway
↓
OpenClaw
```
V1 不把移动端直接做成 OpenClaw 插件/渠道,而是先做一个独立客户端。
详细规划见:[`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md)
## 项目结构
- `composeApp/`:共享 UI 与跨平台应用代码
- `iosApp/`:iOS 宿主工程
- `docs/`:架构、接入与迭代文档
## 开发阶段
当前阶段:
1. 建立应用骨架
2. 用 Mock 数据跑通会话/聊天/设置/状态页面
3. 再接入真实 BFF
4. 最后联通 OpenClaw
## 常用命令
### Android
```bash
./gradlew :composeApp:assembleDebug ./gradlew :composeApp:assembleDebug
``` ```
- on Windows
```shell
.\gradlew.bat :composeApp:assembleDebug
```
### Build and Run Web Application ### Web (Wasm)
To build and run the development version of the web app, use the run configuration from the run widget ```bash
in your IDE's toolbar or run it directly from the terminal:
- for the Wasm target (faster, modern browsers):
- on macOS/Linux
```shell
./gradlew :composeApp:wasmJsBrowserDevelopmentRun ./gradlew :composeApp:wasmJsBrowserDevelopmentRun
``` ```
- on Windows
```shell
.\gradlew.bat :composeApp:wasmJsBrowserDevelopmentRun
```
- for the JS target (slower, supports older browsers):
- on macOS/Linux
```shell
./gradlew :composeApp:jsBrowserDevelopmentRun
```
- on Windows
```shell
.\gradlew.bat :composeApp:jsBrowserDevelopmentRun
```
### Build and Run iOS Application ### iOS
To build and run the development version of the iOS app, use the run configuration from the run widget 使用 Xcode 打开 `iosApp/` 后运行。
in your IDE’s toolbar or open the [/iosApp](./iosApp) directory in Xcode and run it from there.
---
Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html),
[Compose Multiplatform](https://github.com/JetBrains/compose-multiplatform/#compose-multiplatform),
[Kotlin/Wasm](https://kotl.in/wasm/)…
We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web).
If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP).
+498
View File
@@ -0,0 +1,498 @@
# OpenClawApp 架构规划(V1)
## 1. 目标
OpenClawApp 不是把 OpenClaw 整体搬到手机上运行,而是做一个 **面向移动端的 OpenClaw 客户端**。
手机端负责:
- 登录与设备绑定
- 会话列表浏览
- 聊天消息收发
- 查看 Agent / Session / Task 状态
- 接收推送通知
- 触发常用控制动作(切换模型、切换 agent、查看状态)
OpenClaw 服务端继续负责:
- Agent 运行
- Tool 调用
- Session 管理
- Subagent / Cron / ACP 等能力
- 模型接入与执行
---
## 2. 核心原则
### 2.1 不直接把 App 做成 OpenClaw 插件
V1 不采用“移动端 App 作为 OpenClaw 渠道插件”的方式接入。
原因:
1. 插件/渠道更适合“消息入口”,不适合承载完整移动端控制台能力。
2. App 后续需要会话列表、状态页、推送、权限控制、文件上传等,这些超出了普通 channel/plugin 的舒适边界。
3. 手机端不应该直接暴露 OpenClaw 内部权限与 provider key。
### 2.2 采用三层架构
推荐架构:
```text
OpenClawApp (Android/iOS/Web)
↓
BFF / Mobile Gateway(自建中转服务)
↓
OpenClaw Gateway / Session Runtime
```
其中:
- **App**:UI + 本地状态 + 用户交互
- **BFF**:鉴权、接口适配、消息转发、推送、聚合查询
- **OpenClaw**:真正的智能体与工具执行系统
---
## 3. 系统分层设计
## 3.1 移动端 App 层
职责:
- 管理服务器配置
- 登录态管理
- 会话列表与消息页展示
- 流式消息渲染
- Agent/模型状态展示
- 本地缓存与离线展示
- 触发推送注册
建议模块:
- `app/core`:配置、常量、环境
- `app/network`:请求封装、鉴权、SSE/WebSocket
- `app/data`:Repository、DTO、缓存模型
- `app/features/sessions`:会话列表
- `app/features/chat`:聊天页
- `app/features/settings`:设置页
- `app/features/status`:运行状态页
- `app/ui`:主题、导航、组件
---
## 3.2 BFF(Backend For Frontend)层
BFF 是整个移动端方案的关键。
职责:
- App 用户鉴权(登录 token / 设备绑定)
- 对 OpenClaw 内部接口做二次封装
- 提供稳定、面向移动端的 API
- 统一消息格式
- 提供流式消息接口(SSE 或 WebSocket)
- 聚合状态(当前模型、当前 agent、session 列表)
- 对接推送服务(FCM / APNs)
- 限流、审计、权限隔离
BFF **不承载 AI 能力**,只做接入层和移动端适配层。
---
## 3.3 OpenClaw 层
保留现有 OpenClaw 能力,BFF 通过以下方式与它对接:
- 查询 session 列表
- 查询 session 历史消息
- 给 session 发消息
- 查询当前模型与 agent 状态
- 查询任务、subagent、cron 执行结果
- 订阅/轮询新消息与执行完成事件
如果后续 OpenClaw 暴露更适合移动端的扩展接口,再考虑写服务端插件,但 **不是 V1 前提**。
---
## 4. 推荐接入方式
## 4.1 V1 接入模式
### App → BFF
统一走 HTTPS API。
- 普通查询:REST
- 实时消息:优先 SSE,其次 WebSocket
- 文件上传:multipart/form-data
### BFF → OpenClaw
优先级:
1. 复用 OpenClaw 已有稳定接口
2. 如现有接口不适合,BFF 做适配/转译
3. 必要时再补一个 OpenClaw 服务端扩展
---
## 4.2 为什么优先 SSE
聊天流式输出场景下,SSE 比 WebSocket 更轻:
- 服务端实现成本低
- 前端接入简单
- 更适合“单向持续推流”的消息场景
- 首版排障更容易
WebSocket 适合后续做:
- typing 状态
- 多事件总线
- 实时任务控制
- 双向推送控制流
**结论:V1 聊天流优先 SSE。**
---
## 5. 安全设计
## 5.1 不在 App 里存 OpenClaw 主密钥
App 不能直接持有:
- OpenClaw provider API keys
- 高权限控制密钥
- 服务器内部凭证
App 只持有:
- App 登录 token
- 短期 refresh token(如果需要)
- 当前用户配置
---
## 5.2 BFF 负责权限隔离
BFF 负责:
- 鉴权
- 用户/设备绑定
- 可访问 session 范围限制
- 关键动作审计
- 限流
- 推送 token 管理
---
## 5.3 建议的部署要求
- BFF 走 HTTPS
- 服务器侧保存 OpenClaw 连接凭据
- 关键操作写日志
- 支持单用户模式(V1 可先只服务你自己)
---
## 6. V1 功能范围(MVP)
V1 只做最小可用闭环:
### 6.1 必做
1. 服务器配置页
- BFF 地址
- 登录 token / 密码
- 默认 agent
2. 会话列表页
- session 名称
- 最后一条消息
- 更新时间
3. 聊天页
- 查看历史消息
- 发送文本消息
- 接收流式回复
- 展示 tool/status 占位信息
4. 设置页
- 查看当前连接状态
- 查看当前模型
- 切换默认 agent
5. 基础状态页
- OpenClaw 在线状态
- 当前模型
- 最近活跃时间
---
### 6.2 暂不做
V1 暂不做:
- 完整文件管理
- 工具调用全过程可视化
- 多账号体系
- 复杂权限模型
- 本地运行 agent
- 离线发送队列
- 复杂群聊/多渠道能力
---
## 7. 推荐 API 设计(BFF 对 App)
## 7.1 认证
### `POST /api/auth/login`
请求:
```json
{
"server": "https://your-bff.example.com",
"password": "***"
}
```
响应:
```json
{
"token": "...",
"user": {
"id": "xiaobai",
"name": "xiaobai"
}
}
```
---
## 7.2 状态
### `GET /api/status`
返回:
```json
{
"online": true,
"openclawVersion": "2026.x",
"currentModel": "cliproxy/gpt-5.4",
"defaultAgent": "main",
"updatedAt": "2026-03-07T00:00:00+08:00"
}
```
---
## 7.3 会话列表
### `GET /api/sessions`
返回:
```json
[
{
"id": "agent:main:main",
"title": "主会话",
"lastMessage": "你好",
"updatedAt": "2026-03-07T00:00:00+08:00"
}
]
```
---
## 7.4 消息历史
### `GET /api/sessions/{id}/messages?cursor=...`
返回标准消息列表,支持分页。
---
## 7.5 发送消息
### `POST /api/sessions/{id}/messages`
请求:
```json
{
"message": "你好"
}
```
响应:
```json
{
"accepted": true,
"messageId": "msg_xxx"
}
```
---
## 7.6 流式消息
### `GET /api/sessions/{id}/stream`
SSE 事件建议:
- `message.delta`
- `message.completed`
- `tool.started`
- `tool.completed`
- `session.updated`
- `error`
---
## 7.7 Agent / 模型
### `GET /api/agents`
### `POST /api/agents/default`
### `GET /api/models/current`
V1 只需要“查询当前模型”和“切换默认 agent”,模型切换可以先不开放。
---
## 8. 客户端数据模型建议
## 8.1 Session
```kotlin
data class SessionSummary(
val id: String,
val title: String,
val lastMessage: String?,
val updatedAt: String,
)
```
## 8.2 Message
```kotlin
data class ChatMessage(
val id: String,
val role: String,
val text: String,
val createdAt: String,
val status: String? = null,
)
```
## 8.3 Status
```kotlin
data class ServerStatus(
val online: Boolean,
val openClawVersion: String,
val currentModel: String,
val defaultAgent: String,
val updatedAt: String,
)
```
---
## 9. UI 结构建议
V1 页面:
1. `ServerConfigScreen`
2. `SessionListScreen`
3. `ChatScreen`
4. `StatusScreen`
5. `SettingsScreen`
导航建议:
- 首次启动:ServerConfig
- 登录后:首页为 SessionList
- 点击 session 进入 Chat
- 底部 tab:Sessions / Status / Settings
---
## 10. 迭代计划
## Phase 1:App 骨架 + Mock 数据
目标:先把 UI 和状态流跑通。
包括:
- 项目目录重构
- 页面路由
- 主题与基础组件
- 假数据仓库
- 会话列表页
- 聊天页
- 设置页
- 状态页
---
## Phase 2:BFF 定义与联调
目标:App 不再吃 Mock 数据,开始走真实接口。
包括:
- 明确 BFF 技术栈
- 定义 API contract
- App 接入真实接口
- SSE 消息流接入
- 基础错误处理
---
## Phase 3:通知与增强
包括:
- 推送通知
- 文件上传
- tool 状态展示
- session 搜索 / pin
- 更完整的状态页
---
## 11. 当前决定
当前项目明确采用以下方向:
1. **不把移动端直接做成 OpenClaw 插件/渠道**
2. **采用 App + BFF + OpenClaw 三层架构**
3. **V1 先做 App 骨架与 Mock 数据**
4. **后续再接真实 BFF 与 OpenClaw**
---
## 12. 下一步
下一步直接进入实现:
1. 建立 App 目录结构
2. 搭建导航
3. 实现以下页面的初版 UI:
- SessionList
- Chat
- Status
- Settings
4. 使用 Mock Repository 跑通完整流程
这一步完成后,再进入 BFF 对接。