{
  "id": 135,
  "slug": "node-flow-graph-inspector",
  "name": "Interactive Node / Flow Graph Inspector",
  "kind": "ui",
  "family": "Spatial & Canvas",
  "sourceSite": {
    "name": "React Flow",
    "url": "https://reactflow.dev/",
    "verifiedStatus": 200
  },
  "tagline": "Blueprint node-graph editor with draggable workflow nodes, live SVG bezier edges, animated run pulses, and a property inspector.",
  "whyUnique": "Combines direct-manipulation node positioning and animated signal flow along cubic bezier edges with a live property inspector that collapses into a bottom drawer on mobile.",
  "theme": "dark",
  "mobileStrength": "high",
  "tags": [
    "node-graph",
    "flow-editor",
    "workflow-builder",
    "svg-bezier",
    "inspector",
    "automation"
  ],
  "bestFor": [
    "AI agent and LLM pipeline builders",
    "ETL data orchestration and webhook flows",
    "Audio/shader node graph editors",
    "State machine and CI/CD visualizers"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#0B1020",
      "name": "Blueprint Midnight"
    },
    {
      "role": "surface",
      "hex": "#131B2E",
      "name": "Node Slate"
    },
    {
      "role": "ink",
      "hex": "#F1F5F9",
      "name": "Signal White"
    },
    {
      "role": "accent",
      "hex": "#38BDF8",
      "name": "Telemetry Cyan"
    },
    {
      "role": "muted",
      "hex": "#8A9BB8",
      "name": "Grid Steel"
    }
  ],
  "typography": {
    "display": "Inter",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&family=JetBrains+Mono:wght@500;600&display=swap",
    "scaleNotes": "13.5px node titles, 11px mono latency/status pills, 12px inspector form labels."
  },
  "layoutNotes": "Fluid dot-grid node stage on the left paired with a 300px right-hand node property inspector on desktop; slide-up or collapsible inspector panel on mobile.",
  "interactionNotes": "Drag any node to recompute SVG bezier connectors in real time; click a node to edit its label, status, or latency budget; click Run Pipeline to animate execution pulses across edges.",
  "mobileNotes": "Provides Fit View and zoom controls plus a toggleable node inspector sheet so users can inspect and edit nodes cleanly at 390px without losing the graph.",
  "agentGuardrails": {
    "do": [
      "Recompute SVG bezier paths smoothly on every pointermove frame using node port anchors.",
      "Indicate node execution state with both color and text/icon status badges.",
      "Dock the node inspector as a collapsible panel or bottom sheet on mobile screens."
    ],
    "dont": [
      "Never leave edges disconnected or stale when a node is dragged.",
      "Avoid hardcoding fixed pixel canvas dimensions that clip nodes on 390px screens."
    ]
  },
  "demoFile": "demos/node-flow-graph-inspector.html",
  "thumbDesktop": "thumbs/node-flow-graph-inspector-desktop.webp",
  "thumbMobile": "thumbs/node-flow-graph-inspector-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/node-flow-graph-inspector",
    "markdown": "https://templates.michaelpitts.net/t/node-flow-graph-inspector.md",
    "api": "https://templates.michaelpitts.net/api/templates/node-flow-graph-inspector",
    "demo": "https://templates.michaelpitts.net/demos/node-flow-graph-inspector.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/node-flow-graph-inspector-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/node-flow-graph-inspector-mobile.webp"
  },
  "agentPrompt": "Design & build using template #135 \"Interactive Node / Flow Graph Inspector\" (ui / Spatial & Canvas, dark theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/node-flow-graph-inspector.md\nLive demo: https://templates.michaelpitts.net/demos/node-flow-graph-inspector.html\nReal-world inspiration: React Flow (https://reactflow.dev/)\n\nCore aesthetic: Combines direct-manipulation node positioning and animated signal flow along cubic bezier edges with a live property inspector that collapses into a bottom drawer on mobile.\nPalette: canvas: #0B1020 (Blueprint Midnight), surface: #131B2E (Node Slate), ink: #F1F5F9 (Signal White), accent: #38BDF8 (Telemetry Cyan), muted: #8A9BB8 (Grid Steel)\nTypography: Display=\"Inter\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: Fluid dot-grid node stage on the left paired with a 300px right-hand node property inspector on desktop; slide-up or collapsible inspector panel on mobile.\nInteractions: Drag any node to recompute SVG bezier connectors in real time; click a node to edit its label, status, or latency budget; click Run Pipeline to animate execution pulses across edges.\nMobile: Provides Fit View and zoom controls plus a toggleable node inspector sheet so users can inspect and edit nodes cleanly at 390px without losing the graph.\n\nGuardrails:\n- DO: Recompute SVG bezier paths smoothly on every pointermove frame using node port anchors.\n- DO: Indicate node execution state with both color and text/icon status badges.\n- DO: Dock the node inspector as a collapsible panel or bottom sheet on mobile screens.\n- DON'T: Never leave edges disconnected or stale when a node is dragged.\n- DON'T: Avoid hardcoding fixed pixel canvas dimensions that clip nodes on 390px screens.",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>CircuitFlow — Node Graph Inspector</title>\n  <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n  <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n  <link href=\"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap\" rel=\"stylesheet\">\n  <style>\n    :root {\n      --bg: #080d1a;\n      --grid-dot: rgba(148, 163, 184, 0.22);\n      --panel: #0f172a;\n      --card: #141e33;\n      --card-hover: #1a2742;\n      --border: #24324d;\n      --border-active: #38bdf8;\n      --ink: #f1f5f9;\n      --ink-muted: #94a3b8;\n      --ink-faint: #64748b;\n\n      --c-trigger: #f59e0b;\n      --c-transform: #38bdf8;\n      --c-model: #a78bfa;\n      --c-router: #10b981;\n      --c-sink: #fb7185;\n\n      --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;\n      --font-mono: 'JetBrains Mono', ui-monospace, monospace;\n    }\n\n    * { box-sizing: border-box; margin: 0; padding: 0; }\n\n    html, body {\n      height: 100%;\n      background: var(--bg);\n      color: var(--ink);\n      font-family: var(--font-sans);\n      -webkit-font-smoothing: antialiased;\n      overflow: hidden;\n    }\n\n    .app {\n      display: flex;\n      flex-direction: column;\n      height: 100dvh;\n      width: 100vw;\n      overflow: hidden;\n    }\n\n    /* Top Header */\n    .topbar {\n      height: 56px;\n      padding: 0 16px;\n      background: var(--panel);\n      border-bottom: 1px solid var(--border);\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 12px;\n      flex-shrink: 0;\n      z-index: 20;\n    }\n\n    .brand {\n      display: flex;\n      align-items: center;\n      gap: 10px;\n      min-width: 0;\n    }\n\n    .brand-icon {\n      width: 30px;\n      height: 30px;\n      border-radius: 8px;\n      background: rgba(56, 189, 248, 0.14);\n      border: 1px solid rgba(56, 189, 248, 0.35);\n      color: #38bdf8;\n      display: grid;\n      place-items: center;\n      flex-shrink: 0;\n    }\n\n    .brand-text h1 {\n      font-size: 14px;\n      font-weight: 600;\n      letter-spacing: -0.01em;\n      white-space: nowrap;\n    }\n\n    .brand-text span {\n      font-family: var(--font-mono);\n      font-size: 11px;\n      color: var(--ink-muted);\n    }\n\n    .top-actions {\n      display: flex;\n      align-items: center;\n      gap: 8px;\n    }\n\n    .btn {\n      appearance: none;\n      border: 1px solid var(--border);\n      background: var(--card);\n      color: var(--ink);\n      font-family: var(--font-sans);\n      font-size: 12.5px;\n      font-weight: 500;\n      padding: 0 12px;\n      min-height: 38px;\n      border-radius: 8px;\n      cursor: pointer;\n      display: inline-flex;\n      align-items: center;\n      gap: 6px;\n      transition: background 0.15s, border-color 0.15s, transform 0.1s;\n      white-space: nowrap;\n    }\n\n    .btn:hover {\n      background: var(--card-hover);\n      border-color: #3b517a;\n    }\n\n    .btn-run {\n      background: linear-gradient(135deg, #0284c7, #2563eb);\n      border-color: rgba(56, 189, 248, 0.5);\n      color: #fff;\n      font-weight: 600;\n    }\n    .btn-run:hover {\n      background: linear-gradient(135deg, #0ea5e9, #3b82f6);\n    }\n    .btn-run:disabled {\n      opacity: 0.65;\n      cursor: wait;\n    }\n\n    /* Main Split */\n    .main {\n      flex: 1;\n      display: grid;\n      grid-template-columns: 1fr 330px;\n      min-height: 0;\n      position: relative;\n      overflow: hidden;\n    }\n\n    /* Blueprint Canvas */\n    .canvas-wrap {\n      position: relative;\n      overflow: hidden;\n      background-color: var(--bg);\n      background-image: radial-gradient(var(--grid-dot) 1.25px, transparent 1.25px);\n      background-size: 24px 24px;\n      touch-action: none;\n      user-select: none;\n    }\n\n    .viewport {\n      position: absolute;\n      inset: 0;\n      transform-origin: 0 0;\n    }\n\n    .edges-layer {\n      position: absolute;\n      inset: 0;\n      width: 1600px;\n      height: 1000px;\n      overflow: visible;\n      pointer-events: none;\n    }\n\n    .edge-path {\n      fill: none;\n      stroke: #334155;\n      stroke-width: 2.25;\n      transition: stroke 0.25s;\n    }\n\n    .edge-path.active {\n      stroke: #38bdf8;\n      stroke-width: 2.75;\n    }\n\n    .edge-path.pulse-running {\n      stroke: #38bdf8;\n      stroke-dasharray: 8 6;\n      animation: dashFlow 0.7s linear infinite;\n    }\n\n    @keyframes dashFlow {\n      to { stroke-dashoffset: -28; }\n    }\n\n    .pulse-dot {\n      fill: #38bdf8;\n      filter: drop-shadow(0 0 6px #38bdf8);\n    }\n\n    /* Node Cards */\n    .node {\n      position: absolute;\n      width: 214px;\n      background: var(--card);\n      border: 1.5px solid var(--border);\n      border-radius: 11px;\n      padding: 11px 13px;\n      cursor: grab;\n      box-shadow: 0 8px 24px rgba(2, 6, 23, 0.45);\n      transition: border-color 0.15s, box-shadow 0.15s, opacity 0.2s;\n      touch-action: none;\n    }\n\n    .node:active { cursor: grabbing; }\n\n    .node.selected {\n      border-color: var(--border-active);\n      box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18), 0 12px 28px rgba(2, 6, 23, 0.6);\n    }\n\n    .node.disabled {\n      opacity: 0.48;\n      border-style: dashed;\n    }\n\n    .node.running {\n      border-color: #38bdf8;\n      box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.28);\n    }\n\n    .node.done {\n      border-color: #10b981;\n    }\n\n    .node-head {\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 6px;\n      margin-bottom: 6px;\n    }\n\n    .node-kind {\n      font-family: var(--font-mono);\n      font-size: 10px;\n      font-weight: 600;\n      text-transform: uppercase;\n      letter-spacing: 0.06em;\n      padding: 2px 6px;\n      border-radius: 4px;\n    }\n\n    .node-status {\n      font-family: var(--font-mono);\n      font-size: 10.5px;\n      color: var(--ink-muted);\n    }\n\n    .node.done .node-status { color: #34d399; }\n    .node.running .node-status { color: #38bdf8; }\n\n    .node-title {\n      font-size: 13.5px;\n      font-weight: 600;\n      color: var(--ink);\n      margin-bottom: 4px;\n      white-space: nowrap;\n      overflow: hidden;\n      text-overflow: ellipsis;\n    }\n\n    .node-sub {\n      font-family: var(--font-mono);\n      font-size: 11px;\n      color: var(--ink-muted);\n      white-space: nowrap;\n      overflow: hidden;\n      text-overflow: ellipsis;\n    }\n\n    .port {\n      position: absolute;\n      top: 50%;\n      width: 10px;\n      height: 10px;\n      border-radius: 50%;\n      background: #0f172a;\n      border: 2px solid #64748b;\n      transform: translateY(-50%);\n    }\n    .port-in { left: -6px; }\n    .port-out { right: -6px; }\n    .node.selected .port { border-color: #38bdf8; }\n\n    /* Floating Canvas Controls */\n    .canvas-controls {\n      position: absolute;\n      left: 14px;\n      bottom: 14px;\n      display: flex;\n      align-items: center;\n      gap: 4px;\n      background: rgba(15, 23, 42, 0.92);\n      border: 1px solid var(--border);\n      padding: 4px;\n      border-radius: 10px;\n      backdrop-filter: blur(8px);\n      z-index: 10;\n    }\n\n    .zoom-btn {\n      appearance: none;\n      border: none;\n      background: transparent;\n      color: var(--ink-muted);\n      font-family: var(--font-mono);\n      font-size: 12px;\n      min-width: 36px;\n      min-height: 36px;\n      padding: 0 8px;\n      border-radius: 6px;\n      cursor: pointer;\n    }\n    .zoom-btn:hover {\n      background: var(--card-hover);\n      color: var(--ink);\n    }\n\n    .run-banner {\n      position: absolute;\n      left: 14px;\n      top: 14px;\n      background: rgba(15, 23, 42, 0.9);\n      border: 1px solid var(--border);\n      padding: 7px 12px;\n      border-radius: 8px;\n      font-family: var(--font-mono);\n      font-size: 11.5px;\n      color: var(--ink-muted);\n      pointer-events: none;\n      z-index: 10;\n    }\n\n    /* Inspector Sidebar / Mobile Drawer */\n    .inspector {\n      background: var(--panel);\n      border-left: 1px solid var(--border);\n      display: flex;\n      flex-direction: column;\n      min-height: 0;\n      overflow-y: auto;\n      z-index: 15;\n    }\n\n    .inspector-head {\n      padding: 14px 16px;\n      border-bottom: 1px solid var(--border);\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 8px;\n    }\n\n    .inspector-head h2 {\n      font-size: 13px;\n      font-weight: 600;\n      text-transform: uppercase;\n      letter-spacing: 0.05em;\n      color: var(--ink-muted);\n    }\n\n    .close-drawer {\n      display: none;\n      appearance: none;\n      border: 1px solid var(--border);\n      background: var(--card);\n      color: var(--ink);\n      min-width: 44px;\n      min-height: 44px;\n      border-radius: 8px;\n      cursor: pointer;\n      font-size: 16px;\n    }\n\n    .inspector-body {\n      padding: 16px;\n      display: flex;\n      flex-direction: column;\n      gap: 14px;\n    }\n\n    .field {\n      display: flex;\n      flex-direction: column;\n      gap: 6px;\n    }\n\n    .field label {\n      font-size: 12px;\n      font-weight: 500;\n      color: var(--ink-muted);\n    }\n\n    .field input[type=\"text\"],\n    .field input[type=\"number\"],\n    .field select,\n    .field textarea {\n      width: 100%;\n      background: var(--bg);\n      border: 1px solid var(--border);\n      border-radius: 7px;\n      color: var(--ink);\n      font-family: var(--font-mono);\n      font-size: 12.5px;\n      padding: 9px 10px;\n      outline: none;\n      transition: border-color 0.15s;\n    }\n\n    .field input:focus,\n    .field select:focus,\n    .field textarea:focus {\n      border-color: var(--border-active);\n    }\n\n    .field-row {\n      display: grid;\n      grid-template-columns: 1fr 1fr;\n      gap: 10px;\n    }\n\n    .toggle-row {\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      padding: 10px 12px;\n      background: var(--bg);\n      border: 1px solid var(--border);\n      border-radius: 8px;\n    }\n\n    .toggle-row span {\n      font-size: 13px;\n      font-weight: 500;\n    }\n\n    .toggle-row input[type=\"checkbox\"] {\n      width: 18px;\n      height: 18px;\n      accent-color: #38bdf8;\n      cursor: pointer;\n    }\n\n    .metrics-box {\n      background: var(--bg);\n      border: 1px solid var(--border);\n      border-radius: 8px;\n      padding: 12px;\n      display: grid;\n      grid-template-columns: 1fr 1fr;\n      gap: 10px;\n    }\n\n    .metric-item span {\n      display: block;\n      font-size: 11px;\n      color: var(--ink-faint);\n      margin-bottom: 2px;\n    }\n\n    .metric-item strong {\n      font-family: var(--font-mono);\n      font-size: 13px;\n      color: var(--ink);\n    }\n\n    .inspector-toggle-mobile {\n      display: none;\n    }\n\n    @media (max-width: 860px) {\n      .main {\n        grid-template-columns: 1fr;\n      }\n\n      .hide-mobile { display: none; }\n\n      .btn { min-height: 44px; padding: 0 11px; }\n      .zoom-btn { min-width: 44px; min-height: 44px; }\n\n      .inspector-toggle-mobile {\n        display: inline-flex;\n      }\n\n      .inspector {\n        position: fixed;\n        left: 0;\n        right: 0;\n        bottom: 0;\n        max-height: 68dvh;\n        border-left: none;\n        border-top: 1px solid var(--border-active);\n        border-radius: 16px 16px 0 0;\n        box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.55);\n        transform: translateY(105%);\n        transition: transform 0.25s ease;\n      }\n\n      .inspector.open {\n        transform: translateY(0);\n      }\n\n      .close-drawer {\n        display: inline-grid;\n        place-items: center;\n      }\n    }\n  </style>\n</head>\n<body>\n  <div class=\"app\">\n    <header class=\"topbar\">\n      <div class=\"brand\">\n        <div class=\"brand-icon\" aria-hidden=\"true\">\n          <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.2\"><rect x=\"3\" y=\"4\" width=\"6\" height=\"6\" rx=\"1\"/><rect x=\"15\" y=\"14\" width=\"6\" height=\"6\" rx=\"1\"/><path d=\"M9 7h4a2 2 0 0 1 2 2v5\"/></svg>\n        </div>\n        <div class=\"brand-text\">\n          <h1>Ingestion &amp; Triage Pipeline</h1>\n          <span class=\"hide-mobile\">6 nodes · 5 edges · drag nodes to reposition</span>\n        </div>\n      </div>\n\n      <div class=\"top-actions\">\n        <button id=\"btnInspectMobile\" class=\"btn inspector-toggle-mobile\" type=\"button\">Inspector</button>\n        <button id=\"btnFit\" class=\"btn hide-mobile\" type=\"button\">Fit View</button>\n        <button id=\"btnRun\" class=\"btn btn-run\" type=\"button\">\n          <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><polygon points=\"6 4 20 12 6 20 6 4\"/></svg>\n          <span>Run Pipeline</span>\n        </button>\n      </div>\n    </header>\n\n    <div class=\"main\">\n      <div id=\"canvasWrap\" class=\"canvas-wrap\" aria-label=\"Interactive flow graph canvas\">\n        <div id=\"runBanner\" class=\"run-banner\">Idle · Select any node to inspect or drag</div>\n        <div id=\"viewport\" class=\"viewport\">\n          <svg id=\"edgesLayer\" class=\"edges-layer\"></svg>\n          <div id=\"nodesLayer\"></div>\n        </div>\n\n        <div class=\"canvas-controls\">\n          <button id=\"zoomOut\" class=\"zoom-btn\" type=\"button\" aria-label=\"Zoom out\">−</button>\n          <span id=\"zoomPct\" style=\"font-family:var(--font-mono);font-size:11.5px;color:var(--ink-muted);padding:0 6px;\">100%</span>\n          <button id=\"zoomIn\" class=\"zoom-btn\" type=\"button\" aria-label=\"Zoom in\">+</button>\n          <button id=\"zoomReset\" class=\"zoom-btn\" type=\"button\">Fit</button>\n        </div>\n      </div>\n\n      <aside id=\"inspector\" class=\"inspector\" aria-label=\"Node property inspector\">\n        <div class=\"inspector-head\">\n          <h2>Node Inspector</h2>\n          <button id=\"closeDrawer\" class=\"close-drawer\" type=\"button\" aria-label=\"Close inspector\">✕</button>\n        </div>\n        <div id=\"inspectorBody\" class=\"inspector-body\"></div>\n      </aside>\n    </div>\n  </div>\n\n  <script>\n    const KIND_COLORS = {\n      trigger: { color: '#f59e0b', bg: 'rgba(245, 158, 11, 0.14)' },\n      transform: { color: '#38bdf8', bg: 'rgba(56, 189, 248, 0.14)' },\n      model: { color: '#a78bfa', bg: 'rgba(167, 139, 250, 0.14)' },\n      router: { color: '#10b981', bg: 'rgba(16, 185, 129, 0.14)' },\n      sink: { color: '#fb7185', bg: 'rgba(251, 113, 133, 0.14)' }\n    };\n\n    const nodes = [\n      { id: 'n1', kind: 'trigger', title: 'Webhook Ingest', config: 'POST /v2/events/support', timeout: 800, retries: 2, enabled: true, x: 40, y: 170, latency: 18, notes: 'Verifies HMAC-SHA256 signature before enqueueing.' },\n      { id: 'n2', kind: 'transform', title: 'PII Redactor', config: 'regex + presidio-fast', timeout: 1200, retries: 1, enabled: true, x: 300, y: 170, latency: 42, notes: 'Strips credit cards, SSNs, and bearer tokens.' },\n      { id: 'n3', kind: 'model', title: 'Embedding Classifier', config: 'text-embed-v3 · 768d', timeout: 3500, retries: 2, enabled: true, x: 560, y: 80, latency: 164, notes: 'Computes intent vector and urgency score.' },\n      { id: 'n4', kind: 'router', title: 'Confidence Router', config: 'score >= 0.86', timeout: 400, retries: 0, enabled: true, x: 560, y: 270, latency: 9, notes: 'Routes high-confidence tickets to auto-index.' },\n      { id: 'n5', kind: 'sink', title: 'Vector Index', config: 'qdrant://prod-us-east', timeout: 1500, retries: 3, enabled: true, x: 830, y: 120, latency: 31, notes: 'Upserts payload with tenant namespace.' },\n      { id: 'n6', kind: 'sink', title: 'Human Review Queue', config: 'linear://triage-inbox', timeout: 2000, retries: 2, enabled: true, x: 830, y: 290, latency: 54, notes: 'Escalates low-confidence items to on-call.' }\n    ];\n\n    const edges = [\n      { id: 'e1', from: 'n1', to: 'n2' },\n      { id: 'e2', from: 'n2', to: 'n3' },\n      { id: 'e3', from: 'n3', to: 'n4' },\n      { id: 'e4', from: 'n4', to: 'n5' },\n      { id: 'e5', from: 'n4', to: 'n6' }\n    ];\n\n    let selectedId = 'n3';\n    let scale = 1;\n    let panX = 0;\n    let panY = 0;\n    let isRunning = false;\n\n    const canvasWrap = document.getElementById('canvasWrap');\n    const viewport = document.getElementById('viewport');\n    const edgesLayer = document.getElementById('edgesLayer');\n    const nodesLayer = document.getElementById('nodesLayer');\n    const inspector = document.getElementById('inspector');\n    const inspectorBody = document.getElementById('inspectorBody');\n    const runBanner = document.getElementById('runBanner');\n    const zoomPct = document.getElementById('zoomPct');\n\n    function getNode(id) {\n      return nodes.find(n => n.id === id);\n    }\n\n    function applyTransform() {\n      viewport.style.transform = `translate(${panX}px, ${panY}px) scale(${scale})`;\n      zoomPct.textContent = `${Math.round(scale * 100)}%`;\n    }\n\n    function fitView() {\n      const rect = canvasWrap.getBoundingClientRect();\n      const minX = Math.min(...nodes.map(n => n.x)) - 28;\n      const minY = Math.min(...nodes.map(n => n.y)) - 36;\n      const maxX = Math.max(...nodes.map(n => n.x + 214)) + 28;\n      const maxY = Math.max(...nodes.map(n => n.y + 92)) + 60;\n      const w = maxX - minX;\n      const h = maxY - minY;\n      scale = Math.min(1.05, Math.max(0.32, Math.min(rect.width / w, rect.height / h)));\n      panX = (rect.width - w * scale) / 2 - minX * scale;\n      panY = (rect.height - h * scale) / 2 - minY * scale;\n      applyTransform();\n    }\n\n    function bezierPath(a, b) {\n      const x1 = a.x + 214;\n      const y1 = a.y + 44;\n      const x2 = b.x;\n      const y2 = b.y + 44;\n      const dx = Math.max(60, Math.abs(x2 - x1) * 0.5);\n      return `M ${x1} ${y1} C ${x1 + dx} ${y1}, ${x2 - dx} ${y2}, ${x2} ${y2}`;\n    }\n\n    function renderEdges() {\n      const svgNS = 'http://www.w3.org/2000/svg';\n      edgesLayer.innerHTML = '';\n      edges.forEach(edge => {\n        const a = getNode(edge.from);\n        const b = getNode(edge.to);\n        const path = document.createElementNS(svgNS, 'path');\n        path.setAttribute('id', `path-${edge.id}`);\n        path.setAttribute('d', bezierPath(a, b));\n        const isSel = edge.from === selectedId || edge.to === selectedId;\n        path.setAttribute('class', `edge-path ${isSel ? 'active' : ''}`);\n        edgesLayer.appendChild(path);\n      });\n    }\n\n    function renderNodes() {\n      nodesLayer.innerHTML = '';\n      nodes.forEach(n => {\n        const k = KIND_COLORS[n.kind];\n        const el = document.createElement('div');\n        el.className = `node ${n.id === selectedId ? 'selected' : ''} ${n.enabled ? '' : 'disabled'}`;\n        el.dataset.id = n.id;\n        el.style.left = `${n.x}px`;\n        el.style.top = `${n.y}px`;\n        el.innerHTML = `\n          ${n.kind !== 'trigger' ? '<div class=\"port port-in\"></div>' : ''}\n          ${n.kind !== 'sink' ? '<div class=\"port port-out\"></div>' : ''}\n          <div class=\"node-head\">\n            <span class=\"node-kind\" style=\"color:${k.color};background:${k.bg}\">${n.kind}</span>\n            <span class=\"node-status\" id=\"status-${n.id}\">${n.enabled ? `${n.latency}ms` : 'paused'}</span>\n          </div>\n          <div class=\"node-title\">${n.title}</div>\n          <div class=\"node-sub\">${n.config}</div>\n        `;\n        attachDrag(el, n);\n        nodesLayer.appendChild(el);\n      });\n    }\n\n    function attachDrag(el, node) {\n      let dragging = false;\n      let startX = 0, startY = 0, origX = 0, origY = 0;\n\n      el.addEventListener('pointerdown', (e) => {\n        e.stopPropagation();\n        selectNode(node.id, false);\n        dragging = true;\n        startX = e.clientX;\n        startY = e.clientY;\n        origX = node.x;\n        origY = node.y;\n        el.setPointerCapture(e.pointerId);\n      });\n\n      el.addEventListener('pointermove', (e) => {\n        if (!dragging) return;\n        const dx = (e.clientX - startX) / scale;\n        const dy = (e.clientY - startY) / scale;\n        node.x = Math.round(origX + dx);\n        node.y = Math.round(origY + dy);\n        el.style.left = `${node.x}px`;\n        el.style.top = `${node.y}px`;\n        renderEdges();\n      });\n\n      el.addEventListener('pointerup', (e) => {\n        if (!dragging) return;\n        dragging = false;\n        el.releasePointerCapture(e.pointerId);\n        const moved = Math.hypot(e.clientX - startX, e.clientY - startY);\n        if (moved < 5 && window.innerWidth <= 860) {\n          inspector.classList.add('open');\n        }\n      });\n    }\n\n    function selectNode(id, openDrawer = true) {\n      selectedId = id;\n      document.querySelectorAll('.node').forEach(el => {\n        el.classList.toggle('selected', el.dataset.id === id);\n      });\n      renderEdges();\n      renderInspector();\n      if (openDrawer && window.innerWidth <= 860) {\n        inspector.classList.add('open');\n      }\n    }\n\n    function renderInspector() {\n      const n = getNode(selectedId);\n      if (!n) return;\n      const k = KIND_COLORS[n.kind];\n      inspectorBody.innerHTML = `\n        <div style=\"display:flex;align-items:center;justify-content:space-between;\">\n          <span class=\"node-kind\" style=\"color:${k.color};background:${k.bg};font-size:11px;\">${n.kind} · ${n.id}</span>\n          <span style=\"font-family:var(--font-mono);font-size:11px;color:var(--ink-faint);\">x:${n.x} y:${n.y}</span>\n        </div>\n\n        <div class=\"field\">\n          <label for=\"inpTitle\">Node Name</label>\n          <input id=\"inpTitle\" type=\"text\" value=\"${n.title.replace(/\"/g, '&quot;')}\">\n        </div>\n\n        <div class=\"field\">\n          <label for=\"inpConfig\">Endpoint / Model / Expression</label>\n          <input id=\"inpConfig\" type=\"text\" value=\"${n.config.replace(/\"/g, '&quot;')}\">\n        </div>\n\n        <div class=\"field-row\">\n          <div class=\"field\">\n            <label for=\"inpTimeout\">Timeout (ms)</label>\n            <input id=\"inpTimeout\" type=\"number\" min=\"100\" step=\"100\" value=\"${n.timeout}\">\n          </div>\n          <div class=\"field\">\n            <label for=\"inpRetries\">Max Retries</label>\n            <input id=\"inpRetries\" type=\"number\" min=\"0\" max=\"5\" value=\"${n.retries}\">\n          </div>\n        </div>\n\n        <label class=\"toggle-row\">\n          <span>Node Enabled</span>\n          <input id=\"inpEnabled\" type=\"checkbox\" ${n.enabled ? 'checked' : ''}>\n        </label>\n\n        <div class=\"field\">\n          <label for=\"inpNotes\">Operator Notes</label>\n          <textarea id=\"inpNotes\" rows=\"3\">${n.notes}</textarea>\n        </div>\n\n        <div class=\"metrics-box\">\n          <div class=\"metric-item\"><span>P95 Latency</span><strong>${n.latency} ms</strong></div>\n          <div class=\"metric-item\"><span>Success Rate</span><strong>99.94%</strong></div>\n        </div>\n      `;\n\n      const syncNodeCard = () => {\n        const card = nodesLayer.querySelector(`.node[data-id=\"${n.id}\"]`);\n        if (!card) return;\n        card.querySelector('.node-title').textContent = n.title || 'Untitled Node';\n        card.querySelector('.node-sub').textContent = n.config;\n        card.classList.toggle('disabled', !n.enabled);\n        const st = document.getElementById(`status-${n.id}`);\n        if (st) st.textContent = n.enabled ? `${n.latency}ms` : 'paused';\n      };\n\n      document.getElementById('inpTitle').addEventListener('input', (e) => { n.title = e.target.value; syncNodeCard(); });\n      document.getElementById('inpConfig').addEventListener('input', (e) => { n.config = e.target.value; syncNodeCard(); });\n      document.getElementById('inpTimeout').addEventListener('input', (e) => { n.timeout = Number(e.target.value) || 0; });\n      document.getElementById('inpRetries').addEventListener('input', (e) => { n.retries = Number(e.target.value) || 0; });\n      document.getElementById('inpEnabled').addEventListener('change', (e) => { n.enabled = e.target.checked; syncNodeCard(); });\n      document.getElementById('inpNotes').addEventListener('input', (e) => { n.notes = e.target.value; });\n    }\n\n    // Canvas panning\n    let panning = false, pStartX = 0, pStartY = 0, origPanX = 0, origPanY = 0;\n    canvasWrap.addEventListener('pointerdown', (e) => {\n      if (e.target.closest('.node') || e.target.closest('.canvas-controls')) return;\n      panning = true;\n      pStartX = e.clientX;\n      pStartY = e.clientY;\n      origPanX = panX;\n      origPanY = panY;\n      canvasWrap.setPointerCapture(e.pointerId);\n    });\n    canvasWrap.addEventListener('pointermove', (e) => {\n      if (!panning) return;\n      panX = origPanX + (e.clientX - pStartX);\n      panY = origPanY + (e.clientY - pStartY);\n      applyTransform();\n    });\n    canvasWrap.addEventListener('pointerup', () => { panning = false; });\n\n    // Animated Run Pipeline\n    async function animateEdge(edgeId, duration = 420) {\n      const path = document.getElementById(`path-${edgeId}`);\n      if (!path) return;\n      path.classList.add('pulse-running');\n      const len = path.getTotalLength();\n      const dot = document.createElementNS('http://www.w3.org/2000/svg', 'circle');\n      dot.setAttribute('r', '5');\n      dot.setAttribute('class', 'pulse-dot');\n      edgesLayer.appendChild(dot);\n\n      const start = performance.now();\n      await new Promise(resolve => {\n        function step(now) {\n          const t = Math.min(1, (now - start) / duration);\n          const pt = path.getPointAtLength(len * t);\n          dot.setAttribute('cx', pt.x);\n          dot.setAttribute('cy', pt.y);\n          if (t < 1) requestAnimationFrame(step);\n          else resolve();\n        }\n        requestAnimationFrame(step);\n      });\n\n      dot.remove();\n      path.classList.remove('pulse-running');\n    }\n\n    async function runPipeline() {\n      if (isRunning) return;\n      isRunning = true;\n      const btnRun = document.getElementById('btnRun');\n      btnRun.disabled = true;\n      runBanner.textContent = 'Running pipeline trace…';\n\n      document.querySelectorAll('.node').forEach(el => el.classList.remove('running', 'done'));\n\n      const stages = [\n        { nodeIds: ['n1'], outEdges: ['e1'] },\n        { nodeIds: ['n2'], outEdges: ['e2'] },\n        { nodeIds: ['n3'], outEdges: ['e3'] },\n        { nodeIds: ['n4'], outEdges: ['e4', 'e5'] },\n        { nodeIds: ['n5', 'n6'], outEdges: [] }\n      ];\n\n      let totalMs = 0;\n      for (const stage of stages) {\n        stage.nodeIds.forEach(id => {\n          const card = nodesLayer.querySelector(`.node[data-id=\"${id}\"]`);\n          const st = document.getElementById(`status-${id}`);\n          const n = getNode(id);\n          if (card && n.enabled) {\n            card.classList.add('running');\n            st.textContent = 'running…';\n          }\n        });\n        await new Promise(r => setTimeout(r, 260));\n        stage.nodeIds.forEach(id => {\n          const card = nodesLayer.querySelector(`.node[data-id=\"${id}\"]`);\n          const st = document.getElementById(`status-${id}`);\n          const n = getNode(id);\n          if (card && n.enabled) {\n            card.classList.remove('running');\n            card.classList.add('done');\n            const jitter = Math.max(5, n.latency + Math.round((Math.random() - 0.5) * 10));\n            totalMs += jitter;\n            st.textContent = `200 · ${jitter}ms`;\n          }\n        });\n        if (stage.outEdges.length) {\n          await Promise.all(stage.outEdges.map(eid => animateEdge(eid, 380)));\n        }\n      }\n\n      runBanner.textContent = `Trace succeeded · ${totalMs}ms total · 6/6 nodes healthy`;\n      btnRun.disabled = false;\n      isRunning = false;\n    }\n\n    document.getElementById('btnRun').addEventListener('click', runPipeline);\n    document.getElementById('btnFit').addEventListener('click', fitView);\n    document.getElementById('zoomReset').addEventListener('click', fitView);\n    document.getElementById('zoomIn').addEventListener('click', () => { scale = Math.min(1.6, scale + 0.15); applyTransform(); });\n    document.getElementById('zoomOut').addEventListener('click', () => { scale = Math.max(0.3, scale - 0.15); applyTransform(); });\n    document.getElementById('btnInspectMobile').addEventListener('click', () => inspector.classList.toggle('open'));\n    document.getElementById('closeDrawer').addEventListener('click', () => inspector.classList.remove('open'));\n\n    window.addEventListener('resize', fitView);\n\n    renderNodes();\n    renderEdges();\n    renderInspector();\n    requestAnimationFrame(fitView);\n  </script>\n</body>\n</html>\n"
}
