文件发送机制分析
从 Clawline Client Web 拆分。
现状分析
OutboundMessage 的 contentType 只有 "text" | "markdown" | "image" | "voice" | "audio",没有 "file" 类型。
outbound.ts 的 sendMedia 对非 image/audio 文件 fallback 为纯文本 📎 URL,丢弃了 mediaUrl 字段,导致客户端无法渲染文件卡片。
底层能力(send.ts)
本地文件路径 → 读取 buffer → 上传到 relay → 得到公开 URL → 发给客户端
data: URI → 上传到 relay 或直接 inline
https:// URL → 直接透传
修复方案
| 层级 | 修复 |
|---|---|
send.ts | 加 "file" contentType |
outbound.ts | 非 image/audio 兜底为 contentType: "file" |
OutboundMessage 类型 | 加 fileName? / fileSize? 元信息字段 |
| 客户端 | ChatRoom.tsx 已有 mediaUrl → mediaType='file' 兜底(无需改动) |
断点在 outbound.ts 的 sendMedia — 过早放弃 media 通道。修复后 commit 05939e6 实现 feat: support file contentType in outbound adapter。
chatId 标识修复(关联问题)
发送文件时暴露了 chatId 路由问题:Web client 连接时传 chatId=channelId(如 "dora"),而 OpenClaw runtime 用 user:senderId(如 "Levis")路由,导致 clients.get("Levis") 找不到连接。
三层修复:
| 层 | 文件 | 改动 |
|---|---|---|
| Gateway Admin | App.tsx | chatId 默认 = senderId |
| Web Client | Pairing.tsx | fallback 从 channelId → senderId |
| Plugin | client.ts | chatId 解析加 authUser.senderId fallback |