fix(tui): paste local images as file:// attachments
Keep the short basename in FileAttachment.name for display and provider
filename metadata. Send the filesystem path as a file:// URI so admission
retains source.uri and existing toLLMMessages location text can surface it.
Clipboard bitmaps stay data: URIs named "clipboard" and do not get a fake
Attached file path note.
Fixes#41454
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
The reason will be displayed to describe this comment to others. Learn more.
This changes when the file is read: before, the TUI embedded the file's contents at paste time; now the server opens the path when the prompt is submitted. Two cases that work today will break:
Remote server (--server <url>): the path is on the user's machine, so the server's readFileAttachment can't open it and the prompt fails.
Also, the TUI still reads up to 20 MB of the file above (readLocalAttachment) and then throws the contents away.
Could you keep the embedded data: contents and send the path alongside them? Or send file:// only when the server is local, and fall back to data: otherwise?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The reason will be displayed to describe this comment to others. Learn more.
Good catch — switched back to embedding data: at paste time.
The absolute path now rides in FileAttachment.description (basename stays in name). toLLMMessages only emits Attached file: <path> when that description is an absolute filesystem path, so clipboard / free-form descriptions stay out of the path note.
That keeps remote --server and ephemeral paths working while still giving the model a real location when one exists.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The reason will be displayed to describe this comment to others. Learn more.
This is left over from the file:// approach. Pastes no longer create file: links, but @-mentions of image files do (autocomplete.tsx uses pathToFileURL). With isPromptImageUri, @-mentioned images now show up in the prompt's image previews and preview dialog. The TUI also tries to load them from a path that may only exist on the server when using --server. Since this fix doesn't need it, please drop the file: branch and isPromptImageUri (and their uses in prompt/index.tsx and mini/footer.prompt.tsx), along with the file:// label test in attachment.test.ts.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
All reactions
const pathname = URL.parse(uri)?.pathname ?? uri
if (/\.(avif|gif|jpe?g|png|webp)$/i.test(pathname)) return "Image"
if (/\.pdf$/i.test(pathname)) return "PDF"
}
return undefined
}
export function isPromptImageUri(uri: string) {
return attachmentKind(uri) === "Image"
}
function attachmentMetadata(file: PromptFileIdentity) {
There was an error while loading. Please reload this page.
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.