Open History to see the last commit
1import { type EnvironmentContextRecord, resolveEnvironmentMachineKind } from "@t3tools/contracts";
2
3import { useGT } from "gt-react";
4
5import { useEnvironment } from "~/state/environments";
6import { ContextChip, ContextChipLabel } from "./ContextChip";
7import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
8import { SharedTooltipTrigger } from "./ui/shared-tooltip";
9
10/**
11 * Inline chip for a mentioned machine, in the composer and in sent messages. Prefers the
12 * name this client knows the machine by, and draws it with its machine icon.
13 */
14export function EnvironmentContextChip(props: {
15 record: Pick<EnvironmentContextRecord, "environmentId" | "label">;
16 copyMarkdown?: string;
17}) {
18 const gt = useGT();
19 const environment = useEnvironment(props.record.environmentId);
20 const label = environment?.label.trim() || props.record.label;
21 return (
22 <SharedTooltipTrigger
23 render={
24 <ContextChip
25 kind="environment"
26 tabIndex={0}
27 aria-label={gt("Machine, {label}", { label })}
28 data-markdown-copy={props.copyMarkdown}
29 >
30 <EnvironmentMachineIcon
31 kind={resolveEnvironmentMachineKind(environment?.serverConfig ?? null)}
32 />
33 <ContextChipLabel>{label}</ContextChipLabel>
34 </ContextChip>
35 }
36 label={environment ? gt("T3 Code environment") : gt("Machine not in this app")}
37 />
38 );
39}