Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

45 linesCodeBlameRaw
1/**
2 * AI Elements' Message (registry.ai-sdk.dev/message.json), in g1t's
3 * tokens: a person's words as a bubble on the right, g1t's as text on the
4 * page, and a row of quiet actions under an answer. The Markdown itself is
5 * response.tsx.
6 */
7import type { ComponentProps, ReactNode } from "react";
8
9import { cn } from "../../lib/cn";
10import { Button } from "../ui/button";
11import { Hint } from "../ui/hint";
12
13export function Message({ from, className, ...props }: ComponentProps<"div"> & { from: "user" | "assistant" }) {
14 return (
15 <div data-from={from} className={cn("group/message flex w-full flex-col gap-1.5", from === "user" ? "items-end" : "items-start", className)} {...props} />
16 );
17}
18
19/** A person's words: a bubble, their line breaks kept. */
20export function MessageContent({ className, ...props }: ComponentProps<"div">) {
21 return (
22 <div
23 className={cn(
24 "w-fit max-w-[85%] rounded-2xl rounded-br-md bg-raised px-3.5 py-2 text-[0.9375rem] leading-[1.55] wrap-break-word whitespace-pre-wrap text-fg",
25 className,
26 )}
27 {...props}
28 />
29 );
30}
31
32/** What can be done with an answer, shown under it; brighter on hover. */
33export function MessageActions({ className, ...props }: ComponentProps<"div">) {
34 return <div className={cn("flex min-h-7 flex-wrap items-center gap-0.5 text-xs text-faint", className)} {...props} />;
35}
36
37export function MessageAction({ label, children, className, ...props }: ComponentProps<typeof Button> & { label: string; children: ReactNode }) {
38 return (
39 <Hint label={label}>
40 <Button type="button" variant="ghost" size="icon-xs" aria-label={label} className={cn("size-7 text-faint hover:text-fg", className)} {...props}>
41 {children}
42 </Button>
43 </Hint>
44 );
45}