@linkshell/gateway
v0.2.22
Published
LinkShell Gateway — WebSocket 消息中转服务,连接 CLI 和手机 App。
Readme
@linkshell/gateway
LinkShell Gateway — WebSocket 消息中转服务,连接 CLI 和手机 App。
Gateway 不运行任何终端进程,只负责配对、会话管理和消息路由。
部署
Docker(推荐)
docker compose up -d直接运行
pnpm install
pnpm --filter @linkshell/gateway build
PORT=8787 node packages/gateway/dist/gateway/src/index.js环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| PORT | 8787 | 监听端口 |
| LOG_LEVEL | info | 日志级别:debug / info / warn / error |
API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | /healthz | 健康检查 |
| POST | /pairings | 创建配对(返回 6 位 code,10 分钟有效) |
| POST | /pairings/claim | 用 code 换取 sessionId |
| GET | /pairings/:code/status | 查询配对状态 |
| GET | /sessions | 列出活跃会话 |
| GET | /sessions/:id | 会话详情 |
| WS | /ws?sessionId=&role= | 实时连接(role=host 或 client) |
特性
- 内存态会话管理(无外部依赖)
- ACK 追踪 + 输出缓存(最近 200 条,client 重连时快速重放)
- 单设备控制权管理(claim/grant/reject/release)
- 心跳 ping/pong 检测死连接(20s 间隔)
- 会话 TTL(host 断开保留 60s,空闲 30min 清理)
- IP 限流(配对 30 req/min,WebSocket 20 conn/min)
- CORS 支持
- 协议版本协商
- 优雅关闭(SIGINT/SIGTERM)
代码入口
如果要继续改 Gateway,优先从这几个文件进入:
- src/index.ts
- src/pairings.ts
- src/sessions.ts
- src/relay.ts
License
MIT
