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

thread-work-log.tsx

1,371 lines47.3 KB

1import { QuestionAnswerHistory } from "./QuestionAnswerHistory";
2import {
3 getQuestionAnswerPreview,
4 hasQuestionAnswer,
5} from "@t3tools/client-runtime/work-log/user-input";
6import * as Haptics from "expo-haptics";
7import { Image } from "expo-image";
8import { type AppSymbolName, SymbolView } from "../../components/AppSymbol";
9import { MaskedView } from "@expo/ui/community/masked-view";
10import type { LegendListRef } from "@legendapp/list/react-native";
11import { AnimatedLegendList } from "@legendapp/list/reanimated";
12import { useIsFocused } from "@react-navigation/native";
13import {
14 memo,
15 useCallback,
16 useEffect,
17 useId,
18 useLayoutEffect,
19 useMemo,
20 useRef,
21 useState,
22 type ComponentProps,
23 type ReactNode,
24} from "react";
25import {
26 AccessibilityInfo,
27 AppState,
28 type ColorValue,
29 Pressable,
30 ScrollView,
31 StyleSheet,
32 View,
33} from "react-native";
34import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
35import type { EnvironmentId, ToolActivityIcon } from "@t3tools/contracts";
36import { toolActivityFaviconUrl } from "@t3tools/shared/favicon";
37​
38import { AppText as Text } from "../../components/AppText";
39import { T3Wordmark } from "../../components/T3Wordmark";
40import { cn } from "../../lib/cn";
41import { THREAD_WORK_ROW_MIN_HEIGHT, type deriveThreadWorkLogSizing } from "../../lib/layout";
42import {
43 type AgentSpawnSummary,
44 type ThreadFeedActivity,
45 workEntryRowLabel,
46} from "../../lib/threadActivity";
47import {
48 resolveThreadWorkGroupInitialScroll,
49 shouldFollowThreadWorkGroupAppend,
50 type ThreadWorkGroupScrollPosition,
51} from "./thread-feed-live-follow";
52import {
53 resolveWorkEntryToolPresentation,
54 type ToolGroupSummaryKind,
55 workEntryViewedImagePath,
56} from "@t3tools/client-runtime/work-log/presentation";
57import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
58import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText";
59import Animated, {
60 cancelAnimation,
61 Easing,
62 FadeIn,
63 FadeOut,
64 LinearTransition,
65 ReduceMotion,
66 useAnimatedStyle,
67 useSharedValue,
68 withDelay,
69 withRepeat,
70 withSequence,
71 withTiming,
72} from "react-native-reanimated";
73import { useAssetUrl } from "../../state/assets";
74​
75const SHIMMER_WIDTH = 72;
76const SHIMMER_SWEEP_MS = 1_350;
77const SHIMMER_PAUSE_MS = 1_450;
78const SHIMMER_ICON_AND_GAP_WIDTH = 30;
79export const THREAD_DISCLOSURE_TRANSITION_MS = 180;
80const WORK_LOG_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
81const WORK_LOG_DETAIL_ENTER_TRANSITION = FadeIn.duration(140);
82const WORK_LOG_DETAIL_EXIT_TRANSITION = FadeOut.duration(120);
83type WorkContentIcon = AppSymbolName | "browser" | "device" | "t3-code" | "pull-request";
84​
85function WorkLogIcon(props: {
86 readonly icon: WorkContentIcon;
87 readonly color: ColorValue;
88 readonly colorClassName?: string;
89 readonly highlighted?: boolean;
90}) {
91 const colorClassName = props.highlighted ? "accent-foreground" : props.colorClassName;
92 if (props.icon === "t3-code") {
93 return (
94 <T3Wordmark height={10} {...(colorClassName ? { colorClassName } : { color: props.color })} />
95 );
96 }
97 return (
98 <SymbolView
99 name={
100 props.icon === "pull-request"
101 ? "arrow.triangle.pull"
102 : props.icon === "browser"
103 ? { ios: "globe", android: "public" }
104 : props.icon === "device"
105 ? { ios: "iphone", android: "smartphone" }
106 : props.icon
107 }
108 size={14}
109 weight="medium"
110 {...(colorClassName ? { tintColorClassName: colorClassName } : { tintColor: props.color })}
111 type="monochrome"
112 />
113 );
115​
116export function ThreadDisclosureChevron(props: {
117 readonly expanded: boolean;
118 readonly collapsedDirection: "right" | "down";
119 readonly size: number;
120 readonly tintColor: ColorValue;
121}) {
122 const expandedAngle = props.collapsedDirection === "right" ? 90 : 180;
123 const rotation = useSharedValue(props.expanded ? expandedAngle : 0);
124​
125 useLayoutEffect(() => {
126 rotation.value = withTiming(props.expanded ? expandedAngle : 0, {
127 duration: THREAD_DISCLOSURE_TRANSITION_MS,
128 reduceMotion: ReduceMotion.System,
129 });
130 }, [expandedAngle, props.expanded, rotation]);
131​
132 const rotationStyle = useAnimatedStyle(() => ({
133 transform: [{ rotate: `${rotation.value}deg` }],
134 }));
135​
136 return (
137 <Animated.View
138 accessible={false}
139 accessibilityElementsHidden
140 importantForAccessibility="no-hide-descendants"
141 pointerEvents="none"
142 style={[{ width: props.size, height: props.size }, rotationStyle]}
143 >
144 <SymbolView
145 name={props.collapsedDirection === "right" ? "chevron.right" : "chevron.down"}
146 size={props.size}
147 tintColor={props.tintColor}
148 type="monochrome"
149 />
150 </Animated.View>
151 );
153​
154function ShimmerWorkContent(props: {
155 readonly textClassName?: string;
156 readonly compact?: boolean;
157 readonly environmentId?: EnvironmentId;
158 readonly highlighted: boolean;
159 readonly icon: WorkContentIcon;
160 readonly iconSubtleColor: ColorValue;
161 readonly label: string;
162 readonly onTextLayout?: ComponentProps<typeof Text>["onTextLayout"];
163 readonly showIcon: boolean;
164 readonly themeAppearance?: "light" | "dark";
165 readonly toolIcon?: ToolActivityIcon;
166}) {
167 return (
168 <View className="flex-row items-center gap-1.5">
169 {props.showIcon ? (
170 <View className="h-6 w-6 shrink-0 items-center justify-center">
171 {props.toolIcon && props.environmentId ? (
172 <ToolActivityIconView
173 environmentId={props.environmentId}
174 icon={props.toolIcon}
175 fallback={props.icon}
176 fallbackColor={props.iconSubtleColor}
177 themeAppearance={props.themeAppearance ?? "light"}
178 />
179 ) : (
180 <WorkLogIcon
181 icon={props.icon}
182 color={props.iconSubtleColor}
183 highlighted={props.highlighted}
184 />
185 )}
186 </View>
187 ) : null}
188 <Text
189 className={cn(
190 "min-w-0 shrink",
191 props.compact ? "text-xs" : "text-sm",
192 props.highlighted ? "text-foreground" : "text-foreground-muted",
193 props.textClassName,
194 )}
195 numberOfLines={1}
196 onTextLayout={props.onTextLayout}
197 >
198 {props.label}
199 </Text>
200 </View>
201 );
203​
204export function ShimmeringWorkContent(props: {
205 readonly className?: string;
206 readonly textClassName?: string;
207 /** Secondary line: no icon slot, caption size. */
208 readonly compact?: boolean;
209 readonly environmentId?: EnvironmentId;
210 readonly icon: WorkContentIcon;
211 readonly iconSubtleColor: ColorValue;
212 readonly label: string;
213 readonly showIcon: boolean;
214 readonly themeAppearance?: "light" | "dark";
215 readonly toolIcon?: ToolActivityIcon;
216}) {
217 const [availableWidth, setAvailableWidth] = useState(0);
218 const [textWidth, setTextWidth] = useState(0);
219 const [appIsActive, setAppIsActive] = useState(AppState.currentState === "active");
220 const [reducedMotion, setReducedMotion] = useState(true);
221 const screenIsFocused = useIsFocused();
222 const progress = useSharedValue(0);
223 const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`;
224 const contentWidth = Math.min(
225 availableWidth,
226 (props.showIcon ? SHIMMER_ICON_AND_GAP_WIDTH : 0) + Math.ceil(textWidth),
227 );
228​
229 useEffect(() => {
230 const subscription = AppState.addEventListener("change", (state) => {
231 setAppIsActive(state === "active");
232 });
233 return () => subscription.remove();
234 }, []);
235​
236 useEffect(() => {
237 void AccessibilityInfo.isReduceMotionEnabled().then(setReducedMotion);
238 const subscription = AccessibilityInfo.addEventListener(
239 "reduceMotionChanged",
240 setReducedMotion,
241 );
242 return () => subscription.remove();
243 }, []);
244​
245 useEffect(() => {
246 cancelAnimation(progress);
247 progress.value = 0;
248 if (contentWidth <= 0 || reducedMotion || !appIsActive || !screenIsFocused) return;
249​
250 progress.value = withRepeat(
251 withSequence(
252 withTiming(1, {
253 duration: SHIMMER_SWEEP_MS,
254 easing: Easing.linear,
255 reduceMotion: ReduceMotion.Never,
256 }),
257 withDelay(
258 SHIMMER_PAUSE_MS,
259 withTiming(0, { duration: 0, reduceMotion: ReduceMotion.Never }),
260 ),
261 ),
262 -1,
263 false,
264 undefined,
265 ReduceMotion.Never,
266 );
267 return () => cancelAnimation(progress);
268 }, [appIsActive, contentWidth, progress, reducedMotion, screenIsFocused]);
269​
270 const sweepStyle = useAnimatedStyle(() => ({
271 transform: [{ translateX: -SHIMMER_WIDTH + progress.value * (contentWidth + SHIMMER_WIDTH) }],
272 }));
273 const counterSweepStyle = useAnimatedStyle(() => ({
274 transform: [{ translateX: SHIMMER_WIDTH - progress.value * (contentWidth + SHIMMER_WIDTH) }],
275 }));
276​
277 return (
278 <View
279 className={cn("min-w-0 flex-1 overflow-hidden", props.className)}
280 onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)}
281 >
282 <ShimmerWorkContent
283 textClassName={props.textClassName}
284 compact={props.compact}
285 environmentId={props.environmentId}
286 highlighted={false}
287 icon={props.icon}
288 iconSubtleColor={props.iconSubtleColor}
289 label={props.label}
290 showIcon={props.showIcon}
291 themeAppearance={props.themeAppearance}
292 toolIcon={props.toolIcon}
293 onTextLayout={(event) => setTextWidth(event.nativeEvent.lines[0]?.width ?? 0)}
294 />
295 {!reducedMotion && appIsActive && screenIsFocused && contentWidth > 0 ? (
296 <Animated.View
297 className="absolute inset-y-0 left-0 overflow-hidden"
298 pointerEvents="none"
299 accessible={false}
300 accessibilityElementsHidden
301 importantForAccessibility="no-hide-descendants"
302 style={[{ width: SHIMMER_WIDTH }, sweepStyle]}
303 >
304 <MaskedView
305 style={StyleSheet.absoluteFill}
306 maskElement={
307 <Svg width="100%" height="100%">
308 <Defs>
309 <LinearGradient id={gradientId} x1="0%" x2="100%" y1="0%" y2="0%">
310 <Stop offset="0" stopColor="white" stopOpacity={0} />
311 <Stop offset="0.15" stopColor="white" stopOpacity={0.12} />
312 <Stop offset="0.35" stopColor="white" stopOpacity={0.55} />
313 <Stop offset="0.5" stopColor="white" stopOpacity={1} />
314 <Stop offset="0.65" stopColor="white" stopOpacity={0.55} />
315 <Stop offset="0.85" stopColor="white" stopOpacity={0.12} />
316 <Stop offset="1" stopColor="white" stopOpacity={0} />
317 </LinearGradient>
318 </Defs>
319 <Rect width="100%" height="100%" fill={`url(#${gradientId})`} />
320 </Svg>
321 }
322 >
323 <Animated.View style={[{ width: availableWidth }, counterSweepStyle]}>
324 <ShimmerWorkContent
325 textClassName={props.textClassName}
326 compact={props.compact}
327 environmentId={props.environmentId}
328 highlighted
329 icon={props.icon}
330 iconSubtleColor={props.iconSubtleColor}
331 label={props.label}
332 showIcon={props.showIcon}
333 themeAppearance={props.themeAppearance}
334 toolIcon={props.toolIcon}
335 />
336 </Animated.View>
337 </MaskedView>
338 </Animated.View>
339 ) : null}
340 </View>
341 );
343​
344function workRowSymbolName(icon: ThreadFeedActivity["icon"]): AppSymbolName {
345 switch (icon) {
346 case "agent":
347 return { ios: "sparkles", android: "auto_awesome" };
348 case "alert":
349 return { ios: "exclamationmark.triangle", android: "error" };
350 case "browser":
351 return { ios: "safari", android: "public" };
352 case "check":
353 return { ios: "checkmark", android: "check" };
354 case "command":
355 return { ios: "terminal", android: "terminal" };
356 case "computer":
357 return { ios: "desktopcomputer", android: "desktop_windows" };
358 case "edit":
359 return { ios: "square.and.pencil", android: "edit" };
360 case "eye":
361 return { ios: "eye", android: "visibility" };
362 case "globe":
363 return { ios: "globe", android: "public" };
364 case "hammer":
365 return { ios: "hammer", android: "construction" };
366 case "lock":
367 return { ios: "lock", android: "lock" };
368 case "message":
369 return { ios: "bubble.left", android: "chat_bubble" };
370 case "warning":
371 return { ios: "xmark", android: "close" };
372 case "wrench":
373 return { ios: "wrench", android: "build" };
374 case "zap":
375 return { ios: "bolt", android: "bolt" };
376 }
378​
379// Entering fades only for rows created moments ago: rows remount whenever the
380// list scrolls them back into view, and old rows must not replay an entrance.
381const FRESH_ROW_WINDOW_MS = 3_000;
382function isFreshRow(createdAt: string): boolean {
383 const timestamp = Date.parse(createdAt);
384 return Number.isFinite(timestamp) && Date.now() - timestamp < FRESH_ROW_WINDOW_MS;
386​
387// The minimum matches min-h-8 below. Exact sizing is disabled when native
388// accessibility scaling can make the single-line text taller than that minimum.
389const WORK_ROW_HEIGHT = THREAD_WORK_ROW_MIN_HEIGHT;
390const WORK_ROW_GAP = 1; // gap-px
391const WORK_LOG_BOTTOM_MARGIN = 3.5; // mb-1 with the mobile 14px rem
392const WORK_GROUP_MAX_HEIGHT = 256;
393const WORK_GROUP_EDGE_FADE_HEIGHT = 12;
394​
395export const WORK_GROUP_TOGGLE_HEIGHT = THREAD_WORK_ROW_MIN_HEIGHT;
396​
397function workLogRowsHeight(
398 activities: ReadonlyArray<ThreadFeedActivity>,
399 rowHeight = WORK_ROW_HEIGHT,
400): number {
401 return activities.length * rowHeight + Math.max(0, activities.length - 1) * WORK_ROW_GAP;
403​
404export function collapsedWorkLogHeight(activities: ReadonlyArray<ThreadFeedActivity>): number {
405 if (activities.length === 0) {
406 return 0;
407 }
408 const height = workLogRowsHeight(activities);
409 return (
410 WORK_LOG_BOTTOM_MARGIN +
411 (activities[0]?.groupedToolDetail ? Math.min(height, WORK_GROUP_MAX_HEIGHT) : height)
412 );
414​
415interface ThreadWorkLogProps {
416 readonly activities: ReadonlyArray<ThreadFeedActivity>;
417 readonly anchorKey: string;
418 readonly environmentId: EnvironmentId;
419 readonly copiedRowId: string | null;
420 readonly expandedRows: Readonly<Record<string, boolean>>;
421 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
422 readonly scrollPositions: Map<string, ThreadWorkGroupScrollPosition>;
423 readonly iconSubtleColor: ColorValue;
424 /** Feed background, painted as the scroll-edge fade over a long group. */
425 readonly edgeFadeColor: string;
426 readonly themeAppearance: "light" | "dark";
427 readonly onCopyRow: (rowId: string, value: string) => void;
428 readonly onToggleRow: (rowId: string, anchorKey: string) => void;
429 readonly renderImage: MarkdownImageRenderer;
431​
432export function ThreadWorkLog(props: ThreadWorkLogProps) {
433 const renderRow = useCallback(
434 (row: ThreadFeedActivity) => (
435 <ThreadWorkLogRow
436 key={row.id}
437 row={row}
438 anchorKey={props.anchorKey}
439 copied={props.copiedRowId === row.id}
440 expanded={props.expandedRows[row.id] ?? false}
441 environmentId={props.environmentId}
442 iconSubtleColor={props.iconSubtleColor}
443 onCopyRow={props.onCopyRow}
444 onToggleRow={props.onToggleRow}
445 renderImage={props.renderImage}
446 themeAppearance={props.themeAppearance}
447 />
448 ),
449 [
450 props.anchorKey,
451 props.copiedRowId,
452 props.expandedRows,
453 props.environmentId,
454 props.iconSubtleColor,
455 props.onCopyRow,
456 props.onToggleRow,
457 props.renderImage,
458 props.themeAppearance,
459 ],
460 );
461​
462 if (props.activities.length === 0) {
463 return null;
464 }
465​
466 return (
467 <View className="-mx-1 mb-1 px-1 py-0">
468 {props.activities[0]?.groupedToolDetail ? (
469 <ThreadWorkGroupList
470 activities={props.activities}
471 edgeFadeColor={props.edgeFadeColor}
472 expandedRows={props.expandedRows}
473 groupId={props.anchorKey}
474 rowSizing={props.rowSizing}
475 scrollPositions={props.scrollPositions}
476 renderRow={renderRow}
477 />
478 ) : (
479 <View className="gap-px">{props.activities.map(renderRow)}</View>
480 )}
481 </View>
482 );
484​
485function ThreadWorkGroupList(props: {
486 readonly activities: ReadonlyArray<ThreadFeedActivity>;
487 readonly edgeFadeColor: string;
488 readonly expandedRows: Readonly<Record<string, boolean>>;
489 readonly groupId: string;
490 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
491 readonly scrollPositions: Map<string, ThreadWorkGroupScrollPosition>;
492 readonly renderRow: (row: ThreadFeedActivity) => ReactNode;
493}) {
494 const estimatedRowsHeight = workLogRowsHeight(
495 props.activities,
496 props.rowSizing.estimatedRowHeight,
497 );
498 const [initialPosition] = useState(() => {
499 const position = props.scrollPositions.get(props.groupId);
500 return props.activities.some((row) => row.id === position?.rowId) ? position : undefined;
501 });
502 const [initialScrollIndex] = useState(() =>
503 resolveThreadWorkGroupInitialScroll(props.activities, initialPosition),
504 );
505 const [restoringPosition, setRestoringPosition] = useState(initialScrollIndex !== undefined);
506 const listRef = useRef<LegendListRef>(null);
507 const loadedRef = useRef(false);
508 const userScrollingRef = useRef(false);
509 const pendingAppendHeightRef = useRef<number | null>(null);
510 const previousContent = useRef({
511 rows: props.activities,
512 height: Math.max(estimatedRowsHeight, initialPosition?.contentHeight ?? 0),
513 expandedRows: props.expandedRows,
514 });
515 const [measuredContent, setMeasuredContent] = useState(() => ({
516 height: Math.max(estimatedRowsHeight, initialPosition?.contentHeight ?? 0),
517 rowCount: props.activities.length,
518 }));
519 const contentHeight = Math.max(
520 1,
521 measuredContent.height +
522 Math.max(0, props.activities.length - measuredContent.rowCount) *
523 (props.rowSizing.estimatedRowHeight + WORK_ROW_GAP),
524 );
525 const height = Math.min(contentHeight, WORK_GROUP_MAX_HEIGHT);
526 const scrollOffset = useSharedValue(initialPosition?.scrollOffset ?? 0);
527 const sharedValues = useMemo(() => ({ scrollOffset }), [scrollOffset]);
528​
529 // Each edge fades only while content continues past it. Scroll offset stays
530 // on the UI thread; only content-size changes update React state.
531 const topFadeStyle = useAnimatedStyle(() => ({
532 opacity: Math.min(1, Math.max(0, scrollOffset.value) / WORK_GROUP_EDGE_FADE_HEIGHT),
533 }));
534 const bottomFadeStyle = useAnimatedStyle(() => ({
535 opacity: Math.min(
536 1,
537 Math.max(0, contentHeight - height - scrollOffset.value) / WORK_GROUP_EDGE_FADE_HEIGHT,
538 ),
539 }));
540 const rememberPosition = useCallback(() => {
541 if (!loadedRef.current) return;
542 const state = listRef.current?.getState();
543 const position = state && resolveWorkGroupScrollAnchor(state);
544 if (!state || !position) return;
545 props.scrollPositions.set(props.groupId, {
546 ...position,
547 contentHeight: state.contentLength,
548 });
549 }, [props.groupId, props.scrollPositions]);
550 const finishPendingAppend = useCallback(() => {
551 const targetHeight = pendingAppendHeightRef.current;
552 const state = listRef.current?.getState();
553 if (
554 targetHeight !== null &&
555 state &&
556 !userScrollingRef.current &&
557 Math.abs(state.scrollLength - targetHeight) <= 1
558 ) {
559 pendingAppendHeightRef.current = null;
560 void listRef.current?.scrollToEnd({ animated: false });
561 }
562 }, []);
563 const onContentSizeChange = useCallback(
564 (nextHeight: number) => {
565 const previous = previousContent.current;
566 const detailsChanged = previous.expandedRows !== props.expandedRows;
567 const followAppend =
568 loadedRef.current &&
569 shouldFollowThreadWorkGroupAppend({
570 previousRows: previous.rows,
571 rows: props.activities,
572 previousContentHeight: previous.height,
573 contentHeight: nextHeight,
574 viewportHeight: Math.min(previous.height, WORK_GROUP_MAX_HEIGHT),
575 scrollOffset: scrollOffset.value,
576 detailsChanged,
577 userScrolling: userScrollingRef.current,
578 });
579 previousContent.current = {
580 rows: props.activities,
581 height: nextHeight,
582 expandedRows: props.expandedRows,
583 };
584 setMeasuredContent((current) =>
585 current.height === nextHeight && current.rowCount === props.activities.length
586 ? current
587 : { height: nextHeight, rowCount: props.activities.length },
588 );
589 // Follow new calls only, never a detail toggle or a growing tool result.
590 if (followAppend) {
591 pendingAppendHeightRef.current = Math.min(nextHeight, WORK_GROUP_MAX_HEIGHT);
592 } else if (detailsChanged || userScrollingRef.current || previous.rows !== props.activities) {
593 pendingAppendHeightRef.current = null;
594 } else if (pendingAppendHeightRef.current !== null) {
595 pendingAppendHeightRef.current = Math.min(nextHeight, WORK_GROUP_MAX_HEIGHT);
596 }
597 // A short group can grow its viewport on this append. Wait for that
598 // layout before calculating the end offset, rather than jumping twice.
599 finishPendingAppend();
600 rememberPosition();
601 },
602 [props.activities, props.expandedRows, scrollOffset, finishPendingAppend, rememberPosition],
603 );
604 // The native ScrollView reports its content size a frame or more after
605 // LegendList has laid the rows out, so a detail toggle rendered the group
606 // at its old height while the rows below already moved. Read the size
607 // LegendList computes on the JS thread instead; it settles in the same
608 // commit as the row measurement that changed it.
609 const onContentSizeChangeRef = useRef(onContentSizeChange);
610 useLayoutEffect(() => {
611 onContentSizeChangeRef.current = onContentSizeChange;
612 }, [onContentSizeChange]);
613 const subscribeToContentSize = useCallback((list: LegendListRef | null) => {
614 listRef.current = list;
615 if (!list) return;
616 const unsubscribe = list.getState().listen("totalSize", () => {
617 onContentSizeChangeRef.current(list.getState().contentLength);
618 });
619 onContentSizeChangeRef.current(list.getState().contentLength);
620 return unsubscribe;
621 }, []);
622 const getFixedItemSize = useCallback(
623 (row: ThreadFeedActivity, index: number) =>
624 props.expandedRows[row.id] || props.rowSizing.fixedRowHeight === undefined
625 ? undefined
626 : props.rowSizing.fixedRowHeight + (index < props.activities.length - 1 ? WORK_ROW_GAP : 0),
627 [props.activities.length, props.expandedRows, props.rowSizing.fixedRowHeight],
628 );
629 const renderItem = useCallback(
630 ({ item, index }: { item: ThreadFeedActivity; index: number }) => (
631 <View className={index < props.activities.length - 1 ? "pb-px" : undefined}>
632 {props.renderRow(item)}
633 </View>
634 ),
635 [props.activities.length, props.renderRow],
636 );
637​
638 return (
639 <View style={{ height, overflow: "hidden" }}>
640 <AnimatedLegendList
641 ref={subscribeToContentSize}
642 data={props.activities}
643 keyExtractor={workLogRowKey}
644 estimatedItemSize={props.rowSizing.estimatedRowHeight + WORK_ROW_GAP}
645 getFixedItemSize={getFixedItemSize}
646 initialScrollIndex={initialScrollIndex}
647 // Bootstrap overscan is only 50px. An offset inside expanded detail can
648 // otherwise leave its own row unmeasured until after scroll restoration.
649 alwaysRender={
650 restoringPosition && initialPosition ? { keys: [initialPosition.rowId] } : undefined
651 }
652 recycleItems={false}
653 extraData={props.renderRow}
654 renderItem={renderItem}
655 sharedValues={sharedValues}
656 onLayout={finishPendingAppend}
657 onLoad={() => {
658 loadedRef.current = true;
659 setRestoringPosition(false);
660 rememberPosition();
661 }}
662 onScroll={rememberPosition}
663 onScrollBeginDrag={() => {
664 userScrollingRef.current = true;
665 pendingAppendHeightRef.current = null;
666 }}
667 onScrollEndDrag={() => {
668 userScrollingRef.current = false;
669 }}
670 onMomentumScrollBegin={() => {
671 userScrollingRef.current = true;
672 pendingAppendHeightRef.current = null;
673 }}
674 onMomentumScrollEnd={() => {
675 userScrollingRef.current = false;
676 rememberPosition();
677 }}
678 maintainVisibleContentPosition
679 nestedScrollEnabled
680 directionalLockEnabled
681 showsVerticalScrollIndicator
682 scrollsToTop={false}
683 bounces={false}
684 keyboardShouldPersistTaps="handled"
685 style={{ height }}
686 />
687 <Animated.View
688 pointerEvents="none"
689 className="absolute inset-x-0 top-0"
690 style={[{ height: WORK_GROUP_EDGE_FADE_HEIGHT }, topFadeStyle]}
691 >
692 <EdgeFade color={props.edgeFadeColor} direction="down" />
693 </Animated.View>
694 <Animated.View
695 pointerEvents="none"
696 className="absolute inset-x-0 bottom-0"
697 style={[{ height: WORK_GROUP_EDGE_FADE_HEIGHT }, bottomFadeStyle]}
698 >
699 <EdgeFade color={props.edgeFadeColor} direction="up" />
700 </Animated.View>
701 </View>
702 );
704​
705/** A screen-colored gradient painted over the list edge that still has content past it. */
706function EdgeFade(props: { readonly color: string; readonly direction: "up" | "down" }) {
707 const gradientId = `work-group-fade-${useId().replaceAll(":", "")}`;
708 return (
709 <Svg width="100%" height="100%">
710 <Defs>
711 <LinearGradient id={gradientId} x1="0%" x2="0%" y1="0%" y2="100%">
712 <Stop
713 offset={0}
714 stopColor={props.color}
715 stopOpacity={props.direction === "down" ? 1 : 0}
716 />
717 <Stop
718 offset={1}
719 stopColor={props.color}
720 stopOpacity={props.direction === "down" ? 0 : 1}
721 />
722 </LinearGradient>
723 </Defs>
724 <Rect width="100%" height="100%" fill={`url(#${gradientId})`} />
725 </Svg>
726 );
728​
729function workLogRowKey(row: ThreadFeedActivity): string {
730 return row.id;
732​
733const ThreadWorkLogRow = memo(function ThreadWorkLogRow(
734 props: Omit<
735 ThreadWorkLogProps,
736 | "activities"
737 | "copiedRowId"
738 | "edgeFadeColor"
739 | "expandedRows"
740 | "rowSizing"
741 | "scrollPositions"
742 > & {
743 readonly row: ThreadFeedActivity;
744 readonly copied: boolean;
745 readonly expanded: boolean;
746 },
747) {
748 const { row, expanded } = props;
749 const canExpand = row.canExpand;
750 const fullDetail = expanded ? row.getFullDetail() : null;
751 const viewedImagePath = workEntryViewedImagePath(row.workEntry);
752 const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry);
753 const previewText = workEntryRowLabel(row.workEntry);
754 const answerPreview = row.workEntry.questionAnswer
755 ? getQuestionAnswerPreview(row.workEntry.questionAnswer)
756 : null;
757 const accessiblePreview = [previewText, answerPreview].filter(Boolean).join(": ");
758 const displayText = workEntryRowLabel(row.workEntry, expanded);
759 const iconIsDestructive = row.icon === "alert" || row.icon === "warning";
760 const failed = row.status === "failure";
761 const toolIcon = row.workEntry.toolIcon ?? row.workEntry.toolSource?.icon;
762 const icon = toolPresentation?.icon ?? workRowSymbolName(row.icon);
763​
764 return (
765 <Animated.View
766 layout={WORK_LOG_LAYOUT_TRANSITION}
767 className="overflow-hidden"
768 {...(isFreshRow(row.createdAt) ? { entering: FadeIn.duration(200) } : {})}
769 >
770 <Pressable
771 accessibilityRole={canExpand ? "button" : undefined}
772 accessibilityLabel={failed ? `${accessiblePreview}, tool call failed` : accessiblePreview}
773 accessibilityHint={
774 canExpand
775 ? `Double tap to ${expanded ? "hide" : "show"} full details. Long press to copy.`
776 : "Long press to copy."
777 }
778 accessibilityState={canExpand ? { expanded } : undefined}
779 hitSlop={4}
780 onPress={() => {
781 if (canExpand) {
782 void Haptics.selectionAsync();
783 props.onToggleRow(row.id, props.anchorKey);
784 }
785 }}
786 onLongPress={() => props.onCopyRow(row.id, row.getCopyText())}
787 className="rounded-md px-0.5 py-0 active:bg-subtle"
788 >
789 <View className="min-h-8 flex-row items-center gap-1.5">
790 {row.live && !expanded ? (
791 <ShimmeringWorkContent
792 environmentId={props.environmentId}
793 icon={icon}
794 iconSubtleColor={props.iconSubtleColor}
795 label={displayText}
796 showIcon
797 themeAppearance={props.themeAppearance}
798 toolIcon={toolIcon}
799 />
800 ) : (
801 <>
802 <View className="h-6 w-6 shrink-0 items-center justify-center">
803 {toolIcon ? (
804 <ToolActivityIconView
805 environmentId={props.environmentId}
806 icon={toolIcon}
807 fallback={icon}
808 fallbackColor={props.iconSubtleColor}
809 themeAppearance={props.themeAppearance}
810 />
811 ) : (
812 <WorkLogIcon
813 icon={icon}
814 color={props.iconSubtleColor}
815 colorClassName={
816 iconIsDestructive
817 ? "accent-adaptive-rose-600-400"
818 : failed
819 ? "accent-danger-foreground/40"
820 : undefined
821 }
822 />
823 )}
824 </View>
825 <Text
826 className={cn(
827 "min-w-0 flex-1 text-sm text-foreground-muted",
828 iconIsDestructive && "font-t3-medium text-adaptive-rose-600-400",
829 )}
830 numberOfLines={expanded ? undefined : 1}
831 >
832 {displayText}
833 {answerPreview ? (
834 <Text
835 className={
836 !expanded &&
837 row.workEntry.questionAnswer &&
838 hasQuestionAnswer(row.workEntry.questionAnswer)
839 ? "text-foreground"
840 : "text-foreground-subtle"
841 }
842 >{` ${answerPreview}`}</Text>
843 ) : null}
844 </Text>
845 </>
846 )}
847​
848 <View className="shrink-0 flex-row items-center gap-px">
849 {props.copied ? (
850 <Text className="pr-1 font-t3-medium text-3xs text-adaptive-emerald-600-400">
851 Copied
852 </Text>
853 ) : null}
854 {failed && toolIcon !== undefined ? (
855 <View
856 className="h-4 w-4 items-center justify-center"
857 accessibilityElementsHidden
858 importantForAccessibility="no-hide-descendants"
859 >
860 <SymbolView
861 name="xmark"
862 size={11}
863 tintColorClassName="accent-danger-foreground/40"
864 type="monochrome"
865 />
866 </View>
867 ) : null}
868 <View className="h-4 w-4 items-center justify-center">
869 {canExpand ? (
870 <ThreadDisclosureChevron
871 expanded={expanded}
872 collapsedDirection="down"
873 size={11}
874 tintColor={props.iconSubtleColor}
875 />
876 ) : null}
877 </View>
878 </View>
879 </View>
880 </Pressable>
881​
882 {expanded && (fullDetail || viewedImagePath || row.workEntry.questionAnswer) ? (
883 <Animated.View
884 entering={WORK_LOG_DETAIL_ENTER_TRANSITION}
885 exiting={WORK_LOG_DETAIL_EXIT_TRANSITION}
886 layout={WORK_LOG_LAYOUT_TRANSITION}
887 className="ml-7 border-l border-border pb-1 pl-3 pt-0.5"
888 >
889 {row.workEntry.questionAnswer ? (
890 <QuestionAnswerHistory
891 environmentId={props.environmentId}
892 answer={row.workEntry.questionAnswer}
893 />
894 ) : null}
895 {viewedImagePath ? (
896 <View className="pb-1.5">
897 {props.renderImage({ href: viewedImagePath, alt: null, title: null })}
898 </View>
899 ) : null}
900 <ScrollView
901 nestedScrollEnabled
902 directionalLockEnabled
903 showsVerticalScrollIndicator
904 className="max-h-60"
905 contentContainerStyle={{ paddingRight: 8 }}
906 >
907 <Text selectable className="font-mono text-2xs leading-normal text-foreground-muted">
908 {fullDetail}
909 </Text>
910 </ScrollView>
911 </Animated.View>
912 ) : null}
913 </Animated.View>
914 );
915});
916​
917export function ThreadWorkGroupToggle(props: {
918 readonly environmentId: EnvironmentId;
919 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
920 readonly expanded: boolean;
921 readonly hiddenCount: number;
922 readonly iconSubtleColor: import("react-native").ColorValue;
923 readonly summary: string;
924 readonly summaryKind: ToolGroupSummaryKind;
925 readonly summaryToolIcon?: "browser" | "device" | "t3-code" | "pull-request" | "brain";
926 readonly themeAppearance: "light" | "dark";
927 readonly toolSurface?: import("@t3tools/contracts").ToolActivitySurface;
928 readonly toolIcon?: ToolActivityIcon;
929 readonly hasFailure: boolean;
930 readonly shimmer: boolean;
931 readonly onToggle: () => void;
932}) {
933 const accessibilityLabel = props.hasFailure
934 ? `${props.summary}, tool call failed`
935 : props.summary;
936 const icon =
937 props.summaryToolIcon ??
938 (props.toolSurface
939 ? workRowSymbolName(props.toolSurface)
940 : toolGroupSummarySymbolName(props.summaryKind));
941​
942 return (
943 <View className="-mx-1 px-1 py-0">
944 <Pressable
945 accessibilityRole="button"
946 accessibilityState={{ expanded: props.expanded }}
947 accessibilityLabel={accessibilityLabel}
948 accessibilityHint={`Double tap to ${props.expanded ? "hide" : "show"} ${props.hiddenCount} tool ${props.hiddenCount === 1 ? "call" : "calls"}.`}
949 hitSlop={4}
950 onPress={() => {
951 void Haptics.selectionAsync();
952 props.onToggle();
953 }}
954 className="min-h-8 flex-row items-center gap-1.5 rounded-md px-0.5 py-0 active:bg-subtle"
955 style={{ minHeight: props.rowSizing.estimatedRowHeight }}
956 >
957 {props.shimmer ? (
958 <ShimmeringWorkContent
959 key={props.rowSizing.textSizeKey}
960 environmentId={props.environmentId}
961 icon={icon}
962 iconSubtleColor={props.iconSubtleColor}
963 label={props.summary}
964 showIcon
965 themeAppearance={props.themeAppearance}
966 toolIcon={props.toolIcon}
967 />
968 ) : (
969 <>
970 <View className="h-6 w-6 items-center justify-center">
971 <ToolActivityIconView
972 environmentId={props.environmentId}
973 icon={props.toolIcon}
974 fallback={icon}
975 fallbackColor={props.iconSubtleColor}
976 themeAppearance={props.themeAppearance}
977 />
978 </View>
979 <Text
980 key={props.rowSizing.textSizeKey}
981 className="min-w-0 flex-1 text-sm text-foreground-muted"
982 numberOfLines={1}
983 >
984 {props.summary}
985 </Text>
986 </>
987 )}
988 <ThreadDisclosureChevron
989 expanded={props.expanded}
990 collapsedDirection="down"
991 size={11}
992 tintColor={props.iconSubtleColor}
993 />
994 </Pressable>
995 </View>
996 );
998​
999const AGENT_SPAWN_TONE_DOT_CLASS = {
1000 working: "bg-adaptive-sky-600-400",
1001 completed: "bg-adaptive-emerald-600-400",
1002 failed: "bg-adaptive-rose-600-400",
1003 stopped: "bg-foreground-muted",
1004} as const satisfies Record<AgentSpawnSummary["tone"], string>;
1005​
1006/**
1007 * A batch of spawned subagents. The status line updates in place as members
1008 * report progress; expanding lists each member. Text nodes carry keys tied to
1009 * the row identity only, so a progress tick re-renders the labels without
1010 * remounting the card (see the batch key in appendActivityGroupRows).
1011 */
1012export const ThreadAgentSpawnCard = memo(function ThreadAgentSpawnCard(props: {
1013 readonly summary: AgentSpawnSummary;
1014 readonly expanded: boolean;
1015 readonly iconSubtleColor: ColorValue;
1016 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
1017 readonly onToggle: () => void;
1018 readonly onCopy: () => void;
1019}) {
1020 const { summary, expanded } = props;
1021 const working = summary.tone === "working";
1022 const memberCount = summary.members.length;
1023 const canExpand = memberCount > 0;
1024 return (
1025 <Animated.View layout={WORK_LOG_LAYOUT_TRANSITION} className="-mx-1 mb-1 px-1">
1026 <Pressable
1027 accessibilityRole={canExpand ? "button" : undefined}
1028 accessibilityState={canExpand ? { expanded } : undefined}
1029 accessibilityLabel={`${summary.title}, ${summary.status}`}
1030 accessibilityHint={
1031 canExpand
1032 ? `Double tap to ${expanded ? "hide" : "show"} ${memberCount} ${memberCount === 1 ? "subagent" : "subagents"}. Long press to copy.`
1033 : "Long press to copy."
1035 hitSlop={4}
1036 onPress={() => {
1037 if (!canExpand) return;
1038 void Haptics.selectionAsync();
1039 props.onToggle();
1040 }}
1041 onLongPress={props.onCopy}
1042 className="rounded-xl border border-border-subtle bg-card px-2.5 py-2 active:bg-subtle"
1044 <View className="flex-row items-center gap-2">
1045 <View className="h-6 w-6 shrink-0 items-center justify-center">
1046 <SymbolView
1047 name={{ ios: "sparkles", android: "auto_awesome" }}
1048 size={14}
1049 weight="medium"
1050 tintColor={props.iconSubtleColor}
1051 type="monochrome"
1052 />
1053 </View>
1054 <View className="min-w-0 flex-1 gap-0.5">
1055 <Text
1056 key={props.rowSizing.textSizeKey}
1057 className="font-t3-medium text-sm text-foreground"
1058 numberOfLines={1}
1060 {summary.title}
1061 </Text>
1062 <View className="flex-row items-center gap-1.5">
1063 <View
1064 className={cn(
1065 "h-1.5 w-1.5 shrink-0 rounded-full",
1066 AGENT_SPAWN_TONE_DOT_CLASS[summary.tone],
1067 )}
1068 />
1069 {working ? (
1070 <ShimmeringWorkContent
1071 key={props.rowSizing.textSizeKey}
1072 compact
1073 icon="brain"
1074 iconSubtleColor={props.iconSubtleColor}
1075 label={summary.status}
1076 showIcon={false}
1077 />
1078 ) : (
1079 <Text className="min-w-0 flex-1 text-xs text-foreground-muted" numberOfLines={1}>
1080 {summary.status}
1081 </Text>
1082 )}
1083 </View>
1084 </View>
1085 {canExpand ? (
1086 <ThreadDisclosureChevron
1087 expanded={expanded}
1088 collapsedDirection="down"
1089 size={11}
1090 tintColor={props.iconSubtleColor}
1091 />
1092 ) : null}
1093 </View>
1094 {expanded && canExpand ? (
1095 <Animated.View
1096 entering={WORK_LOG_DETAIL_ENTER_TRANSITION}
1097 exiting={WORK_LOG_DETAIL_EXIT_TRANSITION}
1098 layout={WORK_LOG_LAYOUT_TRANSITION}
1099 className="ml-8 mt-1.5 gap-1.5 border-l border-border pl-3"
1101 {summary.members.map((member) => (
1102 <View key={member.title} className="gap-px">
1103 <View className="flex-row items-center gap-1.5">
1104 <View
1105 className={cn(
1106 "h-1.5 w-1.5 shrink-0 rounded-full",
1107 AGENT_SPAWN_TONE_DOT_CLASS[member.tone],
1108 )}
1109 />
1110 <Text className="min-w-0 flex-1 text-xs text-foreground" numberOfLines={1}>
1111 {member.title}
1112 </Text>
1113 <Text className="shrink-0 text-2xs text-foreground-muted">{member.status}</Text>
1114 </View>
1115 {member.detail ? (
1116 <Text
1117 selectable
1118 className="pl-3 font-mono text-2xs leading-normal text-foreground-muted"
1119 numberOfLines={expanded ? 6 : 1}
1121 {member.detail}
1122 </Text>
1123 ) : null}
1124 </View>
1125 ))}
1126 </Animated.View>
1127 ) : null}
1128 </Pressable>
1129 </Animated.View>
1130 );
1131});
1132​
1133export function ThreadThinkingRow(props: {
1134 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
1135 readonly iconSubtleColor: ColorValue;
1136}) {
1137 return (
1138 <View
1139 accessible
1140 accessibilityLabel="Thinking"
1141 className="-mx-1 min-h-8 flex-row items-center px-1.5 py-0"
1142 style={{ minHeight: props.rowSizing.estimatedRowHeight }}
1144 <ShimmeringWorkContent
1145 key={props.rowSizing.textSizeKey}
1146 icon="brain"
1147 iconSubtleColor={props.iconSubtleColor}
1148 label="Thinking"
1149 showIcon
1150 />
1151 </View>
1152 );
1154​
1155/**
1156 * A provider's thinking trace. Collapsed by default: reasoning is context for
1157 * the answer, not the answer. `expanded` lives on the feed so it survives row
1158 * recycling; `children` is the trace body and only mounts while open.
1159 */
1160export function ThreadReasoningRow(props: {
1161 readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
1162 readonly iconSubtleColor: ColorValue;
1163 readonly expanded: boolean;
1164 readonly label: string;
1165 readonly streaming: boolean;
1166 readonly onToggle: () => void;
1167 readonly children: ReactNode;
1168}) {
1169 return (
1170 <View className={cn("-mx-1 px-1 py-0", props.expanded && "pb-1.5")}>
1171 <Pressable
1172 accessibilityRole="button"
1173 accessibilityState={{ expanded: props.expanded }}
1174 accessibilityLabel={props.label}
1175 accessibilityHint={`Double tap to ${props.expanded ? "hide" : "show"} the thinking trace.`}
1176 hitSlop={4}
1177 onPress={() => {
1178 void Haptics.selectionAsync();
1179 props.onToggle();
1180 }}
1181 className="min-h-8 flex-row items-center gap-1.5 rounded-md px-0.5 py-0 active:bg-subtle"
1182 style={{ minHeight: props.rowSizing.estimatedRowHeight }}
1184 {props.streaming ? (
1185 <ShimmeringWorkContent
1186 key={props.rowSizing.textSizeKey}
1187 icon="brain"
1188 iconSubtleColor={props.iconSubtleColor}
1189 label={props.label}
1190 showIcon
1191 />
1192 ) : (
1193 <>
1194 <View className="h-6 w-6 shrink-0 items-center justify-center">
1195 <WorkLogIcon icon="brain" color={props.iconSubtleColor} />
1196 </View>
1197 <Text
1198 key={props.rowSizing.textSizeKey}
1199 className="min-w-0 flex-1 text-sm text-foreground-muted"
1200 numberOfLines={1}
1202 {props.label}
1203 </Text>
1204 </>
1205 )}
1206 <ThreadDisclosureChevron
1207 expanded={props.expanded}
1208 collapsedDirection="right"
1209 size={11}
1210 tintColor={props.iconSubtleColor}
1211 />
1212 </Pressable>
1213 {props.expanded ? (
1214 <Animated.View
1215 entering={WORK_LOG_DETAIL_ENTER_TRANSITION}
1216 exiting={WORK_LOG_DETAIL_EXIT_TRANSITION}
1217 layout={WORK_LOG_LAYOUT_TRANSITION}
1218 className="ml-7 mt-1 rounded-xl bg-subtle px-3 py-2"
1220 <ScrollView
1221 nestedScrollEnabled
1222 directionalLockEnabled
1223 showsVerticalScrollIndicator
1224 className="max-h-80"
1226 {props.children}
1227 </ScrollView>
1228 </Animated.View>
1229 ) : null}
1230 </View>
1231 );
1233​
1234function ToolActivityIconView(props: {
1235 readonly environmentId: EnvironmentId;
1236 readonly icon?: ToolActivityIcon;
1237 readonly fallback: WorkContentIcon;
1238 readonly fallbackColor: ColorValue;
1239 readonly themeAppearance: "light" | "dark";
1240}) {
1241 if (!props.icon) {
1242 return <WorkLogIcon icon={props.fallback} color={props.fallbackColor} />;
1244 if (props.icon._tag === "website") {
1245 const source = toolActivityFaviconUrl(props.icon, props.themeAppearance, 32);
1246 return source ? (
1247 <ToolActivityImage
1248 key={source}
1249 source={source}
1250 fallback={props.fallback}
1251 color={props.fallbackColor}
1252 themeAppearance={props.themeAppearance}
1253 />
1254 ) : (
1255 <WorkLogIcon icon={props.fallback} color={props.fallbackColor} />
1256 );
1258 if (props.icon._tag === "themed-logo") {
1259 const source =
1260 props.themeAppearance === "dark"
1261 ? (props.icon.logoUrlDark ?? props.icon.logoUrl)
1262 : props.icon.logoUrl;
1263 return (
1264 <ToolActivityImage
1265 key={source}
1266 source={source}
1267 fallback={props.fallback}
1268 color={props.fallbackColor}
1269 themeAppearance={props.themeAppearance}
1270 />
1271 );
1273 return (
1274 <NativeAppToolActivityIcon
1275 environmentId={props.environmentId}
1276 app={props.icon.app}
1277 fallback={props.fallback}
1278 color={props.fallbackColor}
1279 themeAppearance={props.themeAppearance}
1280 />
1281 );
1283​
1284function NativeAppToolActivityIcon(props: {
1285 readonly environmentId: EnvironmentId;
1286 readonly app: Extract<ToolActivityIcon, { readonly _tag: "native-app" }>["app"];
1287 readonly fallback: WorkContentIcon;
1288 readonly color: ColorValue;
1289 readonly themeAppearance: "light" | "dark";
1290}) {
1291 const source = useAssetUrl(props.environmentId, {
1292 _tag: "native-app-icon",
1293 app: props.app,
1294 });
1295 return source ? (
1296 <ToolActivityImage
1297 key={source}
1298 source={source}
1299 fallback={props.fallback}
1300 color={props.color}
1301 themeAppearance={props.themeAppearance}
1302 />
1303 ) : (
1304 <WorkLogIcon icon={props.fallback} color={props.color} />
1305 );
1307​
1308function ToolActivityImage(props: {
1309 readonly source: string;
1310 readonly fallback: WorkContentIcon;
1311 readonly color: ColorValue;
1312 readonly themeAppearance: "light" | "dark";
1313}) {
1314 const [loaded, setLoaded] = useState(false);
1315 const [failed, setFailed] = useState(false);
1316 return (
1317 <View className="h-4 w-4 items-center justify-center overflow-hidden rounded-[3px] bg-background">
1318 {!loaded || failed ? <WorkLogIcon icon={props.fallback} color={props.color} /> : null}
1319 {!failed ? (
1320 <View
1321 style={[
1322 StyleSheet.absoluteFill,
1323 props.themeAppearance === "light" ? { filter: [{ brightness: 0.6 }] } : undefined,
1324 ]}
1326 <Image
1327 source={props.source}
1328 cachePolicy="memory-disk"
1329 contentFit="contain"
1330 style={[StyleSheet.absoluteFill, { opacity: loaded ? 0.7 : 0 }]}
1331 onLoad={() => setLoaded(true)}
1332 onError={() => setFailed(true)}
1333 />
1334 </View>
1335 ) : null}
1336 </View>
1337 );
1339​
1340function toolGroupSummarySymbolName(kind: ToolGroupSummaryKind): AppSymbolName {
1341 switch (kind) {
1342 case "pull-request":
1343 case "link-pr":
1344 case "unlink-pr":
1345 case "list-prs":
1346 return "arrow.triangle.pull";
1347 case "read":
1348 return { ios: "eye", android: "visibility" };
1349 case "edit":
1350 return { ios: "square.and.pencil", android: "edit" };
1351 case "command":
1352 return { ios: "terminal", android: "terminal" };
1353 case "device":
1354 return { ios: "iphone", android: "smartphone" };
1355 case "browser":
1356 case "search":
1357 return { ios: "globe", android: "public" };
1358 case "code-search":
1359 return "magnifyingglass";
1360 case "other":
1361 return { ios: "wrench", android: "build" };
1362 case "agent-tool":
1363 return { ios: "sparkles", android: "auto_awesome" };
1364 case "tone-tool":
1365 return { ios: "bolt", android: "bolt" };
1366 case "dynamic-tool":
1367 case "update":
1368 case "mixed":
1369 return { ios: "hammer", android: "construction" };