File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -561,13 +561,24 @@ export const executeToolServer = async (
561561 responseHeaders [ key ] = value ;
562562 } ) ;
563563
564- const text = await res . text ( ) ;
565564 let responseData ;
565+ const contentType = res . headers . get ( 'Content-Type' ) ?. split ( ';' ) [ 0 ] ?. trim ( ) ?? '' ;
566566
567567 try {
568- responseData = JSON . parse ( text ) ;
568+ responseData = await res . clone ( ) . json ( ) ;
569569 } catch {
570- responseData = text ;
570+ if ( contentType . startsWith ( 'text/' ) || ! contentType ) {
571+ responseData = await res . text ( ) ;
572+ } else {
573+ const buf = await res . arrayBuffer ( ) ;
574+ const bytes = new Uint8Array ( buf ) ;
575+ let binary = '' ;
576+ for ( let i = 0 ; i < bytes . length ; i ++ ) {
577+ binary += String . fromCharCode ( bytes [ i ] ) ;
578+ }
579+ const b64 = btoa ( binary ) ;
580+ responseData = `data:${ contentType } ;base64,${ b64 } ` ;
581+ }
571582 }
572583 return [ responseData , responseHeaders ] ;
573584 } catch ( err : any ) {
You can’t perform that action at this time.
0 commit comments