Open History to see the last commit
1import { scopeProjectRef } from "@t3tools/client-runtime/environment";
2import type { ThreadContextRecord, ProjectId } from "@t3tools/contracts";
3import { Link } from "@tanstack/react-router";
4import { MessagesSquareIcon } from "lucide-react";
5import { useGT } from "gt-react";
6
7import { useProject, useThreadShell } from "~/state/entities";
8import { orchestrationEnvironment } from "~/state/orchestration";
9import { useEnvironmentQuery } from "~/state/query";
10import { ContextChip, ContextChipLabel } from "./ContextChip";
11import { ProjectFavicon } from "./ProjectFavicon";
12import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
13
14export function ThreadContextChip(props: {
15 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
16 projectId?: ProjectId | null;
17 copyMarkdown?: string;
18 unreadable?: boolean;
19}) {
20 const gt = useGT();
21 const { environmentId, threadId } = props.record;
22 const shell = useThreadShell({ environmentId, threadId });
23 const lookup = useEnvironmentQuery(
24 shell === null && props.projectId === undefined
25 ? orchestrationEnvironment.threadLinkMetadata({
26 environmentId,
27 input: { threadIds: [threadId] },
28 })
29 : null,
30 );
31 const metadata = lookup.data?.[threadId];
32 const projectId = shell?.projectId ?? props.projectId ?? metadata?.projectId;
33 const project = useProject(projectId ? scopeProjectRef(environmentId, projectId) : null);
34 const title = shell?.title?.trim() || metadata?.title.trim() || props.record.title;
35 return (
36 <Tooltip>
37 <TooltipTrigger
38 render={
39 <ContextChip
40 kind="thread"
41 {...(props.unreadable ? { state: "invalid" as const } : {})}
42 render={
43 <Link
44 to="/$environmentId/$threadId"
45 params={{ environmentId, threadId }}
46 draggable={false}
47 />
48 }
49 aria-label={gt("Thread, {title}", { title })}
50 data-markdown-copy={props.copyMarkdown}
51 className="no-underline"
52 >
53 {project ? (
54 <ProjectFavicon project={project} className="size-[1em] self-center" />
55 ) : (
56 <MessagesSquareIcon />
57 )}
58 <ContextChipLabel>{title}</ContextChipLabel>
59 </ContextChip>
60 }
61 />
62 <TooltipPopup side="top">
63 {props.unreadable
64 ? gt(
65 "On another machine, so this machine's agent can't read it. Remove it or switch back to send.",
66 )
67 : gt("Open thread")}
68 </TooltipPopup>
69 </Tooltip>
70 );
71}