Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): keep each dashboard funnel stage in its own colors
marcoteb39e75d73f5fd
diff --git a/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts b/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.tsindex e8cfff3aa..8817ffe91 100644--- a/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts@@ -3,7 +3,8 @@* told what was changed or left out: list blocks, table cells, KPI figures,* footer provenance, series colors and gauge readings.*/-import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { Chart } from 'chart.js'import * as fs from 'fs'import * as os from 'os'import * as path from 'path'@@ -592,6 +593,113 @@ describe('gauge', () => {})})+describe('funnel stages', () => {+ interface Stages {+ labels: unknown[]+ data: unknown[]+ backgroundColor: unknown+ borderColor: unknown+ }++ async function dashboardFunnel(data: Record<string, unknown>): Promise<Stages> {+ const { html } = await render({ data: { title: 'T', charts: [{ type: 'funnel', ...data }] } })+ const [funnel] = chartSpecs(html)+ const ds = (funnel.datasets as Array<Record<string, unknown>>)[0]+ return {+ labels: funnel.labels as unknown[],+ data: ds.data as unknown[],+ backgroundColor: ds.backgroundColor,+ borderColor: ds.borderColor,+ }+ }++ /** The funnel clerum__generate_chart draws from the same data, as Chart.js drew it. */+ async function pngFunnel(data: Record<string, unknown>): Promise<Stages> {+ const seen: Stages[] = []+ const draw = Chart.prototype.draw+ const spy = vi.spyOn(Chart.prototype, 'draw').mockImplementation(function (this: Chart) {+ const ds = this.data.datasets[0]+ seen.push({+ labels: [...(this.data.labels ?? [])],+ data: [...ds.data],+ backgroundColor: ds.backgroundColor,+ borderColor: ds.borderColor,+ })+ return draw.call(this)+ })+ try {+ const tool = INTERNAL_TOOLS.find(t => t.name === 'clerum__generate_chart')!+ const r = await tool.execute(+ { filename: 'f.png', type: 'funnel', showValues: false, data },+ outputDir+ )+ expect(r.success, r.error).toBe(true)+ } finally {+ spy.mockRestore()+ }+ return seen[seen.length - 1]+ }++ it('keeps each stage in the colors it was sent with when the stages are sorted', async () => {+ const funnel = await dashboardFunnel({+ labels: ['low', 'high'],+ datasets: [+ {+ data: [1, 10],+ backgroundColor: ['#111111', '#222222'],+ borderColor: ['#333333', '#444444'],+ },+ ],+ })+ expect(funnel).toEqual({+ labels: ['high', 'low'],+ data: [10, 1],+ backgroundColor: ['#222222', '#111111'],+ borderColor: ['#444444', '#333333'],+ })+ })++ it('gives each stage the color a short list gave it before the sort, as the PNG does', async () => {+ const data = {+ labels: ['Visits', 'Paid', 'Signups', 'Trials'],+ datasets: [+ {+ data: [2400, 10000, 2400, 5000],+ backgroundColor: ['#dc2626', '#16a34a', '#f59e0b'],+ borderColor: '#0f172a',+ },+ ],+ }+ const dashboard = await dashboardFunnel(data)+ expect(dashboard).toEqual({+ labels: ['Paid', 'Trials', 'Visits', 'Signups'],+ data: [10000, 5000, 2400, 2400],+ backgroundColor: ['#16a34a', '#dc2626', '#dc2626', '#f59e0b'],+ borderColor: '#0f172a',+ })+ expect(await pngFunnel(data)).toEqual(dashboard)+ })++ it('moves a replaced color with its stage and leaves series colors as they were', async () => {+ const replaced = await dashboardFunnel({+ labels: ['a', 'b'],+ datasets: [{ data: [1, 2], backgroundColor: ['#111111', 'nope'] }],+ })+ expect(replaced.backgroundColor).toEqual(['$chart-0', '#111111'])+ expect(replaced.borderColor).toBe('$chart-0')++ const single = await dashboardFunnel({+ labels: ['a', 'b'],+ datasets: [{ data: [1, 2], backgroundColor: '#111111', borderColor: [] }],+ })+ expect(single).toMatchObject({ labels: ['b', 'a'], backgroundColor: '#111111' })+ expect(single.borderColor).toEqual([])++ const plain = await dashboardFunnel({ labels: ['a', 'b'], datasets: [{ data: [1, 2] }] })+ expect(plain).toMatchObject({ backgroundColor: '$chart-0', borderColor: '$chart-0' })+ })+})+describe('value tables without Chart.js', () => {it('keeps the radius of a bubble', async () => {const { html } = await render({diff --git a/mcp-host/src/workflow/dashboardCharts.ts b/mcp-host/src/workflow/dashboardCharts.tsindex 31f53237b..9ab1d8fa2 100644--- a/mcp-host/src/workflow/dashboardCharts.ts+++ b/mcp-host/src/workflow/dashboardCharts.ts@@ -284,12 +284,23 @@ function translate(chart.type = 'bar'chart.indexAxis = 'y'chart.legend = false- const pairs = firstSeriesValues(datasets[0]).map((v, i) => ({ v, l: labels[i] ?? '' }))+ const first = datasets[0]+ const pairs = firstSeriesValues(first).map((v, i) => ({ v, l: labels[i] ?? '', i }))pairs.sort((a, b) => b.v - a.v)chart.labels = pairs.map(p => p.l)- chart.datasets = [- { ...styled({ ...datasets[0], data: pairs.map(p => p.v) }, 0, 'bar'), label: '' },- ]+ // Per-stage colors follow their stage through the sort, as in the PNG+ // funnel; a short list wraps as Chart.js wraps it.+ const follow = (colors: string | string[] | undefined) =>+ Array.isArray(colors) && colors.length > 0+ ? pairs.map(p => colors[p.i % colors.length])+ : colors+ const stages = {+ ...first,+ data: pairs.map(p => p.v),+ backgroundColor: follow(first?.backgroundColor),+ borderColor: follow(first?.borderColor),+ }+ chart.datasets = [{ ...styled(stages, 0, 'bar'), label: '' }]return { chart, warnings }}case 'waterfall': {