Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(mcp-host): keep the dashboard vocabulary apart from its renderer
marcoteb9c914657f989
diff --git a/mcp-host/src/workflow/dashboardChartJs.ts b/mcp-host/src/workflow/dashboardChartJs.tsnew file mode 100644index 000000000..341a55e45--- /dev/null+++ b/mcp-host/src/workflow/dashboardChartJs.ts@@ -0,0 +1,18 @@+/** The Chart.js bundle a dashboard inlines, read once. */+import * as fs from 'fs'+import * as path from 'path'++let cachedChartJsBundle: string | undefined++/**+ * The Chart.js UMD bundle. chart.js exports only ".", "./auto" and+ * "./helpers", so resolving "chart.js/dist/chart.umd.js" throws+ * ERR_PACKAGE_PATH_NOT_EXPORTED; the entry point resolves, and the bundle sits+ * beside it in dist/.+ */+export function loadChartJsBundle(): string {+ if (cachedChartJsBundle) return cachedChartJsBundle+ const bundle = path.join(path.dirname(require.resolve('chart.js')), 'chart.umd.js')+ cachedChartJsBundle = fs.readFileSync(bundle, 'utf-8')+ return cachedChartJsBundle+}diff --git a/mcp-host/src/workflow/dashboardCharts.ts b/mcp-host/src/workflow/dashboardCharts.tsindex 80fa77d0b..c1b543c63 100644--- a/mcp-host/src/workflow/dashboardCharts.ts+++ b/mcp-host/src/workflow/dashboardCharts.ts@@ -7,26 +7,9 @@import { ChartDataError, coerceNumber, normalizeChartData } from './chartData'import type { NormalizedDataset, NormalizedPoint } from './chartData'import { escapeHtml } from './dashboardHtml'+import { DASHBOARD_CHART_TYPES } from './dashboardVocabulary'-/** Every chart type the dashboard draws, the same set clerum__generate_chart accepts. */-export const DASHBOARD_CHART_TYPES = [- 'line',- 'bar',- 'horizontalBar',- 'pie',- 'doughnut',- 'area',- 'radar',- 'polarArea',- 'scatter',- 'bubble',- 'stackedBar',- 'stackedArea',- 'mixedBarLine',- 'gauge',- 'waterfall',- 'funnel',-] as const+export { DASHBOARD_CHART_TYPES } from './dashboardVocabulary'const KNOWN_TYPES = new Set<string>(DASHBOARD_CHART_TYPES)const SLICE_TYPES = new Set(['pie', 'doughnut', 'polarArea'])diff --git a/mcp-host/src/workflow/dashboardRender.ts b/mcp-host/src/workflow/dashboardRender.tsindex e4c4c5953..4f0adcda5 100644--- a/mcp-host/src/workflow/dashboardRender.ts+++ b/mcp-host/src/workflow/dashboardRender.ts@@ -10,6 +10,7 @@ import {replacedBytes,} from './artifactOutput'import { coerceNumber } from './chartData'+import { loadChartJsBundle } from './dashboardChartJs'import { DashboardCharts } from './dashboardCharts'import { escapeHtml, escapeHtmlAttr, oneOf, safeJsonForScript } from './dashboardHtml'import { dashboardScript } from './dashboardScript'@@ -19,11 +20,28 @@ import {type DashboardThemeColors,type ThemeName,} from './dashboardThemes'+import {+ BLOCK_TYPES,+ CALLOUT_TONES,+ DASHBOARD_TEMPLATE_NAMES,+ type DashboardTemplateName,+ HERO_STATUSES,+ SECTION_TYPES,+} from './dashboardVocabulary'import { inlineSpans } from './inlineMarkup'import { choose, own } from './ownEntry'import { headerText, normalizeTableRows } from './tableRows'import type { InternalToolResult } from './types'+export {+ BLOCK_TYPES,+ CALLOUT_TONES,+ DASHBOARD_TEMPLATE_NAMES,+ HERO_STATUSES,+ SECTION_TYPES,+} from './dashboardVocabulary'+export { loadChartJsBundle } from './dashboardChartJs'+function dashboardColorVars(c: DashboardThemeColors): string {return `--bg: ${c.bg};@@ -904,8 +922,6 @@ function dashItems(const cardNotice = (message: string) =>`<div class="callout" data-tone="danger">${escapeHtml(message)}</div>`-export const HERO_STATUSES = ['green', 'yellow', 'red', 'neutral'] as const-function renderHero(o: Record<string, unknown>): string {const eyebrowText = dashText(o.eyebrow)const eyebrow = eyebrowText ? `<div class="hero__eyebrow">${escapeHtml(eyebrowText)}</div>` : ''@@ -1172,9 +1188,6 @@ function fitRowsToHeaders(return fitted}-export const SECTION_TYPES = ['narrative', 'bullets', 'callout', 'code'] as const-export const CALLOUT_TONES = ['info', 'success', 'warning', 'danger'] as const-function renderSectionHtml(s: unknown, where: string): string {const section = dashRecord(s, where, 'a section object {type, content}')if (section.type !== undefined && !SECTION_TYPES.includes(section.type as never)) {@@ -1403,32 +1416,8 @@ ${scripts}</html>`}-// ─── Chart.js bundle loader (cached) ────────────────────────────────--let cachedChartJsBundle: string | undefined--/**- * The Chart.js UMD bundle. chart.js exports only ".", "./auto" and- * "./helpers", so resolving "chart.js/dist/chart.umd.js" throws- * ERR_PACKAGE_PATH_NOT_EXPORTED; the entry point resolves, and the bundle sits- * beside it in dist/.- */-export function loadChartJsBundle(): string {- if (cachedChartJsBundle) return cachedChartJsBundle- const bundle = path.join(path.dirname(require.resolve('chart.js')), 'chart.umd.js')- cachedChartJsBundle = fs.readFileSync(bundle, 'utf-8')- return cachedChartJsBundle-}-// ─── Templates ──────────────────────────────────────────────────────-type DashboardTemplateName =- | 'executive-brief'- | 'operations-pulse'- | 'financial-review'- | 'technical-report'- | 'custom'-type DashData = Record<string, unknown>// The fields are named rather than spread: a spread reads every key, which@@ -1539,22 +1528,6 @@ const DASHBOARD_TEMPLATES: Record<// ─── Custom template (composable blocks) ────────────────────────────-export const BLOCK_TYPES = [- 'hero',- 'kpis',- 'chart',- 'charts-grid',- 'table',- 'narrative',- 'bullets',- 'code',- 'callout',- 'incidents',- 'service-health',- 'divider',- 'spacer',-] as const-/** Blocks that are content of their own; charts and card groups count their entries. */const COUNTED_BLOCKS = new Set(['table', 'narrative', 'bullets', 'code', 'callout'])@@ -1829,11 +1802,3 @@ export async function runGenerateDashboard(return { success: false, error: err instanceof Error ? err.message : String(err) }}}--export const DASHBOARD_TEMPLATE_NAMES = [- 'executive-brief',- 'operations-pulse',- 'financial-review',- 'technical-report',- 'custom',-] as constdiff --git a/mcp-host/src/workflow/dashboardVocabulary.ts b/mcp-host/src/workflow/dashboardVocabulary.tsnew file mode 100644index 000000000..e0bf77de9--- /dev/null+++ b/mcp-host/src/workflow/dashboardVocabulary.ts@@ -0,0 +1,55 @@+/**+ * The names `clerum__generate_dashboard` accepts, apart from the renderer, so+ * its schema can list them without loading the renderer.+ */++/** Every chart type the dashboard draws, the same set clerum__generate_chart accepts. */+export const DASHBOARD_CHART_TYPES = [+ 'line',+ 'bar',+ 'horizontalBar',+ 'pie',+ 'doughnut',+ 'area',+ 'radar',+ 'polarArea',+ 'scatter',+ 'bubble',+ 'stackedBar',+ 'stackedArea',+ 'mixedBarLine',+ 'gauge',+ 'waterfall',+ 'funnel',+] as const++export const HERO_STATUSES = ['green', 'yellow', 'red', 'neutral'] as const++export const SECTION_TYPES = ['narrative', 'bullets', 'callout', 'code'] as const+export const CALLOUT_TONES = ['info', 'success', 'warning', 'danger'] as const++export const BLOCK_TYPES = [+ 'hero',+ 'kpis',+ 'chart',+ 'charts-grid',+ 'table',+ 'narrative',+ 'bullets',+ 'code',+ 'callout',+ 'incidents',+ 'service-health',+ 'divider',+ 'spacer',+] as const++export const DASHBOARD_TEMPLATE_NAMES = [+ 'executive-brief',+ 'operations-pulse',+ 'financial-review',+ 'technical-report',+ 'custom',+] as const++export type DashboardTemplateName = (typeof DASHBOARD_TEMPLATE_NAMES)[number]diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.tsindex 529115c29..b7974bae0 100644--- a/mcp-host/src/workflow/internalTools.ts+++ b/mcp-host/src/workflow/internalTools.ts@@ -32,15 +32,15 @@ import {MIN_CHART_DIMENSION,} from './chartThemes'import { CONTEXT_FILES_TOOLS, loadContextFilesMounts } from './contextFiles'-import { DASHBOARD_CHART_TYPES } from './dashboardCharts'+import { runGenerateDashboard } from './dashboardRender'import {BLOCK_TYPES,CALLOUT_TONES,+ DASHBOARD_CHART_TYPES,DASHBOARD_TEMPLATE_NAMES,HERO_STATUSES,SECTION_TYPES,- runGenerateDashboard,-} from './dashboardRender'+} from './dashboardVocabulary'import {DOCX_IMAGE_FILE_DESCRIPTION,IMAGE_FILE_DESCRIPTION,@@ -64,7 +64,7 @@ export { enforceQuota, getDirectorySize } from './artifactOutput'export { CHART_THEMES } from './chartThemes'export type { ChartTheme } from './chartThemes'export { escapeHtmlAttr, safeJsonForScript } from './dashboardHtml'-export { loadChartJsBundle } from './dashboardRender'+export { loadChartJsBundle } from './dashboardChartJs'// Accessor to the current Host CRD, injected by main (avoids a circular import).// Re-read on every getOutputDir() call because `currentHost` is hydrated async