From deddc656d7016132fc1731f05d837cd5712effa0 Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Tue, 19 Nov 2024 08:55:55 +0100 Subject: [PATCH] Fix OtherTrigger->(new Memory->Agent) case --- .../src/utils/connectionNodeUtils.test.ts | 38 +++++++++++++++++-- .../src/utils/connectionNodeUtils.ts | 2 +- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/editor-ui/src/utils/connectionNodeUtils.test.ts b/packages/editor-ui/src/utils/connectionNodeUtils.test.ts index 165a4ace57..4dca7f2f99 100644 --- a/packages/editor-ui/src/utils/connectionNodeUtils.test.ts +++ b/packages/editor-ui/src/utils/connectionNodeUtils.test.ts @@ -1,4 +1,9 @@ -import { AGENT_NODE_TYPE, CHAT_TRIGGER_NODE_TYPE, MANUAL_TRIGGER_NODE_TYPE } from '@/constants'; +import { + AGENT_NODE_TYPE, + CHAT_TRIGGER_NODE_TYPE, + MANUAL_TRIGGER_NODE_TYPE, + ZENDESK_TRIGGER_NODE_TYPE, +} from '@/constants'; import { adjustNewNodes } from '@/utils/connectionNodeUtils'; import { createPinia, setActivePinia } from 'pinia'; @@ -61,7 +66,18 @@ describe('adjustNewlyConnectedNodes', () => { }); }); - it('modifies sessionId with ChatTrigger->(new Memory->Agent)', () => { + it('does not modify promptType with OtherTrigger->new Agent', () => { + const source = { type: ZENDESK_TRIGGER_NODE_TYPE }; + const target = { type: AGENT_NODE_TYPE }; + + adjustNewNodes(source, target, { sourceIsNew: false }); + + expect(target).toEqual({ + type: AGENT_NODE_TYPE, + }); + }); + + it('does not modify sessionId with ChatTrigger->(new Memory->Agent)', () => { const trigger = { type: CHAT_TRIGGER_NODE_TYPE, name: 'trigger' }; getsourceNodesByDepth.mockReturnValue([{ name: trigger.name }]); getNode.mockReturnValue({ type: trigger.type }); @@ -76,7 +92,7 @@ describe('adjustNewlyConnectedNodes', () => { }); }); - it('does not modify sessionId with ManualTrigger->(new Memory->Agent)', () => { + it('does modify sessionId with ManualTrigger->(new Memory->Agent)', () => { const trigger = { type: MANUAL_TRIGGER_NODE_TYPE, name: 'trigger' }; getsourceNodesByDepth.mockReturnValue([{ name: trigger.name }]); getNode.mockReturnValue({ type: trigger.type }); @@ -91,4 +107,20 @@ describe('adjustNewlyConnectedNodes', () => { parameters: { sessionIdType: 'customKey' }, }); }); + + it('does modify sessionId with OtherTrigger->(new Memory->Agent)', () => { + const trigger = { type: ZENDESK_TRIGGER_NODE_TYPE, name: 'trigger' }; + getsourceNodesByDepth.mockReturnValue([{ name: trigger.name }]); + getNode.mockReturnValue({ type: trigger.type }); + + const target = { type: AGENT_NODE_TYPE, name: 'myAgent' }; + const source = { type: '@n8n/n8n-nodes-langchain.memoryBufferWindow' }; + + adjustNewNodes(source, target, { targetIsNew: false }); + + expect(source).toEqual({ + type: '@n8n/n8n-nodes-langchain.memoryBufferWindow', + parameters: { sessionIdType: 'customKey' }, + }); + }); }); diff --git a/packages/editor-ui/src/utils/connectionNodeUtils.ts b/packages/editor-ui/src/utils/connectionNodeUtils.ts index 7068b176d4..46ba46f810 100644 --- a/packages/editor-ui/src/utils/connectionNodeUtils.ts +++ b/packages/editor-ui/src/utils/connectionNodeUtils.ts @@ -32,7 +32,7 @@ function adjustNewSource(source: AddedNode, target: AddedNode) { const { getCurrentWorkflow } = useWorkflowsStore(); const workflow = getCurrentWorkflow(); - // If a memory node is added to an Agent, the memory node is actually a parent since it provides input + // If a memory node is added to an Agent, the memory node is actually the source since it provides input // So we need to look for the Agent's (other) parents to determine if there is a sessionId provider const ps = workflow.getParentNodesByDepth(target.name, 1); if (