From 4050afee4df50eb3da1606a5894308f158cc29d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Dr=C4=83gan=20R=C4=83dule=C8=9B?= Date: Thu, 16 Jul 2026 20:59:50 +0200 Subject: [PATCH] feat(web): accept any file in the composer, render file chips - drag/drop and paste accept non-image files (staged as name+size chips); images keep the existing preview tiles and expand dialog - timeline renders file attachments as download chips via the signed asset URL - drafts persist an optional attachment type (missing = image, so existing persisted drafts decode unchanged; no storage version bump) - limits and copy: 10 MB per attachment, 8 attachments per message Co-Authored-By: Claude Fable 5 --- apps/web/src/components/ChatView.logic.ts | 6 +- apps/web/src/components/ChatView.tsx | 16 ++--- apps/web/src/components/chat/ChatComposer.tsx | 64 ++++++++++++------- .../chat/ComposerPreviewAnnotationCards.tsx | 4 +- .../src/components/chat/MessagesTimeline.tsx | 39 ++++++++++- apps/web/src/composerDraftStore.ts | 36 ++++++++--- apps/web/src/historyBootstrap.ts | 22 +++++-- apps/web/src/lib/attachmentSize.ts | 9 +++ apps/web/src/types.ts | 7 +- 9 files changed, 150 insertions(+), 53 deletions(-) create mode 100644 apps/web/src/lib/attachmentSize.ts diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index 325f9afa90..1c5e72f0de 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -10,7 +10,7 @@ import { type TurnId, } from "@t3tools/contracts"; import { type ChatMessage, type SessionPhase, type Thread } from "../types"; -import { type ComposerImageAttachment, type DraftThreadState } from "../composerDraftStore"; +import { type ComposerAttachment, type DraftThreadState } from "../composerDraftStore"; import * as Schema from "effect/Schema"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { environmentThreadDetails } from "../state/threads"; @@ -193,9 +193,7 @@ export function resolveSendEnvMode(input: { return input.isGitRepo ? input.requestedEnvMode : "local"; } -export function cloneComposerImageForRetry( - image: ComposerImageAttachment, -): ComposerImageAttachment { +export function cloneComposerImageForRetry(image: ComposerAttachment): ComposerAttachment { if (typeof URL === "undefined" || !image.previewUrl.startsWith("blob:")) { return image; } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index c296c71706..7c326ec6b4 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -162,7 +162,7 @@ import { } from "../logicalProject"; import { buildDraftThreadRouteParams } from "../threadRoutes"; import { - type ComposerImageAttachment, + type ComposerAttachment, type DraftThreadEnvMode, useComposerDraftStore, type DraftId, @@ -261,8 +261,8 @@ import { } from "../versionSkew"; import { useAssetUrls } from "../assets/assetUrls"; -const IMAGE_ONLY_BOOTSTRAP_PROMPT = - "[User attached one or more images without additional text. Respond using the conversation context and the attached image(s).]"; +const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT = + "[User attached one or more files without additional text. Respond using the conversation context and the attached file(s).]"; const EMPTY_ACTIVITIES: OrchestrationThreadActivity[] = []; const EMPTY_PROVIDERS: ServerProvider[] = []; const EMPTY_PROVIDER_SKILLS: ServerProvider["skills"] = []; @@ -1190,7 +1190,7 @@ function ChatViewContent(props: ChatViewProps) { : null, ); const promptRef = useRef(""); - const composerImagesRef = useRef([]); + const composerImagesRef = useRef([]); const composerTerminalContextsRef = useRef([]); const composerElementContextsRef = useRef([]); const localComposerRef = useRef(null); @@ -4179,11 +4179,11 @@ function ChatViewContent(props: ChatViewProps) { model: ctxSelectedModel, models: ctxSelectedProviderModels, effort: ctxSelectedPromptEffort, - text: messageTextForSend || IMAGE_ONLY_BOOTSTRAP_PROMPT, + text: messageTextForSend || ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, }); const turnAttachmentsPromise = Promise.all( composerImagesSnapshot.map(async (image) => ({ - type: "image" as const, + type: image.type, name: image.name, mimeType: image.mimeType, sizeBytes: image.sizeBytes, @@ -4191,7 +4191,7 @@ function ChatViewContent(props: ChatViewProps) { })), ); const optimisticAttachments = composerImagesSnapshot.map((image) => ({ - type: "image" as const, + type: image.type, id: image.id, name: image.name, mimeType: image.mimeType, @@ -4253,7 +4253,7 @@ function ChatViewContent(props: ChatViewProps) { let titleSeed = trimmed; if (!titleSeed) { if (firstComposerImageName) { - titleSeed = `Image: ${firstComposerImageName}`; + titleSeed = `${composerImagesSnapshot[0]?.type === "file" ? "File" : "Image"}: ${firstComposerImageName}`; } else if (composerTerminalContextsSnapshot.length > 0) { titleSeed = formatTerminalContextLabel(composerTerminalContextsSnapshot[0]!); } else if (composerElementContextsSnapshot.length > 0) { diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index f3346b4100..3a03e8a7a2 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -49,7 +49,7 @@ import { makeComposerMentionDragHandlers, } from "./composerMentionDrag"; import { - type ComposerImageAttachment, + type ComposerAttachment, type DraftId, type PersistedComposerImageAttachment, useComposerDraftStore, @@ -101,6 +101,7 @@ import { BotIcon, CheckIcon, CircleAlertIcon, + FileTextIcon, ListTodoIcon, PencilRulerIcon, type LucideIcon, @@ -130,6 +131,7 @@ import { import { formatProviderSkillDisplayName } from "../../providerSkillPresentation"; import { searchProviderSkills } from "../../providerSkillSearch"; import { useMediaQuery } from "../../hooks/useMediaQuery"; +import { formatAttachmentSizeLabel } from "../../lib/attachmentSize"; import type { ReviewCommentContext } from "../../reviewCommentContext"; const IMAGE_SIZE_LIMIT_LABEL = `${Math.round(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES / (1024 * 1024))}MB`; @@ -425,7 +427,7 @@ export interface ChatComposerHandle { /** Get the current prompt/effort/model state for use in send. */ getSendContext: () => { prompt: string; - images: ComposerImageAttachment[]; + images: ComposerAttachment[]; terminalContexts: TerminalContextDraft[]; elementContexts: ElementContextDraft[]; previewAnnotations: PreviewAnnotationPayload[]; @@ -516,7 +518,7 @@ export interface ChatComposerProps { // Refs the parent needs kept in sync promptRef: React.RefObject; - composerImagesRef: React.RefObject; + composerImagesRef: React.RefObject; composerTerminalContextsRef: React.RefObject; composerElementContextsRef: React.RefObject; composerRef: React.RefObject; @@ -1175,14 +1177,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) ); const addComposerImage = useCallback( - (image: ComposerImageAttachment) => { + (image: ComposerAttachment) => { addComposerDraftImage(composerDraftTarget, image); }, [composerDraftTarget, addComposerDraftImage], ); const addComposerImagesToDraft = useCallback( - (images: ComposerImageAttachment[]) => { + (images: ComposerAttachment[]) => { addComposerDraftImages(composerDraftTarget, images); }, [composerDraftTarget, addComposerDraftImages], @@ -1392,6 +1394,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) try { const dataUrl = await readFileAsDataUrl(image.file); stagedAttachmentById.set(image.id, { + type: image.type, id: image.id, name: image.name, mimeType: image.mimeType, @@ -1792,32 +1795,29 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) if (pendingUserInputs.length > 0) { toastManager.add({ type: "error", - title: "Attach images after answering plan questions.", + title: "Attach files after answering plan questions.", }); return; } - const nextImages: ComposerImageAttachment[] = []; + const nextImages: ComposerAttachment[] = []; let nextImageCount = composerImagesRef.current.length; let error: string | null = null; for (const file of files) { - if (!file.type.startsWith("image/")) { - error = `Unsupported file type for '${file.name}'. Please attach image files only.`; - continue; - } if (file.size > PROVIDER_SEND_TURN_MAX_IMAGE_BYTES) { error = `'${file.name}' exceeds the ${IMAGE_SIZE_LIMIT_LABEL} attachment limit.`; continue; } if (nextImageCount >= PROVIDER_SEND_TURN_MAX_ATTACHMENTS) { - error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} images per message.`; + error = `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} attachments per message.`; break; } + const isImage = file.type.startsWith("image/"); const previewUrl = URL.createObjectURL(file); nextImages.push({ - type: "image", + type: isImage ? "image" : "file", id: randomUUID(), - name: file.name || "image", - mimeType: file.type, + name: file.name || (isImage ? "image" : "file"), + mimeType: file.type || "application/octet-stream", sizeBytes: file.size, previewUrl, file, @@ -1842,10 +1842,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) const onComposerPaste = (event: React.ClipboardEvent) => { const files = Array.from(event.clipboardData.files); if (files.length === 0) return; - const imageFiles = files.filter((file) => file.type.startsWith("image/")); - if (imageFiles.length === 0) return; event.preventDefault(); - addComposerImages(imageFiles); + addComposerImages(files); }; const onComposerDragEnter = (event: React.DragEvent) => { @@ -2352,7 +2350,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) removeComposerDraftPreviewAnnotation(composerDraftTarget, annotationId) } onExpandImage={(imageId) => { - const preview = buildExpandedImagePreview(composerImages, imageId); + const preview = buildExpandedImagePreview( + composerImages.filter((attachment) => attachment.type === "image"), + imageId, + ); if (preview) onExpandImage(preview); }} className="mb-3" @@ -2403,15 +2404,34 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) .map((image) => (
- {image.previewUrl ? ( + {image.type === "file" ? ( + <> + +
+
+ {image.name} +
+
+ {formatAttachmentSizeLabel(image.sizeBytes)} +
+
+ + ) : image.previewUrl ? (