AI Assistant: adjust filterValue schema for gemini#33741
Conversation
| type FilterExprObj = BasicFilterExpr | CombinedFilterExpr | NegatedFilterExpr; | ||
| type FilterExpr = BasicFilterExpr | CombinedFilterExpr | NegatedFilterExpr; | ||
|
|
||
| interface FilterExprNode { |
There was a problem hiding this comment.
The node id lives on this wrapper, not inside the expr union. Azure OpenAI's strict structured-output mode rejects an anyOf whose object branches share an identical property (the variants would all carry id: string); keeping id out of the union leaves the branches sharing only their type discriminator.
There was a problem hiding this comment.
Pull request overview
Adjusts the filterValueCommand Zod schema used by the grid AI assistant so it works with structured-output providers (notably Gemini) that don't support recursive schemas. The previous recursive expression form (using nested left/right/expression) is replaced with a flat node-list tree ({ rootId, nodes } where nodes reference each other by id), and a new converter walks the node graph to produce the existing legacy filterValue array consumed by the grid. Tests are updated and expanded accordingly.
Changes:
- Replaced the recursive
z.lazyschema with separate basic/combined/negated variants that reference other nodes by id, plus aFilterExprTreewrapper. - Added a
convertFilterExprToArrayimplementation that validates uniqueness, missing references, and cycles, and updated the command description to instruct the model in the new format. - Refactored existing filtering tests around new
basicNode/combinedNode/negatedNode/treehelpers and added coverage for empty nodes, strictness, duplicate ids, missing rootId/refs, cycles, and unreachable nodes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/filtering.ts |
Switches filterValueCommand to a flat node-list schema and adds an id-resolving converter to the legacy array form. |
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/filtering.test.ts |
Rewrites helpers/tests for the new tree shape and adds converter-failure tests (duplicate id, missing refs, cycle, unreachable nodes). |
No description provided.