Skip to content

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

TypeScript

perf(mcp-host): load the dashboard renderer on first use

marcoteb86bf4c417225
diff --git a/mcp-host/src/workflow/__tests__/internalTools.lazyLoad.test.ts b/mcp-host/src/workflow/__tests__/internalTools.lazyLoad.test.ts
index 44ca76fdb..1285034f7 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.lazyLoad.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.lazyLoad.test.ts
@@ -1,5 +1,6 @@
-// Importing the internal tools loads no document library: the host starts
-// without them, and each loads the first time its generator runs.
+// Importing the internal tools loads no document library and no generator
+// module: the host starts without them, and each loads the first time its
+// generator runs.
import { describe, expect, it, vi } from 'vitest'
import { createRequire } from 'module'
import * as path from 'path'
@@ -23,6 +24,16 @@ vi.mock('chart.js', () => (imported.push('chart.js'), {}))
vi.mock('@napi-rs/canvas', () => (imported.push('@napi-rs/canvas'), {}))
vi.mock('jszip', () => (imported.push('jszip'), {}))
+// Generator modules, recorded and left as they are.
+const generators = vi.hoisted(() => [] as string[])
+vi.mock('../dashboardRender', async original => (generators.push('dashboardRender'), original()))
+vi.mock('../dashboardCharts', async original => (generators.push('dashboardCharts'), original()))
+vi.mock('../chartGenerator', async original => (generators.push('chartGenerator'), original()))
+vi.mock('../pdfGenerator', async original => (generators.push('pdfGenerator'), original()))
+vi.mock('../docxGenerator', async original => (generators.push('docxGenerator'), original()))
+vi.mock('../xlsxWorkbook', async original => (generators.push('xlsxWorkbook'), original()))
+vi.mock('../pptxDeck', async original => (generators.push('pptxDeck'), original()))
+
/** Libraries Node has loaded through require, which vi.mock does not see. */
function required(): string[] {
const cache = createRequire(path.resolve('package.json')).cache
@@ -39,4 +50,10 @@ describe('internal tools module', () => {
expect(imported).toEqual([])
expect(required()).toEqual(before)
})
+
+ it('loads no generator module when imported', async () => {
+ const { INTERNAL_TOOLS } = await import('../internalTools')
+ expect(INTERNAL_TOOLS.length).toBeGreaterThan(0)
+ expect(generators).toEqual([])
+ })
})
diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.ts
index 5e1c07ea5..c1f377cc2 100644
--- a/mcp-host/src/workflow/internalTools.ts
+++ b/mcp-host/src/workflow/internalTools.ts
@@ -7,13 +7,12 @@
*
* This file lists them. Each schema is in toolSchemas/, and each generator is
* its own module, loaded with its library on first use: pdfmake (PDF), docx
- * (DOCX), exceljs (XLSX), pptxgenjs (PPTX), chart.js (PNG charts); markdown and
- * the dashboard HTML are written as strings. No headless browser is involved,
+ * (DOCX), exceljs (XLSX), pptxgenjs (PPTX), chart.js (PNG charts), and the
+ * dashboard renderer; markdown and the dashboard HTML are written as strings. No headless browser is involved,
* but @napi-rs/canvas is native, and charts, PDFs and the measuring of DOCX
* tables and slide text read the fonts the image installs (fonts.ts).
*/
import { CONTEXT_FILES_TOOLS, loadContextFilesMounts } from './contextFiles'
-import { runGenerateDashboard } from './dashboardRender'
import { runGenerateMarkdown } from './markdownGenerator'
import { runGeneratePptx } from './pptxGenerator'
import { fromModule, nullsUnset, prepared } from './toolExecution'
@@ -72,7 +71,10 @@ const generateXlsx: InternalToolDefinition = { ...XLSX_TOOL, execute: runGenerat
const generateDashboardTool: InternalToolDefinition = {
...DASHBOARD_TOOL,
execute(args: Record<string, unknown>, outputDir: string): Promise<InternalToolResult> {
- return runGenerateDashboard(args, outputDir)
+ return fromModule(
+ () => import('./dashboardRender'),
+ m => m.runGenerateDashboard(args, outputDir)
+ )
},
}