Accept AVIF and JXL image attachments

Both are converted to WebP in the browser like other non-WebP images, so
providers never see them. Browsers that can't decode JXL now get a readable
error instead of [object Event].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 18:14:28 +00:00
co-authored by Claude Opus 5.5
parent da2b390bdd
commit 3ee881427c
3 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ export async function toAttach(file, opts) {
if (file instanceof File) {
const name = file.name || 'file', mime = (file.type || 'application/octet-stream').toLowerCase();
if (isVideo(name, mime)) return compressVideo(file, opts);
if (/^image\//.test(mime) || /\.(png|jpe?g|webp|gif)$/i.test(name)) {
if (/^image\//.test(mime) || /\.(png|jpe?g|webp|gif|avif|jxl)$/i.test(name)) {
const data = await imgToWebp(file, 2048, 94, mime === 'image/webp' || /\.webp$/i.test(name));
return { type: 'image_url', image_url: { url: data } };
}
+1 -1
View File
@@ -6,7 +6,7 @@
<button id="sendBtn" type="submit" aria-label="Send" class="shrink-0 rounded-2xl bg-black text-white h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-black/90 active:scale-[.98] transition"><i data-lucide="sparkles" class="h-5 w-5"></i></button>
<button id="attachBtn" type="button" aria-label="Attach" class="relative shrink-0 rounded-2xl bg-gray-100 text-gray-900 h-10 w-10 inline-flex items-center justify-center shadow-sm hover:bg-gray-200 active:scale-[.98] transition"><i data-lucide="paperclip" class="h-5 w-5"></i><span id="attachBadge" class="hidden absolute -top-1 -right-1 h-4 min-w-4 px-1 rounded-full bg-black text-white text-[10px] leading-4 text-center"></span></button>
</div>
<input id="fileInput" type="file" class="hidden" multiple accept="image/png,image/jpeg,image/webp,image/gif,application/pdf,audio/wav,audio/x-wav,audio/mpeg,audio/mp3,video/*"/>
<input id="fileInput" type="file" class="hidden" multiple accept="image/png,image/jpeg,image/webp,image/gif,image/avif,image/jxl,.avif,.jxl,application/pdf,audio/wav,audio/x-wav,audio/mpeg,audio/mp3,video/*"/>
</form>
</div>
</footer>
+2 -1
View File
@@ -28,7 +28,8 @@ export const imgToWebp = (f, D = 96, q = 75, k) => new Promise((r, j) => {
r(c.toDataURL('image/webp', clamp(q, 0, 100) / 100));
URL.revokeObjectURL(i.src);
};
i.onerror = j; i.src = URL.createObjectURL(f);
i.onerror = () => (URL.revokeObjectURL(i.src), j(new Error("this browser can't read this image format")));
i.src = URL.createObjectURL(f);
});
export const b64 = x => x.split(',')[1] || '';
export const utob = s => btoa(unescape(encodeURIComponent(s)));