Skip to content

Commit f15680b

Browse files
feat(mobile): update tool summaries and chat transitions (pingdotgg#8793)
1 parent 2daff8c commit f15680b

14 files changed

Lines changed: 2978 additions & 894 deletions

File tree

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 178 additions & 119 deletions
Large diffs are not rendered by default.

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 160 additions & 140 deletions
Large diffs are not rendered by default.

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 122 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { type LegendListRef } from "@legendapp/list/react-native";
44
import type { EnvironmentId, MessageId, ThreadId, TurnId } from "@t3tools/contracts";
55
import { classifyMarkdownImageSource } from "@t3tools/client-runtime/markdown-images";
66
import { CHAT_LIST_ANCHOR_OFFSET, resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
7-
import { formatElapsed } from "@t3tools/shared/orchestrationTiming";
87
import { SymbolView } from "../../components/AppSymbol";
98
import { HeaderHeightContext } from "@react-navigation/elements";
109
import { useNavigation } from "@react-navigation/native";
@@ -45,7 +44,13 @@ import {
4544
import { TouchableOpacity } from "react-native-gesture-handler";
4645
import ImageViewing from "react-native-image-viewing";
4746
import { useSafeAreaInsets } from "react-native-safe-area-context";
48-
import Animated, { FadeIn, FadeInUp, type SharedValue } from "react-native-reanimated";
47+
import Animated, {
48+
FadeIn,
49+
FadeInUp,
50+
FadeOut,
51+
LinearTransition,
52+
type SharedValue,
53+
} from "react-native-reanimated";
4954
import { useUniwindTheme } from "../../lib/useUniwindTheme";
5055
import { IOS_NAV_BAR_HEIGHT } from "../../lib/layoutMetrics";
5156
import { useFontFamily } from "../../lib/useFontFamily";
@@ -84,9 +89,7 @@ import {
8489
import {
8590
resolveMarkdownFontSizes,
8691
resolveNativeMarkdownTypography,
87-
scaledTypographyLineHeight,
8892
} from "../../lib/appearancePreferences";
89-
import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
9093
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
9194
import { useAppearanceCodeSurface } from "../settings/appearance/useAppearanceCodeSurface";
9295
import { markdownFileIconSource } from "@t3tools/mobile-markdown-text/file-icons";
@@ -105,6 +108,7 @@ import {
105108
collapsedWorkLogHeight,
106109
ThreadWorkGroupToggle,
107110
ThreadWorkLog,
111+
THREAD_DISCLOSURE_TRANSITION_MS,
108112
WORK_GROUP_TOGGLE_HEIGHT,
109113
} from "./thread-work-log";
110114
import { useMarkdownCodeHighlight } from "./markdownCodeHighlightState";
@@ -134,9 +138,10 @@ function formatMessageTime(input: string): string {
134138
// so its height is a constant; a drifted value costs one correction on
135139
// measure, not a persistent offset.
136140
const TURN_FOLD_HEIGHT = 56; // min-h-11 (44) + mb-3 (12)
137-
// The working row has no min-height clamp — its height follows the scaled
138-
// text-xs line height (see workingRowHeight in ThreadFeed).
139-
const WORKING_ROW_VERTICAL_EXTRAS = 24; // py-1 (8) + mb-4 (16)
141+
const THREAD_FEED_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
142+
const THREAD_FEED_DISCLOSURE_ENTER_TRANSITION = FadeIn.duration(140);
143+
const THREAD_FEED_DISCLOSURE_EXIT_TRANSITION = FadeOut.duration(120);
144+
const EMPTY_DISCLOSURE_ENTRY_IDS: ReadonlySet<string> = new Set();
140145

141146
// Entering animations must only play for rows born just now — LegendList
142147
// remounts rows when they scroll back into view, and replaying an entrance for
@@ -985,10 +990,6 @@ function renderFeedEntry(
985990
const entry = info.item;
986991
const { markdownStyles, iconSubtleColor, userBubbleColor } = props;
987992

988-
if (entry.type === "working") {
989-
return <WorkingTimelineRow startedAt={entry.createdAt} />;
990-
}
991-
992993
if (entry.type === "turn-fold") {
993994
return (
994995
<Pressable
@@ -1017,7 +1018,10 @@ function renderFeedEntry(
10171018
expanded={entry.expanded}
10181019
hiddenCount={entry.hiddenCount}
10191020
iconSubtleColor={iconSubtleColor}
1020-
onlyToolActivities={entry.onlyToolActivities}
1021+
summary={entry.summary}
1022+
summaryKind={entry.summaryKind}
1023+
hasFailure={entry.hasFailure}
1024+
shimmer={entry.shimmer}
10211025
onToggle={() => props.onToggleWorkGroup(entry.groupId)}
10221026
/>
10231027
);
@@ -1180,32 +1184,6 @@ function renderFeedEntry(
11801184
);
11811185
}
11821186

1183-
const WorkingTimelineRow = memo(function WorkingTimelineRow(props: { readonly startedAt: string }) {
1184-
const [nowMs, setNowMs] = useState(() => Date.now());
1185-
1186-
useEffect(() => {
1187-
const intervalId = setInterval(() => {
1188-
setNowMs(Date.now());
1189-
}, 1_000);
1190-
return () => clearInterval(intervalId);
1191-
}, [props.startedAt]);
1192-
1193-
const durationLabel = formatElapsed(props.startedAt, new Date(nowMs).toISOString()) ?? "0s";
1194-
1195-
return (
1196-
<View className="mb-4 flex-row items-center gap-2 px-1.5 py-1">
1197-
<View className="flex-row items-center gap-1">
1198-
<View className="h-1 w-1 rounded-full bg-adaptive-neutral-400-500" />
1199-
<View className="h-1 w-1 rounded-full bg-adaptive-neutral-400-a80-500-a80" />
1200-
<View className="h-1 w-1 rounded-full bg-adaptive-neutral-400-a60-500-a60" />
1201-
</View>
1202-
<Text className="font-t3-medium text-xs tabular-nums text-adaptive-neutral-600-400">
1203-
Working for {durationLabel}
1204-
</Text>
1205-
</View>
1206-
);
1207-
});
1208-
12091187
function UserMessageContent(props: {
12101188
readonly text: string;
12111189
readonly markdownStyles: MarkdownStyleSet;
@@ -1479,14 +1457,14 @@ function ThreadFeedPlaceholder(props: {
14791457
export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
14801458
const navigation = useNavigation();
14811459
const copyFeedbackTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
1482-
const foldSettleFrameRef = useRef<number | null>(null);
1483-
const foldSettleSecondFrameRef = useRef<number | null>(null);
1460+
const disclosureSettleFrameRef = useRef<number | null>(null);
1461+
const disclosureSettleSecondFrameRef = useRef<number | null>(null);
14841462
const disclosureAnchorKeyRef = useRef<string | null>(null);
1463+
const previousPresentedFeedRef = useRef<ReadonlyArray<ThreadFeedEntry> | null>(null);
14851464
const headerMaterialVisibleRef = useRef(false);
14861465
const previousLatestTurnRef = useRef(props.latestTurn);
14871466
const userScrollSettleTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
14881467
const { width: windowWidth } = useWindowDimensions();
1489-
const { appearance } = useAppearancePreferences();
14901468
const [viewportWidth, setViewportWidth] = useState(() =>
14911469
props.layoutVariant === "split" ? 0 : windowWidth,
14921470
);
@@ -1791,14 +1769,37 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
17911769
props.latestTurn,
17921770
],
17931771
);
1772+
const disclosureEnteringEntryIds = useMemo(() => {
1773+
const anchorKey = disclosureAnchorKeyRef.current;
1774+
const previousPresentedFeed = previousPresentedFeedRef.current;
1775+
if (!disclosureToggleSettling || anchorKey === null || previousPresentedFeed === null) {
1776+
return EMPTY_DISCLOSURE_ENTRY_IDS;
1777+
}
1778+
1779+
const previousIds = new Set(previousPresentedFeed.map((entry) => entry.id));
1780+
const anchorIndex = presentedFeed.findIndex((entry) => entry.id === anchorKey);
1781+
const enteringIds = new Set<string>();
1782+
if (anchorIndex < 0) {
1783+
return enteringIds;
1784+
}
1785+
for (let index = anchorIndex + 1; index < presentedFeed.length; index += 1) {
1786+
const entryId = presentedFeed[index]!.id;
1787+
if (previousIds.has(entryId)) {
1788+
break;
1789+
}
1790+
enteringIds.add(entryId);
1791+
}
1792+
return enteringIds;
1793+
}, [disclosureToggleSettling, presentedFeed]);
1794+
1795+
useLayoutEffect(() => {
1796+
previousPresentedFeedRef.current = presentedFeed;
1797+
}, [presentedFeed]);
17941798

1795-
// The empty↔filled key below remounts the list, which resets its imperative
1796-
// content-inset override — and useKeyboardChatComposerInset (mounted above
1797-
// the remount boundary) deduplicates by height, so it never re-reports the
1798-
// composer inset to the fresh instance. Re-report the measured overlay height
1799-
// (composer plus any pending approval / user-input card) so the remounted
1800-
// list's scroll math gets the true value; on Android the declarative
1801-
// contentInset floor below covers the window before this effect lands.
1799+
// The empty↔filled key below remounts the list and resets its imperative
1800+
// content-inset override. Seed the fresh instance synchronously with the
1801+
// current overlay height before the scroll integration's next reaction;
1802+
// on Android the declarative contentInset floor covers this same window.
18021803
const listMountKey = `${feedThreadKey}:${props.feed.length === 0 ? "empty" : "filled"}`;
18031804
useLayoutEffect(() => {
18041805
const bottom = props.contentInsetEndAdjustment.value;
@@ -1863,34 +1864,52 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18631864
if (copyFeedbackTimeoutRef.current) {
18641865
clearTimeout(copyFeedbackTimeoutRef.current);
18651866
}
1866-
if (foldSettleFrameRef.current !== null) {
1867-
cancelAnimationFrame(foldSettleFrameRef.current);
1867+
if (disclosureSettleFrameRef.current !== null) {
1868+
cancelAnimationFrame(disclosureSettleFrameRef.current);
18681869
}
1869-
if (foldSettleSecondFrameRef.current !== null) {
1870-
cancelAnimationFrame(foldSettleSecondFrameRef.current);
1870+
if (disclosureSettleSecondFrameRef.current !== null) {
1871+
cancelAnimationFrame(disclosureSettleSecondFrameRef.current);
18711872
}
18721873
};
18731874
}, []);
18741875

1875-
const suspendEndScrollMaintenanceForDisclosure = useCallback((anchorKey: string | null) => {
1876-
disclosureAnchorKeyRef.current = anchorKey;
1877-
setDisclosureToggleSettling(true);
1878-
if (foldSettleFrameRef.current !== null) {
1879-
cancelAnimationFrame(foldSettleFrameRef.current);
1876+
const settleDisclosureAfterLayout = useCallback(() => {
1877+
if (disclosureSettleFrameRef.current !== null) {
1878+
cancelAnimationFrame(disclosureSettleFrameRef.current);
18801879
}
1881-
if (foldSettleSecondFrameRef.current !== null) {
1882-
cancelAnimationFrame(foldSettleSecondFrameRef.current);
1880+
if (disclosureSettleSecondFrameRef.current !== null) {
1881+
cancelAnimationFrame(disclosureSettleSecondFrameRef.current);
18831882
}
1884-
foldSettleFrameRef.current = requestAnimationFrame(() => {
1885-
foldSettleSecondFrameRef.current = requestAnimationFrame(() => {
1883+
disclosureSettleFrameRef.current = requestAnimationFrame(() => {
1884+
disclosureSettleSecondFrameRef.current = requestAnimationFrame(() => {
18861885
disclosureAnchorKeyRef.current = null;
18871886
setDisclosureToggleSettling(false);
1888-
foldSettleFrameRef.current = null;
1889-
foldSettleSecondFrameRef.current = null;
1887+
disclosureSettleFrameRef.current = null;
1888+
disclosureSettleSecondFrameRef.current = null;
18901889
});
18911890
});
18921891
}, []);
18931892

1893+
const suspendEndScrollMaintenanceForDisclosure = useCallback((anchorKey: string | null) => {
1894+
disclosureAnchorKeyRef.current = anchorKey;
1895+
setDisclosureToggleSettling(true);
1896+
}, []);
1897+
1898+
// Start the quiet-frame countdown after React has committed the disclosure.
1899+
// Every measured item-size change restarts it, so end maintenance cannot
1900+
// wake between the data mutation and LegendList's final layout correction.
1901+
useLayoutEffect(() => {
1902+
if (disclosureAnchorKeyRef.current !== null) {
1903+
settleDisclosureAfterLayout();
1904+
}
1905+
}, [expandedTurnIds, expandedWorkGroups, expandedWorkRows, settleDisclosureAfterLayout]);
1906+
1907+
const handleItemSizeChanged = useCallback(() => {
1908+
if (disclosureAnchorKeyRef.current !== null) {
1909+
settleDisclosureAfterLayout();
1910+
}
1911+
}, [settleDisclosureAfterLayout]);
1912+
18941913
const shouldRestoreVisibleContentPosition = useCallback((entry: ThreadFeedEntry) => {
18951914
const disclosureAnchorKey = disclosureAnchorKeyRef.current;
18961915
return disclosureAnchorKey === null || entry.id === disclosureAnchorKey;
@@ -1975,58 +1994,64 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
19751994
// scrolling up through unmeasured content corrects each row's height as it
19761995
// mounts — the feed visibly jumps. Fixed sizes make the small chrome rows
19771996
// exact; message rows stay undefined and use LegendList's per-type running
1978-
// average once one of their type has been measured. Text-driven heights
1979-
// follow the configurable base font size via scaledTypographyLineHeight.
1980-
const workingRowHeight =
1981-
WORKING_ROW_VERTICAL_EXTRAS +
1982-
scaledTypographyLineHeight(MOBILE_TYPOGRAPHY.label, appearance.baseFontSize);
1997+
// average once one of their type has been measured.
19831998
const getFixedItemSize = useCallback(
19841999
(entry: ThreadFeedEntry) => {
19852000
switch (entry.type) {
19862001
case "turn-fold":
19872002
return TURN_FOLD_HEIGHT;
19882003
case "work-toggle":
19892004
return WORK_GROUP_TOGGLE_HEIGHT;
1990-
case "working":
1991-
return workingRowHeight;
19922005
case "activity-group":
19932006
// Expanded rows append a variable detail block — fall back to
19942007
// measurement for those groups.
19952008
return entry.activities.some((activity) => expandedWorkRows[activity.id])
19962009
? undefined
1997-
: collapsedWorkLogHeight(entry.activities, appearance.baseFontSize);
2010+
: collapsedWorkLogHeight(entry.activities);
19982011
default:
19992012
return undefined;
20002013
}
20012014
},
2002-
[expandedWorkRows, workingRowHeight, appearance.baseFontSize],
2015+
[expandedWorkRows],
20032016
);
20042017

20052018
const renderItem = useCallback(
2006-
(info: { item: ThreadFeedEntry; index: number }) =>
2007-
renderFeedEntry(info, {
2008-
environmentId: props.environmentId,
2009-
copiedRowId,
2010-
expandedWorkRows,
2011-
terminalAssistantMessageIds,
2012-
unsettledTurnId,
2013-
onCopyWorkRow,
2014-
onToggleWorkGroup,
2015-
onToggleWorkRow,
2016-
onToggleTurnFold,
2017-
onPressImage,
2018-
onMarkdownLinkPress,
2019-
renderMarkdownImage,
2020-
iconSubtleColor,
2021-
userBubbleColor,
2022-
markdownStyles,
2023-
reviewCommentColors,
2024-
reviewCommentBubbleWidth,
2025-
userBubbleMaxWidth,
2026-
skills: props.skills,
2027-
}),
2019+
(info: { item: ThreadFeedEntry; index: number }) => (
2020+
<Animated.View
2021+
key={info.item.id}
2022+
entering={
2023+
disclosureEnteringEntryIds.has(info.item.id)
2024+
? THREAD_FEED_DISCLOSURE_ENTER_TRANSITION
2025+
: undefined
2026+
}
2027+
exiting={THREAD_FEED_DISCLOSURE_EXIT_TRANSITION}
2028+
>
2029+
{renderFeedEntry(info, {
2030+
environmentId: props.environmentId,
2031+
copiedRowId,
2032+
expandedWorkRows,
2033+
terminalAssistantMessageIds,
2034+
unsettledTurnId,
2035+
onCopyWorkRow,
2036+
onToggleWorkGroup,
2037+
onToggleWorkRow,
2038+
onToggleTurnFold,
2039+
onPressImage,
2040+
onMarkdownLinkPress,
2041+
renderMarkdownImage,
2042+
iconSubtleColor,
2043+
userBubbleColor,
2044+
markdownStyles,
2045+
reviewCommentColors,
2046+
reviewCommentBubbleWidth,
2047+
userBubbleMaxWidth,
2048+
skills: props.skills,
2049+
})}
2050+
</Animated.View>
2051+
),
20282052
[
20292053
copiedRowId,
2054+
disclosureEnteringEntryIds,
20302055
expandedWorkRows,
20312056
terminalAssistantMessageIds,
20322057
unsettledTurnId,
@@ -2093,7 +2118,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
20932118
}
20942119
: { scrollIndicatorInsets: { top: topContentInset, bottom: 0 } })}
20952120
{...(anchoredEndSpace ? { anchoredEndSpace } : {})}
2096-
// Patched LegendList prop (patches/@legendapp__list@3.2.0.patch):
2121+
// Patched LegendList prop (patches/@legendapp__list@3.3.5.patch):
20972122
// lets its scroll math clamp programmatic scrolls to -headerInset
20982123
// instead of 0, so initialScrollAtEnd/maintainScrollAtEnd on short
20992124
// content rest below the transparent header rather than at frame top.
@@ -2148,6 +2173,8 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
21482173
entry.type === "message" ? `message:${entry.message.role}` : entry.type
21492174
}
21502175
getFixedItemSize={getFixedItemSize}
2176+
itemLayoutAnimation={THREAD_FEED_LAYOUT_TRANSITION}
2177+
onItemSizeChanged={handleItemSizeChanged}
21512178
// Measure rows well before they scroll into view so estimate→actual
21522179
// corrections land offscreen instead of under the user's finger.
21532180
drawDistance={500}

0 commit comments

Comments
 (0)