feat(service-ai): visualize_data tool — return charts from AI data queries#1820
Merged
Conversation
…eries Adds a `visualize_data` AI tool so the data-query assistant can answer with a CHART instead of plain text/markdown. The tool runs an aggregation through the existing analytics service (auto-inferred cube), maps the result into the SDUI `<chart>` contract, and emits it to the client as a `data-chart` custom stream part (same onProgress → Vercel UI-message-stream channel that `data-build-progress` already uses). It also returns a compact textual summary so the model narrates the answer alongside the rendered chart. - tools/visualize-data.tool.ts: VISUALIZE_DATA_TOOL + handler + register fn. function+field → analytics measure key (count / <field>_sum / …); single dimension → x-axis; measures → series; chartType (bar/line/pie/…). - plugin.ts: register when an analytics service is present; persist as tool metadata in lockstep (Studio visibility). - skills/data-explorer-skill.ts: expose visualize_data + chart trigger phrases and guidance to prefer it for "chart/plot/trend/breakdown" requests. Frontend rendering lands in objectui (plugin-chatbot). Verified end-to-end in the console against a live LLM: AI picks visualize_data → analytics aggregates → data-chart part → bar chart renders in the chat bubble. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lets the AI data-query assistant answer with a chart instead of only text. Adds a
visualize_datatool that aggregates a data object via the existing analytics service and streams the result to the client as adata-chartpart for inline rendering.The frontend half (rendering the
data-chartpart in the chat bubble) is a companion PR in objectui (plugin-chatbot).How
tools/visualize-data.tool.ts—VISUALIZE_DATA_TOOL+ handler +registerVisualizeDataTool. Maps the tool args (objectName,dimension,measures[{function,field}],chartType,where) into anAnalyticsQuery(auto-inferred cube;function+field→ measure keycount/<field>_sum/…), runsIAnalyticsService.query, shapes rows into the SDUI<chart>contract (chartType,data,xAxisKey,series), and emitsctx.onProgress({ type: 'data-chart', id, data }). Returns a compact JSON summary so the model narrates.plugin.ts— registers the tool when ananalyticsservice is present; persists it astoolmetadata in lockstep (Studio visibility).skills/data-explorer-skill.ts— exposesvisualize_data, adds chart trigger phrases, and instructs the agent to prefer it for "chart/plot/trend/breakdown" asks.Reuses the same
onProgress→ Vercel UI-message-streamdata-*channel thatdata-build-progressalready uses — no protocol/contract changes.Testing
visualize-data.tool.test.ts(5 tests) — measure-key mapping,wherepass-through, default chartType,data-chartpayload shape, error path.visualize_data→ analytics auto-infers a cube forshowcase_taskbystatus→data-chartpart → a 5-bar chart renders in the console chat bubble.🤖 Generated with Claude Code