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

thread-work-log.tsx

1,472 lines51.1 KB

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