-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(acp): preserve file attachment metadata during session replay #6342
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: dev
Are you sure you want to change the base?
Conversation
9b3ebbb to
cd8fde1
Compare
f8f3077 to
0a9c595
Compare
| mediaType: part.mime, | ||
| filename: part.filename, | ||
| }) | ||
| if (part.type === "file") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im skeptical of the updates here, what are the reasons here?
This file shouldnt really need updates to fix acp stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - the message-v2.ts changes were unnecessary for this fix.
The initial approach tried to handle binary content detection at the LLM message conversion layer, but that was the wrong place to solve this problem. The actual issue is purely in the ACP layer: when replaying a session, OpenCode's file parts weren't being converted back to proper ACP content blocks (image, resource, resource_link).
The current fix keeps all changes in agent.ts.
I updated the PR and the PR description.
0a9c595 to
ecaf273
Compare
This PR fixes the issue where file attachments were not being correctly replayed during ACP session reload. Changes to processMessage(): - Add handling for 'file' parts to correctly replay attachments - file:// URLs -> resource_link blocks - Images -> image blocks with preserved filename - Text files -> resource blocks with decoded text - Binary files -> resource blocks with blob data - Filter synthetic text parts from ACP output Changes to prompt(): - Preserve filenames from resource_link.name and image.uri - Handle binary resource blocks (PDFs, etc.) as file parts - Check for truthy resource.text instead of just property existence
ecaf273 to
44fccaf
Compare
|
/review |
| // - data: URLs with text/* or application/json → resource with text | ||
| // - data: URLs with other types → resource with blob | ||
| const url = part.url | ||
| const filename = part.filename ?? "file" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style note: This uses a let statement which the style guide recommends avoiding. One alternative would be to calculate the effective MIME type inline:
const effectiveMime = (() => {
const base64Match = url.match(/^data:([^;]+);base64,(.*)$/)
return base64Match?.[1] || part.mime || "application/octet-stream"
})()However, the current approach is readable and the reassignment is simple enough. Feel free to keep as-is if you prefer the clarity.
|
lgtm |
Problem
When reloading an ACP session, file attachments were not being replayed correctly:
filetype parts in stored messages were not being sent to ACP clients at allSolution
Updated
processMessage()inagent.tsto properly handlefileparts during session replay:file://URLs → Replayed asresource_linkblocksimageblocks with preserved original filenametext/*,application/json) → Replayed asresourceblocks with decoded textresourceblocks with blob dataAlso updated the
prompt()method to:resource_link.nameandimage.uriresourceblocks (PDFs, etc.) by storing them as file parts with data URLsresource.textinstead of just property existenceChanges
filepart handling inprocessMessage()for session replay!part.synthetic)resource_link.namewhen converting to internal partsresource.blobblocks inprompt()