Skip to content

feat(serve): image input and an image read route for graphical clients #558

Closed

Description

@ajianaz

What problem does this solve?

Image input exists in tole-core (#212: ImageRef, jailed load, run_turn_with_images), but tole serve has no way to use it:

  • POST /sessions/{id}/prompt takes {"text"} only. A graphical client cannot attach an image or paste one from the clipboard.
  • A transcript entry that carries payload.images (path, mime, bytes, fnv1a64) cannot be rendered by a client: there is no route that returns the bytes, and a remote client (mobile, a browser) has no access to the server's filesystem anyway.

Every graphical client (#527 desktop, #528 mobile, #529 web) needs both, so the server side should land once, before any client starts.

Proposed solution

Three additive routes/fields, all behind the existing bearer token:

  1. Upload: POST /sessions/{id}/images with the raw bytes as the body. The server sniffs the type (PNG, JPEG, GIF, WebP), enforces the existing 10 MiB cap, spills the file to the existing images directory through the same resolve path the CLI uses, and returns the reference (mime, bytes, fnv1a64, an opaque id).
  2. Prompt: POST /sessions/{id}/prompt accepts an optional images: [<ref id>] next to text. The turn records them as durable references exactly as --image does (no blob in the log). Verify that the serve turn path can pass images through to run_turn_with_images and add the plumbing if it cannot.
  3. Read: GET /sessions/{id}/images/{fnv1a64} returns the bytes of an image that is recorded in that session's log, re-checking the jail and the hash like every provider request does. Anything not referenced by the session is a 404.

Limits and safety (this is the part that needs care, because a remote client can fill the disk):

  • Upload body size limit equal to the image cap, counted inside the existing 32-connection cap.
  • A per-session and a total quota on the spill directory, with a clear error when exceeded.
  • Content type is always sniffed from the bytes, never trusted from the request; the read route serves a fixed Content-Type from the recorded mime plus X-Content-Type-Options: nosniff.
  • Image text is untrusted content from the model's point of view, as for --image today.

Open questions

  • Raw body vs multipart for the upload (raw keeps the hand-rolled server simple).
  • Whether to also accept an inline data: URL in the prompt as a shortcut for small images (simple, but large JSON bodies). Check the server's current request body limit before deciding.
  • Whether uploaded-but-unused images are garbage collected, and when.

Alternatives considered

  • Only an inline base64 images field in the prompt: no extra route, but no way to render history, and large JSON bodies.
  • Serve files by path: rejected, remote clients have no shared filesystem and it widens the jail.

Acceptance criteria

  • Upload, prompt-with-images and read work end to end in the serve test harness (real binary), including resume after a restart.
  • A hash or jail mismatch is reported, never silently served.
  • Oversized, wrong-type, over-quota and unauthenticated requests are refused with tests.
  • No change to the tole-core public API; documented in docs/mobile-control.md.

Part of #523. Related: #212, #524, #527, #528, #529.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions