The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 86 lines 3.36 KB
Raw
1 import { scopeProjectRef } from "@t3tools/client-runtime/environment";
2 import type { ThreadContextRecord, ProjectId } from "@t3tools/contracts";
3 import { Link, useNavigate } from "@tanstack/react-router";
4 import { MessagesSquareIcon } from "lucide-react";
5 import { useGT } from "gt-react";
6
7 import { resolveThreadOpenRoute } from "~/lib/sideChatPane";
8 import { buildThreadRouteParams } from "~/threadRoutes";
9 import { useProject, useThreadShell } from "~/state/entities";
10 import { orchestrationEnvironment } from "~/state/orchestration";
11 import { useEnvironmentQuery } from "~/state/query";
12 import { ContextChip, ContextChipLabel } from "./ContextChip";
13 import { ProjectFavicon } from "./ProjectFavicon";
14 import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
15
16 export function ThreadContextChip(props: {
17 record: Pick<ThreadContextRecord, "environmentId" | "threadId" | "title">;
18 projectId?: ProjectId | null;
19 copyMarkdown?: string;
20 unreadable?: boolean;
21 }) {
22 const gt = useGT();
23 const { environmentId, threadId } = props.record;
24 const shell = useThreadShell({ environmentId, threadId });
25 const lookup = useEnvironmentQuery(
26 shell === null && props.projectId === undefined
27 ? orchestrationEnvironment.threadLinkMetadata({
28 environmentId,
29 input: { threadIds: [threadId] },
30 })
31 : null,
32 );
33 const metadata = lookup.data?.[threadId];
34 const projectId = shell?.projectId ?? props.projectId ?? metadata?.projectId;
35 const project = useProject(projectId ? scopeProjectRef(environmentId, projectId) : null);
36 const title = shell?.title?.trim() || metadata?.title.trim() || props.record.title;
37 const navigate = useNavigate();
38 return (
39 <Tooltip>
40 <TooltipTrigger
41 render={
42 <ContextChip
43 kind="thread"
44 {...(props.unreadable ? { state: "invalid" as const } : {})}
45 render={
46 <Link
47 to="/$environmentId/$threadId"
48 params={{ environmentId, threadId }}
49 onClick={(event) => {
50 if (shell?.lineage.sideChat !== true || event.button !== 0) return;
51 if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
52 // A side chat opens as a tab beside its parent, not as its own page.
53 event.preventDefault();
54 void navigate({
55 to: "/$environmentId/$threadId",
56 params: buildThreadRouteParams(
57 resolveThreadOpenRoute({ environmentId, threadId }, shell),
58 ),
59 });
60 }}
61 draggable={false}
62 />
63 }
64 aria-label={gt("Thread, {title}", { title })}
65 data-markdown-copy={props.copyMarkdown}
66 className="no-underline"
67 >
68 {project ? (
69 <ProjectFavicon project={project} className="size-[1em] self-center" />
70 ) : (
71 <MessagesSquareIcon />
72 )}
73 <ContextChipLabel>{title}</ContextChipLabel>
74 </ContextChip>
75 }
76 />
77 <TooltipPopup side="top">
78 {props.unreadable
79 ? gt(
80 "On another machine, so this machine's agent can't read it. Remove it or switch back to send.",
81 )
82 : gt("Open thread")}
83 </TooltipPopup>
84 </Tooltip>
85 );
86 }