@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

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