UNPKG

@fusedashlabs/ui9000-workspace

Version:

UI9000 workspace MCP. One tool, show_workspace, draws a chart from your table. Set TYPESAFE_API_KEY to let Jev choose the chart.

41 lines (40 loc) • 1.31 kB
export function asRowObjects(payload) { if (!Array.isArray(payload) || payload.length === 0) return null; const rows = []; for (const item of payload) { if (!item || typeof item !== 'object' || Array.isArray(item)) return null; rows.push(item); } return rows; } export function aggregatePoints(rows, labelField, metricField, relabel = (label) => label) { if (!labelField || !metricField) return null; if (!(labelField in rows[0]) || !(metricField in rows[0])) return null; const sums = new Map(); for (const row of rows) { const label = relabel(String(row[labelField] ?? '').trim()); const value = Number(row[metricField]); if (!label || !Number.isFinite(value)) continue; sums.set(label, (sums.get(label) ?? 0) + value); } if (sums.size === 0) return null; return [...sums.entries()].map(([label, value]) => ({ label, value })); } export function numericColumn(rows, field) { if (!field || !(field in rows[0])) return null; const values = []; for (const row of rows) { const n = Number(row[field]); if (!Number.isFinite(n)) continue; values.push(n); } return values.length > 0 ? values : null; }