Skip to content

feat: Add chat history - #698

Merged
dmitriy-kostianetskiy merged 4 commits into
mainfrom
feat/ai-chart-refactoring
Jun 9, 2026
Merged

dmitriy-kostianetskiy merged 4 commits into
mainfrom
feat/ai-chart-refactoring

Conversation

@dmitriy-kostianetskiy

@dmitriy-kostianetskiy dmitriy-kostianetskiy commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Browse a Chat History view to see, select, and switch between past sessions.
    • Header includes a History button and displays the current session name; “New session” remains available when none.
    • Rename and delete sessions (inline or via dialogs), with contextual confirmation and immediate delete for empty sessions.
    • Session list shows message counts, last-opened times, and message previews; empty state offers a CTA to create the first chat.
    • Loading skeleton shown while chat data is being fetched.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 42219aeb-4c5a-4f18-91c0-6a07f53b654e

📥 Commits

Reviewing files that changed from the base of the PR and between af97534 and 969ae38.

📒 Files selected for processing (1)
  • packages/ai-core/src/components/ChatHistoryItem.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/ai-core/src/components/ChatHistoryItem.tsx

📝 Walkthrough

Walkthrough

Adds an in-chat session history UI: new ChatHeader, ChatHistoryView, SessionActionsMenu, and ChatHistoryItem components; exposes Header and History on the Chat compound; and wires a showHistory toggle in AssistantChatContainer to switch between messages and the history view.

Changes

Chat Session History Navigation

Layer / File(s) Summary
Extend Chat compound component
packages/ai-core/src/components/Chat.tsx
The Chat compound component now exposes Header and History static subcomponents and updates the ChatComponent type accordingly.
Session actions dropdown menu
packages/ai-core/src/components/SessionActionsMenu.tsx
Adds SessionActionsMenu, a tooltip-wrapped dropdown trigger with Rename and Delete menu items that call parent callbacks.
History list item UI and interactions
packages/ai-core/src/components/ChatHistoryItem.tsx
ChatHistoryItem renders a session row with name, message count, relative last-opened time, preview text, hover-revealed inline rename/delete buttons, and click/keyboard activation handling.
Session history list and management
packages/ai-core/src/components/ChatHistoryView.tsx
ChatHistoryView renders the History screen with back navigation, sorted session list, empty-state create-first-session CTA, rename/delete dialogs, and store-backed session actions.
Chat header with session controls
packages/ai-core/src/components/ChatHeader.tsx
ChatHeader shows a History button, current session name, session actions menu, and New session button; wires rename/delete dialogs to store actions.
Container history toggle and routing
apps/sqlrooms-cli-ui/src/components/AssistantChatContainer.tsx
AssistantChatContainer adds showHistory state and conditionally renders Chat.Header, Chat.History, or the main messages area, switching sessions via the AI store.

Sequence Diagram

sequenceDiagram
  participant User
  participant AssistantChatContainer
  participant ChatHeader
  participant ChatHistoryView
  participant SessionActionsMenu
  participant AIStore

  User->>AssistantChatContainer: Open chat
  AssistantChatContainer->>ChatHeader: Render header (when session exists)
  User->>ChatHeader: Click History button
  ChatHeader->>AssistantChatContainer: set showHistory = true
  AssistantChatContainer->>ChatHistoryView: Render history view
  User->>ChatHistoryView: Click session row
  ChatHistoryView->>AIStore: switchSession(sessionId)
  AIStore->>AssistantChatContainer: active session updated
  User->>ChatHistoryView: Open actions on a session
  ChatHistoryView->>SessionActionsMenu: trigger menu
  User->>SessionActionsMenu: Select Rename or Delete
  SessionActionsMenu->>AIStore: renameSession / deleteSession
  AIStore->>ChatHistoryView: sessions list updated
  User->>ChatHeader: Click back
  ChatHeader->>AssistantChatContainer: set showHistory = false
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#628: Both PRs modify packages/ai-core/src/components/Chat.tsx to extend the Chat compound component API via ChatComponent/Object.assign.

Suggested reviewers

  • ilyabo
  • lixun910

Poem

🐰 In carrot code I hop and write,

