11'use client'
22
3- import { useMemo , useState } from 'react'
4- import {
5- ChevronDown ,
6- ChevronDownSquare ,
7- ChevronRight ,
8- ChevronUpSquare ,
9- Code ,
10- Cpu ,
11- ExternalLink ,
12- } from 'lucide-react'
3+ import { useState } from 'react'
4+ import { ChevronDown , ChevronRight , Code , Cpu , ExternalLink } from 'lucide-react'
135import {
146 AgentIcon ,
157 ApiIcon ,
@@ -203,40 +195,11 @@ export function TraceSpansDisplay({
203195 // Keep track of expanded spans
204196 const [ expandedSpans , setExpandedSpans ] = useState < Set < string > > ( new Set ( ) )
205197
206- // Function to collect all span IDs recursively (for expand all functionality)
207- const collectAllSpanIds = ( spans : TraceSpan [ ] ) : string [ ] => {
208- const ids : string [ ] = [ ]
209-
210- const collectIds = ( span : TraceSpan ) => {
211- const spanId = span . id || `span-${ span . name } -${ span . startTime } `
212- ids . push ( spanId )
213-
214- // Process children
215- if ( span . children && span . children . length > 0 ) {
216- span . children . forEach ( collectIds )
217- }
218- }
219-
220- spans . forEach ( collectIds )
221- return ids
222- }
223-
224- const allSpanIds = useMemo ( ( ) => {
225- if ( ! traceSpans || traceSpans . length === 0 ) return [ ]
226- return collectAllSpanIds ( traceSpans )
227- } , [ traceSpans ] )
228-
229198 // Early return after all hooks
230199 if ( ! traceSpans || traceSpans . length === 0 ) {
231200 return < div className = 'text-muted-foreground text-sm' > No trace data available</ div >
232201 }
233202
234- // Format total duration for better readability
235- const _formatTotalDuration = ( ms : number ) => {
236- if ( ms < 1000 ) return `${ ms } ms`
237- return `${ ( ms / 1000 ) . toFixed ( 2 ) } s (${ ms } ms)`
238- }
239-
240203 // Find the earliest start time among all spans to be the workflow start time
241204 const workflowStartTime = traceSpans . reduce ( ( earliest , span ) => {
242205 const startTime = new Date ( span . startTime ) . getTime ( )
@@ -269,48 +232,10 @@ export function TraceSpansDisplay({
269232 }
270233 }
271234
272- // Handle expand all / collapse all
273- const handleExpandAll = ( ) => {
274- const newExpandedSpans = new Set ( allSpanIds )
275- setExpandedSpans ( newExpandedSpans )
276-
277- if ( onExpansionChange ) {
278- onExpansionChange ( true )
279- }
280- }
281-
282- const handleCollapseAll = ( ) => {
283- setExpandedSpans ( new Set ( ) )
284-
285- if ( onExpansionChange ) {
286- onExpansionChange ( false )
287- }
288- }
289-
290- // Determine if all spans are currently expanded
291- const allExpanded = allSpanIds . length > 0 && allSpanIds . every ( ( id ) => expandedSpans . has ( id ) )
292-
293235 return (
294236 < div className = 'w-full' >
295237 < div className = 'mb-2 flex items-center justify-between' >
296- < div className = 'font-medium text-muted-foreground text-xs' > Trace Spans</ div >
297- < button
298- onClick = { allExpanded ? handleCollapseAll : handleExpandAll }
299- className = 'flex items-center gap-1 text-muted-foreground text-xs transition-colors hover:text-foreground'
300- title = { allExpanded ? 'Collapse all spans' : 'Expand all spans' }
301- >
302- { allExpanded ? (
303- < >
304- < ChevronUpSquare className = 'h-3.5 w-3.5' />
305- < span > Collapse</ span >
306- </ >
307- ) : (
308- < >
309- < ChevronDownSquare className = 'h-3.5 w-3.5' />
310- < span > Expand</ span >
311- </ >
312- ) }
313- </ button >
238+ < div className = 'font-medium text-muted-foreground text-xs' > Workflow Execution</ div >
314239 </ div >
315240 < div className = 'w-full overflow-hidden rounded-md border shadow-sm' >
316241 { traceSpans . map ( ( span , index ) => {
@@ -369,7 +294,8 @@ function TraceSpanItem({
369294 const expanded = expandedSpans . has ( spanId )
370295 const hasChildren = span . children && span . children . length > 0
371296 const hasToolCalls = span . toolCalls && span . toolCalls . length > 0
372- const hasNestedItems = hasChildren || hasToolCalls
297+ const hasInputOutput = Boolean ( span . input || span . output )
298+ const hasNestedItems = hasChildren || hasToolCalls || hasInputOutput
373299
374300 // Calculate timing information
375301 const spanStartTime = new Date ( span . startTime ) . getTime ( )
@@ -389,9 +315,6 @@ function TraceSpanItem({
389315 const safeStartPercent = Math . min ( 100 , Math . max ( 0 , relativeStartPercent ) )
390316 const safeWidthPercent = Math . max ( 2 , Math . min ( 100 - safeStartPercent , actualDurationPercent ) )
391317
392- // For parent-relative timing display
393- const _startOffsetPercentage = totalDuration > 0 ? ( startOffset / totalDuration ) * 100 : 0
394-
395318 // Handle click to expand/collapse this span
396319 const handleSpanClick = ( ) => {
397320 if ( hasNestedItems ) {
@@ -605,17 +528,17 @@ function TraceSpanItem({
605528 </ div >
606529 </ div >
607530
608- { /* Children and tool calls */ }
531+ { /* Expanded content */ }
609532 { expanded && (
610533 < div >
611534 { /* Block Input/Output Data */ }
612535 { ( span . input || span . output ) && (
613- < div className = 'mt-2 ml-8 space-y-3 overflow-hidden' >
536+ < div className = 'mt-2 mr-4 mb-4 ml-8 space-y-3 overflow-hidden' >
614537 { /* Input Data */ }
615538 { span . input && (
616539 < div >
617540 < h4 className = 'mb-2 font-medium text-muted-foreground text-xs' > Input</ h4 >
618- < div className = 'overflow-hidden rounded-md bg-secondary/30 p-3' >
541+ < div className = 'mb-2 overflow-hidden rounded-md bg-secondary/30 p-3' >
619542 < BlockDataDisplay data = { span . input } blockType = { span . type } isInput = { true } />
620543 </ div >
621544 </ div >
@@ -627,7 +550,7 @@ function TraceSpanItem({
627550 < h4 className = 'mb-2 font-medium text-muted-foreground text-xs' >
628551 { span . status === 'error' ? 'Error Details' : 'Output' }
629552 </ h4 >
630- < div className = 'overflow-hidden rounded-md bg-secondary/30 p-3' >
553+ < div className = 'mb-2 overflow-hidden rounded-md bg-secondary/30 p-3' >
631554 < BlockDataDisplay
632555 data = { span . output }
633556 blockType = { span . type }
@@ -639,12 +562,8 @@ function TraceSpanItem({
639562 ) }
640563 </ div >
641564 ) }
642- </ div >
643- ) }
644565
645- { /* Children and tool calls */ }
646- { expanded && (
647- < div >
566+ { /* Children and tool calls */ }
648567 { /* Render child spans */ }
649568 { hasChildren && (
650569 < div >
0 commit comments