Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@djbarnwal
Copy link
Member

@djbarnwal djbarnwal commented Oct 12, 2025

Adds tool create_chart for embedding charts into AI chat.

Further -

  • Moves "go to explore" button and associated logic to features/explores
  • Add title and go to explore button capability for ChartContainer
  • More narrow types for chart fields for different chart types

TODO

  • Disable create_chart for external MCP clients

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@djbarnwal djbarnwal marked this pull request as ready for review October 14, 2025 23:06
@djbarnwal djbarnwal self-assigned this Oct 14, 2025
}

// Check if this property is a field config object
if (isFieldConfig(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g., maybe here's an opportunity for a guard clause

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFieldConfig has a type guard clause built in

timeZone: chartSpec.time_range.time_zone || "UTC",
}
: {
start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), // Default to last 30 days
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: comment says 30 days but the code says 7

spec: CartesianChartSpec & TimeRange;
}
| { chart_type: "donut_chart"; spec: CircularChartSpec & TimeRange }
| { chart_type: "pie_chart"; spec: CircularChartSpec & TimeRange }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't see pie_chart in the backend prompts. Should it be?

Copy link
Member Author

@djbarnwal djbarnwal Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

donut_chart and pie_chart are the same. We moved from pie_chart keyword in favor of donut. We still keep pie_chart for backward compatibility.

