feat: support per-bot workspace switching

This commit is contained in:
xmanrui 2026-08-17 23:56:27 +08:00
parent adcace3512
commit 44dd50216a
64 changed files with 3878 additions and 712 deletions

View file

@ -0,0 +1,28 @@
import * as React from 'react';
/** Keep every full-snapshot response ordered behind the latest client mutation. */
export function useWorkspaceSnapshotFence() {
const state = React.useRef({ version: 0, pendingMutations: 0 });
return React.useMemo(() => Object.freeze({
beginStatus() {
return state.current.pendingMutations === 0 ? state.current.version : null;
},
canCommitStatus(version) {
return version !== null
&& state.current.pendingMutations === 0
&& state.current.version === version;
},
beginMutation() {
state.current.pendingMutations += 1;
state.current.version += 1;
return state.current.version;
},
canCommitMutation(version) {
return state.current.version === version;
},
endMutation() {
state.current.pendingMutations = Math.max(0, state.current.pendingMutations - 1);
return state.current.pendingMutations === 0;
},
}), []);
}