feat(core): Update LLM applications building support (no-changelog) (#7710)
extracted out of #7336 --------- Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com> Co-authored-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Alex Grozav <alex@grozav.com>
This commit is contained in:
committed by
GitHub
parent
4a89504d54
commit
117962d473
47
packages/editor-ui/src/__tests__/defaults.ts
Normal file
47
packages/editor-ui/src/__tests__/defaults.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { INodeTypeData, INodeTypeDescription } from 'n8n-workflow';
|
||||
import {
|
||||
AGENT_NODE_TYPE,
|
||||
MANUAL_CHAT_TRIGGER_NODE_TYPE,
|
||||
MANUAL_TRIGGER_NODE_TYPE,
|
||||
} from '@/constants';
|
||||
import nodeTypesJson from '../../../nodes-base/dist/types/nodes.json';
|
||||
|
||||
const allNodeTypes = [...nodeTypesJson];
|
||||
|
||||
function findNodeWithName(name: string): INodeTypeDescription {
|
||||
return allNodeTypes.find((node) => node.name === name) as INodeTypeDescription;
|
||||
}
|
||||
|
||||
export const testingNodeTypes: INodeTypeData = {
|
||||
[MANUAL_TRIGGER_NODE_TYPE]: {
|
||||
sourcePath: '',
|
||||
type: {
|
||||
description: findNodeWithName(MANUAL_TRIGGER_NODE_TYPE),
|
||||
},
|
||||
},
|
||||
[MANUAL_CHAT_TRIGGER_NODE_TYPE]: {
|
||||
sourcePath: '',
|
||||
type: {
|
||||
description: findNodeWithName(MANUAL_CHAT_TRIGGER_NODE_TYPE),
|
||||
},
|
||||
},
|
||||
[AGENT_NODE_TYPE]: {
|
||||
sourcePath: '',
|
||||
type: {
|
||||
description: findNodeWithName(AGENT_NODE_TYPE),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const defaultMockNodeTypes: INodeTypeData = {
|
||||
[MANUAL_TRIGGER_NODE_TYPE]: testingNodeTypes[MANUAL_TRIGGER_NODE_TYPE],
|
||||
};
|
||||
|
||||
export function mockNodeTypesToArray(nodeTypes: INodeTypeData): INodeTypeDescription[] {
|
||||
return Object.values(nodeTypes).map(
|
||||
(nodeType) => nodeType.type.description as INodeTypeDescription,
|
||||
);
|
||||
}
|
||||
|
||||
export const defaultMockNodeTypesArray: INodeTypeDescription[] =
|
||||
mockNodeTypesToArray(defaultMockNodeTypes);
|
||||
111
packages/editor-ui/src/__tests__/mocks.ts
Normal file
111
packages/editor-ui/src/__tests__/mocks.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import type {
|
||||
INodeType,
|
||||
INodeTypeData,
|
||||
INodeTypes,
|
||||
IVersionedNodeType,
|
||||
IConnections,
|
||||
IDataObject,
|
||||
INode,
|
||||
IPinData,
|
||||
IWorkflowSettings,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeHelpers, Workflow } from 'n8n-workflow';
|
||||
import { uuid } from '@jsplumb/util';
|
||||
import { defaultMockNodeTypes } from '@/__tests__/defaults';
|
||||
import type {
|
||||
INodeUi,
|
||||
ITag,
|
||||
IUsedCredential,
|
||||
IUser,
|
||||
IWorkflowDb,
|
||||
WorkflowMetadata,
|
||||
} from '@/Interface';
|
||||
|
||||
export function createTestNodeTypes(data: INodeTypeData = {}): INodeTypes {
|
||||
const getResolvedKey = (key: string) => {
|
||||
const resolvedKeyParts = key.split(/[\/.]/);
|
||||
return resolvedKeyParts[resolvedKeyParts.length - 1];
|
||||
};
|
||||
|
||||
const nodeTypes = {
|
||||
...defaultMockNodeTypes,
|
||||
...Object.keys(data).reduce<INodeTypeData>((acc, key) => {
|
||||
acc[getResolvedKey(key)] = data[key];
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
|
||||
function getByName(nodeType: string): INodeType | IVersionedNodeType {
|
||||
return nodeTypes[getResolvedKey(nodeType)].type;
|
||||
}
|
||||
|
||||
function getByNameAndVersion(nodeType: string, version?: number): INodeType {
|
||||
return NodeHelpers.getVersionedNodeType(getByName(nodeType), version);
|
||||
}
|
||||
|
||||
return {
|
||||
getByName,
|
||||
getByNameAndVersion,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestWorkflowObject(options: {
|
||||
id?: string;
|
||||
name?: string;
|
||||
nodes: INode[];
|
||||
connections: IConnections;
|
||||
active?: boolean;
|
||||
nodeTypes?: INodeTypeData;
|
||||
staticData?: IDataObject;
|
||||
settings?: IWorkflowSettings;
|
||||
pinData?: IPinData;
|
||||
}) {
|
||||
return new Workflow({
|
||||
...options,
|
||||
id: options.id ?? uuid(),
|
||||
active: options.active ?? false,
|
||||
nodeTypes: createTestNodeTypes(options.nodeTypes),
|
||||
connections: options.connections ?? {},
|
||||
});
|
||||
}
|
||||
|
||||
export function createTestWorkflow(options: {
|
||||
id?: string;
|
||||
name: string;
|
||||
active?: boolean;
|
||||
createdAt?: number | string;
|
||||
updatedAt?: number | string;
|
||||
nodes?: INodeUi[];
|
||||
connections?: IConnections;
|
||||
settings?: IWorkflowSettings;
|
||||
tags?: ITag[] | string[];
|
||||
pinData?: IPinData;
|
||||
sharedWith?: Array<Partial<IUser>>;
|
||||
ownedBy?: Partial<IUser>;
|
||||
versionId?: string;
|
||||
usedCredentials?: IUsedCredential[];
|
||||
meta?: WorkflowMetadata;
|
||||
}): IWorkflowDb {
|
||||
return {
|
||||
...options,
|
||||
createdAt: options.createdAt ?? '',
|
||||
updatedAt: options.updatedAt ?? '',
|
||||
versionId: options.versionId ?? '',
|
||||
id: options.id ?? uuid(),
|
||||
active: options.active ?? false,
|
||||
connections: options.connections ?? {},
|
||||
} as IWorkflowDb;
|
||||
}
|
||||
|
||||
export function createTestNode(
|
||||
node: Partial<INode> & { name: INode['name']; type: INode['type'] },
|
||||
): INode {
|
||||
return {
|
||||
id: uuid(),
|
||||
typeVersion: 1,
|
||||
position: [0, 0] as [number, number],
|
||||
parameters: {},
|
||||
...node,
|
||||
};
|
||||
}
|
||||
@@ -41,6 +41,7 @@ const defaultSettings: IN8nUISettings = {
|
||||
oauthCallbackUrls: { oauth1: '', oauth2: '' },
|
||||
onboardingCallPromptEnabled: false,
|
||||
personalizationSurveyEnabled: false,
|
||||
releaseChannel: 'stable',
|
||||
posthog: {
|
||||
apiHost: '',
|
||||
apiKey: '',
|
||||
|
||||
Reference in New Issue
Block a user