Skip to main content

Module attachments

Module attachments 

Source
Expand description

#499: pictures on disk — the original at full size, and a copy small enough for the wire.

A picture rides in every later request of the session, so a 2 MiB ceiling on what goes on the wire is right. Applying that ceiling to the file someone attached was not: an 18 MB photo from a camera could not enter the conversation at all, and the only options it left — shrink it yourself, or put it on the box and pass a path — both lose the thing the person wanted.

So two copies, and they mean different things:

  • The original, byte-identical to what was uploaded, under <root>/<session>/<sha256[:16]>-<name>.<ext>. Never rewritten; the hash in the name means a re-sent picture costs nothing and two sessions’ copies stay distinct. A later turn can crop it at full resolution, hand it to a render as a reference, or send it as a file.
  • The working copy, at or under COPY_TARGET_BYTES, sent to the model. Shrunk to MAX_EDGE and then by quality, in that order, because resolution is what a model reads. PNG stays PNG (a screenshot re-encoded as JPEG rings around text, which is exactly what the model was asked about); JPEG stays JPEG at q88.

A picture already under the target needs no second file: the original is the working copy, and Stored::resized says so. That is the common case — a screenshot — and it costs one write.

Nothing here calls a network, and nothing here modifies a file it did not create. The store is 0600 in a 0700 directory, and Store::prune is least-recently-used against a byte budget, because an 18 MB-per-photo default with no ceiling fills a disk.

Structs§

Store
Where pictures are kept, and how much room they may take.
Stored
A picture kept on disk.

Enums§

Helper
One of the three helpers this build knows how to drive, chosen by what is installed.

Constants§

COPY_TARGET_BYTES
What a working copy aims for, so it has headroom under WIRE_LIMIT_BYTES rather than exactly touching it — base64 padding and a header’s own overhead are not worth a refusal.
MAX_EDGE
The longest edge a working copy keeps. Enough for a model to read text in a screenshot and to see detail in a photo, and small enough that the copy is a fraction of the original.
WIRE_LIMIT_BYTES
The wire limit a picture has to fit: what rides in the request body and in the history.

Functions§

dimensions
The pixel size, read from the header — PNG, JPEG, WebP and GIF, no decoder.