Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): show what a gauge, funnel or waterfall draws in its fallback table

marcoteb94e98bc9fda0
diff --git a/mcp-host/src/workflow/__tests__/dashboardCharts.table.test.ts b/mcp-host/src/workflow/__tests__/dashboardCharts.table.test.ts
new file mode 100644
index 000000000..fdb37cb15
--- /dev/null
+++ b/mcp-host/src/workflow/__tests__/dashboardCharts.table.test.ts
@@ -0,0 +1,77 @@
+// The table a dashboard shows when Chart.js is not inlined holds what the
+// chart draws, not what was sent.
+import { describe, expect, it } from 'vitest'
+import { prepareDashboardChart } from '../dashboardCharts'
+
+describe('the table shown in place of a chart', () => {
+ it('shows the one value a gauge draws, not the ones it left out', () => {
+ const prepared = prepareDashboardChart(
+ { type: 'gauge', labels: ['CPU', 'RAM'], datasets: [{ label: 'Load', data: [40, 80] }] },
+ 'charts[0]'
+ )
+ expect(prepared.warnings.join(' ')).toContain('1 more in datasets[0].data was left out')
+ expect(prepared.table).toEqual({
+ labels: ['CPU', 'Max'],
+ series: [{ label: 'Load', values: ['40', '100'] }],
+ })
+ })
+
+ it('shows the reading a gauge prints when it is past the dial', () => {
+ const prepared = prepareDashboardChart(
+ { type: 'gauge', gaugeMax: 50, datasets: [{ data: [72.456] }] },
+ 'charts[0]'
+ )
+ expect(prepared.table?.series[0].values).toEqual(['72.46', '50'])
+ })
+
+ it("lists a funnel's stages in the order it draws them", () => {
+ const prepared = prepareDashboardChart(
+ {
+ type: 'funnel',
+ labels: ['Visit', 'Buy', 'Cart'],
+ datasets: [{ label: 'Users', data: [100, 10, 40] }],
+ },
+ 'charts[0]'
+ )
+ expect(prepared.table).toEqual({
+ labels: ['Visit', 'Cart', 'Buy'],
+ series: [{ label: 'Users', values: ['100', '40', '10'] }],
+ })
+ })
+
+ it("lists a waterfall's changes as sent and the total it draws", () => {
+ const prepared = prepareDashboardChart(
+ {
+ type: 'waterfall',
+ labels: ['Start', 'Sales', 'Costs'],
+ datasets: [{ label: 'Cash', data: [0.1, 0.2, -0.125] }],
+ },
+ 'charts[0]'
+ )
+ expect(prepared.table).toEqual({
+ labels: ['Start', 'Sales', 'Costs', 'Total'],
+ series: [{ label: 'Cash', values: ['0.1', '0.2', '-0.125', '0.18'] }],
+ })
+ })
+
+ it('keeps every series of an ordinary chart', () => {
+ const prepared = prepareDashboardChart(
+ {
+ type: 'bar',
+ labels: ['a', 'b'],
+ datasets: [
+ { label: 'One', data: [1, null] },
+ { label: 'Two', data: [3, 4] },
+ ],
+ },
+ 'charts[0]'
+ )
+ expect(prepared.table).toEqual({
+ labels: ['a', 'b'],
+ series: [
+ { label: 'One', values: ['1', ''] },
+ { label: 'Two', values: ['3', '4'] },
+ ],
+ })
+ })
+})
diff --git a/mcp-host/src/workflow/dashboardCharts.ts b/mcp-host/src/workflow/dashboardCharts.ts
index 09b2ad1d6..ef77cd5df 100644
--- a/mcp-host/src/workflow/dashboardCharts.ts
+++ b/mcp-host/src/workflow/dashboardCharts.ts
@@ -71,6 +71,8 @@ interface ValueTable {
interface Translated {
chart: Omit<ClientChart, 'id'>
warnings: string[]
+ /** What a composed chart draws, for the table shown in its place; others list their series. */
+ table?: ValueTable
}
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -286,7 +288,11 @@ function translate(
borderColor: follow(first?.borderColor),
}
chart.datasets = [{ ...styled(stages, 0, 'bar'), label: '' }]
- return { chart, warnings }
+ const table = {
+ labels: chart.labels,
+ series: [{ label: first?.label ?? '', values: stages.data.map(String) }],
+ }
+ return { chart, warnings, table }
}
case 'waterfall': {
chart.type = 'bar'
@@ -303,6 +309,12 @@ function translate(
floats.push([0, total])
colors.push('$chart-0')
chart.labels = [...labels, 'Total']
+ const table = {
+ labels: chart.labels,
+ series: [
+ { label: datasets[0]?.label ?? '', values: [...deltas.map(String), readout(total)] },
+ ],
+ }
chart.datasets = [
{
label: datasets[0]?.label ?? '',
@@ -311,7 +323,7 @@ function translate(
borderColor: colors,
},
]
- return { chart, warnings }
+ return { chart, warnings, table }
}
case 'gauge': {
chart.type = 'doughnut'
@@ -348,7 +360,11 @@ function translate(
},
]
chart.gauge = { value: readout(raw), max: readout(max) }
- return { chart, warnings }
+ const table = {
+ labels: [chart.labels[0], 'Max'],
+ series: [{ label: datasets[0]?.label ?? '', values: [chart.gauge.value, chart.gauge.max] }],
+ }
+ return { chart, warnings, table }
}
default:
chart.datasets = datasets.map((ds, i) => styled(ds, i))
@@ -471,7 +487,7 @@ export function prepareDashboardChart(raw: unknown, where: string): PreparedChar
caption:
type === 'gauge' && Array.isArray(raw.labels) ? optionalText(raw.labels[0]) : undefined,
chart: translated.chart,
- table: valueTable(type, labels, datasets),
+ table: translated.table ?? valueTable(type, labels, datasets),
warnings,
}
} catch (err) {