Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): keep a PPTX table column at its minimum width
marcotebec70d48bd632
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.tsindex 6d1e93177..902cee999 100644--- a/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts@@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'import * as fs from 'fs'import * as os from 'os'import * as path from 'path'+import { layoutTable } from '../pptxTables'import { fitText, textBlockHeight } from '../pptxText'import {generatePptx,@@ -138,6 +139,26 @@ describe('clerum__generate_pptx — long tables continue on further slides', ()})})+describe('PPTX table columns', () => {+ it('keeps a narrow column at its minimum whether the others fit or not', () => {+ for (const word of ['Internationalization', 'Internationalization'.repeat(3)]) {+ const table = {+ headers: ['#', 'Alpha', 'Beta', 'Gamma', 'Delta'],+ rows: [['1', word, word, word, word]],+ }+ const { columnWidths } = layoutTable(table, { w: 9.2, h: 5 }, true, 'slides[0]', [])+ expect(columnWidths[0]).toBeGreaterThanOrEqual(0.6 - 1e-6)+ expect(columnWidths.reduce((a, b) => a + b, 0)).toBeCloseTo(9.2, 4)+ }+ })++ it('gives every column the same width when too many for each to have its minimum', () => {+ const table = { headers: Array.from({ length: 20 }, (_, i) => `Column${i}`), rows: [] }+ const { columnWidths } = layoutTable(table, { w: 9.2, h: 5 }, true, 'slides[0]', [])+ for (const w of columnWidths) expect(w).toBeCloseTo(9.2 / 20, 4)+ })+})+describe('clerum__generate_pptx — text stays inside its box', () => {it('keeps a long title clear of the body and the body clear of the footer', async () => {const title = long(24, 'Quarterly')diff --git a/mcp-host/src/workflow/pptxTables.ts b/mcp-host/src/workflow/pptxTables.tsindex 6669cdf57..8d9ddc960 100644--- a/mcp-host/src/workflow/pptxTables.ts+++ b/mcp-host/src/workflow/pptxTables.ts@@ -15,7 +15,10 @@ const CELL_PAD_X = 0.2const EMU = 914400-/** A column never gets narrower than this, even when others need the room. */+/**+ * A column never gets narrower than this, even when others need the room,+ * unless the table has too many columns for every one to have it.+ */const MIN_COLUMN = 0.6export interface TablePage {@@ -60,14 +63,33 @@ function columnWidths(table: PptxTable, width: number, size: number): number[] {floor.push(Math.max(Math.min(longestWord, width * 0.3) + CELL_PAD_X, MIN_COLUMN))}const naturalSum = natural.reduce((a, b) => a + b, 0)- if (naturalSum <= width) return natural.map(w => (w * width) / naturalSum)+ if (naturalSum <= width) return scaledTo(natural, width)const floorSum = floor.reduce((a, b) => a + b, 0)- if (floorSum >= width) return floor.map(w => (w * width) / floorSum)+ if (floorSum >= width) return scaledTo(floor, width)const slack = natural.map((w, c) => Math.max(w - floor[c], 0))const slackSum = slack.reduce((a, b) => a + b, 0)return floor.map((w, c) => w + (slack[c] * (width - floorSum)) / (slackSum || 1))}+/**+ * `widths` scaled to sum to `total`. A column the scaling would leave under+ * MIN_COLUMN gets MIN_COLUMN and the others share the rest; when the columns+ * cannot all have it, they get equal widths.+ */+function scaledTo(widths: number[], total: number): number[] {+ if (widths.length * MIN_COLUMN >= total) return widths.map(() => total / widths.length)+ const pinned = new Set<number>()+ for (;;) {+ const freeSum = widths.reduce((sum, w, i) => (pinned.has(i) ? sum : sum + w), 0)+ const scale = (total - pinned.size * MIN_COLUMN) / freeSum+ const under = widths+ .map((_, i) => i)+ .filter(i => !pinned.has(i) && widths[i] * scale < MIN_COLUMN)+ if (under.length === 0) return widths.map((w, i) => (pinned.has(i) ? MIN_COLUMN : w * scale))+ for (const i of under) pinned.add(i)+ }+}+function rowHeight(cells: string[], widths: number[], size: number, bold: boolean): number {let tallest = 0cells.forEach((cell, c) => {