The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { Button } from "../../components/ui/Button"; |
| 2 | import { ThreadSubagentGroup } from "./thread-subagent-group"; |
| 3 | import { ProposedPlanCard } from "./ProposedPlanCard"; |
| 4 | import { |
| 5 | WorkLogLabel, |
| 6 | WorkLogBlock, |
| 7 | WorkLogRows, |
| 8 | WorkLogIconSlot, |
| 9 | WorkLogPressable, |
| 10 | } from "./work-log-layout"; |
| 11 | import { QuestionAnswerHistory } from "./QuestionAnswerHistory"; |
| 12 | import { McpSignInSheet, type McpSignInTarget } from "./McpSignInSheet"; |
| 13 | import { ThreadCommandOutput, useCommandOutputStreaming } from "./thread-command-output"; |
| 14 | import { |
| 15 | getQuestionAnswerPreview, |
| 16 | hasQuestionAnswer, |
| 17 | } from "@t3tools/client-runtime/work-log/user-input"; |
| 18 | import * as Haptics from "expo-haptics"; |
| 19 | import { T, useGT, useMessages } from "gt-react-native"; |
| 20 | import { Image } from "expo-image"; |
| 21 | import { type AppSymbolName, SymbolView } from "../../components/ui/AppSymbol"; |
| 22 | import { MaskedView } from "@expo/ui/community/masked-view"; |
| 23 | import type { LegendListRef } from "@legendapp/list/react-native"; |
| 24 | import { AnimatedLegendList } from "@legendapp/list/reanimated"; |
| 25 | import { useIsFocused } from "@react-navigation/native"; |
| 26 | import { |
| 27 | useEffect, |
| 28 | useId, |
| 29 | useLayoutEffect, |
| 30 | useMemo, |
| 31 | useRef, |
| 32 | useState, |
| 33 | type ComponentProps, |
| 34 | type ReactNode, |
| 35 | } from "react"; |
| 36 | import { |
| 37 | Animated as NativeAnimated, |
| 38 | type ColorValue, |
| 39 | Pressable, |
| 40 | ScrollView, |
| 41 | StyleSheet, |
| 42 | Text as RNText, |
| 43 | useAnimatedValue, |
| 44 | View, |
| 45 | } from "react-native"; |
| 46 | import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg"; |
| 47 | import { |
| 48 | ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE, |
| 49 | type EnvironmentId, |
| 50 | type RunId, |
| 51 | type ThreadId, |
| 52 | type ToolActivityIcon, |
| 53 | } from "@t3tools/contracts"; |
| 54 | import { useAtomValue } from "@effect/atom-react"; |
| 55 | import { Atom } from "effect/reactivity"; |
| 56 | import * as DateTime from "effect/DateTime"; |
| 57 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 58 | import { environmentThreadDetails, threadEnvironment } from "../../state/threads"; |
| 59 | import { useAtomCommand } from "../../state/use-atom-command"; |
| 60 | import { toolActivityFaviconUrl } from "@t3tools/shared/favicon"; |
| 61 | import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity"; |
| 62 | import { useMarkdownCodeHighlight } from "./markdownCodeHighlightState"; |
| 63 | import { highlightCommand, type HighlightedLines } from "../../lib/highlights"; |
| 64 | import { |
| 65 | commandHighlightLanguage, |
| 66 | withVisibleControlCharacters, |
| 67 | } from "@t3tools/client-runtime/work-log/command-label"; |
| 68 | |
| 69 | import { AppText as Text } from "../../components/ui/AppText"; |
| 70 | import { T3Wordmark } from "../../components/T3Wordmark"; |
| 71 | import { BrowserAppIcon } from "./BrowserAppIcon"; |
| 72 | import { useAppActive, useReduceMotionEnabled } from "../../lib/appState"; |
| 73 | import { cn } from "../../lib/cn"; |
| 74 | import { THREAD_WORK_ROW_MIN_HEIGHT, type deriveThreadWorkLogSizing } from "../../lib/layout"; |
| 75 | import { |
| 76 | formatItemFullDetail, |
| 77 | type ThreadFeedActivity, |
| 78 | workEntryRowLabel, |
| 79 | } from "../../lib/threadActivity"; |
| 80 | import { |
| 81 | isJsonToolText, |
| 82 | toolCallLines, |
| 83 | turnItemOutputImages, |
| 84 | turnItemOutputText, |
| 85 | } from "@t3tools/client-runtime/work-log/item-detail"; |
| 86 | import { useTurnItemDetail } from "../../state/queries"; |
| 87 | import { |
| 88 | resolveThreadWorkGroupInitialScroll, |
| 89 | type ThreadWorkGroupScrollPosition, |
| 90 | } from "./thread-feed-scroll-position"; |
| 91 | import { |
| 92 | resolveWorkEntryToolPresentation, |
| 93 | toolGroupAction, |
| 94 | type ToolGroupSummaryKind, |
| 95 | workEntryViewedImagePath, |
| 96 | } from "@t3tools/client-runtime/work-log/presentation"; |
| 97 | import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution"; |
| 98 | import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText"; |
| 99 | import type { FilePreviewSource } from "../../components/ui/FilePreviewModal"; |
| 100 | import { FilePreviewGallery } from "../../components/ui/FilePreviewGallery"; |
| 101 | import { ThreadMarkdownImage } from "./ThreadMarkdownImage"; |
| 102 | import Animated, { |
| 103 | FadeIn, |
| 104 | FadeOut, |
| 105 | LinearTransition, |
| 106 | ReduceMotion, |
| 107 | useAnimatedScrollHandler, |
| 108 | useAnimatedStyle, |
| 109 | useSharedValue, |
| 110 | withTiming, |
| 111 | } from "react-native-reanimated"; |
| 112 | import { useAssetUrl } from "../../state/assets"; |
| 113 | import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs"; |
| 114 | import { useOpenLinkedThread } from "./useOpenLinkedThread"; |
| 115 | import { startShimmerSteps } from "./work-shimmer-steps"; |
| 116 | |
| 117 | const SHIMMER_WIDTH = 72; |
| 118 | const SHIMMER_ICON_AND_GAP_WIDTH = 30; |
| 119 | export const THREAD_DISCLOSURE_TRANSITION_MS = 180; |
| 120 | const WORK_LOG_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS); |
| 121 | const WORK_LOG_DETAIL_ENTER_TRANSITION = FadeIn.duration(140); |
| 122 | const WORK_LOG_DETAIL_EXIT_TRANSITION = FadeOut.duration(120); |
| 123 | type WorkContentIcon = |
| 124 | | AppSymbolName |
| 125 | | "browser" |
| 126 | | "computer" |
| 127 | | "device" |
| 128 | | "t3-code" |
| 129 | | "pull-request"; |
| 130 | |
| 131 | function WorkLogIcon(props: { |
| 132 | readonly icon: WorkContentIcon; |
| 133 | readonly color: ColorValue; |
| 134 | readonly colorClassName?: string; |
| 135 | readonly highlighted?: boolean; |
| 136 | }) { |
| 137 | const colorClassName = props.highlighted ? "accent-foreground" : props.colorClassName; |
| 138 | if (props.icon === "t3-code") { |
| 139 | return ( |
| 140 | <T3Wordmark height={10} {...(colorClassName ? { colorClassName } : { color: props.color })} /> |
| 141 | ); |
| 142 | } |
| 143 | if (props.icon === "computer") { |
| 144 | return ( |
| 145 | <BrowserAppIcon |
| 146 | size={14} |
| 147 | {...(colorClassName ? { colorClassName } : { color: props.color })} |
| 148 | /> |
| 149 | ); |
| 150 | } |
| 151 | return ( |
| 152 | <SymbolView |
| 153 | name={ |
| 154 | props.icon === "pull-request" |
| 155 | ? PullRequestGlyph.pullRequest |
| 156 | : props.icon === "browser" |
| 157 | ? { ios: "globe", android: "public" } |
| 158 | : props.icon === "device" |
| 159 | ? { ios: "iphone", android: "smartphone" } |
| 160 | : props.icon |
| 161 | } |
| 162 | size={14} |
| 163 | weight="medium" |
| 164 | {...(colorClassName ? { tintColorClassName: colorClassName } : { tintColor: props.color })} |
| 165 | type="monochrome" |
| 166 | /> |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | export function ThreadDisclosureChevron(props: { |
| 171 | readonly expanded: boolean; |
| 172 | readonly collapsedDirection: "right" | "down"; |
| 173 | readonly size: number; |
| 174 | readonly tintColor: ColorValue; |
| 175 | }) { |
| 176 | const expandedAngle = props.collapsedDirection === "right" ? 90 : 180; |
| 177 | const rotation = useSharedValue(props.expanded ? expandedAngle : 0); |
| 178 | |
| 179 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- drives the chevron's Reanimated rotation value when the expanded state changes |
| 180 | useLayoutEffect(() => { |
| 181 | rotation.set( |
| 182 | withTiming(props.expanded ? expandedAngle : 0, { |
| 183 | duration: THREAD_DISCLOSURE_TRANSITION_MS, |
| 184 | reduceMotion: ReduceMotion.System, |
| 185 | }), |
| 186 | ); |
| 187 | }, [expandedAngle, props.expanded, rotation]); |
| 188 | |
| 189 | const rotationStyle = useAnimatedStyle(() => ({ |
| 190 | transform: [{ rotate: `${rotation.value}deg` }], |
| 191 | })); |
| 192 | |
| 193 | return ( |
| 194 | <Animated.View |
| 195 | accessible={false} |
| 196 | accessibilityElementsHidden |
| 197 | importantForAccessibility="no-hide-descendants" |
| 198 | pointerEvents="none" |
| 199 | style={[{ width: props.size, height: props.size }, rotationStyle]} |
| 200 | > |
| 201 | <SymbolView |
| 202 | name={props.collapsedDirection === "right" ? "chevron.right" : "chevron.down"} |
| 203 | size={props.size} |
| 204 | tintColor={props.tintColor} |
| 205 | type="monochrome" |
| 206 | /> |
| 207 | </Animated.View> |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | function ShimmerWorkContent(props: { |
| 212 | readonly textClassName?: string; |
| 213 | readonly compact?: boolean; |
| 214 | readonly environmentId?: EnvironmentId; |
| 215 | readonly highlighted: boolean; |
| 216 | readonly icon: WorkContentIcon; |
| 217 | readonly iconSubtleColor: ColorValue; |
| 218 | readonly label: string; |
| 219 | readonly onTextLayout?: ComponentProps<typeof Text>["onTextLayout"]; |
| 220 | readonly showIcon: boolean; |
| 221 | readonly themeAppearance?: "light" | "dark"; |
| 222 | readonly toolIcon?: ToolActivityIcon; |
| 223 | }) { |
| 224 | return ( |
| 225 | <View className="flex-row items-center gap-1.5"> |
| 226 | {props.showIcon ? ( |
| 227 | <View className="h-6 w-6 shrink-0 items-center justify-center"> |
| 228 | {props.toolIcon && props.environmentId ? ( |
| 229 | <ToolActivityIconView |
| 230 | environmentId={props.environmentId} |
| 231 | icon={props.toolIcon} |
| 232 | fallback={props.icon} |
| 233 | fallbackColor={props.iconSubtleColor} |
| 234 | themeAppearance={props.themeAppearance ?? "light"} |
| 235 | /> |
| 236 | ) : ( |
| 237 | <WorkLogIcon |
| 238 | icon={props.icon} |
| 239 | color={props.iconSubtleColor} |
| 240 | highlighted={props.highlighted} |
| 241 | /> |
| 242 | )} |
| 243 | </View> |
| 244 | ) : null} |
| 245 | <Text |
| 246 | className={cn( |
| 247 | "min-w-0 shrink", |
| 248 | props.compact ? "text-xs" : "text-sm", |
| 249 | props.highlighted ? "text-foreground" : "text-foreground-muted", |
| 250 | props.textClassName, |
| 251 | )} |
| 252 | numberOfLines={1} |
| 253 | onTextLayout={props.onTextLayout} |
| 254 | > |
| 255 | {props.label} |
| 256 | </Text> |
| 257 | </View> |
| 258 | ); |
| 259 | } |
| 260 | |
| 261 | export function ShimmeringWorkContent(props: { |
| 262 | readonly className?: string; |
| 263 | readonly textClassName?: string; |
| 264 | readonly compact?: boolean; |
| 265 | readonly environmentId?: EnvironmentId; |
| 266 | readonly icon: WorkContentIcon; |
| 267 | readonly iconSubtleColor: ColorValue; |
| 268 | readonly label: string; |
| 269 | readonly showIcon: boolean; |
| 270 | readonly themeAppearance?: "light" | "dark"; |
| 271 | readonly toolIcon?: ToolActivityIcon; |
| 272 | }) { |
| 273 | const [availableWidth, setAvailableWidth] = useState(0); |
| 274 | const [textWidth, setTextWidth] = useState(0); |
| 275 | const appIsActive = useAppActive(); |
| 276 | const reducedMotion = useReduceMotionEnabled(); |
| 277 | const screenIsFocused = useIsFocused(); |
| 278 | // Native from creation, so each setValue updates the view without a React render. |
| 279 | const progress = useAnimatedValue(0, { useNativeDriver: true }); |
| 280 | const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`; |
| 281 | const contentWidth = Math.min( |
| 282 | availableWidth, |
| 283 | (props.showIcon ? SHIMMER_ICON_AND_GAP_WIDTH : 0) + Math.ceil(textWidth), |
| 284 | ); |
| 285 | |
| 286 | // Uses a native Animated value instead of Reanimated, whose per-frame commits |
| 287 | // starve React's while commit pausing is disabled (package.json). See |
| 288 | // docs/internals/performance-regressions.md. |
| 289 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- steps the native shimmer value on timers while visible and active, and stops them on cleanup |
| 290 | useEffect(() => { |
| 291 | progress.setValue(0); |
| 292 | if (contentWidth <= 0 || reducedMotion || !appIsActive || !screenIsFocused) return; |
| 293 | return startShimmerSteps(progress); |
| 294 | }, [appIsActive, contentWidth, progress, reducedMotion, screenIsFocused]); |
| 295 | |
| 296 | // The React Compiler memoizes these, so re-renders don't rebuild the native |
| 297 | // animation nodes. |
| 298 | const sweepTranslateX = progress.interpolate({ |
| 299 | inputRange: [0, 1], |
| 300 | outputRange: [-SHIMMER_WIDTH, contentWidth], |
| 301 | }); |
| 302 | const counterSweepTranslateX = progress.interpolate({ |
| 303 | inputRange: [0, 1], |
| 304 | outputRange: [SHIMMER_WIDTH, -contentWidth], |
| 305 | }); |
| 306 | |
| 307 | return ( |
| 308 | <View |
| 309 | className={cn("min-w-0 flex-1 overflow-hidden", props.className)} |
| 310 | onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)} |
| 311 | > |
| 312 | <ShimmerWorkContent |
| 313 | textClassName={props.textClassName} |
| 314 | compact={props.compact} |
| 315 | environmentId={props.environmentId} |
| 316 | highlighted={false} |
| 317 | icon={props.icon} |
| 318 | iconSubtleColor={props.iconSubtleColor} |
| 319 | label={props.label} |
| 320 | showIcon={props.showIcon} |
| 321 | themeAppearance={props.themeAppearance} |
| 322 | toolIcon={props.toolIcon} |
| 323 | onTextLayout={(event) => setTextWidth(event.nativeEvent.lines[0]?.width ?? 0)} |
| 324 | /> |
| 325 | {!reducedMotion && appIsActive && screenIsFocused && contentWidth > 0 ? ( |
| 326 | <NativeAnimated.View |
| 327 | pointerEvents="none" |
| 328 | accessible={false} |
| 329 | accessibilityElementsHidden |
| 330 | importantForAccessibility="no-hide-descendants" |
| 331 | style={{ |
| 332 | position: "absolute", |
| 333 | top: 0, |
| 334 | bottom: 0, |
| 335 | left: 0, |
| 336 | overflow: "hidden", |
| 337 | width: SHIMMER_WIDTH, |
| 338 | transform: [{ translateX: sweepTranslateX }], |
| 339 | }} |
| 340 | > |
| 341 | <MaskedView |
| 342 | style={StyleSheet.absoluteFill} |
| 343 | maskElement={ |
| 344 | <Svg width="100%" height="100%"> |
| 345 | <Defs> |
| 346 | <LinearGradient id={gradientId} x1="0%" x2="100%" y1="0%" y2="0%"> |
| 347 | <Stop offset="0" stopColor="white" stopOpacity={0} /> |
| 348 | <Stop offset="0.15" stopColor="white" stopOpacity={0.12} /> |
| 349 | <Stop offset="0.35" stopColor="white" stopOpacity={0.55} /> |
| 350 | <Stop offset="0.5" stopColor="white" stopOpacity={1} /> |
| 351 | <Stop offset="0.65" stopColor="white" stopOpacity={0.55} /> |
| 352 | <Stop offset="0.85" stopColor="white" stopOpacity={0.12} /> |
| 353 | <Stop offset="1" stopColor="white" stopOpacity={0} /> |
| 354 | </LinearGradient> |
| 355 | </Defs> |
| 356 | <Rect width="100%" height="100%" fill={`url(#${gradientId})`} /> |
| 357 | </Svg> |
| 358 | } |
| 359 | > |
| 360 | <NativeAnimated.View |
| 361 | style={{ width: availableWidth, transform: [{ translateX: counterSweepTranslateX }] }} |
| 362 | > |
| 363 | <ShimmerWorkContent |
| 364 | textClassName={props.textClassName} |
| 365 | compact={props.compact} |
| 366 | environmentId={props.environmentId} |
| 367 | highlighted |
| 368 | icon={props.icon} |
| 369 | iconSubtleColor={props.iconSubtleColor} |
| 370 | label={props.label} |
| 371 | showIcon={props.showIcon} |
| 372 | themeAppearance={props.themeAppearance} |
| 373 | toolIcon={props.toolIcon} |
| 374 | /> |
| 375 | </NativeAnimated.View> |
| 376 | </MaskedView> |
| 377 | </NativeAnimated.View> |
| 378 | ) : null} |
| 379 | </View> |
| 380 | ); |
| 381 | } |
| 382 | |
| 383 | function workRowSymbolName(icon: ThreadFeedActivity["icon"]): WorkContentIcon { |
| 384 | switch (icon) { |
| 385 | case "agent": |
| 386 | return "robot"; |
| 387 | case "alert": |
| 388 | return { ios: "exclamationmark.triangle", android: "error" }; |
| 389 | case "browser": |
| 390 | return { ios: "safari", android: "public" }; |
| 391 | case "check": |
| 392 | return { ios: "checkmark", android: "check" }; |
| 393 | case "command": |
| 394 | return { ios: "terminal", android: "terminal" }; |
| 395 | case "computer": |
| 396 | return "computer"; |
| 397 | case "code": |
| 398 | return "chevron.left.forwardslash.chevron.right"; |
| 399 | case "edit": |
| 400 | return { ios: "square.and.pencil", android: "edit" }; |
| 401 | case "eye": |
| 402 | return { ios: "eye", android: "visibility" }; |
| 403 | case "globe": |
| 404 | return { ios: "globe", android: "public" }; |
| 405 | case "search": |
| 406 | return "magnifyingglass"; |
| 407 | case "stop": |
| 408 | return "stop.fill"; |
| 409 | case "hammer": |
| 410 | return { ios: "hammer", android: "construction" }; |
| 411 | case "lock": |
| 412 | return { ios: "lock", android: "lock" }; |
| 413 | case "message": |
| 414 | return { ios: "bubble.left", android: "chat_bubble" }; |
| 415 | case "warning": |
| 416 | return { ios: "xmark", android: "close" }; |
| 417 | case "wrench": |
| 418 | return { ios: "wrench", android: "build" }; |
| 419 | case "zap": |
| 420 | return { ios: "bolt", android: "bolt" }; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // Animate only fresh rows; virtualization remounts old rows during scrolling. |
| 425 | const FRESH_ROW_WINDOW_MS = 3_000; |
| 426 | function isFreshRow(createdAt: string): boolean { |
| 427 | const timestamp = Date.parse(createdAt); |
| 428 | return Number.isFinite(timestamp) && Date.now() - timestamp < FRESH_ROW_WINDOW_MS; |
| 429 | } |
| 430 | |
| 431 | // Match min-h-8; disable exact sizing when native accessibility scaling can exceed it. |
| 432 | const WORK_ROW_HEIGHT = THREAD_WORK_ROW_MIN_HEIGHT; |
| 433 | const WORK_ROW_GAP = 1; |
| 434 | const WORK_LOG_BOTTOM_MARGIN = 3.5; |
| 435 | const WORK_GROUP_MAX_HEIGHT = 256; |
| 436 | const WORK_GROUP_EDGE_FADE_HEIGHT = 12; |
| 437 | |
| 438 | export const WORK_GROUP_TOGGLE_HEIGHT = THREAD_WORK_ROW_MIN_HEIGHT; |
| 439 | |
| 440 | function workLogRowsHeight( |
| 441 | activities: ReadonlyArray<ThreadFeedActivity>, |
| 442 | rowHeight = WORK_ROW_HEIGHT, |
| 443 | ): number { |
| 444 | return activities.length * rowHeight + Math.max(0, activities.length - 1) * WORK_ROW_GAP; |
| 445 | } |
| 446 | |
| 447 | export function collapsedWorkLogHeight( |
| 448 | activities: ReadonlyArray<ThreadFeedActivity>, |
| 449 | continues = false, |
| 450 | ): number { |
| 451 | const bottomMargin = continues ? 0 : WORK_LOG_BOTTOM_MARGIN; |
| 452 | if (activities.length === 0) { |
| 453 | return 0; |
| 454 | } |
| 455 | if (activities[0]?.projectedItem.item.type === "subagent") { |
| 456 | return bottomMargin + WORK_ROW_HEIGHT; |
| 457 | } |
| 458 | const height = workLogRowsHeight(activities); |
| 459 | return ( |
| 460 | bottomMargin + |
| 461 | (activities[0]?.groupedToolDetail ? Math.min(height, WORK_GROUP_MAX_HEIGHT) : height) |
| 462 | ); |
| 463 | } |
| 464 | |
| 465 | interface ThreadWorkLogProps { |
| 466 | readonly continuesWorkLog?: boolean | undefined; |
| 467 | readonly activities: ReadonlyArray<ThreadFeedActivity>; |
| 468 | readonly anchorKey: string; |
| 469 | readonly environmentId: EnvironmentId; |
| 470 | readonly workspaceRoot?: string | null | undefined; |
| 471 | readonly copiedRowId: string | null; |
| 472 | readonly expandedRows: Readonly<Record<string, boolean>>; |
| 473 | readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>; |
| 474 | readonly scrollPositions: Map<string, ThreadWorkGroupScrollPosition>; |
| 475 | readonly iconSubtleColor: ColorValue; |
| 476 | readonly edgeFadeColor: string; |
| 477 | readonly themeAppearance: "light" | "dark"; |
| 478 | readonly onCopyRow: (rowId: string, value: string) => void; |
| 479 | /** `groupId` is the group a lone call stands in for; it opens and closes with the row. */ |
| 480 | readonly onToggleRow: (rowId: string, anchorKey: string, groupId?: string) => void; |
| 481 | readonly renderImage: MarkdownImageRenderer; |
| 482 | readonly renderReasoning: (text: string) => ReactNode; |
| 483 | readonly onPressPreview: (source: FilePreviewSource) => void; |
| 484 | } |
| 485 | |
| 486 | export function ThreadWorkLog(props: ThreadWorkLogProps) { |
| 487 | const renderRow = (row: ThreadFeedActivity) => ( |
| 488 | <ThreadWorkLogRow |
| 489 | key={row.id} |
| 490 | row={row} |
| 491 | anchorKey={props.anchorKey} |
| 492 | copied={props.copiedRowId === row.id} |
| 493 | expanded={props.expandedRows[row.id] ?? false} |
| 494 | environmentId={props.environmentId} |
| 495 | iconSubtleColor={props.iconSubtleColor} |
| 496 | onCopyRow={props.onCopyRow} |
| 497 | onToggleRow={props.onToggleRow} |
| 498 | renderImage={props.renderImage} |
| 499 | renderReasoning={props.renderReasoning} |
| 500 | onPressPreview={props.onPressPreview} |
| 501 | themeAppearance={props.themeAppearance} |
| 502 | /> |
| 503 | ); |
| 504 | |
| 505 | if (props.activities.length === 0) { |
| 506 | return null; |
| 507 | } |
| 508 | |
| 509 | const plan = props.activities[0]?.projectedItem.item; |
| 510 | if (plan?.type === "proposed_plan") { |
| 511 | return ( |
| 512 | <ProposedPlanCard |
| 513 | environmentId={props.environmentId} |
| 514 | workspaceRoot={props.workspaceRoot} |
| 515 | markdown={plan.markdown} |
| 516 | renderMarkdown={props.renderReasoning} |
| 517 | /> |
| 518 | ); |
| 519 | } |
| 520 | |
| 521 | if (props.activities[0]?.projectedItem.item.type === "subagent") { |
| 522 | return <ThreadSubagentGroup {...props} />; |
| 523 | } |
| 524 | |
| 525 | if ( |
| 526 | props.activities[0]?.groupedToolDetail && |
| 527 | props.activities.every((row) => row.projectedItem.item.type === "reasoning") |
| 528 | ) { |
| 529 | return ( |
| 530 | <WorkLogBlock continues={props.continuesWorkLog}> |
| 531 | <ThreadReasoningGroup |
| 532 | activities={props.activities} |
| 533 | edgeFadeColor={props.edgeFadeColor} |
| 534 | renderReasoning={props.renderReasoning} |
| 535 | /> |
| 536 | </WorkLogBlock> |
| 537 | ); |
| 538 | } |
| 539 | |
| 540 | return ( |
| 541 | <WorkLogBlock continues={props.continuesWorkLog}> |
| 542 | {props.activities[0]?.groupedToolDetail ? ( |
| 543 | <ThreadWorkGroupList |
| 544 | activities={props.activities} |
| 545 | edgeFadeColor={props.edgeFadeColor} |
| 546 | expandedRows={props.expandedRows} |
| 547 | groupId={props.anchorKey} |
| 548 | rowSizing={props.rowSizing} |
| 549 | scrollPositions={props.scrollPositions} |
| 550 | renderRow={renderRow} |
| 551 | /> |
| 552 | ) : ( |
| 553 | <WorkLogRows>{props.activities.map(renderRow)}</WorkLogRows> |
| 554 | )} |
| 555 | </WorkLogBlock> |
| 556 | ); |
| 557 | } |
| 558 | |
| 559 | function ThreadReasoningGroup(props: { |
| 560 | readonly activities: ReadonlyArray<ThreadFeedActivity>; |
| 561 | readonly edgeFadeColor: string; |
| 562 | readonly renderReasoning: (text: string) => ReactNode; |
| 563 | }) { |
| 564 | const scrollOffset = useSharedValue(0); |
| 565 | const contentHeight = useSharedValue(0); |
| 566 | const viewportHeight = useSharedValue(0); |
| 567 | const onScroll = useAnimatedScrollHandler((event) => { |
| 568 | scrollOffset.set(event.contentOffset.y); |
| 569 | }); |
| 570 | const bottomFadeStyle = useAnimatedStyle(() => ({ |
| 571 | opacity: Math.min( |
| 572 | 1, |
| 573 | Math.max(0, contentHeight.value - viewportHeight.value - scrollOffset.value) / |
| 574 | WORK_GROUP_EDGE_FADE_HEIGHT, |
| 575 | ), |
| 576 | })); |
| 577 | |
| 578 | return ( |
| 579 | <View className="ml-7"> |
| 580 | <Animated.ScrollView |
| 581 | nestedScrollEnabled |
| 582 | className="max-h-96" |
| 583 | contentContainerClassName="py-1" |
| 584 | scrollEventThrottle={16} |
| 585 | onScroll={onScroll} |
| 586 | onLayout={(event) => { |
| 587 | viewportHeight.set(event.nativeEvent.layout.height); |
| 588 | }} |
| 589 | onContentSizeChange={(_width, height) => { |
| 590 | contentHeight.set(height); |
| 591 | }} |
| 592 | > |
| 593 | {props.activities.map((row) => ( |
| 594 | <View key={row.id}>{props.renderReasoning(row.workEntry.detail ?? "")}</View> |
| 595 | ))} |
| 596 | </Animated.ScrollView> |
| 597 | <Animated.View |
| 598 | pointerEvents="none" |
| 599 | className="absolute inset-x-0 bottom-0" |
| 600 | style={[{ height: WORK_GROUP_EDGE_FADE_HEIGHT }, bottomFadeStyle]} |
| 601 | > |
| 602 | <EdgeFade color={props.edgeFadeColor} direction="up" /> |
| 603 | </Animated.View> |
| 604 | </View> |
| 605 | ); |
| 606 | } |
| 607 | |
| 608 | const WORK_GROUP_MAINTAIN_SCROLL_AT_END = { |
| 609 | animated: false, |
| 610 | on: { dataAppend: true }, |
| 611 | } as const; |
| 612 | |
| 613 | function ThreadWorkGroupList(props: { |
| 614 | readonly activities: ReadonlyArray<ThreadFeedActivity>; |
| 615 | readonly edgeFadeColor: string; |
| 616 | readonly expandedRows: Readonly<Record<string, boolean>>; |
| 617 | readonly groupId: string; |
| 618 | readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>; |
| 619 | readonly scrollPositions: Map<string, ThreadWorkGroupScrollPosition>; |
| 620 | readonly renderRow: (row: ThreadFeedActivity) => ReactNode; |
| 621 | }) { |
| 622 | const estimatedRowsHeight = workLogRowsHeight( |
| 623 | props.activities, |
| 624 | props.rowSizing.estimatedRowHeight, |
| 625 | ); |
| 626 | const savedPosition = props.scrollPositions.get(props.groupId); |
| 627 | const initialPosition = props.activities.some((row) => row.id === savedPosition?.rowId) |
| 628 | ? savedPosition |
| 629 | : undefined; |
| 630 | const initialScrollIndex = resolveThreadWorkGroupInitialScroll(props.activities, initialPosition); |
| 631 | const listRef = useRef<LegendListRef>(null); |
| 632 | const previousTextSize = useRef(props.rowSizing.textSizeKey); |
| 633 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- clears the list's cached row sizes when the text size changes |
| 634 | useLayoutEffect(() => { |
| 635 | if (previousTextSize.current === props.rowSizing.textSizeKey) return; |
| 636 | previousTextSize.current = props.rowSizing.textSizeKey; |
| 637 | listRef.current?.clearCaches({ mode: "sizes" }); |
| 638 | }, [props.rowSizing.textSizeKey]); |
| 639 | const loadedRef = useRef(false); |
| 640 | const [contentHeight, setContentHeight] = useState(estimatedRowsHeight); |
| 641 | const height = Math.min(contentHeight, WORK_GROUP_MAX_HEIGHT); |
| 642 | const scrollOffset = useSharedValue(initialPosition?.scrollOffset ?? 0); |
| 643 | const sharedValues = { scrollOffset }; |
| 644 | |
| 645 | // Each edge fades only while content continues past it. Scroll offset stays |
| 646 | // on the UI thread; only content-size changes update React state. |
| 647 | const topFadeStyle = useAnimatedStyle(() => ({ |
| 648 | opacity: Math.min(1, Math.max(0, scrollOffset.value) / WORK_GROUP_EDGE_FADE_HEIGHT), |
| 649 | })); |
| 650 | const bottomFadeStyle = useAnimatedStyle(() => ({ |
| 651 | opacity: Math.min( |
| 652 | 1, |
| 653 | Math.max(0, contentHeight - height - scrollOffset.value) / WORK_GROUP_EDGE_FADE_HEIGHT, |
| 654 | ), |
| 655 | })); |
| 656 | const rememberPosition = (scroll: number) => { |
| 657 | if (!loadedRef.current) return; |
| 658 | const position = listRef.current?.anchorVisibleContent({ hold: false }); |
| 659 | if (!position) return; |
| 660 | props.scrollPositions.set(props.groupId, { |
| 661 | rowId: position.key, |
| 662 | offsetWithinRow: position.offset, |
| 663 | scrollOffset: scroll, |
| 664 | }); |
| 665 | }; |
| 666 | const handleMetricsChange = () => { |
| 667 | const metrics = listRef.current?.getState(); |
| 668 | if (!metrics) return; |
| 669 | setContentHeight(Math.max(1, metrics.contentLength)); |
| 670 | rememberPosition(metrics.scroll); |
| 671 | }; |
| 672 | const handleReady = () => { |
| 673 | loadedRef.current = true; |
| 674 | handleMetricsChange(); |
| 675 | }; |
| 676 | // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to LegendList's totalSize state to report content height in the same commit |
| 677 | useLayoutEffect(() => { |
| 678 | const state = listRef.current?.getState(); |
| 679 | if (!state) return; |
| 680 | handleMetricsChange(); |
| 681 | const stops = [ |
| 682 | state.listen("totalSize", handleMetricsChange), |
| 683 | state.listen("footerSize", handleMetricsChange), |
| 684 | state.listen("headerSize", handleMetricsChange), |
| 685 | ]; |
| 686 | return () => { |
| 687 | for (const stop of stops) stop(); |
| 688 | }; |
| 689 | }, [handleMetricsChange]); |
| 690 | const getFixedItemSize = (row: ThreadFeedActivity, index: number) => |
| 691 | props.expandedRows[row.id] || props.rowSizing.fixedRowHeight === undefined |
| 692 | ? undefined |
| 693 | : props.rowSizing.fixedRowHeight + (index < props.activities.length - 1 ? WORK_ROW_GAP : 0); |
| 694 | const renderItem = ({ item, index }: { item: ThreadFeedActivity; index: number }) => ( |
| 695 | <View className={index < props.activities.length - 1 ? "pb-px" : undefined}> |
| 696 | {props.renderRow(item)} |
| 697 | </View> |
| 698 | ); |
| 699 | |
| 700 | return ( |
| 701 | <View style={{ height, overflow: "hidden" }}> |
| 702 | {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- Nested in a fixed-height card inside the thread feed, which owns the header's scroll view. */} |
| 703 | <AnimatedLegendList |
| 704 | ref={listRef} |
| 705 | data={props.activities} |
| 706 | dataKey={props.groupId} |
| 707 | keyExtractor={workLogRowKey} |
| 708 | estimatedItemSize={props.rowSizing.estimatedRowHeight + WORK_ROW_GAP} |
| 709 | getFixedItemSize={getFixedItemSize} |
| 710 | initialScrollIndex={initialScrollIndex} |
| 711 | recycleItems={false} |
| 712 | extraData={props.renderRow} |
| 713 | renderItem={renderItem} |
| 714 | sharedValues={sharedValues} |
| 715 | onReady={handleReady} |
| 716 | onScroll={handleMetricsChange} |
| 717 | onLayout={handleMetricsChange} |
| 718 | maintainScrollAtEnd={WORK_GROUP_MAINTAIN_SCROLL_AT_END} |
| 719 | maintainScrollAtEndThreshold={1 / Math.max(1, height)} |
| 720 | maintainVisibleContentPosition |
| 721 | nestedScrollEnabled |
| 722 | directionalLockEnabled |
| 723 | showsVerticalScrollIndicator |
| 724 | scrollsToTop={false} |
| 725 | bounces={false} |
| 726 | keyboardShouldPersistTaps="handled" |
| 727 | style={{ height }} |
| 728 | /> |
| 729 | <Animated.View |
| 730 | pointerEvents="none" |
| 731 | className="absolute inset-x-0 top-0" |
| 732 | style={[{ height: WORK_GROUP_EDGE_FADE_HEIGHT }, topFadeStyle]} |
| 733 | > |
| 734 | <EdgeFade color={props.edgeFadeColor} direction="down" /> |
| 735 | </Animated.View> |
| 736 | <Animated.View |
| 737 | pointerEvents="none" |
| 738 | className="absolute inset-x-0 bottom-0" |
| 739 | style={[{ height: WORK_GROUP_EDGE_FADE_HEIGHT }, bottomFadeStyle]} |
| 740 | > |
| 741 | <EdgeFade color={props.edgeFadeColor} direction="up" /> |
| 742 | </Animated.View> |
| 743 | </View> |
| 744 | ); |
| 745 | } |
| 746 | |
| 747 | /** A screen-colored gradient painted over the list edge that still has content past it. */ |
| 748 | function EdgeFade(props: { readonly color: string; readonly direction: "up" | "down" }) { |
| 749 | const gradientId = `work-group-fade-${useId().replaceAll(":", "")}`; |
| 750 | return ( |
| 751 | <Svg width="100%" height="100%"> |
| 752 | <Defs> |
| 753 | <LinearGradient id={gradientId} x1="0%" x2="0%" y1="0%" y2="100%"> |
| 754 | <Stop |
| 755 | offset={0} |
| 756 | stopColor={props.color} |
| 757 | stopOpacity={props.direction === "down" ? 1 : 0} |
| 758 | /> |
| 759 | <Stop |
| 760 | offset={1} |
| 761 | stopColor={props.color} |
| 762 | stopOpacity={props.direction === "down" ? 0 : 1} |
| 763 | /> |
| 764 | </LinearGradient> |
| 765 | </Defs> |
| 766 | <Rect width="100%" height="100%" fill={`url(#${gradientId})`} /> |
| 767 | </Svg> |
| 768 | ); |
| 769 | } |
| 770 | |
| 771 | function workLogRowKey(row: ThreadFeedActivity): string { |
| 772 | return row.id; |
| 773 | } |
| 774 | |
| 775 | function WorkspacePreparationRetryButton(props: { |
| 776 | readonly environmentId: EnvironmentId; |
| 777 | readonly threadId: ThreadId; |
| 778 | readonly runId: RunId; |
| 779 | }) { |
| 780 | const retryable = useAtomValue( |
| 781 | environmentThreadDetails.threadAtom(scopeThreadRef(props.environmentId, props.threadId)), |
| 782 | (thread) => { |
| 783 | const run = thread?.projection.runs.find((candidate) => candidate.id === props.runId); |
| 784 | return run?.status === "failed" && run.workspacePreparation !== undefined; |
| 785 | }, |
| 786 | ); |
| 787 | const gt = useGT(); |
| 788 | const retry = useAtomCommand(threadEnvironment.retryWorkspacePreparation, "retry setup"); |
| 789 | const [busy, setBusy] = useState(false); |
| 790 | if (!retryable) return null; |
| 791 | return ( |
| 792 | <View className="ml-7 mt-2"> |
| 793 | <Button |
| 794 | label={gt("Retry")} |
| 795 | tone="secondary" |
| 796 | accessibilityLabel={gt("Retry workspace preparation")} |
| 797 | disabled={busy} |
| 798 | onPress={() => { |
| 799 | setBusy(true); |
| 800 | void Haptics.selectionAsync(); |
| 801 | void retry({ |
| 802 | environmentId: props.environmentId, |
| 803 | input: { threadId: props.threadId, runId: props.runId }, |
| 804 | }).finally(() => setBusy(false)); |
| 805 | }} |
| 806 | icon="arrow.clockwise" |
| 807 | /> |
| 808 | </View> |
| 809 | ); |
| 810 | } |
| 811 | |
| 812 | function ToolCodeText({ |
| 813 | code, |
| 814 | language, |
| 815 | theme, |
| 816 | }: { |
| 817 | readonly code: string; |
| 818 | readonly language: "typescript" | "html" | "json"; |
| 819 | readonly theme: "light" | "dark"; |
| 820 | }) { |
| 821 | const lines = useMarkdownCodeHighlight({ code, language, theme, enabled: true }); |
| 822 | return <HighlightedCodeText code={code} lines={lines} />; |
| 823 | } |
| 824 | |
| 825 | function CommandCodeText({ |
| 826 | command, |
| 827 | theme, |
| 828 | }: { |
| 829 | readonly command: string; |
| 830 | readonly theme: "light" | "dark"; |
| 831 | }) { |
| 832 | const code = withVisibleControlCharacters(command.trim()); |
| 833 | const lines = useMemo( |
| 834 | () => highlightCommand(code, commandHighlightLanguage(code), theme), |
| 835 | [code, theme], |
| 836 | ); |
| 837 | return <HighlightedCodeText code={code} lines={lines} />; |
| 838 | } |
| 839 | |
| 840 | function HighlightedCodeText({ |
| 841 | code, |
| 842 | lines, |
| 843 | }: { |
| 844 | readonly code: string; |
| 845 | readonly lines: HighlightedLines | null; |
| 846 | }) { |
| 847 | let offset = 0; |
| 848 | const highlighted = lines?.flatMap((line, lineIndex) => { |
| 849 | const separator = lineIndex > 0 ? "\n" : ""; |
| 850 | offset += separator.length; |
| 851 | return [ |
| 852 | separator, |
| 853 | ...line.map((token) => { |
| 854 | const start = offset; |
| 855 | offset += token.content.length; |
| 856 | // Plain RN Text inherits the mono font; AppText would reset it to sans. |
| 857 | return ( |
| 858 | <RNText key={start} style={token.color ? { color: token.color } : undefined}> |
| 859 | {token.content} |
| 860 | </RNText> |
| 861 | ); |
| 862 | }), |
| 863 | ]; |
| 864 | }); |
| 865 | return ( |
| 866 | <Text selectable className="font-mono text-2xs leading-normal text-foreground"> |
| 867 | {highlighted ?? code} |
| 868 | </Text> |
| 869 | ); |
| 870 | } |
| 871 | |
| 872 | // Rows that aren't sign-in notices read this, so every row reads an atom. |
| 873 | const NOT_SIGNED_IN = Atom.make(false); |
| 874 | |
| 875 | const ThreadWorkLogRow = function ThreadWorkLogRow( |
| 876 | props: Omit< |
| 877 | ThreadWorkLogProps, |
| 878 | | "continuesWorkLog" |
| 879 | | "activities" |
| 880 | | "copiedRowId" |
| 881 | | "edgeFadeColor" |
| 882 | | "expandedRows" |
| 883 | | "rowSizing" |
| 884 | | "scrollPositions" |
| 885 | > & { |
| 886 | readonly row: ThreadFeedActivity; |
| 887 | readonly copied: boolean; |
| 888 | readonly expanded: boolean; |
| 889 | }, |
| 890 | ) { |
| 891 | const { row, expanded } = props; |
| 892 | const gt = useGT(); |
| 893 | const messages = useMessages(); |
| 894 | const openLinkedThread = useOpenLinkedThread(); |
| 895 | const canSignInToMcp = useAtomValue( |
| 896 | threadEnvironment.mcpSignInStart.permissionAtom(props.environmentId), |
| 897 | ); |
| 898 | const [mcpSignInOpen, setMcpSignInOpen] = useState(false); |
| 899 | const signInNotice = row.projectedItem.item; |
| 900 | const mcpSignedIn = useAtomValue( |
| 901 | signInNotice.type === "system_notice" && signInNotice.mcpSignIn !== undefined |
| 902 | ? threadEnvironment.mcpSignedInAtom(props.environmentId, { |
| 903 | threadId: signInNotice.threadId, |
| 904 | server: signInNotice.mcpSignIn.server, |
| 905 | noticeAt: DateTime.toEpochMillis(signInNotice.updatedAt), |
| 906 | }) |
| 907 | : NOT_SIGNED_IN, |
| 908 | ); |
| 909 | const streamsOutput = |
| 910 | useCommandOutputStreaming(props.environmentId) && |
| 911 | row.projectedItem.item.type === "command_execution"; |
| 912 | const fetchedDetail = useTurnItemDetail( |
| 913 | expanded && row.fetchesDetail && !streamsOutput |
| 914 | ? { environmentId: props.environmentId, row: row.projectedItem } |
| 915 | : null, |
| 916 | ); |
| 917 | const failureItem = row.projectedItem.item; |
| 918 | if (failureItem.type === "error" && failureItem.status === "failed") { |
| 919 | const warning = failureItem.failure.class === "usage_limit"; |
| 920 | const timestamp = new Date(row.createdAt); |
| 921 | const resetAt = failureItem.failure.resetAt; |
| 922 | // The reset time is the viewer's local time; naming the zone keeps it unambiguous. |
| 923 | const resetTime = resetAt |
| 924 | ? `${new Date(resetAt).toLocaleString(undefined, { |
| 925 | month: "short", |
| 926 | day: "numeric", |
| 927 | hour: "numeric", |
| 928 | minute: "2-digit", |
| 929 | })} (${new Intl.DateTimeFormat().resolvedOptions().timeZone})` |
| 930 | : null; |
| 931 | const label = warning |
| 932 | ? resetTime |
| 933 | ? gt("Usage limit reached. Retry after {resetTime}.", { resetTime }) |
| 934 | : gt("Usage limit reached.") |
| 935 | : row.summary; |
| 936 | return ( |
| 937 | <WorkLogPressable |
| 938 | accessibilityLabel={ |
| 939 | warning |
| 940 | ? label |
| 941 | : gt("{summary}: {message}", { |
| 942 | summary: row.summary, |
| 943 | message: failureItem.failure.message, |
| 944 | }) |
| 945 | } |
| 946 | accessibilityHint={gt("Long press to copy.")} |
| 947 | onLongPress={() => props.onCopyRow(row.id, row.getCopyText())} |
| 948 | > |
| 949 | <View className="flex-1 py-1"> |
| 950 | <View className="flex-row items-center gap-1.5"> |
| 951 | <WorkLogIconSlot> |
| 952 | <WorkLogIcon |
| 953 | icon="exclamationmark.circle" |
| 954 | color={props.iconSubtleColor} |
| 955 | colorClassName={warning ? "accent-warning-foreground" : "accent-danger-foreground"} |
| 956 | /> |
| 957 | </WorkLogIconSlot> |
| 958 | <Text |
| 959 | className={ |
| 960 | warning |
| 961 | ? "min-w-0 flex-1 font-t3-medium text-sm text-warning-foreground" |
| 962 | : "min-w-0 flex-1 font-t3-medium text-sm text-adaptive-rose-600-400" |
| 963 | } |
| 964 | > |
| 965 | {label} |
| 966 | </Text> |
| 967 | {props.copied ? ( |
| 968 | <Text className="pr-1 font-t3-medium text-3xs text-adaptive-emerald-600-400"> |
| 969 | <T>Copied</T> |
| 970 | </Text> |
| 971 | ) : null} |
| 972 | <Text |
| 973 | accessibilityLabel={timestamp.toLocaleString()} |
| 974 | className="shrink-0 text-xs text-foreground-subtle" |
| 975 | > |
| 976 | {timestamp.toLocaleString(undefined, { |
| 977 | month: "short", |
| 978 | day: "numeric", |
| 979 | hour: "numeric", |
| 980 | minute: "2-digit", |
| 981 | })} |
| 982 | </Text> |
| 983 | </View> |
| 984 | {!warning ? ( |
| 985 | <Text selectable className="ml-7 text-sm text-foreground"> |
| 986 | {failureItem.failure.message} |
| 987 | </Text> |
| 988 | ) : null} |
| 989 | {failureItem.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE && |
| 990 | failureItem.runId !== null ? ( |
| 991 | <WorkspacePreparationRetryButton |
| 992 | environmentId={props.environmentId} |
| 993 | threadId={failureItem.threadId} |
| 994 | runId={failureItem.runId} |
| 995 | /> |
| 996 | ) : null} |
| 997 | </View> |
| 998 | </WorkLogPressable> |
| 999 | ); |
| 1000 | } |
| 1001 | const notifiedSubagentThreadId = |
| 1002 | row.projectedItem.item.type === "notification" |
| 1003 | ? notificationChildThreadId(row.projectedItem.item.source) |
| 1004 | : undefined; |
| 1005 | const notice = row.projectedItem.item; |
| 1006 | const mcpSignInTarget: McpSignInTarget | null = |
| 1007 | canSignInToMcp && |
| 1008 | notice.type === "system_notice" && |
| 1009 | notice.mcpSignIn !== undefined && |
| 1010 | notice.providerThreadId !== null |
| 1011 | ? { |
| 1012 | threadId: notice.threadId, |
| 1013 | providerThreadId: notice.providerThreadId, |
| 1014 | server: notice.mcpSignIn.server, |
| 1015 | } |
| 1016 | : null; |
| 1017 | // Signed in, the notice is an ordinary row again. |
| 1018 | const opensMcpSignIn = mcpSignInTarget !== null && !mcpSignedIn; |
| 1019 | // A sign-in notice opens its sheet instead; a nested button would be out of VoiceOver's reach. |
| 1020 | const canExpand = row.canExpand && notifiedSubagentThreadId === undefined && !opensMcpSignIn; |
| 1021 | const reasoning = row.projectedItem.item.type === "reasoning" ? row.projectedItem.item : null; |
| 1022 | const fetchedItem = fetchedDetail.data?.item ?? null; |
| 1023 | const isRead = toolGroupAction(row.workEntry) === "read"; |
| 1024 | const shownItem = fetchedItem ?? row.projectedItem.item; |
| 1025 | const call = |
| 1026 | expanded && !isRead && shownItem.type === "command_execution" |
| 1027 | ? toolCallLines({ command: shownItem.input }) |
| 1028 | : expanded && !isRead && shownItem.type === "dynamic_tool" |
| 1029 | ? toolCallLines({ args: shownItem.input }) |
| 1030 | : expanded && shownItem.type === "file_search" |
| 1031 | ? toolCallLines({ args: { pattern: shownItem.pattern } }) |
| 1032 | : expanded && shownItem.type === "web_search" |
| 1033 | ? toolCallLines({ args: { query: shownItem.patterns?.join(", ") } }) |
| 1034 | : null; |
| 1035 | const failedExitCode = |
| 1036 | call && shownItem.type === "command_execution" && shownItem.exitCode |
| 1037 | ? shownItem.exitCode |
| 1038 | : null; |
| 1039 | const fullDetail = |
| 1040 | expanded && !reasoning && !call && !row.workEntry.questionAnswer |
| 1041 | ? fetchedItem && !isRead |
| 1042 | ? formatItemFullDetail(row.projectedItem, fetchedItem) |
| 1043 | : row.getFullDetail() |
| 1044 | : null; |
| 1045 | const outputImages = expanded && fetchedItem ? turnItemOutputImages(fetchedItem) : []; |
| 1046 | const viewedImagePath = workEntryViewedImagePath(row.workEntry); |
| 1047 | const fetchedOutput = |
| 1048 | !expanded || streamsOutput |
| 1049 | ? null |
| 1050 | : shownItem.type === "file_search" || shownItem.type === "web_search" |
| 1051 | ? turnItemOutputText(shownItem) |
| 1052 | : fetchedItem |
| 1053 | ? (turnItemOutputText(fetchedItem) ?? |
| 1054 | (outputImages.length > 0 || viewedImagePath ? null : gt("No output."))) |
| 1055 | : fetchedDetail.error |
| 1056 | ? gt("Couldn't load output: {error}", { error: fetchedDetail.error }) |
| 1057 | : row.fetchesDetail |
| 1058 | ? fetchedDetail.data |
| 1059 | ? gt("Output is no longer available.") |
| 1060 | : gt("Loading output…") |
| 1061 | : null; |
| 1062 | const exitLine = |
| 1063 | failedExitCode === null ? null : ( |
| 1064 | <Text className="mt-1.5 font-mono text-2xs leading-normal text-danger-foreground"> |
| 1065 | exit {failedExitCode} |
| 1066 | </Text> |
| 1067 | ); |
| 1068 | const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry, undefined, messages); |
| 1069 | const previewText = row.groupStandIn?.label ?? workEntryRowLabel(row.workEntry, false, messages); |
| 1070 | const answerPreview = row.workEntry.questionAnswer |
| 1071 | ? getQuestionAnswerPreview(row.workEntry.questionAnswer) |
| 1072 | : null; |
| 1073 | const accessiblePreview = [previewText, answerPreview].filter(Boolean).join(": "); |
| 1074 | const displayText = |
| 1075 | row.groupStandIn?.label ?? workEntryRowLabel(row.workEntry, expanded, messages); |
| 1076 | const isSystemNotice = row.projectedItem.item.type === "system_notice"; |
| 1077 | const isUsageLimit = |
| 1078 | row.projectedItem.item.type === "error" && |
| 1079 | row.projectedItem.item.failure.class === "usage_limit" && |
| 1080 | row.projectedItem.item.status !== "completed"; |
| 1081 | const iconIsDestructive = |
| 1082 | !isSystemNotice && !isUsageLimit && (row.icon === "alert" || row.icon === "warning"); |
| 1083 | const failed = row.status === "failure"; |
| 1084 | const toolIcon = row.workEntry.toolIcon ?? row.workEntry.toolSource?.icon; |
| 1085 | const icon = reasoning ? "brain" : (toolPresentation?.icon ?? workRowSymbolName(row.icon)); |
| 1086 | |
| 1087 | return ( |
| 1088 | <Animated.View |
| 1089 | layout={WORK_LOG_LAYOUT_TRANSITION} |
| 1090 | className="overflow-hidden" |
| 1091 | {...(isFreshRow(row.createdAt) ? { entering: FadeIn.duration(200) } : {})} |
| 1092 | > |
| 1093 | <WorkLogPressable |
| 1094 | accessibilityRole={ |
| 1095 | notifiedSubagentThreadId !== undefined |
| 1096 | ? "link" |
| 1097 | : canExpand || opensMcpSignIn |
| 1098 | ? "button" |
| 1099 | : undefined |
| 1100 | } |
| 1101 | accessibilityLabel={ |
| 1102 | failed |
| 1103 | ? gt("{preview}, tool call failed", { preview: accessiblePreview }) |
| 1104 | : mcpSignInTarget !== null && mcpSignedIn |
| 1105 | ? gt("{preview}, signed in", { preview: accessiblePreview }) |
| 1106 | : accessiblePreview |
| 1107 | } |
| 1108 | accessibilityHint={ |
| 1109 | notifiedSubagentThreadId !== undefined |
| 1110 | ? gt("Opens this agent's thread. Long press to copy.") |
| 1111 | : opensMcpSignIn |
| 1112 | ? gt("Opens the sign-in. Long press to copy.") |
| 1113 | : canExpand |
| 1114 | ? expanded |
| 1115 | ? gt("Double tap to hide full details. Long press to copy.") |
| 1116 | : gt("Double tap to show full details. Long press to copy.") |
| 1117 | : gt("Long press to copy.") |
| 1118 | } |
| 1119 | accessibilityState={canExpand ? { expanded } : undefined} |
| 1120 | onPress={() => { |
| 1121 | if (notifiedSubagentThreadId !== undefined) { |
| 1122 | openLinkedThread({ |
| 1123 | environmentId: String(props.environmentId), |
| 1124 | threadId: String(notifiedSubagentThreadId), |
| 1125 | }); |
| 1126 | return; |
| 1127 | } |
| 1128 | if (opensMcpSignIn) { |
| 1129 | void Haptics.selectionAsync(); |
| 1130 | setMcpSignInOpen(true); |
| 1131 | return; |
| 1132 | } |
| 1133 | if (canExpand) { |
| 1134 | void Haptics.selectionAsync(); |
| 1135 | props.onToggleRow(row.id, props.anchorKey, row.groupStandIn?.groupId); |
| 1136 | } |
| 1137 | }} |
| 1138 | onLongPress={() => props.onCopyRow(row.id, row.getCopyText())} |
| 1139 | > |
| 1140 | {row.live && !expanded ? ( |
| 1141 | <ShimmeringWorkContent |
| 1142 | environmentId={props.environmentId} |
| 1143 | icon={icon} |
| 1144 | iconSubtleColor={props.iconSubtleColor} |
| 1145 | label={displayText} |
| 1146 | showIcon |
| 1147 | themeAppearance={props.themeAppearance} |
| 1148 | toolIcon={toolIcon} |
| 1149 | /> |
| 1150 | ) : ( |
| 1151 | <> |
| 1152 | <WorkLogIconSlot> |
| 1153 | {toolIcon ? ( |
| 1154 | <ToolActivityIconView |
| 1155 | environmentId={props.environmentId} |
| 1156 | icon={toolIcon} |
| 1157 | fallback={icon} |
| 1158 | fallbackColor={props.iconSubtleColor} |
| 1159 | themeAppearance={props.themeAppearance} |
| 1160 | /> |
| 1161 | ) : ( |
| 1162 | <WorkLogIcon |
| 1163 | icon={icon} |
| 1164 | color={props.iconSubtleColor} |
| 1165 | colorClassName={ |
| 1166 | isUsageLimit |
| 1167 | ? "accent-warning-foreground" |
| 1168 | : iconIsDestructive |
| 1169 | ? "accent-adaptive-rose-600-400" |
| 1170 | : failed |
| 1171 | ? "accent-danger-foreground/40" |
| 1172 | : undefined |
| 1173 | } |
| 1174 | /> |
| 1175 | )} |
| 1176 | </WorkLogIconSlot> |
| 1177 | <WorkLogLabel |
| 1178 | tone={isUsageLimit ? "warning" : iconIsDestructive ? "danger" : "default"} |
| 1179 | > |
| 1180 | {displayText} |
| 1181 | {answerPreview ? ( |
| 1182 | <Text |
| 1183 | className={ |
| 1184 | !expanded && |
| 1185 | row.workEntry.questionAnswer && |
| 1186 | hasQuestionAnswer(row.workEntry.questionAnswer) |
| 1187 | ? "text-foreground" |
| 1188 | : "text-foreground-subtle" |
| 1189 | } |
| 1190 | >{` ${answerPreview}`}</Text> |
| 1191 | ) : null} |
| 1192 | </WorkLogLabel> |
| 1193 | </> |
| 1194 | )} |
| 1195 | |
| 1196 | <View className="shrink-0 flex-row items-center gap-px"> |
| 1197 | {props.copied ? ( |
| 1198 | <Text className="pr-1 font-t3-medium text-3xs text-adaptive-emerald-600-400"> |
| 1199 | <T>Copied</T> |
| 1200 | </Text> |
| 1201 | ) : mcpSignInTarget !== null ? ( |
| 1202 | <Text |
| 1203 | className={cn( |
| 1204 | "pr-1 font-t3-medium text-sm", |
| 1205 | mcpSignedIn ? "text-adaptive-emerald-600-400" : "text-primary", |
| 1206 | )} |
| 1207 | > |
| 1208 | {mcpSignedIn ? <T>Signed in</T> : <T>Sign in</T>} |
| 1209 | </Text> |
| 1210 | ) : null} |
| 1211 | {failed && toolIcon !== undefined ? ( |
| 1212 | <View |
| 1213 | className="h-4 w-4 items-center justify-center" |
| 1214 | accessibilityElementsHidden |
| 1215 | importantForAccessibility="no-hide-descendants" |
| 1216 | > |
| 1217 | <SymbolView |
| 1218 | name="xmark" |
| 1219 | size={11} |
| 1220 | tintColorClassName="accent-danger-foreground/40" |
| 1221 | type="monochrome" |
| 1222 | /> |
| 1223 | </View> |
| 1224 | ) : null} |
| 1225 | <View className="h-4 w-4 items-center justify-center"> |
| 1226 | {canExpand ? ( |
| 1227 | <ThreadDisclosureChevron |
| 1228 | expanded={expanded} |
| 1229 | collapsedDirection="down" |
| 1230 | size={11} |
| 1231 | tintColor={props.iconSubtleColor} |
| 1232 | /> |
| 1233 | ) : null} |
| 1234 | </View> |
| 1235 | </View> |
| 1236 | </WorkLogPressable> |
| 1237 | {mcpSignInOpen && mcpSignInTarget !== null ? ( |
| 1238 | <McpSignInSheet |
| 1239 | environmentId={props.environmentId} |
| 1240 | target={mcpSignInTarget} |
| 1241 | onClose={() => setMcpSignInOpen(false)} |
| 1242 | /> |
| 1243 | ) : null} |
| 1244 | |
| 1245 | {expanded && |
| 1246 | (reasoning || |
| 1247 | fullDetail || |
| 1248 | call || |
| 1249 | fetchedOutput || |
| 1250 | viewedImagePath || |
| 1251 | outputImages.length > 0 || |
| 1252 | row.workEntry.questionAnswer) ? ( |
| 1253 | <Animated.View |
| 1254 | entering={WORK_LOG_DETAIL_ENTER_TRANSITION} |
| 1255 | exiting={WORK_LOG_DETAIL_EXIT_TRANSITION} |
| 1256 | layout={WORK_LOG_LAYOUT_TRANSITION} |
| 1257 | className={reasoning ? "ml-7 py-1" : "pb-1 pt-0.5"} |
| 1258 | > |
| 1259 | {row.workEntry.questionAnswer ? ( |
| 1260 | <QuestionAnswerHistory |
| 1261 | environmentId={props.environmentId} |
| 1262 | answer={row.workEntry.questionAnswer} |
| 1263 | /> |
| 1264 | ) : null} |
| 1265 | {viewedImagePath ? ( |
| 1266 | <View className="pb-1.5"> |
| 1267 | {props.renderImage({ href: viewedImagePath, alt: null, title: null })} |
| 1268 | </View> |
| 1269 | ) : null} |
| 1270 | <FilePreviewGallery |
| 1271 | value={outputImages.map((resource) => ({ |
| 1272 | kind: "image", |
| 1273 | environmentId: props.environmentId, |
| 1274 | resource, |
| 1275 | }))} |
| 1276 | > |
| 1277 | {outputImages.map((resource) => ( |
| 1278 | <View key={resource.index} className="pb-1.5"> |
| 1279 | <ThreadMarkdownImage |
| 1280 | environmentId={props.environmentId} |
| 1281 | resource={resource} |
| 1282 | alt={null} |
| 1283 | onPressPreview={props.onPressPreview} |
| 1284 | /> |
| 1285 | </View> |
| 1286 | ))} |
| 1287 | </FilePreviewGallery> |
| 1288 | <ScrollView |
| 1289 | nestedScrollEnabled |
| 1290 | directionalLockEnabled |
| 1291 | showsVerticalScrollIndicator |
| 1292 | className="max-h-60" |
| 1293 | contentContainerStyle={{ paddingRight: 8 }} |
| 1294 | > |
| 1295 | {reasoning ? ( |
| 1296 | props.renderReasoning(reasoning.text) |
| 1297 | ) : call ? ( |
| 1298 | [ |
| 1299 | call.command ? ( |
| 1300 | <CommandCodeText |
| 1301 | key="command" |
| 1302 | command={call.command} |
| 1303 | theme={props.themeAppearance} |
| 1304 | /> |
| 1305 | ) : null, |
| 1306 | ...(call.args ?? []).map(([key, value]) => { |
| 1307 | const language = |
| 1308 | key === "html" |
| 1309 | ? "html" |
| 1310 | : key === "code" && |
| 1311 | shownItem.type === "dynamic_tool" && |
| 1312 | isJavaScriptReplTool(shownItem.toolName) |
| 1313 | ? "typescript" |
| 1314 | : isJsonToolText(value) |
| 1315 | ? "json" |
| 1316 | : null; |
| 1317 | return language ? ( |
| 1318 | <View key={key}> |
| 1319 | <Text className="font-mono text-2xs leading-normal text-foreground-muted"> |
| 1320 | {key} |
| 1321 | </Text> |
| 1322 | <ToolCodeText |
| 1323 | code={value} |
| 1324 | language={language} |
| 1325 | theme={props.themeAppearance} |
| 1326 | /> |
| 1327 | </View> |
| 1328 | ) : ( |
| 1329 | `${key} ${value}` |
| 1330 | ); |
| 1331 | }), |
| 1332 | call.argsText, |
| 1333 | ] |
| 1334 | .filter((line) => Boolean(line)) |
| 1335 | .map( |
| 1336 | (line, index) => |
| 1337 | /* oxlint-disable react/no-array-index-key -- Log lines are stateless positions within this output. */ typeof line === |
| 1338 | "string" ? ( |
| 1339 | <Text |
| 1340 | key={`${index}:${line}`} |
| 1341 | selectable |
| 1342 | className="font-mono text-2xs leading-normal text-foreground" |
| 1343 | > |
| 1344 | {isJsonToolText(line) ? ( |
| 1345 | <ToolCodeText code={line} language="json" theme={props.themeAppearance} /> |
| 1346 | ) : ( |
| 1347 | line |
| 1348 | )} |
| 1349 | </Text> |
| 1350 | ) : ( |
| 1351 | line |
| 1352 | ) /* oxlint-enable react/no-array-index-key */, |
| 1353 | ) |
| 1354 | ) : fullDetail ? ( |
| 1355 | <Text selectable className="font-mono text-2xs leading-normal text-foreground-muted"> |
| 1356 | {isJsonToolText(fullDetail) ? ( |
| 1357 | <ToolCodeText code={fullDetail} language="json" theme={props.themeAppearance} /> |
| 1358 | ) : ( |
| 1359 | fullDetail |
| 1360 | )} |
| 1361 | </Text> |
| 1362 | ) : null} |
| 1363 | {fetchedOutput ? ( |
| 1364 | <Text |
| 1365 | selectable |
| 1366 | className={cn( |
| 1367 | "font-mono text-2xs leading-normal text-foreground-muted", |
| 1368 | (!call || call.command || call.args || call.argsText) && "mt-1.5", |
| 1369 | )} |
| 1370 | > |
| 1371 | {isJsonToolText(fetchedOutput) ? ( |
| 1372 | <ToolCodeText |
| 1373 | code={fetchedOutput} |
| 1374 | language="json" |
| 1375 | theme={props.themeAppearance} |
| 1376 | /> |
| 1377 | ) : ( |
| 1378 | fetchedOutput |
| 1379 | )} |
| 1380 | </Text> |
| 1381 | ) : null} |
| 1382 | {streamsOutput ? null : exitLine} |
| 1383 | </ScrollView> |
| 1384 | {streamsOutput ? ( |
| 1385 | <> |
| 1386 | <ThreadCommandOutput |
| 1387 | environmentId={props.environmentId} |
| 1388 | threadId={row.projectedItem.sourceThreadId} |
| 1389 | itemId={row.projectedItem.sourceItemId} |
| 1390 | themeAppearance={props.themeAppearance} |
| 1391 | /> |
| 1392 | {exitLine} |
| 1393 | </> |
| 1394 | ) : null} |
| 1395 | </Animated.View> |
| 1396 | ) : null} |
| 1397 | </Animated.View> |
| 1398 | ); |
| 1399 | }; |
| 1400 | |
| 1401 | export function ThreadWorkGroupToggle(props: { |
| 1402 | readonly environmentId: EnvironmentId; |
| 1403 | readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>; |
| 1404 | readonly expanded: boolean; |
| 1405 | readonly hiddenCount: number; |
| 1406 | readonly iconSubtleColor: import("react-native").ColorValue; |
| 1407 | readonly summary: string; |
| 1408 | readonly summaryKind: ToolGroupSummaryKind; |
| 1409 | readonly summaryToolIcon?: "browser" | "device" | "t3-code" | "pull-request" | "brain"; |
| 1410 | readonly themeAppearance: "light" | "dark"; |
| 1411 | readonly toolSurface?: import("@t3tools/contracts").ToolActivitySurface; |
| 1412 | readonly toolIcon?: ToolActivityIcon; |
| 1413 | readonly hasFailure: boolean; |
| 1414 | readonly shimmer: boolean; |
| 1415 | readonly thought?: string | undefined; |
| 1416 | readonly trailing?: ReactNode; |
| 1417 | readonly onToggle: () => void; |
| 1418 | }) { |
| 1419 | const gt = useGT(); |
| 1420 | const statusLabel = props.hasFailure |
| 1421 | ? gt("{preview}, tool call failed", { preview: props.summary }) |
| 1422 | : props.summary; |
| 1423 | const accessibilityLabel = props.thought ? `${props.thought} ${statusLabel}` : statusLabel; |
| 1424 | const icon = |
| 1425 | props.summaryToolIcon ?? |
| 1426 | (props.toolSurface |
| 1427 | ? workRowSymbolName(props.toolSurface) |
| 1428 | : toolGroupSummarySymbolName(props.summaryKind)); |
| 1429 | |
| 1430 | return ( |
| 1431 | <WorkLogBlock layout="group-header"> |
| 1432 | {props.thought ? ( |
| 1433 | <Pressable |
| 1434 | accessible={false} |
| 1435 | onPress={props.onToggle} |
| 1436 | className="flex-row items-start gap-1.5 rounded-md px-0.5 active:bg-subtle" |
| 1437 | > |
| 1438 | <WorkLogIconSlot> |
| 1439 | <WorkLogIcon icon="brain" color={props.iconSubtleColor} /> |
| 1440 | </WorkLogIconSlot> |
| 1441 | <Text |
| 1442 | selectable={false} |
| 1443 | numberOfLines={4} |
| 1444 | ellipsizeMode="tail" |
| 1445 | className="min-w-0 flex-1 py-0.5 text-sm text-foreground-muted" |
| 1446 | > |
| 1447 | {props.thought} |
| 1448 | </Text> |
| 1449 | </Pressable> |
| 1450 | ) : null} |
| 1451 | <View className="flex-row items-center"> |
| 1452 | <View className="min-w-0 flex-1"> |
| 1453 | <WorkLogPressable |
| 1454 | accessibilityRole="button" |
| 1455 | accessibilityState={{ expanded: props.expanded }} |
| 1456 | accessibilityLabel={accessibilityLabel} |
| 1457 | accessibilityHint={ |
| 1458 | props.expanded |
| 1459 | ? gt( |
| 1460 | "{count, plural, one {Double tap to hide {count} tool call.} other {Double tap to hide {count} tool calls.}}", |
| 1461 | { count: props.hiddenCount }, |
| 1462 | ) |
| 1463 | : gt( |
| 1464 | "{count, plural, one {Double tap to show {count} tool call.} other {Double tap to show {count} tool calls.}}", |
| 1465 | { count: props.hiddenCount }, |
| 1466 | ) |
| 1467 | } |
| 1468 | onPress={() => { |
| 1469 | void Haptics.selectionAsync(); |
| 1470 | props.onToggle(); |
| 1471 | }} |
| 1472 | rowSizing={props.rowSizing} |
| 1473 | > |
| 1474 | {props.shimmer ? ( |
| 1475 | <ShimmeringWorkContent |
| 1476 | environmentId={props.environmentId} |
| 1477 | icon={icon} |
| 1478 | iconSubtleColor={props.iconSubtleColor} |
| 1479 | label={props.summary} |
| 1480 | showIcon |
| 1481 | themeAppearance={props.themeAppearance} |
| 1482 | toolIcon={props.toolIcon} |
| 1483 | /> |
| 1484 | ) : ( |
| 1485 | <> |
| 1486 | <WorkLogIconSlot> |
| 1487 | <ToolActivityIconView |
| 1488 | environmentId={props.environmentId} |
| 1489 | icon={props.toolIcon} |
| 1490 | fallback={icon} |
| 1491 | fallbackColor={props.iconSubtleColor} |
| 1492 | themeAppearance={props.themeAppearance} |
| 1493 | /> |
| 1494 | </WorkLogIconSlot> |
| 1495 | <WorkLogLabel>{props.summary}</WorkLogLabel> |
| 1496 | </> |
| 1497 | )} |
| 1498 | <ThreadDisclosureChevron |
| 1499 | expanded={props.expanded} |
| 1500 | collapsedDirection="down" |
| 1501 | size={11} |
| 1502 | tintColor={props.iconSubtleColor} |
| 1503 | /> |
| 1504 | </WorkLogPressable> |
| 1505 | </View> |
| 1506 | {props.trailing} |
| 1507 | </View> |
| 1508 | </WorkLogBlock> |
| 1509 | ); |
| 1510 | } |
| 1511 | |
| 1512 | export function ThreadThinkingRow(props: { |
| 1513 | readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>; |
| 1514 | readonly iconSubtleColor: ColorValue; |
| 1515 | readonly label?: string; |
| 1516 | /** Replaces "Thinking" while the provider has not started a turn. */ |
| 1517 | readonly providerStartingLabel?: string | undefined; |
| 1518 | }) { |
| 1519 | const gt = useGT(); |
| 1520 | const label = props.providerStartingLabel ?? props.label ?? gt("Thinking"); |
| 1521 | return ( |
| 1522 | <View |
| 1523 | accessible |
| 1524 | accessibilityLabel={label} |
| 1525 | className="-mx-1 min-h-8 flex-row items-center px-1.5 py-0" |
| 1526 | style={{ minHeight: props.rowSizing.estimatedRowHeight }} |
| 1527 | > |
| 1528 | <ShimmeringWorkContent |
| 1529 | icon="brain" |
| 1530 | iconSubtleColor={props.iconSubtleColor} |
| 1531 | label={label} |
| 1532 | showIcon |
| 1533 | /> |
| 1534 | </View> |
| 1535 | ); |
| 1536 | } |
| 1537 | |
| 1538 | function ToolActivityIconView(props: { |
| 1539 | readonly environmentId: EnvironmentId; |
| 1540 | readonly icon?: ToolActivityIcon; |
| 1541 | readonly fallback: WorkContentIcon; |
| 1542 | readonly fallbackColor: ColorValue; |
| 1543 | readonly themeAppearance: "light" | "dark"; |
| 1544 | }) { |
| 1545 | if (!props.icon) { |
| 1546 | return <WorkLogIcon icon={props.fallback} color={props.fallbackColor} />; |
| 1547 | } |
| 1548 | if (props.icon._tag === "website") { |
| 1549 | const source = toolActivityFaviconUrl(props.icon, props.themeAppearance, 32); |
| 1550 | return source ? ( |
| 1551 | <ToolActivityImage |
| 1552 | key={source} |
| 1553 | source={source} |
| 1554 | fallback={props.fallback} |
| 1555 | color={props.fallbackColor} |
| 1556 | themeAppearance={props.themeAppearance} |
| 1557 | /> |
| 1558 | ) : ( |
| 1559 | <WorkLogIcon icon={props.fallback} color={props.fallbackColor} /> |
| 1560 | ); |
| 1561 | } |
| 1562 | if (props.icon._tag === "themed-logo") { |
| 1563 | const source = |
| 1564 | props.themeAppearance === "dark" |
| 1565 | ? (props.icon.logoUrlDark ?? props.icon.logoUrl) |
| 1566 | : props.icon.logoUrl; |
| 1567 | return ( |
| 1568 | <ToolActivityImage |
| 1569 | key={source} |
| 1570 | source={source} |
| 1571 | fallback={props.fallback} |
| 1572 | color={props.fallbackColor} |
| 1573 | themeAppearance={props.themeAppearance} |
| 1574 | /> |
| 1575 | ); |
| 1576 | } |
| 1577 | return ( |
| 1578 | <NativeAppToolActivityIcon |
| 1579 | environmentId={props.environmentId} |
| 1580 | app={props.icon.app} |
| 1581 | fallback={props.fallback} |
| 1582 | color={props.fallbackColor} |
| 1583 | themeAppearance={props.themeAppearance} |
| 1584 | /> |
| 1585 | ); |
| 1586 | } |
| 1587 | |
| 1588 | function NativeAppToolActivityIcon(props: { |
| 1589 | readonly environmentId: EnvironmentId; |
| 1590 | readonly app: Extract<ToolActivityIcon, { readonly _tag: "native-app" }>["app"]; |
| 1591 | readonly fallback: WorkContentIcon; |
| 1592 | readonly color: ColorValue; |
| 1593 | readonly themeAppearance: "light" | "dark"; |
| 1594 | }) { |
| 1595 | const source = useAssetUrl(props.environmentId, { |
| 1596 | _tag: "native-app-icon", |
| 1597 | app: props.app, |
| 1598 | }); |
| 1599 | return source ? ( |
| 1600 | <ToolActivityImage |
| 1601 | key={source} |
| 1602 | source={source} |
| 1603 | fallback={props.fallback} |
| 1604 | color={props.color} |
| 1605 | themeAppearance={props.themeAppearance} |
| 1606 | /> |
| 1607 | ) : ( |
| 1608 | <WorkLogIcon icon={props.fallback} color={props.color} /> |
| 1609 | ); |
| 1610 | } |
| 1611 | |
| 1612 | function ToolActivityImage(props: { |
| 1613 | readonly source: string; |
| 1614 | readonly fallback: WorkContentIcon; |
| 1615 | readonly color: ColorValue; |
| 1616 | readonly themeAppearance: "light" | "dark"; |
| 1617 | }) { |
| 1618 | const [loaded, setLoaded] = useState(false); |
| 1619 | const [failed, setFailed] = useState(false); |
| 1620 | return ( |
| 1621 | <View className="h-4 w-4 items-center justify-center overflow-hidden rounded-[3px] bg-screen"> |
| 1622 | {!loaded || failed ? <WorkLogIcon icon={props.fallback} color={props.color} /> : null} |
| 1623 | {!failed ? ( |
| 1624 | <View |
| 1625 | style={[ |
| 1626 | StyleSheet.absoluteFill, |
| 1627 | props.themeAppearance === "light" ? { filter: [{ brightness: 0.7 }] } : undefined, |
| 1628 | ]} |
| 1629 | > |
| 1630 | <Image |
| 1631 | source={props.source} |
| 1632 | cachePolicy="memory-disk" |
| 1633 | contentFit="contain" |
| 1634 | style={[ |
| 1635 | StyleSheet.absoluteFill, |
| 1636 | { opacity: loaded ? (props.themeAppearance === "dark" ? 0.7 : 1) : 0 }, |
| 1637 | ]} |
| 1638 | onLoad={() => setLoaded(true)} |
| 1639 | onError={() => setFailed(true)} |
| 1640 | /> |
| 1641 | </View> |
| 1642 | ) : null} |
| 1643 | </View> |
| 1644 | ); |
| 1645 | } |
| 1646 | |
| 1647 | function toolGroupSummarySymbolName(kind: ToolGroupSummaryKind): AppSymbolName { |
| 1648 | switch (kind) { |
| 1649 | case "pull-request": |
| 1650 | case "link-pr": |
| 1651 | case "unlink-pr": |
| 1652 | case "list-prs": |
| 1653 | case "watch-pr": |
| 1654 | case "unwatch-pr": |
| 1655 | return PullRequestGlyph.pullRequest; |
| 1656 | case "read": |
| 1657 | return { ios: "eye", android: "visibility" }; |
| 1658 | case "edit": |
| 1659 | return { ios: "square.and.pencil", android: "edit" }; |
| 1660 | case "thread-create": |
| 1661 | return { ios: "bubble.left", android: "chat" }; |
| 1662 | case "command": |
| 1663 | return { ios: "terminal", android: "terminal" }; |
| 1664 | case "device": |
| 1665 | return { ios: "iphone", android: "smartphone" }; |
| 1666 | case "browser": |
| 1667 | case "search": |
| 1668 | return { ios: "globe", android: "public" }; |
| 1669 | case "code-search": |
| 1670 | return "magnifyingglass"; |
| 1671 | case "other": |
| 1672 | return { ios: "wrench", android: "build" }; |
| 1673 | case "reasoning": |
| 1674 | return { ios: "brain", android: "psychology" }; |
| 1675 | case "agent-tool": |
| 1676 | return "robot"; |
| 1677 | case "tone-tool": |
| 1678 | return { ios: "bolt", android: "bolt" }; |
| 1679 | case "dynamic-tool": |
| 1680 | case "update": |
| 1681 | case "mixed": |
| 1682 | return { ios: "hammer", android: "construction" }; |
| 1683 | } |
| 1684 | } |