DSH / Atlas
2026-10-21implementedfeature

Composer image upload on add

输入框在加入时上传图片

The Web composer kept image drafts in the browser and base64-encoded each image into `session/prompt` at send time, so the Host received, validated, normalized, and stored image bytes inside prompt admission. Generic files already uploaded when picked ([generic file upload](2026-08-26-generic-file-upload.md)). An image message therefore carried up to the per-message image byte limit in one RPC body, and its send time

English

Problem

The Web composer kept image drafts in the browser and base64-encoded each image into session/prompt at send time, so the Host received, validated, normalized, and stored image bytes inside prompt admission. Generic files already uploaded when picked (generic file upload). An image message therefore carried up to the per-message image byte limit in one RPC body, and its send time grew with image size; a composer that waits for the Host to accept a message before clearing it would hold the draft for that whole transfer.

Decision

An ordinary Session's composer uploads each image draft as soon as it is added, through the same FIFO background-upload queue, Worker carriers, progress, retry, and cancellation that generic files use. The raw upload route takes a mediaType query parameter for an image upload; the Host reads at most the smaller of the deployment's per-image and per-message image byte limits, then validates, normalizes, and stores the image with ctx.attachments.saveImages exactly as prompt admission would, and stages the normalized image under a receipt for that Session. The prompt cites the receipt in an ordinary file part, so session/prompt keeps its wire types; prompt admission resolves the receipt to the stored image, applies the model's image-input check to the prompt, and counts stored images toward maxImagesPerMessage and maxMessageImageBytes together with encoded ones, each stored image by the bytes of its upload. Send waits until every image draft has a receipt, and a failed image upload turns its thumbnail into a retry control. Commands accept only file receipts, so command submissions keep encoding images inline. A continuable subagent's composer keeps inline images because the Host stages uploads only for ordinary Sessions; SDK and other wire callers may still send encoded images.

Alternatives considered

  • A dedicated image-receipt prompt part. Rejected: the receipt already names what was staged, so a second part kind would widen the session/prompt wire union, its generated catalogs, and every consumer that switches on parts without changing what the Host admits.
  • A separate image upload route or Remote method. Rejected: one route with an explicit mediaType parameter reuses Session addressing, carrier selection, progress, and the failure envelope; the exact-bytes Remote fallback has no image caller.
  • Upload images but normalize them at send. Rejected: normalization is the expensive part of image admission, so deferring it would keep the send-time cost this change removes.

Consequences

  • Sending an image message transfers only references, and the normalization cost moves to the moment the image is added.
  • Per-image refusals such as an undecodable or oversized image surface when the image is added: the thumbnail names the refusal instead of offering a retry, and Enter repeats it. The model's image-input check and the per-message image count and byte limits still apply at send.
  • Commands accept only file receipts, so a command submission that carries an image waits for the image upload like a message and then encodes the image inline: the image is stored a second time, and its unused receipt lasts until its Session ends.
  • Removing an image while it uploads cancels the upload, and a cancelled upload receives no receipt; an image whose storage had already begun, or whose upload had finished, stays under DSH_HOME, which never deletes attachments. On a remote Host the bytes reach the server as soon as the user adds the image.
  • Staged image receipts share the generic files' in-memory lifetime: a Host restart between adding and sending surfaces FILE_NOT_STAGED, and the user adds the image again.
  • Image drafts, like file drafts, are not restored after a page reload or after their Session's client scope is released.

Testing

Host coverage pins image staging through the raw route, the per-image byte bound that stops reading, unsupported types, subagent refusal, command refusal of image receipts, receipt resolution into the admitted image, the image-input check for an uploaded image, the per-message byte limit across receipts, and withheld receipts for uploads cancelled after their last chunk or during storage. Attachment admission coverage pins stored-image pass-through and the combined image count and byte limits. Client coverage pins image upload start, retry, cancellation, the send gate, receipt citation without re-encoding, inline images for drafts without an upload, the rail's progress, retry, and refusal states, and the Enter explanation of a held send.

Related

The generic file upload note owns the background-upload queue, carriers, staging lifetime, and file storage that image uploads reuse.

