/** * Object View - Generic Python object introspection viewer * Displays metrics, spectral graphs, and serialized data for: * - PyTorch/NumPy tensors * - PIL Images * - SafeTensors models * - Generic Python objects */ import { BaseView, escapeHtml } from "./base_view.js"; class ObjectView extends BaseView { static id = "object"; static displayName = "Object"; static priority = 5; static OBJECT_MARKER = "$WAS_OBJECT$"; static detect(content) { try { let jsonContent = content; if (content.startsWith(this.OBJECT_MARKER)) { jsonContent = content.slice(this.OBJECT_MARKER.length); } const parsed = JSON.parse(jsonContent); if (parsed.type === "object_viewer" && Array.isArray(parsed.objects)) { return 150; } } catch {} return 0; } static getContentMarker() { return this.OBJECT_MARKER; } static render(content, theme) { let data; try { let jsonContent = content; if (content.startsWith(this.OBJECT_MARKER)) { jsonContent = content.slice(this.OBJECT_MARKER.length); } data = JSON.parse(jsonContent); } catch { return `
Invalid object data`; } const objects = data.objects || []; if (objects.length === 0) { return `
No objects to display