feat(files): add client.files and image_ref support in realtime#145
Merged
Conversation
Adds a server-managed file upload surface backed by POST /v1/files in the
bouncer. `client.files.upload(blob)` returns a `FileReference`; pass `ref.id`
to `rt.set({ image })`, `setImage(...)`, or `initialState.image` to reuse the
asset across realtime updates without re-uploading or base64'ing it every
time.
Realtime accepts the id as a plain string (callers persist the id in their
own storage; the full metadata object is not required).
Example:
const ref = await client.files.upload(blob);
await rt.set({ image: ref.id, prompt: "make it cinematic" });
await rt.set({ image: ref.id, prompt: "now in noir" }); // reused
commit: |
client.files and image_ref support in realtime
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5534fd1. Configure here.
Bugbot review: response.ok already covers 204, so the extra status !== 204 branch is dead. Simplifies to !response.ok.
Mirrors the bouncer's new ttl_seconds field. FileReference.expires_at is now string | null since persistent uploads have no expiry.
Catches "forever" / -1 / out-of-range values at the call site instead of after a round-trip. Matches the pattern in realtime/methods.ts where client-side input is parsed with zod before being sent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Adds a server-managed file upload surface to the SDK, backed by
POST /v1/filesin the api. Users upload an asset once, get a"file_..."id, and reuse it across realtime updates without re-uploading or base64-ing it on every call. Files expire after 24 h server-side.The realtime methods (
set,setImage,initialState.image) accept the id as a plain string — callers persist the id in their own storage, not the full metadata object. The SDK detects the"file_"prefix and routes through theimage_reffield on the wire (mutually exclusive withimage_data).Usage
Changes
client.filessub-client:upload(file),get(fileId),delete(fileId).set_imagewire message gains an optionalimage_ref(oneof withimage_data); the internalsetImageAPI takes a{ kind: "data" | "ref" }payload.setInputSchema.imageandmodelStateSchema.imageaccept a"file_..."id string; non-file_strings still flow throughimageToBase64(data URLs, http(s) URLs, raw base64) as today.client.files, 1 new test for the realtime ref path. Updated the 5 existing realtime unit tests to match the new internal payload shape.Note
Medium Risk
Changes realtime signaling and connect initial-state behavior for a new wire field; scope is SDK-only with tests, but incorrect ref handling could break image updates in production sessions.
Overview
Adds
client.files(upload,get,delete) againstPOST/GET/DELETE /v1/files, with optional TTL validation and newFILES_*error codes, wired intocreateDecartClient.Realtime
set,setImage, andinitialState.imagenow accept a plainfile_...id: the SDK routes those throughimage_refon the wire instead of base64image_data, using an internal{ kind: "data" | "ref" }payload through signaling and stream session.The SDK test page gains a Files API panel (upload, metadata, delete, use ref as image). Unit, realtime unit, and e2e tests cover the files client and ref-based image paths.
Reviewed by Cursor Bugbot for commit 0f37b6b. Bugbot is set up for automated code reviews on this repo. Configure here.