char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
59778f019
char/aliceai-t5-moe
1/** 2* HTTP request inspection utilities for diagnostic logging. 3* These helpers extract metadata from fetch-style request arguments 4* without exposing sensitive payload data. 5*/ 6 7export interface RequestBodySummary { 8kind :string ; 9size ?:number ; 10} 11 12export function getRequestUrl ( input :RequestInfo | URL ) :string { 13if ( typeof input === 'string' ) { 14return input ; 15} 16 17if ( input instanceof URL ) { 18return input . href ; 19} 20 21return input . url ; 22} 23 24export function getRequestMethod ( 25input :RequestInfo | URL , 26init ?:RequestInit , 27baseInit ?:RequestInit 28) :string { 29if ( init ?. method ) { 30return init . method ; 31} 32 33if ( typeof Request !== 'undefined' && input instanceof Request ) { 34return input . method ; 35} 36 37return baseInit ?. method ?? 'GET' ; 38} 39 40export function getRequestBody ( 41input :RequestInfo | URL , 42init ?:RequestInit 43) :BodyInit | null | undefined { 44if ( init ?. body !== undefined ) { 45return init . body ; 46} 47 48if ( typeof Request !== 'undefined' && input instanceof Request ) { 49return input . body ; 50} 51 52return undefined ; 53} 54 55export function summarizeRequestBody ( body :BodyInit | null | undefined ) :RequestBodySummary { 56if ( body == null ) { 57return { kind :'empty' }; 58} 59 60if ( typeof body === 'string' ) { 61return { kind :'string' , size :body . length }; 62} 63 64if ( body instanceof Blob ) { 65return { kind :'blob' , size :body . size }; 66} 67 68if ( body instanceof URLSearchParams ) { 69return { kind :'urlsearchparams' , size :body . toString (). length }; 70} 71 72if ( body instanceof FormData ) { 73return { kind :'formdata' }; 74} 75 76if ( body instanceof ArrayBuffer ) { 77return { kind :'arraybuffer' , size :body . byteLength }; 78} 79 80if ( ArrayBuffer . isView ( body )) { 81return { kind :body . constructor . name , size :body . byteLength }; 82} 83 84return { kind :typeof body }; 85} 86 87export function formatDiagnosticErrorMessage ( error :unknown ) :string { 88const message = error instanceof Error ?error . message :String ( error ); 89 90return message . includes ( 'Failed to fetch' ) ?` ${ message } (check CORS?)` :message ; 91} 92 93export function extractJsonRpcMethods ( body :BodyInit | null | undefined ) :string [] | undefined { 94if ( typeof body !== 'string' ) { 95return undefined ; 96} 97 98try { 99const parsed = JSON . parse ( body ); 100const messages = Array . isArray ( parsed ) ?parsed :[ parsed ]; 101const methods = messages 102. map (( message :Record < string , unknown >) => 103typeof message ?. method === 'string' ?( message . method as string ) :undefined 104) 105. filter (( method :string | undefined ) :method isstring => Boolean ( method )); 106 107return methods . length > 0 ?methods :undefined ; 108} catch { 109return undefined ; 110} 111}