ohbaby-cli 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4566,6 +4566,7 @@ function OhbabyTerminalApp({
4566
4566
  const catalogRequestSequenceRef = useRef(0);
4567
4567
  const contextRefreshSequenceRef = useRef(0);
4568
4568
  const contextNoticeSequenceRef = useRef(0);
4569
+ const snapshotRefreshSequenceRef = useRef(0);
4569
4570
  const didClearOnStartRef = useRef(false);
4570
4571
  const disposedRef = useRef(false);
4571
4572
  const [screenGeneration, setScreenGeneration] = useState(0);
@@ -4864,11 +4865,24 @@ function OhbabyTerminalApp({
4864
4865
  return;
4865
4866
  }
4866
4867
  eventDispatcher.dispatch(tuiEvent);
4867
- if (isNewSessionSelectionEvent(tuiEvent)) {
4868
+ const isNewSessionSelection = isNewSessionSelectionEvent(tuiEvent);
4869
+ if (isNewSessionSelection) {
4870
+ snapshotRefreshSequenceRef.current += 1;
4868
4871
  writeStdout(NEW_SESSION_CLEAR_SEQUENCE);
4869
4872
  setScreenGeneration((current) => current + 1);
4870
4873
  setActiveCommandPanel(null);
4871
4874
  }
4875
+ const selectedExistingSessionId = selectedExistingSessionIdFromEvent(tuiEvent);
4876
+ if (selectedExistingSessionId !== void 0) {
4877
+ const requestSequence2 = snapshotRefreshSequenceRef.current + 1;
4878
+ snapshotRefreshSequenceRef.current = requestSequence2;
4879
+ void client.getSnapshot().then((snapshot) => {
4880
+ if (disposedRef.current || requestSequence2 !== snapshotRefreshSequenceRef.current || snapshot.activeSessionId !== selectedExistingSessionId) {
4881
+ return;
4882
+ }
4883
+ store.replaceSnapshot(snapshot);
4884
+ }).catch(() => void 0);
4885
+ }
4872
4886
  if (tuiEvent.type === "command.result.delivered" && tuiEvent.action?.kind === "app.exit") {
4873
4887
  exit();
4874
4888
  }
@@ -4876,12 +4890,14 @@ function OhbabyTerminalApp({
4876
4890
  void loadCatalog().catch(() => void 0);
4877
4891
  }
4878
4892
  });
4893
+ const requestSequence = snapshotRefreshSequenceRef.current + 1;
4894
+ snapshotRefreshSequenceRef.current = requestSequence;
4879
4895
  void client.getSnapshot().then((snapshot) => {
4880
- if (!disposedRef.current) {
4896
+ if (!disposedRef.current && requestSequence === snapshotRefreshSequenceRef.current) {
4881
4897
  store.replaceSnapshot(snapshot);
4882
4898
  }
4883
4899
  }).catch((caught) => {
4884
- if (!disposedRef.current) {
4900
+ if (!disposedRef.current && requestSequence === snapshotRefreshSequenceRef.current) {
4885
4901
  store.dispatch({
4886
4902
  status: {
4887
4903
  kind: "error",
@@ -5062,6 +5078,17 @@ function isNewSessionSelectionEvent(tuiEvent) {
5062
5078
  const data = tuiEvent.action.data;
5063
5079
  return isStringRecord(data) && data.source === "new";
5064
5080
  }
5081
+ function selectedExistingSessionIdFromEvent(tuiEvent) {
5082
+ if (tuiEvent.type !== "command.result.delivered" || tuiEvent.action?.kind !== "session.selected") {
5083
+ return void 0;
5084
+ }
5085
+ const data = tuiEvent.action.data;
5086
+ if (!isStringRecord(data) || data.source === "new") {
5087
+ return void 0;
5088
+ }
5089
+ const choiceId = data.choiceId;
5090
+ return typeof choiceId === "string" && choiceId.length > 0 ? choiceId : void 0;
5091
+ }
5065
5092
  function isStringRecord(value) {
5066
5093
  return typeof value === "object" && value !== null && !Array.isArray(value);
5067
5094
  }