Skip to content

AI Assistant: Integration between AiIntegration, GridCommands, AiAssistant and AiChat#33564

Merged
dmirgaev merged 4 commits into
DevExpress:26_1from
dmirgaev:26_1__ai_assistant_integration
May 14, 2026
Merged

AI Assistant: Integration between AiIntegration, GridCommands, AiAssistant and AiChat#33564
dmirgaev merged 4 commits into
DevExpress:26_1from
dmirgaev:26_1__ai_assistant_integration

Conversation

@dmirgaev
Copy link
Copy Markdown
Contributor

No description provided.

@dmirgaev dmirgaev self-assigned this May 12, 2026
Copilot AI review requested due to automatic review settings May 12, 2026 23:07
@dmirgaev dmirgaev requested a review from a team as a code owner May 12, 2026 23:07
@dmirgaev dmirgaev added the 26_1 label May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 CommandResults alias usage with CommandResult[] across AI chat/assistant plumbing.
  • Extends AIAssistantIntegrationController.sendRequest to accept a per-request responseSchema and an extraContext selector, and implements buildContext(...) 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 through error.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 via failAIMessage and is currently a hard-coded English internal detail. Replace with a localized, user-facing message (and/or ensure this situation cannot happen after init()).
      if (!responseSchema) {
        // TODO: Change error message
        const error = new Error('Grid commands not initialized');

        this.failAIMessage(aiMessage.id, error);
        this.setProcessing(false);
        reject(error);

Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts Outdated
Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_chat/utils.ts Outdated
Copilot AI review requested due to automatic review settings May 13, 2026 00:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.selectedRowKeys is 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 to unknown[] (or Array<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 onAIAssistantRequestCreating sets args.cancel = true, sendRequest returns without invoking any callback and without setting this.abort. Callers (e.g., AIAssistantController) currently set their own processing flag before calling sendRequest, so this path can leave the request promise pending indefinitely. Consider either notifying via callbacks (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 message comments inside the .fail and onError handlers 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);

Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts Outdated
Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts Outdated
@Alyar666 Alyar666 self-requested a review May 13, 2026 09:07
Copilot AI review requested due to automatic review settings May 13, 2026 10:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Comment thread packages/devextreme/testing/helpers/stubs/zodStub.js Outdated
Copilot AI review requested due to automatic review settings May 13, 2026 11:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Comment thread packages/devextreme/testing/helpers/stubs/zodStub.js Outdated
Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts Outdated
Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/index.ts Outdated
Comment thread packages/devextreme/js/__internal/grids/data_grid/ai_assistant/commands/index.ts Outdated
Copilot AI review requested due to automatic review settings May 13, 2026 14:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-level filterValue even 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 between context.filtering.filterValue and missing per-column filterValue). Include filterValue: column.filterValue (and update GridColumnContext accordingly).
        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,
        });

Comment thread packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts Outdated
@dmirgaev dmirgaev force-pushed the 26_1__ai_assistant_integration branch from 6cf79c5 to e1f919d Compare May 13, 2026 15:57
Copilot AI review requested due to automatic review settings May 13, 2026 16:48
@dmirgaev dmirgaev force-pushed the 26_1__ai_assistant_integration branch from e1f919d to 40a3e2b Compare May 13, 2026 16:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

  • CustomizeResponseTitle is now used via option('aiAssistant.customizeResponseTitle'), but the public grid typings (js/common/grids.d.ts and ts/dx.all.d.ts) don’t expose this callback on the AIAssistant options. 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;

Copilot AI review requested due to automatic review settings May 13, 2026 17:37
@dmirgaev dmirgaev force-pushed the 26_1__ai_assistant_integration branch from a79aa76 to ecf2136 Compare May 13, 2026 17:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 22 changed files in this pull request and generated 3 comments.

Comment thread packages/devextreme/testing/helpers/stubs/zodStub.js Outdated
@dmirgaev dmirgaev force-pushed the 26_1__ai_assistant_integration branch from 4b9bc45 to 7d1ca02 Compare May 13, 2026 18:01
dmirgaev added 3 commits May 13, 2026 22:03
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
Copilot AI review requested due to automatic review settings May 13, 2026 18:05
@dmirgaev dmirgaev force-pushed the 26_1__ai_assistant_integration branch from 7d1ca02 to 1fdcade Compare May 13, 2026 18:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 (via failAIMessage). 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 ensuring GridCommands is 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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we don't need method to add extra content, just overload buildContext, buildColumnContext

clearGroupingCommand,
summaryCommand,
clearSummaryCommand,
// TODO: try to remove "as GridCommand[]"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add test for grid context

selectByKeysCommand,
clearSortingCommand,
sortingCommand,
// TODO: try to remove "as GridCommand[]"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same, remove this comment, please

@dmirgaev dmirgaev merged commit 333e3e3 into DevExpress:26_1 May 14, 2026
148 of 151 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants