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