From 02d387334997227b88ac10d6964fe4c6d5b9c7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milorad=20FIlipovi=C4=87?= Date: Fri, 6 Sep 2024 11:06:51 +0200 Subject: [PATCH] fix: Prevent AI assistant session reset when workflow is saved (#10707) --- cypress/e2e/45-ai-assistant.cy.ts | 15 +++++++++++++++ .../src/components/N8nAvatar/Avatar.vue | 4 ++++ packages/editor-ui/src/stores/assistant.store.ts | 15 +++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/45-ai-assistant.cy.ts b/cypress/e2e/45-ai-assistant.cy.ts index f80b4637d0f48..19dc5380f9a8e 100644 --- a/cypress/e2e/45-ai-assistant.cy.ts +++ b/cypress/e2e/45-ai-assistant.cy.ts @@ -1,3 +1,4 @@ +import { SCHEDULE_TRIGGER_NODE_NAME } from '../constants'; import { NDV, WorkflowPage } from '../pages'; import { AIAssistant } from '../pages/features/ai-assistant'; @@ -287,4 +288,18 @@ describe('AI Assistant::enabled', () => { // Now, session should be reset aiAssistant.getters.placeholderMessage().should('be.visible'); }); + + it('Should not reset assistant session when workflow is saved', () => { + cy.intercept('POST', '/rest/ai-assistant/chat', { + statusCode: 200, + fixture: 'aiAssistant/simple_message_response.json', + }).as('chatRequest'); + wf.actions.addInitialNodeToCanvas(SCHEDULE_TRIGGER_NODE_NAME); + aiAssistant.actions.openChat(); + aiAssistant.actions.sendMessage('Hello'); + wf.actions.openNode(SCHEDULE_TRIGGER_NODE_NAME); + ndv.getters.nodeExecuteButton().click(); + wf.getters.isWorkflowSaved(); + aiAssistant.getters.placeholderMessage().should('not.exist'); + }); }); diff --git a/packages/design-system/src/components/N8nAvatar/Avatar.vue b/packages/design-system/src/components/N8nAvatar/Avatar.vue index 96686abc5061d..246140f940b9b 100644 --- a/packages/design-system/src/components/N8nAvatar/Avatar.vue +++ b/packages/design-system/src/components/N8nAvatar/Avatar.vue @@ -63,6 +63,10 @@ const getSize = (size: string): number => sizes[size]; display: inline-flex; justify-content: center; align-items: center; + + svg { + border-radius: 50%; + } } .empty { diff --git a/packages/editor-ui/src/stores/assistant.store.ts b/packages/editor-ui/src/stores/assistant.store.ts index 4c36b91cb7ce4..de50aa6261bc7 100644 --- a/packages/editor-ui/src/stores/assistant.store.ts +++ b/packages/editor-ui/src/stores/assistant.store.ts @@ -1,5 +1,11 @@ import { chatWithAssistant, replaceCode } from '@/api/assistant'; -import { VIEWS, EDITABLE_CANVAS_VIEWS, STORES, AI_ASSISTANT_EXPERIMENT } from '@/constants'; +import { + VIEWS, + EDITABLE_CANVAS_VIEWS, + STORES, + AI_ASSISTANT_EXPERIMENT, + PLACEHOLDER_EMPTY_WORKFLOW_ID, +} from '@/constants'; import type { ChatRequest } from '@/types/assistant.types'; import type { ChatUI } from 'n8n-design-system/types/assistant'; import { defineStore } from 'pinia'; @@ -116,7 +122,11 @@ export const useAssistantStore = defineStore(STORES.ASSISTANT, () => { watch(route, () => { const activeWorkflowId = workflowsStore.workflowId; - if (!currentSessionId.value || currentSessionWorkflowId.value === activeWorkflowId) { + if ( + !currentSessionId.value || + currentSessionWorkflowId.value === PLACEHOLDER_EMPTY_WORKFLOW_ID || + currentSessionWorkflowId.value === activeWorkflowId + ) { return; } resetAssistantChat(); @@ -276,6 +286,7 @@ export const useAssistantStore = defineStore(STORES.ASSISTANT, () => { { chat_session_id: currentSessionId.value, task: isSupportChatSessionInProgress.value ? 'support' : 'error', + node_type: chatSessionError.value?.node.type, }, { withPostHog: true }, );