feat(editor): Support node-creator actions for vector store nodes (#11032)

This commit is contained in:
oleg
2024-10-01 14:10:08 +02:00
committed by GitHub
parent 3a9c65e1cb
commit 72b70d9d98
7 changed files with 94 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ import { useNodeCreatorStore } from '@/stores/nodeCreator.store';
import NodeIcon from '@/components/NodeIcon.vue';
import { useActions } from '../composables/useActions';
import { useViewStacks } from '../composables/useViewStacks';
import { useI18n } from '@/composables/useI18n';
import { useTelemetry } from '@/composables/useTelemetry';
import { useNodeType } from '@/composables/useNodeType';
@@ -34,6 +35,7 @@ const telemetry = useTelemetry();
const { actions } = useNodeCreatorStore();
const { getAddedNodesAndConnections } = useActions();
const { activeViewStack } = useViewStacks();
const { isSubNodeType } = useNodeType({
nodeType: props.nodeType,
});
@@ -61,7 +63,7 @@ const dataTestId = computed(() =>
);
const hasActions = computed(() => {
return nodeActions.value.length > 1;
return nodeActions.value.length > 1 && !activeViewStack.hideActions;
});
const nodeActions = computed(() => {

View File

@@ -90,7 +90,8 @@ function onSelected(item: INodeCreateElement) {
if (item.type === 'node') {
const nodeActions = actions?.[item.key] || [];
if (nodeActions.length <= 1) {
// Only show actions if there are more than one or if the view is not an AI subcategory
if (nodeActions.length <= 1 || activeViewStack.value.hideActions) {
selectNodeType([item.key]);
return;
}

View File

@@ -1,5 +1,5 @@
import type { ActionTypeDescription, ActionsRecord, SimplifiedNodeType } from '@/Interface';
import { CUSTOM_API_CALL_KEY, HTTP_REQUEST_NODE_TYPE } from '@/constants';
import { AI_SUBCATEGORY, CUSTOM_API_CALL_KEY, HTTP_REQUEST_NODE_TYPE } from '@/constants';
import { memoize, startCase } from 'lodash-es';
import type {
ICredentialType,
@@ -97,6 +97,36 @@ function operationsCategory(nodeTypeDescription: INodeTypeDescription): ActionTy
return items;
}
function modeCategory(nodeTypeDescription: INodeTypeDescription): ActionTypeDescription[] {
// Mode actions should only be available for AI nodes
const isAINode = nodeTypeDescription.codex?.categories?.includes(AI_SUBCATEGORY);
if (!isAINode) return [];
const matchedProperty = nodeTypeDescription.properties.find(
(property) => property.name?.toLowerCase() === 'mode',
);
if (!matchedProperty?.options) return [];
const modeOptions = matchedProperty.options as INodePropertyOptions[];
const items = modeOptions.map((item: INodePropertyOptions) => ({
...getNodeTypeBase(nodeTypeDescription),
actionKey: item.value as string,
displayName: item.action ?? startCase(item.name),
description: item.description ?? '',
displayOptions: matchedProperty.displayOptions,
values: {
[matchedProperty.name]: item.value,
},
}));
// Do not return empty category
if (items.length === 0) return [];
return items;
}
function triggersCategory(nodeTypeDescription: INodeTypeDescription): ActionTypeDescription[] {
const matchingKeys = ['event', 'events', 'trigger on'];
const isTrigger = nodeTypeDescription.displayName?.toLowerCase().includes('trigger');
@@ -231,7 +261,12 @@ export function useActionsGenerator() {
function generateNodeActions(node: INodeTypeDescription | undefined) {
if (!node) return [];
if (node.codex?.subcategories?.AI?.includes('Tools')) return [];
return [...triggersCategory(node), ...operationsCategory(node), ...resourceCategories(node)];
return [
...triggersCategory(node),
...operationsCategory(node),
...resourceCategories(node),
...modeCategory(node),
];
}
function filterActions(actions: ActionTypeDescription[]) {
// Do not show single action nodes

View File

@@ -68,6 +68,7 @@ interface ViewStack {
searchItems?: SimplifiedNodeType[];
forceIncludeNodes?: string[];
mode?: 'actions' | 'nodes';
hideActions?: boolean;
baseFilter?: (item: INodeCreateElement) => boolean;
itemsMapper?: (item: INodeCreateElement) => INodeCreateElement;
panelClass?: string;
@@ -344,6 +345,7 @@ export const useViewStacks = defineStore('nodeCreatorViewStacks', () => {
subcategory: connectionType,
};
},
hideActions: true,
preventBack: true,
});
}