Skip to content

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

TypeScript

fix(mcp-host): keep emoji whole in XLSX and PPTX files over 16K characters

marcoteb1a2e3f2451f6
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 902cee999..6333c6329 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.pptx.layout.test.ts
@@ -574,6 +574,35 @@ describe('clerum__generate_pptx — slide XML', () => {
})
})
+describe('clerum__generate_pptx — characters outside the BMP', () => {
+ it('writes every emoji whole in slides larger than 16K characters', async () => {
+ // Each slide of this table runs past 16,384 characters with emoji at the mark.
+ const cell = '\u{1F600}'.repeat(240)
+ const result = await generatePptx(
+ {
+ filename: 'e.pptx',
+ slides: [
+ {
+ layout: 'title-table',
+ title: 'T',
+ table: {
+ headers: ['A', 'B', 'C', 'D', 'E'],
+ rows: Array.from({ length: 12 }, () => [cell, cell, cell, cell, cell]),
+ },
+ },
+ ],
+ },
+ outputDir
+ )
+ expect(result.success, result.error).toBe(true)
+ const file = result.artifact!.path
+ const xml = Array.from({ length: slideCount(file) }, (_, i) => slideXml(file, i + 1)).join('')
+ expect(xml.length).toBeGreaterThan(16_384)
+ expect(xml).not.toContain('\uFFFD')
+ expect(xml.match(/\u{1F600}/gu)).toHaveLength(12 * 5 * 240)
+ })
+})
+
describe('clerum__generate_pptx — scripts other than Latin', () => {
it('tags Chinese, Japanese and Korean runs with their language', async () => {
const result = await generatePptx(
diff --git a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
index 0447e878e..c208192db 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.xlsx.values.test.ts
@@ -179,6 +179,21 @@ describe('numbers reach the sheet as numbers', () => {
})
})
+describe('characters outside the BMP', () => {
+ it('writes every emoji whole, wherever it falls in the shared strings', async () => {
+ // 9,000 emoji are 18,000 UTF-16 units, so one straddles the 16,384 mark.
+ const text = '\u{1F600}'.repeat(9000)
+ const result = await generate({
+ filename: 'e.xlsx',
+ sheets: [{ name: 'E', rows: [['Emoji'], [text]] }],
+ })
+ expect(result.success, result.error).toBe(true)
+ const shared = zipEntryText(result.artifact!.path, 'xl/sharedStrings.xml')
+ expect(shared).not.toContain('\uFFFD')
+ expect(shared).toContain(text)
+ })
+})
+
describe('column formats', () => {
it('reads 0-100 values in a percent column as percentage points', async () => {
const { ws } = await oneSheet([
diff --git a/mcp-host/src/workflow/pptxDeck.ts b/mcp-host/src/workflow/pptxDeck.ts
index 99a192b34..ed003f473 100644
--- a/mcp-host/src/workflow/pptxDeck.ts
+++ b/mcp-host/src/workflow/pptxDeck.ts
@@ -37,6 +37,7 @@ import {
truncateToLines,
wrapLines,
} from './pptxText'
+import { keepZipTextWhole } from './zipText'
const PptxGenJS = require('pptxgenjs')
@@ -1415,6 +1416,7 @@ export async function buildPptxDeck(
const unique = [...new Set(warnings)]
warnings.splice(0, warnings.length, ...unique)
+ keepZipTextWhole()
const buffer = (await pptx.write({ outputType: 'nodebuffer' })) as Buffer
return { buffer: await withOnePropertiesPerParagraph(buffer), slides: planned.length }
}
diff --git a/mcp-host/src/workflow/xlsxWorkbook.ts b/mcp-host/src/workflow/xlsxWorkbook.ts
index 53d3a7c84..72895623a 100644
--- a/mcp-host/src/workflow/xlsxWorkbook.ts
+++ b/mcp-host/src/workflow/xlsxWorkbook.ts
@@ -42,6 +42,7 @@ import {
sheetTable,
tableWidth,
} from './xlsxSheet'
+import { keepZipTextWhole } from './zipText'
interface XlsxPalette {
// ARGB hex (no leading '#'), 8 chars: AA RR GG BB
@@ -898,6 +899,7 @@ export async function buildXlsxWorkbook(
(warnings.length > 0 ? ` Details: ${warnings.join(' ')}` : ''),
}
}
+ keepZipTextWhole()
const raw = (await workbook.xlsx.writeBuffer()) as unknown as ArrayBufferView
return {
ok: true,
diff --git a/mcp-host/src/workflow/zipText.ts b/mcp-host/src/workflow/zipText.ts
new file mode 100644
index 000000000..0d2dba673
--- /dev/null
+++ b/mcp-host/src/workflow/zipText.ts
@@ -0,0 +1,29 @@
+/**
+ * Text parts of the Office packages the generators write, kept whole.
+ */
+import JSZip from 'jszip'
+
+let whole = false
+
+/**
+ * JSZip encodes a string it is handed to UTF-8 in chunks of 16K characters, so
+ * a character outside the BMP, such as an emoji, that straddles a chunk edge is
+ * written as two U+FFFD. ExcelJS and pptxgenjs hand it their XML as strings.
+ * From the first call on, a text string is handed over as its UTF-8 bytes,
+ * which are what JSZip writes for it when nothing is split. Set when a package
+ * is written, so importing this module changes nothing.
+ */
+export function keepZipTextWhole(): void {
+ if (whole) return
+ whole = true
+ const proto = JSZip.prototype as unknown as { file: (...args: unknown[]) => unknown }
+ const file = proto.file
+ proto.file = function (this: unknown, ...args: unknown[]) {
+ const [name, data, options] = args
+ const binary = options as { binary?: boolean; base64?: boolean } | undefined
+ if (args.length > 1 && typeof data === 'string' && !binary?.binary && !binary?.base64) {
+ return file.call(this, name, Buffer.from(data, 'utf8'), options)
+ }
+ return file.apply(this, args)
+ }
+}