Open History to see the last commit
1import type { ProviderDriverKind, ServerProvider } from "@t3tools/contracts";
2import { BotIcon, type LucideIcon } from "lucide-react";
3import { cn } from "../../lib/utils";
4import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances";
5import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
6
7export function threadRelationshipStatusLabel(status: string | null): string {
8 switch (status) {
9 case "preparing":
10 case "starting":
11 return "Starting";
12 case "running":
13 case "in_progress":
14 return "Running";
15 case "pending":
16 case "queued":
17 return "Queued";
18 case "waiting":
19 case "blocked":
20 return "Waiting";
21 case "completed":
22 return "Done";
23 case "failed":
24 case "error":
25 return "Failed";
26 case "cancelled":
27 case "interrupted":
28 return "Stopped";
29 case "rolled_back":
30 return "Reverted";
31 case "resolved_native":
32 return "Resolved (native)";
33 case "resolved_portable":
34 return "Resolved (portable)";
35 case "consumed":
36 return "Consumed";
37 case "superseded":
38 return "Superseded";
39 case "idle":
40 return "Idle";
41 default:
42 return "Unknown";
43 }
44}
45
46export function ThreadRelationshipIcon({
47 driver,
48 provider,
49 providerEntries = [],
50 status,
51 fallbackIcon: FallbackIcon = BotIcon,
52}: {
53 driver?: ProviderDriverKind | undefined;
54 provider?: ServerProvider | undefined;
55 providerEntries?: ReadonlyArray<ProviderInstanceEntry>;
56 status: string | null;
57 fallbackIcon?: LucideIcon;
58}) {
59 const iconClassName = "size-4 shrink-0 text-muted-foreground";
60 const entry = driver
61 ? providerEntries.find((candidate) => candidate.instanceId === provider?.instanceId)
62 : undefined;
63 const showInstanceBadge = entry !== undefined && shouldShowInstanceBadge(entry, providerEntries);
64 return (
65 <span className="relative inline-flex size-4 shrink-0 items-center justify-center">
66 {driver ? (
67 <ProviderInstanceIcon
68 driverKind={driver}
69 displayName={entry?.displayName ?? provider?.displayName ?? driver}
70 accentColor={entry?.accentColor}
71 acpRegistryAgentId={entry?.acpRegistryAgentId}
72 acpRegistryIconUrl={entry?.acpRegistryIconUrl ?? provider?.iconUrl}
73 showBadge={showInstanceBadge}
74 size="compact"
75 iconClassName={iconClassName}
76 className="z-auto"
77 />
78 ) : (
79 <FallbackIcon className={iconClassName} />
80 )}
81 <span
82 className={cn(
83 "absolute size-2 rounded-full border-2 border-card",
84 showInstanceBadge ? "-left-1 -top-1" : "-bottom-1 -right-1",
85 status === "running" ||
86 status === "in_progress" ||
87 status === "pending" ||
88 status === "waiting"
89 ? "bg-info"
90 : status === "failed" || status === "error"
91 ? "bg-destructive"
92 : status === "completed"
93 ? "bg-success"
94 : "bg-muted-foreground/45",
95 )}
96 aria-hidden="true"
97 />
98 </span>
99 );
100}