Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(mcp-host): take the PDF page width in the image schema from the layout
marcoteb43419237c732
diff --git a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.tsindex f121a8b72..721121b57 100644--- a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts@@ -567,6 +567,24 @@ describe('PDF images', () => {}})+ it('fills the page with an image as wide as the schema says the page is', async () => {+ const images = (tool.parameters as { properties: Record<string, any> }).properties.images+ const said = /the page is (\d+) wide/.exec(images.items.anyOf[1].properties.width.description)+ const page = Number(said![1])+ writePng('wide.png', 3000, 300)+ const { pages } = await render({+ filename: 'i.pdf',+ body: 'x',+ images: [+ { path: 'wide.png', width: page },+ { path: 'wide.png', width: page * 2 },+ ],+ })+ const widths = pages.flatMap(p => p.images).map(box => box.x1 - box.x0)+ expect(widths).toHaveLength(2)+ for (const width of widths) expect(width).toBeCloseTo(page, 0)+ })+it('keeps a sized image above a footer of several lines', async () => {writePng('tall.png', 200, 3000)const footerText = Array.from({ length: 6 }, (_, i) => `FOOTLINE${i}`).join('\n')diff --git a/mcp-host/src/workflow/documentSchema.ts b/mcp-host/src/workflow/documentSchema.tsindex 03d4d6ed6..5f96693e1 100644--- a/mcp-host/src/workflow/documentSchema.ts+++ b/mcp-host/src/workflow/documentSchema.ts@@ -6,6 +6,9 @@/** Footer lines that fit once the bottom margin has grown to hold them. */export const PDF_MAX_FOOTER_LINES = 6+/** Points between the side margins of a portrait A4 page, where every image is placed. */+export const PDF_PORTRAIT_WIDTH = 515+/** Where images come from, for the schema: the name clerum__generate_chart reports. */export const IMAGE_FILE_DESCRIPTION ="File name of a PNG or JPEG (GIF, WebP and SVG are converted) in the output folder, as returned by clerum__generate_chart, e.g. 'sales.png'."diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.tsindex 469a0b4cc..b634abebc 100644--- a/mcp-host/src/workflow/internalTools.ts+++ b/mcp-host/src/workflow/internalTools.ts@@ -45,6 +45,7 @@ import {DOCX_IMAGE_FILE_DESCRIPTION,IMAGE_FILE_DESCRIPTION,PDF_MAX_FOOTER_LINES,+ PDF_PORTRAIT_WIDTH,} from './documentSchema'import {NATIVE_CHART_TYPES,@@ -438,7 +439,7 @@ const generatePdf: InternalToolDefinition = {path: { type: 'string', description: IMAGE_FILE_DESCRIPTION },width: {type: 'number',- description: 'Width in points (the page is 515 wide); the height follows.',+ description: `Width in points (the page is ${PDF_PORTRAIT_WIDTH} wide); the height follows.`,},height: {type: 'number',diff --git a/mcp-host/src/workflow/pdfTables.ts b/mcp-host/src/workflow/pdfTables.tsindex 745092ecf..f91f61ce4 100644--- a/mcp-host/src/workflow/pdfTables.ts+++ b/mcp-host/src/workflow/pdfTables.ts@@ -7,6 +7,7 @@* cell instead, and the type size or the page orientation gives way before a* table has to do that to ordinary words.*/+import { PDF_PORTRAIT_WIDTH } from './documentSchema'/** Width of `text` at 1pt in the body face; widths scale linearly with size. */export type UnitMeasure = (text: string, bold: boolean) => number@@ -43,7 +44,7 @@ export interface TableLayout {}/** A4 content boxes with the documents' 40pt side and 60pt top margins and the smallest bottom one. */-export const PORTRAIT: PageBox = { width: 515, height: 722 }+export const PORTRAIT: PageBox = { width: PDF_PORTRAIT_WIDTH, height: 722 }export const LANDSCAPE: PageBox = { width: 762, height: 475 }export const MIN_BOTTOM_MARGIN = 60