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

ThreadRelationshipsControl.tsx

705 lines29.1 KB

1import { useAtomValue } from "@effect/atom-react";
2import { ThreadDetailsControl } from "./ThreadDetailsControl";
3import { ThreadHoverCardPopup } from "../ThreadHoverCard";
4import { ThreadDetailsSection } from "./ThreadDetailsSection";
5import { SectionHeaderStatus } from "../ui/collapsible-section-header";
6import { SubagentTooltipContent } from "./SubagentTooltipContent";
7import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
8import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
9import {
10 deriveWorkflowGroups,
11 projectedSubagentsToRuntime,
12 type RuntimeSubagent,
13} from "@t3tools/client-runtime/state/subagentRuntime";
14import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
15import { deriveProviderSubagentStatus } from "@t3tools/client-runtime/state/thread-execution";
16import {
17 deriveThreadRelationshipGraph,
18 immediateThreadRelationships,
19 isParentThreadRelationship,
20 threadRelationshipRowStatus,
21 orderWebThreadLineageRows,
22 resolveMergeBackTargetThreadId,
23 type ThreadRelationshipEdge,
24 type ThreadRelationshipWalkRow,
25} from "@t3tools/client-runtime/state/thread-relationships";
26import {
27 canDetachThreadProviderSession,
28 resolveLatestMergeBackRun,
29} from "@t3tools/client-runtime/state/thread-workflows";
30import {
31 isOrchestrationV2WorkActive,
32 isProviderNativeSubagentThread,
33 NodeId,
34 type EnvironmentId,
35 type OrchestrationV2Subagent,
36 type OrchestrationV2ThreadShell,
37 type ThreadId,
38} from "@t3tools/contracts";
39import { deriveSubagentElapsedMs } from "@t3tools/shared/orchestrationTiming";
40import { groupBy } from "effect/Array";
41import * as DateTime from "effect/DateTime";
42import { useNavigate } from "@tanstack/react-router";
43import {
44 ArrowRightIcon,
45 BotIcon,
46 ChevronDownIcon,
47 CornerLeftUpIcon,
48 GitForkIcon,
49 LoaderCircleIcon,
50 MoreHorizontalIcon,
51 PlusIcon,
52 SquareIcon,
53 UnplugIcon,
54} from "lucide-react";
55import { useState, type ReactNode } from "react";
56​
57import { useArchivedThreadSnapshots } from "../../lib/archivedThreadsState";
58import { buildThreadRouteParams } from "../../threadRoutes";
59import {
60 useProjects,
61 useThreadProjection,
62 useThreadRelationshipShells,
63} from "../../state/entities";
64import { useEnvironmentProviders } from "../../state/environments";
65import { threadEnvironment } from "../../state/threads";
66import { orchestrationEnvironment } from "../../state/orchestration";
67import { useAtomCommand } from "../../state/use-atom-command";
68import { AgentElapsed } from "./AgentElapsed";
69import { ThreadRelationshipIcon, threadRelationshipStatusLabel } from "./ThreadRelationshipIcon";
70import { ThreadLineageWorkflowRow } from "./ThreadLineageWorkflowRow";
71​
72import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
73import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
74import { toastManager } from "../ui/toast";
75import { cn } from "~/lib/utils";
76import {
77 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
78 THREAD_DETAILS_PANEL_ICON_CLASS,
79 THREAD_DETAILS_PANEL_LABEL_CLASS,
80 THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
81 THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
82 THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
83} from "./threadDetailsPanelStyles";
84​
85const THREAD_LINEAGE_INITIAL_COUNT = 6;
86const THREAD_LINEAGE_PAGE_COUNT = 12;
87​
88function resolveThreadLineageWindow<Row>(
89 rows: ReadonlyArray<Row>,
90 visibleCount: number,
91): { readonly visibleRows: ReadonlyArray<Row>; readonly hiddenCount: number } {
92 const visibleRows = rows.slice(0, visibleCount);
93 return { visibleRows, hiddenCount: rows.length - visibleRows.length };
95​
96function ThreadLineageRowList(props: {
97 readonly hiddenCount: number;
98 readonly onShowMore: () => void;
99 readonly children: ReactNode;
100}) {
101 return (
102 <>
103 {/* ScrollArea's max-height viewport measures badly inside this scrolling panel. */}
104 <ul
105 aria-label="Related threads"
106 className="m-0 max-h-[13.5rem] list-none overflow-y-auto overscroll-contain p-0 has-data-workflow-expanded:max-h-[min(28rem,55dvh)]"
107 >
108 {props.children}
109 </ul>
110 {props.hiddenCount > 0 ? (
111 <button
112 type="button"
113 onClick={props.onShowMore}
114 className={`flex h-8 w-full cursor-pointer items-center rounded-lg ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-sm font-medium text-muted-foreground/70 hover:bg-black/[0.055] hover:text-foreground/80 dark:hover:bg-white/[0.075]`}
115 >
116 <PlusIcon aria-hidden className="size-4 shrink-0" />
117 Show {Math.min(props.hiddenCount, THREAD_LINEAGE_PAGE_COUNT)} more
118 </button>
119 ) : null}
120 </>
121 );
123​
124function ThreadLineageGroup(props: {
125 readonly label: string | null;
126 readonly rows: ReadonlyArray<ThreadRelationshipWalkRow>;
127 readonly expanded: boolean;
128 readonly children: (rows: ReadonlyArray<ThreadRelationshipWalkRow>) => ReactNode;
129}) {
130 const [expanded, setExpanded] = useState(props.expanded);
131 const [visibleCount, setVisibleCount] = useState(THREAD_LINEAGE_INITIAL_COUNT);
132 const { visibleRows, hiddenCount } = resolveThreadLineageWindow(props.rows, visibleCount);
133 const failedCount = props.rows.filter(
134 ({ edge }) => edge.status === "failed" || edge.status === "error",
135 ).length;
136 if (props.rows.length === 0) return null;
137 return (
138 <div>
139 {props.label ? (
140 <ThreadDetailsControl aria-expanded={expanded} onClick={() => setExpanded(!expanded)}>
141 <BotIcon aria-hidden className={THREAD_DETAILS_PANEL_ICON_CLASS} />
142 <span className={cn(THREAD_DETAILS_PANEL_LABEL_CLASS, "min-w-0 flex-1 truncate")}>
143 {props.label}
144 </span>
145 {failedCount > 0 ? <SectionHeaderStatus>{failedCount} failed</SectionHeaderStatus> : null}
146 {expanded ? null : (
147 <span className="shrink-0 text-xs font-normal tabular-nums text-muted-foreground">
148 {props.rows.length}
149 </span>
150 )}
151 <ChevronDownIcon
152 aria-hidden
153 className={cn(
154 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
155 "transition-transform",
156 !expanded && "rotate-180 redesign:-rotate-90",
157 )}
158 />
159 </ThreadDetailsControl>
160 ) : null}
161 {expanded ? (
162 <ThreadLineageRowList
163 hiddenCount={hiddenCount}
164 onShowMore={() => setVisibleCount((count) => count + THREAD_LINEAGE_PAGE_COUNT)}
165 >
166 {props.children(visibleRows)}
167 </ThreadLineageRowList>
168 ) : null}
169 </div>
170 );
172​
173function relationshipLabel(edge: ThreadRelationshipEdge, currentThreadId: ThreadId) {
174 if (edge.kind === "transfer") return "Context transfer";
175 if (edge.kind === "subagent") {
176 return edge.sourceThreadId === currentThreadId ? "Subagent" : "Parent agent";
177 }
178 return edge.sourceThreadId === currentThreadId ? "Fork" : "Parent thread";
180​
181function relationshipThreadTitle(input: {
182 readonly title: string;
183 readonly isSubagent: boolean;
184}): string {
185 if (!input.isSubagent) return input.title;
186 return formatSubagentDisplayTitle(input.title);
188​
189function currentSubagent<Agent extends RuntimeSubagent>(
190 agent: Agent | undefined,
191 childThread: OrchestrationV2ThreadShell | null | undefined,
192): Agent | undefined {
193 if (!agent || !childThread || isOrchestrationV2WorkActive(agent.status)) return agent;
194 const liveStatus =
195 childThread.activityRunStatus ?? (childThread.status === "queued" ? "queued" : null);
196 const newerRun =
197 childThread.latestRunRequestedAt &&
198 DateTime.toEpochMillis(childThread.latestRunRequestedAt) >
199 Date.parse(agent.completedAt ?? agent.startedAt ?? agent.updatedAt);
200 if (!liveStatus && !newerRun) return agent;
201 const status = liveStatus ?? childThread.status;
202 const startedAt = liveStatus ? childThread.activityRunStartedAt : childThread.latestRunStartedAt;
203 const completedAt = liveStatus ? null : childThread.latestRunCompletedAt;
204 return {
205 ...agent,
206 status:
207 status === "preparing" || status === "starting" || status === "queued"
208 ? "pending"
209 : status === "rolled_back"
210 ? "interrupted"
211 : status,
212 startedAt: startedAt ? DateTime.formatIso(startedAt) : null,
213 completedAt: completedAt ? DateTime.formatIso(completedAt) : null,
214 progress: null,
215 result: null,
216 error: null,
217 };
219​
220export function ThreadRelationshipsPanel(props: {
221 readonly environmentId: EnvironmentId;
222 readonly threadId: ThreadId;
223}) {
224 const ref = scopeThreadRef(props.environmentId, props.threadId);
225 const projection = useThreadProjection(ref)?.projection ?? null;
226 const providersByEnvironment = useEnvironmentProviders();
227 const relationshipShells = useThreadRelationshipShells(ref);
228 const allProjects = useProjects();
229 const archived = useArchivedThreadSnapshots([props.environmentId]);
230 const archivedShells = archived.snapshots.find(
231 (entry) => entry.environmentId === props.environmentId,
232 )?.snapshot.threads;
233 const currentThread =
234 projection?.thread ??
235 relationshipShells.find((thread) => thread.id === props.threadId) ??
236 archivedShells?.find((thread) => thread.id === props.threadId);
237 const parentThreadId =
238 currentThread?.forkedFrom?.type === "run"
239 ? currentThread.forkedFrom.threadId
240 : currentThread?.lineage.parentThreadId;
241 const parentShell = parentThreadId
242 ? (relationshipShells.find((thread) => thread.id === parentThreadId) ??
243 archivedShells?.find((thread) => thread.id === parentThreadId))
244 : undefined;
245 const parentRef =
246 parentShell && isProviderNativeSubagentThread(parentShell)
247 ? scopeThreadRef(props.environmentId, parentShell.id)
248 : null;
249 const parentProjection = useThreadProjection(parentRef)?.projection;
250 const navigate = useNavigate();
251 const mergeBack = useAtomCommand(threadEnvironment.mergeBack);
252 const stopSession = useAtomCommand(threadEnvironment.stopSession);
253 const interruptTurn = useAtomCommand(threadEnvironment.interruptTurn);
254 const stopWorkflowCommand = useAtomCommand(orchestrationEnvironment.stopWorkflow);
255 const canOperateWorkflow = useAtomValue(
256 orchestrationEnvironment.stopWorkflow.permissionAtom(props.environmentId),
257 );
258 const [busyAction, setBusyAction] = useState<"merge" | "detach" | null>(null);
259 const [stoppingId, setStoppingId] = useState<string | null>(null);
260 // Derive graphs after hooks to preserve their compiler cache.
261 const providers = providersByEnvironment.get(props.environmentId);
262 const projects = allProjects.filter((project) => project.environmentId === props.environmentId);
263 const parentNativeStatus = parentProjection
264 ? deriveProviderSubagentStatus(parentProjection)?.status
265 : undefined;
266 const projected = projection?.subagents ?? [];
267 const runtimeSubagents = projectedSubagentsToRuntime(projected);
268 const byId = new Map(runtimeSubagents.map((agent) => [agent.id, agent]));
269 const subagentsByThreadId = new Map(
270 projected
271 .filter((subagent) => subagent.childThreadId !== null)
272 .map((subagent) => [
273 subagent.childThreadId,
274 {
275 ...byId.get(subagent.id)!,
276 id: subagent.id,
277 threadId: subagent.threadId,
278 runId: subagent.runId,
279 nativeTaskRef: subagent.nativeTaskRef,
280 nativeStatus: subagent.status,
281 driver: subagent.driver,
282 providerInstanceId: subagent.providerInstanceId,
283 origin: subagent.origin,
284 modelSelection: subagent.modelSelection,
285 },
286 ]),
287 );
288 const workflowGroupsById = new Map(
289 deriveWorkflowGroups(runtimeSubagents).map((group) => [group.workflow.id, group]),
290 );
291 const shells: ReadonlyArray<OrchestrationV2ThreadShell> = [
292 ...relationshipShells,
293 ...(archivedShells ?? []),
294 ];
295 const graph = deriveThreadRelationshipGraph({ threads: shells, projection });
296 const currentProject = projects.find((project) => project.id === currentThread?.projectId);
297 const latestMergeBackRun = projection === null ? null : resolveLatestMergeBackRun(projection);
298 const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
299 const relationshipRows = orderWebThreadLineageRows({
300 graph,
301 rows: immediateThreadRelationships(graph, props.threadId),
302 currentThreadId: props.threadId,
303 mergeTargetThreadId,
304 }).map((row) => {
305 const agent =
306 row.edge.kind === "subagent" && !isParentThreadRelationship(row.edge, props.threadId)
307 ? subagentsByThreadId.get(row.threadId)
308 : undefined;
309 const workflowGroup = agent === undefined ? undefined : workflowGroupsById.get(agent.id);
310 return workflowGroup === undefined
311 ? row
312 : { ...row, edge: { ...row.edge, status: workflowGroup.workflow.status } };
313 });
314 const canMerge = mergeTargetThreadId !== null && latestMergeBackRun !== null;
315 const canDetach = projection ? canDetachThreadProviderSession(projection) : false;
316​
317 const {
318 related = [],
319 active = [],
320 previous = [],
321 } = groupBy(relationshipRows, ({ edge }) => {
322 if (edge.kind !== "subagent" || isParentThreadRelationship(edge, props.threadId))
323 return "related";
324 return ["completed", "failed", "error", "cancelled", "interrupted", "idle"].includes(
325 edge.status ?? "",
326 )
327 ? "previous"
328 : "active";
329 });
330 const groups = [
331 { id: "related", label: null, rows: related, expanded: true },
332 { id: "active", label: null, rows: active, expanded: true },
333 { id: "previous", label: "Previous agents", rows: previous, expanded: false },
334 ];
335 const runningCount =
336 (projection?.subagents.filter(
337 (agent) => agent.childThreadId === null && agent.status === "running",
338 ).length ?? 0) + active.filter(({ edge }) => edge.status === "running").length;
339​
340 if (relationshipRows.length === 0 && runningCount === 0) {
341 return null;
342 }
343​
344 const openThread = (threadId: ThreadId) => {
345 void navigate({
346 to: "/$environmentId/$threadId",
347 params: buildThreadRouteParams(scopeThreadRef(props.environmentId, threadId)),
348 });
349 };
350​
351 const merge = async () => {
352 if (!latestMergeBackRun || mergeTargetThreadId === null || busyAction !== null) return;
353 setBusyAction("merge");
354 const result = await mergeBack({
355 environmentId: props.environmentId,
356 input: {
357 sourceThreadId: props.threadId,
358 targetThreadId: mergeTargetThreadId,
359 runId: latestMergeBackRun.id,
360 },
361 });
362 setBusyAction(null);
363 if (result._tag === "Success") openThread(mergeTargetThreadId);
364 };
365​
366 const detach = async () => {
367 if (!canDetach || busyAction !== null) return;
368 setBusyAction("detach");
369 await stopSession({
370 environmentId: props.environmentId,
371 input: { threadId: props.threadId },
372 });
373 setBusyAction(null);
374 };
375​
376 const stopSubagent = async (
377 childThreadId: ThreadId,
378 agent: Pick<OrchestrationV2Subagent, "id" | "threadId">,
379 ) => {
380 if (stoppingId !== null) return;
381 setStoppingId(childThreadId);
382 const result = await interruptTurn({
383 environmentId: props.environmentId,
384 input: { threadId: agent.threadId, subagentId: agent.id },
385 });
386 setStoppingId(null);
387 if (result._tag === "Failure") {
388 toastManager.add({ type: "error", title: "Could not stop subagent" });
389 }
390 };
391​
392 const stopWorkflow = async (subagentId: string) => {
393 if (stoppingId !== null) return;
394 setStoppingId(subagentId);
395 const result = await stopWorkflowCommand({
396 environmentId: props.environmentId,
397 input: { threadId: props.threadId, subagentId: NodeId.make(subagentId) },
398 });
399 setStoppingId(null);
400 if (result._tag === "Failure") {
401 toastManager.add({ type: "error", title: "Could not stop workflow" });
402 }
403 };
404​
405 const parentTitle =
406 mergeTargetThreadId === null
407 ? null
408 : (graph.nodes.get(mergeTargetThreadId)?.thread?.title ?? null);
409​
410 return (
411 <ThreadDetailsSection
412 headingId="thread-details-lineage-heading"
413 title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
414 // A lone "Previous agents" row names itself; the heading returns for status or actions.
415 showHeading={runningCount > 0 || canDetach || related.length > 0 || active.length > 0}
416 data-thread-relationships-panel
417 actions={
418 canDetach ? (
419 <Menu>
420 <MenuTrigger
421 render={
422 <ThreadDetailsControl
423 size="icon-xs"
424 variant="ghost"
425 part="icon"
426 aria-label="More thread actions"
427 disabled={busyAction !== null}
428 />
429 }
430 >
431 <MoreHorizontalIcon className="size-3.5" />
432 </MenuTrigger>
433 <MenuPopup align="end" className="min-w-60 max-w-(--available-width)">
434 <MenuItem onClick={() => void detach()}>
435 <UnplugIcon className="size-3.5" />
436 Disconnect agent session
437 </MenuItem>
438 </MenuPopup>
439 </Menu>
440 ) : null
441 }
442 >
443 {groups.map((group) => (
444 <ThreadLineageGroup key={`${scopedThreadKey(ref)}:${group.id}`} {...group}>
445 {(visibleRows) =>
446 visibleRows.map(({ threadId, edge }) => {
447 const node = graph.nodes.get(threadId);
448 const isSubagent = edge.kind === "subagent";
449 const isMergeTarget = threadId === mergeTargetThreadId;
450 const isParent = isParentThreadRelationship(edge, props.threadId);
451 const rowStatus =
452 (isParent && threadId === parentRef?.threadId
453 ? (node?.thread?.activityRunStatus ?? parentNativeStatus)
454 : undefined) ?? threadRelationshipRowStatus(graph, { threadId, edge });
455 const RelationshipIcon = isParent
456 ? CornerLeftUpIcon
457 : isSubagent
458 ? BotIcon
459 : GitForkIcon;
460 const relationship = relationshipLabel(edge, props.threadId);
461 const projectedAgent =
462 isSubagent && !isParent ? subagentsByThreadId.get(threadId) : undefined;
463 const workflowGroup =
464 projectedAgent === undefined
465 ? undefined
466 : workflowGroupsById.get(projectedAgent.id);
467 const agent = workflowGroup
468 ? projectedAgent
469 : currentSubagent(projectedAgent, node?.thread);
470 const failed = rowStatus === "failed" || rowStatus === "error";
471 const canStop =
472 agent &&
473 (agent.origin === "app_owned" ||
474 (agent.origin === "provider_native" &&
475 agent.driver === "claudeAgent" &&
476 agent.runId != null &&
477 agent.nativeTaskRef?.strength === "strong" &&
478 agent.nativeTaskRef.nativeId !== null &&
479 ["pending", "running", "waiting"].includes(agent.nativeStatus))) &&
480 agent.startedAt &&
481 ["pending", "running", "waiting"].includes(agent.status);
482 const threadTitle = relationshipThreadTitle({
483 title:
484 workflowGroup?.workflow.workflowName ??
485 node?.thread?.title ??
486 agent?.title ??
487 threadId,
488 isSubagent,
489 });
490 const provider = providers?.find(
491 (entry) =>
492 entry.instanceId ===
493 (agent?.providerInstanceId ?? node?.thread?.providerInstanceId),
494 );
495 const providerDriver = agent?.driver ?? provider?.driver;
496 const canStopWorkflow =
497 canOperateWorkflow &&
498 workflowGroup?.workflow.status === "running" &&
499 agent?.origin === "provider_native" &&
500 providerDriver === "claudeAgent";
501 const trailingVisibilityClass = (workflowGroup ? canStopWorkflow : canStop)
502 ? "group-hover:opacity-0 group-focus-within:opacity-0 pointer-coarse:opacity-0 [@media(hover:none)]:opacity-0"
503 : "";
504 const project = projects.find((project) => project.id === node?.thread?.projectId);
505 const relationshipHint = node?.missing
506 ? "This related thread is unavailable"
507 : `Open ${relationship.toLowerCase()} in this chat`;
508 const RelationshipPopup = agent ? ThreadHoverCardPopup : TooltipPopup;
509 const relationshipTooltip = agent ? (
510 <SubagentTooltipContent
511 title={threadTitle}
512 model={agent.model}
513 providerInstanceId={agent.providerInstanceId}
514 origin={agent.origin}
515 modelSelection={agent.modelSelection}
516 provider={provider}
517 providers={providers}
518 driver={providerDriver}
519 elapsed={<AgentElapsed agent={agent} />}
520 status={agent.status}
521 result={agent.result}
522 progress={agent.progress}
523 parentThread={currentThread ?? undefined}
524 childThread={node?.thread ?? undefined}
525 parentProject={currentProject}
526 childProject={project}
527 />
528 ) : (
529 relationshipHint
530 );
531 const relationshipContent = (
532 <>
533 <ThreadRelationshipIcon
534 driver={isSubagent && !isParent ? providerDriver : undefined}
535 provider={provider}
536 fallbackIcon={RelationshipIcon}
537 status={rowStatus}
538 />
539 <span className="min-w-0 flex-1">
540 <span className="block truncate text-left text-sm font-medium leading-4 text-foreground/85">
541 {threadTitle}
542 </span>
543 </span>
544 {agent ? null : (
545 <ArrowRightIcon className="size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100" />
546 )}
547 {agent &&
548 !failed &&
549 (deriveSubagentElapsedMs(agent, 0) !== null || canStopWorkflow) ? (
550 <span
551 className={`shrink-0 text-2xs font-normal tabular-nums text-muted-foreground ${canStopWorkflow ? "min-w-6 text-end" : ""} ${trailingVisibilityClass}`}
552 >
553 <AgentElapsed agent={agent} compact />
554 </span>
555 ) : !isMergeTarget ? (
556 <span
557 className={
558 workflowGroup
559 ? "sr-only"
560 : `shrink-0 text-2xs ${failed ? "text-destructive" : "text-muted-foreground"} ${trailingVisibilityClass}`
561 }
562 >
563 {threadRelationshipStatusLabel(rowStatus)}
564 </span>
565 ) : null}
566 </>
567 );
568 const relationshipLink = (
569 <Tooltip>
570 <TooltipTrigger
571 delay={200}
572 render={
573 <ThreadDetailsControl
574 size="sm"
575 variant="ghost"
576 part={workflowGroup ? "primary" : "row"}
577 disabled={node?.missing === true}
578 onClick={() => openThread(threadId)}
579 />
580 }
581 >
582 {relationshipContent}
583 </TooltipTrigger>
584 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
585 </Tooltip>
586 );
587 if (workflowGroup && agent) {
588 return (
589 <ThreadLineageWorkflowRow
590 key={threadId}
591 group={workflowGroup}
592 providerInstanceId={agent.providerInstanceId}
593 provider={provider}
594 providers={providers}
595 driver={providerDriver}
596 onOpenThread={(memberThreadId) => openThread(memberThreadId as ThreadId)}
597 isThreadAvailable={(memberThreadId) =>
598 graph.nodes.get(memberThreadId as ThreadId)?.missing === false
599 }
600 onStop={canStopWorkflow ? () => void stopWorkflow(agent.id) : undefined}
601 stopping={stoppingId === agent.id}
602 stopDisabled={stoppingId !== null}
603 header={relationshipLink}
604 />
605 );
606 }
607 return (
608 <li key={threadId} className="group relative flex h-8 items-center rounded-lg">
609 {isMergeTarget ? (
610 <div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
611 <Tooltip>
612 <TooltipTrigger
613 delay={200}
614 render={
615 <ThreadDetailsControl
616 size="sm"
617 variant="ghost"
618 part="primary"
619 aria-label={`${threadTitle} ${threadRelationshipStatusLabel(rowStatus)}`}
620 disabled={node?.missing === true}
621 onClick={() => openThread(threadId)}
622 />
623 }
624 >
625 {relationshipContent}
626 </TooltipTrigger>
627 <RelationshipPopup side="left">{relationshipTooltip}</RelationshipPopup>
628 </Tooltip>
629 <span
630 aria-hidden="true"
631 className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS}
632 />
633 <Tooltip>
634 <TooltipTrigger
635 render={
636 <ThreadDetailsControl
637 size="sm"
638 variant="ghost"
639 part="secondary"
640 aria-label={
641 parentTitle
642 ? `Merge back to ${parentTitle}`
643 : "Merge back to source conversation"
644 }
645 disabled={!canMerge || busyAction !== null}
646 onClick={() => void merge()}
647 >
648 {busyAction === "merge" ? (
649 <LoaderCircleIcon className="size-3 animate-spin" />
650 ) : (
651 <PullRequestGlyph.merged className="size-3" />
652 )}
653 </ThreadDetailsControl>
654 }
655 />
656 <TooltipPopup side="left">
657 {latestMergeBackRun === null
658 ? "Complete a run in this fork before merging it back"
659 : parentTitle
660 ? `Merge this conversation back into ${parentTitle}`
661 : "Merge this conversation back into its source"}
662 </TooltipPopup>
663 </Tooltip>
664 <span className="shrink-0 border border-transparent ps-1 pe-2.5 text-2xs font-medium text-muted-foreground">
665 {threadRelationshipStatusLabel(rowStatus)}
666 </span>
667 </div>
668 ) : (
669 relationshipLink
670 )}
671 {canStop && agent ? (
672 <div className="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100 pointer-coarse:pointer-events-auto pointer-coarse:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100">
673 <Tooltip>
674 <TooltipTrigger
675 render={
676 <ThreadDetailsControl
677 size="icon-xs"
678 variant="ghost"
679 part="icon"
680 tone="destructive"
681 aria-label={`Stop subagent ${threadTitle}`}
682 disabled={stoppingId !== null}
683 onClick={() => void stopSubagent(threadId, agent)}
684 />
685 }
686 >
687 {stoppingId === threadId ? (
688 <LoaderCircleIcon aria-hidden className="size-3 animate-spin" />
689 ) : (
690 <SquareIcon aria-hidden className="size-3 fill-current" />
691 )}
692 </TooltipTrigger>
693 <TooltipPopup side="left">Stop subagent</TooltipPopup>
694 </Tooltip>
695 </div>
696 ) : null}
697 </li>
698 );
699 })
700 }
701 </ThreadLineageGroup>
702 ))}
703 </ThreadDetailsSection>
704 );