Skip to content

refactor(dashboard): unify AI chat surfaces on assistant-ui Thread#1427

Open
mantrakp04 wants to merge 7 commits into
refactor/data-grid-and-dashboard-surfacesfrom
refactor/assistant-ui-chat-surfaces
Open

refactor(dashboard): unify AI chat surfaces on assistant-ui Thread#1427
mantrakp04 wants to merge 7 commits into
refactor/data-grid-and-dashboard-surfacesfrom
refactor/assistant-ui-chat-surfaces

Conversation

@mantrakp04
Copy link
Copy Markdown
Collaborator

@mantrakp04 mantrakp04 commented May 12, 2026

Summary

  • Replace the bespoke ai-chat-shared chat UI (used by ask-ai, the stack companion widget, vibe coding chat, and the create-dashboard preview) with the shared assistant-ui Thread component.
  • Extract streaming request/format helpers into a new components/assistant-ui/chat-stream.ts module so each surface only owns its ChatModelAdapter.
  • Add a reusable ToolFallback for tool-call rendering and delete the now-unused ai-chat-shared.tsx (-1386 / +747 lines net).

Stacked on top of refactor/data-grid-and-dashboard-surfaces.

Base: refactor/data-grid-and-dashboard-surfaces → Head: refactor/assistant-ui-chat-surfaces · 18 files changed

Red outlines on the after shots mark the unified assistant-ui Thread surface in each location.

Screenshots

Analytics → Tables — AI Query dialog

Before After
Light
Dark

Stack Companion — chat widget

Before After
Light
Dark

Ask-AI command palette (⌘K → Ask AI)

Before After
Light
Dark

Email editor — embedded chat panel

Before After
Light
Dark

Notes for reviewers

The four surfaces above all previously shared components/commands/ai-chat-shared.tsx (516 lines, deleted). After this PR they each own a thin ChatModelAdapter and render through components/assistant-ui/thread.tsx + the new chat-stream.ts helpers. Visual differences between before and after are intentional — the assistant-ui Thread brings its own message bubbles, scroll-to-bottom behaviour, composer, and ToolFallback rendering. The email editor's chat panel is the surface where the behaviour change is most visible (tool-call rendering now consistent with the rest of the app).

Heaviest changes (lines):

  • components/stack-companion/ai-chat-widget.tsx (571)
  • components/commands/ai-chat-shared.tsx (516, deleted)
  • analytics/tables/ai-query-dialog.tsx (429)
  • components/vibe-coding/chat-adapters.ts (400)
  • components/assistant-ui/chat-stream.ts (284, new)
  • components/commands/ask-ai.tsx (274)
  • components/assistant-ui/thread.tsx (115)
  • components/assistant-ui/tool-fallback.tsx (113)

Test plan

  • pnpm lint
  • pnpm typecheck
  • Manually exercise each affected surface: command-center Ask AI, stack-companion widget, vibe-coding chat, analytics tables AI query, create-dashboard preview, email editor chat.
  • Verify tool-call chips render consistently across all four surfaces (uses the new ToolFallback).
  • Verify streaming + cancel works on each adapter (chat-stream.ts is shared).

Replaces the bespoke ai-chat-shared chat UI used by ask-ai, the stack
companion widget, vibe coding chat, and the create-dashboard preview
with the shared assistant-ui Thread component. Extracts the streaming
request/format helpers into a new chat-stream module and the tool call
UI into a reusable ToolFallback.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-auth-mcp Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-backend Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-dashboard Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-demo Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-docs Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-preview-backend Ready Ready Preview, Comment May 14, 2026 6:40pm
stack-preview-dashboard Ready Ready Preview, Comment May 14, 2026 6:40pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 098b5912-5b33-4803-8c9a-0e0ba5c6f149

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/assistant-ui-chat-surfaces

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 12, 2026

Greptile Summary

This PR replaces four separate bespoke chat UIs (ask-ai, stack-companion widget, vibe-coding chat, analytics query dialog) with the shared assistant-ui Thread component, and extracts streaming/formatting helpers into a new components/assistant-ui/chat-stream.ts module. The net result is −1386/+747 lines with consistent rendering, scroll management, and error handling across all surfaces.

  • chat-stream.ts centralises sendAiStreamRequest, formatThreadMessagesForBackend, uiPartsToChatContent, createUnifiedAiTransport, and createUnifiedAiChatAdapter; parse failures now call captureError instead of being silently dropped.
  • thread.tsx gains welcome, assistantContentComponents, and autoFocusComposer props; per-surface background and gradient logic is removed in favour of a transparent root.
  • use-ai-query-chat.ts migrates from useChat+DefaultChatTransport to useLocalThreadRuntime+createAnalyticsQueryChatAdapter, with manual runtime.thread.subscribe bridging thread state to React.

Confidence Score: 5/5

Safe to merge; the refactoring is largely mechanical and well-tested with no data-integrity or auth regressions.

The streaming and formatting helpers are cleanly extracted and the previous silent-parse-drop bug is now fixed with captureError. The migration from useChat to useLocalRuntime/useLocalThreadRuntime is consistent across surfaces, tests cover the updated extractLatestQuery logic, and backward-compatible deserialization of legacy stored messages is handled. New findings are limited to the dropped onBlur keyboard shortcut in the command-palette ask-ai panel and the semantically mismatched DatabaseIcon used as the generic tool fallback icon.

The three email page clients (email-drafts, email-templates, email-themes) each set composerAttachments without providing an attachmentAdapter, which was flagged in the previous review and remains unresolved.

