Skip to content

feat(chat): Add images to web chat - #1933

Merged
dcramer merged 6 commits into
mainfrom
feat/web-image-input
Sep 25, 2026
Merged

dcramer merged 6 commits into
mainfrom
feat/web-image-input

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Add image paste, drag-and-drop, and file selection to web chat. Show removable previews and keep images for failed-send retries. Store files before accepting the message, then send the original images to the model. Show web and saved Slack attachments in the transcript under existing access rules.

Accept up to three PNG, JPEG, GIF, or WebP images per message, with a 3 MB total limit. The limit leaves room for base64 and text within the host request limit. Draft images stay in browser memory. Stored files follow existing retention rules. Slack previews require saved file IDs and stored bytes.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Sep 25, 2026 6:09pm UTC

Request Review

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

56 screenshot changes — 0 changed · 56 added · 0 removed

Review screenshots in Frameshift

@sentry-junior sentry-junior Bot changed the title feat(chat): Support web image input and shared attachment previews feat(chat): Add images to web chat Sep 25, 2026
Keep image input with stable message IDs and synchronized mailbox updates. Move image send coverage into the send scenarios and retain accepted rows until server visibility.

Co-Authored-By: David Cramer <[email protected]>
Share message validation between create and continue requests. Reuse the Slack attachment lookup for transcript previews. Make image checks explicit, simplify pending message labels, and use the store API in attachment test setup.

Co-Authored-By: David Cramer <[email protected]>
@dcramer

dcramer commented Sep 25, 2026

Copy link
Copy Markdown
Member

needs updated with main; conflict

Keep image previews in TranscriptMessageView after main replaces the raw transcript view with the conversation event log.
@dcramer
dcramer marked this pull request as ready for review September 25, 2026 18:12
@github-actions github-actions Bot added the risk: high PR risk score: high label Sep 25, 2026
@dcramer
dcramer merged commit 0d60de0 into main Sep 25, 2026
46 checks passed
@dcramer
dcramer deleted the feat/web-image-input branch September 25, 2026 18:28
thomasjiangcy added a commit that referenced this pull request Nov 3, 2026
)

Slack images in the current message now reach the model as native image
parts, not a vision-model summary. Before, the main model got a
500-character summary from `AI_VISION_MODEL` and lost small text, exact
numbers, and dense UI detail. Prod runs one `anthropic/claude-opus-5.5`
profile, which reads images.

Web chat (#1933) already sends original images this way. Pi converts
`ImageContent` to Anthropic base64 image blocks.

**Behavior**
- Images go in natively only when every profile model accepts image
input. The router picks the profile after attachments resolve, so every
model it can pick must read images.
- The media type comes from the file bytes, not Slack's declared type.
Providers reject an image whose bytes do not match its media type.
- A vision summary is still used when a profile model is text-only, and
for images in earlier thread messages (thread hydration does not
change).
- The "no vision model" notice now shows only when neither path can read
the image.

**Tests**
- `attachment-media-behavior`: the first scenario now sends a mislabeled
PNG natively. The second scenario uses a text-only model to cover the
omitted-image notice.
- `bot-image-hydration`: the inline-summary scenarios use real PNG bytes
and a text-only model, so they test the fallback by model and not by
fake bytes.

**Not in scope**
Native PDFs and other files. pi-ai 0.85.1 and 1.5.0 have no document
content type, although Anthropic accepts `document` blocks.

<!-- junior-request-attribution:start -->
via @thomasjiangcy.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CCUMX7ET0%3A1793719349.640159 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CCUMX7ET0%3A1793719349.640159)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CCUMX7ET0%3A1793719349.640159/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Thomas Jiang <[email protected]>
BYK added a commit that referenced this pull request Nov 12, 2026
…#3181)

Web chat sent images as base64 in the message JSON. The 3 MB limit from
#1933 was only there to fit under the 4.5 MB Vercel Function body cap,
and only images were allowed. This change moves the bytes off the API
request, so web chat can take the same files as Slack.

## Upload flow

