Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): read nested and numbered bullets a slide cannot show as sent
marcoteb2cda8516fff3
diff --git a/mcp-host/src/workflow/__tests__/pptxInput.test.ts b/mcp-host/src/workflow/__tests__/pptxInput.test.tsnew file mode 100644index 000000000..3b9d38307--- /dev/null+++ b/mcp-host/src/workflow/__tests__/pptxInput.test.ts@@ -0,0 +1,95 @@+/**+ * How the PPTX tool reads the text a model sends before any slide is laid+ * out: lists, enums, KPIs and table cells.+ */+import { describe, expect, it } from 'vitest'+import {+ PptxInputError,+ type ReadContext,+ readEnum,+ readKpis,+ readStringList,+ readTable,+} from '../pptxInput'++const context = (): ReadContext => ({ outputDir: '/nonexistent', warnings: [] })+const list = (value: unknown, ctx = context()) => readStringList(value, 'bullets', 200, ctx)++describe('readStringList', () => {+ it('reads one item per line and drops the bullet a slide prints itself', () => {+ expect(list('- One\n* Two\n\n• Three')).toEqual(['One', 'Two', 'Three'])+ })++ it('takes the numbers off a numbered list and keeps its order', () => {+ expect(list('1. First\n2) Second\n10. Tenth')).toEqual(['First', 'Second', 'Tenth'])+ expect(list(['1. First', '2. Second'])).toEqual(['First', 'Second'])+ })++ it('keeps a number that starts an item when the text is not a list', () => {+ expect(list('2024. A record year')).toEqual(['2024. A record year'])+ expect(list(['2024. A record year', 'Revenue doubled'])).toEqual([+ '2024. A record year',+ 'Revenue doubled',+ ])+ })++ it('sets a nested bullet at the first level and says so', () => {+ const ctx = context()+ expect(list('- Revenue\n - EMEA up 12%\n 1. APAC flat\n- Costs', ctx)).toEqual([+ 'Revenue',+ 'EMEA up 12%',+ 'APAC flat',+ 'Costs',+ ])+ expect(ctx.warnings).toHaveLength(1)+ expect(ctx.warnings[0]).toContain('bullets line 2 is a nested bullet')+ })++ it('names the array entry of a nested bullet', () => {+ const ctx = context()+ list(['Revenue', ' - EMEA up 12%'], ctx)+ expect(ctx.warnings[0]).toContain('bullets[1] is a nested bullet')+ })++ it('does not take indented prose for a nested bullet', () => {+ const ctx = context()+ expect(list('Revenue\n grew in every region', ctx)).toEqual([+ 'Revenue',+ 'grew in every region',+ ])+ expect(ctx.warnings).toEqual([])+ })++ it('refuses a value that is not a list', () => {+ expect(() => list({ a: 1 })).toThrow(PptxInputError)+ })+})++describe('readEnum', () => {+ it('accepts an allowed value and names the field of any other', () => {+ expect(readEnum('a', 'f', ['a', 'b'] as const)).toBe('a')+ expect(readEnum('', 'f', ['a'] as const)).toBeUndefined()+ expect(() => readEnum('c', 'f', ['a', 'b'] as const)).toThrow(+ 'f must be one of a, b; received "c".'+ )+ })+})++describe('readKpis', () => {+ it('requires a value and reads a number as text', () => {+ const ctx = context()+ expect(readKpis([{ label: 'Revenue', value: 48 }], 'kpis', ctx)[0]).toMatchObject({+ label: 'Revenue',+ value: '48',+ })+ expect(() => readKpis([{ label: 'Revenue' }], 'kpis', ctx)).toThrow('kpis[0].value is missing')+ })+})++describe('readTable', () => {+ it('refuses a cell that is an object, naming it', () => {+ expect(() => readTable({ headers: ['A'], rows: [[{ x: 1 }]] }, 'table', context())).toThrow(+ PptxInputError+ )+ })+})diff --git a/mcp-host/src/workflow/pptxInput.ts b/mcp-host/src/workflow/pptxInput.tsindex 57fb686ca..ba401bad1 100644--- a/mcp-host/src/workflow/pptxInput.ts+++ b/mcp-host/src/workflow/pptxInput.ts@@ -171,8 +171,17 @@ export function readText(/** A Markdown list marker, which the slide's own bullet would print twice. */const LIST_MARKER = /^[-*+•]\s+/+/** A numbered list marker; the slide's bullet replaces it and the order stays. */+const ORDERED_MARKER = /^\d{1,9}[.)]\s+/+/** A list item set in from the left: a bullet nested under the one above. */+const NESTED_ITEM = /^[ \t]+(?:[-*+•]|\d{1,9}[.)])\s/-/** A list of text items. One string is read as one item per line. */+/**+ * A list of text items. One string is read as one item per line. Slides show+ * one level of bullets, so a nested item joins the first level, and the result+ * says so. Numbers are taken off only when every item is a list item: a lone+ * "2024. A record year" keeps its year.+ */export function readStringList(value: unknown,where: string,@@ -180,15 +189,36 @@ export function readStringList(ctx: ReadContext): string[] | undefined {if (value === undefined || value === null) return undefined- let items: Array<string | undefined>+ let raw: unknown[]+ let at: (i: number) => stringif (typeof value === 'string') {- items = value.split('\n').map((line, i) => readText(line, `${where} line ${i + 1}`, max, ctx))+ raw = value.split('\n')+ at = i => `${where} line ${i + 1}`} else if (Array.isArray(value)) {- items = value.map((item, i) => readText(item, `${where}[${i}]`, max, ctx))+ raw = value+ at = i => `${where}[${i}]`} else {throw new PptxInputError(`${where} must be a list of text items; received ${describe(value)}.`)}- return items.map(item => item?.replace(LIST_MARKER, '')).filter((item): item is string => !!item)+ const nested = raw.map(item => typeof item === 'string' && NESTED_ITEM.test(item))+ const items = raw+ .map((item, i) => ({ text: readText(item, at(i), max, ctx), nested: nested[i] }))+ .filter((item): item is { text: string; nested: boolean } => !!item.text)+ const marked = (text: string) => LIST_MARKER.test(text) || ORDERED_MARKER.test(text)+ const numbered = items.length > 1 && items.every(item => marked(item.text))+ const first = nested.indexOf(true)+ if (first >= 0) {+ ctx.warnings.push(+ `${at(first)} is a nested bullet; slides show one level of bullets, so it was set at the ` ++ 'first level with the others. Put the detail on its own slide or in the item it belongs to.'+ )+ }+ return items+ .map(({ text, nested }) => {+ const bare = text.replace(LIST_MARKER, '')+ return numbered || nested ? bare.replace(ORDERED_MARKER, '') : bare+ })+ .filter(Boolean)}export function readEnum<T extends string>(