Important Files Changed

Filename Overview
apps/dashboard/src/components/assistant-ui/chat-stream.ts New module centralizing AI streaming helpers. Parse failures now call captureError. Callers passing a plain currentUser value (not a getter) freeze the user at adapter creation time.
apps/dashboard/src/components/assistant-ui/thread.tsx Adds welcome, assistantContentComponents, and autoFocusComposer props. Removes per-surface background and gradient logic in favour of a transparent root.
apps/dashboard/src/components/assistant-ui/tool-fallback.tsx New reusable collapsible tool-call card. Hardcodes DatabaseIcon for all tool names, which is semantically wrong for non-database tools like docs.
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/analytics/tables/use-ai-query-chat.ts Migrated from useChat to useLocalThreadRuntime. currentUser is a plain value in useMemo deps, so every token refresh rebuilds the adapter and potentially resets the conversation.
apps/dashboard/src/components/commands/ask-ai.tsx Replaces bespoke chat UI with Thread + useLocalRuntime. The onBlur prop from CmdKPreviewProps is no longer wired, removing the ArrowLeft keyboard shortcut to return focus to the command palette.
apps/dashboard/src/components/stack-companion/ai-chat-widget.tsx Large simplification removing bespoke scroll/input management. storedMessagesToThreadMessages handles backward-compatible deserialization of legacy message formats. pendingMessagesRef save-queue logic is preserved correctly.
apps/dashboard/src/components/vibe-coding/chat-adapters.ts Removes ~200 lines of duplicated streaming/formatting helpers now in chat-stream.ts. Adds createAnalyticsQueryChatAdapter.
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/analytics/tables/ai-query-dialog.tsx Replaces manual message rendering with AssistantRuntimeProvider + Thread. Adds editable Textarea for the current query draft with Cmd+Enter and on-blur apply.
apps/dashboard/src/app/(main)/(protected)/projects/[projectId]/email-drafts/[draftId]/page-client.tsx Adds composerAttachments without a corresponding attachmentAdapter. Same pattern in email-templates and email-themes.
apps/dashboard/src/components/commands/ai-chat-shared.tsx Deleted (-558 lines). All helpers replaced by chat-stream.ts, thread.tsx, tool-fallback.tsx, and markdown-text.tsx.

Fix All in Claude Code Fix All in Cursor Fix All in Codex

Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/dashboard/src/components/commands/ask-ai.tsx:96-103
**`onBlur` keyboard-navigation prop is silently dropped**

`CmdKPreviewProps` includes an `onBlur` callback that the old implementation invoked when the user pressed `ArrowLeft` at position 0 in the follow-up input, returning keyboard focus to the command-palette search bar. `AIChatPreviewInner` now ignores this prop entirely — it's spread into the component via `...rest` but never destructured or forwarded to the `Thread` composer. Users relying on the ArrowLeft shortcut to navigate back to the command palette will find it no longer works.

### Issue 2 of 2
apps/dashboard/src/components/assistant-ui/tool-fallback.tsx:52-53
**`DatabaseIcon` used for all tool types regardless of semantics**

The fallback icon is `DatabaseIcon` for every tool call, including the `docs` tool used by the ask-ai and stack-companion surfaces. When the backend calls `docs` to retrieve documentation, users see a database icon and the label "docs" — which is confusing. Consider mapping `docs` to a document/book icon, or using a more neutral icon (e.g. `CpuIcon` / `SparkleIcon`) as the default.

Reviews (4): Last reviewed commit: "Refactor AIChatPreview component to util..." | Re-trigger Greptile

Comment thread apps/dashboard/src/components/assistant-ui/chat-stream.ts
Comment thread apps/dashboard/src/components/stack-companion/ai-chat-widget.tsx
Comment thread apps/dashboard/src/components/stack-companion/ai-chat-widget.tsx
Comment thread apps/dashboard/src/components/stack-companion/ai-chat-widget.tsx
Comment thread apps/dashboard/src/components/stack-companion/ai-chat-widget.tsx
Comment thread apps/dashboard/src/components/assistant-ui/chat-stream.ts
Comment thread apps/dashboard/src/components/assistant-ui/chat-stream.ts
…nd theme components

- Introduced the `composerAttachments` prop in the `EmailDraftUI`, `EmailTemplateUI`, and `EmailThemeUI` components to enhance functionality and support attachment features in email creation.
- Updated the AI query dialog to include new components such as `MarkdownText`, `Thread`, and `ToolFallback` for improved user interaction.
- Refactored the chat handling logic to utilize `ThreadMessage` for better message structure and processing.
- Replaced the `setMessages` method with `clearMessages` for more intuitive chat management.
- Enhanced test cases to accommodate the new message structure and ensure robust functionality.

These changes streamline the AI query experience and improve the overall user interface in the analytics section.
- Added error capturing for parsing failures in the AI chat stream to improve debugging and error tracking.
- Updated the AI chat widget to generate a unique tool call ID using `crypto.randomUUID()` when none is provided, ensuring each tool call is uniquely identifiable.

These changes improve the robustness of the chat functionality and enhance error visibility.
Comment thread apps/dashboard/src/components/commands/ask-ai.tsx Outdated
- Updated the AIChatPreview component to accept the query prop directly, enhancing its functionality by using it as a key for the inner component.
- This change improves the component's performance and ensures that the correct query is passed down to the AIChatPreviewInner.
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