Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SubagentTooltipContent.tsx

188 lines7.1 KB

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 { REASONING_EFFORT_OPTION_IDS } from "@t3tools/client-runtime/state/thread-execution";
15import { getModelSelectionStringOptionValue, resolveSelectableModel } from "@t3tools/shared/model";
16import { getTraitsSpeedDisplay, TraitsSpeedIcon } from "./TraitsSpeed";
17import type { ReactNode } from "react";
18import {
19 BotIcon,
20 CheckIcon,
21 CircleDashedIcon,
22 CircleXIcon,
23 FolderIcon,
24 GitBranchIcon,
25 TerminalIcon,
26} from "lucide-react";
27import { ThreadHoverCard } from "../ThreadHoverCard";
28import { MiddleTruncate } from "../ui/middle-truncate";
29import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
30import { cn } from "~/lib/utils";
31import { deriveProviderInstanceEntries, shouldShowInstanceBadge } from "../../providerInstances";
32​
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 childSelection =
54 props.modelSelection ??
55 (props.origin === "app_owned" ? props.childThread?.modelSelection : undefined);
56 const {
57 modelLabel,
58 modelSlug,
59 workspace: metadata,
60 } = resolveSubagentMetadata({ ...props, modelSelection: childSelection });
61 const preview = subagentDetailPreview(props);
62 const providerModel = props.provider?.models.find((candidate) => candidate.slug === modelSlug);
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 && childSelection?.instanceId === props.providerInstanceId
73 ? childSelection
74 : undefined;
75 const effort = REASONING_EFFORT_OPTION_IDS.map((id) =>
76 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({
88 ...descriptor,
89 currentValue: saved.value,
90 });
91 }
92 if (
93 descriptor.id === "serviceTier" &&
94 descriptor.type === "select" &&
95 typeof saved?.value === "string" &&
96 descriptor.options.some((option) => option.id === saved.value)
97 ) {
98 return getTraitsSpeedDisplay({
99 ...descriptor,
100 currentValue: saved.value,
101 });
102 }
103 return null;
104 })
105 .find(Boolean)
106 : undefined;
107 const driver = props.provider?.driver ?? props.driver;
108 const entries = deriveProviderInstanceEntries(props.providers ?? []);
109 const entry = entries.find((candidate) => candidate.instanceId === props.provider?.instanceId);
110 const showInstanceBadge = entry !== undefined && shouldShowInstanceBadge(entry, entries);
111 const working = ["running", "in_progress", "pending", "waiting"].includes(props.status);
112 const failed = ["failed", "error"].includes(props.status);
113 const StatusIcon = working
114 ? CircleDashedIcon
115 : failed
116 ? CircleXIcon
117 : props.status === "completed"
118 ? CheckIcon
119 : CircleDashedIcon;
120 return (
121 <ThreadHoverCard title={props.title}>
122 <div className="flex min-w-0 items-center gap-2">
123 {driver ? (
124 <ProviderInstanceIcon
125 driverKind={driver}
126 displayName={entry?.displayName ?? props.provider?.displayName ?? driver}
127 accentColor={entry?.accentColor}
128 acpRegistryIconUrl={props.provider?.iconUrl}
129 showBadge={showInstanceBadge && entry?.accentColor !== undefined}
130 badgeContent="none"
131 badgeClassName="h-2 min-w-2 px-0"
132 iconClassName="size-3 shrink-0 grayscale opacity-60"
133 />
134 ) : (
135 <BotIcon className="size-3 shrink-0" />
136 )}
137 <span className="inline-flex min-w-0 items-center gap-1 text-foreground/75">
138 <span className="min-w-0 truncate">
139 {showInstanceBadge ? `${modelLabel} · ${entry.displayName}` : modelLabel}
140 </span>
141 {effort || speed?.speedIcon ? (
142 <span className="inline-flex shrink-0 items-center gap-1">
143 {effort ? " · " : null}
144 {speed?.speedIcon && provider ? (
145 <TraitsSpeedIcon provider={provider.driver} speedIcon={speed.speedIcon} size="xs" />
146 ) : null}
147 {effort}
148 </span>
149 ) : null}
150 </span>
151 </div>
152 <div className="flex min-w-0 items-center justify-between gap-4">
153 <span
154 className={cn(
155 "inline-flex items-center gap-1 rounded-sm font-medium capitalize",
156 working
157 ? "text-info"
158 : failed
159 ? "text-error"
160 : props.status === "completed"
161 ? "text-success"
162 : "text-muted-foreground",
163 )}
164 >
165 <StatusIcon aria-hidden className="size-3 shrink-0" />
166 {props.status.replaceAll("_", " ")}
167 </span>
168 {props.elapsed}
169 </div>
170 {metadata.map(({ label, value }) => {
171 const Icon = label === "Branch" ? GitBranchIcon : FolderIcon;
172 return (
173 <div key={label} className="flex min-w-0 items-center gap-2">
174 <Icon aria-hidden className="size-3 shrink-0" />
175 <span className="sr-only">{label}</span>
176 <MiddleTruncate value={value} className="flex" showTitle={false} />
177 </div>
178 );
179 })}
180 {preview ? (
181 <div className="flex min-w-0 items-center gap-2">
182 <TerminalIcon aria-hidden className="size-3 shrink-0" />
183 <MiddleTruncate value={preview} className="flex" showTitle={false} />
184 </div>
185 ) : null}
186 </ThreadHoverCard>
187 );