Skip to content

Commit

Permalink
fix: Prevent AI assistant session reset when workflow is saved (#10707)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic authored and tomi committed Sep 6, 2024
1 parent b28900a commit 02d3873
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
15 changes: 15 additions & 0 deletions cypress/e2e/45-ai-assistant.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SCHEDULE_TRIGGER_NODE_NAME } from '../constants';
import { NDV, WorkflowPage } from '../pages';
import { AIAssistant } from '../pages/features/ai-assistant';

Expand Down Expand Up @@ -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');
});
});
4 changes: 4 additions & 0 deletions packages/design-system/src/components/N8nAvatar/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions packages/editor-ui/src/stores/assistant.store.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 },
);
Expand Down

0 comments on commit 02d3873

Please sign in to comment.