Manages the dialog-history concerns for the chat panel, including archive navigation, read-only archived conversation mode, and rename/archive/restore confirmation modals — keeping `EmbeddableChat` as a thin orchestration layer. ## Key Components ### `UseChatDialogManagerArgs` Input interface wiring adapter callbacks into the manager: | Field | Type | Description | |---|---|---| | `dialogs` | `ReadonlyArray` | Active (non-archived) dialogs | | `activeDialogId` | `string \| null \| undefined` | Currently open dialog | | `selectDialog` | `(id: string \| null) => void` | Opens a dialog by id | | `clearMessages` | `() => void` | Resets active conversation | | `renameDialog` | `(id, title) => Promise` | Renames a dialog | | `archiveDialog` | `(id) => Promise` | Archives a dialog | | `fetchArchivedDialogs` | `(params) => Promise` | Optional; gates archive UI | | `unarchiveDialog` | `(id) => Promise` | Optional; gates restore UI | ### `useChatDialogManager` The primary hook. Returns a flat object of state and handlers consumed directly by the chat panel JSX. **Key return groups:** - **Archive page** — `archiveOpen`, `archivedDialogs`, `archivedCursor`, `archivedLoading`, `archivedPending`, `openArchive`, `closeArchive`, `loadArchivedPage`, `handleArchivedSelect` - **Current-chat navigation** — `handleSelectDialog`, `isOpeningDialog`, `handleBack`, `resetToNewChat`, `activeDialog` - **Archived conversation mode** — `isViewingArchived` - **Action modals** — `renameTarget`, `archiveTarget`, `restoreTarget` (+ setters), `handleConfirmRename`, `handleConfirmArchive`, `handleConfirmRestore` ## Usage Example ```typescript const dialogManager = useChatDialogManager({ dialogs, activeDialogId, selectDialog, clearMessages, renameDialog, archiveDialog, fetchArchivedDialogs, unarchiveDialog, }) // Open archive page dialogManager.openArchive() // Load next page of archived dialogs await dialogManager.loadArchivedPage(dialogManager.archivedCursor ?? undefined) // Trigger archive confirmation modal dialogManager.setArchiveTarget(someDialog) await dialogManager.handleConfirmArchive() ``` > **Note:** `loadArchivedPage` uses a monotonic request ID (`archivedRequestIdRef`) to prevent stale responses from clobbering newer results during overlapping background refresh and pagination fetches. A 120 ms skeleton delay avoids flashing the empty state on cached/fast first-page loads. ## Source [`use-chat-dialog-manager.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/use-chat-dialog-manager.ts)