Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(mcp-host): type the deck builder with pptxgenjs's own types
marcotebeff8b23035e8
diff --git a/mcp-host/src/workflow/__tests__/pptxCharts.test.ts b/mcp-host/src/workflow/__tests__/pptxCharts.test.tsindex e35e2d39e..082fc0ea2 100644--- a/mcp-host/src/workflow/__tests__/pptxCharts.test.ts+++ b/mcp-host/src/workflow/__tests__/pptxCharts.test.ts@@ -8,7 +8,7 @@ import { ChartSpecError, type NativeChart, nativeChartArgs, readNativeChart } frconst style = { colors: ['#111111', '#222222'], textColor: '#000000', mutedColor: '#666666' }const pptx = {charts: { BAR: 'bar', LINE: 'line', PIE: 'pie', AREA: 'area', DOUGHNUT: 'doughnut' },-}+} as constdescribe('readNativeChart', () => {it('reads labels and datasets nested under data or at the top', () => {diff --git a/mcp-host/src/workflow/pptxCharts.ts b/mcp-host/src/workflow/pptxCharts.tsindex c09f0a4f4..3e6b4cb90 100644--- a/mcp-host/src/workflow/pptxCharts.ts+++ b/mcp-host/src/workflow/pptxCharts.ts@@ -4,7 +4,9 @@* The data goes through the same normalizer as clerum__generate_chart, because* PowerPoint drops chart-cache values written as text such as "1,200".*/+import type PptxGenJS from 'pptxgenjs'import { ChartDataError, normalizeChartData } from './chartData'+import type { PptxDeck } from './pptxDraw'import { PPTX_FONT_FACE } from './pptxText'import { NATIVE_CHART_TYPES } from './pptxVocabulary'@@ -171,8 +173,8 @@ function valueFormats(values: number[]): { label: string; axis: string } {export function nativeChartArgs(chart: NativeChart,style: NativeChartStyle,- pptx: any-): { type: string; data: unknown[]; options: Record<string, unknown> } {+ pptx: Pick<PptxDeck, 'charts'>+): { type: PptxGenJS.CHART_NAME; data: unknown[]; options: Record<string, unknown> } {const c = pptx.charts ?? {}const type =chart.type === 'line'diff --git a/mcp-host/src/workflow/pptxDeck.ts b/mcp-host/src/workflow/pptxDeck.tsindex f680578e7..beef079b2 100644--- a/mcp-host/src/workflow/pptxDeck.ts+++ b/mcp-host/src/workflow/pptxDeck.ts@@ -6,6 +6,7 @@* lists and tables that do not fit continue on further slides, titles and* values shrink to fit their boxes, and pictures keep their proportions.*/+import type PptxGenJSType from 'pptxgenjs'import { documentEastAsianScript } from './docxScript'import { choose } from './ownEntry'import { type DrawContext, hex } from './pptxDraw'@@ -27,7 +28,8 @@ import { PPTX_FONT_FACE, TEXT_INSET_X, truncateToLines, wrapLines } from './pptximport { PPTX_ASPECT_RATIOS, PPTX_PALETTES, PPTX_TEMPLATES } from './pptxVocabulary'import { keepZipTextWhole } from './zipText'-const PptxGenJS = require('pptxgenjs')+// Loaded with require so the tests and the Host run the same CommonJS bundle.+const PptxGenJS: typeof PptxGenJSType = require('pptxgenjs')/** The slides `args` describe, from a template's data or from slides[]. */function readDeck(args: Record<string, unknown>, ctx: ReadContext): PptxSlide[] {diff --git a/mcp-host/src/workflow/pptxDraw.ts b/mcp-host/src/workflow/pptxDraw.tsindex 164351119..9fef3b24b 100644--- a/mcp-host/src/workflow/pptxDraw.ts+++ b/mcp-host/src/workflow/pptxDraw.ts@@ -1,4 +1,5 @@/** What every slide renderer shares: the drawing context, colors and fitted text. */+import type PptxGenJS from 'pptxgenjs'import { type PptxPicture } from './pptxInput'import { type Frame } from './pptxLayout'import { TEXT_INSET_X, TEXT_INSET_Y, fitText, lineHeightIn, truncateToLines } from './pptxText'@@ -9,10 +10,21 @@ export function hex(c: string): string {return c.replace(/^#/, '').toUpperCase()}+/**+ * The deck pptxgenjs builds. Its `charts` and `shapes` name tables exist at+ * run time (getters on the instance) but its types leave them out.+ */+export type PptxDeck = PptxGenJS & {+ readonly charts?: Partial<+ Record<'AREA' | 'BAR' | 'DOUGHNUT' | 'LINE' | 'PIE', PptxGenJS.CHART_NAME>+ >+ readonly shapes?: Partial<Record<'RECTANGLE' | 'ROUNDED_RECTANGLE', PptxGenJS.ShapeType>>+}+export interface DrawContext {frame: Framepalette: PptxPalette- pptx: any+ pptx: PptxDeckwarnings: string[]logo?: PptxPicture}diff --git a/mcp-host/src/workflow/pptxRender.ts b/mcp-host/src/workflow/pptxRender.tsindex 5fb322024..60c6d6afe 100644--- a/mcp-host/src/workflow/pptxRender.ts+++ b/mcp-host/src/workflow/pptxRender.ts@@ -329,8 +329,8 @@ function drawTable(slide: Slide, planned: PlannedSlide, ctx: DrawContext): voidcolor: hex(p.text),fill: r % 2 === 0 ? { color: hex(p.surface) } : undefined,}),- align: 'left',- valign: 'top',+ align: 'left' as const,+ valign: 'top' as const,...runOptions(slide, text, 'left'),},}))diff --git a/mcp-host/src/workflow/pptxRuns.ts b/mcp-host/src/workflow/pptxRuns.tsindex f9a1d8754..7d251fd34 100644--- a/mcp-host/src/workflow/pptxRuns.ts+++ b/mcp-host/src/workflow/pptxRuns.ts@@ -1,4 +1,5 @@/** Text runs on a slide: language, direction and bullets. */+import type PptxGenJS from 'pptxgenjs'import { bidiLanguage, hasRtlLetter, isRtlText, scriptSegments } from './docxScript'import { type PptxSlide, isRecord } from './pptxInput'import { type Box } from './pptxLayout'@@ -7,7 +8,7 @@ import { scriptOptions } from './pptxText'// U+2022, not U+25CF: PowerPoint sets the ambiguous-width U+25CF in the East Asian face of// a CJK-tagged paragraph, where the dot is larger than on the Latin lines around it.const BULLET = { code: '2022' }-export type Slide = any+export type Slide = PptxGenJS.Slide/** The language of each slide's text of Han characters alone: the deck's. */export const hanLanguage = new WeakMap<Slide, string>()