Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughIntroduces variant-based styling for MessageContent; adds a new MessagePart component to render assistant message parts; removes the previous assistant message renderer; refactors Messages to render per-part with streaming state passed down. Public APIs change for MessageContent and Messages; PreviewMessage export is removed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Messages as Messages (list)
participant Message as Message (item)
participant Part as MessagePart
participant UI as Reasoning/Response/ToolCard
participant Error as ErrorToolCard
User->>Messages: View conversation (status, messages)
loop For each message
Messages->>Message: Render with from=role
alt message has parts
loop For each part
Messages->>Part: Render({ part, isStreaming, messageId, partIndex })
alt part.type == reasoning
Part->>UI: ReasoningTrigger/ReasoningContent (stream-aware)
else part.type == text and part.text
Part->>UI: Response
else part.type starts with tool-*
alt output has error
Part->>Error: Render error message
else input/output available
Part->>UI: Render corresponding Tool UI
end
else
Part-->>Message: null
end
end
else
Message-->>Messages: No parts
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (4)
apps/web/components/ai-elements/message.tsx (1)
22-24: Stray/invalid Tailwind token.
is-user:darkhas no utility after the colon; it compiles to a dead class. Remove it.-const messageContentVariants = cva( - "is-user:dark flex flex-col gap-2 overflow-hidden rounded-lg text-sm", +const messageContentVariants = cva( + "flex flex-col gap-2 overflow-hidden rounded-lg text-sm",apps/web/components/assistant-chat/message-part.tsx (3)
27-29: Use semantic color token for errors.Prefer theme-aligned
text-destructiveover a hard-coded red for consistency with shadcn/ui.-function ErrorToolCard({ error }: { error: string }) { - return <div className="rounded border p-2 text-red-500">Error: {error}</div>; -} +function ErrorToolCard({ error }: { error: string }) { + return <div className="rounded border p-2 text-destructive">Error: {error}</div>; +}
39-45: Reduce duplication in tool rendering.The repeated input/output/error branches per tool inflate maintenance cost. Consider a small dispatcher + helpers to DRY this up.
Example sketch:
- if (part.type === "tool-getUserRulesAndSettings") { ... } - if (part.type === "tool-getLearnedPatterns") { ... } + const renderers = { + "tool-getUserRulesAndSettings": () => ({ input: <BasicToolInfo text="Reading rules and settings..." />, output: <BasicToolInfo text="Read rules and settings" /> }), + "tool-getLearnedPatterns": () => ({ input: <BasicToolInfo text="Reading learned patterns..." />, output: <BasicToolInfo text="Read learned patterns" /> }), + "tool-createRule": () => ({ + input: <BasicToolInfo text={`Creating rule "${part.input.name}"...`} />, + output: <CreatedRuleToolCard args={part.input} ruleId={part.output.ruleId} />, + }), + // ...others + } as const; + + const renderTool = renderers[part.type as keyof typeof renderers]; + if (renderTool) { + const { input, output } = renderTool(); + if (part.state === "input-available") return input; + if (part.state === "output-available") { + if ("error" in part.output) return <ErrorToolCard error={String(part.output.error)} />; + return output; + } + }Also applies to: 53-218
37-45: Unnecessary key props inside returned elements.This component itself is already keyed by the parent list. Keys on the single returned root elements don’t add value and can cause unintended remounts if they change.
Also applies to: 58-67, 74-83, 96-107, 115-134, 142-161, 169-187, 193-201, 207-217
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/web/components/ai-elements/message.tsx(3 hunks)apps/web/components/assistant-chat/message-part.tsx(1 hunks)apps/web/components/assistant-chat/message.tsx(0 hunks)apps/web/components/assistant-chat/messages.tsx(2 hunks)
💤 Files with no reviewable changes (1)
- apps/web/components/assistant-chat/message.tsx
🧰 Additional context used
📓 Path-based instructions (11)
apps/web/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use@/for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
apps/web/**/*.tsx
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.tsx: Follow tailwindcss patterns with prettier-plugin-tailwindcss
Prefer functional components with hooks
Use shadcn/ui components when available
Ensure responsive design with mobile-first approach
Follow consistent naming conventions (PascalCase for components)
Use LoadingContent component for async data
Useresult?.serverErrorwithtoastErrorandtoastSuccess
UseLoadingContentcomponent to handle loading and error states consistently
Passloading,error, and children props toLoadingContent
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
apps/web/components/**/*.tsx
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
Use React Hook Form with Zod validation for form handling
Use the
LoadingContentcomponent to handle loading and error states consistently in data-fetching components.Use PascalCase for components (e.g.
components/Button.tsx)
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
!{.cursor/rules/*.mdc}
📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.tsx: Use React Hook Form with Zod for validation
Validate form inputs before submission
Show validation errors inline next to form fields
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
**/*.{ts,tsx}: UsecreateScopedLoggerfor logging in backend TypeScript files
Typically add the logger initialization at the top of the file when usingcreateScopedLogger
Only use.with()on a logger instance within a specific function, not for a global loggerImport Prisma in the project using
import prisma from "@/utils/prisma";
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
apps/web/components/!(ui)/**
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
All other components are in
components/
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{js,jsx,ts,tsx}: Don't useelements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
!pages/_document.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{jsx,tsx}: Don't destructure props inside JSX components in Solid projects.
Don't use both children and dangerouslySetInnerHTML props on the same element.
Don't use Array index in keys.
Don't assign to React component props.
Don't define React components inside other components.
Don't use event handlers on non-interactive elements.
Don't assign JSX properties multiple times.
Don't add extra closing tags for components without children.
Use <>...</> instead of ....
Don't insert comments as text nodes.
Don't use the return value of React.render.
Make sure all dependencies are correctly specified in React hooks.
Make sure all React hooks are called from the top level of component functions.
Don't use unnecessary fragments.
Don't pass children as props.
Use semantic elements instead of role attributes in JSX.
Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx
**/*.{html,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{html,jsx,tsx}: Don't use or elements.
Don't use accessKey attribute on any HTML element.
Don't set aria-hidden="true" on focusable elements.
Don't add ARIA roles, states, and properties to elements that don't support them.
Only use the scope prop on elements.
Don't assign non-interactive ARIA roles to interactive HTML elements.
Make sure label elements have text content and are associated with an input.
Don't assign interactive ARIA roles to non-interactive HTML elements.
Don't assign tabIndex to non-interactive HTML elements.
Don't use positive integers for tabIndex property.
Don't include "image", "picture", or "photo" in img alt prop.
Don't use explicit role property that's the same as the implicit/default role.
Make static elements with click handlers use a valid role attribute.
Always include a title element for SVG elements.
Give all elements requiring alt text meaningful information for screen readers.
Make sure anchors have content that's accessible to screen readers.
Assign tabIndex to non-interactive HTML elements with aria-activedescendant.
Include all required ARIA attributes for elements with ARIA roles.
Make sure ARIA properties are valid for the element's supported roles.
Always include a type attribute for button elements.
Make elements with interactive roles and handlers focusable.
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden).
Always include a lang attribute on the html element.
Always include a title attribute for iframe elements.
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress.
Accompany onMouseOver/onMouseOut with onFocus/onBlur.
Include caption tracks for audio and video elements.
Make sure all anchors are valid and navigable.
Ensure all ARIA properties (aria-*) are valid.
Use valid, non-abstract ARIA roles for elements with ARIA roles.
Use valid ARIA state and property values.
Use valid values for the autocomplete attribute on input eleme...Files:
apps/web/components/assistant-chat/message-part.tsxapps/web/components/ai-elements/message.tsxapps/web/components/assistant-chat/messages.tsx🧬 Code graph analysis (3)
apps/web/components/assistant-chat/message-part.tsx (4)
apps/web/components/assistant-chat/types.ts (1)
ChatMessage(42-47)apps/web/components/ai-elements/reasoning.tsx (3)
Reasoning(43-111)ReasoningTrigger(125-152)ReasoningContent(160-173)apps/web/components/ai-elements/response.tsx (1)
Response(9-20)apps/web/components/assistant-chat/tools.tsx (7)
BasicToolInfo(23-29)CreatedRuleToolCard(31-101)UpdatedRuleConditions(103-190)UpdatedRuleActions(192-282)UpdatedLearnedPatterns(284-338)UpdateAbout(340-347)AddToKnowledgeBase(349-372)apps/web/components/ai-elements/message.tsx (1)
apps/web/utils/index.ts (1)
cn(4-6)apps/web/components/assistant-chat/messages.tsx (3)
apps/web/components/ai-elements/conversation.tsx (2)
Conversation(12-20)ConversationContent(26-31)apps/web/components/ai-elements/message.tsx (2)
Message(11-20)MessageContent(47-59)apps/web/components/assistant-chat/message-part.tsx (1)
MessagePart(31-221)⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (6)
apps/web/components/ai-elements/message.tsx (3)
27-41: Variants structure looks good.Good use of group-scoped arbitrary selectors (
group-[.is-user]/group-[.is-assistant]) and sensible defaults. This will keep styling consistent across per-part rendering.
44-51: Type surface is clear and future-proof.Extending
VariantProps<typeof messageContentVariants>onMessageContentPropsis the right move; thevariantprop is correctly exposed.
72-75: Avatar tweak LGTM.Removing the redundant
ringutility and keepingring-1 ring-borderis cleaner.apps/web/components/assistant-chat/message-part.tsx (2)
31-46: Reasoning streaming block LGTM.Properly wires
Reasoning, trigger, and content; passesisStreamingdown as intended.
48-51: Guard against empty text LGTM.Returning
nullon empty text avoids mounting empty Response blocks.apps/web/components/assistant-chat/messages.tsx (1)
44-55: Thinking indicator LGTM.Shows only after user submits and before assistant streams; matches expected UX.
| className={cn(messageContentVariants({ variant, className }))} | ||
| {...props} |
There was a problem hiding this comment.
Bug: className isn’t applied when using CVA.
cva expects "class" or external merge. Passing className inside the variants object is ignored, so consumer-supplied classes won’t render.
Apply:
- className={cn(messageContentVariants({ variant, className }))}
+ className={cn(messageContentVariants({ variant }), className)}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| className={cn(messageContentVariants({ variant, className }))} | |
| {...props} | |
| className={cn(messageContentVariants({ variant }), className)} | |
| {...props} |
🤖 Prompt for AI Agents
In apps/web/components/ai-elements/message.tsx around lines 54-55, the code
passes className into the CVA variants object so consumer classes are ignored;
remove className from the messageContentVariants call and instead merge the
returned variant classes with the incoming className (e.g., call
messageContentVariants with only variant and then combine its result with the
consumer className via the cn utility) so consumer-supplied classes are applied,
then spread the remaining props as before.
| regenerate, | ||
| setInput, | ||
| }: MessagesProps) { | ||
| export function Messages({ status, messages, setInput }: MessagesProps) { |
There was a problem hiding this comment.
Prop type/API mismatch: remove unused/required props.
MessagesProps still requires setMessages, regenerate, and isArtifactVisible, but the component no longer accepts/uses them. This will break call sites.
-interface MessagesProps {
- status: UseChatHelpers<ChatMessage>["status"];
- messages: Array<ChatMessage>;
- setMessages: UseChatHelpers<ChatMessage>["setMessages"];
- regenerate: UseChatHelpers<ChatMessage>["regenerate"];
- isArtifactVisible: boolean;
- setInput: (input: string) => void;
-}
+interface MessagesProps {
+ status: UseChatHelpers<ChatMessage>["status"];
+ messages: Array<ChatMessage>;
+ setInput: (input: string) => void;
+}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export function Messages({ status, messages, setInput }: MessagesProps) { | |
| interface MessagesProps { | |
| status: UseChatHelpers<ChatMessage>["status"]; | |
| messages: Array<ChatMessage>; | |
| setInput: (input: string) => void; | |
| } | |
| export function Messages({ status, messages, setInput }: MessagesProps) { |
🤖 Prompt for AI Agents
In apps/web/components/assistant-chat/messages.tsx around line 22, the
MessagesProps type still lists setMessages, regenerate, and isArtifactVisible
even though the Messages component no longer accepts or uses them; update the
MessagesProps definition to remove those three props (or mark them optional if
other call sites still rely on them) so the prop type matches the component API,
then update any call sites or imports that expect those props to either stop
passing them or handle the now-optional props.
| <Message from={message.role} key={message.id}> | ||
| <MessageContent> | ||
| {message.parts?.map((part, index) => ( | ||
| <MessagePart | ||
| key={`${message.id}-${index}`} | ||
| part={part} | ||
| isStreaming={status === "streaming"} | ||
| messageId={message.id} | ||
| partIndex={index} | ||
| /> | ||
| ))} | ||
| </MessageContent> | ||
| </Message> | ||
| ))} |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Scope streaming to the last message’s last part to avoid false “streaming” flags.
Currently every part in every message receives isStreaming while the chat is streaming. Limit it to the active part to prevent UI flicker (e.g., reasoning auto-close logic).
- {message.parts?.map((part, index) => (
- <MessagePart
- key={`${message.id}-${index}`}
- part={part}
- isStreaming={status === "streaming"}
- messageId={message.id}
- partIndex={index}
- />
- ))}
+ {message.parts?.map((part, index) => {
+ const isLastMessage = message.id === messages[messages.length - 1]?.id;
+ const isLastPart = index === (message.parts?.length ?? 0) - 1;
+ return (
+ <MessagePart
+ key={`${message.id}-${index}`}
+ part={part}
+ isStreaming={isLastMessage && isLastPart && status === "streaming"}
+ messageId={message.id}
+ partIndex={index}
+ />
+ );
+ })}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {messages.map((message) => ( | |
| <Message from={message.role} key={message.id}> | |
| <MessageContent> | |
| {message.parts?.map((part, index) => ( | |
| <MessagePart | |
| key={`${message.id}-${index}`} | |
| part={part} | |
| isStreaming={status === "streaming"} | |
| messageId={message.id} | |
| partIndex={index} | |
| /> | |
| ))} | |
| </MessageContent> | |
| </Message> | |
| {messages.map((message) => ( | |
| <Message from={message.role} key={message.id}> | |
| <MessageContent> | |
| {message.parts?.map((part, index) => { | |
| const isLastMessage = message.id === messages[messages.length - 1]?.id; | |
| const isLastPart = index === (message.parts?.length ?? 0) - 1; | |
| return ( | |
| <MessagePart | |
| key={`${message.id}-${index}`} | |
| part={part} | |
| isStreaming={isLastMessage && isLastPart && status === "streaming"} | |
| messageId={message.id} | |
| partIndex={index} | |
| /> | |
| ); | |
| })} | |
| </MessageContent> | |
| </Message> |
🤖 Prompt for AI Agents
In apps/web/components/assistant-chat/messages.tsx around lines 28 to 41, the
current code passes isStreaming to every MessagePart while the chat status is
"streaming"; change this so only the active (last message's last part) receives
isStreaming=true. Before mapping, compute the last message id and last part
index (e.g., find the last message with parts and its parts.length - 1) and then
set isStreaming to status === "streaming" && message.id === lastMessageId &&
index === lastPartIndex when rendering each MessagePart.
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="apps/web/components/assistant-chat/messages.tsx">
<violation number="1" location="apps/web/components/assistant-chat/messages.tsx:28">
Streaming state is applied to all messages; capture the outer index so only the latest message can stream.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| setMessages={setMessages} | ||
| regenerate={regenerate} | ||
| /> | ||
| {messages.map((message) => ( |
There was a problem hiding this comment.
Streaming state is applied to all messages; capture the outer index so only the latest message can stream.
Prompt for AI agents
Address the following comment on apps/web/components/assistant-chat/messages.tsx at line 28:
<comment>Streaming state is applied to all messages; capture the outer index so only the latest message can stream.</comment>
<file context>
@@ -21,26 +19,26 @@ interface MessagesProps {
- setMessages={setMessages}
- regenerate={regenerate}
- />
+ {messages.map((message) => (
+ <Message from={message.role} key={message.id}>
+ <MessageContent>
</file context>
Summary by CodeRabbit
New Features
UI
Refactor