2026-01-16 14:47:10 -05:00
|
|
|
/**
|
|
|
|
|
* Introspection Panel - Shows discovered expressions and extractors from NX model
|
|
|
|
|
*/
|
|
|
|
|
|
2026-01-20 14:26:20 -05:00
|
|
|
import { useState, useEffect, useCallback, useMemo } from 'react';
|
2026-01-16 14:47:10 -05:00
|
|
|
import {
|
|
|
|
|
X,
|
|
|
|
|
Search,
|
|
|
|
|
RefreshCw,
|
|
|
|
|
Plus,
|
|
|
|
|
ChevronDown,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
FileBox,
|
|
|
|
|
Cpu,
|
|
|
|
|
FlaskConical,
|
|
|
|
|
SlidersHorizontal,
|
|
|
|
|
AlertTriangle,
|
2026-01-20 14:47:09 -05:00
|
|
|
Scale,
|
|
|
|
|
Link,
|
|
|
|
|
Box,
|
|
|
|
|
Settings2,
|
2026-01-16 14:47:10 -05:00
|
|
|
} from 'lucide-react';
|
|
|
|
|
import { useCanvasStore } from '../../../hooks/useCanvasStore';
|
|
|
|
|
|
|
|
|
|
interface IntrospectionPanelProps {
|
|
|
|
|
filePath: string;
|
2026-01-20 14:14:14 -05:00
|
|
|
studyId?: string;
|
2026-01-16 14:47:10 -05:00
|
|
|
onClose: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Expression {
|
|
|
|
|
name: string;
|
|
|
|
|
value: number;
|
2026-01-20 14:26:20 -05:00
|
|
|
rhs?: string;
|
2026-01-16 14:47:10 -05:00
|
|
|
min?: number;
|
|
|
|
|
max?: number;
|
2026-01-20 14:26:20 -05:00
|
|
|
unit?: string;
|
|
|
|
|
units?: string; // API returns 'units' not 'unit'
|
2026-01-16 14:47:10 -05:00
|
|
|
type: string;
|
|
|
|
|
source?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Extractor {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
always?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DependentFile {
|
|
|
|
|
path: string;
|
|
|
|
|
type: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 14:26:20 -05:00
|
|
|
// The API returns expressions in a nested structure
|
|
|
|
|
interface ExpressionsResult {
|
|
|
|
|
user: Expression[];
|
|
|
|
|
internal: Expression[];
|
|
|
|
|
total_count: number;
|
|
|
|
|
user_count: number;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 14:47:10 -05:00
|
|
|
interface IntrospectionResult {
|
2026-01-20 14:26:20 -05:00
|
|
|
part_file?: string;
|
|
|
|
|
part_path?: string;
|
|
|
|
|
file_path?: string;
|
|
|
|
|
file_type?: string;
|
|
|
|
|
success?: boolean;
|
|
|
|
|
error?: string | null;
|
|
|
|
|
// Expressions can be either an array (old format) or object with user/internal (new format)
|
|
|
|
|
expressions: Expression[] | ExpressionsResult;
|
|
|
|
|
solver_type?: string | null;
|
|
|
|
|
dependent_files?: DependentFile[];
|
|
|
|
|
extractors_available?: Extractor[];
|
|
|
|
|
warnings?: string[];
|
|
|
|
|
// Additional fields from NX introspection
|
|
|
|
|
mass_properties?: Record<string, unknown>;
|
|
|
|
|
materials?: Record<string, unknown>;
|
|
|
|
|
bodies?: Record<string, unknown>;
|
|
|
|
|
attributes?: Array<{ title: string; value: string }>;
|
|
|
|
|
units?: Record<string, unknown>;
|
|
|
|
|
linked_parts?: Record<string, unknown>;
|
2026-01-16 14:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
2026-01-20 14:14:14 -05:00
|
|
|
export function IntrospectionPanel({ filePath, studyId, onClose }: IntrospectionPanelProps) {
|
2026-01-16 14:47:10 -05:00
|
|
|
const [result, setResult] = useState<IntrospectionResult | null>(null);
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
|
const [expandedSections, setExpandedSections] = useState<Set<string>>(
|
|
|
|
|
new Set(['expressions', 'extractors'])
|
|
|
|
|
);
|
|
|
|
|
const [searchTerm, setSearchTerm] = useState('');
|
|
|
|
|
|
|
|
|
|
const { addNode, nodes } = useCanvasStore();
|
|
|
|
|
|
|
|
|
|
const runIntrospection = useCallback(async () => {
|
|
|
|
|
if (!filePath) return;
|
|
|
|
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
setError(null);
|
|
|
|
|
try {
|
2026-01-20 14:14:14 -05:00
|
|
|
let res;
|
|
|
|
|
|
|
|
|
|
// If we have a studyId, use the study-aware introspection endpoint
|
|
|
|
|
if (studyId) {
|
|
|
|
|
// Don't encode studyId - it may contain slashes for nested paths (e.g., M1_Mirror/study_name)
|
|
|
|
|
res = await fetch(`/api/optimization/studies/${studyId}/nx/introspect`);
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback to direct path introspection
|
|
|
|
|
res = await fetch('/api/nx/introspect', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ file_path: filePath }),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const errData = await res.json().catch(() => ({}));
|
|
|
|
|
throw new Error(errData.detail || 'Introspection failed');
|
|
|
|
|
}
|
2026-01-16 14:47:10 -05:00
|
|
|
const data = await res.json();
|
2026-01-20 14:14:14 -05:00
|
|
|
|
|
|
|
|
// Handle different response formats
|
|
|
|
|
setResult(data.introspection || data);
|
2026-01-16 14:47:10 -05:00
|
|
|
} catch (e) {
|
2026-01-20 14:14:14 -05:00
|
|
|
const msg = e instanceof Error ? e.message : 'Failed to introspect model';
|
|
|
|
|
setError(msg);
|
|
|
|
|
console.error('Introspection error:', e);
|
2026-01-16 14:47:10 -05:00
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
2026-01-20 14:14:14 -05:00
|
|
|
}, [filePath, studyId]);
|
2026-01-16 14:47:10 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
runIntrospection();
|
|
|
|
|
}, [runIntrospection]);
|
|
|
|
|
|
|
|
|
|
const toggleSection = (section: string) => {
|
|
|
|
|
setExpandedSections((prev) => {
|
|
|
|
|
const next = new Set(prev);
|
|
|
|
|
if (next.has(section)) next.delete(section);
|
|
|
|
|
else next.add(section);
|
|
|
|
|
return next;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addExpressionAsDesignVar = (expr: Expression) => {
|
|
|
|
|
// Find a good position (left of model node)
|
|
|
|
|
const modelNode = nodes.find((n) => n.data.type === 'model');
|
|
|
|
|
const existingDvars = nodes.filter((n) => n.data.type === 'designVar');
|
|
|
|
|
|
|
|
|
|
const position = {
|
|
|
|
|
x: (modelNode?.position.x || 300) - 250,
|
|
|
|
|
y: (modelNode?.position.y || 100) + existingDvars.length * 100,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Calculate min/max based on value if not provided
|
|
|
|
|
const minValue = expr.min ?? expr.value * 0.5;
|
|
|
|
|
const maxValue = expr.max ?? expr.value * 1.5;
|
|
|
|
|
|
|
|
|
|
addNode('designVar', position, {
|
|
|
|
|
label: expr.name,
|
|
|
|
|
expressionName: expr.name,
|
|
|
|
|
minValue,
|
|
|
|
|
maxValue,
|
|
|
|
|
unit: expr.unit,
|
|
|
|
|
configured: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addExtractorNode = (extractor: Extractor) => {
|
|
|
|
|
// Find a good position (right of solver node)
|
|
|
|
|
const solverNode = nodes.find((n) => n.data.type === 'solver');
|
|
|
|
|
const existingExtractors = nodes.filter((n) => n.data.type === 'extractor');
|
|
|
|
|
|
|
|
|
|
const position = {
|
|
|
|
|
x: (solverNode?.position.x || 400) + 200,
|
|
|
|
|
y: (solverNode?.position.y || 100) + existingExtractors.length * 100,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addNode('extractor', position, {
|
|
|
|
|
label: extractor.name,
|
|
|
|
|
extractorId: extractor.id,
|
|
|
|
|
extractorName: extractor.name,
|
|
|
|
|
configured: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-20 14:26:20 -05:00
|
|
|
// Handle both array format (old) and object format (new API)
|
|
|
|
|
const allExpressions: Expression[] = useMemo(() => {
|
|
|
|
|
if (!result?.expressions) return [];
|
|
|
|
|
|
|
|
|
|
// Check if expressions is an array (old format) or object (new format)
|
|
|
|
|
if (Array.isArray(result.expressions)) {
|
|
|
|
|
return result.expressions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// New format: { user: [...], internal: [...] }
|
|
|
|
|
const exprObj = result.expressions as ExpressionsResult;
|
|
|
|
|
return [...(exprObj.user || []), ...(exprObj.internal || [])];
|
|
|
|
|
}, [result?.expressions]);
|
|
|
|
|
|
|
|
|
|
const filteredExpressions = allExpressions.filter((e) =>
|
|
|
|
|
e.name.toLowerCase().includes(searchTerm.toLowerCase())
|
|
|
|
|
);
|
2026-01-16 14:47:10 -05:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="bg-dark-850 border border-dark-700 rounded-xl w-80 max-h-[70vh] flex flex-col shadow-xl">
|
|
|
|
|
{/* Header */}
|
|
|
|
|
<div className="flex items-center justify-between px-4 py-3 border-b border-dark-700">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Search size={16} className="text-primary-400" />
|
|
|
|
|
<span className="font-medium text-white text-sm">Model Introspection</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
|
<button
|
|
|
|
|
onClick={runIntrospection}
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
className="p-1.5 text-dark-400 hover:text-white hover:bg-dark-700 rounded transition-colors"
|
|
|
|
|
title="Refresh"
|
|
|
|
|
>
|
|
|
|
|
<RefreshCw size={14} className={isLoading ? 'animate-spin' : ''} />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
className="p-1.5 text-dark-400 hover:text-white hover:bg-dark-700 rounded transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<X size={14} />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Search */}
|
|
|
|
|
<div className="px-4 py-2 border-b border-dark-700">
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Filter expressions..."
|
|
|
|
|
value={searchTerm}
|
|
|
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
|
|
|
className="w-full px-3 py-1.5 bg-dark-800 border border-dark-600 rounded-lg
|
|
|
|
|
text-sm text-white placeholder-dark-500 focus:outline-none focus:border-primary-500"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Content */}
|
|
|
|
|
<div className="flex-1 overflow-auto">
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<div className="flex items-center justify-center h-32 text-dark-500">
|
|
|
|
|
<RefreshCw size={20} className="animate-spin mr-2" />
|
|
|
|
|
Analyzing model...
|
|
|
|
|
</div>
|
|
|
|
|
) : error ? (
|
|
|
|
|
<div className="p-4 text-red-400 text-sm">{error}</div>
|
|
|
|
|
) : result ? (
|
|
|
|
|
<div className="p-2 space-y-2">
|
|
|
|
|
{/* Solver Type */}
|
|
|
|
|
{result.solver_type && (
|
|
|
|
|
<div className="p-2 bg-dark-800 rounded-lg">
|
|
|
|
|
<div className="flex items-center gap-2 text-sm">
|
|
|
|
|
<Cpu size={14} className="text-violet-400" />
|
|
|
|
|
<span className="text-dark-300">Solver:</span>
|
|
|
|
|
<span className="text-white font-medium">{result.solver_type}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Expressions Section */}
|
|
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('expressions')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<SlidersHorizontal size={14} className="text-emerald-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
|
|
|
|
Expressions ({filteredExpressions.length})
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('expressions') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('expressions') && (
|
|
|
|
|
<div className="p-2 space-y-1 max-h-48 overflow-y-auto">
|
|
|
|
|
{filteredExpressions.length === 0 ? (
|
|
|
|
|
<p className="text-xs text-dark-500 text-center py-2">
|
|
|
|
|
No expressions found
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
filteredExpressions.map((expr) => (
|
|
|
|
|
<div
|
|
|
|
|
key={expr.name}
|
|
|
|
|
className="flex items-center justify-between p-2 bg-dark-850 rounded hover:bg-dark-750 group transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-sm text-white truncate">{expr.name}</p>
|
|
|
|
|
<p className="text-xs text-dark-500">
|
2026-01-20 14:26:20 -05:00
|
|
|
{expr.value} {expr.units || expr.unit || ''}
|
2026-01-16 14:47:10 -05:00
|
|
|
{expr.source === 'inferred' && (
|
|
|
|
|
<span className="ml-1 text-amber-500">(inferred)</span>
|
|
|
|
|
)}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => addExpressionAsDesignVar(expr)}
|
|
|
|
|
className="p-1.5 text-dark-500 hover:text-primary-400 hover:bg-dark-700 rounded
|
|
|
|
|
opacity-0 group-hover:opacity-100 transition-all"
|
|
|
|
|
title="Add as Design Variable"
|
|
|
|
|
>
|
|
|
|
|
<Plus size={14} />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-20 14:47:09 -05:00
|
|
|
{/* Mass Properties Section */}
|
|
|
|
|
{result.mass_properties && (
|
|
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('mass')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Scale size={14} className="text-blue-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">Mass Properties</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('mass') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('mass') && (
|
|
|
|
|
<div className="p-2 space-y-1">
|
|
|
|
|
{result.mass_properties.mass_kg !== undefined && (
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Mass</span>
|
|
|
|
|
<span className="text-white font-mono">
|
|
|
|
|
{(result.mass_properties.mass_kg as number).toFixed(4)} kg
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{result.mass_properties.volume_mm3 !== undefined && (result.mass_properties.volume_mm3 as number) > 0 && (
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Volume</span>
|
|
|
|
|
<span className="text-white font-mono">
|
|
|
|
|
{((result.mass_properties.volume_mm3 as number) / 1e9).toFixed(6)} m³
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{result.mass_properties.surface_area_mm2 !== undefined && (result.mass_properties.surface_area_mm2 as number) > 0 && (
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Surface Area</span>
|
|
|
|
|
<span className="text-white font-mono">
|
|
|
|
|
{((result.mass_properties.surface_area_mm2 as number) / 1e6).toFixed(4)} m²
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{Array.isArray(result.mass_properties.center_of_gravity_mm) && (
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">CoG (mm)</span>
|
|
|
|
|
<span className="text-white font-mono text-right">
|
|
|
|
|
[{(result.mass_properties.center_of_gravity_mm as number[]).map((v: number) => v.toFixed(1)).join(', ')}]
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{typeof result.mass_properties.num_bodies === 'number' && (
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Bodies</span>
|
|
|
|
|
<span className="text-white font-mono">{result.mass_properties.num_bodies}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Linked Parts / File Dependencies Section */}
|
|
|
|
|
{result.linked_parts && (
|
|
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('linked')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Link size={14} className="text-purple-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
|
|
|
|
Linked Parts ({(result.linked_parts.loaded_parts as Array<{name: string}>)?.length || 0})
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('linked') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('linked') && (
|
|
|
|
|
<div className="p-2 space-y-1 max-h-48 overflow-y-auto">
|
|
|
|
|
{((result.linked_parts.loaded_parts as Array<{name: string, path: string, leaf_name: string}>) || []).map((part) => (
|
|
|
|
|
<div
|
|
|
|
|
key={part.path}
|
|
|
|
|
className="p-2 bg-dark-850 rounded"
|
|
|
|
|
>
|
|
|
|
|
<p className="text-sm text-white">{part.name}</p>
|
|
|
|
|
<p className="text-xs text-dark-500 truncate" title={part.path}>
|
|
|
|
|
{part.leaf_name || part.path.split(/[/\\]/).pop()}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
{((result.linked_parts.loaded_parts as Array<unknown>) || []).length === 0 && (
|
|
|
|
|
<p className="text-xs text-dark-500 text-center py-2">No linked parts found</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Bodies Section */}
|
|
|
|
|
{result.bodies && (result.bodies.counts as {total: number})?.total > 0 && (
|
|
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('bodies')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Box size={14} className="text-orange-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
|
|
|
|
Bodies ({(result.bodies.counts as {total: number})?.total || 0})
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('bodies') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('bodies') && (
|
|
|
|
|
<div className="p-2 space-y-1">
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Solid Bodies</span>
|
|
|
|
|
<span className="text-white font-mono">{(result.bodies.counts as {solid: number})?.solid || 0}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">Sheet Bodies</span>
|
|
|
|
|
<span className="text-white font-mono">{(result.bodies.counts as {sheet: number})?.sheet || 0}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Units Section */}
|
|
|
|
|
{result.units && (
|
|
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('units')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<Settings2 size={14} className="text-gray-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
|
|
|
|
Units ({(result.units as {system?: string})?.system || 'Unknown'})
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('units') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('units') && (
|
|
|
|
|
<div className="p-2 space-y-1">
|
|
|
|
|
{(result.units as {base_units?: Record<string, string>})?.base_units &&
|
|
|
|
|
Object.entries((result.units as {base_units: Record<string, string>}).base_units).map(([key, value]) => (
|
|
|
|
|
<div key={key} className="flex justify-between p-2 bg-dark-850 rounded text-xs">
|
|
|
|
|
<span className="text-dark-400">{key}</span>
|
|
|
|
|
<span className="text-white font-mono">{value}</span>
|
|
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-01-20 14:26:20 -05:00
|
|
|
{/* Extractors Section - only show if available */}
|
|
|
|
|
{(result.extractors_available?.length ?? 0) > 0 && (
|
2026-01-16 14:47:10 -05:00
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('extractors')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<FlaskConical size={14} className="text-cyan-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
2026-01-20 14:26:20 -05:00
|
|
|
Available Extractors ({result.extractors_available?.length || 0})
|
2026-01-16 14:47:10 -05:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('extractors') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('extractors') && (
|
|
|
|
|
<div className="p-2 space-y-1 max-h-48 overflow-y-auto">
|
2026-01-20 14:26:20 -05:00
|
|
|
{(result.extractors_available || []).map((ext) => (
|
2026-01-16 14:47:10 -05:00
|
|
|
<div
|
|
|
|
|
key={ext.id}
|
|
|
|
|
className="flex items-center justify-between p-2 bg-dark-850 rounded hover:bg-dark-750 group transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-sm text-white">{ext.name}</p>
|
|
|
|
|
<p className="text-xs text-dark-500">
|
|
|
|
|
{ext.id}
|
|
|
|
|
{ext.description && ` - ${ext.description}`}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => addExtractorNode(ext)}
|
|
|
|
|
className="p-1.5 text-dark-500 hover:text-primary-400 hover:bg-dark-700 rounded
|
|
|
|
|
opacity-0 group-hover:opacity-100 transition-all"
|
|
|
|
|
title="Add Extractor"
|
|
|
|
|
>
|
|
|
|
|
<Plus size={14} />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-01-20 14:26:20 -05:00
|
|
|
)}
|
2026-01-16 14:47:10 -05:00
|
|
|
|
|
|
|
|
{/* Dependent Files */}
|
2026-01-20 14:26:20 -05:00
|
|
|
{(result.dependent_files?.length ?? 0) > 0 && (
|
2026-01-16 14:47:10 -05:00
|
|
|
<div className="border border-dark-700 rounded-lg overflow-hidden">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => toggleSection('files')}
|
|
|
|
|
className="w-full flex items-center justify-between px-3 py-2 bg-dark-800 hover:bg-dark-750 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<FileBox size={14} className="text-amber-400" />
|
|
|
|
|
<span className="text-sm font-medium text-white">
|
2026-01-20 14:26:20 -05:00
|
|
|
Dependent Files ({result.dependent_files?.length || 0})
|
2026-01-16 14:47:10 -05:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{expandedSections.has('files') ? (
|
|
|
|
|
<ChevronDown size={14} className="text-dark-400" />
|
|
|
|
|
) : (
|
|
|
|
|
<ChevronRight size={14} className="text-dark-400" />
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{expandedSections.has('files') && (
|
|
|
|
|
<div className="p-2 space-y-1 max-h-32 overflow-y-auto">
|
2026-01-20 14:26:20 -05:00
|
|
|
{(result.dependent_files || []).map((file) => (
|
2026-01-16 14:47:10 -05:00
|
|
|
<div
|
|
|
|
|
key={file.path}
|
|
|
|
|
className="flex items-center gap-2 p-2 bg-dark-850 rounded"
|
|
|
|
|
>
|
|
|
|
|
<FileBox size={14} className="text-dark-400 flex-shrink-0" />
|
|
|
|
|
<div className="flex-1 min-w-0">
|
|
|
|
|
<p className="text-sm text-white truncate">{file.name}</p>
|
|
|
|
|
<p className="text-xs text-dark-500">{file.type}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Warnings */}
|
2026-01-20 14:26:20 -05:00
|
|
|
{(result.warnings?.length ?? 0) > 0 && (
|
2026-01-16 14:47:10 -05:00
|
|
|
<div className="p-2 bg-amber-500/10 border border-amber-500/30 rounded-lg">
|
|
|
|
|
<div className="flex items-center gap-1.5 mb-1">
|
|
|
|
|
<AlertTriangle size={12} className="text-amber-400" />
|
|
|
|
|
<p className="text-xs text-amber-400 font-medium">Warnings</p>
|
|
|
|
|
</div>
|
2026-01-20 14:26:20 -05:00
|
|
|
{(result.warnings || []).map((w, i) => (
|
2026-01-16 14:47:10 -05:00
|
|
|
<p key={i} className="text-xs text-amber-300">
|
|
|
|
|
{w}
|
|
|
|
|
</p>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center h-32 text-dark-500 text-sm">
|
|
|
|
|
Select a model to introspect
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|