feat: AI Town MVP - 完整三层架构实现
- Python FastAPI 引擎:世界状态模拟、全局能量条、世界事件系统 - Node.js WebSocket 服务器:实时通信、事件队列批处理 - 前端仪表盘:世界状态可视化、行动日志、事件展示 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
52
server-node/README.md
Normal file
52
server-node/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# AI Town Server (Node.js)
|
||||
|
||||
WebSocket 服务器,连接前端和 Python 引擎。
|
||||
|
||||
## 功能
|
||||
|
||||
- HTTP 静态托管 `../web` 目录
|
||||
- WebSocket 接收客户端消息并入队
|
||||
- 每 2 秒批量调用 Python 引擎并广播结果
|
||||
|
||||
## 启动
|
||||
|
||||
```bash
|
||||
# 安装依赖
|
||||
npm install
|
||||
|
||||
# 开发模式(热重载)
|
||||
npm run dev
|
||||
|
||||
# 生产构建
|
||||
npm run build
|
||||
npm start
|
||||
```
|
||||
|
||||
## 依赖服务
|
||||
|
||||
启动前需先运行 Python 引擎:
|
||||
|
||||
```bash
|
||||
cd ../engine-python
|
||||
uvicorn app.main:app --port 8000
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
- `GET /health` - 健康检查,返回 `ok`
|
||||
- `WebSocket /` - 游戏消息通道
|
||||
|
||||
## WebSocket 协议
|
||||
|
||||
**客户端发送:**
|
||||
```json
|
||||
{ "type": "comment", "text": "你好", "user": "玩家A" }
|
||||
```
|
||||
|
||||
**服务端广播:**
|
||||
```json
|
||||
{
|
||||
"world_state": { "tick": 1, "weather": "sunny", ... },
|
||||
"actions": [{ "agent_id": "alice", "say": "...", "do": "..." }]
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user