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