feat(core): export chart validation from flint-chart - #113
feat(core): export chart validation from flint-chart#113Wei Tao (taoche) wants to merge 4 commits into
Conversation
Move the validate/assemble logic that lived only inside flint-chart-mcp into the core package as `flint-chart/validate` (also re-exported from the root). Hosts that let an agent author ChartAssemblyInput outside MCP can now call validateChart(input, backend) and get the same per-problem feedback the validate_chart tool provides, without vendoring MCP sources. - validateChart / validateChartInput / assembleForBackend / stripPrivateKeys - validateSemanticTypes: unregistered semantic_types labels, surfaced by validateChart as unknown_semantic_type warnings - isRegistered / getRegisteredTypes exported from flint-chart/core - flint-chart-mcp now consumes the core implementation; it only adds data.url resolution on top Co-Authored-By: Claude Code <noreply@anthropic.com>
- validateSemanticTypes returns ChartWarning[] directly instead of a separate issue shape that validateChart then re-mapped - drop the MCP-side re-check of data.values that only existed to word the error differently; core message is now host-neutral - MCP reuses core ValidateResult and a single CAPS constant Co-Authored-By: Claude Code <noreply@anthropic.com>
validateData / validateEncodings / validateEncodingsAgainstTemplate / validateCanvasCaps replace one 45-line function and the `any` casts with an isRecord type guard. Tests now cover one scenario each, plus unknown backend, non-array values, and template skipping for unknown chart types. Co-Authored-By: Claude Code <noreply@anthropic.com>
Hosts that bypass the MCP data-source layer previously got a misleading "field does not exist" (or a TypeError) for non-object rows, and silently accepted data carrying both values and url. Both checks now live in validateChartInput, matching what resolveDataSource already enforces. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Validated this against the real host that motivated #104 (an LLM agent authoring Setup: Result: typecheck + lint clean, and all 17 of the host's FlintChart validation tests pass unchanged — unknown chart type, nonexistent field, unsupported channel, missing required channel, unregistered One gap it surfaced (fixed in 300bf80): the vendored copy had pulled two checks out of Also worth noting for the semantic-types half of the issue: the host wants unregistered labels to be a hard error (an agent writing |
|
@microsoft-github-policy-service agree |
Closes #104
Summary
Moves the validate/assemble logic that lived only inside
flint-chart-mcp(src/tools/validate.ts,src/render/assemble.ts) into the core package as a newflint-chart/validatesubpath (also re-exported from the rootflint-chart). Hosts that let an agent authorChartAssemblyInputoutside MCP can now callvalidateChart(input, backend)and get the same per-problem feedback thevalidate_charttool provides, instead of vendoring MCP sources.Exported from
flint-chart/flint-chart/validatevalidateChart(input, backend, options?)— never throwsvalidateChartInput(input, backend?, options?)— shape checks, throws on first problemvalidateSemanticTypes(semantic_types)— labels not in the type registry;validateChartsurfaces these asunknown_semantic_typewarnings (not errors), sovalidis unaffectedassembleForBackend(backend, input, options?),stripPrivateKeys(spec)ValidationBackend(vegalite | echarts | chartjs | plotly),ValidateChartOptions(maxDataRows,maxCanvasDim),ValidateResult,AssembleResultAlso
isRegistered/getRegisteredTypesexported fromflint-chart/coreflint-chart-mcpnow consumes the core implementation; it only addsdata.urlresolution on top (render/assemble.tsshrinks to ~80 lines). Public MCP surface (validateInput,assembleForBackend,stripPrivateKeys,MAX_DATA_ROWS,MAX_CANVAS_DIM,validate_chartoutput) is unchanged.packages/flint-js/README.md,docs/api-reference.md(en + zh-CN), CHANGELOG[Unreleased]Design notes
src/validate/rather thancore/because validation needs the backend assemblers and template registries, andcore/is intentionally backend-free.data.valuesand stays pure JS (no fs). Localdata.urlreading remains an MCP concern.plotlyis included as a validation backend since it has an assembler and template registry, even though MCP can't render it.Test plan
npm run typecheck(flint-js + flint-mcp)npm run lint— no new warningsnpm run test:js— 1501 passed (incl. 17 new intests/validate.test.ts)npm run test:mcp— 85 passed (existingvalidate_charttests unchanged)🤖 Generated with Claude Code