Fix pending Jupyter workspace handoff
This commit is contained in:
@@ -20,8 +20,8 @@ import {
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import {
|
||||
consumePendingWorkspaceSessionId,
|
||||
readActiveSessionId,
|
||||
readPendingWorkspaceSessionId,
|
||||
writeActiveSessionId,
|
||||
} from "@/lib/claw-active-session";
|
||||
import { ClawSessionReplayProvider } from "@/lib/claw-session-replay";
|
||||
@@ -39,19 +39,13 @@ export const Assistant = () => {
|
||||
const selectedSessionId = readActiveSessionId();
|
||||
const lastSessionId = getLastSessionId(messages);
|
||||
const pendingWorkspaceSessionId =
|
||||
messages.length <= 1 ? consumePendingWorkspaceSessionId() : null;
|
||||
const usablePendingWorkspaceSessionId =
|
||||
pendingWorkspaceSessionId &&
|
||||
(!selectedSessionId ||
|
||||
selectedSessionId === pendingWorkspaceSessionId)
|
||||
? pendingWorkspaceSessionId
|
||||
: null;
|
||||
messages.length <= 1 ? readPendingWorkspaceSessionId() : null;
|
||||
const selectedResumeSessionId =
|
||||
messages.length > 1 ? selectedSessionId : null;
|
||||
const outgoingSessionId =
|
||||
lastSessionId ??
|
||||
selectedResumeSessionId ??
|
||||
usablePendingWorkspaceSessionId ??
|
||||
pendingWorkspaceSessionId ??
|
||||
options.id;
|
||||
const lastUserMessage = [...messages]
|
||||
.reverse()
|
||||
|
||||
@@ -81,6 +81,7 @@ import {
|
||||
} from "@/components/ui/tooltip";
|
||||
import {
|
||||
clearActiveSessionId,
|
||||
clearPendingWorkspaceSessionId,
|
||||
PENDING_WORKSPACE_SESSION_CHANGED_EVENT,
|
||||
readActiveSessionId,
|
||||
readPendingWorkspaceSessionId,
|
||||
@@ -312,6 +313,11 @@ function usePendingWorkspaceSessionId() {
|
||||
function useCurrentThreadSessionId({ includePending = false } = {}) {
|
||||
const currentRun = useReplayedRunState();
|
||||
const pendingSessionId = usePendingWorkspaceSessionId();
|
||||
useEffect(() => {
|
||||
if (currentRun.sessionId && currentRun.sessionId === pendingSessionId) {
|
||||
clearPendingWorkspaceSessionId();
|
||||
}
|
||||
}, [currentRun.sessionId, pendingSessionId]);
|
||||
return currentRun.sessionId ?? (includePending ? pendingSessionId : null);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"use client";
|
||||
|
||||
const ACTIVE_SESSION_ID_KEY = "claw.activeSessionId";
|
||||
const PENDING_WORKSPACE_SESSION_ID_KEY = "claw.pendingWorkspaceSessionId";
|
||||
export const ACTIVE_SESSION_CHANGED_EVENT = "claw-active-session-changed";
|
||||
export const PENDING_WORKSPACE_SESSION_CHANGED_EVENT =
|
||||
"claw-pending-workspace-session-changed";
|
||||
|
||||
let pendingWorkspaceSessionId: string | null = null;
|
||||
|
||||
export function readActiveSessionId() {
|
||||
if (typeof window === "undefined") return null;
|
||||
return (
|
||||
@@ -55,8 +56,7 @@ export function writePendingWorkspaceSessionId(
|
||||
clearPendingWorkspaceSessionId();
|
||||
return;
|
||||
}
|
||||
window.sessionStorage.setItem(PENDING_WORKSPACE_SESSION_ID_KEY, normalized);
|
||||
window.localStorage.setItem(PENDING_WORKSPACE_SESSION_ID_KEY, normalized);
|
||||
pendingWorkspaceSessionId = normalized;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(PENDING_WORKSPACE_SESSION_CHANGED_EVENT, {
|
||||
detail: { sessionId: normalized },
|
||||
@@ -64,28 +64,14 @@ export function writePendingWorkspaceSessionId(
|
||||
);
|
||||
}
|
||||
|
||||
export function consumePendingWorkspaceSessionId() {
|
||||
const sessionId = readPendingWorkspaceSessionId();
|
||||
clearPendingWorkspaceSessionId();
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
export function readPendingWorkspaceSessionId() {
|
||||
if (typeof window === "undefined") return null;
|
||||
return (
|
||||
normalizeSessionId(
|
||||
window.sessionStorage.getItem(PENDING_WORKSPACE_SESSION_ID_KEY),
|
||||
) ??
|
||||
normalizeSessionId(
|
||||
window.localStorage.getItem(PENDING_WORKSPACE_SESSION_ID_KEY),
|
||||
)
|
||||
);
|
||||
return pendingWorkspaceSessionId;
|
||||
}
|
||||
|
||||
function clearPendingWorkspaceSessionId() {
|
||||
export function clearPendingWorkspaceSessionId() {
|
||||
if (typeof window === "undefined") return;
|
||||
window.sessionStorage.removeItem(PENDING_WORKSPACE_SESSION_ID_KEY);
|
||||
window.localStorage.removeItem(PENDING_WORKSPACE_SESSION_ID_KEY);
|
||||
pendingWorkspaceSessionId = null;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(PENDING_WORKSPACE_SESSION_CHANGED_EVENT, {
|
||||
detail: { sessionId: null },
|
||||
|
||||
Reference in New Issue
Block a user