Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadContextChip.tsx

43 lines1.5 KB

1import type { ThreadContextRecord } from "@t3tools/contracts";
2import { Link } from "@tanstack/react-router";
3import { MessagesSquareIcon } from "lucide-react";
4​
5import { useThreadShell } from "~/state/entities";
6import { ContextChip, ContextChipLabel } from "./ContextChip";
7import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
8​
9export function ThreadContextChip(props: {
10 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
11 copyMarkdown?: string;
12 unreadable?: boolean;
13}) {
14 const { environmentId, threadId } = props.record;
15 const shell = useThreadShell({ environmentId, threadId });
16 const title = shell?.title?.trim() || props.record.title;
17 return (
18 <Tooltip>
19 <TooltipTrigger
20 render={
21 <ContextChip
22 kind="thread"
23 {...(props.unreadable ? { state: "invalid" as const } : {})}
24 render={<Link to="/$environmentId/$threadId" params={{ environmentId, threadId }} />}
25 aria-label={`Thread, ${title}`}
26 data-markdown-copy={props.copyMarkdown}
27 className="no-underline"
28 >
29 <MessagesSquareIcon />
30 <ContextChipLabel>{title}</ContextChipLabel>
31 </ContextChip>
32 }
33 />
34 <TooltipPopup side="top">
35 {props.unreadable
36 ? "On another machine, so this machine's agent can't read it. Remove it or switch back to send."
37 : shell
38 ? "Open thread"
39 : "Thread no longer available"}
40 </TooltipPopup>
41 </Tooltip>
42 );