chat: send a file to a room, and bound what an agent may attach #81

Merged
mikluko merged 1 commit from send-file into main 2026-11-16 10:14:06 +00:00
Owner

The room's end of an agent's attach (spec-bb1.39), against the seam of roomcity-b8's #77 (server.Files: SendFile(ctx, session, File) (event, err)), which the serve adapter fills in once #77 is on main.

  • chat.Driver.SendFile(ctx, room, speaker, File{Name, MediaType, Caption, Data}). Matrix: the file is uploaded to the media repository as the agent's user and sent as an m.image when it is a PNG, JPEG or GIF whose size can be read (info has the type, size, width and height), else as an m.file; an SVG is a file until a client is seen to draw one. The caption is the body and the name the filename; with no caption the name is the body. A 413 on the upload is chat.ErrFileTooLarge; another answer of 4xx is a refusal (#68's chat.Refused); anything else is the homeserver out of reach.
  • (*chat.Service).Attach(ctx, session, File) (MessageID, error) applies the bounds, which are keys of [chat]: max_file (a size, "10MiB" by default) and file_kinds (media types or type/*; default image/*, text/*, application/pdf, application/json). Errors wrap chat.ErrFileTooLarge, ErrFileKind, ErrNoRoom (a session with no room yet) or ErrChatDown with a text that says what the room takes, for the agent to read.
  • Tests: the service's bounds and the four errors against the fake driver; on a Tuwunel, a PNG with a caption comes back as an m.image with its width and height and the same bytes from the media repository, a text file as an m.file, an SVG as an m.file; the upload's 413 and the picture that cannot be read.

It is on #68's branch (it uses chat.Refused): merge it after. Not here: the serve adapter (after #77), the transcript's File event and the renderer's default case for it (b8's type), the incoming direction.

The room's end of an agent's `attach` (spec-bb1.39), against the seam of roomcity-b8's #77 (`server.Files`: `SendFile(ctx, session, File) (event, err)`), which the serve adapter fills in once #77 is on main. - `chat.Driver.SendFile(ctx, room, speaker, File{Name, MediaType, Caption, Data})`. Matrix: the file is uploaded to the media repository as the agent's user and sent as an `m.image` when it is a PNG, JPEG or GIF whose size can be read (`info` has the type, size, width and height), else as an `m.file`; an SVG is a file until a client is seen to draw one. The caption is the body and the name the `filename`; with no caption the name is the body. A 413 on the upload is `chat.ErrFileTooLarge`; another answer of 4xx is a refusal (#68's `chat.Refused`); anything else is the homeserver out of reach. - `(*chat.Service).Attach(ctx, session, File) (MessageID, error)` applies the bounds, which are keys of `[chat]`: `max_file` (a size, `"10MiB"` by default) and `file_kinds` (media types or `type/*`; default `image/*`, `text/*`, `application/pdf`, `application/json`). Errors wrap `chat.ErrFileTooLarge`, `ErrFileKind`, `ErrNoRoom` (a session with no room yet) or `ErrChatDown` with a text that says what the room takes, for the agent to read. - Tests: the service's bounds and the four errors against the fake driver; on a Tuwunel, a PNG with a caption comes back as an `m.image` with its width and height and the same bytes from the media repository, a text file as an `m.file`, an SVG as an `m.file`; the upload's 413 and the picture that cannot be read. It is on #68's branch (it uses `chat.Refused`): merge it after. Not here: the serve adapter (after #77), the transcript's File event and the renderer's default case for it (b8's type), the incoming direction.
chat: keep how far each session is shown, and take the stream up from there
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 42s
91506374b7
Assisted-By: Claude <noreply@anthropic.com>
chat: send a file to a room, and bound what an agent may attach
Some checks failed
image / image (pull_request) Successful in 18s
test / changelog (pull_request) Failing after 5s
test / go (pull_request) Successful in 40s
1915c1b0a9
Assisted-By: Claude <noreply@anthropic.com>
mikluko force-pushed send-file from 1915c1b0a9
Some checks failed
image / image (pull_request) Successful in 18s
test / changelog (pull_request) Failing after 5s
test / go (pull_request) Successful in 40s
to b38512952f
Some checks failed
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 22s
test / go (pull_request) Has been cancelled
2026-11-16 09:49:28 +00:00
Compare
mikluko force-pushed send-file from b38512952f
Some checks failed
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 22s
test / go (pull_request) Has been cancelled
to a81f407b80
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 20s
test / go (pull_request) Successful in 50s
2026-11-16 09:50:01 +00:00
Compare
Author
Owner

Read at a81f407 (its own commit, on #68's old branch). The driver's part holds: the upload as the agent's user, an m.image only for a picture whose size can be read, the caption and the name where clients look for them, a 413 told from the other refusals. One change before it merges, and two things for the wiring.

  1. The kind that Attach checks is the one the caller names. That name is the session's word: the host makes it from the file's extension, and a session can also make the call itself, with its own token, and say what it likes. So file_kinds holds for the names of files and not for what they are: a zip called notes.txt is a text/plain that the room takes, and anything at all called x.png is an image/png (sent as a file, since it does not read as a picture, but sent). The bound is the owner's, on what an agent may put in the room. Check it against what the bytes show (http.DetectContentType knows the kinds the default list names, and what it calls application/octet-stream is nothing it can vouch for), refuse a file whose bytes belong to another kind than the one named, and upload it under the kind that was checked. A test with a zip named as text and an HTML page named as a picture.

  2. For the adapter in serve, with roomcity-b8: the server's handler maps its own server.ErrFileTooLarge, ErrFileKind, ErrNoRoom and ErrChatDown, and Attach wraps chat's four of the same names, which are other values. The adapter has to turn one into the other, or every refusal reaches the agent as Internal.

  3. Also for the adapter: there are two bounds on size and they do not know of each other. The server reads no further than server.DefaultMaxFile, a constant of 10 MiB, before the call reaches Attach; [chat] max_file is checked after. A city that raises max_file gets the server's refusal at 10 MiB all the same. One number, from [chat] max_file, has to reach LimitSend and Host.MaxFile.

It is behind main by the release and #76; rebase onto main with the change.

Read at a81f407 (its own commit, on #68's old branch). The driver's part holds: the upload as the agent's user, an `m.image` only for a picture whose size can be read, the caption and the name where clients look for them, a 413 told from the other refusals. One change before it merges, and two things for the wiring. 1. The kind that `Attach` checks is the one the caller names. That name is the session's word: the host makes it from the file's extension, and a session can also make the call itself, with its own token, and say what it likes. So `file_kinds` holds for the names of files and not for what they are: a zip called `notes.txt` is a `text/plain` that the room takes, and anything at all called `x.png` is an `image/png` (sent as a file, since it does not read as a picture, but sent). The bound is the owner's, on what an agent may put in the room. Check it against what the bytes show (`http.DetectContentType` knows the kinds the default list names, and what it calls `application/octet-stream` is nothing it can vouch for), refuse a file whose bytes belong to another kind than the one named, and upload it under the kind that was checked. A test with a zip named as text and an HTML page named as a picture. 2. For the adapter in serve, with roomcity-b8: the server's handler maps its own `server.ErrFileTooLarge`, `ErrFileKind`, `ErrNoRoom` and `ErrChatDown`, and `Attach` wraps `chat`'s four of the same names, which are other values. The adapter has to turn one into the other, or every refusal reaches the agent as Internal. 3. Also for the adapter: there are two bounds on size and they do not know of each other. The server reads no further than `server.DefaultMaxFile`, a constant of 10 MiB, before the call reaches `Attach`; `[chat] max_file` is checked after. A city that raises `max_file` gets the server's refusal at 10 MiB all the same. One number, from `[chat] max_file`, has to reach `LimitSend` and `Host.MaxFile`. It is behind main by the release and #76; rebase onto main with the change.
mikluko force-pushed send-file from a81f407b80
All checks were successful
test / changelog (pull_request) Successful in 6s
image / image (pull_request) Successful in 20s
test / go (pull_request) Successful in 50s
to 257f2695d2
Some checks failed
test / changelog (pull_request) Failing after 9s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 1m11s
2026-11-16 09:59:57 +00:00
Compare
mikluko force-pushed send-file from 257f2695d2
Some checks failed
test / changelog (pull_request) Failing after 9s
image / image (pull_request) Successful in 17s
test / go (pull_request) Successful in 1m11s
to e5c74d3c28
Some checks failed
test / changelog (pull_request) Successful in 5s
image / image (pull_request) Successful in 23s
test / go (pull_request) Failing after 11m14s
2026-11-16 10:02:43 +00:00
Compare
mikluko deleted branch send-file 2026-11-16 10:14:06 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mikluko/roomcity!81
No description provided.