AI Assistant: fix json schema building#33588
Open
dmirgaev wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Grid AI Assistant’s response JSON Schema generation to be compatible with structured-output APIs (notably OpenAI Structured Outputs), by normalizing unsupported schema constructs and ensuring $ref resolution works at the schema root.
Changes:
- Switch JSON Schema generation to
zod-to-json-schema’sopenAitarget and remove reliance on draft-07$schema. - Add schema post-processing utilities to (1) expand array-style
typetoanyOfand (2) hoist/rewrite$reftargets into root-level$defs. - Refactor
filterValuecommand schema to a discriminated-union object format (instead of tuple arrays) and update/add tests for schema + execution + integration behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts | Adds JSON Schema transformation utilities (expandTypeArraysToAnyOf, $ref hoisting/rewriting helpers). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts | Simplifies JsonSchema typing and introduces ResponseSchemaBranch shape used by schema builder. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/grid_commands.ts | Builds OpenAI-targeted response schema, expands type unions, and hoists $defs to schema root. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/index.ts | Removes obsolete TODO comment. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/filtering.ts | Changes filter expression input to object-based discriminated union; converts to DataGrid’s expected array filter format at execution. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/tests/filtering.test.ts | Updates filter command schema/execute tests for the new object expression format. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_integration_controller.ts | Refactors context building into overridable buildContext / buildColumnContext and caches controllers during init(). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/utils.test.ts | Adds unit tests for the new schema utilities (expandTypeArraysToAnyOf, hoistSchemaRefs). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/grid_commands.test.ts | Updates schema tests for OpenAI target and adds coverage for $defs hoisting / inline $ref rewriting. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/ai_assistant_integration_controller.integration.test.ts | Minor typing cleanup in test setup (aligns with new controller behavior). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/ai_assistant_controller.test.ts | Adds coverage for additional failure paths, request concurrency rejection, header title formatting, and dispose behavior. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/commands/index.ts | Removes obsolete TODO comment. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/ai_assistant_integration_controller.ts | Updates overrides to buildContext / buildColumnContext to enrich context with summary info. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/tests/ai_assistant_integration_controller.integration.test.ts | New integration tests validating DataGrid-specific context enrichment and lifecycle behaviors. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/tests/ai_assistant_controller.test.ts | New controller tests ensuring DataGrid controller inherits core behavior and wiring. |
Comment on lines
+82
to
+98
|
|
||
| if (Array.isArray(result.type)) { | ||
| const { type, ...rest } = result; | ||
|
|
||
| return { | ||
| anyOf: (type as string[]).map((t) => ({ type: t })), | ||
| ...rest, | ||
| }; | ||
| } | ||
|
|
||
| for (const key of SCHEMA_TRAVERSAL_KEYS) { | ||
| if (key in result) { | ||
| result[key] = transformNested(key, result[key]); | ||
| } | ||
| } | ||
|
|
||
| return result; |
| return undefined; | ||
| } | ||
|
|
||
| current = (current as Record<string, unknown>)[segment]; |
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.
No description provided.