gptel
gptel copied to clipboard
Fix attachment link resolution with org-attach ID-based storage
Summary
Fixes #1073
This PR fixes an issue where gptel does not correctly locate media files referenced by org-mode "attachment" links when using org-attach's ID-based storage support.
Changes
1. gptel-org.el (gptel--parse-media-links)
- Use
org-attach-expandto properly resolve attachment-type links to their actual file paths - This is necessary when org-attach uses ID-based storage where attachment directories are not relative to the current file
- Added
declare-functionfororg-attach-expand
2. gptel-request.el (gptel--realize-query)
- Call
gptel--parse-bufferin the original buffer context rather than the temp buffer - This ensures
org-attach-expandhas access to Org properties (ID, ATTACH_DIR) needed to resolve attachment paths - These properties are not copied to the temp buffer, so the context switch is necessary
Testing
- Backward compatible: file-type links continue to work as before
- Attachment-type links now properly expand to absolute paths when using ID-based storage
- Existing test suite validates media link parsing functionality
Test plan
- Customize
org-attach-id-dirto a location outside the working directory - Create an Org file with a heading that has an ID property
- Attach an image file to the heading using
org-attach - Link to the attachment using
[[attachment:filename.png]] - Enable media tracking in gptel
- Send a query asking about the image
- Verify the image is correctly encoded and sent to the LLM
Without this fix, the LLM would not receive the image. With the fix, the image is properly encoded and included in the request.
🤖 Generated with Claude Code