Persist Jupyter workspace bindings

This commit is contained in:
wuyang6
2026-05-13 17:59:50 +08:00
parent b7dba5f5b8
commit ef703ff49b
3 changed files with 208 additions and 18 deletions
@@ -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) {