fix(web): reject unsupported composer image types at attach time (#6574)

This commit is contained in:
mohammed shazeb authored and GitHub committed 2026-08-15 12:01:26 +00:00
1 parent 7afa184a99
commit 34a12bc33f
5 files changed
+39

No files matched your search

@@ -1,4 +1,5 @@
import {
isProviderSendTurnSupportedImageMimeType,
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
} from "@t3tools/contracts";
@@ -162,6 +163,13 @@ export async function buildIncomingShareDraft(input: {
await releaseOwnedFiles(input.fileReader, [uri, payload.value]);
continue;
}
if (!isProviderSendTurnSupportedImageMimeType(mimeType)) {
warnings.push(
`'${resolved?.originalName ?? fallbackName(uri, index, mimeType)}' is not a supported image type.`,
);
await releaseOwnedFiles(input.fileReader, [uri, payload.value]);
continue;
}
if (
resolved?.contentSize !== null &&
resolved?.contentSize !== undefined &&
+5
View File
@@ -1,4 +1,5 @@
import {
isProviderSendTurnSupportedImageMimeType,
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
type UploadChatImageAttachment,
@@ -98,6 +99,10 @@ export async function pickComposerImages(input: { readonly existingCount: number
error = `Unsupported file type for '${asset.fileName ?? "image"}'.`;
continue;
}
if (!isProviderSendTurnSupportedImageMimeType(mimeType)) {
error = `'${asset.fileName ?? "image"}' is not a supported image type. Attach GIF, JPEG, PNG, or WebP images.`;
continue;
}
const base64 = asset.base64;
if (!base64) {
@@ -12,6 +12,7 @@ import type {
ThreadId,
} from "@t3tools/contracts";
import {
isProviderSendTurnSupportedImageMimeType,
ProviderDriverKind,
ProviderInstanceId,
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
@@ -2305,6 +2306,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
error = `Unsupported file type for '${file.name}'. Please attach image files only.`;
continue;
}
if (!isProviderSendTurnSupportedImageMimeType(file.type)) {
error = `'${file.name}' is not a supported image type. Attach GIF, JPEG, PNG, or WebP images.`;
continue;
}
if (reservedCount >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) {
error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`;
break;
@@ -23,6 +23,7 @@ import {
ThreadCreatedPayload,
ThreadTurnDiff,
ThreadTurnStartRequestedPayload,
isProviderSendTurnSupportedImageMimeType,
} from "./orchestration.ts";
import { ProviderInstanceId } from "./providerInstance.ts";
@@ -935,3 +936,9 @@ it.effect("project favicon overrides accept only supported image files", () =>
assert.strictEqual(invalid._tag, "Failure");
}),
);
it("isProviderSendTurnSupportedImageMimeType accepts raster formats and rejects svg", () => {
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/png"), true);
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("IMAGE/JPEG"), true);
assert.strictEqual(isProviderSendTurnSupportedImageMimeType("image/svg+xml"), false);
});
+14
View File
@@ -144,6 +144,20 @@ export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
export const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES = [
"image/gif",
"image/jpeg",
"image/png",
"image/webp",
] as const;
const PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET = new Set<string>(
PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPES,
);
/** Whether a pasted or picked image mime type can be sent on a provider turn. */
export function isProviderSendTurnSupportedImageMimeType(mimeType: string): boolean {
return PROVIDER_SEND_TURN_SUPPORTED_IMAGE_MIME_TYPE_SET.has(mimeType.toLowerCase());
}
const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
// Correlation id is command id by design in this model.