diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts index 46eb167bd1b1..97c6e0776b0f 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view.test.ts @@ -162,7 +162,10 @@ describe('AIAssistantView', () => { expect(mockAIAssistantController.getMessageStore).toHaveBeenCalledTimes(1); expect(aiChatConfig.chatOptions).toEqual(expect.objectContaining({ - dataSource: mockMessageStore, + dataSource: expect.objectContaining({ + store: mockMessageStore, + pushAggregationTimeout: 0, + }), reloadOnChange: true, onMessageEntered: expect.any(Function), })); diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.test.ts index ccd53fa31c3a..d39acd4706ab 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/__tests__/ai_assistant_view_controller.integration.test.ts @@ -463,4 +463,73 @@ describe('AIAssistantViewController', () => { expect(getMessageStatusClass($messages.eq(0))).toBe(MessageStatus.Success); }); }); + + describe('manual store push', () => { + // eslint-disable-next-line @typescript-eslint/init-declarations + let validateSpy; + // eslint-disable-next-line @typescript-eslint/init-declarations + let executeCommandsSpy; + + beforeEach(() => { + validateSpy = jest.spyOn(GridCommands.prototype, 'validate') + .mockReturnValue(true); + executeCommandsSpy = jest.spyOn(GridCommands.prototype, 'executeCommands') + .mockResolvedValue([ + { status: 'success', message: 'Done' }, + ] as CommandResult[]); + }); + + afterEach(() => { + validateSpy.mockRestore(); + executeCommandsSpy.mockRestore(); + }); + + it('should not throw error when user message is manually pushed to the message store', async () => { + // eslint-disable-next-line @typescript-eslint/init-declarations + let chatStore; + const { aiIntegration } = createMockAIIntegration(); + + await createDataGrid({ + dataSource: [ + { id: 1, name: 'Name 1' }, + ], + columns: [ + { dataField: 'id', caption: 'ID', dataType: 'number' }, + { dataField: 'name', caption: 'Name', dataType: 'string' }, + ], + aiAssistant: { + enabled: true, + aiIntegration, + chat: { + user: { id: 'user' }, + onInitialized: (e) => { + chatStore = e.component?.getDataSource().store(); + }, + }, + popup: { + visible: true, + }, + }, + }); + + try { + chatStore.push([{ + type: 'insert', + data: { + id: 'manual-msg-1', + author: { id: 'user', name: 'User' }, + text: 'Sort by name', + timestamp: new Date().toISOString(), + }, + }]); + + await flushAsync(); + await flushAsync(); + } catch (error) { + expect(error).toBeUndefined(); // Force fail if error is thrown + } + + expect(true).toBe(true); + }); + }); }); diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts index cca5ac0776c7..1c7514a8b157 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/ai_assistant_view.ts @@ -129,7 +129,10 @@ export class AIAssistantView extends View { private getAIChatOptions(): ChatProperties { return { - dataSource: this.messageStore, + dataSource: { + store: this.messageStore, + pushAggregationTimeout: 0, + }, reloadOnChange: true, onMessageEntered: (e): void => { this.executeRequest(e.message);