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

TimelineWorkGroupRows.tsx

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