Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(IOPreview): add footer rendering for corrected output when corrections are enabled (#11543)

marliessophie6e6606f06e7c
diff --git a/web/src/components/trace2/components/IOPreview/IOPreviewJSON.tsx b/web/src/components/trace2/components/IOPreview/IOPreviewJSON.tsx
index 1b2015f494..3fe2034c78 100644
--- a/web/src/components/trace2/components/IOPreview/IOPreviewJSON.tsx
+++ b/web/src/components/trace2/components/IOPreview/IOPreviewJSON.tsx
@@ -243,6 +243,28 @@ function IOPreviewJSONInner({
minHeight: "200px",
});
}
+ if (showCorrections) {
+ result.push({
+ key: "corrections",
+ title: "Output correction",
+ data: null,
+ hideData: true, // Hide key/value display, only show header/footer
+ backgroundColor: outputBgColor,
+ minHeight: "4px",
+ // Add corrected output as footer when corrections are enabled
+ renderFooter: () => (
+ <CorrectedOutputField
+ actualOutput={parsedOutput}
+ existingCorrection={outputCorrection}
+ observationId={observationId}
+ projectId={projectId}
+ traceId={traceId}
+ environment={environment}
+ compact={true}
+ />
+ ),
+ });
+ }
if (showMetadata) {
result.push({
key: "metadata",
@@ -263,6 +285,12 @@ function IOPreviewJSONInner({
inputBgColor,
outputBgColor,
metadataBgColor,
+ showCorrections,
+ observationId,
+ outputCorrection,
+ projectId,
+ traceId,
+ environment,
]);
// Wait for parsing to complete before rendering to avoid flicker
@@ -438,16 +466,6 @@ function IOPreviewJSONInner({
) : (
viewerContent
)}
- {showCorrections && (
- <CorrectedOutputField
- actualOutput={parsedOutput}
- existingCorrection={outputCorrection}
- observationId={observationId}
- projectId={projectId}
- traceId={traceId}
- environment={environment}
- />
- )}
</div>
</div>
);
diff --git a/web/src/components/trace2/components/IOPreview/components/CorrectedOutputField.tsx b/web/src/components/trace2/components/IOPreview/components/CorrectedOutputField.tsx
index 8d74adcf3a..e9bb3f8c3f 100644
--- a/web/src/components/trace2/components/IOPreview/components/CorrectedOutputField.tsx
+++ b/web/src/components/trace2/components/IOPreview/components/CorrectedOutputField.tsx
@@ -25,6 +25,7 @@ interface CorrectedOutputFieldProps {
actualOutput?: unknown;
existingCorrection?: ScoreDomain | null;
observationId?: string;
+ compact?: boolean; // Use smaller font size for JSON Beta view
}
export function CorrectedOutputField({
@@ -34,6 +35,7 @@ export function CorrectedOutputField({
projectId,
traceId,
environment = "default",
+ compact = false,
}: CorrectedOutputFieldProps) {
const hasAccess = useHasProjectAccess({ projectId, scope: "scores:CUD" });
@@ -158,8 +160,13 @@ export function CorrectedOutputField({
<div className="group relative rounded-md">
<div className="flex items-center justify-between py-1.5">
<div className="flex items-center gap-1">
- <span className="text-sm font-medium">
- Corrected Output (Beta)
+ <span
+ className={cn(
+ "text-sm font-medium",
+ compact ? "text-xs" : "text-sm",
+ )}
+ >
+ {compact ? "" : "Corrected Output (Beta)"}
</span>
<HoverCard>
<HoverCardTrigger asChild>
diff --git a/web/src/components/ui/AdvancedJsonViewer/MultiSectionJsonViewer.tsx b/web/src/components/ui/AdvancedJsonViewer/MultiSectionJsonViewer.tsx
index effe660725..fb23297c36 100644
--- a/web/src/components/ui/AdvancedJsonViewer/MultiSectionJsonViewer.tsx
+++ b/web/src/components/ui/AdvancedJsonViewer/MultiSectionJsonViewer.tsx
@@ -132,6 +132,8 @@ export const MultiSectionJsonViewer = forwardRef<
data: s.data,
backgroundColor: s.backgroundColor,
minHeight: s.minHeight,
+ hasFooter: !!s.renderFooter,
+ hideData: s.hideData,
})),
[sections],
);
diff --git a/web/src/components/ui/AdvancedJsonViewer/SimpleMultiSectionViewer.tsx b/web/src/components/ui/AdvancedJsonViewer/SimpleMultiSectionViewer.tsx
index 23934b1e39..d97107ac46 100644
--- a/web/src/components/ui/AdvancedJsonViewer/SimpleMultiSectionViewer.tsx
+++ b/web/src/components/ui/AdvancedJsonViewer/SimpleMultiSectionViewer.tsx
@@ -425,8 +425,15 @@ export const SimpleMultiSectionViewer = memo(
)}
{/* Render section footer if exists */}
- {jsonSection?.renderFooter && (
- <div>{jsonSection.renderFooter(sectionContext)}</div>
+ {jsonSection?.renderFooter && sectionContext.isExpanded && (
+ <div
+ style={{
+ width: containerWidth ? `${containerWidth}px` : "100%",
+ paddingBottom: "0.5rem",
+ }}
+ >
+ {jsonSection.renderFooter(sectionContext)}
+ </div>
)}
</div>
);
diff --git a/web/src/components/ui/AdvancedJsonViewer/VirtualizedMultiSectionViewer.tsx b/web/src/components/ui/AdvancedJsonViewer/VirtualizedMultiSectionViewer.tsx
index b640745c11..c71585f31c 100644
--- a/web/src/components/ui/AdvancedJsonViewer/VirtualizedMultiSectionViewer.tsx
+++ b/web/src/components/ui/AdvancedJsonViewer/VirtualizedMultiSectionViewer.tsx
@@ -369,6 +369,9 @@ export const VirtualizedMultiSectionViewer = memo(
}
if (node.nodeType === "section-footer") {
+ // Skip footer if section is collapsed
+ if (!node.isExpanded) return null;
+
const jsonSection = node.sectionKey
? sectionsMap.get(node.sectionKey)
: null;
@@ -388,12 +391,10 @@ export const VirtualizedMultiSectionViewer = memo(
position: "absolute",
top: 0,
left: 0,
- minWidth: effectiveRowWidth
- ? `${effectiveRowWidth}px`
- : "100%",
- width: "max-content",
+ width: containerWidth ? `${containerWidth}px` : "100%",
transform: `translateY(${virtualRow.start}px)`,
backgroundColor: node.backgroundColor || theme.background,
+ paddingBottom: "0.5rem",
}}
>
{jsonSection?.renderFooter?.(sectionContext)}
diff --git a/web/src/components/ui/AdvancedJsonViewer/types.ts b/web/src/components/ui/AdvancedJsonViewer/types.ts
index 48090477bf..1f43802e22 100644
--- a/web/src/components/ui/AdvancedJsonViewer/types.ts
+++ b/web/src/components/ui/AdvancedJsonViewer/types.ts
@@ -452,6 +452,9 @@ export interface JsonSection {
/** Minimum height for section content (CSS value, e.g., "200px", "50vh") */
minHeight?: string;
+
+ /** Hide the data/key-value display, only show header/footer */
+ hideData?: boolean;
}
/**
diff --git a/web/src/components/ui/AdvancedJsonViewer/utils/multiSectionTree.ts b/web/src/components/ui/AdvancedJsonViewer/utils/multiSectionTree.ts
index 00094198c4..5d210d15ac 100644
--- a/web/src/components/ui/AdvancedJsonViewer/utils/multiSectionTree.ts
+++ b/web/src/components/ui/AdvancedJsonViewer/utils/multiSectionTree.ts
@@ -30,6 +30,10 @@ export interface SectionConfig {
backgroundColor?: string;
/** Minimum height for section content (CSS value) */
minHeight?: string;
+ /** Whether this section has a footer (triggers footer node creation) */
+ hasFooter?: boolean;
+ /** Hide the data/key-value display, only show header/footer */
+ hideData?: boolean;
}
/**
@@ -150,59 +154,64 @@ export function buildMultiSectionTree(
nodeMap.set(headerNode.id, headerNode);
metaRoot.children.push(headerNode);
- // 2b. Build JSON tree for this section
- const jsonTree = buildTreeFromJSON(section.data, {
- rootKey: section.key,
- initialExpansion: getStoredExpansion(section.key) ?? true,
- widthEstimator: config?.widthConfig,
- });
-
- // Track max content width from this section
- maxContentWidth = Math.max(maxContentWidth, jsonTree.maxContentWidth);
-
- // 2c. Re-parent JSON tree under header node and update properties
- let sectionLineNumber = 1;
- const stack: { node: TreeNode; newDepth: number }[] = [
- { node: jsonTree.rootNode, newDepth: 0 },
- ];
-
- while (stack.length > 0) {
- const { node, newDepth } = stack.pop()!;
-
- // Update node properties for multi-section
- node.depth = newDepth;
- node.sectionKey = section.key;
- node.backgroundColor = section.backgroundColor;
- node.minHeight = section.minHeight;
- node.nodeType = "json";
-
- // Set section line number (stable, assigned once during tree building)
- node.sectionLineNumber = sectionLineNumber++;
-
- // Update absolute line number
- node.absoluteLineNumber = absoluteLineNumber++;
-
- // Track max depth
- maxDepth = Math.max(maxDepth, node.depth);
-
- // Add to collections
- allNodes.push(node);
- nodeMap.set(node.id, node);
-
- // Process children in reverse order (for correct stack ordering)
- for (let i = node.children.length - 1; i >= 0; i--) {
- stack.push({ node: node.children[i]!, newDepth: newDepth + 1 });
+ // 2b. Build JSON tree for this section (skip if hideData is true)
+ if (!section.hideData) {
+ const jsonTree = buildTreeFromJSON(section.data, {
+ rootKey: section.key,
+ initialExpansion: getStoredExpansion(section.key) ?? true,
+ widthEstimator: config?.widthConfig,
+ });
+
+ // Track max content width from this section
+ maxContentWidth = Math.max(maxContentWidth, jsonTree.maxContentWidth);
+
+ // 2c. Re-parent JSON tree under header node and update properties
+ let sectionLineNumber = 1;
+ const stack: { node: TreeNode; newDepth: number }[] = [
+ { node: jsonTree.rootNode, newDepth: 0 },
+ ];
+
+ while (stack.length > 0) {
+ const { node, newDepth } = stack.pop()!;
+
+ // Update node properties for multi-section
+ node.depth = newDepth;
+ node.sectionKey = section.key;
+ node.backgroundColor = section.backgroundColor;
+ node.minHeight = section.minHeight;
+ node.nodeType = "json";
+
+ // Set section line number (stable, assigned once during tree building)
+ node.sectionLineNumber = sectionLineNumber++;
+
+ // Update absolute line number
+ node.absoluteLineNumber = absoluteLineNumber++;
+
+ // Track max depth
+ maxDepth = Math.max(maxDepth, node.depth);
+
+ // Add to collections
+ allNodes.push(node);
+ nodeMap.set(node.id, node);
+
+ // Process children in reverse order (for correct stack ordering)
+ for (let i = node.children.length - 1; i >= 0; i--) {
+ stack.push({ node: node.children[i]!, newDepth: newDepth + 1 });
+ }
}
- }
-
- // Link JSON root to header
- jsonTree.rootNode.parentNode = headerNode;
- jsonTree.rootNode.indexInParent = 0;
- headerNode.children.push(jsonTree.rootNode);
- headerNode.childCount = 1;
- // Set total descendant count (for row count display, independent of expansion)
- headerNode.totalDescendantCount = jsonTree.totalNodeCount;
+ // Link JSON root to header
+ jsonTree.rootNode.parentNode = headerNode;
+ jsonTree.rootNode.indexInParent = 0;
+ headerNode.children.push(jsonTree.rootNode);
+ headerNode.childCount = 1;
+
+ // Set total descendant count (for row count display, independent of expansion)
+ headerNode.totalDescendantCount = jsonTree.totalNodeCount;
+ } else {
+ // No data to show, set counts to 0
+ headerNode.totalDescendantCount = 0;
+ }
// 2c. Create spacer node if minHeight is set and content is shorter
if (section.minHeight) {
@@ -242,7 +251,39 @@ export function buildMultiSectionTree(
}
}
- // Recompute header offsets after adding JSON tree and spacer
+ // 2d. Create footer node if section has a footer
+ if (section.hasFooter) {
+ const footerNode: TreeNode = {
+ id: `${section.key}__footer`,
+ key: `${section.key}__footer`,
+ pathArray: ["__meta_root__", `${section.key}__footer`],
+ value: null,
+ type: "object",
+ depth: 0,
+ parentNode: headerNode,
+ children: [],
+ childCount: 0,
+ isExpandable: false,
+ isExpanded: true,
+ userExpand: undefined,
+ childOffsets: [],
+ visibleDescendantCount: 0,
+ absoluteLineNumber: absoluteLineNumber++,
+ indexInParent: headerNode.children.length,
+ isLastChild: false,
+ nodeType: "section-footer",
+ sectionKey: section.key,
+ backgroundColor: section.backgroundColor,
+ sectionLineNumber: undefined,
+ };
+
+ allNodes.push(footerNode);
+ nodeMap.set(footerNode.id, footerNode);
+ headerNode.children.push(footerNode);
+ headerNode.childCount += 1;
+ }
+
+ // Recompute header offsets after adding JSON tree, spacer, and footer
recomputeNodeOffsets(headerNode);
});