The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 218 lines 8.47 KB
Raw
1 import type {
2 OrchestrationV2ThreadShell,
3 OrchestrationV2TurnItemStatus,
4 OrchestrationProjectShell,
5 ServerProvider,
6 ProviderDriverKind,
7 ProviderInstanceId,
8 OrchestrationV2Subagent,
9 } from "@t3tools/contracts";
10 import {
11 resolveSubagentMetadata,
12 subagentDetailPreview,
13 } from "@t3tools/client-runtime/state/subagent-display";
14 import { REASONING_EFFORT_OPTION_IDS } from "@t3tools/client-runtime/state/thread-execution";
15 import { getModelSelectionStringOptionValue, resolveSelectableModel } from "@t3tools/shared/model";
16 import { getTraitsSpeedDisplay, TraitsSpeedIcon } from "./TraitsSpeed";
17 import { useGT, useMessages } from "gt-react";
18 import type { ReactNode } from "react";
19 import {
20 BotIcon,
21 CheckIcon,
22 CircleDashedIcon,
23 CircleXIcon,
24 FolderIcon,
25 GitBranchIcon,
26 TerminalIcon,
27 } from "lucide-react";
28 import { ThreadHoverCard } from "../ThreadHoverCard";
29 import { MiddleTruncate } from "../ui/middle-truncate";
30 import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
31 import { cn } from "~/lib/utils";
32 import { deriveProviderInstanceEntries, shouldShowInstanceBadge } from "../../providerInstances";
33
34 export function SubagentTooltipContent(props: {
35 title: string;
36 model: string | null;
37 providerInstanceId: ProviderInstanceId;
38 origin: OrchestrationV2Subagent["origin"];
39 modelSelection?: OrchestrationV2Subagent["modelSelection"];
40 provider?: ServerProvider | undefined;
41 providers?: ReadonlyArray<ServerProvider> | undefined;
42 driver?: ProviderDriverKind | undefined;
43 elapsed?: ReactNode;
44 parentThread?: Pick<OrchestrationV2ThreadShell, "projectId" | "worktreePath"> | undefined;
45 childThread?:
46 | Pick<OrchestrationV2ThreadShell, "branch" | "worktreePath" | "modelSelection">
47 | undefined;
48 parentProject?: Pick<OrchestrationProjectShell, "workspaceRoot"> | undefined;
49 childProject?: Pick<OrchestrationProjectShell, "id" | "title" | "workspaceRoot"> | undefined;
50 status: OrchestrationV2TurnItemStatus;
51 result?: string | null | undefined;
52 progress?: string | null | undefined;
53 }) {
54 const gt = useGT();
55 const messages = useMessages();
56 const childSelection =
57 props.modelSelection ??
58 (props.origin === "app_owned" ? props.childThread?.modelSelection : undefined);
59 const {
60 modelLabel,
61 modelSlug,
62 workspace: metadata,
63 } = resolveSubagentMetadata({ ...props, modelSelection: childSelection }, messages);
64 const hasProjectRow =
65 props.parentThread !== undefined &&
66 props.childProject !== undefined &&
67 props.childProject.id !== props.parentThread.projectId;
68 const preview = subagentDetailPreview(props);
69 const providerModel = props.provider?.models.find((candidate) => candidate.slug === modelSlug);
70 const childModel = props.provider
71 ? (resolveSelectableModel(
72 props.provider.driver,
73 childSelection?.model,
74 props.provider.models,
75 ) ?? childSelection?.model.trim())
76 : childSelection?.model.trim();
77 const provider = props.provider;
78 const matchingSelection =
79 childModel === modelSlug && childSelection?.instanceId === props.providerInstanceId
80 ? childSelection
81 : undefined;
82 const effort = REASONING_EFFORT_OPTION_IDS.map((id) =>
83 getModelSelectionStringOptionValue(matchingSelection, id),
84 ).find(Boolean);
85 const speed = provider
86 ? providerModel?.capabilities?.optionDescriptors
87 ?.map((descriptor) => {
88 const saved = matchingSelection?.options?.find((option) => option.id === descriptor.id);
89 if (
90 descriptor.id === "fastMode" &&
91 descriptor.type === "boolean" &&
92 typeof saved?.value === "boolean"
93 ) {
94 return getTraitsSpeedDisplay(
95 {
96 ...descriptor,
97 currentValue: saved.value,
98 },
99 messages,
100 );
101 }
102 if (
103 descriptor.id === "serviceTier" &&
104 descriptor.type === "select" &&
105 typeof saved?.value === "string" &&
106 descriptor.options.some((option) => option.id === saved.value)
107 ) {
108 return getTraitsSpeedDisplay(
109 {
110 ...descriptor,
111 currentValue: saved.value,
112 },
113 messages,
114 );
115 }
116 return null;
117 })
118 .find(Boolean)
119 : undefined;
120 const driver = props.provider?.driver ?? props.driver;
121 const entries = deriveProviderInstanceEntries(props.providers ?? []);
122 const entry = entries.find((candidate) => candidate.instanceId === props.provider?.instanceId);
123 const showInstanceBadge = entry !== undefined && shouldShowInstanceBadge(entry, entries);
124 const working = ["running", "in_progress", "pending", "waiting"].includes(props.status);
125 const failed = ["failed", "error"].includes(props.status);
126 const StatusIcon = working
127 ? CircleDashedIcon
128 : failed
129 ? CircleXIcon
130 : props.status === "completed"
131 ? CheckIcon
132 : CircleDashedIcon;
133 return (
134 <ThreadHoverCard title={props.title}>
135 <div className="flex min-w-0 items-center gap-2">
136 {driver ? (
137 <ProviderInstanceIcon
138 driverKind={driver}
139 displayName={entry?.displayName ?? props.provider?.displayName ?? driver}
140 accentColor={entry?.accentColor}
141 acpRegistryIconUrl={props.provider?.iconUrl}
142 showBadge={showInstanceBadge && entry?.accentColor !== undefined}
143 badgeContent="none"
144 badgeClassName="h-2 min-w-2 px-0"
145 iconClassName="size-3 shrink-0 opacity-60"
146 />
147 ) : (
148 <BotIcon className="size-3 shrink-0" />
149 )}
150 <span className="inline-flex min-w-0 items-center gap-1 text-foreground/75">
151 <span className="min-w-0 truncate">
152 {showInstanceBadge ? `${modelLabel} · ${entry.displayName}` : modelLabel}
153 </span>
154 {effort || speed?.speedIcon ? (
155 <span className="inline-flex shrink-0 items-center gap-1">
156 {effort ? " · " : null}
157 {speed?.speedIcon && provider ? (
158 <TraitsSpeedIcon provider={provider.driver} speedIcon={speed.speedIcon} size="xs" />
159 ) : null}
160 {effort}
161 </span>
162 ) : null}
163 </span>
164 </div>
165 <div className="flex min-w-0 items-center justify-between gap-4">
166 <span
167 className={cn(
168 "inline-flex items-center gap-1 rounded-sm font-medium capitalize",
169 working
170 ? "text-info"
171 : failed
172 ? "text-error"
173 : props.status === "completed"
174 ? "text-success"
175 : "text-muted-foreground",
176 )}
177 >
178 <StatusIcon aria-hidden className="size-3 shrink-0" />
179 {props.status === "idle"
180 ? gt("idle", { $context: "subagent status" })
181 : props.status === "pending"
182 ? gt("pending", { $context: "subagent status" })
183 : props.status === "running"
184 ? gt("running", { $context: "subagent status" })
185 : props.status === "waiting"
186 ? gt("waiting", { $context: "subagent status" })
187 : props.status === "completed"
188 ? gt("completed", { $context: "subagent status" })
189 : props.status === "failed"
190 ? gt("failed", { $context: "subagent status" })
191 : props.status === "cancelled"
192 ? gt("cancelled", { $context: "subagent status" })
193 : props.status === "interrupted"
194 ? gt("interrupted", { $context: "subagent status" })
195 : (props.status as string).replaceAll("_", " ")}
196 </span>
197 {props.elapsed}
198 </div>
199 {metadata.map(({ label, value }, index) => {
200 const Icon =
201 props.childThread?.branch && !(hasProjectRow && index === 0) ? GitBranchIcon : FolderIcon;
202 return (
203 <div key={label} className="flex min-w-0 items-center gap-2">
204 <Icon aria-hidden className="size-3 shrink-0" />
205 <span className="sr-only">{label}</span>
206 <MiddleTruncate value={value} className="flex" showTitle={false} />
207 </div>
208 );
209 })}
210 {preview ? (
211 <div className="flex min-w-0 items-center gap-2">
212 <TerminalIcon aria-hidden className="size-3 shrink-0" />
213 <MiddleTruncate value={preview} className="flex" showTitle={false} />
214 </div>
215 ) : null}
216 </ThreadHoverCard>
217 );
218 }