Files
openclawapp/bff/README.md
T

108 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OpenClawApp BFF
这是 OpenClawApp 的移动端中转后端(BFF,Backend For Frontend)。
## 目标
它负责:
- 统一移动端 API
- 管理鉴权
- 屏蔽 OpenClaw / 上游系统的内部细节
- 提供稳定的 `/api/status`、`/api/sessions`、`/api/messages` 等接口
- 后续承接 SSE / 推送 / 文件上传 / 审计 / 限流
当前提供两种 backend mode:
- `mock`:本地内存数据,方便联调 App
- `openclaw`:预留 OpenClaw 接入 provider(当前还是占位实现)
---
## 目录结构
```text
bff/
app/
main.py
auth.py
config.py
deps.py
models.py
services/
base.py
mock_backend.py
openclaw_backend.py
requirements.txt
.env.example
```
---
## 快速启动
```bash
cd bff
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
uvicorn app.main:app --reload --host 0.0.0.0 --port 8788
```
启动后可访问:
- `GET /healthz`
- `GET /api/status`
- `GET /api/sessions`
- `GET /api/sessions/{session_id}/messages`
- `POST /api/sessions/{session_id}/messages`
- `GET /api/agents`
---
## 鉴权
默认使用 Bearer Token:
```http
Authorization: Bearer dev-token
```
可通过 `.env` 中的 `BFF_AUTH_TOKEN` 修改。
---
## 环境变量
见 `.env.example`。
常用项:
- `BFF_BACKEND_MODE=mock|openclaw`
- `BFF_AUTH_TOKEN=...`
- `BFF_LOGIN_PASSWORD=...`
- `OPENCLAW_BASE_URL=...`
- `OPENCLAW_API_TOKEN=...`
---
## 当前状态
### 已完成
- App 所需基础 API
- Bearer Token 鉴权
- Mock backend
- 可切换 backend provider 架构
- FastAPI 工程骨架
### 下一步
- 真正接上 OpenClaw provider
- SSE 流式输出
- 更完整的错误分类
- Push token 管理
- 文件上传
- 审计日志