export const QUERY_DEVTOOLS_HEADER = 'x-librechat-enable-query-devtools'; const QUERY_DEVTOOLS_SENTINEL = 'data-librechat-query-devtools="true"'; const QUERY_DEVTOOLS_BOOTSTRAP = ``; export interface QueryDevtoolsRequest { get(header: string): string | undefined; } export const shouldEnableQueryDevtools = (req: QueryDevtoolsRequest): boolean => req.get(QUERY_DEVTOOLS_HEADER) === '1'; const injectQueryDevtoolsBootstrap = (html: string): string => { if (html.includes(QUERY_DEVTOOLS_SENTINEL)) { return html; } if (html.includes('')) { return html.replace('', `${QUERY_DEVTOOLS_BOOTSTRAP}`); } return html.replace(/]*)>/i, `${QUERY_DEVTOOLS_BOOTSTRAP}`); }; export const maybeInjectQueryDevtoolsBootstrap = ( html: string, req: QueryDevtoolsRequest, ): string => { if (!shouldEnableQueryDevtools(req)) { return html; } return injectQueryDevtoolsBootstrap(html); };