File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
packages/backend/server/src/plugins/copilot/context Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { SafeIntResolver } from 'graphql-scalars';
1919import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs' ;
2020
2121import {
22+ BlobQuotaExceeded ,
2223 CallMetric ,
2324 CopilotEmbeddingUnavailable ,
2425 CopilotFailedToMatchContext ,
@@ -42,6 +43,7 @@ import {
4243 ContextFileStatus ,
4344 DocChunkSimilarity ,
4445 FileChunkSimilarity ,
46+ MAX_EMBEDDABLE_SIZE ,
4547} from './types' ;
4648
4749@InputType ( )
@@ -396,6 +398,12 @@ export class CopilotContextResolver {
396398 if ( ! lock ) {
397399 return new TooManyRequest ( 'Server is busy' ) ;
398400 }
401+
402+ const length = Number ( ctx . req . headers [ 'content-length' ] ) ;
403+ if ( length && length >= MAX_EMBEDDABLE_SIZE ) {
404+ throw new BlobQuotaExceeded ( ) ;
405+ }
406+
399407 const session = await this . context . get ( options . contextId ) ;
400408
401409 try {
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import { nanoid } from 'nanoid';
77import {
88 BlobQuotaExceeded ,
99 CopilotContextFileNotSupported ,
10- OneMB ,
1110 PrismaTransaction ,
1211 UserFriendlyError ,
1312} from '../../../base' ;
@@ -22,6 +21,7 @@ import {
2221 DocChunkSimilarity ,
2322 EmbeddingClient ,
2423 FileChunkSimilarity ,
24+ MAX_EMBEDDABLE_SIZE ,
2525} from './types' ;
2626
2727export class ContextSession implements AsyncDisposable {
@@ -62,7 +62,7 @@ export class ContextSession implements AsyncDisposable {
6262
6363 private readStream (
6464 readable : Readable ,
65- maxSize = 50 * OneMB
65+ maxSize = MAX_EMBEDDABLE_SIZE
6666 ) : Promise < Buffer < ArrayBuffer > > {
6767 return new Promise < Buffer < ArrayBuffer > > ( ( resolve , reject ) => {
6868 const chunks : Uint8Array [ ] = [ ] ;
@@ -136,7 +136,7 @@ export class ContextSession implements AsyncDisposable {
136136 }
137137
138138 try {
139- const buffer = await this . readStream ( readable , 50 * OneMB ) ;
139+ const buffer = await this . readStream ( readable ) ;
140140 const file = new File ( [ buffer ] , name ) ;
141141 return await this . addFile ( file , fileId , signal ) ;
142142 } catch ( e : any ) {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { File } from 'node:buffer';
22
33import { z } from 'zod' ;
44
5- import { CopilotContextFileNotSupported } from '../../../base' ;
5+ import { CopilotContextFileNotSupported , OneMB } from '../../../base' ;
66import { parseDoc } from '../../../native' ;
77
88declare global {
@@ -18,6 +18,8 @@ declare global {
1818 }
1919}
2020
21+ export const MAX_EMBEDDABLE_SIZE = 50 * OneMB ;
22+
2123export enum ContextFileStatus {
2224 processing = 'processing' ,
2325 finished = 'finished' ,
You can’t perform that action at this time.
0 commit comments