openclaw/apps/web/app/workspace/workspace-switch.ts
kumarabhirup 7dd38c185c
refactor(workspace): rename replaceUrlToWorkspace to replaceUrlToRoot
URL sync is now handled by the centralized effect, not callers.
2026-03-05 22:54:18 -08:00

37 lines
1.2 KiB
TypeScript

type WorkspaceEmptyContent = { kind: "none" };
type WorkspaceSwitchDeps = {
setBrowseDir: (dir: string | null) => void;
setActivePath: (path: string | null) => void;
setContent: (content: WorkspaceEmptyContent) => void;
setChatSidebarPreview: (preview: null) => void;
setShowChatSidebar: (show: boolean) => void;
setActiveSessionId: (sessionId: string | null) => void;
setActiveSubagentKey: (sessionKey: string | null) => void;
resetMainChat: () => void;
replaceUrlToRoot: () => void;
reconnectWorkspaceWatcher: () => void;
refreshSessions: () => void;
refreshContext: () => void;
};
/**
* Keep workspace switching deterministic:
* clear file/chat selection first, then force a fresh chat session so
* subsequent messages cannot reuse the prior workspace's session key.
*/
export function resetWorkspaceStateOnSwitch(deps: WorkspaceSwitchDeps): void {
deps.setBrowseDir(null);
deps.setActivePath(null);
deps.setContent({ kind: "none" });
deps.setChatSidebarPreview(null);
deps.setShowChatSidebar(true);
deps.setActiveSessionId(null);
deps.setActiveSubagentKey(null);
deps.resetMainChat();
deps.replaceUrlToRoot();
deps.reconnectWorkspaceWatcher();
deps.refreshSessions();
deps.refreshContext();
}