@@ -20,7 +20,7 @@ import type { AcpMessage } from "@posthog/shared";
2020import { CHAT_CONTENT_MAX_WIDTH } from "@posthog/ui/features/sessions/constants" ;
2121import { openUrlInBrowser } from "@posthog/ui/utils/browser" ;
2222import { Badge , Box , Flex , Text } from "@radix-ui/themes" ;
23- import { type ComponentType , useMemo } from "react" ;
23+ import { type ComponentType , useMemo , useState } from "react" ;
2424import { accumulateSessionResources } from "./accumulateSessionResources" ;
2525
2626/**
@@ -70,6 +70,13 @@ interface SessionResourcesBarProps {
7070 events : AcpMessage [ ] ;
7171}
7272
73+ /**
74+ * How many chips to show before collapsing the rest behind a "+N" badge.
75+ * Keeps the bar to a single tidy row in the common case; the user can expand
76+ * to reveal everything when the agent has touched a lot of products.
77+ */
78+ const MAX_VISIBLE_CHIPS = 6 ;
79+
7380/**
7481 * Persistent bar above the composer listing the PostHog products the agent has
7582 * touched so far this session — via the MCP `exec` tool, or by reading a file
@@ -79,17 +86,28 @@ interface SessionResourcesBarProps {
7986 */
8087export function SessionResourcesBar ( { events } : SessionResourcesBarProps ) {
8188 const products = useMemo ( ( ) => accumulateSessionResources ( events ) , [ events ] ) ;
89+ const [ expanded , setExpanded ] = useState ( false ) ;
8290
8391 if ( products . length === 0 ) return null ;
8492
93+ const overflowCount = products . length - MAX_VISIBLE_CHIPS ;
94+ const hasOverflow = overflowCount > 0 ;
95+ const visibleProducts =
96+ hasOverflow && ! expanded ? products . slice ( 0 , MAX_VISIBLE_CHIPS ) : products ;
97+
8598 return (
8699 < Box className = "mb-3" >
87100 < Box className = "mx-auto" style = { { maxWidth : CHAT_CONTENT_MAX_WIDTH } } >
88- < Flex align = "center" gap = "2" wrap = "wrap" className = "px-3 pt-2" >
89- < Text color = "gray" className = "whitespace-nowrap text-[12px]" >
101+ < Flex
102+ align = "center"
103+ gap = "1"
104+ wrap = "wrap"
105+ className = "overflow-hidden px-3 pt-2"
106+ >
107+ < Text color = "gray" className = "whitespace-nowrap text-[11px]" >
90108 PostHog resources used
91109 </ Text >
92- { products . map ( ( product ) => {
110+ { visibleProducts . map ( ( product ) => {
93111 const Icon = PRODUCT_ICON [ product . id ] ?? SparkleIcon ;
94112 const docUrl = PRODUCT_DOC_URL [ product . id ] ;
95113 return (
@@ -99,18 +117,32 @@ export function SessionResourcesBar({ events }: SessionResourcesBarProps) {
99117 color = "gray"
100118 variant = "soft"
101119 className = {
102- docUrl ? "cursor-pointer hover:bg-gray-4" : undefined
120+ docUrl
121+ ? "max-w-full cursor-pointer text-[11px] hover:bg-gray-4"
122+ : "max-w-full text-[11px]"
103123 }
104124 onClick = {
105125 docUrl ? ( ) => void openUrlInBrowser ( docUrl ) : undefined
106126 }
107127 title = { docUrl ? `Open ${ product . label } docs` : undefined }
108128 >
109- < Icon size = { 12 } />
110- { product . label }
129+ < Icon size = { 11 } className = "shrink-0" />
130+ < span className = "truncate" > { product . label } </ span >
111131 </ Badge >
112132 ) ;
113133 } ) }
134+ { hasOverflow && (
135+ < Badge
136+ size = "1"
137+ color = "gray"
138+ variant = "soft"
139+ className = "cursor-pointer text-[11px] hover:bg-gray-4"
140+ onClick = { ( ) => setExpanded ( ( prev ) => ! prev ) }
141+ title = { expanded ? "Show fewer" : "Show all resources used" }
142+ >
143+ { expanded ? "Show less" : `+${ overflowCount } more` }
144+ </ Badge >
145+ ) }
114146 </ Flex >
115147 </ Box >
116148 </ Box >
0 commit comments