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

ThreadChipHoverCard.tsx

90 lines3.6 KB

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 pullRequests={shell.pullRequests} />
51 </div>
52 ) : null
53 }
54 >
55 {props.project ? (
56 <div className="flex min-w-0 items-center gap-2">
57 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
58 <div className="min-w-0 truncate text-foreground/75">{props.project.title}</div>
59 </div>
60 ) : null}
61 {shell?.branch ? (
62 <div className="flex min-w-0 items-center gap-2">
63 <GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />
64 <MiddleTruncate value={shell.branch} className="flex" />
65 </div>
66 ) : null}
67 {provider && modelLabel ? (
68 <div className="flex min-w-0 items-center gap-2">
69 <ProviderInstanceIcon
70 driverKind={provider.driver}
71 displayName={resolveProviderInstanceDisplayName(provider)}
72 acpRegistryIconUrl={provider.iconUrl}
73 iconClassName="size-3 shrink-0 opacity-60"
74 />
75 <div className="min-w-0 truncate text-foreground/75">{modelLabel}</div>
76 </div>
77 ) : null}
78 {props.unreadable ? (
79 <div className="flex min-w-0 items-start gap-2 text-warning">
80 <CircleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />
81 <div className="min-w-0 flex-1 wrap-break-word">
82 {gt(
83 "On another machine, so this machine's agent can't read it. Remove it or switch back to send.",
84 )}
85 </div>
86 </div>
87 ) : null}
88 </ThreadHoverCard>
89 );