Files
Dorod-Sky/skyvern-frontend/src/store/DebugStoreContext.tsx

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-07-07 22:30:33 -04:00
import React, { createContext, useMemo } from "react";
import { useLocation } from "react-router-dom";
import { lsKeys } from "@/util/env";
2025-07-07 22:30:33 -04:00
function useIsDebugMode() {
const location = useLocation();
return useMemo(
() => location.pathname.includes("debug"),
[location.pathname],
);
}
function getCurrentBrowserSessionId() {
const stored = localStorage.getItem(lsKeys.optimisticBrowserSession);
let browserSessionId: string | null = null;
try {
const parsed = JSON.parse(stored ?? "");
const { browser_session_id } = parsed;
browserSessionId = browser_session_id as string;
} catch {
// pass
}
return browserSessionId;
}
2025-07-07 22:30:33 -04:00
export type DebugStoreContextType = {
isDebugMode: boolean;
getCurrentBrowserSessionId: () => string | null;
2025-07-07 22:30:33 -04:00
};
export const DebugStoreContext = createContext<
DebugStoreContextType | undefined
>(undefined);
export const DebugStoreProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const isDebugMode = useIsDebugMode();
return (
<DebugStoreContext.Provider
value={{ isDebugMode, getCurrentBrowserSessionId }}
>
2025-07-07 22:30:33 -04:00
{children}
</DebugStoreContext.Provider>
);
};