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

TimelineWorkGroupRows.tsx

759 lines24.4 KB

1import { TimelinePendingApprovalRow } from "./TimelinePendingApprovalRow";
2import { WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
3import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
4import { type ToolActivityIcon } from "@t3tools/contracts";
5import {
6 liveThoughtLine,
7 resolveViewedImageAsset,
8 workEntriesViewedImagePaths,
9} from "@t3tools/client-runtime/work-log/presentation";
10import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
11import { useAssetUrls } from "~/assets/assetUrls";
12import { observeResize } from "~/lib/observeResize";
13import { tickTextContent } from "~/lib/tickTextContent";
14import { observeVisibleAnimation } from "../../lib/visibleAnimation";
15import { T, useGT, useMessages } from "gt-react";
16import { memo, use, useLayoutEffect, useRef, useState, type ReactNode } from "react";
17import { LegendList, type LegendListRef } from "@legendapp/list/react";
18import { workEntryDisplayIndicatesToolFailure } from "../../session-logic";
19import ChatMarkdown from "../ChatMarkdown";
20import { assetMediaActionsSource } from "./ChatMarkdownMedia";
21import { Minimize2Icon, XIcon } from "lucide-react";
22import { Button } from "../ui/button";
23import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
24import {
25 liveWorkEntryLabel,
26 resolveWorkGroupScrollIndex,
27 shouldFollowWorkGroupAppend,
28 workEntryIsVisibleInGroup,
29 type MessagesTimelineRow,
30} from "./MessagesTimeline.logic";
31import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
32import { Spinner } from "../ui/spinner";
33import { WorktreeSetupCard } from "./WorktreeSetupCard";
34import { cn } from "~/lib/utils";
35import { type TimestampFormat } from "@t3tools/contracts/settings";
36import {
37 TimelineRowCtx,
38 TimelineRowActivityCtx,
39 WorkGroupViewCtx,
40 type WorkGroupViewedImage,
41 type TimelineWorkEntry,
42 type TimelineRow,
43} from "./timelineRowContext";
44import { ProviderStartingIcon } from "./ProviderStartingIcon";
45import { TimelineRowTimestamp, ActivityShimmerOverlay } from "./TimelineRowParts";
46import {
47 failedToolIconClassName,
48 toolIconAcceptsTint,
49 type WorkEntryIconName,
50 ToolActivityIconView,
51} from "./TimelineToolActivityIcon";
52import {
53 useThreadReadTarget,
54 threadReadLabel,
55 ThreadReadLabel,
56 ReasoningTraceContent,
57 SimpleWorkEntryRow,
58} from "./TimelineWorkEntryRow";
59import {
60 sliceThoughtPreviewSource,
61 thoughtPreviewMarkdown,
62 toolGroupSummaryIconName,
63 workEntryIconName,
64} from "./TimelineWorkEntryRow.logic";
65import { formatWorkingTimerNow } from "./TimelineWorkGroupRows.logic";
66​
67export const WorkGroupSection = memo(function WorkGroupSection({
68 anchorKey,
69 groupedEntries,
70 isExpandedToolGroup,
71 displayLabel,
72}: {
73 anchorKey: string;
74 groupedEntries: Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"];
75 isExpandedToolGroup: boolean;
76 displayLabel?: string | undefined;
77}) {
78 const { workspaceRoot, routeThreadKey, onToggleWorkEntry, pendingApprovals } =
79 use(TimelineRowCtx);
80 const gt = useGT();
81 const nonEmptyEntries = groupedEntries.filter((entry) => {
82 const item = entry.projectedItem?.item;
83 return (
84 (item?.type === "approval_request" && pendingApprovals.has(item.requestId)) ||
85 workEntryIsVisibleInGroup(entry, isExpandedToolGroup)
86 );
87 });
88​
89 if (nonEmptyEntries.length === 0) return null;
90 if (isExpandedToolGroup && nonEmptyEntries.every((entry) => entry.itemType === "reasoning")) {
91 return <ReasoningTraceContent entries={nonEmptyEntries} />;
92 }
93 if (isExpandedToolGroup) {
94 return (
95 <ExpandedWorkGroupEntries
96 key={`${routeThreadKey}:${anchorKey}`}
97 anchorKey={anchorKey}
98 entries={nonEmptyEntries}
99 groupedEntries={groupedEntries}
100 workspaceRoot={workspaceRoot}
101 />
102 );
103 }
104​
105 return (
106 <section aria-label={gt`Activity`}>
107 {nonEmptyEntries.map((workEntry) => (
108 <SimpleWorkEntryRow
109 key={workEntry.id}
110 workEntry={workEntry}
111 workspaceRoot={workspaceRoot}
112 displayLabel={displayLabel}
113 onToggleEntry={() => onToggleWorkEntry(anchorKey)}
114 />
115 ))}
116 </section>
117 );
118});
119​
120function WorkingTimer({ createdAt }: { createdAt: string }) {
121 const { activeThreadEnvironmentId } = use(TimelineRowCtx);
122 return (
123 <span
124 ref={tickTextContent(() => formatWorkingTimerNow(createdAt, activeThreadEnvironmentId), true)}
125 className="tabular-nums"
126 />
127 );
129​
130const compactWorkEntryHeight = 24;
131const workGroupOverflowAllowance = 2 * compactWorkEntryHeight;
132​
133// The thumbnail strip below the group is its own virtualized row, so the gallery an expanded
134// entry opens is built from the same entries rather than from the strip's mounted images.
135function useWorkGroupViewedImages(
136 groupedEntries: ReadonlyArray<TimelineWorkEntry>,
137): ReadonlyArray<WorkGroupViewedImage> {
138 const { threadRef, workspaceRoot, activeThreadEnvironmentId } = use(TimelineRowCtx);
139 const gt = useGT();
140 const fallbackName = gt({ context: "fallback name of an image without alt text" })`image`;
141 const viewed = threadRef
142 ? workEntriesViewedImagePaths(groupedEntries).flatMap((path) => {
143 const asset = resolveViewedImageAsset(path, {
144 threadId: threadRef.threadId,
145 workspaceRoot,
146 });
147 return asset ? [{ path, asset }] : [];
148 })
149 : [];
150 const environmentId = threadRef?.environmentId ?? activeThreadEnvironmentId;
151 const urls = useAssetUrls(
152 environmentId,
153 viewed.map(({ asset }) => asset.resource),
154 );
155 return viewed.map(({ path, asset }, index) => {
156 const url = urls[index];
157 if (!url) return { path, item: null };
158 const src = url + asset.srcFragment;
159 const name = asset.alt.trim() || fallbackName;
160 return {
161 path,
162 item: {
163 src,
164 name,
165 actionsSource: assetMediaActionsSource({
166 environmentId,
167 resource: asset.resource,
168 kind: "image",
169 name: asset.alt || fallbackName,
170 src,
171 workspaceRoot,
172 }),
173 },
174 };
175 });
177​
178function ExpandedWorkGroupEntries({
179 anchorKey,
180 entries,
181 groupedEntries,
182 workspaceRoot,
183}: {
184 anchorKey: string;
185 entries: TimelineWorkEntry[];
186 groupedEntries: ReadonlyArray<TimelineWorkEntry>;
187 workspaceRoot: string | undefined;
188}) {
189 const { workGroupViewState: viewState, onToggleWorkEntry } = use(TimelineRowCtx);
190 const gt = useGT();
191 const [initialScrollIndex] = useState(() =>
192 resolveWorkGroupScrollIndex(entries, viewState.scrollPositions.get(anchorKey)),
193 );
194 const [restoringPosition, setRestoringPosition] = useState(initialScrollIndex !== undefined);
195 const listRef = useRef<LegendListRef>(null);
196 const [expandedContentHeight, setExpandedContentHeight] = useState(0);
197 const [fitsWithAllowance, setFitsWithAllowance] = useState(true);
198 const [fades, setFades] = useState({ top: false, bottom: false, viewportHeight: 0 });
199 const [appendState, setAppendState] = useState({ entries, follow: false });
200 // Capture the pre-change edge once per incoming array, before new layout
201 // metrics arrive. Edge/viewport changes never turn a status update into a follow.
202 if (appendState.entries !== entries) {
203 setAppendState({
204 entries,
205 follow:
206 fades.viewportHeight > 0 &&
207 shouldFollowWorkGroupAppend(appendState.entries, entries, fades.bottom ? Infinity : 0),
208 });
209 }
210​
211 const viewedImages = useWorkGroupViewedImages(groupedEntries);
212 const groupView = {
213 state: viewState,
214 viewedImages,
215 onToggleEntry: () => onToggleWorkEntry(anchorKey),
216 };
217 const updateScrollFades = () => {
218 const element = listRef.current?.getScrollableNode();
219 if (!element) return;
220 const distanceFromEnd = element.scrollHeight - element.clientHeight - element.scrollTop;
221 const viewportHeight = element.clientHeight;
222 const top = element.scrollTop > 1;
223 const bottom = distanceFromEnd > 1;
224 setFades((previous) =>
225 previous.top === top &&
226 previous.bottom === bottom &&
227 previous.viewportHeight === viewportHeight
228 ? previous
229 : { top, bottom, viewportHeight },
230 );
231 };
232​
233 const handleScroll = () => {
234 const state = listRef.current?.getState();
235 const position = state && resolveWorkGroupScrollAnchor(state);
236 if (position) {
237 viewState.scrollPositions.set(anchorKey, {
238 entryId: position.rowId,
239 offset: position.offsetWithinRow,
240 });
241 }
242 updateScrollFades();
243 };
244​
245 const handleLoad = () => {
246 const list = listRef.current;
247 const element = list?.getScrollableNode();
248 if (initialScrollIndex && list && element) {
249 // Bootstrap can report the restored target before the DOM has applied it.
250 // Reconcile once at load, before releasing the measured anchor row.
251 const offset = Math.max(
252 0,
253 Math.min(list.getState().scroll, element.scrollHeight - element.clientHeight),
254 );
255 if (Math.abs(element.scrollTop - offset) > 1) {
256 void list.scrollToOffset({ offset, animated: false });
257 }
258 }
259 setRestoringPosition(false);
260 };
261​
262 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- measures the list and its content to set the height limit and scroll fades
263 useLayoutEffect(() => {
264 const element = listRef.current?.getScrollableNode();
265 if (!element) return;
266 const updateLayout = () => {
267 const overflow = element.scrollHeight - element.clientHeight;
268 // Fractional zoom can round scrollHeight 1px above clientHeight on content that fits;
269 // without this slack the allowance toggles on every layout pass.
270 setFitsWithAllowance(overflow <= (fitsWithAllowance ? 1 : workGroupOverflowAllowance - 1));
271 updateScrollFades();
272 };
273 updateLayout();
274 const content = element.firstElementChild;
275 return observeResize(content ? [element, content] : element, updateLayout);
276 }, [fitsWithAllowance, updateScrollFades]);
277​
278 const renderEntry = ({ item }: { item: TimelineWorkEntry }) => (
279 <SimpleWorkEntryRow key={item.id} workEntry={item} workspaceRoot={workspaceRoot} />
280 );
281​
282 const updateExpandedContentHeight = () => {
283 const state = listRef.current?.getState();
284 let height = 0;
285 for (const entryId of viewState.expandedEntries) {
286 if (state?.indexByKey(entryId) === undefined) continue;
287 height += Math.max(
288 0,
289 (state.sizes.get(entryId) ?? compactWorkEntryHeight) - compactWorkEntryHeight,
290 );
291 }
292 setExpandedContentHeight(height);
293 };
294​
295 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reads expanded row sizes from LegendList's measured state after layout
296 useLayoutEffect(updateExpandedContentHeight, [entries, updateExpandedContentHeight]);
297​
298 return (
299 <WorkGroupViewCtx value={groupView}>
300 <WorkLogList>
301 <LegendList
302 ref={listRef}
303 data={entries}
304 extraData={workspaceRoot}
305 keyExtractor={workEntryKey}
306 renderItem={renderEntry}
307 estimatedItemSize={compactWorkEntryHeight}
308 drawDistance={240}
309 recycleItems
310 {...(initialScrollIndex ? { initialScrollIndex } : {})}
311 maintainScrollAtEnd={
312 appendState.follow ? { animated: false, on: { dataChange: true } } : false
313 }
314 maintainScrollAtEndThreshold={1 / Math.max(1, fades.viewportHeight)}
315 // Measure the restored row even when an intra-row offset puts its
316 // estimated bounds outside the list's small bootstrap render window.
317 {...(restoringPosition && initialScrollIndex
318 ? { alwaysRender: { indices: [initialScrollIndex.index] } }
319 : {})}
320 maintainVisibleContentPosition
321 onLoad={handleLoad}
322 onScroll={handleScroll}
323 onLayout={updateScrollFades}
324 onItemSizeChanged={updateExpandedContentHeight}
325 tabIndex={0}
326 role="region"
327 aria-label={gt`Tool calls`}
328 data-tool-group-scroll
329 style={{
330 maxHeight: `calc(min(18rem, 50dvh) + ${
331 expandedContentHeight + (fitsWithAllowance ? workGroupOverflowAllowance : 0)
332 }px)`,
333 }}
334 className={cn(
335 "scrollbar-gutter-stable scroll-py-6 overflow-x-hidden rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
336 getVirtualizedScrollFadeClassName(fades),
337 )}
338 />
339 </WorkLogList>
340 </WorkGroupViewCtx>
341 );
343​
344const workEntryKey = (entry: TimelineWorkEntry) => entry.id;
345​
346export function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
347 const { isCompacting, isPreparingWorktree, backgroundWorktreeSetup } =
348 use(TimelineRowActivityCtx);
349 const compacting = row.compacting === true || isCompacting;
350 const shimmer = isPreparingWorktree || compacting;
351 const label = isPreparingWorktree ? (
352 <T>Setting up worktree…</T>
353 ) : compacting ? (
354 <CompactingLabel createdAt={row.createdAt} />
355 ) : row.createdAt ? (
356 <T>
357 Working for <WorkingTimer createdAt={row.createdAt} />
358 </T>
359 ) : (
360 <T>Working...</T>
361 );
362 return (
363 <div className="border-b border-border/60 pb-2 pt-1">
364 <div className="flex h-6 min-w-0 items-baseline gap-2 px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
365 <span
366 ref={shimmer ? observeVisibleAnimation : undefined}
367 className="relative shrink-0 overflow-hidden whitespace-nowrap"
368 >
369 {label}
370 {shimmer ? <ActivityShimmerOverlay>{label}</ActivityShimmerOverlay> : null}
371 </span>
372 {backgroundWorktreeSetup ? (
373 <BackgroundWorktreeSetupChip snapshot={backgroundWorktreeSetup} />
374 ) : null}
375 </div>
376 </div>
377 );
379​
380function BackgroundWorktreeSetupChip({ snapshot }: { snapshot: WorktreeSetupSnapshot }) {
381 const ctx = use(TimelineRowCtx);
382 const gt = useGT();
383 const terminalId = snapshot.setupScript?.terminalId ?? null;
384 const openTerminal = ctx.onOpenWorktreeSetupTerminal;
385 const onOpenTerminal = openTerminal && terminalId ? () => openTerminal(terminalId) : null;
386 const scriptName = snapshot.setupScript?.name ?? gt`Setup script`;
387 return (
388 <Popover>
389 <PopoverTrigger
390 render={
391 <Button
392 variant="ghost-muted"
393 size="micro"
394 className="ml-auto min-w-0 shrink-0"
395 aria-label={gt`Background setup is still running: ${{ scriptName }}. Show setup progress.`}
396 />
397 }
398 >
399 <Spinner className="size-3 shrink-0" />
400 <span className="truncate">
401 <T>Background setup</T>
402 </span>
403 </PopoverTrigger>
404 <PopoverPopup side="bottom" align="end" width="lg" padding="compact">
405 <WorktreeSetupCard
406 snapshot={snapshot}
407 embedded
408 onCancel={null}
409 onWorkLocally={null}
410 onOpenTerminal={onOpenTerminal}
411 />
412 </PopoverPopup>
413 </Popover>
414 );
416​
417function CompactingLabel({ createdAt }: { createdAt: string | null }) {
418 return (
419 <span className="inline-flex items-center gap-1.5">
420 <Minimize2Icon aria-hidden="true" className="size-3" />
421 {createdAt ? (
422 <span>
423 <T>
424 Compacting for <WorkingTimer createdAt={createdAt} />
425 </T>
426 </span>
427 ) : (
428 <T>Compacting…</T>
429 )}
430 </span>
431 );
433​
434export function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "thinking" }> }) {
435 const ctx = use(TimelineRowCtx);
436 const gt = useGT();
437 const m = useMessages();
438 const {
439 isCompacting,
440 isPreparingWorktree,
441 liveAnswerPreview,
442 providerStartingLabel,
443 providerStarting,
444 } = use(TimelineRowActivityCtx);
445 if (isPreparingWorktree || isCompacting) return <WorkLogRow label="" />;
446 // A failed group keeps this disclosure while an approval waits, but nothing is thinking then.
447 const live = ctx.pendingApprovals.size === 0;
448 const activity = (
449 <LiveActivityRow
450 label={
451 (providerStartingLabel === null ? null : m(providerStartingLabel)) ??
452 row.label ??
453 liveAnswerPreview ??
454 gt`Thinking`
455 }
456 iconName="brain"
457 iconNode={
458 providerStarting === null ? undefined : (
459 <ProviderStartingIcon
460 environmentId={ctx.activeThreadEnvironmentId ?? null}
461 instanceId={providerStarting.instanceId}
462 driver={providerStarting.driver}
463 />
464 )
465 }
466 active={live}
467 shimmer={live}
468 />
469 );
470 const { groupId } = row;
471 if (groupId === undefined) return activity;
472 return (
473 <button
474 type="button"
475 className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
476 aria-expanded={row.expanded === true}
477 onClick={() => ctx.onToggleWorkGroup(groupId, row.id)}
478 >
479 {activity}
480 </button>
481 );
483​
484function LiveActivityRow({
485 label,
486 iconName,
487 iconNode,
488 toolIcon,
489 failed = false,
490 active = false,
491 shimmer = false,
492}: {
493 label: ReactNode;
494 iconName?: WorkEntryIconName;
495 /** Replaces the named icon. */
496 iconNode?: ReactNode;
497 toolIcon?: ToolActivityIcon | undefined;
498 failed?: boolean;
499 active?: boolean;
500 shimmer?: boolean;
501}) {
502 const animated = active && !failed;
503 const showShimmer = animated && shimmer;
504 return (
505 <div
506 ref={animated ? observeVisibleAnimation : undefined}
507 className="relative min-h-6 w-fit max-w-full min-w-0 overflow-hidden rounded-md text-sm leading-relaxed"
508 >
509 <LiveActivityContent
510 label={label}
511 iconName={iconName}
512 iconNode={iconNode}
513 toolIcon={toolIcon}
514 failed={failed}
515 announceFailure={failed}
516 active={animated && !shimmer}
517 />
518 {showShimmer ? (
519 <ActivityShimmerOverlay>
520 <LiveActivityContent
521 label={label}
522 iconName={iconName}
523 iconNode={iconNode}
524 toolIcon={toolIcon}
525 highlighted
526 />
527 </ActivityShimmerOverlay>
528 ) : null}
529 </div>
530 );
532​
533function LiveActivityContent({
534 label,
535 iconName,
536 iconNode,
537 toolIcon,
538 failed = false,
539 announceFailure = false,
540 active = false,
541 highlighted = false,
542}: {
543 label: ReactNode;
544 iconName: WorkEntryIconName | undefined;
545 iconNode?: ReactNode;
546 toolIcon?: ToolActivityIcon | undefined;
547 failed?: boolean;
548 announceFailure?: boolean;
549 active?: boolean;
550 highlighted?: boolean;
551}) {
552 const gt = useGT();
553 const showTrailingFailureMark =
554 failed && iconName !== undefined && !toolIconAcceptsTint(toolIcon);
555​
556 return (
557 <WorkLogRow
558 icon={
559 iconName ? (
560 <span
561 className={cn(
562 "flex size-4 items-center justify-center",
563 failed
564 ? failedToolIconClassName
565 : highlighted
566 ? "text-foreground"
567 : "text-icon-muted",
568 )}
569 role={announceFailure ? "img" : undefined}
570 aria-label={announceFailure ? gt`Tool call failed` : undefined}
571 >
572 {iconNode ? (
573 <span className={cn("flex", !highlighted && "opacity-70")}>{iconNode}</span>
574 ) : (
575 <ToolActivityIconView
576 icon={toolIcon}
577 fallbackName={iconName}
578 className="block size-4 shrink-0 stroke-2"
579 muted={!highlighted}
580 />
581 )}
582 </span>
583 ) : null
584 }
585 label={
586 <span
587 className={cn(
588 "block truncate",
589 highlighted && "text-foreground",
590 active && "live-tool-shine",
591 )}
592 >
593 {label}
594 </span>
595 }
596 trailing={
597 showTrailingFailureMark ? (
598 <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
599 ) : null
600 }
601 />
602 );
604​
605export function LiveWorkEntryTimelineRow({
606 row,
607}: {
608 row: Extract<TimelineRow, { kind: "work-live" }>;
609}) {
610 const ctx = use(TimelineRowCtx);
611 const gt = useGT();
612 const m = useMessages();
613 const threadTarget = useThreadReadTarget(
614 row.entry,
615 ctx.activeThreadEnvironmentId,
616 ctx.threadRef !== null,
617 );
618 const label = liveWorkEntryLabel(row.entry, ctx.workspaceRoot, row.active, m);
619 const threadLabel = threadReadLabel(label, row.entry, threadTarget, m);
620​
621 const item = row.entry.projectedItem?.item;
622 const pendingApproval =
623 item?.type === "approval_request" ? ctx.pendingApprovals.get(item.requestId) : undefined;
624 if (pendingApproval) return <TimelinePendingApprovalRow approval={pendingApproval} />;
625​
626 const failed = workEntryDisplayIndicatesToolFailure(row.entry);
627 const thoughtLine =
628 row.thought && !row.expanded
629 ? liveThoughtLine(sliceThoughtPreviewSource(row.thought.detail ?? ""))
630 : "";
631 const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought;
632​
633 return (
634 <button
635 type="button"
636 className={cn(
637 "group/live-work flex w-full max-w-full cursor-pointer rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
638 thoughtLine ? "flex-col items-start" : "min-h-6 items-center",
639 )}
640 aria-label={
641 failed
642 ? gt`${{ label: `${thoughtLine ? `${thoughtLine} ` : ""}${threadLabel?.text ?? label}` }}, tool call failed`
643 : undefined
644 }
645 aria-expanded={row.expanded}
646 onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
647 >
648 {thoughtLine ? (
649 <WorkLogRow
650 icon={
651 <span className="flex size-4 items-center justify-center text-icon-muted">
652 <ToolActivityIconView
653 icon={undefined}
654 fallbackName="brain"
655 className="block size-4 shrink-0 stroke-2"
656 muted
657 />
658 </span>
659 }
660 label={
661 <span className="line-clamp-4">
662 <ChatMarkdown
663 inline
664 text={thoughtLine}
665 cwd={ctx.markdownCwd}
666 parseRawHtml={false}
667 extensions={thoughtPreviewMarkdown(gt`Thought`)}
668 />
669 </span>
670 }
671 wrapLabel
672 />
673 ) : null}
674 <LiveActivityRow
675 label={
676 thoughtIsStatus ? (
677 row.active ? (
678 gt`Thinking`
679 ) : (
680 gt`Thought`
681 )
682 ) : row.entry.itemType === "reasoning" ? (
683 <ChatMarkdown
684 inline
685 text={sliceThoughtPreviewSource(row.entry.detail ?? label)}
686 cwd={ctx.markdownCwd}
687 parseRawHtml={false}
688 extensions={
689 row.active
690 ? thoughtPreviewMarkdown(gt`Thinking`)
691 : thoughtPreviewMarkdown(gt`Thought`)
692 }
693 />
694 ) : threadLabel ? (
695 <ThreadReadLabel label={threadLabel} linked={false} />
696 ) : (
697 label
698 )
699 }
700 iconName={workEntryIconName(row.entry)}
701 toolIcon={row.entry.toolIcon ?? row.entry.toolSource?.icon}
702 failed={failed}
703 active={row.active}
704 />
705 </button>
706 );
708​
709export function WorkGroupToggleTimelineRow({
710 row,
711}: {
712 row: Extract<TimelineRow, { kind: "work-toggle" }>;
713}) {
714 const ctx = use(TimelineRowCtx);
715 return (
716 <WorkGroupHeader
717 label={row.summary}
718 iconName={row.toolSurface ?? toolGroupSummaryIconName(row.summaryKind)}
719 toolIcon={row.toolIcon}
720 failed={row.hasFailure}
721 expanded={row.expanded}
722 createdAt={row.createdAt}
723 timestampFormat={ctx.timestampFormat}
724 onToggle={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
725 />
726 );
728​
729function WorkGroupHeader(props: {
730 label: string;
731 iconName: WorkEntryIconName;
732 toolIcon?: ToolActivityIcon | undefined;
733 failed?: boolean | undefined;
734 expanded: boolean;
735 createdAt: string;
736 timestampFormat: TimestampFormat;
737 onToggle: () => void;
738}) {
739 const gt = useGT();
740 return (
741 <WorkLogButton
742 aria-label={props.failed ? gt`${{ label: props.label }}, tool call failed` : props.label}
743 aria-expanded={props.expanded}
744 onClick={props.onToggle}
745 icon={
746 <ToolActivityIconView
747 icon={props.toolIcon}
748 fallbackName={props.iconName}
749 className="size-4 shrink-0 stroke-2 text-icon-muted"
750 muted
751 />
752 }
753 label={<span className="block truncate">{props.label}</span>}
754 trailing={
755 <TimelineRowTimestamp createdAt={props.createdAt} timestampFormat={props.timestampFormat} />
756 }
757 />
758 );