Skip to content

Commit 93376e4

Browse files
mdshzb04juliusmarminge
authored andcommitted
fix(web): reject unsupported composer image types at attach time
SVG and other non-raster images were accepted in the composer but failed when the turn reached Claude. Validate against the shared supported mime list before adding attachments on web and mobile. Fixes #6020.
1 parent 2cb1a26 commit 93376e4

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎apps/mobile/src/features/sharing/incoming-share-model.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
isProviderSendTurnSupportedImageMimeType,
23
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
34
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
45
} from "@t3tools/contracts";
@@ -162,6 +163,13 @@ export async function buildIncomingShareDraft(input: {
162163
await releaseOwnedFiles(input.fileReader, [uri, payload.value]);
163164
continue;
164165
}
166+
if (!isProviderSendTurnSupportedImageMimeType(mimeType)) {
167+
warnings.push(
168+
`'${resolved?.originalName ?? fallbackName(uri, index, mimeType)}' is not a supported image type.`,
169+
);
170+
await releaseOwnedFiles(input.fileReader, [uri, payload.value]);
171+
continue;
172+
}
165173
if (
166174
resolved?.contentSize !== null &&
167175
resolved?.contentSize !== undefined &&

‎apps/mobile/src/lib/composerImages.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
isProviderSendTurnSupportedImageMimeType,
23
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
34
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
45
type UploadChatImageAttachment,
@@ -98,6 +99,10 @@ export async function pickComposerImages(input: { readonly existingCount: number
9899
error = `Unsupported file type for '${asset.fileName ?? "image"}'.`;
99100
continue;
100101
}
102+
if (!isProviderSendTurnSupportedImageMimeType(mimeType)) {
103+
error = `'${asset.fileName ?? "image"}' is not a supported image type. Attach GIF, JPEG, PNG, or WebP images.`;
104+
continue;
105+
}
101106

102107
const base64 = asset.base64;
103108
if (!base64) {

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
ThreadId,
1313
} from "@t3tools/contracts";
1414
import {
15+
isProviderSendTurnSupportedImageMimeType,
1516
ProviderDriverKind,
1617
ProviderInstanceId,
1718
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
@@ -2303,6 +2304,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
23032304
error = `Unsupported file type for '${file.name}'. Please attach image files only.`;
23042305
continue;
23052306
}
2307+
if (!isProviderSendTurnSupportedImageMimeType(file.type)) {
2308+
error = `'${file.name}' is not a supported image type. Attach GIF, JPEG, PNG, or WebP images.`;
2309+
continue;
2310+
}
23062311
if (reservedCount >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
23072312
error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
23082313
break;

‎packages/contracts/src/orchestration.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
ThreadCreatedPayload,
2424
ThreadTurnDiff,
2525
ThreadTurnStartRequestedPayload,
26+
isProviderSendTurnSupportedImageMimeType,
2627
} from "./orchestration.ts";
2728
import { ProviderInstanceId } from "./providerInstance.ts";
2829

@@ -935,3 +936,9 @@ it.effect("project favicon overrides accept only supported image files", () =>
935936
assert.strictEqual(invalid._tag, "Failure");
936937
}),
937938
);
939+
940+
it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects svg", () => {
941+
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/png"), true);
942+
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("IMAGE/JPEG"), true);
943+
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/svg+xml"), false);
944+
});

‎packages/contracts/src/orchestration.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
144144
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
145145
export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
146146
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
147+
export const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES = [
148+
"image/gif",
149+
"image/jpeg",
150+
"image/png",
151+
"image/webp",
152+
] as const;
153+
const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET = new Set<string>(
154+
PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES,
155+
);
156+
157+
/** Whether a pasted or picked image mime type can be sent on a provider turn. */
158+
export function isProviderSendTurnSupportedImageMimeType(mimeType: string): boolean {
159+
return PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET.has(mimeType.toLowerCase());
160+
}
147161
const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
148162
const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
149163
// Correlation id is command id by design in this model.

0 commit comments

Comments
 (0)