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

ThreadFeed.tsx

1,475 lines46.4 KB

1import * as Haptics from "expo-haptics";
2import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
3import { type LegendListRef } from "@legendapp/list/react-native";
4import type { EnvironmentId, MessageId, ThreadId, TurnId } from "@t3tools/contracts";
5import { CHAT_LIST_ANCHOR_OFFSET, resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
6import { SymbolView } from "expo-symbols";
7import { useRouter } from "expo-router";
8import {
9 memo,
10 useCallback,
11 useEffect,
12 useMemo,
13 useRef,
14 useState,
15 type ReactNode,
16 type RefObject,
17} from "react";
18import {
19 Markdown,
20 type CustomRenderers,
21 type NodeStyleOverrides,
22 type PartialMarkdownTheme,
23} from "react-native-nitro-markdown";
24import {
25 ActivityIndicator,
26 Image,
27 Linking,
28 Pressable,
29 ScrollView,
30 StyleSheet,
31 Text as NativeText,
32 type ColorValue,
33 useColorScheme,
34 useWindowDimensions,
35 View,
36} from "react-native";
37import { TouchableOpacity } from "react-native-gesture-handler";
38import ImageViewing from "react-native-image-viewing";
39import { useSafeAreaInsets } from "react-native-safe-area-context";
40import type { SharedValue } from "react-native-reanimated";
41import { useThemeColor } from "../../lib/useThemeColor";
42import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
43import {
44 hasNativeSelectableMarkdownText,
45 SelectableMarkdownText,
46 type NativeMarkdownTextStyle,
47 type SelectableMarkdownSkill,
48} from "../../native/SelectableMarkdownText";
49​
50import { AppText as Text } from "../../components/AppText";
51import { CopyTextButton } from "../../components/CopyTextButton";
52import {
53 parseReviewCommentMessageSegments,
54 type ReviewInlineComment,
55} from "../review/reviewCommentSelection";
56import { resolveNativeReviewDiffView } from "../diffs/nativeReviewDiffSurface";
57import {
58 buildNativeReviewDiffData,
59 createNativeReviewDiffTheme,
60 NATIVE_REVIEW_DIFF_CONTENT_WIDTH,
61 NATIVE_REVIEW_DIFF_ROW_HEIGHT,
62 NATIVE_REVIEW_DIFF_STYLE,
63} from "../review/nativeReviewDiffAdapter";
64import { buildReviewParsedDiff } from "../review/reviewModel";
65import { cn } from "../../lib/cn";
66import type { LayoutVariant } from "../../lib/layout";
67import { buildThreadFilesNavigation } from "../../lib/routes";
68import { MOBILE_CODE_SURFACE, MOBILE_TYPOGRAPHY } from "../../lib/typography";
69import { markdownFileIconSource } from "@t3tools/mobile-markdown-text/file-icons";
70import { resolveMarkdownLinkPresentation } from "@t3tools/mobile-markdown-text/links";
71import {
72 deriveThreadFeedPresentation,
73 type ThreadFeedEntry,
74 type ThreadFeedLatestTurn,
75} from "../../lib/threadActivity";
76import type { ThreadContentPresentation } from "./threadContentPresentation";
77import { ThreadWorkLog } from "./thread-work-log";
78import { useAssetUrl } from "../../state/assets";
79import { resolveWorkspaceRelativeFilePath } from "../files/filePath";
80​
81const MESSAGE_TIME_FORMATTER = new Intl.DateTimeFormat(undefined, {
82 hour: "numeric",
83 minute: "2-digit",
84});
85​
86function formatMessageTime(input: string): string {
87 const timestamp = Date.parse(input);
88 if (Number.isNaN(timestamp)) {
89 return "";
90 }
91 return MESSAGE_TIME_FORMATTER.format(timestamp);
93​
94export interface ThreadFeedProps {
95 readonly environmentId: EnvironmentId;
96 readonly threadId: ThreadId;
97 readonly workspaceRoot?: string | null;
98 readonly feed: ReadonlyArray<ThreadFeedEntry>;
99 readonly contentPresentation: ThreadContentPresentation;
100 readonly agentLabel: string;
101 readonly latestTurn: ThreadFeedLatestTurn | null;
102 readonly listRef: RefObject<LegendListRef | null>;
103 readonly freeze: SharedValue<boolean>;
104 readonly anchorMessageId: MessageId | null;
105 readonly contentInsetEndAdjustment: SharedValue<number>;
106 readonly contentTopInset?: number;
107 readonly contentBottomInset?: number;
108 readonly layoutVariant?: LayoutVariant;
109 readonly skills?: ReadonlyArray<SelectableMarkdownSkill>;
111​
112function MessageAttachmentImage(props: {
113 readonly environmentId: EnvironmentId;
114 readonly attachmentId: string;
115 readonly className: string;
116 readonly onPressImage: (uri: string, headers?: Record<string, string>) => void;
117}) {
118 const uri = useAssetUrl(props.environmentId, {
119 _tag: "attachment",
120 attachmentId: props.attachmentId,
121 });
122​
123 if (uri === null) {
124 return (
125 <View className={`${props.className} items-center justify-center`}>
126 <ActivityIndicator />
127 </View>
128 );
129 }
130​
131 return (
132 <TouchableOpacity activeOpacity={0.7} onPress={() => props.onPressImage(uri)}>
133 <Image source={{ uri }} className={props.className} resizeMode="cover" />
134 </TouchableOpacity>
135 );
137​
138const MARKDOWN_COLORS = {
139 light: {
140 body: "#111111",
141 strong: "#000000",
142 link: "#2563eb",
143 blockquoteBorder: "rgba(0, 0, 0, 0.08)",
144 blockquoteBackground: "rgba(0, 0, 0, 0.02)",
145 codeBackground: "rgba(0, 0, 0, 0.04)",
146 codeText: "#262626",
147 inlineCodeText: "#5f6368",
148 horizontalRule: "rgba(0, 0, 0, 0.08)",
149 userBody: "#ffffff",
150 userCodeBackground: "rgba(255, 255, 255, 0.22)",
151 userCodeText: "#ffffff",
152 userInlineCodeText: "rgba(255, 255, 255, 0.82)",
153 userFenceBackground: "rgba(0, 0, 0, 0.16)",
154 userFenceText: "#ffffff",
155 },
156 dark: {
157 body: "#e5e5e5",
158 strong: "#f5f5f5",
159 link: "#60a5fa",
160 blockquoteBorder: "rgba(255, 255, 255, 0.1)",
161 blockquoteBackground: "rgba(255, 255, 255, 0.03)",
162 codeBackground: "rgba(255, 255, 255, 0.06)",
163 codeText: "#e5e5e5",
164 inlineCodeText: "#b8bcc2",
165 horizontalRule: "rgba(255, 255, 255, 0.08)",
166 userBody: "#ffffff",
167 userCodeBackground: "rgba(255, 255, 255, 0.18)",
168 userCodeText: "#ffffff",
169 userInlineCodeText: "rgba(255, 255, 255, 0.82)",
170 userFenceBackground: "rgba(0, 0, 0, 0.28)",
171 userFenceText: "#ffffff",
172 },
173} as const;
174​
175interface MarkdownStyleSets {
176 readonly user: MarkdownStyleSet;
177 readonly assistant: MarkdownStyleSet;
179​
180interface MarkdownStyleSet {
181 readonly theme: PartialMarkdownTheme;
182 readonly styles: NodeStyleOverrides;
183 readonly renderers: CustomRenderers;
184 readonly nativeTextStyle: NativeMarkdownTextStyle;
186​
187interface ReviewCommentColors {
188 readonly background: ColorValue;
189 readonly border: ColorValue;
190 readonly mutedBackground: ColorValue;
191 readonly text: ColorValue;
192 readonly mutedText: ColorValue;
193 readonly codeBackground: ColorValue;
195​
196const failedMarkdownFaviconHosts = new Set<string>();
197const markdownLinkStyles = StyleSheet.create({
198 inlineIcon: {
199 width: 14,
200 height: 14,
201 marginHorizontal: 3,
202 transform: [{ translateY: 2 }],
203 },
204 favicon: {
205 borderRadius: 3,
206 },
207 file: {
208 fontFamily: "DMSans_700Bold",
209 fontWeight: "700",
210 },
211});
212​
213const MarkdownExternalLink = memo(function MarkdownExternalLink(props: {
214 readonly children: ReactNode;
215 readonly color: string;
216 readonly host: string;
217 readonly href: string;
218}) {
219 const [failed, setFailed] = useState(() => failedMarkdownFaviconHosts.has(props.host));
220​
221 return (
222 <NativeText
223 onPress={() => {
224 void Linking.openURL(props.href);
225 }}
226 style={{
227 color: props.color,
228 fontFamily: "DMSans_400Regular",
229 textDecorationLine: "none",
230 }}
231 >
232 {!failed ? (
233 <Image
234 source={{
235 uri: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(props.host)}&sz=32`,
236 }}
237 style={[markdownLinkStyles.inlineIcon, markdownLinkStyles.favicon]}
238 onError={() => {
239 failedMarkdownFaviconHosts.add(props.host);
240 setFailed(true);
241 }}
242 />
243 ) : (
244 <NativeText style={{ color: props.color }}>{" ◉ "}</NativeText>
245 )}
246 {props.children}
247 </NativeText>
248 );
249});
250​
251function useReviewCommentColors(): ReviewCommentColors {
252 const colorScheme = useColorScheme();
253 const isDark = colorScheme === "dark";
254 const background = isDark ? "#151515" : "#ffffff";
255 const border = isDark ? "#2a2a2a" : "#d7d7d7";
256 const mutedBackground = isDark ? "#242424" : "#f2f2f2";
257 const text = isDark ? "#f3f3f3" : "#111111";
258 const mutedText = isDark ? "#8f8f8f" : "#666666";
259 const codeBackground = isDark ? "#0f0f0f" : "#ffffff";
260​
261 return useMemo(
262 () => ({
263 background,
264 border,
265 mutedBackground,
266 text,
267 mutedText,
268 codeBackground,
269 }),
270 [background, border, codeBackground, mutedBackground, mutedText, text],
271 );
273​
274function useMarkdownStyles(onLinkPress: (href: string) => void): MarkdownStyleSets {
275 const colorScheme = useColorScheme();
276 const colors = MARKDOWN_COLORS[colorScheme === "dark" ? "dark" : "light"];
277 const inlineSkillForeground = String(useThemeColor("--color-inline-skill-foreground"));
278​
279 return useMemo(() => {
280 const markdownBodyColor = colors.body;
281 const markdownStrongColor = colors.strong;
282 const markdownLinkColor = colors.link;
283 const markdownBlockquoteBg = colors.blockquoteBackground;
284 const markdownBlockquoteBorder = colors.blockquoteBorder;
285 const markdownCodeBg = colors.codeBackground;
286 const markdownCodeText = colors.codeText;
287 const markdownInlineCodeText = colors.inlineCodeText;
288 const markdownHrColor = colors.horizontalRule;
289 const markdownUserBodyColor = colors.userBody;
290 const markdownUserCodeBg = colors.userCodeBackground;
291 const markdownUserCodeText = colors.userCodeText;
292 const markdownUserInlineCodeText = colors.userInlineCodeText;
293 const markdownUserFenceBg = colors.userFenceBackground;
294 const markdownUserFenceText = colors.userFenceText;
295​
296 const baseTheme: PartialMarkdownTheme = {
297 colors: {
298 text: markdownBodyColor,
299 heading: markdownStrongColor,
300 link: markdownLinkColor,
301 blockquote: markdownBlockquoteBorder,
302 border: markdownHrColor,
303 surfaceLight: markdownBlockquoteBg,
304 accent: markdownLinkColor,
305 tableBorder: markdownHrColor,
306 tableHeader: markdownBlockquoteBg,
307 tableHeaderText: markdownStrongColor,
308 tableRowOdd: "transparent",
309 tableRowEven: "transparent",
310 },
311 spacing: {
312 xs: 4,
313 s: 4,
314 m: 8,
315 l: 8,
316 xl: 16,
317 },
318 fontSizes: {
319 s: 13,
320 m: 15,
321 h1: 20,
322 h2: 18,
323 h3: 16,
324 h4: 14,
325 h5: 14,
326 h6: 14,
327 },
328 fontFamilies: {
329 regular: "DMSans_400Regular",
330 heading: "DMSans_700Bold",
331 mono: "ui-monospace",
332 },
333 headingWeight: "700",
334 borderRadius: {
335 s: 4,
336 m: 8,
337 l: 12,
338 },
339 showCodeLanguage: false,
340 };
341​
342 const baseStyles: NodeStyleOverrides = {
343 document: { flexShrink: 1 },
344 paragraph: { marginTop: 0, marginBottom: 10 },
345 list: { marginTop: 4, marginBottom: 8 },
346 list_item: { marginTop: 0, marginBottom: 4 },
347 task_list_item: { marginTop: 0, marginBottom: 4 },
348 text: { lineHeight: 22 },
349 bold: {
350 fontWeight: "700",
351 color: markdownStrongColor,
352 fontFamily: "DMSans_700Bold",
353 },
354 italic: { fontStyle: "italic" },
355 link: {
356 color: markdownLinkColor,
357 textDecorationLine: "underline" as const,
358 },
359 blockquote: {
360 borderLeftWidth: 2,
361 borderLeftColor: markdownBlockquoteBorder,
362 paddingLeft: 11,
363 paddingVertical: 2,
364 marginLeft: 0,
365 marginVertical: 10,
366 },
367 heading: {
368 fontFamily: "DMSans_700Bold",
369 color: markdownStrongColor,
370 marginTop: 18,
371 marginBottom: 8,
372 },
373 horizontal_rule: {
374 backgroundColor: markdownHrColor,
375 height: 1,
376 marginVertical: 12,
377 },
378 };
379​
380 const createMarkdownRenderers = (
381 inlineTextColor: string,
382 inlineCodeTextColor: string,
383 blockBackgroundColor: string,
384 blockTextColor: string,
385 preserveSoftBreaks: boolean,
386 ): CustomRenderers => ({
387 link: ({ children, href = "" }) => {
388 const presentation = resolveMarkdownLinkPresentation(href);
389 if (presentation.kind === "file") {
390 return (
391 <NativeText
392 onPress={() => onLinkPress(href)}
393 style={[markdownLinkStyles.file, { color: inlineTextColor }]}
394 >
395 <Image
396 source={markdownFileIconSource(presentation.icon)}
397 style={markdownLinkStyles.inlineIcon}
398 />
399 {presentation.label}
400 </NativeText>
401 );
402 }
403 if (presentation.kind === "external") {
404 return (
405 <MarkdownExternalLink
406 href={presentation.href}
407 host={presentation.host}
408 color={markdownLinkColor}
409 >
410 {children}
411 </MarkdownExternalLink>
412 );
413 }
414 const linkHref = presentation.href;
415 return (
416 <NativeText
417 onPress={
418 linkHref
419 ? () => {
420 void Linking.openURL(linkHref);
421 }
422 : undefined
423 }
424 style={{
425 color: markdownLinkColor,
426 textDecorationLine: "underline",
427 }}
428 >
429 {children}
430 </NativeText>
431 );
432 },
433 list: ({ node, Renderer, ordered = false, start = 1 }) => (
434 <View style={{ marginTop: 2, marginBottom: 8 }}>
435 {node.children?.map((child, index) => {
436 const childKey = `${child.type}:${child.beg ?? "unknown"}:${child.end ?? "unknown"}`;
437 if (child.type === "task_list_item") {
438 return (
439 <Renderer key={childKey} node={child} depth={1} inListItem parentIsText={false} />
440 );
441 }
442 return (
443 <View
444 key={childKey}
445 style={{
446 flexDirection: "row",
447 alignItems: "flex-start",
448 marginBottom: 3,
449 }}
450 >
451 <NativeText
452 style={{
453 width: ordered ? 22 : 12,
454 marginRight: 5,
455 color: inlineTextColor,
456 fontFamily: "DMSans_400Regular",
457 ...MOBILE_TYPOGRAPHY.body,
458 textAlign: ordered ? "right" : "center",
459 }}
460 >
461 {ordered ? `${start + index}.` : "•"}
462 </NativeText>
463 <View style={{ flex: 1, minWidth: 0 }}>
464 <Renderer node={child} depth={1} inListItem parentIsText={false} />
465 </View>
466 </View>
467 );
468 })}
469 </View>
470 ),
471 code_inline: ({ content }) => {
472 const value = content ?? "";
473 return (
474 <NativeText
475 style={{
476 color: inlineCodeTextColor,
477 fontFamily: "ui-monospace",
478 fontSize: MOBILE_TYPOGRAPHY.label.fontSize,
479 lineHeight: 22,
480 }}
481 >
482 {value}
483 </NativeText>
484 );
485 },
486 ...(preserveSoftBreaks
487 ? {
488 soft_break: () => <NativeText>{"\n"}</NativeText>,
489 }
490 : {}),
491 code_block: ({ content, language }) => (
492 <View
493 style={{
494 backgroundColor: blockBackgroundColor,
495 borderRadius: 10,
496 borderWidth: 1,
497 borderColor: markdownHrColor,
498 marginVertical: 12,
499 overflow: "hidden",
500 }}
501 >
502 {language ? (
503 <View
504 style={{
505 borderBottomWidth: 1,
506 borderBottomColor: markdownHrColor,
507 paddingHorizontal: 14,
508 paddingVertical: 8,
509 }}
510 >
511 <NativeText
512 style={{
513 color: markdownBodyColor,
514 fontFamily: "ui-monospace",
515 fontSize: MOBILE_TYPOGRAPHY.label.fontSize,
516 opacity: 0.7,
517 textTransform: "uppercase",
518 }}
519 >
520 {language}
521 </NativeText>
522 </View>
523 ) : null}
524 <ScrollView
525 horizontal
526 showsHorizontalScrollIndicator={false}
527 bounces={false}
528 contentContainerStyle={{ paddingHorizontal: 14, paddingVertical: 12 }}
529 >
530 <NativeText
531 selectable
532 style={{
533 color: blockTextColor,
534 fontFamily: "ui-monospace",
535 fontSize: MOBILE_TYPOGRAPHY.label.fontSize,
536 lineHeight: 18,
537 }}
538 >
539 {content}
540 </NativeText>
541 </ScrollView>
542 </View>
543 ),
544 });
545​
546 const userTheme: PartialMarkdownTheme = {
547 ...baseTheme,
548 colors: {
549 ...baseTheme.colors,
550 text: markdownUserBodyColor,
551 heading: markdownUserBodyColor,
552 link: markdownUserBodyColor,
553 code: markdownUserCodeText,
554 codeBackground: markdownUserCodeBg,
555 border: markdownUserFenceBg,
556 },
557 };
558 const userStyles: NodeStyleOverrides = {
559 ...baseStyles,
560 paragraph: { marginTop: 0, marginBottom: 0 },
561 bold: {
562 fontWeight: "700",
563 color: markdownUserBodyColor,
564 fontFamily: "DMSans_700Bold",
565 },
566 heading: {
567 ...baseStyles.heading,
568 color: markdownUserBodyColor,
569 marginTop: 8,
570 marginBottom: 4,
571 },
572 link: {
573 color: markdownUserBodyColor,
574 textDecorationLine: "underline" as const,
575 },
576 };
577​
578 const assistantTheme: PartialMarkdownTheme = {
579 ...baseTheme,
580 colors: {
581 ...baseTheme.colors,
582 code: markdownCodeText,
583 codeBackground: markdownCodeBg,
584 border: markdownCodeBg,
585 },
586 };
587 const assistantStyles: NodeStyleOverrides = {
588 ...baseStyles,
589 };
590​
591 return {
592 user: {
593 theme: userTheme,
594 styles: userStyles,
595 renderers: createMarkdownRenderers(
596 markdownUserCodeText,
597 markdownUserInlineCodeText,
598 markdownUserFenceBg,
599 markdownUserFenceText,
600 true,
601 ),
602 nativeTextStyle: {
603 color: markdownUserBodyColor,
604 strongColor: markdownUserBodyColor,
605 mutedColor: markdownUserBodyColor,
606 linkColor: markdownUserBodyColor,
607 inlineCodeColor: markdownUserInlineCodeText,
608 codeColor: markdownUserCodeText,
609 codeBackgroundColor: markdownUserCodeBg,
610 codeBlockBackgroundColor: markdownUserFenceBg,
611 fileTextColor: "#ffffff",
612 skillTextColor: "#f0abfc",
613 quoteMarkerColor: markdownUserBodyColor,
614 dividerColor: markdownUserBodyColor,
615 ...MOBILE_TYPOGRAPHY.body,
616 fontFamily: "DMSans_400Regular",
617 headingFontFamily: "DMSans_700Bold",
618 boldFontFamily: "DMSans_700Bold",
619 },
620 },
621 assistant: {
622 theme: assistantTheme,
623 styles: assistantStyles,
624 renderers: createMarkdownRenderers(
625 markdownCodeText,
626 markdownInlineCodeText,
627 markdownCodeBg,
628 markdownCodeText,
629 false,
630 ),
631 nativeTextStyle: {
632 color: markdownBodyColor,
633 strongColor: markdownStrongColor,
634 mutedColor: markdownBodyColor,
635 linkColor: markdownLinkColor,
636 inlineCodeColor: markdownInlineCodeText,
637 codeColor: markdownCodeText,
638 codeBackgroundColor: markdownCodeBg,
639 codeBlockBackgroundColor: markdownCodeBg,
640 fileTextColor: markdownCodeText,
641 skillTextColor: inlineSkillForeground,
642 quoteMarkerColor: markdownBlockquoteBorder,
643 dividerColor: markdownHrColor,
644 ...MOBILE_TYPOGRAPHY.body,
645 fontFamily: "DMSans_400Regular",
646 headingFontFamily: "DMSans_700Bold",
647 boldFontFamily: "DMSans_700Bold",
648 },
649 },
650 };
651 }, [colors, inlineSkillForeground, onLinkPress]);
653​
654function renderFeedEntry(
655 info: { item: ThreadFeedEntry; index: number },
656 props: Pick<ThreadFeedProps, "environmentId" | "skills"> & {
657 readonly copiedRowId: string | null;
658 readonly expandedWorkGroups: Record<string, boolean>;
659 readonly expandedWorkRows: Record<string, boolean>;
660 readonly terminalAssistantMessageIds: ReadonlySet<string>;
661 readonly unsettledTurnId: TurnId | null;
662 readonly onCopyWorkRow: (rowId: string, value: string) => void;
663 readonly onToggleWorkGroup: (groupId: string) => void;
664 readonly onToggleWorkRow: (rowId: string) => void;
665 readonly onToggleTurnFold: (turnId: TurnId) => void;
666 readonly onPressImage: (uri: string, headers?: Record<string, string>) => void;
667 readonly onMarkdownLinkPress: (href: string) => void;
668 readonly iconSubtleColor: string | import("react-native").ColorValue;
669 readonly userBubbleColor: string | import("react-native").ColorValue;
670 readonly markdownStyles: MarkdownStyleSets;
671 readonly reviewCommentColors: ReviewCommentColors;
672 readonly reviewCommentBubbleWidth: number;
673 readonly userBubbleMaxWidth: number;
674 },
675) {
676 const entry = info.item;
677 const { markdownStyles, iconSubtleColor, userBubbleColor } = props;
678​
679 if (entry.type === "turn-fold") {
680 return (
681 <Pressable
682 accessibilityRole="button"
683 accessibilityState={{ expanded: entry.expanded }}
684 onPress={() => props.onToggleTurnFold(entry.turnId)}
685 hitSlop={4}
686 className="mb-3 min-h-11 flex-row items-center gap-2 border-b border-neutral-200/80 px-2 dark:border-white/[0.08]"
687 >
688 <Text className="font-t3-medium text-sm tabular-nums text-foreground-muted">
689 {entry.label}
690 </Text>
691 <SymbolView
692 name={entry.expanded ? "chevron.down" : "chevron.right"}
693 size={15}
694 tintColor={iconSubtleColor}
695 type="monochrome"
696 />
697 </Pressable>
698 );
699 }
700​
701 if (entry.type === "message") {
702 const { message } = entry;
703 const isUser = message.role === "user";
704 const styles = isUser ? markdownStyles.user : markdownStyles.assistant;
705 const timestampLabel = formatMessageTime(isUser ? message.createdAt : message.updatedAt);
706 const attachments = message.attachments ?? [];
707 const hasReviewCommentContext = message.text.includes("<review_comment");
708 const assistantTurnStillInProgress =
709 message.role === "assistant" &&
710 props.unsettledTurnId !== null &&
711 message.turnId === props.unsettledTurnId;
712 const showAssistantMeta =
713 message.role === "assistant" &&
714 props.terminalAssistantMessageIds.has(message.id) &&
715 !assistantTurnStillInProgress &&
716 !message.streaming;
717​
718 if (isUser) {
719 return (
720 <View className="mb-5 items-end">
721 <View
722 className="min-w-0 gap-2 rounded-[20px] px-3.5 py-2.5"
723 style={{
724 backgroundColor: userBubbleColor,
725 maxWidth: props.userBubbleMaxWidth,
726 ...(hasReviewCommentContext ? { width: props.reviewCommentBubbleWidth } : null),
727 }}
728 >
729 {message.text.trim().length > 0 ? (
730 <UserMessageContent
731 text={message.text}
732 markdownStyles={styles}
733 reviewCommentColors={props.reviewCommentColors}
734 skills={props.skills}
735 onLinkPress={props.onMarkdownLinkPress}
736 />
737 ) : null}
738 {attachments.map((attachment) => {
739 return (
740 <MessageAttachmentImage
741 key={attachment.id}
742 environmentId={props.environmentId}
743 attachmentId={attachment.id}
744 className="aspect-[1.3] w-full rounded-[14px] bg-white/15"
745 onPressImage={props.onPressImage}
746 />
747 );
748 })}
749 </View>
750 <View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
751 <Text className="font-t3-medium text-xs tabular-nums text-neutral-600 dark:text-neutral-400">
752 {timestampLabel}
753 </Text>
754 {message.text.trim().length > 0 ? (
755 <CopyTextButton
756 accessibilityLabel="Copy message"
757 text={message.text}
758 tintColor={iconSubtleColor}
759 buttonSize={28}
760 iconSize={13}
761 />
762 ) : null}
763 </View>
764 </View>
765 );
766 }
767​
768 // Skip empty assistant messages (no text, no attachments) — they would
769 // render as an orphaned timestamp and break adjacent activity-group merging.
770 if (message.text.trim().length === 0 && attachments.length === 0) {
771 return null;
772 }
773​
774 return (
775 <View className={cn(showAssistantMeta ? "mb-5 px-1" : "mb-2 px-1")}>
776 {message.text.trim().length > 0 ? (
777 hasNativeSelectableMarkdownText() ? (
778 <SelectableMarkdownText
779 markdown={message.text}
780 skills={props.skills}
781 textStyle={styles.nativeTextStyle}
782 onLinkPress={props.onMarkdownLinkPress}
783 />
784 ) : (
785 <Markdown
786 options={{ gfm: true }}
787 renderers={styles.renderers}
788 styles={styles.styles}
789 theme={styles.theme}
790 >
791 {message.text}
792 </Markdown>
793 )
794 ) : null}
795 {attachments.map((attachment) => {
796 return (
797 <MessageAttachmentImage
798 key={attachment.id}
799 environmentId={props.environmentId}
800 attachmentId={attachment.id}
801 className="mt-1.5 aspect-[1.3] w-full rounded-[18px] bg-neutral-200 dark:bg-neutral-800"
802 onPressImage={props.onPressImage}
803 />
804 );
805 })}
806 {showAssistantMeta ? (
807 <View className="mt-1 flex-row items-center gap-1">
808 <CopyTextButton
809 accessibilityLabel="Copy message"
810 text={message.text}
811 tintColor={iconSubtleColor}
812 buttonSize={28}
813 iconSize={13}
814 />
815 <Text className="font-t3-medium text-xs tabular-nums text-neutral-600 dark:text-neutral-400">
816 {timestampLabel}
817 </Text>
818 </View>
819 ) : null}
820 </View>
821 );
822 }
823​
824 return (
825 <ThreadWorkLog
826 activities={entry.activities}
827 copiedRowId={props.copiedRowId}
828 expanded={props.expandedWorkGroups[entry.id] ?? false}
829 expandedRows={props.expandedWorkRows}
830 iconSubtleColor={iconSubtleColor}
831 onCopyRow={props.onCopyWorkRow}
832 onToggleGroup={() => props.onToggleWorkGroup(entry.id)}
833 onToggleRow={props.onToggleWorkRow}
834 />
835 );
837​
838function UserMessageContent(props: {
839 readonly text: string;
840 readonly markdownStyles: MarkdownStyleSet;
841 readonly reviewCommentColors: ReviewCommentColors;
842 readonly skills?: ReadonlyArray<SelectableMarkdownSkill>;
843 readonly onLinkPress: (href: string) => void;
844}) {
845 const segments = parseReviewCommentMessageSegments(props.text);
846 const hasReviewComment = segments.some((segment) => segment.kind === "review-comment");
847 if (!hasReviewComment) {
848 if (hasNativeSelectableMarkdownText()) {
849 return (
850 <SelectableMarkdownText
851 markdown={props.text}
852 skills={props.skills}
853 textStyle={props.markdownStyles.nativeTextStyle}
854 preserveSoftBreaks
855 onLinkPress={props.onLinkPress}
856 />
857 );
858 }
859 return (
860 <Markdown
861 options={{ gfm: true }}
862 renderers={props.markdownStyles.renderers}
863 styles={props.markdownStyles.styles}
864 theme={props.markdownStyles.theme}
865 >
866 {props.text}
867 </Markdown>
868 );
869 }
870​
871 return (
872 <View className="w-full gap-2">
873 {segments.map((segment) => {
874 if (segment.kind === "review-comment") {
875 return (
876 <ReviewCommentCard
877 key={segment.comment.id}
878 comment={segment.comment}
879 colors={props.reviewCommentColors}
880 />
881 );
882 }
883​
884 const text = segment.text.trim();
885 if (text.length === 0) {
886 return null;
887 }
888​
889 return hasNativeSelectableMarkdownText() ? (
890 <SelectableMarkdownText
891 key={segment.id}
892 markdown={text}
893 skills={props.skills}
894 textStyle={props.markdownStyles.nativeTextStyle}
895 preserveSoftBreaks
896 onLinkPress={props.onLinkPress}
897 />
898 ) : (
899 <Markdown
900 key={segment.id}
901 options={{ gfm: true }}
902 renderers={props.markdownStyles.renderers}
903 styles={props.markdownStyles.styles}
904 theme={props.markdownStyles.theme}
905 >
906 {text}
907 </Markdown>
908 );
909 })}
910 </View>
911 );
913​
914const ReviewCommentCard = memo(function ReviewCommentCard(props: {
915 readonly comment: ReviewInlineComment;
916 readonly colors: ReviewCommentColors;
917}) {
918 const colorScheme = useColorScheme();
919 const appearanceScheme = colorScheme === "light" ? "light" : "dark";
920 const NativeReviewDiffView = resolveNativeReviewDiffView();
921 const patch = useMemo(() => buildReviewCommentPatch(props.comment), [props.comment]);
922 const parsedDiff = useMemo(
923 () => buildReviewParsedDiff(patch, `thread-review-comment:${props.comment.id}`),
924 [patch, props.comment.id],
925 );
926 const nativeReviewDiffData = useMemo(() => buildNativeReviewDiffData(parsedDiff), [parsedDiff]);
927 const compactNativeRows = useMemo(
928 () => nativeReviewDiffData.rows.filter((row) => row.kind !== "file"),
929 [nativeReviewDiffData.rows],
930 );
931 const nativeReviewDiffTheme = useMemo(
932 () => createNativeReviewDiffTheme(appearanceScheme),
933 [appearanceScheme],
934 );
935 const nativeRowsJson = useMemo(() => JSON.stringify(compactNativeRows), [compactNativeRows]);
936 const nativeThemeJson = useMemo(
937 () => JSON.stringify(nativeReviewDiffTheme),
938 [nativeReviewDiffTheme],
939 );
940 const nativeStyleJson = useMemo(() => JSON.stringify(NATIVE_REVIEW_DIFF_STYLE), []);
941 const nativeDiffHeight = useMemo(
942 () =>
943 Math.min(
944 360,
945 Math.max(
946 112,
947 compactNativeRows.length * NATIVE_REVIEW_DIFF_ROW_HEIGHT +
948 NATIVE_REVIEW_DIFF_STYLE.fileHeaderVerticalMargin,
949 ),
950 ),
951 [compactNativeRows.length],
952 );
953 const shouldRenderNativeDiff = NativeReviewDiffView != null && compactNativeRows.length > 0;
954​
955 return (
956 <View
957 className="w-full overflow-hidden rounded-[16px] border"
958 style={{
959 backgroundColor: props.colors.background,
960 borderColor: props.colors.border,
961 borderCurve: "continuous",
962 }}
963 >
964 <View
965 className="flex-row items-center gap-2 border-b px-3 py-2"
966 style={{ borderColor: props.colors.border }}
967 >
968 <View
969 className="size-6 items-center justify-center rounded-[7px]"
970 style={{ backgroundColor: props.colors.mutedBackground, borderCurve: "continuous" }}
971 >
972 <SymbolView
973 name="doc.text"
974 size={13}
975 tintColor={props.colors.mutedText}
976 type="monochrome"
977 />
978 </View>
979 <View className="min-w-0 flex-1">
980 <Text
981 className="font-mono text-xs leading-[16px]"
982 numberOfLines={1}
983 style={{ color: props.colors.text }}
984 >
985 {compactFileName(props.comment.filePath)}
986 </Text>
987 </View>
988 </View>
989 {shouldRenderNativeDiff ? (
990 <View
991 className="border-t"
992 collapsable={false}
993 style={{
994 backgroundColor: nativeReviewDiffTheme.background,
995 borderColor: props.colors.border,
996 height: nativeDiffHeight,
997 }}
998 >
999 <NativeReviewDiffView
1000 collapsable={false}
1001 style={StyleSheet.absoluteFill}
1002 appearanceScheme={appearanceScheme}
1003 contentWidth={NATIVE_REVIEW_DIFF_CONTENT_WIDTH}
1004 rowHeight={NATIVE_REVIEW_DIFF_ROW_HEIGHT}
1005 rowsJson={nativeRowsJson}
1006 styleJson={nativeStyleJson}
1007 themeJson={nativeThemeJson}
1008 />
1009 </View>
1010 ) : props.comment.diff.trim().length > 0 ? (
1011 <ScrollView
1012 horizontal
1013 nestedScrollEnabled
1014 directionalLockEnabled
1015 showsHorizontalScrollIndicator={false}
1016 bounces={false}
1017 className="border-t"
1018 style={{ backgroundColor: props.colors.codeBackground, borderColor: props.colors.border }}
1019 contentContainerStyle={{ padding: 10 }}
1021 <NativeText
1022 selectable
1023 style={{
1024 color: props.colors.text,
1025 fontFamily: "ui-monospace",
1026 fontSize: MOBILE_CODE_SURFACE.fontSize,
1027 lineHeight: MOBILE_CODE_SURFACE.rowHeight,
1028 }}
1030 {props.comment.diff.trim()}
1031 </NativeText>
1032 </ScrollView>
1033 ) : null}
1034 {props.comment.text.length > 0 ? (
1035 <View className="border-t px-3 py-3" style={{ borderColor: props.colors.border }}>
1036 <Text
1037 selectable
1038 className="text-base leading-[21px]"
1039 style={{ color: props.colors.text }}
1041 {props.comment.text}
1042 </Text>
1043 </View>
1044 ) : null}
1045 </View>
1046 );
1047});
1048​
1049function buildReviewCommentPatch(comment: ReviewInlineComment): string {
1050 if ((comment.fenceLanguage ?? "diff") !== "diff") {
1051 return "";
1053 const diff = comment.diff.trim();
1054 if (!diff) {
1055 return "";
1057​
1058 if (diff.startsWith("diff --git ")) {
1059 return diff;
1061​
1062 const normalizedPath = comment.filePath.replaceAll("\\", "/");
1063 return [
1064 `diff --git a/${normalizedPath} b/${normalizedPath}`,
1065 `--- a/${normalizedPath}`,
1066 `+++ b/${normalizedPath}`,
1067 diff,
1068 ].join("\n");
1070​
1071function compactFileName(filePath: string): string {
1072 const normalized = filePath.replaceAll("\\", "/");
1073 const lastSlashIndex = normalized.lastIndexOf("/");
1074 return lastSlashIndex >= 0 ? normalized.slice(lastSlashIndex + 1) : normalized;
1076​
1077function ThreadFeedPlaceholder(props: {
1078 readonly bottomInset: number;
1079 readonly detail: string;
1080 readonly horizontalPadding: number;
1081 readonly loading?: boolean;
1082 readonly title: string;
1083 readonly topInset: number;
1084}) {
1085 return (
1086 <View
1087 style={{
1088 flex: 1,
1089 flexGrow: 1,
1090 alignItems: "center",
1091 justifyContent: "center",
1092 paddingTop: props.topInset,
1093 paddingBottom: props.bottomInset,
1094 paddingHorizontal: props.horizontalPadding + 24,
1095 }}
1097 <View className="max-w-[320px] items-center gap-2">
1098 {props.loading ? <ActivityIndicator style={{ marginBottom: 6 }} /> : null}
1099 <Text className="text-center font-t3-bold text-lg text-foreground">{props.title}</Text>
1100 <Text className="text-center text-sm leading-5 text-foreground-secondary">
1101 {props.detail}
1102 </Text>
1103 </View>
1104 </View>
1105 );
1107​
1108export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
1109 const router = useRouter();
1110 const copyFeedbackTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
1111 const foldSettleFrameRef = useRef<number | null>(null);
1112 const foldSettleSecondFrameRef = useRef<number | null>(null);
1113 const previousLatestTurnRef = useRef(props.latestTurn);
1114 const { width: viewportWidth } = useWindowDimensions();
1115 const [foldToggleSettling, setFoldToggleSettling] = useState(false);
1116 const [interactionState, setInteractionState] = useState<{
1117 readonly copiedRowId: string | null;
1118 readonly expandedWorkGroups: Record<string, boolean>;
1119 readonly expandedWorkRows: Record<string, boolean>;
1120 readonly expandedTurnIds: ReadonlySet<TurnId>;
1121 }>({
1122 copiedRowId: null,
1123 expandedWorkGroups: {},
1124 expandedWorkRows: {},
1125 expandedTurnIds: new Set(),
1126 });
1127 const { copiedRowId, expandedWorkGroups, expandedWorkRows, expandedTurnIds } = interactionState;
1128 const [expandedImage, setExpandedImage] = useState<{
1129 uri: string;
1130 headers?: Record<string, string>;
1131 } | null>(null);
1132 const horizontalPadding = props.layoutVariant === "split" ? 20 : 16;
1133 const contentWidth = Math.max(0, viewportWidth - horizontalPadding * 2);
1134 const userBubbleMaxWidth = contentWidth * 0.85;
1135 const reviewCommentBubbleWidth = Math.min(Math.max(280, contentWidth * 0.85), contentWidth);
1136 const insets = useSafeAreaInsets();
1137 const topContentInset = props.contentTopInset ?? insets.top + 44;
1138 const bottomContentInset = props.contentBottomInset ?? 18;
1139​
1140 const iconSubtleColor = useThemeColor("--color-icon-subtle");
1141 const userBubbleColor = useThemeColor("--color-user-bubble");
1142 const onMarkdownLinkPress = useCallback(
1143 (href: string) => {
1144 const presentation = resolveMarkdownLinkPresentation(href);
1145 if (presentation.kind === "file") {
1146 const relativePath = resolveWorkspaceRelativeFilePath(
1147 props.workspaceRoot,
1148 presentation.path,
1149 );
1150 if (relativePath) {
1151 void Haptics.selectionAsync();
1152 router.push(
1153 buildThreadFilesNavigation(
1154 { environmentId: props.environmentId, threadId: props.threadId },
1155 relativePath,
1156 presentation.line,
1157 ),
1158 );
1160 return;
1162​
1163 if (presentation.href) {
1164 void Linking.openURL(presentation.href);
1166 },
1167 [props.environmentId, props.threadId, props.workspaceRoot, router],
1168 );
1169 const markdownStyles = useMarkdownStyles(onMarkdownLinkPress);
1170 const reviewCommentColors = useReviewCommentColors();
1171 // LegendList does not invalidate visible rows when only the renderItem closure changes.
1172 // Keep row-local interaction props in extraData so disclosures and copy feedback repaint.
1173 const listAppearanceData = useMemo(
1174 () => ({
1175 copiedRowId,
1176 expandedWorkGroups,
1177 expandedWorkRows,
1178 iconSubtleColor,
1179 markdownStyles,
1180 reviewCommentColors,
1181 userBubbleColor,
1182 }),
1184 copiedRowId,
1185 expandedWorkGroups,
1186 expandedWorkRows,
1187 iconSubtleColor,
1188 markdownStyles,
1189 reviewCommentColors,
1190 userBubbleColor,
1191 ],
1192 );
1193 const presentedFeed = useMemo(
1194 () => deriveThreadFeedPresentation(props.feed, props.latestTurn, expandedTurnIds),
1195 [expandedTurnIds, props.feed, props.latestTurn],
1196 );
1197 const anchoredEndSpace = useMemo(
1198 () =>
1199 resolveChatListAnchoredEndSpace(
1200 presentedFeed,
1201 props.anchorMessageId,
1202 (entry) => (entry.type === "message" ? entry.id : null),
1203 { anchorOffset: topContentInset + CHAT_LIST_ANCHOR_OFFSET },
1204 ),
1205 [presentedFeed, props.anchorMessageId, topContentInset],
1206 );
1207 const terminalAssistantMessageIds = useMemo(() => {
1208 const terminalIdsByTurn = new Map<TurnId, string>();
1209 for (const entry of props.feed) {
1210 if (entry.type === "message" && entry.message.role === "assistant" && entry.message.turnId) {
1211 terminalIdsByTurn.set(entry.message.turnId, entry.message.id);
1214 return new Set(terminalIdsByTurn.values());
1215 }, [props.feed]);
1216 const unsettledTurnId =
1217 props.latestTurn &&
1218 (props.latestTurn.completedAt === null || props.latestTurn.state === "running")
1219 ? props.latestTurn.turnId
1220 : null;
1221​
1222 useEffect(() => {
1223 const previous = previousLatestTurnRef.current;
1224 previousLatestTurnRef.current = props.latestTurn;
1225 if (!props.latestTurn || !previous) {
1226 return;
1228 if (props.latestTurn.turnId === previous.turnId) {
1229 if (previous.state === "running" && props.latestTurn.state === "interrupted") {
1230 const interruptedTurnId = props.latestTurn.turnId;
1231 setInteractionState((current) => ({
1232 ...current,
1233 expandedTurnIds: new Set(current.expandedTurnIds).add(interruptedTurnId),
1234 }));
1236 return;
1238 setInteractionState((current) => {
1239 if (!current.expandedTurnIds.has(previous.turnId)) {
1240 return current;
1242 const next = new Set(current.expandedTurnIds);
1243 next.delete(previous.turnId);
1244 return { ...current, expandedTurnIds: next };
1245 });
1246 }, [props.latestTurn]);
1247​
1248 useEffect(() => {
1249 return () => {
1250 if (copyFeedbackTimeoutRef.current) {
1251 clearTimeout(copyFeedbackTimeoutRef.current);
1253 if (foldSettleFrameRef.current !== null) {
1254 cancelAnimationFrame(foldSettleFrameRef.current);
1256 if (foldSettleSecondFrameRef.current !== null) {
1257 cancelAnimationFrame(foldSettleSecondFrameRef.current);
1259 };
1260 }, []);
1261​
1262 const onCopyWorkRow = useCallback((rowId: string, value: string) => {
1263 copyTextWithHaptic(value, {
1264 target: "thread-work-row",
1265 feedback: "selection",
1266 });
1267 setInteractionState((current) => ({ ...current, copiedRowId: rowId }));
1268 if (copyFeedbackTimeoutRef.current) {
1269 clearTimeout(copyFeedbackTimeoutRef.current);
1271 copyFeedbackTimeoutRef.current = setTimeout(() => {
1272 setInteractionState((current) =>
1273 current.copiedRowId === rowId ? { ...current, copiedRowId: null } : current,
1274 );
1275 copyFeedbackTimeoutRef.current = null;
1276 }, 1200);
1277 }, []);
1278​
1279 const onToggleWorkGroup = useCallback((groupId: string) => {
1280 setInteractionState((current) => ({
1281 ...current,
1282 expandedWorkGroups: {
1283 ...current.expandedWorkGroups,
1284 [groupId]: !(current.expandedWorkGroups[groupId] ?? false),
1285 },
1286 }));
1287 }, []);
1288​
1289 const onToggleWorkRow = useCallback((rowId: string) => {
1290 setInteractionState((current) => ({
1291 ...current,
1292 expandedWorkRows: {
1293 ...current.expandedWorkRows,
1294 [rowId]: !(current.expandedWorkRows[rowId] ?? false),
1295 },
1296 }));
1297 }, []);
1298​
1299 const onToggleTurnFold = useCallback((turnId: TurnId) => {
1300 setFoldToggleSettling(true);
1301 if (foldSettleFrameRef.current !== null) {
1302 cancelAnimationFrame(foldSettleFrameRef.current);
1304 if (foldSettleSecondFrameRef.current !== null) {
1305 cancelAnimationFrame(foldSettleSecondFrameRef.current);
1307 setInteractionState((current) => {
1308 const next = new Set(current.expandedTurnIds);
1309 if (next.has(turnId)) {
1310 next.delete(turnId);
1311 } else {
1312 next.add(turnId);
1314 return { ...current, expandedTurnIds: next };
1315 });
1316 foldSettleFrameRef.current = requestAnimationFrame(() => {
1317 foldSettleSecondFrameRef.current = requestAnimationFrame(() => {
1318 setFoldToggleSettling(false);
1319 foldSettleFrameRef.current = null;
1320 foldSettleSecondFrameRef.current = null;
1321 });
1322 });
1323 }, []);
1324​
1325 const onPressImage = useCallback((uri: string, headers?: Record<string, string>) => {
1326 setExpandedImage({ uri, headers });
1327 }, []);
1328​
1329 const renderItem = useCallback(
1330 (info: { item: ThreadFeedEntry; index: number }) =>
1331 renderFeedEntry(info, {
1332 environmentId: props.environmentId,
1333 copiedRowId,
1334 expandedWorkGroups,
1335 expandedWorkRows,
1336 terminalAssistantMessageIds,
1337 unsettledTurnId,
1338 onCopyWorkRow,
1339 onToggleWorkGroup,
1340 onToggleWorkRow,
1341 onToggleTurnFold,
1342 onPressImage,
1343 onMarkdownLinkPress,
1344 iconSubtleColor,
1345 userBubbleColor,
1346 markdownStyles,
1347 reviewCommentColors,
1348 reviewCommentBubbleWidth,
1349 userBubbleMaxWidth,
1350 skills: props.skills,
1351 }),
1353 copiedRowId,
1354 expandedWorkGroups,
1355 expandedWorkRows,
1356 terminalAssistantMessageIds,
1357 unsettledTurnId,
1358 iconSubtleColor,
1359 userBubbleColor,
1360 markdownStyles,
1361 reviewCommentColors,
1362 reviewCommentBubbleWidth,
1363 userBubbleMaxWidth,
1364 onCopyWorkRow,
1365 onMarkdownLinkPress,
1366 onPressImage,
1367 onToggleTurnFold,
1368 onToggleWorkGroup,
1369 onToggleWorkRow,
1370 props.environmentId,
1371 props.skills,
1372 ],
1373 );
1374​
1375 if (props.contentPresentation.kind === "loading") {
1376 return (
1377 <ThreadFeedPlaceholder
1378 title="Loading conversation"
1379 detail="Fetching the latest messages from this environment."
1380 loading
1381 topInset={topContentInset}
1382 bottomInset={bottomContentInset}
1383 horizontalPadding={horizontalPadding}
1384 />
1385 );
1387​
1388 if (props.contentPresentation.kind === "unavailable") {
1389 return (
1390 <ThreadFeedPlaceholder
1391 title={props.contentPresentation.title}
1392 detail={props.contentPresentation.detail}
1393 topInset={topContentInset}
1394 bottomInset={bottomContentInset}
1395 horizontalPadding={horizontalPadding}
1396 />
1397 );
1399​
1400 return (
1401 <>
1402 <View style={{ flex: 1 }}>
1403 <KeyboardAwareLegendList
1404 ref={props.listRef}
1405 key={props.threadId}
1406 style={{ flex: 1 }}
1407 automaticallyAdjustsScrollIndicatorInsets={false}
1408 scrollIndicatorInsets={{ top: topContentInset, bottom: 0 }}
1409 {...(anchoredEndSpace ? { anchoredEndSpace } : {})}
1410 contentInsetEndAdjustment={props.contentInsetEndAdjustment}
1411 freeze={props.freeze}
1412 maintainScrollAtEnd={
1413 foldToggleSettling
1414 ? false
1415 : {
1416 animated: false,
1417 on: {
1418 dataChange: true,
1419 itemLayout: true,
1420 layout: true,
1421 },
1424 maintainVisibleContentPosition
1425 data={presentedFeed}
1426 extraData={listAppearanceData}
1427 renderItem={renderItem}
1428 keyExtractor={(entry) => entry.id}
1429 getItemType={(entry) =>
1430 entry.type === "message" ? `message:${entry.message.role}` : entry.type
1432 keyboardShouldPersistTaps="always"
1433 keyboardDismissMode="none"
1434 keyboardLiftBehavior="whenAtEnd"
1435 estimatedItemSize={180}
1436 initialScrollAtEnd
1437 ListHeaderComponent={<View style={{ height: topContentInset }} />}
1438 contentContainerStyle={{
1439 paddingTop: 12,
1440 paddingHorizontal: horizontalPadding,
1441 }}
1442 />
1443 {props.feed.length === 0 ? (
1444 <View pointerEvents="none" style={StyleSheet.absoluteFill}>
1445 <ThreadFeedPlaceholder
1446 title="No conversation yet"
1447 detail="Ask the agent to inspect the repo, run a command, or continue the active thread."
1448 topInset={topContentInset}
1449 bottomInset={bottomContentInset}
1450 horizontalPadding={horizontalPadding}
1451 />
1452 </View>
1453 ) : null}
1454 </View>
1455​
1456 <ImageViewing
1457 images={
1458 expandedImage
1459 ? [
1461 uri: expandedImage.uri,
1462 headers: expandedImage.headers,
1463 },
1465 : []
1467 imageIndex={0}
1468 visible={expandedImage !== null}
1469 onRequestClose={() => setExpandedImage(null)}
1470 swipeToCloseEnabled
1471 doubleTapToZoomEnabled
1472 />
1473 </>
1474 );
1475});