AG-17719 Support Calculated Columns and Show Values As in AI Toolkit - #14329
AG-17719 Support Calculated Columns and Show Values As in AI Toolkit#14329alistairjcbrown wants to merge 8 commits into
Conversation
getStructuredSchema() only describes Grid State, so adding a column (a column-definition change) could not be expressed and the LLM replied with prose instead of acting. Extend both AI Toolkit examples' LLM response schema with a columnDefOperations array and apply those operations via setGridOption before setState. Enable calculatedColumns on both grids and steer the system prompts to Calculated Column formula syntax, including quoting literal text.
The AI Toolkit examples call ai-api.ag-grid.com directly, which browsers block from localhost on CORS (the upstream gates on an origin allow-list). Add a dev-server-only Vite proxy at /ai-proxy that forwards upstream and can present an allowed Origin/Referer and dev token server-side, both env-gated and inert by default. Point an example's AI_API_URL at /ai-proxy via .env.local to use it. This is dev tooling, separable from the example fix, and never ships in the production static build.
showValuesAs was wired into ColumnState (getColumnState/applyColumnState) when the feature landed, but never into the GridState projection, so getState/setState silently dropped it. Carry it through AggregationColumnState, convertColumnState, orderAggregationModel and the setState apply path so it round-trips like aggFunc.
Add a null schema builder (s.null) and extend the aggregation feature schema so each aggregatable column exposes showValuesAs (built-in modes + null to clear) when showValuesAsSvc is present. Behavioural tests cover the schema shape and the full grid-state round-trip.
- Derive SHOW_VALUES_AS_BUILT_IN_TYPES from Record<ShowValuesAsBuiltInType, true> so the built-in mode set is compile-time coupled to the source union (typos, removals and additions now break the build instead of silently misinforming the LLM). - Add a system-prompt note in both examples to carry over a column's existing showValuesAs on aggregation edits, since it is a required, nullable schema property. - Cover the graceful-degradation branch: assert showValuesAs is omitted from the schema when ShowValuesAsModule is absent.
|
❌ Codex review complete; 1 issue found (P0: 0 | P1: 1 | P2: 0 | P3: 0) View full reviewAG-17719 Support Calculated Columns and Show Values As in AI ToolkitPR: #14329 SummaryThis PR extends AI Toolkit examples and structured schema support for calculated-column operations, and adds showValuesAs to aggregation grid state/schema round-tripping. FindingsP0: 0 | P1: 1 | P2: 0 | P3: 0 1 inline comments posted. VerdictAssessment: incorrect The feature direction is coherent, but the state restore path can preserve stale showValuesAs values when the new aggregation model omits the property, which is a substantive behavioural regression for setState replacement semantics. Required Actions:
|
Live-test this PR in PlunkerPaste these two <script src="https://ag-grid.github.io/ag-grid/pr-14329/ag-grid-community.min.js"></script>
<script src="https://ag-grid.github.io/ag-grid/pr-14329/ag-grid-enterprise.min.js"></script>Bundles are removed automatically when the PR is closed. Updated on every push. |
Module Size ComparisonExtreme Values🔺 Largest Increase: AllEnterpriseModule
Significant Changes (≥ 0.5KB)
📊 Full Statistics
All Module Changes
Updated: 2026-07-03T15:43:07.383Z |
- Build the calculated-column ColDef by dropping the operation discriminator and unset values, instead of field-by-field conditional assignment. - Keep the ChatToolPanel change minimal: add applyColumnDefOperations above the existing state-apply branch rather than restructuring the render/setState flow.
| * this forwards it upstream, adding the dev token server-side if one is configured. | ||
| */ | ||
| proxy: { | ||
| '/ai-proxy': { |
There was a problem hiding this comment.
Dev-only proxy: the examples call ai-api.ag-grid.com, which the browser CORS-blocks from localhost. Point an example's AI_API_URL at /ai-proxy via .env.local to test locally. vite.server.* isn't in the production build, so no prod footprint.
| } | ||
| if (typeof aggFunc === 'string') { | ||
| aggregationColumns.push({ colId, aggFunc, valueIndex }); | ||
| aggregationColumns.push({ colId, aggFunc, showValuesAs, valueIndex }); |
There was a problem hiding this comment.
showValuesAs has lived in ColumnState since it shipped but was never wired into GridState — so getState() dropped it and setState() couldn't restore it. Follow-up AG-17765 planned which adds a guard against this (pivotSort is a second instance).
AlpineJosh
left a comment
There was a problem hiding this comment.
Overall looks good. A few minor points to clear up the schema for OpenAI.
I do think it might be worth us splitting up structured schema into individual tool schemas. That way we could provided the calculated column schema ourselves rather than requiring devs to manually type it.
| description: | ||
| 'Calculated Column formula. Reference other columns with bracketed column IDs, for example [gold] * 3 + [silver] * 2 + [bronze], and wrap literal text in double quotes, for example "Hello"', |
There was a problem hiding this comment.
You may need more detail here as to valid operators and functions. It can also be provided as top level context.
| description: 'Whether the new column should be hidden', | ||
| }, | ||
| }, | ||
| required: ['operation', 'colId', 'headerName', 'calculatedExpression'], |
There was a problem hiding this comment.
Annoyingly ChatGPT requires that all fields are marked as required. The only way to make them optional is to union with 'null'. See https://developers.openai.com/api/docs/guides/structured-outputs#supported-schemas
https://ag-grid.atlassian.net/browse/AG-17719
Fix AG-17719