Open History to see the last commit
1import type { ThreadContextRecord } from "@t3tools/contracts";
2import { Link } from "@tanstack/react-router";
3import { MessagesSquareIcon } from "lucide-react";
4
5import { cn } from "~/lib/utils";
6import { useThreadShell } from "~/state/entities";
7import {
8 COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
9 CONTEXT_INLINE_CHIP_INTERACTIVE_CLASS_NAME,
10 CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES,
11} from "./composerInlineChip";
12import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
13
14/**
15 * Inline chip for an attached thread, in the composer and in sent messages. Prefers the
16 * live title so a renamed thread never shows a stale label, and opens the thread on click.
17 */
18export function ThreadContextChip(props: {
19 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
20 className: string;
21 labelClassName: string;
22 copyMarkdown?: string;
23}) {
24 const { environmentId, threadId } = props.record;
25 const shell = useThreadShell({ environmentId, threadId });
26 const title = shell?.title?.trim() || props.record.title;
27 return (
28 <Tooltip>
29 <TooltipTrigger
30 render={
31 <Link
32 to="/$environmentId/$threadId"
33 params={{ environmentId, threadId }}
34 aria-label={`Thread, ${title}`}
35 data-markdown-copy={props.copyMarkdown}
36 className={cn(
37 props.className,
38 CONTEXT_INLINE_CHIP_TONE_CLASS_NAMES.thread,
39 CONTEXT_INLINE_CHIP_INTERACTIVE_CLASS_NAME,
40 "no-underline",
41 )}
42 >
43 <MessagesSquareIcon className={COMPOSER_INLINE_CHIP_ICON_CLASS_NAME} />
44 <span className={props.labelClassName}>{title}</span>
45 </Link>
46 }
47 />
48 <TooltipPopup side="top">{shell ? "Open thread" : "Thread no longer available"}</TooltipPopup>
49 </Tooltip>
50 );
51}