Share pending workspace id across frontend chunks

This commit is contained in:
wuyang6
2026-05-13 17:38:50 +08:00
parent cdbc7d9fb7
commit 9a32b92ea5
+8 -4
View File
@@ -5,7 +5,11 @@ 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; declare global {
interface Window {
__clawPendingWorkspaceSessionId?: string | null;
}
}
export function readActiveSessionId() { export function readActiveSessionId() {
if (typeof window === "undefined") return null; if (typeof window === "undefined") return null;
@@ -56,7 +60,7 @@ export function writePendingWorkspaceSessionId(
clearPendingWorkspaceSessionId(); clearPendingWorkspaceSessionId();
return; return;
} }
pendingWorkspaceSessionId = normalized; window.__clawPendingWorkspaceSessionId = 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 },
@@ -66,12 +70,12 @@ export function writePendingWorkspaceSessionId(
export function readPendingWorkspaceSessionId() { export function readPendingWorkspaceSessionId() {
if (typeof window === "undefined") return null; if (typeof window === "undefined") return null;
return pendingWorkspaceSessionId; return normalizeSessionId(window.__clawPendingWorkspaceSessionId);
} }
export function clearPendingWorkspaceSessionId() { export function clearPendingWorkspaceSessionId() {
if (typeof window === "undefined") return; if (typeof window === "undefined") return;
pendingWorkspaceSessionId = null; window.__clawPendingWorkspaceSessionId = null;
window.dispatchEvent( window.dispatchEvent(
new CustomEvent(PENDING_WORKSPACE_SESSION_CHANGED_EVENT, { new CustomEvent(PENDING_WORKSPACE_SESSION_CHANGED_EVENT, {
detail: { sessionId: null }, detail: { sessionId: null },