feat: let agents work with PDFs, ZIPs, and other files #8092
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 14 commits into
main fromt3code/generic-file-uploadsopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
- apps/web/src/composerDraftStore.ts line 3678OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -3509,3 +3675,4 @@35093675 ...destination,35103676 prompt: movedPrompt,35113677 images: [...destination.images, ...source.images],3678+ files: [...destination.files, ...source.files],apps/mobile/src/features/threads/new-task-flow-provider.tsx line 530OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -519,4 +522,9 @@519522 if (!selectedProjectDraftKey) {520523 return;521524 }525+ const removedAttachment = getComposerDraftSnapshot(selectedProjectDraftKey).attachments.find(526+ (attachment) => attachment.id === imageId,527+ );522528 removeComposerDraftAttachment(selectedProjectDraftKey, imageId);529+ if (removedAttachment?.type === "file") {530+ void removePersistedComposerAttachmentFile(removedAttachment.fileUri);apps/mobile/src/features/threads/new-task-flow-provider.tsx line 530OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -519,4 +522,9 @@519522 if (!selectedProjectDraftKey) {520523 return;521524 }525+ const removedAttachment = getComposerDraftSnapshot(selectedProjectDraftKey).attachments.find(526+ (attachment) => attachment.id === imageId,527+ );522528 removeComposerDraftAttachment(selectedProjectDraftKey, imageId);529+ if (removedAttachment?.type === "file") {530+ void removePersistedComposerAttachmentFile(removedAttachment.fileUri);apps/server/src/assets/AttachmentUpload.ts line 47OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -41,3 +44,4 @@4144 const AttachmentUploadClaims = Schema.Struct({4245 version: Schema.Literal(1),4346 kind: Schema.Literal("attachment-upload"),47+ type: Schema.Literals(["image", "file"]),apps/mobile/src/lib/composerImages.ts line 117OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -29,0 +97,21 @@97+ if (result.canceled) {98+ return { files: [], error: null };99+ }100+101+ const maxBytes = input.maxBytes ?? PROVIDER_SEND_TURN_MAX_FILE_BYTES;102+ const attachments: DraftComposerFileAttachment[] = [];103+ let error: string | null = null;104+ for (const file of result.result.slice(0, remainingSlots)) {105+ const sizeBytes = file.size ?? 0;106+ if (sizeBytes <= 0 || sizeBytes > maxBytes) {107+ error = `'${file.name}' exceeds the ${Math.round(maxBytes / (1024 * 1024))} MB attachment limit.`;108+ continue;109+ }110+ try {111+ attachments.push({112+ id: uuidv4(),113+ type: "file",114+ name: file.name,115+ mimeType: file.type || "application/octet-stream",116+ sizeBytes,117+ fileUri: await persistComposerAttachmentFile(file.uri, file.name),apps/mobile/src/lib/composerImages.ts lines 104 to 104OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -29,0 +84,21 @@84+ files: [],85+ error: `You can attach up to ${PROVIDER_SEND_TURN_MAX_ATTACHMENTS} files per message.`,86+ };87+ }88+89+ const { File } = await import("expo-file-system");90+ const endHandoff = beginForegroundHandoff();91+ let result: PickMultipleFilesResult;92+ try {93+ result = await File.pickFileAsync({ multipleFiles: true });94+ } finally {95+ endHandoff();96+ }97+ if (result.canceled) {98+ return { files: [], error: null };99+ }100+101+ const maxBytes = input.maxBytes ?? PROVIDER_SEND_TURN_MAX_FILE_BYTES;102+ const attachments: DraftComposerFileAttachment[] = [];103+ let error: string | null = null;104+ for (const file of result.result.slice(0, remainingSlots)) {
- @@ -3441,3 +3606,4 @@34413606 ...current,34423607 prompt: "",34433608 images: [],3609+ files: [],apps/mobile/src/features/sharing/incoming-share-model.ts line 254Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -156,5 +164,20 @@156164 await releaseOwnedFiles(input.fileReader, [uri, payload.value]);157165 continue;158166 }159167160- const mimeType = (resolved?.contentMimeType ?? payload.mimeType ?? "image/png").toLowerCase();168+ const mimeType = (169+ resolved?.contentMimeType ??170+ payload.mimeType ??171+ (payload.shareType === "image" ? "image/png" : "application/octet-stream")172+ ).toLowerCase();173+ if (payload.shareType !== "image") {174+ const name = resolved?.originalName ?? fallbackName(uri, index, mimeType);175+ if (!uri) {176+ warnings.push("One shared file could not be read.");177+ continue;178+ }179+ try {180+ const sizeBytes = resolved?.contentSize ?? (await input.fileReader.readSize?.(uri)) ?? 0;181+ if (sizeBytes <= 0 || sizeBytes > PROVIDER_SEND_TURN_MAX_FILE_BYTES) {182+ warnings.push(`'${name}' exceeds the 50 MB attachment limit.`);183+ continue;apps/mobile/src/features/threads/new-task-flow-provider.tsx line 531OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -519,4 +522,10 @@519522 if (!selectedProjectDraftKey) {520523 return;521524 }525+ const removedAttachment = getComposerDraftSnapshot(selectedProjectDraftKey).attachments.find(526+ (attachment) => attachment.id === imageId,527+ );522528 removeComposerDraftAttachment(selectedProjectDraftKey, imageId);529+ if (removedAttachment?.type === "file") {530+ void removePersistedComposerAttachmentFile(removedAttachment.fileUri);531+ }
- apps/web/src/components/chat/ChatComposer.tsx lines 3429 to 3429OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -3312,0 +3409,21 @@3409+ {upload?.status === "uploading"3410+ ? formatAttachmentUploadProgress(upload.progress)3411+ : sizeLabel}3412+ </span>3413+ {upload?.status === "failed" ? (3414+ <Tooltip>3415+ <TooltipTrigger3416+ render={3417+ <Button3418+ variant="ghost"3419+ size="icon-xs"3420+ onClick={() =>3421+ retryAttachmentUpload({ environmentId, image: file })3422+ }3423+ aria-label={`Retry upload for ${file.name}`}3424+ />3425+ }3426+ >3427+ <RotateCcwIcon />3428+ </TooltipTrigger>3429+ <TooltipPopup side="top">{upload.reason}</TooltipPopup>
- apps/web/src/components/chat/ChatComposer.tsx line 2778Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2533,5 +2673,5 @@25332673 // accepted files reserve their attachment slots (via the pending counter)25342674 // before the first await, keeping the total under the limit.25352675 const pendingCount = pendingImageCompressionsRef.current.get(threadId) ?? 0;2536- let reservedCount = composerImagesRef.current.length + pendingCount;2537- const acceptedFiles: File[] = [];2676+ let reservedCount =2677+ composerImagesRef.current.length + composerFilesRef.current.length + pendingCount;apps/mobile/src/features/threads/new-task-flow-provider.tsx line 920OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -916,3 +917,4 @@916917 }917918 clearComposerDraft(pendingTaskDraftKey(editing.messageId));918919 releaseEditingQueuedMessage(editing.messageId);920+ void releaseUnusedComposerAttachmentFiles(editing.attachments);apps/web/src/components/chat/ChatComposer.tsx lines 2190 to 2191OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2116,3 +2184,8 @@21162184 setComposerTrigger(null);21172185 }211821862187+ let unrestoredFileNames: string[] = [];2188+ let restoredFileCount = 0;2189+ if (stashedFiles.length > 0) {2190+ const existingFileIds = new Set(composerFilesRef.current.map((file) => file.id));2191+ const filesToRestore = stashedFiles.filter((file) => !existingFileIds.has(file.id));apps/mobile/src/features/threads/use-project-actions.ts lines 110 to 110OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -85,3 +107,4 @@85107 return AsyncResult.failure(result.cause);86108 }87109 setPendingConnectionError(null);110+ await releaseUnusedComposerAttachmentFiles(input.initialAttachments);
- apps/web/src/components/chat/MessagesTimeline.tsx lines 1075 to 1075OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -1050,3 +1057,19 @@10501057 image={previewImages[index] ?? null}10511058 />10521059 ))}1060+ {userFiles.length > 0 ? (1061+ <div className="mb-2 flex flex-col gap-1">1062+ {userFiles.map((file) => {1063+ const content = (1064+ <>1065+ <FileIcon className="size-4 shrink-0 text-secondary-label" />1066+ <span className="min-w-0 flex-1 truncate">{file.name}</span>1067+ {file.previewUrl ? <DownloadIcon className="size-4 shrink-0" /> : null}1068+ </>1069+ );1070+ return file.previewUrl ? (1071+ <a1072+ key={file.id}1073+ href={file.previewUrl}1074+ download={file.name}1075+ className="flex min-w-0 items-center gap-2 py-1 text-sm hover:text-primary"
- apps/web/src/components/chat/ChatComposer.tsx line 2414Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -2200,4 +2311,8 @@2200231122012312 const deleteStashEntry = useCallback(22022313 (entry: PromptStashEntry) => {2203- const { durable } = takeStashEntry(entry.id);2314+ const { entry: removed, durable } = takeStashEntry(entry.id);2315+ if (durable && removed) {2316+ for (const file of removed.files ?? []) {2317+ releaseAttachmentUpload(file.id);2318+ }
- apps/web/src/components/chat/ChatComposer.tsx line 2304Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -2118,0 +2210,21 @@2210+ composerFilesRef.current.length,2211+ );2212+ const restoredFiles = filesToRestore.slice(0, capacity).map((file) => ({2213+ type: "file" as const,2214+ id: file.id,2215+ name: file.name,2216+ mimeType: file.mimeType,2217+ sizeBytes: file.sizeBytes,2218+ file: null,2219+ uploadedAttachmentId: file.attachmentId,2220+ uploadEnvironmentId: environmentId,2221+ }));2222+ const skippedFiles = filesToRestore.slice(capacity);2223+ unrestoredFileNames = skippedFiles.map((file) => file.name);2224+ for (const file of skippedFiles) {2225+ releasePersistedAttachmentUpload({2226+ id: file.id,2227+ environmentId,2228+ attachmentId: file.attachmentId,2229+ });2230+ }apps/web/src/components/chat/ChatComposer.tsx line 2457Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -2224,2 +2363,21 @@22242363 return;22252364 }2365+ const stashedFiles: PersistedComposerFileAttachment[] = [];2366+ for (const file of files) {2367+ const upload = readAttachmentUpload(file.id);2368+ if (upload?.status !== "ready" || upload.environmentId !== environmentId) {2369+ toastManager.add({2370+ type: "error",2371+ title: "Wait for file uploads before stashing this prompt",2372+ });2373+ return;2374+ }2375+ stashedFiles.push({2376+ id: file.id,2377+ name: file.name,2378+ mimeType: file.mimeType,2379+ sizeBytes: file.sizeBytes,2380+ attachmentId: upload.attachmentId,2381+ environmentId,2382+ });2383+ }apps/web/src/composerDraftStore.ts line 3704OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -3509,3 +3701,4 @@35093701 ...destination,35103702 prompt: movedPrompt,35113703 images: [...destination.images, ...source.images],3704+ files: [...destination.files, ...transferableFiles],
- apps/web/src/components/chat/ComposerStashMenu.tsx lines 185 to 190Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -176,3 +182,9 @@176182 ))}177183 </span>178184 ) : null}185+ {(entry.files?.length ?? 0) > 0 ? (186+ <span className="flex shrink-0 items-center gap-1 text-secondary-label">187+ <FileIcon className="size-4" />188+ {entry.files!.length}189+ </span>190+ ) : null}
- apps/web/src/components/chat/ComposerStashMenu.tsx lines 28 to 29OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -20,4 +20,10 @@2020 return trimmed.length > SNIPPET_MAX_CHARS ? `${trimmed.slice(0, SNIPPET_MAX_CHARS)}…` : trimmed;2121 }2222 const imageCount = entry.attachments.length + entry.droppedImageNames.length;23- return imageCount > 0 ? `(${imageCount} image${imageCount === 1 ? "" : "s"})` : "(empty)";23+ const fileCount = entry.files?.length ?? 0;24+ const attachmentCount = imageCount + fileCount;25+ if (attachmentCount === 0) {26+ return "(empty)";27+ }28+ const label = fileCount > 0 ? "file" : "image";29+ return `(${attachmentCount} ${label}${attachmentCount === 1 ? "" : "s"})`;apps/web/src/composerDraftStore.ts lines 323 to 323Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -295,3 +320,4 @@295320 return (296321 draft.prompt.trim().length > 0 ||297322 draft.images.length > 0 ||323+ draft.files.length > 0 ||
- apps/web/src/components/chat/MessagesTimeline.tsx lines 1092 to 1092OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1052,0 +1072,21 @@1072+ <FileIcon className="size-4 shrink-0 text-secondary-label" />1073+ <span className="min-w-0 flex-1 truncate">{file.name}</span>1074+ <DownloadIcon className="size-4 shrink-0" />1075+ </>1076+ );1077+ return file.previewUrl ? (1078+ <a1079+ key={file.id}1080+ href={file.previewUrl}1081+ download={file.name}1082+ className="flex min-w-0 items-center gap-2 py-1 text-sm hover:underline"1083+ >1084+ {content}1085+ </a>1086+ ) : (1087+ <button1088+ key={file.id}1089+ type="button"1090+ aria-label={`Download ${file.name}`}1091+ onClick={() => ctx.onFileDownload(file)}1092+ className="flex min-w-0 items-center gap-2 py-1 text-sm hover:underline"
- apps/mobile/src/features/threads/use-project-actions.ts line 101OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -77,3 +95,7 @@7795 worktreeBranchName: buildTemporaryWorktreeBranchName(randomHex),7896 }),7997 });98+ await deletePendingMobileAttachments(99+ input.project.environmentId,100+ uploaded.pendingAttachmentIds,101+ );apps/mobile/src/state/use-thread-outbox-drain.ts line 656Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -301 +425,21 @@301425426+ const fileAttachments = nextQueuedMessage.attachments.filter(427+ (attachment) => attachment.type === "file",428+ );429+ if (fileAttachments.length > 0) {430+ const serverConfig = serverConfigs.get(nextQueuedMessage.environmentId);431+ if (!serverConfig) {432+ continue;433+ }434+ const maxBytes = serverConfig.environment.capabilities.fileAttachments?.maxUploadBytes;435+ if (maxBytes === undefined) {436+ setPendingConnectionError("This server does not support file attachments.");437+ continue;438+ }439+ const oversized = fileAttachments.find((attachment) => attachment.sizeBytes > maxBytes);440+ if (oversized) {441+ setPendingConnectionError(442+ `'${oversized.name}' exceeds the ${Math.round(maxBytes / (1024 * 1024))} MB attachment limit.`,443+ );444+ continue;445+ }
- apps/mobile/src/state/use-composer-drafts.ts line 247Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -229,3 +230,17 @@229230 } while (persistTimer !== null);230231 }231232233+export async function releaseUnusedComposerAttachmentFiles(234+ attachments: ReadonlyArray<DraftComposerAttachment>,235+): Promise<void> {236+ const candidates = new Set(237+ attachments238+ .filter((attachment) => attachment.type === "file")239+ .map((attachment) => attachment.fileUri),240+ );241+ if (candidates.size === 0) {242+ return;243+ }244+245+ await flushComposerDrafts();246+ await flushThreadOutbox();@@ -142,9 +142,9 @@142142 supportsText: true,143143 supportsWebUrlWithMaxCount: 1,144144 supportsImageWithMaxCount: 8,145+ supportsFileWithMaxCount: 8,145146 },146147 },147148 android: {148149 enabled: true,149- singleShareMimeTypes: ["text/plain", "image/*"],150- multipleShareMimeTypes: ["image/*"],150+ singleShareMimeTypes: ["*/*"],apps/web/src/components/chat/MessagesTimeline.tsx line 1097Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -1052,0 +1071,21 @@1071+ <>1072+ <FileIcon className="size-4 shrink-0 text-secondary-label" />1073+ <span className="min-w-0 flex-1 truncate">{file.name}</span>1074+ <DownloadIcon className="size-4 shrink-0" />1075+ </>1076+ );1077+ return file.previewUrl ? (1078+ <a1079+ key={file.id}1080+ href={file.previewUrl}1081+ download={file.name}1082+ className="flex min-w-0 items-center gap-2 py-1 text-sm hover:underline"1083+ >1084+ {content}1085+ </a>1086+ ) : (1087+ <button1088+ key={file.id}1089+ type="button"1090+ aria-label={`Download ${file.name}`}1091+ onClick={() => ctx.onFileDownload(file)}apps/mobile/src/state/use-composer-drafts.ts line 629OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -572,3 +626,4 @@572626 appAtomRegistry.set(composerDraftsAtom, next);573627 }574628 await persistenceQueue.run(() => writePersistedComposerDrafts(next));629+ scheduleUnusedComposerAttachmentCleanup(apps/mobile/src/lib/attachmentUpload.ts line 104OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +84,21 @@84+ const pendingAttachmentIds: string[] = [];85+ const createdAttachmentIds: string[] = [];86+ try {87+ for (const attachment of input.attachments) {88+ if (attachment.type === "image") {89+ uploadedAttachments.push(...toUploadChatImageAttachments([attachment]));90+ continue;91+ }92+93+ if (94+ attachment.uploadEnvironmentId === input.environmentId &&95+ attachment.uploadedAttachmentId96+ ) {97+ pendingAttachmentIds.push(attachment.uploadedAttachmentId);98+ uploadedAttachments.push({99+ type: "file",100+ id: attachment.uploadedAttachmentId,101+ name: attachment.name,102+ mimeType: attachment.mimeType,103+ sizeBytes: attachment.sizeBytes,104+ });apps/mobile/src/state/use-composer-drafts.ts lines 629 to 634OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -572,3 +626,9 @@572626 appAtomRegistry.set(composerDraftsAtom, next);573627 }574628 await persistenceQueue.run(() => writePersistedComposerDrafts(next));629+ scheduleUnusedComposerAttachmentCleanup(630+ content.attachments.filter(631+ (attachment) =>632+ !currentAttachmentIds.has(attachment.id) && !nextAttachmentIds.has(attachment.id),633+ ),634+ );apps/mobile/src/features/sharing/IncomingShareProvider.tsx line 141OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -131,5 +135,7 @@131135 clearPayloads: clearSharedPayloads,132136 buildDraft: async ({ payloads, id, createdAt }) => {133137 const cleanupUris = new Set<string>();134- const resolvedPayloads = payloads.some((payload) => payload.shareType === "image")135- ? await resolvedPayloadsForImages()138+ const resolvedPayloads = payloads.some((payload) =>139+ ["image", "file", "audio", "video"].includes(payload.shareType),140+ )141+ ? await resolvedPayloadsForFiles()apps/mobile/src/lib/attachmentUpload.ts line 78Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -0,0 +50,21 @@50+ attachmentEnvironment.remove,51+ { environmentId, input: { attachmentId } },52+ { reportFailure: false, reportDefect: false },53+ ),54+ ),55+ );56+}57+58+export async function uploadMobileAttachments(input: {59+ readonly environmentId: EnvironmentId;60+ readonly attachments: ReadonlyArray<DraftComposerAttachment>;61+}): Promise<{62+ readonly attachments: ReadonlyArray<UploadedMobileAttachment>;63+ readonly pendingAttachmentIds: ReadonlyArray<string>;64+}> {65+ const files = input.attachments.filter((attachment) => attachment.type === "file");66+ if (files.length === 0) {67+ return {68+ attachments: toUploadChatImageAttachments(69+ input.attachments.filter((attachment) => attachment.type === "image"),70+ ),apps/mobile/src/features/sharing/incoming-share-model.ts line 230Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -156,5 +200,20 @@156200 await releaseOwnedFiles(input.fileReader, [uri, payload.value]);157201 continue;158202 }159203160- const mimeType = (resolved?.contentMimeType ?? payload.mimeType ?? "image/png").toLowerCase();204+ const mimeType = (205+ resolved?.contentMimeType ??206+ payload.mimeType ??207+ (payload.shareType === "image" ? "image/png" : "application/octet-stream")208+ ).toLowerCase();209+ if (payload.shareType !== "image") {210+ const name = resolved?.originalName ?? fallbackName(uri, index, mimeType);211+ if (!uri) {212+ warnings.push("One shared file could not be read.");213+ continue;214+ }215+ let persistedFileUri: string | undefined;216+ try {217+ let sizeBytes = resolved?.contentSize ?? (await input.fileReader.readSize?.(uri)) ?? null;218+ if (sizeBytes === null && input.fileReader.persistFile) {219+ persistedFileUri = await input.fileReader.persistFile(uri, name);apps/mobile/src/state/use-thread-composer-state.ts line 329Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -306,0 +308,21 @@308+ const onPickDraftFiles = useCallback(async () => {309+ if (!selectedThreadShell) {310+ return;311+ }312+ const maxBytes =313+ selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.fileAttachments314+ ?.maxUploadBytes;315+ if (maxBytes === undefined) {316+ setPendingConnectionError("This server does not support file attachments.");317+ return;318+ }319+320+ const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);321+ const result = await pickComposerFiles({322+ existingCount: composerDrafts[threadKey]?.attachments.length ?? 0,323+ maxBytes,324+ });325+ if (result.files.length > 0) {326+ appendComposerDraftAttachments(threadKey, result.files);327+ }328+ if (result.error) {packages/contracts/src/orchestration.ts line 218Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -202,4 +215,4 @@202215 });203216 export type UploadChatImageAttachment = typeof UploadChatImageAttachment.Type;204217205-export const ChatAttachment = Schema.Union([ChatImageAttachment]);218+export const ChatAttachment = Schema.Union([ChatImageAttachment, ChatFileAttachment]);apps/mobile/src/state/use-thread-composer-state.ts line 323OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -304,3 +305,19 @@304305 }305306 }, [composerDrafts, selectedThreadShell]);306307308+ const onPickDraftFiles = useCallback(async () => {309+ if (!selectedThreadShell) {310+ return;311+ }312+ const maxBytes =313+ selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.fileAttachments314+ ?.maxUploadBytes;315+ if (maxBytes === undefined) {316+ setPendingConnectionError("This server does not support file attachments.");317+ return;318+ }319+320+ const threadKey = scopedThreadKey(selectedThreadShell.environmentId, selectedThreadShell.id);321+ const result = await pickComposerFiles({322+ existingCount: composerDrafts[threadKey]?.attachments.length ?? 0,323+ maxBytes,apps/web/src/lib/attachmentUploadQueue.ts line 428Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -340,3 +412,9 @@340412 clearUploadState(imageId);341413 }342414415+export function releasePersistedAttachmentUpload(input: {416+ readonly id: string;417+ readonly environmentId: EnvironmentId;418+ readonly attachmentId: string;419+}): void {420+ const upload = readAttachmentUpload(input.id);
- apps/mobile/src/state/use-thread-outbox-drain.ts line 676Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -301,0 +451,21 @@451+ if (!serverConfig) {452+ continue;453+ }454+ const maxBytes = serverConfig.environment.capabilities.fileAttachments?.maxUploadBytes;455+ if (maxBytes === undefined) {456+ attachmentError = "This server does not support file attachments.";457+ } else {458+ const oversized = fileAttachments.find((attachment) => attachment.sizeBytes > maxBytes);459+ if (oversized) {460+ attachmentError = `'${oversized.name}' exceeds the ${Math.round(maxBytes / (1024 * 1024))} MB attachment limit.`;461+ }462+ }463+ }464+ if (attachmentError !== null) {465+ beginDispatchingQueuedMessage(nextQueuedMessage.messageId);466+ void confirmThreadOutboxMessageQueued(nextQueuedMessage)467+ .then((queued) =>468+ queued ? restoreRejectedQueuedMessage(nextQueuedMessage, attachmentError) : true,469+ )470+ .finally(() => finishDispatchingQueuedMessage(nextQueuedMessage.messageId));471+ return;apps/mobile/src/state/use-thread-outbox-drain.ts line 166OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -87,0 +146,21 @@146+147+async function restoreRejectedQueuedMessage(148+ queuedMessage: QueuedThreadMessage,149+ message: string,150+): Promise<boolean> {151+ const draftKey = queuedMessage.creation152+ ? `new-task:${scopedProjectKey(queuedMessage.environmentId, queuedMessage.creation.projectId)}`153+ : scopedThreadKey(queuedMessage.environmentId, queuedMessage.threadId);154+ try {155+ await mergeComposerDraftContent(draftKey, { text: queuedMessage.text, attachments: [] });156+ const existingAttachmentIds = new Set(157+ getComposerDraftSnapshot(draftKey).attachments.map((attachment) => attachment.id),158+ );159+ appendComposerDraftAttachments(160+ draftKey,161+ queuedMessage.attachments.filter((attachment) => !existingAttachmentIds.has(attachment.id)),162+ );163+ await flushComposerDrafts();164+ await removeThreadOutboxMessage(queuedMessage);165+ setPendingConnectionError(message);166+ return true;apps/mobile/src/state/use-thread-outbox-drain.ts line 174OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -87,0 +142,21 @@142+ );143+ throw error;144+ }145+}146+147+async function restoreRejectedQueuedMessage(148+ queuedMessage: QueuedThreadMessage,149+ message: string,150+): Promise<boolean> {151+ const draftKey = queuedMessage.creation152+ ? `new-task:${scopedProjectKey(queuedMessage.environmentId, queuedMessage.creation.projectId)}`153+ : scopedThreadKey(queuedMessage.environmentId, queuedMessage.threadId);154+ try {155+ await mergeComposerDraftContent(draftKey, { text: queuedMessage.text, attachments: [] });156+ const existingAttachmentIds = new Set(157+ getComposerDraftSnapshot(draftKey).attachments.map((attachment) => attachment.id),158+ );159+ appendComposerDraftAttachments(160+ draftKey,161+ queuedMessage.attachments.filter((attachment) => !existingAttachmentIds.has(attachment.id)),162+ );
- apps/mobile/src/features/threads/use-project-actions.ts line 68Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -56,3 +65,4 @@5665 return AsyncResult.failure(Cause.fail(validationError));5766 }586768+ let uploaded: Awaited<ReturnType<typeof uploadMobileAttachments>>;apps/mobile/src/state/use-thread-outbox-drain.ts line 155OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -87,0 +135,21 @@135+ ),136+ );137+ await deletePendingMobileAttachments(138+ queuedMessage.environmentId,139+ uploaded.pendingAttachmentIds.filter(140+ (attachmentId) => !previousAttachmentIds.has(attachmentId),141+ ),142+ );143+ throw error;144+ }145+}146+147+async function restoreRejectedQueuedMessage(148+ queuedMessage: QueuedThreadMessage,149+ message: string,150+): Promise<boolean> {151+ const draftKey = queuedMessage.creation152+ ? `new-task:${scopedProjectKey(queuedMessage.environmentId, queuedMessage.creation.projectId)}`153+ : scopedThreadKey(queuedMessage.environmentId, queuedMessage.threadId);154+ try {155+ await mergeComposerDraftContent(draftKey, { text: queuedMessage.text, attachments: [] });apps/mobile/src/features/threads/NewTaskDraftScreen.tsx lines 440 to 445Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -423,3 +430,9 @@423430 return;424431 }425432433+ if (434+ incomingShare.attachments.some((attachment) => attachment.type === "file") &&435+ selectedEnvironmentServerConfig === null436+ ) {437+ return;438+ }
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
c5745e26-94bb-4d07-8515-e1a5cdc7d93fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share