History lists gleam in morning light,
Rename, delete with gentle cheer,
Hop back to chat — the view is clear,
A tiny rabbit celebrates the merge!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Add chat history' clearly and concisely summarizes the main change—adding chat history functionality—which is supported by the addition of multiple new components (ChatHeader, ChatHistoryView, ChatHistoryItem, SessionActionsMenu) and modifications to AssistantChatContainer and Chat.tsx.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ai-chart-refactoring

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/sqlrooms-cli-ui/src/components/AssistantChatContainer.tsx`:
- Line 4: The component AssistantChatContainer leaves the showHistory boolean
true when all sessions are removed, so creating a new session can mistakenly
show History; update the AssistantChatContainer to explicitly set showHistory =
false whenever the sessions list becomes empty and also clear showHistory right
before creating a new session. Concretely, add a useEffect watching the sessions
array (or sessions.length) to call setShowHistory(false) when it transitions to
zero, and also call setShowHistory(false) at the start of the createNewSession /
handleCreateSession function to ensure the new session opens in chat view.

In `@packages/ai-core/src/components/ChatHeader.tsx`:
- Around line 103-105: The icon-only "new session" Button in ChatHeader (the
Button with onClick={handleCreateSession} containing PlusIcon) lacks an
accessible name — add an explicit accessible label (e.g., aria-label="New
session" or include visually-hidden text inside the Button) so screen readers
can announce the control; ensure the label is descriptive and keep the existing
onClick and PlusIcon intact.

In `@packages/ai-core/src/components/ChatHistoryView.tsx`:
- Around line 81-102: The icon-only action buttons (the Button components
wrapping PencilIcon and TrashIcon used in the rename and delete handlers, and
the similar back-button at lines referenced) lack accessible names; update those
Button usages (the ones with onClick calling onRename/onDelete and the back
button component) to include proper accessible labeling by adding aria-label
attributes or an aria-labelledby reference (e.g., aria-label="Rename chat" and
aria-label="Delete chat" / "Back") or by including visually hidden text inside
the button; keep the existing onClick handlers (onRename/onDelete) and icon
children unchanged while ensuring screen readers receive the descriptive labels.
- Around line 49-59: The session row is rendered as a plain div, which prevents
keyboard users from focusing and activating it; update the element in
ChatHistoryView (the session row rendering that currently uses the div with
className, onClick, onMouseEnter, onMouseLeave and isActive logic) to be a
semantic interactive element—preferably a <button type="button">—so it is
focusable and keyboard-activatable, keep the existing className and event
handlers, ensure any visual focus styles remain intact, and if you cannot use a
button instead add role="button", tabIndex={0}, and key handlers (Enter/Space)
to the same component to provide equivalent keyboard accessibility.

In `@packages/ai-core/src/components/SessionActionsMenu.tsx`:
- Around line 23-25: The menu trigger Button in the SessionActionsMenu component
renders only an icon (MoreVertical) with no accessible name; update the Button
(the icon-only trigger) to include an accessible label such as adding an
aria-label="Open session actions" or aria-label prop that describes its purpose
(or include visually hidden text inside the Button) so assistive technologies
can identify the control; target the Button element that wraps MoreVertical in
SessionActionsMenu and ensure the label is concise and descriptive.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0103f29d-7a89-4093-ab5e-90d8a62946ae

📥 Commits

Reviewing files that changed from the base of the PR and between e59f9b4 and f8d4c31.

📒 Files selected for processing (5)
  • apps/sqlrooms-cli-ui/src/components/AssistantChatContainer.tsx
  • packages/ai-core/src/components/Chat.tsx
  • packages/ai-core/src/components/ChatHeader.tsx
  • packages/ai-core/src/components/ChatHistoryView.tsx
  • packages/ai-core/src/components/SessionActionsMenu.tsx

import {Button, SkeletonPane} from '@sqlrooms/ui';
import {PlusIcon} from 'lucide-react';
import React from 'react';
import React, {useState} from 'react';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reset showHistory when session list becomes empty (or before creating a new one).

showHistory can remain true after sessions are removed, so creating a new session from the empty-state can route users back to History instead of the chat view.

Suggested fix
-import React, {useState} from 'react';
+import React, {useEffect, useState} from 'react';
...
   const [showHistory, setShowHistory] = useState(false);
+
+  useEffect(() => {
+    if (!currentSessionId) {
+      setShowHistory(false);
+    }
+  }, [currentSessionId]);
...
               onClick={() => createSession()}
+              onClick={() => {
+                setShowHistory(false);
+                createSession();
+              }}

Also applies to: 26-27, 31-38

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/sqlrooms-cli-ui/src/components/AssistantChatContainer.tsx` at line 4,
The component AssistantChatContainer leaves the showHistory boolean true when
all sessions are removed, so creating a new session can mistakenly show History;
update the AssistantChatContainer to explicitly set showHistory = false whenever
the sessions list becomes empty and also clear showHistory right before creating
a new session. Concretely, add a useEffect watching the sessions array (or
sessions.length) to call setShowHistory(false) when it transitions to zero, and
also call setShowHistory(false) at the start of the createNewSession /
handleCreateSession function to ensure the new session opens in chat view.

Comment thread packages/ai-core/src/components/ChatHeader.tsx Outdated
Comment thread packages/ai-core/src/components/ChatHistoryView.tsx Outdated
Comment thread packages/ai-core/src/components/ChatHistoryView.tsx Outdated
Comment thread packages/ai-core/src/components/SessionActionsMenu.tsx Outdated
@ilyabo

ilyabo commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

maybe name the PR "Add chat history" to be more concrete?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ai-core/src/components/ChatHistoryItem.tsx`:
- Around line 41-52: The wrapper in ChatHistoryItem is a native <button> (the
group container) but the internal `@sqlrooms/ui` Button components render native
buttons by default, causing nested interactive elements; update the internal
Button usages inside ChatHistoryItem to render as non-button children by passing
asChild={true} (or the library's equivalent prop) so they don't emit a second
<button>, or alternatively change the outer wrapper to a non-button element with
role="button" and keyboard handlers; target the ChatHistoryItem component and
modify the inner Button component instances (or the wrapper element) accordingly
to eliminate nested <button> elements.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1028e88-917a-47b4-a354-d5ca5e36f139

📥 Commits

Reviewing files that changed from the base of the PR and between f8d4c31 and af97534.

📒 Files selected for processing (4)
  • packages/ai-core/src/components/ChatHeader.tsx
  • packages/ai-core/src/components/ChatHistoryItem.tsx
  • packages/ai-core/src/components/ChatHistoryView.tsx
  • packages/ai-core/src/components/SessionActionsMenu.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ai-core/src/components/SessionActionsMenu.tsx
  • packages/ai-core/src/components/ChatHeader.tsx

Comment thread packages/ai-core/src/components/ChatHistoryItem.tsx Outdated
@dmitriy-kostianetskiy dmitriy-kostianetskiy changed the title feat: redesign chat components feat: Add chat history Jun 9, 2026
@dmitriy-kostianetskiy
dmitriy-kostianetskiy merged commit ba95750 into main Jun 9, 2026
4 checks passed
@dmitriy-kostianetskiy
dmitriy-kostianetskiy deleted the feat/ai-chart-refactoring branch June 9, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants