11import Tree from "antd/es/tree" ;
2+ import { Collapse , Space } from "antd" ;
23import type { TreeDataNode } from "antd" ;
34import ReactMarkdown from "react-markdown" ;
45import type { ColorMode } from "@xyflow/react" ;
@@ -25,6 +26,11 @@ export function InspectPanel({colorMode, nodeEntries}: { colorMode: ColorMode, n
2526 }
2627 } , [ ] )
2728
29+ const state = useMemo ( ( ) => {
30+ if ( ! selectedEntry ?. state ) return null ;
31+ return safeParseJSON ( selectedEntry ?. state ) ;
32+ } , [ selectedEntry , safeParseJSON ] )
33+
2834 const system = useMemo ( ( ) => {
2935 const inputs = safeParseJSON ( selectedEntry ?. input ) ;
3036 const system = inputs [ 0 ] || { } ;
@@ -41,6 +47,12 @@ export function InspectPanel({colorMode, nodeEntries}: { colorMode: ColorMode, n
4147 return output [ output . length - 1 ] || null ;
4248 } , [ selectedEntry , safeParseJSON ] )
4349
50+ const sectionMaxHeight = useMemo ( ( ) => {
51+ const reducer : any = ( acc : number , curr : boolean ) => acc + Number ( curr ) ;
52+ const count = [ state , system , input , output ] . map ( Boolean ) . reduce ( reducer , 0 ) ;
53+ return `calc((100vh - 240px) / ${ count } )` ;
54+ } , [ state , system , input , output ] )
55+
4456 const getChildren = useCallback ( ( parent : NodeEntry ) => {
4557 return nodeEntries . filter ( ( { parent_run_id} ) => parent_run_id === parent . run_id ) . map ( child => {
4658 const children : TreeDataNode [ ] = getChildren ( child ) ;
@@ -108,45 +120,95 @@ export function InspectPanel({colorMode, nodeEntries}: { colorMode: ColorMode, n
108120 metrics = { selectedEntry . metrics }
109121 />
110122 ) }
111- { system && (
112- < div className = "inspect-detail-section" >
113- < span className = { `inspect-section-label ${ system . role ?? "" } ` } >
114- < span > System</ span >
115- < span className = "tag" > { system . role ?? "unknown" } </ span >
116- </ span >
117- < div className = "inspect-detail-text" >
118- { system . role
119- ? < ReactMarkdown children = { system . content . trim ( ) } />
120- : < pre > { JSON . stringify ( system , null , 4 ) } </ pre > }
121- </ div >
122- </ div >
123- ) }
124- { input && (
125- < div className = "inspect-detail-section" >
126- < span className = { `inspect-section-label ${ input . role ?? "" } ` } >
127- < span > Input</ span >
128- < span className = "tag" > { input . role ?? "unknown" } </ span >
129- </ span >
130- < div className = "inspect-detail-text" >
131- { input . role
132- ? < ReactMarkdown children = { input . content . trim ( ) } />
133- : < pre > { JSON . stringify ( input , null , 4 ) } </ pre > }
134- </ div >
135- </ div >
136- ) }
137- { output && (
138- < div className = { `inspect-detail-section ${ selectedEntry . node_kind ?? "" } ` } >
139- < span className = { `inspect-section-label ${ output . role ?? "" } ` } >
140- < span > Output</ span >
141- < span className = "tag" > { output . role ?? "unknown" } </ span >
142- </ span >
143- < div className = { `inspect-detail-text ${ selectedEntry . status ?? "" } ` } >
144- { output . role
145- ? < ReactMarkdown children = { output . content . trim ( ) } />
146- : < pre > { JSON . stringify ( output , null , 4 ) } </ pre > }
147- </ div >
148- </ div >
149- ) }
123+ < Space vertical size = { 10 } >
124+ { state && (
125+ < Collapse
126+ defaultActiveKey = "state"
127+ styles = { { body : { maxHeight : sectionMaxHeight } } }
128+ items = { [
129+ {
130+ key : "state" ,
131+ label : "State" ,
132+ showArrow : false ,
133+ children : < pre > { JSON . stringify ( state , null , 2 ) } </ pre > ,
134+ } ,
135+ ] }
136+ />
137+ ) }
138+ { system && (
139+ < Collapse
140+ defaultActiveKey = "system"
141+ styles = { { body : { maxHeight : sectionMaxHeight } } }
142+ items = { [
143+ {
144+ key : "system" ,
145+ showArrow : false ,
146+ label : (
147+ < >
148+ < span > System</ span >
149+ < span className = "tag" > { system . role ?? "unknown" } </ span >
150+ </ >
151+ ) ,
152+ children : (
153+ system . role
154+ ? < ReactMarkdown children = { system . content . trim ( ) } />
155+ : < pre > { JSON . stringify ( system , null , 4 ) } </ pre >
156+ ) ,
157+ } ,
158+ ] }
159+ />
160+ ) }
161+ { input && (
162+ < Collapse
163+ defaultActiveKey = "input"
164+ styles = { { body : { maxHeight : sectionMaxHeight } } }
165+ items = { [
166+ {
167+ key : "input" ,
168+ showArrow : false ,
169+ label : (
170+ < >
171+ < span > Input</ span >
172+ < span className = "tag" > { input . role ?? "unknown" } </ span >
173+ </ >
174+ ) ,
175+ children : (
176+ input . role
177+ ? < ReactMarkdown children = { input . content . trim ( ) } />
178+ : < pre > { JSON . stringify ( input , null , 4 ) } </ pre >
179+ ) ,
180+ } ,
181+ ] }
182+ />
183+ ) }
184+ { output && (
185+ < Collapse
186+ defaultActiveKey = "output"
187+ styles = { { body : { maxHeight : sectionMaxHeight } } }
188+ classNames = { { body : `${ selectedEntry . node_kind ?? "" } ${ selectedEntry . status ?? "" } ` } }
189+ items = { [
190+ {
191+ key : "output" ,
192+ showArrow : false ,
193+ label : (
194+ < >
195+ < span > Output</ span >
196+ < span className = "tag" > { output . role ?? "unknown" } </ span >
197+ </ >
198+ ) ,
199+ children : (
200+ output . role
201+ ? ( output . role === "error" ) ? (
202+ < pre > { output . content . trim ( ) . replace ( / ^ \n + / mg, "\n" ) } </ pre >
203+ )
204+ : < ReactMarkdown children = { output . content . trim ( ) } />
205+ : < pre > { JSON . stringify ( output , null , 4 ) } </ pre >
206+ ) ,
207+ } ,
208+ ] }
209+ />
210+ ) }
211+ </ Space >
150212 </ >
151213 ) }
152214 </ div >
0 commit comments