Open History to see the last commit
1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models";
2import { resolveProviderInstanceDisplayName } from "@t3tools/client-runtime/state/provider-instance-display";
3import { CircleAlertIcon, GitBranchIcon } from "lucide-react";
4import { useGT } from "gt-react";
5
6import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
7import type { useProject } from "~/state/entities";
8import { useEnvironmentProviders } from "~/state/environments";
9import { getTriggerDisplayModelName } from "./chat/providerIconUtils";
10import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
11import { ProjectFavicon } from "./ProjectFavicon";
12import { ThreadHoverCard } from "./ThreadHoverCard";
13import { ThreadPullRequestsMiniList } from "./ThreadStatusIndicators";
14import { MiddleTruncate } from "./ui/middle-truncate";
15
16type ChipProject = NonNullable<ReturnType<typeof useProject>>;
17
18export function ThreadChipHoverCard(props: {
19 title: string;
20 project: ChipProject | null;
21 shell: EnvironmentThreadShell | null;
22 unreadable: boolean;
23}) {
24 const gt = useGT();
25 const { shell } = props;
26 const providers = useEnvironmentProviders();
27 const supportsMultiplePullRequests = useSupportsMultiplePullRequests(
28 shell?.environmentId ?? null,
29 );
30 const instanceId = shell
31 ? (shell.runtime?.providerInstanceId ?? shell.modelSelection.instanceId)
32 : null;
33 const provider =
34 shell && instanceId
35 ? (providers.get(shell.environmentId)?.find((entry) => entry.instanceId === instanceId) ??
36 null)
37 : null;
38 const model = shell
39 ? provider?.models.find((entry) => entry.slug === shell.modelSelection.model)
40 : undefined;
41 const modelLabel = model
42 ? getTriggerDisplayModelName(model, provider?.driver)
43 : shell?.modelSelection.model.trim();
44 return (
45 <ThreadHoverCard
46 title={props.title}
47 footer={
48 supportsMultiplePullRequests && shell && shell.pullRequests.length > 0 ? (
49 <div className="border-t border-border/60 pt-2 pl-0.5 text-xs text-muted-foreground">
50 <ThreadPullRequestsMiniList
51 environmentId={shell.environmentId}
52 projectId={shell.projectId}
53 pullRequests={shell.pullRequests}
54 />
55 </div>
56 ) : null
57 }
58 >
59 {props.project ? (
60 <div className="flex min-w-0 items-center gap-2">
61 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
62 <div className="min-w-0 truncate text-foreground/75">{props.project.title}</div>
63 </div>
64 ) : null}
65 {shell?.branch ? (
66 <div className="flex min-w-0 items-center gap-2">
67 <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />
68 <MiddleTruncate value={shell.branch} className="flex" />
69 </div>
70 ) : null}
71 {provider && modelLabel ? (
72 <div className="flex min-w-0 items-center gap-2">
73 <ProviderInstanceIcon
74 driverKind={provider.driver}
75 displayName={resolveProviderInstanceDisplayName(provider)}
76 acpRegistryIconUrl={provider.iconUrl}
77 iconClassName="size-3 shrink-0 opacity-60"
78 />
79 <div className="min-w-0 truncate text-foreground/75">{modelLabel}</div>
80 </div>
81 ) : null}
82 {props.unreadable ? (
83 <div className="flex min-w-0 items-start gap-2 text-warning">
84 <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />
85 <div className="min-w-0 flex-1 wrap-break-word">
86 {gt`On another machine, so this machine's agent can't read it. Remove it or switch back to send.`}
87 </div>
88 </div>
89 ) : null}
90 </ThreadHoverCard>
91 );
92}