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