AI Assistant: Integration between AiIntegration, GridCommands, AiAssistant and AiChat#33564
Conversation
There was a problem hiding this comment.
Pull request overview
This PR wires the grid AI assistant end-to-end by connecting AIIntegration request execution to GridCommands (including response schema generation + grid context building) and then displaying the results in AIChat, with DataGrid-specific command/extra-context extensions.
Changes:
- Replaces the
CommandResultsalias usage withCommandResult[]across AI chat/assistant plumbing. - Extends
AIAssistantIntegrationController.sendRequestto accept a per-requestresponseSchemaand anextraContextselector, and implementsbuildContext(...)to serialize current grid state. - Introduces a core command registry (
commandsCore) and a DataGrid override controller that supplies DataGrid-specific commands and extra context options.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/devextreme/js/__internal/grids/grid_core/ai_chat/utils.ts | Updates command typing and command-error detection used for message status/icon rendering. |
| packages/devextreme/js/__internal/grids/grid_core/ai_chat/types.ts | Stops re-exporting CommandResults; keeps CommandResult. |
| packages/devextreme/js/__internal/grids/grid_core/ai_chat/ai_chat.ts | Updates command list rendering to accept CommandResult[]. |
| packages/devextreme/js/__internal/grids/grid_core/ai_chat/ai_chat.test.ts | Adjusts tests for the new command array typing. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts | Adds JSON schema/context-related types and updates AI message command typing. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/grid_commands.ts | Minor cleanup of TODO comments; command execution/schema generation remains the same. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/index.ts | Adds a core list of built-in grid AI commands and exports commandsCore. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_integration_controller.ts | Adds responseSchema + extraContext inputs and implements grid/column context building. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts | Uses generated response schema/context, adds response title customization logic, and initializes default command list. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/ai_assistant_integration_controller.integration.test.ts | Expands integration tests for schema passing, abort behavior, and context building. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/commands/index.ts | Builds a DataGrid command set by extending core commands with grouping/summary. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/ai_assistant.ts | Switches DataGrid to use a DataGrid-specific AI assistant controller. |
| packages/devextreme/js/__internal/grids/data_grid/ai_assistant/ai_assistant_controller.ts | Adds DataGrid overrides for command list and extra context options. |
Comments suppressed due to low confidence (3)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:92
- The rejection message
'Default error message'is a placeholder and is user-visible througherror.message. Replace it with a localized and actionable message (or reuse an existing localization key) to avoid shipping placeholder text.
if (!response?.actions || !Array.isArray(response.actions) || !response.actions.length) {
// TODO: need to localize default error message when there are no commands
return Promise.reject(new Error('Default error message'));
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:97
- The rejection message
'Received invalid commands'is hard-coded and not localized. Consider using a localized message (and include basic context like validation failure) since this string will be shown to end users.
if (!this.gridCommands?.validate(response.actions)) {
// TODO: need to localize error message on validation fail
return Promise.reject(new Error('Received invalid commands'));
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:190
new Error('Grid commands not initialized')is user-visible viafailAIMessageand is currently a hard-coded English internal detail. Replace with a localized, user-facing message (and/or ensure this situation cannot happen afterinit()).
if (!responseSchema) {
// TODO: Change error message
const error = new Error('Grid commands not initialized');
this.failAIMessage(aiMessage.id, error);
this.setProcessing(false);
reject(error);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (3)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts:118
GridContext.selection.selectedRowKeysis typed as(string | number)[], but grid selection keys can be any type (e.g., composite/object keys). This makes the context typing incorrect and forces unsafe casts elsewhere. Consider widening this tounknown[](orArray<TKey>/any[]), matching grid option typings, to avoid losing type support for valid key shapes.
search: {
searchText: string;
};
selection: {
selectedRowKeys: (string | number)[];
};
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_integration_controller.ts:75
- If
onAIAssistantRequestCreatingsetsargs.cancel = true,sendRequestreturns without invoking any callback and without settingthis.abort. Callers (e.g.,AIAssistantController) currently set their ownprocessingflag before callingsendRequest, so this path can leave the request promise pending indefinitely. Consider either notifying viacallbacks(e.g.,onError/onAbort) when cancelled, or returning a boolean indicating whether a request was actually started so the caller can cleanly resolve/reject and reset state.
this.executeAction('onAIAssistantRequestCreating', args);
if (args.cancel) {
return;
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:222
- The
// TODO: Change error messagecomments inside the.failandonErrorhandlers are misindented relative to the surrounding block, which is likely to trip formatting/lint rules and makes the nested callback harder to read. Please align these comments with the rest of the block indentation.
resolve();
})
.fail((errorMessage) => {
// TODO: Change error message
const error = errorMessage instanceof Error
? errorMessage
: new Error(String(errorMessage));
this.failAIMessage(aiMessage.id, error);
this.setProcessing(false);
reject(error);
});
},
onError: (error: Error): void => {
// TODO: Change error message
this.failAIMessage(aiMessage.id, error);
this.setProcessing(false);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 19 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_integration_controller.ts:171
buildColumnsContext()currently omits column-levelfilterValueeven though it’s part of the grid column state and is expected by the added tests. This makes the generated AI context incomplete/inconsistent (filter state is split betweencontext.filtering.filterValueand missing per-columnfilterValue). IncludefilterValue: column.filterValue(and updateGridColumnContextaccordingly).
return ({
dataField: column.dataField,
caption: column.caption,
dataType: column.dataType,
visible: column.visible !== false,
sortOrder: column.sortOrder,
sortIndex: column.sortIndex,
fixed: column.fixed,
fixedPosition: column.fixedPosition,
width: column.width,
visibleIndex: column.visibleIndex,
...gridColumnExtraContext,
});
6cf79c5 to
e1f919d
Compare
e1f919d to
40a3e2b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 21 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (1)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts:67
CustomizeResponseTitleis now used viaoption('aiAssistant.customizeResponseTitle'), but the public grid typings (js/common/grids.d.tsandts/dx.all.d.ts) don’t expose this callback on theAIAssistantoptions. If this is intended to be supported, please add the option to the public d.ts so consumers don’t need casts / implicit-any.
// TODO: move to d.ts
export type CustomizeResponseTitle = (
status: MessageStatus,
commandNames: string[],
) => string;
a79aa76 to
ecf2136
Compare
4b9bc45 to
7d1ca02
Compare
actualize tests for AIAssistantIntegrationController implement buildContext method pass response schema to AI Integration from AI controller fix option types and add todos to move them to d.ts implement getCustomizedResponseTitle method add a command list to both controllers temporarily add the specification add getGridCommandList method to be able to override it in a simple way Replace CommandResults type with simple CommandResult[] and remove it from types as redundant
fix review remarks fix qunit stubs add missing methods in zod stub fix qunit tests using stub for zod and zod-to-json-schema packages try to fix qunit tests fix tests of AIAssistantController
fix AIAssistantIntegrationController initialization fix type error fix tests after rebase fix after rebase
7d1ca02 to
1fdcade
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 19 out of 21 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (4)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:89
- This rejection message (
'Default error message') is a placeholder/unlocalized string and may be shown to end users. Please replace it with a specific, localized message for the "no actions" response case.
if (!response?.actions || !Array.isArray(response.actions) || !response.actions.length) {
// TODO: need to localize default error message when there are no commands
return Promise.reject(new Error('Default error message'));
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:94
- This rejection message (
'Received invalid commands') is a placeholder/unlocalized string and may be shown to end users. Please replace it with a localized, actionable message (and ideally include some safe details, e.g., that the AI response didn’t match the expected schema).
if (!this.gridCommands?.validate(response.actions)) {
// TODO: need to localize error message on validation fail
return Promise.reject(new Error('Received invalid commands'));
}
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:100
'Grid commands not initialized'is used as a user-visible error message (viafailAIMessage). If this can happen in production, it should be a localized, user-friendly message (and potentially treated as a configuration error with a dedicated error code).
return this.gridCommands?.executeCommands(response.actions, customizeResponseText)
?? Promise.reject(new Error('Grid commands not initialized'));
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:187
'Grid commands not initialized'is used as a user-visible error message here as well. Please replace with a localized, actionable message (or prevent this branch from being reachable by ensuringGridCommandsis always initialized before requests can be sent).
if (!responseSchema) {
// TODO: Change error message
const error = new Error('Grid commands not initialized');
| import type { Column } from '@ts/grids/grid_core/columns_controller/types'; | ||
|
|
||
| export class DataGridAIAssistantIntegrationController extends AIAssistantIntegrationController { | ||
| protected getGridExtraContext(): GridContext { |
There was a problem hiding this comment.
we don't need method to add extra content, just overload buildContext, buildColumnContext
| clearGroupingCommand, | ||
| summaryCommand, | ||
| clearSummaryCommand, | ||
| // TODO: try to remove "as GridCommand[]" |
There was a problem hiding this comment.
remove this todo, please, it is obvious, and it is easy to forget it in the code
| import { DataGridAIAssistantIntegrationController } from './ai_assistant_integration_controller'; | ||
| import { dataGridCommands } from './commands/index'; | ||
|
|
||
| export class DataGridAIAssistantController extends AIAssistantController { |
There was a problem hiding this comment.
add test for commands list
| import type { GridContext } from '@ts/grids/grid_core/ai_assistant/types'; | ||
| import type { Column } from '@ts/grids/grid_core/columns_controller/types'; | ||
|
|
||
| export class DataGridAIAssistantIntegrationController extends AIAssistantIntegrationController { |
There was a problem hiding this comment.
add test for grid context
| selectByKeysCommand, | ||
| clearSortingCommand, | ||
| sortingCommand, | ||
| // TODO: try to remove "as GridCommand[]" |
There was a problem hiding this comment.
same, remove this comment, please
No description provided.