refactor(tui): extract attachments from document parts in session#3484
refactor(tui): extract attachments from document parts in session#3484Piyush0049 wants to merge 2 commits into
Conversation
This commit updates extractAttachmentsFromSession to properly read modern MessagePartTypeDocument attachments instead of relying solely on the legacy 'Contents of' string matching fallback, addressing the TODO in chat.go.
1104c82 to
85616ba
Compare
|
I just force-pushed to fix a trailing whitespace error that was failing the linter. The CI should pass now. |
|
Blocking issue: binary attachments round-trip as raw base64 text in the prompt. On the resend path, the extracted attachment has Suggested fixes:
|
|
Thanks for the review. I am working on the suggested fixes. |
This fixes a context overflow issue where binary attachments (like images) were being serialized as massive base64 text strings when a message was edited and resent. We now extend messages.Attachment to properly hold MimeType and Data, and rebuild the Document part natively in App.Run.
|
@dgageot I've implemented the primary suggestion to address the context overflow on the resend path. Specifically, I:
Please let me know if this looks good to you. |
Description
This PR resolves a technical debt
TODOinpkg/tui/page/chat/chat.goregarding how attachments are retrieved from session history when editing a past message in the TUI.Previously,
extractAttachmentsFromSessionrelied exclusively on a text-matching fallback ("Contents of <filename>: <dataURL>"). As the codebase has evolved to useMessagePartTypeDocumentfor structured file attachments, this old extraction logic would fail to properly restore modern attachments to the message editor.Changes:
chat.MessagePartTypeDocumentto safely extractInlineTextandInlineData.InlineDatapayloads into standarddata:URIs (base64) so that image attachments render properly in the UI."Contents of "string matching strictly as a fallback (legacyPrefix) to ensure backward compatibility with older saved sessions.TODOcomment.Testing
go build ./pkg/tui/...succeeds.go test ./pkg/tui/page/chat/...passes.