DataGrid - AI Assistant: Implement GridCommands class#33460
DataGrid - AI Assistant: Implement GridCommands class#33460dmirgaev wants to merge 22 commits intoDevExpress:26_1from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces the internal infrastructure for a DataGrid AI Assistant command system by adding a GridCommands utility (schema building, response validation, sequential command execution) plus initial scaffolding for an AIAssistantIntegrationController. It also updates dependencies and adds new localization keys for assistant error/abort messaging.
Changes:
- Add
GridCommands(+ spec doc) and supporting types for command schema generation (JSON Schema draft-07 via Zod) and command execution. - Add a new
AIAssistantIntegrationController(currently with stubbedbuildContext/buildResponseSchema). - Add Jest tests for
GridCommandsand update AI assistant integration controller test import; update deps (zod-to-json-schema) and add new message keys.
Reviewed changes
Copilot reviewed 37 out of 39 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Locks zod-to-json-schema@3.24.6 and pins zod specifier for devextreme importer. |
| packages/devextreme/package.json | Adds zod-to-json-schema dependency; pins zod to an exact version. |
| packages/devextreme/js/localization/messages/ar.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/bg.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/ca.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/cs.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/da.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/de.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/el.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/en.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/es.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/fa.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/fi.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/fr.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/hu.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/it.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/ja.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/ko.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/lt.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/lv.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/nb.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/nl.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/pl.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/pt.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/ro.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/ru.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/sl.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/sv.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/tr.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/uk.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/vi.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/zh.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/localization/messages/zh-tw.json | Adds AI assistant error + execution-abort message keys. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/types.ts | Adds JSON schema type + message customization types for command execution results. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/grid_commands_spec.md | Adds a detailed implementation specification for GridCommands and command set. |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/grid_commands.ts | Implements GridCommands (schema generation, validation, sequential execution, abort + message customization). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_integration_controller.ts | Adds controller scaffold for sending AI requests and aborting them (context/schema currently stubbed). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/grid_commands.test.ts | Adds Jest coverage for GridCommands behaviors (schema, validate, execute, abort, reentrancy, customization). |
| packages/devextreme/js/__internal/grids/grid_core/ai_assistant/tests/ai_assistant_integration_controller.integration.test.ts | Updates test import path to the new controller file. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
40151ee to
530a7ff
Compare
c9fabe8 to
395f2ed
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 37 out of 39 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:95
GridCommandsis instantiated with an empty command registry. With the currentGridCommands.validate/executeCommandsbehavior this makes every AI-produced action unknown/invalid, so the assistant can never successfully validate/execute commands. Register the available grid commands here (e.g., from./commands/*) or otherwise ensure the controller passes a non-empty, feature-appropriate command list.
public init(): void {
this.gridCommands = new GridCommands(this.component, []);
this.messageStore = new ArrayStore<Message, string>({
key: 'id',
});
this.aiAssistantIntegrationController = new AIAssistantIntegrationController(this.component);
this.aiAssistantIntegrationController.init();
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:95
processResponsecallsthis.gridCommands?.validate(response.actions), butGridCommands.validatecurrently expects an object with anactionsarray (it checksres.actions). This mismatch makes validation always fail at runtime. Align the API by either changingGridCommands.validateto accept an actions array, or by passing the full response shape from here.
public init(): void {
this.gridCommands = new GridCommands(this.component, []);
this.messageStore = new ArrayStore<Message, string>({
key: 'id',
});
this.aiAssistantIntegrationController = new AIAssistantIntegrationController(this.component);
this.aiAssistantIntegrationController.init();
83ae1dd to
80be63d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 40 out of 42 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_controller.ts:96
AIAssistantControllerconstructsGridCommandswith an empty command registry. With the newGridCommands.validate()implementation, any non-emptyresponse.actionswill be rejected as “unknown command”, making AI assistant execution fail even when the provider returns actions. The controller needs to pass the actual list of supportedGridCommands (or delay validation/execution until commands are registered).
public init(): void {
this.gridCommands = new GridCommands(this.component, []);
this.messageStore = new ArrayStore<Message, string>({
key: 'id',
});
this.aiAssistantIntegrationController = new AIAssistantIntegrationController(this.component);
this.aiAssistantIntegrationController.init();
}
| public buildResponseSchema(): JsonSchema { | ||
| const branches = [...this.commands.values()].map((command) => { | ||
| const argsSchema = zodToJsonSchema(command.schema, { target: 'jsonSchema7' }); | ||
|
|
||
| // Remove $schema from nested schemas since it's only necessary at root | ||
| delete argsSchema.$schema; | ||
|
|
||
| return { | ||
| type: 'object', | ||
| description: command.description, | ||
| required: ['name', 'args'], | ||
| additionalProperties: false, | ||
| properties: { | ||
| name: { | ||
| type: 'string', | ||
| enum: [command.name], | ||
| }, | ||
| args: argsSchema, | ||
| }, |
There was a problem hiding this comment.
buildResponseSchema() generates JSON Schema from command.schema, but validate() enforces command.schema.strict(). If a command schema is not strict, the LLM may produce extra properties that appear valid per the generated JSON Schema but will be rejected by validate(). Consider generating the schema from the same strict schema you validate against (or otherwise ensure both paths enforce the same additional-properties behavior).
80be63d to
ed1bee8
Compare
|
|
||
| public init(): void { | ||
| this.gridCommands = new GridCommands(this.component); | ||
| this.gridCommands = new GridCommands(this.component, []); |
There was a problem hiding this comment.
please add todo to define default commands list when they are ready + it should support extension in ingerited classed
| JsonSchema, | ||
| } from './types'; | ||
|
|
||
| const DEFAULT_SUCCESS_MESSAGE = 'dxDataGrid-aiAssistantSuccessMessage'; |
There was a problem hiding this comment.
lets move it to const.ts for consistency
|
|
||
| private readonly commands: Map<string, GridCommand<Record<string, unknown>>>; | ||
|
|
||
| private _executing = false; |
There was a problem hiding this comment.
we do not use underscore for private properties and methods anymore - keyword is enough
| constructor(private readonly gridInstance: InternalGrid) { | ||
| private readonly component: InternalGrid; | ||
|
|
||
| private readonly commands: Map<string, GridCommand<Record<string, unknown>>>; |
There was a problem hiding this comment.
please, add todo to specify type when we settle all names and schemas
| this.commands = new Map(); | ||
|
|
||
| for (const command of commands) { | ||
| if (this.commands.has(command.name)) { |
There was a problem hiding this comment.
should we handle it as error ot just overwrite the previous one?
| return false; | ||
| } | ||
|
|
||
| if (!isDefined(action.args) || !isObject(action.args)) { |
There was a problem hiding this comment.
looks like we can combine if with prev condition without loosing readability
| message: action.name, | ||
| }))); | ||
| private async executeCommand( | ||
| command: GridCommand<Record<string, unknown>>, |
There was a problem hiding this comment.
please, add todo to specify type
| const command = this.commands.get(name); | ||
|
|
||
| if (!command) { | ||
| this._executing = false; |
There was a problem hiding this comment.
looks like in current implementation we'll never hit this case - we cannot change commands list in runtime and already validated result, we can keep it for safety, but add comment, please
| } | ||
| } | ||
|
|
||
| public async executeCommands( |
There was a problem hiding this comment.
in ai_assistant_controller we call this methods with commands only, add second arg in call, please
use private types while we not provided callback in public dts
No description provided.