@@ -8,12 +8,12 @@ import {
88 assertKnownSizeWithinLimit ,
99 DEFAULT_MAX_ERROR_BODY_BYTES ,
1010 isPayloadSizeLimitError ,
11- PayloadSizeLimitError ,
1211 readResponseJsonWithLimit ,
1312 readResponseTextWithLimit ,
1413 readResponseToBufferWithLimit ,
1514} from '@/lib/core/utils/stream-limits'
1615import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
16+ import { uploadCopilotFile } from '@/lib/uploads/contexts/copilot'
1717import { uploadExecutionFile } from '@/lib/uploads/contexts/execution'
1818import { FileInputSchema } from '@/lib/uploads/utils/file-schemas'
1919import { processFilesToUserFiles , type RawFileInput } from '@/lib/uploads/utils/file-utils'
@@ -23,7 +23,6 @@ import { assertToolFileAccess } from '@/app/api/files/authorization'
2323const logger = createLogger ( 'DocuSignAPI' )
2424const MAX_DOCUSIGN_DOCUMENT_BYTES = 25 * 1024 * 1024
2525const MAX_DOCUSIGN_JSON_BYTES = 2 * 1024 * 1024
26- const MAX_LEGACY_INLINE_DOCUMENT_BYTES = 7 * 1024 * 1024
2726
2827interface DocuSignAccountInfo {
2928 accountId : string
@@ -140,7 +139,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
140139 case 'void_envelope' :
141140 return await handleVoidEnvelope ( apiBase , headers , params )
142141 case 'download_document' :
143- return await handleDownloadDocument ( apiBase , headers , params )
142+ return await handleDownloadDocument ( apiBase , headers , params , authResult . userId )
144143 case 'list_templates' :
145144 return await handleListTemplates ( apiBase , headers , params )
146145 case 'list_recipients' :
@@ -445,7 +444,8 @@ async function handleVoidEnvelope(
445444async function handleDownloadDocument (
446445 apiBase : string ,
447446 headers : Record < string , string > ,
448- params : Record < string , unknown >
447+ params : Record < string , unknown > ,
448+ userId : string
449449) {
450450 const { envelopeId, documentId } = params
451451 if ( ! envelopeId ) {
@@ -509,17 +509,14 @@ async function handleDownloadDocument(
509509 } )
510510 }
511511
512- if ( buffer . length > MAX_LEGACY_INLINE_DOCUMENT_BYTES ) {
513- throw new PayloadSizeLimitError ( {
514- label : 'DocuSign legacy inline document' ,
515- maxBytes : MAX_LEGACY_INLINE_DOCUMENT_BYTES ,
516- observedBytes : buffer . length ,
517- } )
518- }
519-
520- const base64Content = buffer . toString ( 'base64' )
512+ const file = await uploadCopilotFile ( {
513+ buffer,
514+ fileName,
515+ contentType,
516+ userId,
517+ } )
521518
522- return NextResponse . json ( { base64Content , mimeType : contentType , fileName } )
519+ return NextResponse . json ( { file , mimeType : contentType , fileName } )
523520}
524521
525522async function handleListTemplates (
0 commit comments