Skip to content

Commit 48d5232

Browse files
committed
Refactor MessageBlock to be composed of components, with memo() and useMemo()
1 parent 716440f commit 48d5232

File tree

3 files changed

+682
-346
lines changed

3 files changed

+682
-346
lines changed

cli/src/components/agent-branch-item.tsx

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { TextAttributes, type BorderCharacters } from '@opentui/core'
2-
import React, { type ReactNode } from 'react'
1+
import { TextAttributes } from '@opentui/core'
2+
import React, { memo, type ReactNode } from 'react'
33

44
import { useTheme } from '../hooks/use-theme'
55
import { BORDER_CHARS } from '../utils/ui-constants'
6+
import { useWhyDidYouUpdateById } from '../hooks/use-why-did-you-update'
67

78
interface AgentBranchItemProps {
89
name: string
9-
content: ReactNode
10+
children?: ReactNode
1011
prompt?: string
1112
agentId?: string
1213
isCollapsed: boolean
@@ -20,21 +21,26 @@ interface AgentBranchItemProps {
2021
titleSuffix?: string
2122
}
2223

23-
export const AgentBranchItem = ({
24-
name,
25-
content,
26-
prompt,
27-
agentId,
28-
isCollapsed,
29-
isStreaming,
30-
streamingPreview,
31-
finishedPreview,
32-
statusLabel,
33-
statusColor,
34-
statusIndicator = '●',
35-
onToggle,
36-
titleSuffix,
37-
}: AgentBranchItemProps) => {
24+
export const AgentBranchItem = memo((props: AgentBranchItemProps) => {
25+
const {
26+
name,
27+
children,
28+
prompt,
29+
agentId,
30+
isCollapsed,
31+
isStreaming,
32+
streamingPreview,
33+
finishedPreview,
34+
statusLabel,
35+
statusColor,
36+
statusIndicator = '●',
37+
onToggle,
38+
titleSuffix,
39+
} = props
40+
useWhyDidYouUpdateById('AgentBranchItem', agentId ?? '', props, {
41+
logLevel: 'debug',
42+
enabled: false,
43+
})
3844
const theme = useTheme()
3945

4046
const baseTextAttributes = theme.messageTextAttributes ?? 0
@@ -44,9 +50,7 @@ export const AgentBranchItem = ({
4450
}
4551

4652
const isExpanded = !isCollapsed
47-
const toggleFrameColor = isExpanded
48-
? theme.secondary
49-
: theme.muted
53+
const toggleFrameColor = isExpanded ? theme.secondary : theme.muted
5054
const toggleIconColor = isStreaming ? theme.primary : theme.foreground
5155
const bulletChar = '• '
5256
const toggleIndicator = onToggle ? (isCollapsed ? '▸ ' : '▾ ') : ''
@@ -247,7 +251,7 @@ export const AgentBranchItem = ({
247251
flexDirection: 'row',
248252
gap: 0,
249253
alignItems: 'stretch',
250-
marginBottom: content ? 1 : 0,
254+
marginBottom: children ? 1 : 0,
251255
}}
252256
>
253257
<box
@@ -274,7 +278,7 @@ export const AgentBranchItem = ({
274278
</box>
275279
</box>
276280
)}
277-
{renderExpandedContent(content)}
281+
{renderExpandedContent(children)}
278282
{onToggle && (
279283
<box
280284
style={{
@@ -283,10 +287,7 @@ export const AgentBranchItem = ({
283287
}}
284288
onMouseDown={onToggle}
285289
>
286-
<text
287-
fg={theme.secondary}
288-
style={{ wrapMode: 'none' }}
289-
>
290+
<text fg={theme.secondary} style={{ wrapMode: 'none' }}>
290291
▴ collapse
291292
</text>
292293
</box>
@@ -296,4 +297,4 @@ export const AgentBranchItem = ({
296297
</box>
297298
</box>
298299
)
299-
}
300+
})

0 commit comments

Comments
 (0)