Skip to content
synccn

AI Message

New

One turn in an AI chat: the person's bubble, or the assistant's answer with copy, regenerate, ratings and version arrows.

How do I show "3 days ago" in JavaScript?

AssistantFast

Use Intl.RelativeTimeFormat. It's built in, so there's nothing to install:

  • rtf.format(-3, "day") gives "3 days ago"
  • Pass numeric: "auto" to get "yesterday" instead of "1 day ago"

Installation

$ pnpm dlx shadcn@latest add @synccn/ai-message

First time in this project? Connect synccn with one command.

Usage

import { AIMessage } from "@/components/ui/ai-message";<AIMessage from="assistant" model="Smart" copyText={text} onRegenerate={retry} onFeedback={rate}>…</AIMessage>

API reference

Generated from the component's TypeScript types, so it always matches the code.

AIMessage

One turn in an AI conversation: the person's message as a bubble, or the assistant's answer with copy, regenerate, thumbs up/down and version arrows underneath.

  • fromrequired
    "user" | "assistant"

    Who wrote it. The person's messages are bubbles on the right; the assistant's are full width.

  • name
    string

    Default "Assistant"

    Name shown above assistant messages.

  • model
    string

    Model name shown after the assistant's name.

  • avatar
    React.ReactNode

    Replaces the assistant's sparkle mark.

  • copyText
    string

    Plain text for the copy button. Without it, there's no copy button.

  • onRegenerate
    () => void

    Shows a regenerate button.

  • feedback
    "up" | "down" | null

    Current rating, when controlled.

  • onFeedback
    (value: "up" | "down" | null) => void

    Shows thumbs up and down. Called with the new rating, or null when it's taken back.

  • branch
    AIMessageBranch

    Arrows to flip between regenerated versions.

  • streaming
    boolean

    Default false

    Hides the actions while the answer is still being written.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

npm packages

Accessibility

  • Ratings are toggle buttons with aria-pressed; the version counter is a polite live region.
  • Actions stay hidden while streaming, so screen readers aren't offered half-finished answers to copy.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-label, aria-live, aria-pressed
  • Announces changes to screen readers