-
Notifications
You must be signed in to change notification settings - Fork 222
feat: Enable file attachments in chat agent #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
It might not be a good idea to implement this using the experimental_attachments workaround in an official starter repo. It might be better to wait for the upstream issue cloudflare/agents#154 to be fixed using the correct FileUIPart from the AI SDK than to rely on an experimental feature, depending on their timeline. |
|
Why it's not a good idea? Why it's better to wait? |
I don't think experimental features should make its way into an official example codebase for a GA product, and definetly not when there's a non-experimental alternative (soon to be) available. |
|
Understand your concerns, but here's why I believe using the experimental feature is a good call in this context:
So unless there's a hard blocker or major risk, using this now feels like a pragmatic move. |
|
The approach is good, I don't mind using the ai sdk experimental api. I'll try to review this over the weekend. Thank you! |
|
@riseandignite It looks great to me! Can you please make sure you update the branch with the latest master and resolve the conflicts? I've added some things since you opened this PR. Thank you very much! |
f1f7a0f to
6d1d32f
Compare
|
@Gyurmatag thank you! Done. |
|
Okay, great! Now it's up to @threepointone to review it! :) |
|
@riseandignite love this PR! can we get it up to date and we will kindly ask @threepointone to review it? |
6d1d32f to
57f8b6d
Compare
|
@whoiskatrin thanks! I've updated it. |
seems like your build is failing with some syntax errors |
|
awesome! thanks a ton! @threepointone could you please review this? |
1 similar comment
|
awesome! thanks a ton! @threepointone could you please review this? |
|
@riseandignite fix the build again please :) |


Motivation:
Users often need to discuss specific documents, images, or data files with the AI. Currently, there is no mechanism to upload and reference these files directly within the chat conversation, limiting the agent's contextual understanding. This pr enables it.
Implementation Details:
Frontend (
app.tsx):uploadFilesfunction that sends selected files to a new backend endpoint (/api/upload) viamultipart/form-data.handleAgentSubmitusing theexperimental_attachmentsoption inuseChat.experimental_attachmentsif present, displaying images or providing download links using the URL returned by the server.Backend (
server.ts):/api/uploadroute to handle POST requests with file data.FILE_BUCKET), generating a unique key for each (uploads/{id}/{filename}).attachments, where each object includes the file'sname,contentType, and a dynamically generated publicurlpointing to the file retrieval endpoint./uploads/{id}/{filename}to serve the corresponding file directly from the R2 bucket.Benefits:
Testing:
/api/uploadendpoint./uploads/...URL.experimental_attachmentsand visible in agent messages.