Persist Jupyter workspace bindings
This commit is contained in:
@@ -80,6 +80,7 @@ import {
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import {
|
||||
ACTIVE_SESSION_CHANGED_EVENT,
|
||||
clearActiveSessionId,
|
||||
clearPendingWorkspaceSessionId,
|
||||
PENDING_WORKSPACE_SESSION_CHANGED_EVENT,
|
||||
@@ -310,15 +311,47 @@ function usePendingWorkspaceSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
function useCurrentThreadSessionId({ includePending = false } = {}) {
|
||||
function useActiveSessionId() {
|
||||
const [sessionId, setSessionId] = useState<string | null>(() =>
|
||||
typeof window !== "undefined"
|
||||
? normalizeSessionId(readActiveSessionId())
|
||||
: null,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const refresh = () => {
|
||||
setSessionId(normalizeSessionId(readActiveSessionId()));
|
||||
};
|
||||
window.addEventListener(ACTIVE_SESSION_CHANGED_EVENT, refresh);
|
||||
window.addEventListener("storage", refresh);
|
||||
window.addEventListener("focus", refresh);
|
||||
return () => {
|
||||
window.removeEventListener(ACTIVE_SESSION_CHANGED_EVENT, refresh);
|
||||
window.removeEventListener("storage", refresh);
|
||||
window.removeEventListener("focus", refresh);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
function useCurrentThreadSessionId({
|
||||
includePending = false,
|
||||
includeActive = true,
|
||||
} = {}) {
|
||||
const currentRun = useReplayedRunState();
|
||||
const pendingSessionId = usePendingWorkspaceSessionId();
|
||||
const activeSessionId = useActiveSessionId();
|
||||
useEffect(() => {
|
||||
if (currentRun.sessionId && currentRun.sessionId === pendingSessionId) {
|
||||
clearPendingWorkspaceSessionId();
|
||||
}
|
||||
}, [currentRun.sessionId, pendingSessionId]);
|
||||
return currentRun.sessionId ?? (includePending ? pendingSessionId : null);
|
||||
return (
|
||||
currentRun.sessionId ??
|
||||
(includePending ? pendingSessionId : null) ??
|
||||
(includeActive ? activeSessionId : null)
|
||||
);
|
||||
}
|
||||
|
||||
async function cancelLatestRun(sessionId: string, runId?: string | null) {
|
||||
|
||||
Reference in New Issue
Block a user