@@ -689,35 +689,48 @@ function promptPreflightError(error: unknown): Response {
689689 }
690690}
691691
692- async function readRequestJson ( request : Request ) : Promise < unknown > {
692+ type ReadRequestJsonResult =
693+ | { success : true ; value : unknown }
694+ | { success : false ; response : Response } ;
695+
696+ async function readRequestJson ( request : Request ) : Promise < ReadRequestJsonResult > {
693697 const declaredLength = request . headers . get ( 'content-length' ) ;
694698 if ( declaredLength !== null ) {
695699 const bodyBytes = Number ( declaredLength ) ;
696700 if ( ! Number . isSafeInteger ( bodyBytes ) || bodyBytes > MAX_KILO_PROMPT_JSON_BYTES ) {
697- return facadeError (
698- 400 ,
699- 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
700- 'Basic Kilo prompt body is not supported'
701- ) ;
701+ return {
702+ success : false ,
703+ response : facadeError (
704+ 400 ,
705+ 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
706+ 'Basic Kilo prompt body is not supported'
707+ ) ,
708+ } ;
702709 }
703710 }
704711 const response = new Response ( request . body ) ;
705712 const bytes = await readBoundedBody ( response , MAX_KILO_PROMPT_JSON_BYTES ) ;
706713 if ( ! bytes ) {
707- return facadeError (
708- 400 ,
709- 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
710- 'Basic Kilo prompt body is not supported'
711- ) ;
714+ return {
715+ success : false ,
716+ response : facadeError (
717+ 400 ,
718+ 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
719+ 'Basic Kilo prompt body is not supported'
720+ ) ,
721+ } ;
712722 }
713723 try {
714- return JSON . parse ( new TextDecoder ( ) . decode ( bytes ) ) ;
724+ return { success : true , value : JSON . parse ( new TextDecoder ( ) . decode ( bytes ) ) } ;
715725 } catch {
716- return facadeError (
717- 400 ,
718- 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
719- 'Basic Kilo prompt body is not supported'
720- ) ;
726+ return {
727+ success : false ,
728+ response : facadeError (
729+ 400 ,
730+ 'KILO_BASIC_PROMPT_UNSUPPORTED' ,
731+ 'Basic Kilo prompt body is not supported'
732+ ) ,
733+ } ;
721734 }
722735}
723736
@@ -755,11 +768,11 @@ async function admitBasicPrompt(params: {
755768 cloudAgentSessionId : string ;
756769 deps ?: KiloFacadeRequestDeps ;
757770} ) : Promise < SessionMessageAdmissionResult | Response > {
758- const value = await readRequestJson ( params . request ) ;
759- if ( value instanceof Response ) {
760- return value ;
771+ const body = await readRequestJson ( params . request ) ;
772+ if ( ! body . success ) {
773+ return body . response ;
761774 }
762- const parsed = parseBasicKiloPrompt ( value ) ;
775+ const parsed = parseBasicKiloPrompt ( body . value ) ;
763776 if ( ! parsed . success ) {
764777 return facadeError (
765778 400 ,
0 commit comments