feat(chat): /btw — side questions in a temporary forked session (#2796)
* feat(chat): /btw command — side questions in a temporary forked session /btw <question> forks the current session (full context inheritance) and opens a compact peek panel docked above the composer. The composer itself becomes the btw input while the panel is open: sends route to the fork, the placeholder and a mode chip reflect the target, and the stop button aborts the fork's turn. Closing the panel (or the chip's ✕) destroys the fork, leaving the main conversation untouched. The panel shows only the fork's own tail (messages at/after the fork creation time) and live permission/question cards scoped to the fork. - chat/btw/BtwPanel: peek sheet (desktop + mobile), fork-tail view, auto-close on disappearance, Esc to close - lib/btw: startBtwSession (fork + rename + routed send), closeBtwPanel (close = destroy), filterBtwTailMessages - ChatInput: btw-mode send routing via SendMessageOptions.sessionId, btw-aware activity (stop/abort), placeholder + mode chip - useSessionActivity: exported for per-session activity reads - i18n: btw keys across all 11 locales * fix(chat): keep btw sends isolated * refactor(chat): rework /btw into a metadata-scoped peek panel - Link the active btw fork through the parent session's metadata (openchamber.btwSessionID) so the panel exists only in the session that invoked /btw, follows parent navigation, and survives reloads; the fork carries a kind:'btw' marker with its originalSessionID. - Replace the wall-clock history boundary with the id of the newest cloned message (server-generated ascending ids), stored in fork metadata. - Derive panel identity in useBtwPanelState; useBtwStore shrinks to transient per-parent UI state (collapsed/creating/destroying). - Panel UX: dropdown-style glass surface, chat ScrollShadow, single title+chevron collapse toggle, muted header controls, promote action (keep as a full session and navigate to it), Esc collapses instead of destroying, reserved Working indicator row, streaming auto-follow via ResizeObserver keyed on content readiness. - Add a 'peek' chat surface mode that suppresses per-message controls and turn footers inside the panel; user bubbles keep a small gap below. - Hide btw forks from the sidebar, session switcher, and command palette until promoted; mark the fork before inserting it into local stores. - Delete/archive lifecycle: removing the fork unlinks the parent; removing the parent also removes its temporary fork. - patchSessionMetadata now mirrors updated sessions into live stores. - Localize new strings across all 12 dictionaries; add unit tests for metadata helpers, the btw flow, and the UI store. * fix(chat): clamp the btw panel below the app header when the keyboard is open Reuse useMobileAutocompleteMaxHeight (the composer autocomplete precedent) on the panel's scroll body, reserving the panel header and bottom spacer height, so the sheet adapts to the visual viewport instead of riding under the app header on mobile. * fix(lint): drop unused destructured bindings in sessionBtwMetadata CI eslint has no underscore ignore pattern; strip metadata keys with typed copies and delete instead of discard-destructuring. --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
a317a156cb
commit
46426e8495
@@ -0,0 +1,38 @@
|
||||
import { beforeEach, describe, expect, test } from 'bun:test';
|
||||
import { useBtwStore } from './useBtwStore';
|
||||
|
||||
describe('useBtwStore', () => {
|
||||
beforeEach(() => {
|
||||
useBtwStore.setState({ byParent: {} });
|
||||
});
|
||||
|
||||
test('starts empty', () => {
|
||||
expect(useBtwStore.getState().byParent).toEqual({});
|
||||
});
|
||||
|
||||
test('setPanelState merges patches per parent', () => {
|
||||
useBtwStore.getState().setPanelState('parent-1', { creating: true });
|
||||
useBtwStore.getState().setPanelState('parent-1', { collapsed: true });
|
||||
expect(useBtwStore.getState().byParent['parent-1']).toEqual({ creating: true, collapsed: true });
|
||||
});
|
||||
|
||||
test('parents are independent', () => {
|
||||
useBtwStore.getState().setPanelState('parent-1', { collapsed: true });
|
||||
useBtwStore.getState().setPanelState('parent-2', { destroying: true });
|
||||
expect(useBtwStore.getState().byParent['parent-1']).toEqual({ collapsed: true });
|
||||
expect(useBtwStore.getState().byParent['parent-2']).toEqual({ destroying: true });
|
||||
});
|
||||
|
||||
test('clearPanelState removes only its parent entry', () => {
|
||||
useBtwStore.getState().setPanelState('parent-1', { collapsed: true });
|
||||
useBtwStore.getState().setPanelState('parent-2', { collapsed: true });
|
||||
useBtwStore.getState().clearPanelState('parent-1');
|
||||
expect(useBtwStore.getState().byParent).toEqual({ 'parent-2': { collapsed: true } });
|
||||
});
|
||||
|
||||
test('clearPanelState on an unknown parent is a no-op', () => {
|
||||
const before = useBtwStore.getState().byParent;
|
||||
useBtwStore.getState().clearPanelState('missing');
|
||||
expect(useBtwStore.getState().byParent).toBe(before);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
/**
|
||||
* UI-only state for the `/btw` peek panel.
|
||||
*
|
||||
* The panel's identity is NOT stored here: it is derived from session
|
||||
* metadata (`openchamber.btwSessionID` on the parent — see
|
||||
* `sessionBtwMetadata`), so the panel appears only in the session `/btw` was
|
||||
* typed into and survives reloads. This store keeps only transient
|
||||
* per-parent presentation state that has no authoritative home:
|
||||
*
|
||||
* - `collapsed`: the panel is minimized to the composer chip; the composer
|
||||
* talks to the main session again until it is expanded.
|
||||
* - `creating`: `/btw` is between submit and the parent-metadata link
|
||||
* landing, so the panel can show its starting state immediately.
|
||||
* - `destroying`: close was clicked; hides the panel optimistically while the
|
||||
* unlink/delete round-trip completes.
|
||||
*/
|
||||
type BtwPanelUIState = {
|
||||
collapsed?: boolean;
|
||||
creating?: boolean;
|
||||
destroying?: boolean;
|
||||
};
|
||||
|
||||
type BtwStore = {
|
||||
byParent: Record<string, BtwPanelUIState>;
|
||||
setPanelState: (parentSessionId: string, patch: BtwPanelUIState) => void;
|
||||
clearPanelState: (parentSessionId: string) => void;
|
||||
};
|
||||
|
||||
export const useBtwStore = create<BtwStore>()((set) => ({
|
||||
byParent: {},
|
||||
setPanelState: (parentSessionId, patch) =>
|
||||
set((state) => ({
|
||||
byParent: {
|
||||
...state.byParent,
|
||||
[parentSessionId]: { ...state.byParent[parentSessionId], ...patch },
|
||||
},
|
||||
})),
|
||||
clearPanelState: (parentSessionId) =>
|
||||
set((state) => {
|
||||
if (!(parentSessionId in state.byParent)) return state;
|
||||
const byParent = { ...state.byParent };
|
||||
delete byParent[parentSessionId];
|
||||
return { byParent };
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user