@devries-cameron20 / t3code Mirror · read-only / commits / 14b828e58e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 18:15 UTC

fix(web): attach DNG originals as generic files (#24625)

Julius Marminge committed Oct 24, 2026 at 17:45 UTC 14b828e58e746eeb0bd84073b36387014320cf59
5 files changed +148 -7
apps/web/src/components/chat/composerAttachmentFiles.test.ts
+76 -1
@@ -1,15 +1,90 @@
1 -import { EnvironmentId, PROVIDER_SEND_TURN_MAX_FILE_BYTES } from "@t3tools/contracts";
1 +import {
2 + EnvironmentId,
3 + getProviderAttachmentLimitError,
4 + PROVIDER_SEND_TURN_MAX_FILE_BYTES,
5 +} from "@t3tools/contracts";
6 import { describe, expect, it } from "vite-plus/test";
7
8 +import { isFileAttachment, isImageAttachment } from "../../types";
9 import type { ComposerFileAttachment, ComposerImageAttachment } from "../../composerDraftStore";
10 import {
11 attachmentsToReleaseOnUploadCapabilityLoss,
12 + classifyComposerAttachmentFile,
13 + composerFileAttachmentMimeType,
14 fileAttachmentCapabilityBlockReason,
15 fileAttachmentStagingLimit,
16 + normalizeComposerImageFileMimeType,
17 shouldHandleComposerAttachmentPaste,
18 } from "./composerAttachmentFiles";
19
20 describe("composer attachment files", () => {
21 + it("keeps DNG originals on the file path without changing their bytes", async () => {
22 + const bytes = new Uint8Array([0x49, 0x49, 0x2a, 0x00, 0x08, 0, 0, 0, 0xfe, 0xff, 0x00, 0x80]);
23 + const files = [
24 + new File([bytes], "photo.DNG", { type: "image/tiff" }),
25 + new File([bytes], "photo.dng", { type: "image/png" }),
26 + new File([bytes], "photo.dng", { type: "image/jpeg" }),
27 + new File([bytes], "clipboard", { type: "image/dng" }),
28 + new File([bytes], "clipboard", { type: "image/x-dng" }),
29 + new File([bytes], "clipboard", { type: "image/x-adobe-dng" }),
30 + ];
31 +
32 + const attachments = await Promise.all(
33 + files.map(async (file) => ({
34 + kind: classifyComposerAttachmentFile(file),
35 + bytes: new Uint8Array(await normalizeComposerImageFileMimeType(file).arrayBuffer()),
36 + })),
37 + );
38 +
39 + expect(attachments).toEqual(files.map(() => ({ kind: "file", bytes })));
40 + });
41 +
42 + it("keeps misleading DNG MIME labels out of downstream image detection and budgets", () => {
43 + for (const type of ["image/png", "image/jpeg", "image/tiff", "image/dng", ""]) {
44 + const attachment = {
45 + type: "file" as const,
46 + id: "raw",
47 + name: "photo.DNG",
48 + mimeType: composerFileAttachmentMimeType({ name: "photo.DNG", type }),
49 + sizeBytes: 81 * 1024 * 1024,
50 + };
51 +
52 + expect(isImageAttachment(attachment)).toBe(false);
53 + expect(isFileAttachment(attachment)).toBe(true);
54 + expect(getProviderAttachmentLimitError([attachment])).toBeUndefined();
55 + }
56 + });
57 +
58 + it("claims a captioned DNG paste even when its MIME is generic", () => {
59 + const file = new File(["raw"], "photo.dng", { type: "application/octet-stream" });
60 +
61 + expect(
62 + shouldHandleComposerAttachmentPaste({ files: [file], plainText: "Inspect this original" }),
63 + ).toBe(true);
64 + });
65 +
66 + it("keeps ordinary images on their existing paths", () => {
67 + const files = [
68 + { name: "photo.jpg", type: "image/jpeg" },
69 + { name: "export.dng.png", type: "image/png" },
70 + { name: "photo.webp", type: "image/webp" },
71 + { name: "photo.gif", type: "image/gif" },
72 + { name: "photo.heic", type: "" },
73 + { name: "scan.tif", type: "image/tiff" },
74 + { name: "photo.cr2", type: "image/x-canon-cr2" },
75 + ];
76 +
77 + expect(files.map(classifyComposerAttachmentFile)).toEqual([
78 + "image",
79 + "image",
80 + "image",
81 + "image",
82 + "image",
83 + "unsupported-image",
84 + "unsupported-image",
85 + ]);
86 + });
87 +
88 it("preserves text paste when an application adds a synthetic generic file", () => {
89 const file = new File(["clipboard"], "clipboard.rtf", { type: "application/rtf" });
90
apps/web/src/components/chat/composerAttachmentFiles.ts
+22 -1
@@ -10,7 +10,7 @@ import {
10
11 import type { ComposerFileAttachment, ComposerImageAttachment } from "../../composerDraftStore";
12 import { isHeicImageFile } from "../../lib/imageCompression";
13 -import { isVideoAttachment } from "../../types";
13 +import { isVideoAttachment, videoMimeType } from "../../types";
14
15 type ComposerAttachmentFileKind = "image" | "file" | "unsupported-image";
16
@@ -59,9 +59,29 @@ export function normalizeComposerImageFileMimeType(file: File): File {
59 });
60 }
61
62 +function isDngFile(file: Pick<File, "name" | "type">): boolean {
63 + const mimeType = file.type.split(";", 1)[0]?.trim().toLowerCase();
64 + return (
65 + file.name.toLowerCase().endsWith(".dng") ||
66 + mimeType === "image/dng" ||
67 + mimeType === "image/x-dng" ||
68 + mimeType === "image/x-adobe-dng"
69 + );
70 +}
71 +
72 +export function composerFileAttachmentMimeType(file: Pick<File, "name" | "type">): string {
73 + // Downstream image detection uses MIME, even for attachments staged as files.
74 + if (isDngFile(file)) return "image/x-adobe-dng";
75 + return (
76 + videoMimeType({ name: file.name, mimeType: file.type }) ??
77 + (file.type || "application/octet-stream")
78 + );
79 +}
80 +
81 export function classifyComposerAttachmentFile(
82 file: Pick<File, "name" | "type">,
83 ): ComposerAttachmentFileKind {
84 + if (isDngFile(file)) return "file";
85 if (isHeicImageFile(file)) {
86 return "image";
87 }
@@ -147,6 +167,7 @@ export function shouldHandleComposerAttachmentPaste(input: {
167 }): boolean {
168 if (
169 input.files.some((file) => {
170 + if (isDngFile(file)) return true;
171 const classification = classifyComposerAttachmentFile(file);
172 return classification === "image" || classification === "unsupported-image";
173 })
apps/web/src/components/chat/useComposerAttachmentIntake.ts
+2 -5
@@ -25,6 +25,7 @@ import {
25 } from "../../questionAttachments";
26 import {
27 classifyComposerAttachmentFile,
28 + composerFileAttachmentMimeType,
29 normalizeComposerImageFileMimeType,
30 } from "./composerAttachmentFiles";
31 import {
@@ -45,7 +46,6 @@ import {
46 import { requestConfirmDialog } from "~/confirmDialog";
47 import { toastManager } from "../ui/toast";
48 import { type RefObject, useRef } from "react";
48 -import { videoMimeType } from "../../types";
49 import {
50 addPreparingComposerImages,
51 isPreparingComposerImage,
@@ -162,10 +162,7 @@ export function useComposerAttachmentIntake(input: {
162 for (const file of files) {
163 const attachmentKind = classifyComposerAttachmentFile(file);
164 const fileMimeType =
165 - attachmentKind === "file"
166 - ? (videoMimeType({ name: file.name, mimeType: file.type }) ??
167 - (file.type || "application/octet-stream"))
168 - : file.type;
165 + attachmentKind === "file" ? composerFileAttachmentMimeType(file) : file.type;
166 const matchingReattachMarker =
167 attachmentKind === "file"
168 ? reattachMarkers.find(
apps/web/src/composerDraftStore.test.ts
+36
@@ -521,6 +521,42 @@ describe("composerDraftStore file attachments", () => {
521 expect(draft?.files.map((file) => file.id)).toEqual(["file-accepted"]);
522 });
523
524 + it("reattaches a DNG with an older generic-MIME marker at attachment capacity", () => {
525 + const store = useComposerDraftStore.getState();
526 + const file = new File(["raw"], "photo.DNG", { type: "image/x-adobe-dng" });
527 + const marker: ComposerFileAttachment = {
528 + type: "file",
529 + id: "dng-marker",
530 + name: file.name,
531 + mimeType: "application/octet-stream",
532 + sizeBytes: file.size,
533 + file: null,
534 + };
535 + store.addFiles(threadRef, [marker]);
536 + store.addImages(
537 + threadRef,
538 + Array.from({ length: PROVIDER_SEND_TURN_MAX_ATTACHMENTS - 1 }, (_, index) =>
539 + makeImage({
540 + id: `image-${index}`,
541 + name: `image-${index}.png`,
542 + previewUrl: `blob:image-${index}`,
543 + }),
544 + ),
545 + );
546 +
547 + const repicked: ComposerFileAttachment = {
548 + ...marker,
549 + id: "dng-repicked",
550 + mimeType: file.type,
551 + file,
552 + };
553 + store.addFiles(threadRef, [repicked]);
554 +
555 + const files = store.getComposerDraft(threadRef)?.files;
556 + expect(files).toEqual([repicked]);
557 + expect(files?.some(composerFileNeedsReattach)).toBe(false);
558 + });
559 +
560 it("replaces a needs-reattach marker when the same file is picked again", () => {
561 const store = useComposerDraftStore.getState();
562 const marker: ComposerFileAttachment = { ...makeFile("file-marker"), file: null };
apps/web/src/composerDraftStore.ts
+12
@@ -1,4 +1,5 @@
1 import { stripInlineContextReferences } from "./lib/composerContextReferences";
2 +import { composerFileAttachmentMimeType } from "./components/chat/composerAttachmentFiles";
3 import { elementContextToPreviewAnnotation } from "./lib/elementContext";
4 import {
5 ElementContextDetails,
@@ -804,6 +805,17 @@ export function composerFileMatchesReattachMarker(
805 ): boolean {
806 if (marker.name !== file.name || marker.sizeBytes !== file.sizeBytes) return false;
807 if (marker.mimeType === file.mimeType) return true;
808 + const normalizedMarkerMimeType = composerFileAttachmentMimeType({
809 + name: marker.name,
810 + type: marker.mimeType,
811 + });
812 + if (
813 + normalizedMarkerMimeType === "image/x-adobe-dng" &&
814 + normalizedMarkerMimeType ===
815 + composerFileAttachmentMimeType({ name: file.name, type: file.mimeType })
816 + ) {
817 + return true;
818 + }
819 const markerMimeType = marker.mimeType.toLowerCase();
820 return (
821 (markerMimeType === "" || markerMimeType === "application/octet-stream") &&