feat(server): accept PDF, ZIP, and other file uploads up to 50MB #8235
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/8235/headmerged by t3dotgg(GitHub profile, opens in a new tab) 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:L
- packages/contracts/src/orchestration.ts line 217OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -193,0 +197,21 @@197+ id: ChatAttachmentId,198+ name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),199+ mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100)),200+ sizeBytes: NonNegativeInt.check(201+ Schema.isGreaterThanOrEqualTo(1),202+ Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_FILE_BYTES),203+ ),204+});205+export type ChatFileAttachment = typeof ChatFileAttachment.Type;206+207+/**208+ * Catch-all for attachment types this build does not know. Attachments ride on209+ * persisted events and thread streams, so a newer server or client must be able210+ * to introduce a type without making older readers fail to decode the whole211+ * message. Decoders keep the shared base fields; consumers skip these or render212+ * them as unsupported. Mirrors how `OrchestrationThreadActivity` keeps `kind`213+ * open. Union order matters: known members decode first, so this only catches214+ * genuinely unknown types.215+ */216+export const ChatUnknownAttachment = Schema.Struct({217+ type: TrimmedNonEmptyString.check(Schema.isMaxLength(50)),apps/server/src/attachmentStore.ts lines 45 to 45OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -39,5 +40,6 @@3940 return segment === PENDING_ATTACHMENT_THREAD_SEGMENT ? "_pending" : segment;4041 }414242-export function createPendingAttachmentId(): string {43- return `${PENDING_ATTACHMENT_THREAD_SEGMENT}-${NodeCrypto.randomUUID()}`;43+export function attachmentFileExtension(fileName: string): string {44+ const extension = NodePath.extname(fileName).toLowerCase();45+ return /^\.[a-z0-9]{1,10}$/.test(extension) ? extension : ".bin";apps/server/src/http.ts lines 65 to 65OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -50,4 +50,16 @@5050 const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];5151 const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";525253-export function assetResponseHeaders(filePath: string): Record<string, string> {53+// Types a browser may render as a document if a proxy strips the disposition54+// header. Downloads of these fall back to octet-stream.55+const DOWNLOAD_MIME_TYPE_PATTERN = /^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/;56+const isSafeDownloadMimeType = (mimeType: string): boolean =>57+ DOWNLOAD_MIME_TYPE_PATTERN.test(mimeType) &&58+ !/(?:^text\/html$|svg|xml)/i.test(mimeType.trim().toLowerCase());59+60+/** RFC 6266 disposition with an ASCII fallback name plus a UTF-8 `filename*`. */61+export function downloadContentDisposition(fileName?: string): string {62+ if (fileName === undefined) {63+ return "attachment";64+ }65+ const sanitized = fileName.replace(/[\u0000-\u001f"\\]/g, "_");
- packages/contracts/src/orchestration.ts line 244Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -202,4 +233,8 @@202233 });203234 export type UploadChatImageAttachment = typeof UploadChatImageAttachment.Type;204235205-export const ChatAttachment = Schema.Union([ChatImageAttachment]);236+export const ChatAttachment = Schema.Union([237+ ChatImageAttachment,238+ ChatFileAttachment,239+ ChatUnknownAttachment,240+]);
- apps/server/src/provider/opencodeRuntime.ts line 357OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -345,3 +345,13 @@345345 return header.length > 0 ? `question-${index}-${header}` : `question-${index}`;346346 }347347348+/**349+ * Mimes OpenCode can hand to a model as a native file part. Anything else350+ * (ZIP, binaries) makes its Anthropic path throw AI_UnsupportedFunctionalityError351+ * before the turn starts, so those attachments ride only as the file path352+ * ProviderService puts in the prompt.353+ */354+export function isOpenCodeNativeFileMime(mimeType: string): boolean {355+ const normalized = mimeType.trim().toLowerCase();356+ return (357+ normalized.startsWith("image/") ||
- apps/server/src/http.ts lines 68 to 68Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -50,4 +51,18 @@5051 const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];5152 const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";525353-export function assetResponseHeaders(filePath: string): Record<string, string> {54+// Types a browser may render as a document if a proxy strips the disposition55+// header. Downloads of these fall back to octet-stream.56+const DOWNLOAD_MIME_TYPE_PATTERN = /^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/;57+const isSafeDownloadMimeType = (mimeType: string): boolean =>58+ DOWNLOAD_MIME_TYPE_PATTERN.test(mimeType) &&59+ !/(?:^text\/html$|svg|xml)/i.test(mimeType.trim().toLowerCase());60+61+/** RFC 6266 disposition with an ASCII fallback name plus a UTF-8 `filename*`. */62+export function downloadContentDisposition(fileName?: string): string {63+ if (fileName === undefined) {64+ return "attachment";65+ }66+ // toWellFormed: encodeURIComponent throws URIError on unpaired surrogates.67+ // eslint-disable-next-line no-control-regex -- Header filenames must strip ASCII controls.68+ const sanitized = fileName.toWellFormed().replace(/[\u0000-\u001f"\\]/g, "_");
- @@ -50,4 +51,9 @@5051 const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];5152 const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";525353-export function assetResponseHeaders(filePath: string): Record<string, string> {54+// Types a browser may render as a document if a proxy strips the disposition55+// header. Downloads of these fall back to octet-stream.56+const DOWNLOAD_MIME_TYPE_PATTERN = /^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/;57+const isSafeDownloadMimeType = (mimeType: string): boolean =>58+ DOWNLOAD_MIME_TYPE_PATTERN.test(mimeType) &&59+ !/(?:^text\/html$|svg|xml)/i.test(mimeType.trim().toLowerCase());
t3dotgg(GitHub profile, opens in a new tab) closed this
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:
ae0e9152-6daa-46d3-a592-6ff68346f32fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.