- `POST /api/conversations/attachment-uploads` takes `{filename,
contentType, bytes, idempotencyKey, conversationId?}`. It runs the same
access checks as a send (Conversation exists, accepts web messages,
viewer can add messages). Then it stores a `junior_attachment_uploads`
row bound to the viewer, the Conversation, and the Message idempotency
key. For a new Conversation, the id comes from
`createConversationId(viewer email, idempotencyKey)`.
- The response has a signed `PUT` target from the storage adapter
(`AttachmentStorage.createUploadTarget`):
- **vercel-blob**: `issueSignedToken` + `presignUrl`. One `put` of that
pathname, `allowedContentTypes` = the declared type,
`maximumSizeInBytes` = the declared size, `allowOverwrite: false`, 15
min.
- **s3**: a presigned query URL that also signs `content-length`,
`content-type`, and `if-none-match: *`. S3 rejects a PUT with another
size or type, and a second write. The new integration test checks this
against versitygw.
- **memory** (tests and local dev): no signer. The target is `PUT
/api/conversations/attachment-uploads/:id`, which takes the bytes itself
(still under the host body limit).
- The message body now carries `uploadIds` only, and its body limit is
256 KB. `images` and "Images must total 3 MB or less" are gone (hard
cutover). Before it accepts the Message, the server checks each upload:
it must be in scope, inside the 1 h send window, and written at its
declared size. It streams each object once for size, sha256, and leading
bytes. The type comes from the file signature: a file that says
`image/*` but is not an image is stored as `application/octet-stream`.
The upload id becomes the attachment id, so a retried send with the same
key is idempotent.
- Retention deletes unsent uploads (their object and row) after 24 h. A
sent upload keeps its object, because the attachment row now owns it.

## Model input

This is the Slack rule, now shared in `chat/attachments/model-input.ts`.
Slack's `vision-context.ts` imports the same constants and prompt
helper. Up to 3 images of 5 MiB or less go to the model as images, with
the type taken from the bytes. Every other file gets the
`loadAttachment` pointer. `chat/attachments/images.ts` is deleted.

## Per-file cap: 25 MiB, up to 10 files per message

`loadAttachment` reads the whole file into memory before it writes the
file to the sandbox, and the accept path reads each upload once. 25 MiB
keeps one load far below function memory and covers normal logs, PDFs,
and screenshots. It is a constant (`MAX_INPUT_ATTACHMENT_BYTES`) if we
want to raise it after `loadAttachment` streams.

## Screenshots

Composer with a PDF and a 3.8 MB PNG (mock dashboard, the request body
was 237 B):

![composer with a PDF and a 3.8 MB
image](https://junior-prod.sentry.dev/public/artifacts/f07e5ea6-146b-4d44-93cd-b974c57b6779.png)

Per-file limit error and the new tooltip:

![per-file
limit](https://junior-prod.sentry.dev/public/artifacts/b8601864-538d-438a-bb3f-74616605d3ed.png)

## Open questions for reviewers

- **Vercel Blob presign is not tested against a live store.** I took the
headers (`x-api-version`, `x-content-type`, `x-vercel-blob-access`) from
`@vercel/blob`'s own put path. Please try one upload on a preview deploy
before this leaves draft.
- **S3 bucket CORS.** A browser PUT needs the bucket to allow the
dashboard origin, `PUT`, and the `content-type` and `if-none-match`
headers. Should I document this in the self-hosting docs, or should we
keep S3 on the API PUT fallback?
- **Abuse limits.** Each upload is bound to the viewer and must be sent
within 1 h. There is no per-user quota or rate limit. Is that enough for
now?
- **Accept latency.** The accept path streams each upload once (10 × 25
MiB at worst). A HEAD-style size check would be cheaper, but then the
sha256 and the type sniff need another place.
- The web image eval (`attachments.eval.ts`) now goes through the upload
fixture. I could not run evals here (no gateway key).

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A1b27c73e23968a15f66676ac2202c7cb -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A1b27c73e23968a15f66676ac2202c7cb)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A1b27c73e23968a15f66676ac2202c7cb/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Burak Yigit Kaya <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — a7a934e3 Deployed Sep 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant