From f2fb8ff92fbc862da40ff832ac9a8be3abd4c539 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 16 Oct 2026 12:31:30 -0700 Subject: [PATCH] refactor(native-chat): move transcript row context into its own hook (#29809) --- .../native-chat/NativeChatMessageList.tsx | 53 +++++---------- .../use-native-chat-transcript-row-context.ts | 66 +++++++++++++++++++ 2 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 src/renderer/src/components/native-chat/use-native-chat-transcript-row-context.ts diff --git a/src/renderer/src/components/native-chat/NativeChatMessageList.tsx b/src/renderer/src/components/native-chat/NativeChatMessageList.tsx index 56143c2c374..f325f3694d8 100644 --- a/src/renderer/src/components/native-chat/NativeChatMessageList.tsx +++ b/src/renderer/src/components/native-chat/NativeChatMessageList.tsx @@ -26,7 +26,7 @@ import { NativeChatTranscriptItems, NativeChatWaitingTranscriptItems } from './NativeChatTranscriptItems' -import type { NativeChatTranscriptRowContext } from './NativeChatTranscriptRow' +import { useNativeChatTranscriptRowContext } from './use-native-chat-transcript-row-context' import type { StructuredAgentSessionHostWork } from './use-structured-agent-session-transport-state' import type { NativeChatDeliveryNotice } from './NativeChatMessageRow' import { @@ -63,7 +63,6 @@ import type { NativeChatSettledTurns } from '../../../../shared/native-chat-turn import type { NativeChatDiffReveal, NativeChatDiffTarget } from './native-chat-turn-diffs' import { useNativeChatTurnDiffs } from './use-native-chat-turn-diffs' import { transcriptTailRow } from './native-chat-transcript-tail-row' -import { structuredAgentLabel } from '@/lib/structured-agent-session-launch-label' /** The turn is blocked on the reader. `shown`: the pane draws the prompt itself, as a card; * `unshown`: it cannot (the prompt is only in the agent's terminal). */ @@ -337,40 +336,22 @@ export function NativeChatMessageList({ release: setNavigationRequest }) - const rowContext = useMemo( - () => ({ - agentName: structuredAgentLabel(session.agent), - actionablePromptIds: hostWork?.actionablePromptIds, - expandSignal, - revealedDiff, - taskListPredecessors, - expandedTurnIds, - deliveryNotices, - allowFileUriLinks, - runtimeContext, - onLinkClick, - onToggleExpandedTurn: toggleExpandedTurn, - subagentDisclosure, - onScrollMessageToTop: scrollMessageToTop, - onRevealDiff: revealDiff - }), - [ - session.agent, - hostWork, - allowFileUriLinks, - expandSignal, - expandedTurnIds, - deliveryNotices, - onLinkClick, - revealDiff, - revealedDiff, - runtimeContext, - scrollMessageToTop, - taskListPredecessors, - subagentDisclosure, - toggleExpandedTurn - ] - ) + const rowContext = useNativeChatTranscriptRowContext({ + agent: session.agent, + hostWork, + expandSignal, + revealedDiff, + taskListPredecessors, + expandedTurnIds, + deliveryNotices, + allowFileUriLinks, + runtimeContext, + onLinkClick, + onToggleExpandedTurn: toggleExpandedTurn, + subagentDisclosure, + onScrollMessageToTop: scrollMessageToTop, + onRevealDiff: revealDiff + }) return ( diff --git a/src/renderer/src/components/native-chat/use-native-chat-transcript-row-context.ts b/src/renderer/src/components/native-chat/use-native-chat-transcript-row-context.ts new file mode 100644 index 00000000000..63583fb1fd2 --- /dev/null +++ b/src/renderer/src/components/native-chat/use-native-chat-transcript-row-context.ts @@ -0,0 +1,66 @@ +import { useMemo } from 'react' +import { structuredAgentLabel } from '@/lib/structured-agent-session-launch-label' +import type { NativeChatLiveSession } from './use-native-chat-live-session' +import type { NativeChatTranscriptRowContext } from './NativeChatTranscriptRow' +import type { StructuredAgentSessionHostWork } from './use-structured-agent-session-transport-state' + +type NativeChatTranscriptRowContextInput = Omit< + NativeChatTranscriptRowContext, + 'agentName' | 'actionablePromptIds' +> & { + agent: NativeChatLiveSession['agent'] + hostWork: StructuredAgentSessionHostWork | undefined +} + +/** The context every transcript row reads, stable until one of its inputs changes. */ +export function useNativeChatTranscriptRowContext({ + agent, + hostWork, + expandSignal, + revealedDiff, + taskListPredecessors, + expandedTurnIds, + deliveryNotices, + allowFileUriLinks, + runtimeContext, + onLinkClick, + onToggleExpandedTurn, + subagentDisclosure, + onScrollMessageToTop, + onRevealDiff +}: NativeChatTranscriptRowContextInput): NativeChatTranscriptRowContext { + return useMemo( + () => ({ + agentName: structuredAgentLabel(agent), + actionablePromptIds: hostWork?.actionablePromptIds, + expandSignal, + revealedDiff, + taskListPredecessors, + expandedTurnIds, + deliveryNotices, + allowFileUriLinks, + runtimeContext, + onLinkClick, + onToggleExpandedTurn, + subagentDisclosure, + onScrollMessageToTop, + onRevealDiff + }), + [ + agent, + hostWork, + allowFileUriLinks, + expandSignal, + expandedTurnIds, + deliveryNotices, + onLinkClick, + onRevealDiff, + revealedDiff, + runtimeContext, + onScrollMessageToTop, + taskListPredecessors, + subagentDisclosure, + onToggleExpandedTurn + ] + ) +}