mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Implement feature
This commit is contained in:
parent
af7d6e68d0
commit
70c92760d5
|
@ -44,6 +44,7 @@ import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||||
import { sortNodeCreateElements, transformNodeType } from '../utils';
|
import { sortNodeCreateElements, transformNodeType } from '../utils';
|
||||||
import { useI18n } from '@/composables/useI18n';
|
import { useI18n } from '@/composables/useI18n';
|
||||||
import { useCanvasStore } from '@/stores/canvas.store';
|
import { useCanvasStore } from '@/stores/canvas.store';
|
||||||
|
import { adjustNewlyConnectedNodes } from '@/utils/connectionParameterUtils';
|
||||||
|
|
||||||
export const useActions = () => {
|
export const useActions = () => {
|
||||||
const nodeCreatorStore = useNodeCreatorStore();
|
const nodeCreatorStore = useNodeCreatorStore();
|
||||||
|
@ -276,6 +277,10 @@ export const useActions = () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addedNodes.length === 2) {
|
||||||
|
adjustNewlyConnectedNodes(addedNodes[0], addedNodes[1]);
|
||||||
|
}
|
||||||
|
|
||||||
addedNodes.forEach((node, index) => {
|
addedNodes.forEach((node, index) => {
|
||||||
if (node.type === OPEN_AI_NODE_MESSAGE_ASSISTANT_TYPE) {
|
if (node.type === OPEN_AI_NODE_MESSAGE_ASSISTANT_TYPE) {
|
||||||
node.type = OPEN_AI_NODE_TYPE;
|
node.type = OPEN_AI_NODE_TYPE;
|
||||||
|
|
|
@ -96,6 +96,7 @@ import type { useRouter } from 'vue-router';
|
||||||
import { useClipboard } from '@/composables/useClipboard';
|
import { useClipboard } from '@/composables/useClipboard';
|
||||||
import { useUniqueNodeName } from '@/composables/useUniqueNodeName';
|
import { useUniqueNodeName } from '@/composables/useUniqueNodeName';
|
||||||
import { isPresent } from '../utils/typesUtils';
|
import { isPresent } from '../utils/typesUtils';
|
||||||
|
import { adjustNewlyConnectedNodes } from '@/utils/connectionParameterUtils';
|
||||||
|
|
||||||
type AddNodeData = Partial<INodeUi> & {
|
type AddNodeData = Partial<INodeUi> & {
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -1104,6 +1105,8 @@ export function useCanvasOperations({ router }: { router: ReturnType<typeof useR
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adjustNewlyConnectedNodes(sourceNode, targetNode);
|
||||||
|
|
||||||
workflowsStore.addConnection({
|
workflowsStore.addConnection({
|
||||||
connection: mappedConnection,
|
connection: mappedConnection,
|
||||||
});
|
});
|
||||||
|
|
43
packages/editor-ui/src/utils/connectionParameterUtils.ts
Normal file
43
packages/editor-ui/src/utils/connectionParameterUtils.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { type INode } from 'n8n-workflow';
|
||||||
|
import {
|
||||||
|
AGENT_NODE_TYPE,
|
||||||
|
BASIC_CHAIN_NODE_TYPE,
|
||||||
|
CHAT_TRIGGER_NODE_TYPE,
|
||||||
|
OPEN_AI_ASSISTANT_NODE_TYPE,
|
||||||
|
OPEN_AI_NODE_MESSAGE_ASSISTANT_TYPE,
|
||||||
|
QA_CHAIN_NODE_TYPE,
|
||||||
|
} from '@/constants';
|
||||||
|
|
||||||
|
const AI_NODES = [
|
||||||
|
QA_CHAIN_NODE_TYPE,
|
||||||
|
AGENT_NODE_TYPE,
|
||||||
|
BASIC_CHAIN_NODE_TYPE,
|
||||||
|
OPEN_AI_ASSISTANT_NODE_TYPE,
|
||||||
|
OPEN_AI_NODE_MESSAGE_ASSISTANT_TYPE,
|
||||||
|
];
|
||||||
|
|
||||||
|
const MEMORY_NODE_NAMES = [
|
||||||
|
'memoryBufferWindow',
|
||||||
|
'memoryMotorhead',
|
||||||
|
'memoryPostgresChat',
|
||||||
|
'memoryRedisChat',
|
||||||
|
'memoryXata',
|
||||||
|
'memoryZep',
|
||||||
|
];
|
||||||
|
|
||||||
|
const PROMPT_PROVIDER_NODE_NAMES = [CHAT_TRIGGER_NODE_TYPE];
|
||||||
|
|
||||||
|
type NodeWithType = Pick<INode, 'type'>;
|
||||||
|
|
||||||
|
export function adjustNewlyConnectedNodes(parent: NodeWithType, child: NodeWithType) {
|
||||||
|
if (!PROMPT_PROVIDER_NODE_NAMES.includes(child.type) && AI_NODES.includes(parent.type)) {
|
||||||
|
Object.assign<NodeWithType, Partial<INode>>(child, {
|
||||||
|
parameters: { promptType: 'define' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (PROMPT_PROVIDER_NODE_NAMES.includes(parent.type) && MEMORY_NODE_NAMES.includes(child.type)) {
|
||||||
|
Object.assign<NodeWithType, Partial<INode>>(child, {
|
||||||
|
parameters: { sessionIdType: 'customKey' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue