Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Node template card #54

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/global/common/file/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* mongo fs bucket */
export enum BucketNameEnum {
dataset = 'dataset'
}
Expand All @@ -7,4 +8,4 @@ export const bucketNameMap = {
}
};

export const FileBaseUrl = '/api/common/file/read';
export const ReadFileBaseUrl = '/api/common/file/read';
4 changes: 4 additions & 0 deletions packages/global/common/file/image/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ export const mongoImageTypeMap = {
export const uniqueImageTypeList = Object.entries(mongoImageTypeMap)
.filter(([key, value]) => value.unique)
.map(([key]) => key as `${MongoImageTypeEnum}`);

export const FolderIcon = 'file/fill/folder';
export const FolderImgUrl = '/imgs/files/folder.svg';
export const HttpImgUrl = '/imgs/module/http.png';
3 changes: 0 additions & 3 deletions packages/global/core/dataset/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,5 @@ export const SearchScoreTypeMap = {
}
};

export const FolderIcon = 'file/fill/folder';
export const FolderImgUrl = '/imgs/files/folder.svg';

export const CustomCollectionIcon = 'common/linkBlue';
export const LinkCollectionIcon = 'common/linkBlue';
5 changes: 5 additions & 0 deletions packages/global/core/module/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../chat/type';
import { ChatNodeUsageType } from '../../support/wallet/bill/type';
import { RunningModuleItemType } from './runtime/type';
import { PluginTypeEnum } from 'core/plugin/constants';

export type FlowNodeTemplateType = {
id: string; // module id, unique
Expand All @@ -27,6 +28,10 @@ export type FlowNodeTemplateType = {
showStatus?: boolean; // chatting response step status
inputs: FlowNodeInputItemType[];
outputs: FlowNodeOutputItemType[];

// plugin data
pluginType?: `${PluginTypeEnum}`;
parentId?: string;
};
export type FlowModuleItemType = FlowNodeTemplateType & {
moduleId: string;
Expand Down
17 changes: 16 additions & 1 deletion packages/global/core/plugin/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@ export const defaultModules: ModuleItemType[] = [

export enum PluginTypeEnum {
folder = 'folder',
plugin = 'plugin'
custom = 'custom',
http = 'http'
}
export const pluginTypeMap = {
[PluginTypeEnum.folder]: {
label: '文件夹',
icon: 'file/fill/folder'
},
[PluginTypeEnum.custom]: {
label: '自定义',
icon: 'common/custom'
},
[PluginTypeEnum.http]: {
label: 'HTTP',
icon: 'common/http'
}
};

export enum PluginSourceEnum {
personal = 'personal',
Expand Down
9 changes: 6 additions & 3 deletions packages/global/core/plugin/httpPlugin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HttpModule468 } from '../../module/template/system/http468';
import { HttpParamAndHeaderItemType } from '../../module/api';
import { CreateOnePluginParams } from '../controller';
import { ModuleItemType } from '../../module/type';
import { HttpImgUrl } from '../../../common/file/image/constants';

export const str2OpenApiSchema = (yamlStr = ''): OpenApiJsonSchema => {
try {
Expand All @@ -28,7 +29,9 @@ export const str2OpenApiSchema = (yamlStr = ''): OpenApiJsonSchema => {
.map((path) => {
const methodData: any = data.paths[path];
return Object.keys(methodData)
.filter((method) => ['get', 'post', 'put', 'delete', 'patch'].includes(method))
.filter((method) =>
['get', 'post', 'put', 'delete', 'patch'].includes(method.toLocaleLowerCase())
)
.map((method) => {
const methodInfo = methodData[method];
if (methodInfo.deprecated) return;
Expand Down Expand Up @@ -503,10 +506,10 @@ export const httpApiSchema2Plugins = ({

return {
name: item.name,
avatar: '/icon/logo.svg',
avatar: HttpImgUrl,
intro: item.description,
parentId,
type: PluginTypeEnum.plugin,
type: PluginTypeEnum.http,
modules
};
});
Expand Down
7 changes: 3 additions & 4 deletions packages/service/core/plugin/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PluginTypeEnum } from '@fastgpt/global/core/plugin/constants';
import { pluginTypeMap } from '@fastgpt/global/core/plugin/constants';
import { connectionMongo, type Model } from '../../common/mongo';
const { Schema, model, models } = connectionMongo;
import type { PluginItemSchema } from '@fastgpt/global/core/plugin/type.d';
Expand Down Expand Up @@ -27,9 +27,8 @@ const PluginSchema = new Schema({
},
type: {
type: String,
enum: Object.keys(PluginTypeEnum),
required: true,
default: PluginTypeEnum.plugin
enum: Object.keys(pluginTypeMap),
required: true
},
name: {
type: String,
Expand Down
105 changes: 63 additions & 42 deletions projects/app/src/components/core/module/Flow/ModuleTemplateList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useMemo, useState } from 'react';
import { Box, Flex } from '@chakra-ui/react';
import { Box, Flex, IconButton } from '@chakra-ui/react';
import type {
FlowNodeTemplateType,
moduleTemplateListType
Expand All @@ -24,6 +24,7 @@ import { useRequest } from '@/web/common/hooks/useRequest';
import ParentPaths from '@/components/common/ParentPaths';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { useRouter } from 'next/router';
import { PluginTypeEnum } from '@fastgpt/global/core/plugin/constants';

type ModuleTemplateListProps = {
isOpen: boolean;
Expand Down Expand Up @@ -89,50 +90,62 @@ const ModuleTemplateList = ({ isOpen, onClose }: ModuleTemplateListProps) => {
top={0}
left={0}
bottom={0}
w={'360px'}
w={`${sliderWidth}px`}
onClick={onClose}
/>
<Flex
zIndex={3}
flexDirection={'column'}
position={'absolute'}
top={'65px'}
top={'10px'}
left={0}
pt={'20px'}
pb={4}
h={isOpen ? 'calc(100% - 100px)' : '0'}
h={isOpen ? 'calc(100% - 20px)' : '0'}
w={isOpen ? ['100%', `${sliderWidth}px`] : '0'}
bg={'white'}
boxShadow={'3px 0 20px rgba(0,0,0,0.2)'}
borderRadius={'20px'}
overflow={'hidden'}
borderRadius={'0 20px 20px 0'}
transition={'.2s ease'}
userSelect={'none'}
overflow={isOpen ? 'none' : 'hidden'}
>
<Box mb={2} px={'20px'} whiteSpace={'nowrap'}>
<RowTabs
list={[
{
icon: 'core/modules/basicNode',
label: t('core.module.template.Basic Node'),
value: TemplateTypeEnum.basic
},
{
icon: 'core/modules/systemPlugin',
label: t('core.module.template.System Plugin'),
value: TemplateTypeEnum.systemPlugin
},
{
icon: 'core/modules/teamPlugin',
label: t('core.module.template.Team Plugin'),
value: TemplateTypeEnum.teamPlugin
}
]}
w={'100%'}
py={'5px'}
value={templateType}
onChange={onChangeTab}
/>
<Box mb={2} pl={'20px'} pr={'10px'} whiteSpace={'nowrap'}>
<Flex flex={'1 0 0'} alignItems={'center'} gap={3}>
<RowTabs
list={[
{
icon: 'core/modules/basicNode',
label: t('core.module.template.Basic Node'),
value: TemplateTypeEnum.basic
},
{
icon: 'core/modules/systemPlugin',
label: t('core.module.template.System Plugin'),
value: TemplateTypeEnum.systemPlugin
},
{
icon: 'core/modules/teamPlugin',
label: t('core.module.template.Team Plugin'),
value: TemplateTypeEnum.teamPlugin
}
]}
py={'5px'}
value={templateType}
onChange={onChangeTab}
/>
{/* close icon */}
<IconButton
size={'sm'}
icon={<MyIcon name={'common/backFill'} w={'14px'} color={'myGray.700'} />}
w={'26px'}
h={'26px'}
borderColor={'myGray.300'}
variant={'grayBase'}
aria-label={''}
onClick={onClose}
/>
</Flex>
{templateType === TemplateTypeEnum.teamPlugin && (
<Flex mt={2} alignItems={'center'} h={10}>
{currentParent.parentId !== 'null' && (
Expand Down Expand Up @@ -262,38 +275,46 @@ const RenderList = React.memo(function RenderList({

<>
{item.list
.filter((template: any) =>
.filter((template) =>
item.type === 'personalPlugin'
? template.parentId === currentParent.parentId
: true
)
.map((template: any) => (
.map((template) => (
<Flex
key={template.id}
alignItems={'center'}
p={5}
cursor={'pointer'}
_hover={{ bg: 'myWhite.600' }}
borderRadius={'sm'}
draggable={template.type === 'plugin'}
draggable={template.pluginType !== PluginTypeEnum.folder}
onDragEnd={(e) => {
if (e.clientX < 360) return;
if (e.clientX < sliderWidth) return;
onAddNode({
template: template,
position: { x: e.clientX, y: e.clientY }
});
}}
onClick={(e) => {
if (isPc && template.type === 'plugin') return;
if (template.type === 'plugin') {
onClose();
onAddNode({
template: template,
position: { x: e.clientX, y: e.clientY }
console.log(template);
if (template.pluginType === PluginTypeEnum.folder) {
return setCurrentParent({
parentId: template.id,
parentName: template.name
});
} else {
setCurrentParent({ parentId: template.id, parentName: template.name });
}
if (isPc) {
return onAddNode({
template,
position: { x: sliderWidth * 1.5, y: 200 }
});
}
onAddNode({
template: template,
position: { x: e.clientX, y: e.clientY }
});
onClose();
}}
>
<Avatar
Expand Down
49 changes: 49 additions & 0 deletions projects/app/src/pages/api/admin/initv47.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response';
import { connectToDatabase } from '@/service/mongo';
import { authCert } from '@fastgpt/service/support/permission/auth/common';
import { MongoUsage } from '@fastgpt/service/support/wallet/usage/schema';
import { connectionMongo } from '@fastgpt/service/common/mongo';
import { checkFiles } from '../timerTask/dataset/checkInValidDatasetFiles';
import { addHours } from 'date-fns';
import { checkInvalid as checkInvalidImg } from '../timerTask/dataset/checkInvalidDatasetImage';
import { checkInvalidCollection } from '../timerTask/dataset/checkInvalidMongoCollection';
import { checkInvalidVector } from '../timerTask/dataset/checkInvalidVector';
import { MongoPlugin } from '@fastgpt/service/core/plugin/schema';
import { PluginTypeEnum } from '@fastgpt/global/core/plugin/constants';

/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await connectToDatabase();
await authCert({ req, authRoot: true });

await MongoPlugin.updateMany(
{ type: { $exists: false } },
{
$set: {
type: PluginTypeEnum.custom
}
}
);
await MongoPlugin.updateMany(
{ parentId: { $exists: false } },
{
$set: {
parentId: null
}
}
);

jsonRes(res, {
message: 'success'
});
} catch (error) {
console.log(error);

jsonRes(res, {
code: 500,
error
});
}
}
4 changes: 2 additions & 2 deletions projects/app/src/pages/api/core/dataset/file/getPreviewUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jsonRes } from '@fastgpt/service/common/response';
import { connectToDatabase } from '@/service/mongo';
import { authDatasetFile } from '@fastgpt/service/support/permission/auth/dataset';
import { createFileToken } from '@fastgpt/service/support/permission/controller';
import { BucketNameEnum, FileBaseUrl } from '@fastgpt/global/common/file/constants';
import { BucketNameEnum, ReadFileBaseUrl } from '@fastgpt/global/common/file/constants';

export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
try {
Expand All @@ -25,7 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
});

jsonRes(res, {
data: `${FileBaseUrl}?token=${token}`
data: `${ReadFileBaseUrl}?token=${token}`
});
} catch (error) {
jsonRes(res, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const data: FlowNodeTemplateType[] = userPlugins.map((plugin) => ({
id: String(plugin._id),
parentId: String(plugin.parentId),
type: plugin.type,
pluginType: plugin.type,
templateType: FlowNodeTemplateTypeEnum.personalPlugin,
flowType: FlowNodeTypeEnum.pluginModule,
avatar: plugin.avatar,
Expand Down
8 changes: 2 additions & 6 deletions projects/app/src/pages/dataset/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ import Avatar from '@/components/Avatar';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { serviceSideProps } from '@/web/common/utils/i18n';
import dynamic from 'next/dynamic';
import {
DatasetTypeEnum,
DatasetTypeMap,
FolderIcon,
FolderImgUrl
} from '@fastgpt/global/core/dataset/constants';
import { DatasetTypeEnum, DatasetTypeMap } from '@fastgpt/global/core/dataset/constants';
import { FolderImgUrl, FolderIcon } from '@fastgpt/global/common/file/image/constants';
import MyMenu from '@/components/MyMenu';
import { useRequest } from '@/web/common/hooks/useRequest';
import { useSystemStore } from '@/web/common/system/useSystemStore';
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/pages/plugin/list/component/EditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const defaultForm: EditFormType = {
name: '',
intro: '',
parentId: null,
type: PluginTypeEnum.plugin,
type: PluginTypeEnum.custom,
modules: [
{
moduleId: nanoid(),
Expand Down
Loading
Loading