中文

问题

Web 输入框把图片草稿留在浏览器里,发送时才把每张图片 base64 编码进 session/prompt,Host 在 prompt 准入时才接收、校验、规整并存储图片字节。通用文件早已在选中时上传(通用文件上传)。因此一条图片消息要在一个 RPC 请求体里携带最多达到单条消息图片字节上限的数据,发送耗时随图片大小增长;如果输入框要等 Host 接纳消息后才清空,草稿就要在整个传输期间一直保留。

决定

普通 Session 的输入框在图片草稿加入时就上传它,复用通用文件的先进先出后台上传队列、Worker 载体、进度、重试与取消。原始上传路由用 mediaType 查询参数表示图片上传;Host 最多读取部署配置的单张图片与单条消息图片字节上限中较小的一个,然后按 prompt 准入的同样方式用 ctx.attachments.saveImages 校验、规整并存储图片,再以该 Session 的凭证暂存规整后的图片。prompt 在普通文件部分引用该凭证,因此 session/prompt 的线上类型不变;prompt 准入把凭证解析为已存储的图片,对这条 prompt 执行模型的图片输入检查,并把已存储图片与编码图片一起计入 maxImagesPerMessage 和 maxMessageImageBytes,已存储图片按其上传的字节数计入。发送会等到每个图片草稿都取得凭证;图片上传失败时,缩略图变成重试控件。命令只接受文件凭证,所以命令提交仍以内联方式编码图片。continuable 子代理的输入框继续内联图片,因为 Host 只为普通 Session 暂存上传;SDK 和其他线上调用方仍可发送编码图片。

考虑过的替代方案

  • 专用的图片凭证 prompt 部分。 已否决:凭证本身已经指明暂存的内容,新增一种部分类型会扩大 session/prompt 线上联合类型、它的生成目录以及每个按部分类型分支的消费方,却不改变 Host 准入的内容。
  • 单独的图片上传路由或 Remote 方法。 已否决:一条带显式 mediaType 参数的路由复用了 Session 寻址、载体选择、进度和失败信封;精确字节的 Remote 兜底没有图片调用方。
  • 加入时上传、发送时再规整。 已否决:规整是图片准入中开销最大的部分,推迟它会保留这次改动要消除的发送耗时。

后果

  • 发送图片消息只传引用,规整开销移到图片加入的时刻。
  • 无法解码、超过单张上限等逐张拒绝在图片加入时出现:缩略图说明拒绝原因而不提供重试,按 Enter 也会提示同样的原因。模型的图片输入检查以及单条消息的图片数量与总字节上限仍在发送时执行。
  • 命令只接受文件凭证,所以带图片的命令提交也要像消息一样等图片上传完成,再以内联方式编码图片:同一张图会再存储一次,未被引用的凭证一直留到 Session 结束。
  • 图片上传中移除会取消上传,取消的上传不会取得凭证;已开始存储或已上传完成的图片仍留在 DSH_HOME 下,附件存储从不删除。Host 在远端时,用户一加入图片,字节就到达服务器。
  • 暂存的图片凭证与通用文件同样只存在内存里:在加入与发送之间重启 Host 会得到 FILE_NOT_STAGED,用户需要重新加入图片。
  • 与文件草稿一样,图片草稿在页面刷新后或其 Session 的客户端作用域释放后不会恢复。

测试

Host 侧覆盖经原始路由暂存图片、单张字节上限一超出即停止读取、不支持的类型、子代理拒绝、命令拒绝图片凭证、凭证解析为准入后的图片、已上传图片的图片输入检查、多个凭证合计的单条消息字节上限,以及在最后一个分块之后或存储期间取消的上传不签发凭证。附件准入覆盖已存储图片原样通过,以及合并后的图片数量与总字节上限。客户端覆盖图片上传的开始、重试、取消、发送闸门、发送时引用凭证而不重新编码、没有上传的草稿以内联方式发送图片,附件栏的进度、重试与拒绝状态,以及发送被挡住时按 Enter 的说明。

相关记录

通用文件上传 记录负责图片上传所复用的后台上传队列、载体、暂存生命周期与文件存储。