Concat plugin to app (#1799)

This commit is contained in:
Archer
2024-06-19 14:38:21 +08:00
committed by GitHub
parent b17d14bb7d
commit 565bfc8486
220 changed files with 5018 additions and 4667 deletions

View File

@@ -53,4 +53,5 @@ export const uniqueImageTypeList = Object.entries(mongoImageTypeMap)
export const FolderIcon = 'file/fill/folder';
export const FolderImgUrl = '/imgs/files/folder.svg';
export const HttpPluginImgUrl = '/imgs/app/httpPluginFill.svg';
export const HttpImgUrl = '/imgs/workflow/http.png';

View File

@@ -3,19 +3,10 @@ import { AppTTSConfigType, AppWhisperConfigType } from './type';
export enum AppTypeEnum {
folder = 'folder',
simple = 'simple',
advanced = 'advanced'
workflow = 'advanced',
plugin = 'plugin',
httpPlugin = 'httpPlugin'
}
export const AppTypeMap = {
[AppTypeEnum.folder]: {
label: 'folder'
},
[AppTypeEnum.simple]: {
label: 'simple'
},
[AppTypeEnum.advanced]: {
label: 'advanced'
}
};
export const defaultTTSConfig: AppTTSConfigType = { type: 'web' };

View File

@@ -0,0 +1,24 @@
import { ParentIdType } from 'common/parentFolder/type';
import { AppSchema } from './type';
import { AppTypeEnum } from './constants';
export type CreateAppProps = {
parentId?: ParentIdType;
name?: string;
avatar?: string;
intro?: string;
type?: AppTypeEnum;
modules: AppSchema['modules'];
edges?: AppSchema['edges'];
};
export type CreateHttpPluginChildrenPros = Omit<CreateAppProps, 'type'> & {
parentId: ParentIdType;
name: string;
intro: string;
avatar: string;
modules: AppSchema['modules'];
edges: AppSchema['edges'];
pluginData: {
pluginUniId: string;
};
};

View File

@@ -2,19 +2,20 @@ import { getNanoid } from '../../../common/string/tools';
import { OpenApiJsonSchema } from './type';
import yaml from 'js-yaml';
import { OpenAPIV3 } from 'openapi-types';
import { PluginTypeEnum } from '../constants';
import { FlowNodeInputItemType, FlowNodeOutputItemType } from '../../workflow/type/io.d';
import { FlowNodeInputItemType, FlowNodeOutputItemType } from '../../workflow/type/io';
import { FlowNodeInputTypeEnum, FlowNodeOutputTypeEnum } from '../../workflow/node/constant';
import { NodeInputKeyEnum, WorkflowIOValueTypeEnum } from '../../workflow/constants';
import { PluginInputModule } from '../../workflow/template/system/pluginInput';
import { PluginOutputModule } from '../../workflow/template/system/pluginOutput';
import { HttpModule468 } from '../../workflow/template/system/http468';
import { HttpParamAndHeaderItemType } from '../../workflow/api';
import { CreateOnePluginParams } from '../controller';
import { StoreNodeItemType } from '../../workflow/type';
import { HttpImgUrl } from '../../../common/file/image/constants';
import SwaggerParser from '@apidevtools/swagger-parser';
import { getHandleId } from '../../../core/workflow/utils';
import { getHandleId } from '../../workflow/utils';
import { CreateHttpPluginChildrenPros } from '../controller';
import { AppTypeEnum } from '../constants';
import type { StoreEdgeItemType } from '../../workflow/type/edge';
export const str2OpenApiSchema = async (yamlStr = ''): Promise<OpenApiJsonSchema> => {
try {
@@ -89,7 +90,7 @@ export const httpApiSchema2Plugins = async ({
parentId: string;
apiSchemaStr?: string;
customHeader?: string;
}): Promise<CreateOnePluginParams[]> => {
}): Promise<CreateHttpPluginChildrenPros[]> => {
const jsonSchema = await str2OpenApiSchema(apiSchemaStr);
const baseUrl = jsonSchema.serverPath;
@@ -400,7 +401,7 @@ export const httpApiSchema2Plugins = async ({
}
];
const edges = [
const edges: StoreEdgeItemType[] = [
{
source: pluginInputId,
target: httpId,
@@ -420,9 +421,12 @@ export const httpApiSchema2Plugins = async ({
avatar: HttpImgUrl,
intro: item.description,
parentId,
type: PluginTypeEnum.http,
type: AppTypeEnum.plugin,
modules,
edges
edges,
pluginData: {
pluginUniId: item.name
}
};
});
};

View File

@@ -25,6 +25,12 @@ export type AppSchema = {
modules: StoreNodeItemType[];
edges: StoreEdgeItemType[];
pluginData?: {
nodeVersion?: string;
pluginUniId?: string; // plugin unique id(plugin name)
apiSchemaStr?: string; // api schema string
customHeaders?: string;
};
// App system config
chatConfig: AppChatConfigType;
@@ -44,6 +50,7 @@ export type AppListItemType = {
type: AppTypeEnum;
defaultPermission: PermissionValueType;
permission: AppPermission;
pluginData?: AppSchema['pluginData'];
};
export type AppDetailType = AppSchema & {

View File

@@ -99,7 +99,7 @@ export const appWorkflow2Form = ({
if (!node.pluginId) return;
defaultAppForm.selectedTools.push({
id: node.pluginId,
id: node.nodeId,
pluginId: node.pluginId,
name: node.name,
avatar: node.avatar,

View File

@@ -1,12 +1,12 @@
import { StoreNodeItemType } from '../workflow/type';
import { StoreEdgeItemType } from '../workflow/type/edge';
import { AppChatConfigType } from './type';
import { AppChatConfigType, AppSchema } from './type';
export type AppVersionSchemaType = {
_id: string;
appId: string;
time: Date;
nodes: StoreNodeItemType[];
edges: StoreEdgeItemType[];
chatConfig: AppChatConfigType;
nodes: AppSchema['modules'];
edges: AppSchema['edges'];
chatConfig: AppSchema['chatConfig'];
};

View File

@@ -1,7 +1,7 @@
import { StoreEdgeItemType } from 'core/workflow/type/edge';
import type { StoreNodeItemType } from '../workflow/type';
import { PluginTypeEnum } from './constants';
import { HttpAuthMethodType } from './httpPlugin/type';
import { HttpAuthMethodType } from '../app/httpPlugin/type';
export type CreateOnePluginParams = {
name: string;

View File

@@ -24,6 +24,7 @@ export type PluginItemSchema = {
};
version?: 'v1' | 'v2';
nodeVersion?: string;
inited?: boolean;
};
/* plugin template */
@@ -33,7 +34,7 @@ export type PluginTemplateType = PluginRuntimeType & {
source: `${PluginSourceEnum}`;
templateType: FlowNodeTemplateType['templateType'];
intro: string;
nodeVersion: string;
version: string;
};
export type PluginRuntimeType = {

View File

@@ -118,3 +118,4 @@ export enum FlowNodeTypeEnum {
}
export const EDGE_TYPE = 'default';
export const defaultNodeVersion = '481';

View File

@@ -24,10 +24,7 @@ import { IfElseNode } from './system/ifElse/index';
import { VariableUpdateNode } from './system/variableUpdate';
import { CodeNode } from './system/sandbox';
/* app flow module templates */
export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
SystemConfigNode,
WorkflowStart,
const systemNodes: FlowNodeTemplateType[] = [
AiChatModule,
AssignedAnswerModule,
DatasetSearchModule,
@@ -44,49 +41,26 @@ export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
VariableUpdateNode,
CodeNode
];
/* app flow module templates */
export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
SystemConfigNode,
WorkflowStart,
...systemNodes
];
/* plugin flow module templates */
export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [
PluginInputModule,
PluginOutputModule,
AiChatModule,
AssignedAnswerModule,
DatasetSearchModule,
DatasetConcatModule,
RunAppModule,
ToolModule,
StopToolNode,
ClassifyQuestionModule,
ContextExtractModule,
HttpModule468,
AiQueryExtension,
LafModule,
IfElseNode,
VariableUpdateNode,
CodeNode
...systemNodes
];
/* all module */
export const moduleTemplatesFlat: FlowNodeTemplateType[] = [
...systemNodes,
EmptyNode,
SystemConfigNode,
WorkflowStart,
AiChatModule,
DatasetSearchModule,
DatasetConcatModule,
AssignedAnswerModule,
ClassifyQuestionModule,
ContextExtractModule,
HttpModule468,
ToolModule,
StopToolNode,
AiChatModule,
RunAppModule,
PluginInputModule,
PluginOutputModule,
RunPluginModule,
AiQueryExtension,
LafModule,
IfElseNode,
VariableUpdateNode,
CodeNode
RunPluginModule
];

View File

@@ -21,6 +21,8 @@ import { PluginTypeEnum } from '../../plugin/constants';
import { RuntimeEdgeItemType, StoreEdgeItemType } from './edge';
import { NextApiResponse } from 'next';
import { AppDetailType, AppSchema } from '../../app/type';
import { ParentIdType } from 'common/parentFolder/type';
import { AppTypeEnum } from 'core/app/constants';
export type FlowNodeCommonType = {
flowNodeType: FlowNodeTypeEnum; // render node card
@@ -37,8 +39,8 @@ export type FlowNodeCommonType = {
// plugin data
pluginId?: string;
pluginType?: `${PluginTypeEnum}`;
parentId?: string;
pluginType?: AppTypeEnum;
// parentId: ParentIdType;
};
export type FlowNodeTemplateType = FlowNodeCommonType & {
@@ -65,7 +67,6 @@ export type FlowNodeTemplateType = FlowNodeCommonType & {
// action
forbidDelete?: boolean; // forbid delete
unique?: boolean;
nodeVersion?: string;
};
export type FlowNodeItemType = FlowNodeTemplateType & {
nodeId: string;

View File

@@ -1,21 +1,7 @@
{
"extends":"../../tsconfig.json",
"compilerOptions": {
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": "."
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts"],
"exclude": ["node_modules"]
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts"]
}