Comment on lines 59 to 61
toolResult &&
!toolResult.isError &&
block.toolCall.name === "create_chart" &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe bake these checks into isChartToolResult? Else this conditional is a bit hard-to-read.

}
// Group tool calls with their results within this message
function groupToolCallsWithResults(content: any[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is now more complex, it's further motivation to move this data processing into the Conversation class. I suppose it doesn't need to happen in this PR, but calling it out. For this PR, could you try to reduce the layers of nesting? Any efforts to make this function a bit easier to follow would be appreciated.

@djbarnwal djbarnwal requested a review from ericpgreen2 October 15, 2025 22:53
Copy link
Contributor

@ericpgreen2 ericpgreen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with comments. Great to see this come together!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I think this would better be placed in the runtime/metricsview directory. Here's Claude's thoughts:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's some Claude feedback on the chart tool prompt:
image
image

Comment on lines +30 to +44
$: timeAndFilterStore = readable({
timeRange: timeRange,
comparisonTimeRange: undefined,
showTimeComparison: false,
where: chartSpec.where || {
cond: {
op: "OPERATION_AND",
exprs: [],
},
},
timeGrain: chartSpec.time_grain || "TIME_GRAIN_DAY",
timeRangeState: undefined,
comparisonTimeRangeState: undefined,
hasTimeSeries: true,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to explain this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's tailored for time series charts. What about charts without a time series?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeAndFilterStore is a object representation of our time picker and filter bar UI.

It is required for all charts as well as all other components that we offer. The component make their own queries. As such, they need a time range and filter expression for filtering down the data.

There are some properties which are only relevant to time series which is timeGrain. Otherwise, most of it is used across components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I was thrown by hasTimeSeries: true. Does that need to be a derivative of the chart spec?

djbarnwal and others added 3 commits October 22, 2025 20:21
* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>
@djbarnwal djbarnwal merged commit 8a3b7ea into main Oct 24, 2025
12 checks passed
@djbarnwal djbarnwal deleted the feat/viz-in-chat branch October 24, 2025 10:42
djbarnwal added a commit that referenced this pull request Oct 24, 2025
* refac: pull out metric view selectors from canvas spec

* lint fix

* separate out chart component from canvas

* move chart utils, methods, config to feature/component

* move chart specs and builder

* move canvas chart components

* move timeAndFilter

* ChartSpec name refactor

* update conflict var names

* remove dev route

* remove comments

* add  tool to AI chat

* add go to explore button, update prompt

* viz improvements

* improve prompt

* add chart schema

* update prompt

* add where and time_grain to gen

* move to basic schema validation

* remove temp file

* remove old validation code

* lint fix

* review

* Disable the `create_chart` tool in external MCP connections (#8143)

* review comments

* Adds `chat_charts` feature flag for the `create_chart` tool (#8159)

* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
kaspersjo pushed a commit that referenced this pull request Oct 28, 2025
* refac: pull out metric view selectors from canvas spec

* lint fix

* separate out chart component from canvas

* move chart utils, methods, config to feature/component

* move chart specs and builder

* move canvas chart components

* move timeAndFilter

* ChartSpec name refactor

* update conflict var names

* remove dev route

* remove comments

* add  tool to AI chat

* add go to explore button, update prompt

* viz improvements

* improve prompt

* add chart schema

* update prompt

* add where and time_grain to gen

* move to basic schema validation

* remove temp file

* remove old validation code

* lint fix

* review

* Disable the `create_chart` tool in external MCP connections (#8143)

* review comments

* Adds `chat_charts` feature flag for the `create_chart` tool (#8159)

* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
kaspersjo pushed a commit that referenced this pull request Oct 28, 2025
* refac: pull out metric view selectors from canvas spec

* lint fix

* separate out chart component from canvas

* move chart utils, methods, config to feature/component

* move chart specs and builder

* move canvas chart components

* move timeAndFilter

* ChartSpec name refactor

* update conflict var names

* remove dev route

* remove comments

* add  tool to AI chat

* add go to explore button, update prompt

* viz improvements

* improve prompt

* add chart schema

* update prompt

* add where and time_grain to gen

* move to basic schema validation

* remove temp file

* remove old validation code

* lint fix

* review

* Disable the `create_chart` tool in external MCP connections (#8143)

* review comments

* Adds `chat_charts` feature flag for the `create_chart` tool (#8159)

* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
grahamplata pushed a commit that referenced this pull request Oct 29, 2025
* refac: pull out metric view selectors from canvas spec

* lint fix

* separate out chart component from canvas

* move chart utils, methods, config to feature/component

* move chart specs and builder

* move canvas chart components

* move timeAndFilter

* ChartSpec name refactor

* update conflict var names

* remove dev route

* remove comments

* add  tool to AI chat

* add go to explore button, update prompt

* viz improvements

* improve prompt

* add chart schema

* update prompt

* add where and time_grain to gen

* move to basic schema validation

* remove temp file

* remove old validation code

* lint fix

* review

* Disable the `create_chart` tool in external MCP connections (#8143)

* review comments

* Adds `chat_charts` feature flag for the `create_chart` tool (#8159)

* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
royendo added a commit that referenced this pull request Oct 30, 2025
- Update AI chat documentation to reflect new chart visualization capabilities
- Document chatCharts feature flag in project configuration
- Add details about automatic chart type selection and when charts are generated
- Include examples of enabling chat with visualizations
- List all available chart types (line, area, bar, stacked bar, donut, combo, heatmap)

Related to PR #8122

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
grahamplata pushed a commit that referenced this pull request Oct 30, 2025
* refac: pull out metric view selectors from canvas spec

* lint fix

* separate out chart component from canvas

* move chart utils, methods, config to feature/component

* move chart specs and builder

* move canvas chart components

* move timeAndFilter

* ChartSpec name refactor

* update conflict var names

* remove dev route

* remove comments

* add  tool to AI chat

* add go to explore button, update prompt

* viz improvements

* improve prompt

* add chart schema

* update prompt

* add where and time_grain to gen

* move to basic schema validation

* remove temp file

* remove old validation code

* lint fix

* review

* Disable the `create_chart` tool in external MCP connections (#8143)

* review comments

* Adds `chat_charts` feature flag for the `create_chart` tool (#8159)

* Adds `chat_charts` feature flag for the `create_chart` tool

* Propagate feature flags to the prompts

* Fix test

* Fix test

* QA

* add feature flag to base system prompt

---------

Co-authored-by: Dhiraj Kumar <[email protected]>

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants