The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { msg, T, useGT, useMessages } from "gt-react"; |
| 2 | import type { ReactNode } from "react"; |
| 3 | import type { DeviceToolVersions as ToolVersions } from "@t3tools/contracts"; |
| 4 | import { InlineButton } from "~/components/ui/button"; |
| 5 | import { Popover, PopoverPopup, PopoverTitle, PopoverTrigger } from "~/components/ui/popover"; |
| 6 | |
| 7 | export function DeviceToolVersions({ |
| 8 | tools, |
| 9 | action, |
| 10 | kind, |
| 11 | owner, |
| 12 | error, |
| 13 | }: { |
| 14 | tools: ToolVersions | undefined; |
| 15 | action?: ReactNode; |
| 16 | kind?: keyof ToolVersions; |
| 17 | owner?: string | undefined; |
| 18 | error?: string | undefined; |
| 19 | }) { |
| 20 | const selected = kind ? tools?.[kind] : undefined; |
| 21 | const version = |
| 22 | selected?.runningVersion ?? |
| 23 | (selected?.installedVersions.includes(selected.requiredVersion) |
| 24 | ? selected.requiredVersion |
| 25 | : selected?.installedVersions |
| 26 | .toSorted((a, b) => a.localeCompare(b, undefined, { numeric: true })) |
| 27 | .at(-1)); |
| 28 | const gt = useGT(); |
| 29 | const m = useMessages(); |
| 30 | const label = kind === "hub" ? msg("Device hub") : msg("Agent device"); |
| 31 | return ( |
| 32 | <Popover> |
| 33 | <PopoverTrigger |
| 34 | aria-label={ |
| 35 | kind |
| 36 | ? version |
| 37 | ? gt("{tool}: version {version}. Show details", { tool: m(label), version }) |
| 38 | : selected |
| 39 | ? gt("{tool}: not installed. Show details", { tool: m(label) }) |
| 40 | : gt("{tool}: version unknown. Show details", { tool: m(label) }) |
| 41 | : undefined |
| 42 | } |
| 43 | render={<InlineButton tone="muted" />} |
| 44 | > |
| 45 | {kind |
| 46 | ? version |
| 47 | ? `v${version}` |
| 48 | : selected |
| 49 | ? gt("Not installed") |
| 50 | : gt("Version unknown") |
| 51 | : error |
| 52 | ? gt("Versions unavailable") |
| 53 | : gt("Versions")} |
| 54 | </PopoverTrigger> |
| 55 | <PopoverPopup align="end" width="md"> |
| 56 | <PopoverTitle>{kind ? m(label) : gt("Device tools")}</PopoverTitle> |
| 57 | {tools ? ( |
| 58 | <div className="mt-4 divide-y divide-border/50"> |
| 59 | {( |
| 60 | [ |
| 61 | [msg("Device hub"), tools.hub], |
| 62 | [msg("Agent device"), tools.agent], |
| 63 | ] as const |
| 64 | ) |
| 65 | .filter(([name]) => !kind || name === label) |
| 66 | .map(([name, tool]) => ( |
| 67 | <div key={name} className="space-y-2 py-3 first:pt-0 last:pb-0"> |
| 68 | {!kind ? <p className="text-xs font-medium">{m(name)}</p> : null} |
| 69 | <dl className="grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 text-xs"> |
| 70 | <dt className="text-muted-foreground"> |
| 71 | <T context="running tool version">Running</T> |
| 72 | </dt> |
| 73 | <dd className="text-right font-mono"> |
| 74 | {tool.runningVersion ?? gt("Not running")} |
| 75 | </dd> |
| 76 | <dt className="text-muted-foreground"> |
| 77 | <T context="required tool version">Required</T> |
| 78 | </dt> |
| 79 | <dd className="text-right font-mono">{tool.requiredVersion}</dd> |
| 80 | <dt className="text-muted-foreground"> |
| 81 | <T context="installed tool versions">Installed</T> |
| 82 | </dt> |
| 83 | <dd className="text-right font-mono break-words"> |
| 84 | {tool.installedVersions.join(", ") || gt("None", { $context: "no versions" })} |
| 85 | </dd> |
| 86 | </dl> |
| 87 | </div> |
| 88 | ))} |
| 89 | </div> |
| 90 | ) : ( |
| 91 | <p className="mt-3 text-xs text-muted-foreground"> |
| 92 | <T>Versions have not been checked.</T> |
| 93 | </p> |
| 94 | )} |
| 95 | <p className="mt-4 border-t border-border/50 pt-3 text-xs text-muted-foreground"> |
| 96 | {owner ? `${gt("Managed by {owner}.", { owner })} ` : ""} |
| 97 | {gt("Tools update automatically on this host when needed.")} |
| 98 | </p> |
| 99 | {error ? ( |
| 100 | <p role="status" className="mt-2 text-xs text-destructive"> |
| 101 | {error} |
| 102 | </p> |
| 103 | ) : null} |
| 104 | {action ? <div className="mt-3">{action}</div> : null} |
| 105 | </PopoverPopup> |
| 106 | </Popover> |
| 107 | ); |
| 108 | } |