Skip to content

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

TypeScript

fix(mcp-host): set a long KPI value smaller before shortening it

marcoteb3a81e28e832e
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts
index 6333c6329..c10214ca9 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts
@@ -262,6 +262,33 @@ describe('clerum__generate_pptx — text stays inside its box', () => {
expect(need).toBeLessThanOrEqual((value.sizes[0] * 1.2) / 72 + 1e-3)
})
+ it('sets a long KPI value smaller rather than cutting it when a smaller size fits', async () => {
+ // Under the 80-character limit on a KPI value, too long for the shared size.
+ const status = 'On track in every region after the migration, last two markets in May'
+ const result = await generatePptx(
+ {
+ filename: 'kwrap.pptx',
+ slides: [
+ {
+ layout: 'kpis',
+ title: 'KPIs',
+ kpis: [
+ { label: 'Revenue', value: '$1.2M' },
+ { label: 'Status', value: status },
+ ],
+ },
+ ],
+ },
+ outputDir
+ )
+ expect(result.success, result.error).toBe(true)
+ expect(result.content ?? '').not.toMatch(/kpis\[1\]\.value is too long/)
+ const xml = slideXml(path.join(outputDir, 'kwrap.pptx'), 1)
+ const shown = shapeWithText(xml, 'On track')
+ expect(shown.paragraphs.join(' ').replace(/\s+/g, ' ')).toBe(status)
+ expect(shown.sizes[0]).toBeLessThan(shapeWithText(xml, '$1.2M').sizes[0])
+ })
+
it('sets every KPI value on a slide at one size and centres a short last row', async () => {
const values = ['1%', '2%', '$1,234,567.89', '4%', '5%']
const result = await generatePptx(
diff --git a/mcp-host/src/workflow/pptxDeck.ts b/mcp-host/src/workflow/pptxDeck.ts
index 882dfd7b5..d5e0942b3 100644
--- a/mcp-host/src/workflow/pptxDeck.ts
+++ b/mcp-host/src/workflow/pptxDeck.ts
@@ -819,6 +819,8 @@ interface CardType {
/** Room above the value, the same on every card so the values line up. */
labelHeight: number
valueSize: number
+ /** The value sizes, largest first; a value that wraps may take a smaller one than valueSize. */
+ valueSizes: number[]
}
const LABEL_SIZES = [11, 10, 9]
@@ -861,7 +863,7 @@ function cardType(cards: PptxKpi[], cardW: number, columns: number, people: bool
(oneLine.length > 0 &&
valueSizes.find(size => oneLine.every(c => textWidth(c.value, size, true) <= inner))) ||
smallest
- return { labelSize, labelHeight, valueSize }
+ return { labelSize, labelHeight, valueSize, valueSizes }
}
function drawCard(
@@ -932,11 +934,12 @@ function drawCard(
)
y += h
} else {
- // A value that wraps keeps the size of the other cards' values and stops above the delta.
+ // A value that wraps keeps the size of the other cards' values when it fits
+ // above the delta there, and takes a smaller one before it is shortened.
const value = fitOrShorten(
card.value,
{ w, h: bottom - y },
- [size],
+ type.valueSizes.filter(s => s <= size),
`${card.where}.value`,
ctx.warnings,
{ bold: true }
@@ -945,7 +948,7 @@ function drawCard(
slide,
value.text,
{ x, y, w, h: value.height },
- { fontSize: size, bold: true, color: hex(p.primary) }
+ { fontSize: value.size, bold: true, color: hex(p.primary) }
)
y += value.height
}