Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): let the workflow path reach the repairs the generators make
marcotebc3e04e83c536
diff --git a/mcp-host/src/workflow/__tests__/internalTools.dashboard.contract.test.ts b/mcp-host/src/workflow/__tests__/internalTools.dashboard.contract.test.tsindex 49e1f4aa8..003348555 100644--- a/mcp-host/src/workflow/__tests__/internalTools.dashboard.contract.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.dashboard.contract.test.ts@@ -333,7 +333,7 @@ describe('dashboard schema rejects what cannot render, with the field to fix', (describe('dashboard schema size', () => {it('stays compact, since every model request carries it', () => {- expect(JSON.stringify(dashboardTool().parameters).length).toBeLessThan(13_250)+ expect(JSON.stringify(dashboardTool().parameters).length).toBeLessThan(13_600)})it('points repeated shapes at the field that documents them', () => {diff --git a/mcp-host/src/workflow/__tests__/internalTools.docx.test.ts b/mcp-host/src/workflow/__tests__/internalTools.docx.test.tsindex f9b3ae0e6..ad04be39f 100644--- a/mcp-host/src/workflow/__tests__/internalTools.docx.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.docx.test.ts@@ -576,14 +576,24 @@ describe('generate_docx schema', () => {expect(result.isError, JSON.stringify(result.content)).toBeFalsy()})- it('rejects a row that is not an array with a message naming the field', async () => {+ it('reads rows sent as records by header name, and says so', async () => {const { result } = await router().callTool('clerum__generate_docx', {filename: 'w.docx',body: 'x',tables: [{ headers: ['A'], rows: [{ A: 1 }] }],})+ expect(result.isError, JSON.stringify(result.content)).toBeFalsy()+ expect(JSON.stringify(result.content)).toContain('were objects and were read by header name')+ })++ it('rejects a row that is neither an array nor a record, naming the field', async () => {+ const { result } = await router().callTool('clerum__generate_docx', {+ filename: 'w.docx',+ body: 'x',+ tables: [{ headers: ['A'], rows: ['A1'] }],+ })expect(result.isError).toBe(true)- expect((result.content as { error: string }).error).toContain('tables/0/rows/0 must be array')+ expect((result.content as { error: string }).error).toContain('tables/0/rows/0')})it('describes image paths as the file names generate_chart returns', () => {diff --git a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.tsindex 330735ac7..65456d3e9 100644--- a/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.pdf.layout.test.ts@@ -689,14 +689,14 @@ describe('PDF arguments on the workflow path', () => {expect(result.isError).toBeFalsy()})- it('rejects rows sent as records with the path of the row to fix', async () => {+ it('reads rows sent as records by header name, and says so', async () => {const { result } = await router().callTool('clerum__generate_pdf', {filename: 'o.pdf',body: 'x',tables: [{ headers: ['Name'], rows: [{ Name: 'a' }] }],})- expect(result.isError).toBe(true)- expect((result.content as { error?: string }).error).toMatch(/tables\/0\/rows\/0 must be array/)+ expect(result.isError, JSON.stringify(result.content)).toBeFalsy()+ expect(JSON.stringify(result.content)).toContain('were objects and were read by header name')})})diff --git a/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts b/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.tsindex 37f4e0148..6d9cb3cf6 100644--- a/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.schemaAjv.test.ts@@ -321,6 +321,78 @@ const ACCEPTED: Array<[string, string, Record<string, unknown>]> = ['clerum__generate_markdown',{ filename: 'n.md', content: ['# Title', 'body'] },],+ [+ 'PDF table rows sent as records',+ 'clerum__generate_pdf',+ {+ filename: 'r.pdf',+ body: 'x',+ tables: [{ headers: ['Name', 'Qty'], rows: [{ Name: 'Widget', Qty: 3 }] }],+ },+ ],+ [+ 'DOCX table rows sent as records',+ 'clerum__generate_docx',+ {+ filename: 'r.docx',+ body: 'x',+ tables: [{ headers: ['Name', 'Qty'], rows: [{ Name: 'Widget', Qty: 3 }] }],+ },+ ],+ [+ 'XLSX rows sent as records',+ 'clerum__generate_xlsx',+ { filename: 'r.xlsx', sheets: [{ name: 'S', rows: [{ Name: 'Widget', Qty: 3 }] }] },+ ],+ [+ 'PPTX table rows sent as records',+ 'clerum__generate_pptx',+ {+ filename: 'r.pptx',+ slides: [+ {+ layout: 'title-table',+ title: 'T',+ table: { headers: ['Name', 'Qty'], rows: [{ Name: 'Widget', Qty: 3 }] },+ },+ ],+ },+ ],+ [+ 'dashboard table rows sent as records, and [x, y] points',+ 'clerum__generate_dashboard',+ {+ filename: 'd.html',+ data: {+ title: 'T',+ tables: [{ headers: ['Name', 'Qty'], rows: [{ Name: 'Widget', Qty: 3 }] }],+ charts: [+ {+ type: 'scatter',+ datasets: [+ {+ data: [+ [1, 2],+ [3, 4],+ ],+ },+ ],+ },+ ],+ },+ },+ ],+ [+ 'chart values as {label, value} with text, and {x, y} with a category x',+ 'clerum__generate_chart',+ {+ filename: 'c.png',+ type: 'bar',+ data: {+ datasets: [{ data: [{ label: 'Q1', value: '1,200' }] }, { data: [{ x: 'Jan', y: 5 }] }],+ },+ },+ ],['a numeric PPTX KPI','clerum__generate_pptx',@@ -375,6 +447,13 @@ describe('internal tool schemas accept what the runtimes handle, on the workflow})).not.toBe(true)expect(await accepts('clerum__generate_pdf', { body: 'x' })).not.toBe(true)+ expect(+ await accepts('clerum__generate_pdf', {+ filename: 'r.pdf',+ body: 'x',+ tables: [{ headers: ['Name'], rows: [{ Name: { nested: true } }] }],+ })+ ).not.toBe(true)expect(await accepts('clerum__generate_dashboard', {filename: 'd.html',@@ -391,13 +470,6 @@ describe('internal tool schemas accept what the runtimes handle, on the workflowexpect(await accepts('clerum__generate_markdown', { filename: 'n.md', content: { text: 'x' } })).not.toBe(true)- expect(- await accepts('clerum__generate_pdf', {- filename: 'r.pdf',- body: 'x',- tables: [{ headers: ['A'], rows: [{ A: 1 }] }],- })- ).not.toBe(true)expect(await accepts('clerum__generate_pdf', {filename: 'r.pdf',diff --git a/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts b/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.tsindex 0524beb82..e3ef061fe 100644--- a/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.schemaBudget.test.ts@@ -11,9 +11,9 @@ const BUDGET: Record<string, number> = {clerum__generate_pdf: 3800,clerum__generate_docx: 3200,clerum__generate_xlsx: 5400,- clerum__generate_pptx: 16500,+ clerum__generate_pptx: 16600,clerum__generate_chart: 4300,- clerum__generate_dashboard: 14000,+ clerum__generate_dashboard: 14100,clerum__list_workflows: 500,clerum__read_workflow: 650,clerum__trigger_workflow: 1000,diff --git a/mcp-host/src/workflow/__tests__/internalTools.schemaGemini.test.ts b/mcp-host/src/workflow/__tests__/internalTools.schemaGemini.test.tsindex e8170489e..2968a2ec6 100644--- a/mcp-host/src/workflow/__tests__/internalTools.schemaGemini.test.ts+++ b/mcp-host/src/workflow/__tests__/internalTools.schemaGemini.test.ts@@ -136,7 +136,10 @@ describe('internal tools, as the Gemini driver actually sends them', () => {const xlsx = decls.find(d => d.name === 'clerum__generate_xlsx')!const sheets = (xlsx.parameters.properties as Json).sheets as Jsonconst rows = ((sheets.items as Json).properties as Json).rows as Json- const cell = (rows.items as Json).items as Json+ // A row is an array of cells, or a record read by header name.+ const shapes = (rows.items as Json).anyOf as Json[]+ expect(shapes.map(b => b.type).sort()).toEqual(['ARRAY', 'OBJECT'])+ const cell = shapes.find(b => b.type === 'ARRAY')!.items as Jsonexpect(cell.nullable).toBe(true)expect((cell.anyOf as Json[]).map(b => b.type).sort()).toEqual(['BOOLEAN', 'NUMBER', 'STRING'])})diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.tsindex 9db1f5554..ec378f42f 100644--- a/mcp-host/src/workflow/internalTools.ts+++ b/mcp-host/src/workflow/internalTools.ts@@ -776,14 +776,25 @@ function resolveChartType(// into its own schema — and never as `oneOf`, which it passes through// untranslated for the Gemini API to reject. Every array declares `items`.-/** A table or sheet cell. Each runtime stringifies or formats what arrives. */-const CELL_SCHEMA = {- type: ['string', 'number', 'boolean', 'null'],- description: 'Text, a number, true/false, or null for an empty cell.',+/**+ * The types of a table or sheet cell: text, a number, true/false, or null for+ * an empty cell. Each runtime stringifies or formats what arrives.+ */+const CELL_TYPES = ['string', 'number', 'boolean', 'null']++/**+ * A row sent as a {header: cell} record, which every runtime reads by header+ * name. Gemini rejects an object schema with no properties, so it declares one+ * example key; additionalProperties keeps the others valid.+ */+const RECORD_ROW_SCHEMA = {+ type: 'object',+ properties: { '0': { type: CELL_TYPES, description: 'Cell.' } },+ additionalProperties: { type: CELL_TYPES },}-/** One row of cells, left to right in header order. */-const ROW_SCHEMA = { type: 'array', items: CELL_SCHEMA }+/** One row of cells, left to right in header order, or a record. */+const ROW_SCHEMA = { anyOf: [{ type: 'array', items: { type: CELL_TYPES } }, RECORD_ROW_SCHEMA] }/** A single color, or one per data point. */function colorSchema(what: string): Record<string, unknown> {@@ -796,8 +807,8 @@ function colorSchema(what: string): Record<string, unknown> {/*** One chart data point. Numbers are the norm; the rest are shapes models send* that normalizeChartData repairs or needs — text such as "1,200", null for a- * gap, {x, y[, r]} or [x, y[, r]] for scatter and bubble, and {label, value}- * records or [label, value] pairs.+ * gap, {x, y[, r]} or [x, y[, r]] for scatter and bubble, {x, y} with a+ * category x, and {label, value} records or [label, value] pairs.*/const CHART_POINT_SCHEMA = {anyOf: [@@ -808,11 +819,11 @@ const CHART_POINT_SCHEMA = {{type: 'object',properties: {- x: { type: 'number', description: 'X value.' },+ x: { type: ['number', 'string'], description: 'X value.' },y: { type: 'number', description: 'Y value.' },r: { type: 'number', description: 'Bubble radius (px).' },label: { type: 'string', description: 'Category.' },- value: { type: 'number', description: 'Value.' },+ value: { type: ['number', 'string'], description: 'Value.' },},},],@@ -3223,9 +3234,14 @@ const generateXlsx: InternalToolDefinition = {description:'Rows of cells; the first is the header row unless headers is given. [] for an images-only sheet.',items: {- type: 'array',- description: 'One row, left to right.',- items: XLSX_CELL_SCHEMA,+ anyOf: [+ {+ type: 'array',+ description: 'One row, left to right.',+ items: XLSX_CELL_SCHEMA,+ },+ RECORD_ROW_SCHEMA,+ ],},},titleRow: {@@ -5108,18 +5124,22 @@ const DASH_KPI_SCHEMA = {}const XYR_PROPERTIES = {- x: { type: 'number', description: 'X.' },+ x: { type: ['number', 'string'], description: 'X.' },y: { type: 'number', description: 'Y.' },- r: { type: 'number', description: 'Bubble radius (px).' },+ r: { type: 'number', description: 'Radius (px).' },}-/** One chart value: a number, text such as "1,200", null for a gap, or an object. */+/**+ * One chart value: a number, text such as "1,200", null for a gap, an [x, y]+ * or [label, value] pair, or an object.+ */function dashPoint(objectProperties: Record<string, unknown>): Record<string, unknown> {return {anyOf: [{ type: 'number' },{ type: 'string' },{ type: 'null' },+ { type: 'array', items: { type: ['number', 'string'] } },{ type: 'object', properties: objectProperties },],}@@ -5129,7 +5149,7 @@ function dashPoint(objectProperties: Record<string, unknown>): Record<string, unconst DASH_POINT_SCHEMA = dashPoint({...XYR_PROPERTIES,label: { type: 'string', description: 'Category.' },- value: { type: 'number', description: 'Value.' },+ value: { type: ['number', 'string'], description: 'Value.' },})function dashColor(what: string): Record<string, unknown> {@@ -5440,18 +5460,8 @@ const generateDashboardTool: InternalToolDefinition = {headers: DASH_TABLE_SCHEMA.properties.headers,rows: {type: 'array',- items: {- anyOf: [- { type: 'array', items: { type: CELL_SCHEMA.type } },- {- type: 'object',- // As columnTypes: one example key, the rest by additionalProperties.- properties: { '0': { type: CELL_SCHEMA.type, description: 'Cell.' } },- additionalProperties: { type: CELL_SCHEMA.type },- },- ],- },- description: 'As data.tables[], or {header: cell}.',+ items: ROW_SCHEMA,+ description: 'As data.tables[].',},},description: 'chart: as data.charts[]; table: as data.tables[].',@@ -5556,10 +5566,10 @@ const generateDashboardTool: InternalToolDefinition = {// the schema goes out with every request and JSON Schema $ref is not portable.const PPTX_IMAGE_PATH_DESCRIPTION =- "Image file name in the output folder, as clerum__generate_chart returns it (e.g. 'sales.png'). " ++ "Image file name in the output folder, e.g. from clerum__generate_chart ('sales.png'). " +'PNG, JPEG, GIF, WebP or SVG.'-const PPTX_PATH_SHORT = 'File name, as clerum__generate_chart returns it.'+const PPTX_PATH_SHORT = 'File name from clerum__generate_chart.'/** An array of short texts, or one string read as one item per line. */function pptxTextList(description: string): Record<string, unknown> {@@ -5622,11 +5632,7 @@ function pptxTable(description: string, headers: string, rows: string): Record<sdescription,properties: {headers: { type: 'array', items: { type: ['string', 'number'] }, description: headers },- rows: {- type: 'array',- items: { type: 'array', items: { type: ['string', 'number', 'boolean', 'null'] } },- description: rows,- },+ rows: { type: 'array', items: ROW_SCHEMA, description: rows },},}}@@ -5641,7 +5647,7 @@ const PPTX_CHART_POINT_SCHEMA = {type: 'object',properties: {label: { type: 'string', description: 'Category.' },- value: { type: 'number', description: 'Value.' },+ value: { type: ['number', 'string'], description: 'Value.' },},},],@@ -5685,7 +5691,7 @@ const PPTX_CHART_SCHEMA = {path: {type: 'string',description:- "Chart image file name, as clerum__generate_chart returns it (e.g. 'sales.png'), for " ++ "Chart image file name from clerum__generate_chart (e.g. 'sales.png'), for " +'types the native list lacks. Native data given too is drawn if the file cannot be used.',},type: {