feat(json): add interactive JSON tree viewer with collapse/expand and rainbow colors (#786)
- Add JsonTreeViewer component with collapse/expand for nested objects and arrays - Add rainbow colors by depth level using CSS color-mix() with syntax theme tokens - Add virtualization support (@tanstack/react-virtual) for large JSON files (>200 nodes) - Add JsonTreeView wrapper with Expand All / Collapse All toolbar - Integrate into FilesView: tree/text toggle button, JSON file detection - Integrate into ToolPart: auto-detect JSON tool outputs, render as tree - Integrate into ToolOutputDialog: JSON tree view in expanded dialog - Add jsonTreeUtils.ts: parse, flatten, path utilities No new dependencies - uses existing @tanstack/react-virtual. Colors derived from existing syntax.* theme tokens - works across all themes. Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
d9fdd39f99
commit
6180f388e8
@@ -28,6 +28,36 @@ const formatInputForDisplay = (input: Record<string, unknown>, toolName?: string
|
||||
return formatToolInput(input, toolName || '');
|
||||
};
|
||||
|
||||
export const tryParseJsonOutput = (output: string): { data: unknown; isJson: boolean } => {
|
||||
if (!output || typeof output !== 'string') {
|
||||
return { data: null, isJson: false };
|
||||
}
|
||||
|
||||
const trimmed = output.trim();
|
||||
|
||||
if (!trimmed.startsWith('{') && !trimmed.startsWith('[')) {
|
||||
return { data: null, isJson: false };
|
||||
}
|
||||
|
||||
if (!trimmed.endsWith('}') && !trimmed.endsWith(']')) {
|
||||
return { data: null, isJson: false };
|
||||
}
|
||||
|
||||
if (trimmed.length < 2) {
|
||||
return { data: null, isJson: false };
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed);
|
||||
if (parsed !== null && typeof parsed === 'object') {
|
||||
return { data: parsed, isJson: true };
|
||||
}
|
||||
return { data: null, isJson: false };
|
||||
} catch {
|
||||
return { data: null, isJson: false };
|
||||
}
|
||||
};
|
||||
|
||||
export const formatEditOutput = (output: string, toolName: string, metadata?: Record<string, unknown>): string => {
|
||||
let cleaned = cleanOutput(output);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user