mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
v4.6.2-alpah (#511)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { AppTypeMap } from '@fastgpt/global/core/app/constants';
|
||||
import { connectionMongo, type Model } from '../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import type { AppSchema as AppType } from '@fastgpt/global/core/app/type.d';
|
||||
@@ -31,7 +32,11 @@ const AppSchema = new Schema({
|
||||
type: {
|
||||
type: String,
|
||||
default: 'advanced',
|
||||
enum: ['basic', 'advanced']
|
||||
enum: Object.keys(AppTypeMap)
|
||||
},
|
||||
simpleTemplateId: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
avatar: {
|
||||
type: String,
|
||||
@@ -61,6 +66,7 @@ const AppSchema = new Schema({
|
||||
|
||||
try {
|
||||
AppSchema.index({ updateTime: -1 });
|
||||
AppSchema.index({ teamId: 1 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { connectionMongo, type Model } from '../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import { ChatItemSchema as ChatItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { ChatRoleMap, TaskResponseKeyEnum } from '@fastgpt/global/core/chat/constants';
|
||||
import { ChatRoleMap } from '@fastgpt/global/core/chat/constants';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);
|
||||
import {
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from '@fastgpt/global/support/user/team/constant';
|
||||
import { appCollectionName } from '../app/schema';
|
||||
import { userCollectionName } from '../../support/user/schema';
|
||||
import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
|
||||
|
||||
const ChatItemSchema = new Schema({
|
||||
dataId: {
|
||||
@@ -65,7 +66,7 @@ const ChatItemSchema = new Schema({
|
||||
a: String
|
||||
}
|
||||
},
|
||||
[TaskResponseKeyEnum.responseData]: {
|
||||
[ModuleOutputKeyEnum.responseData]: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
|
@@ -1,16 +1,13 @@
|
||||
import { connectionMongo, type Model } from '../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import { ChatSchema as ChatType } from '@fastgpt/global/core/chat/type.d';
|
||||
import {
|
||||
ChatRoleMap,
|
||||
ChatSourceMap,
|
||||
TaskResponseKeyEnum
|
||||
} from '@fastgpt/global/core/chat/constants';
|
||||
import { ChatRoleMap, ChatSourceMap } from '@fastgpt/global/core/chat/constants';
|
||||
import {
|
||||
TeamCollectionName,
|
||||
TeamMemberCollectionName
|
||||
} from '@fastgpt/global/support/user/team/constant';
|
||||
import { appCollectionName } from '../app/schema';
|
||||
import { ModuleOutputKeyEnum } from '@fastgpt/global/core/module/constants';
|
||||
|
||||
export const chatCollectionName = 'chat';
|
||||
|
||||
@@ -81,7 +78,7 @@ const ChatSchema = new Schema({
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
[TaskResponseKeyEnum.responseData]: {
|
||||
[ModuleOutputKeyEnum.responseData]: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
|
@@ -43,6 +43,14 @@ const DatasetDataSchema = new Schema({
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
qToken: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
aToken: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
indexes: {
|
||||
type: [
|
||||
{
|
||||
@@ -70,9 +78,11 @@ const DatasetDataSchema = new Schema({
|
||||
});
|
||||
|
||||
try {
|
||||
DatasetDataSchema.index({ userId: 1 });
|
||||
DatasetDataSchema.index({ teamId: 1 });
|
||||
DatasetDataSchema.index({ datasetId: 1 });
|
||||
DatasetDataSchema.index({ collectionId: 1 });
|
||||
// full text index
|
||||
DatasetDataSchema.index({ qToken: 'text', aToken: 'text' });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
@@ -1,40 +1,100 @@
|
||||
import { MongoPlugin } from './schema';
|
||||
import { FlowModuleTemplateType } from '@fastgpt/global/core/module/type';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/module/node/constant';
|
||||
import { formatPluginIOModules } from '@fastgpt/global/core/module/utils';
|
||||
import { formatPluginToPreviewModule } from '@fastgpt/global/core/module/utils';
|
||||
import { PluginType2TemplateTypeMap, PluginTypeEnum } from '@fastgpt/global/core/plugin/constants';
|
||||
import type { PluginTemplateType } from '@fastgpt/global/core/plugin/type.d';
|
||||
|
||||
/* plugin templates */
|
||||
export async function getUserPlugins2Templates({
|
||||
teamId
|
||||
}: {
|
||||
teamId: string;
|
||||
}): Promise<FlowModuleTemplateType[]> {
|
||||
const plugins = await MongoPlugin.find({ teamId }).lean();
|
||||
/*
|
||||
plugin id rule:
|
||||
personal: id
|
||||
community: community-id
|
||||
commercial: commercial-id
|
||||
*/
|
||||
|
||||
return plugins.map((plugin) => ({
|
||||
id: String(plugin._id),
|
||||
flowType: FlowNodeTypeEnum.pluginModule,
|
||||
logo: plugin.avatar,
|
||||
name: plugin.name,
|
||||
description: plugin.intro,
|
||||
intro: plugin.intro,
|
||||
showStatus: false,
|
||||
inputs: [],
|
||||
outputs: []
|
||||
}));
|
||||
export async function splitCombinePluginId(id: string) {
|
||||
const splitRes = id.split('-');
|
||||
if (splitRes.length === 1 && id.length === 24) {
|
||||
return {
|
||||
type: PluginTypeEnum.personal,
|
||||
pluginId: id
|
||||
};
|
||||
}
|
||||
|
||||
const [type, pluginId] = id.split('-') as [`${PluginTypeEnum}`, string];
|
||||
if (!type || !pluginId) return Promise.reject('pluginId not found');
|
||||
|
||||
return { type, pluginId: id };
|
||||
}
|
||||
/* one plugin 2 module detail */
|
||||
export async function getPluginModuleDetail({ id }: { id: string }) {
|
||||
const plugin = await MongoPlugin.findById(id);
|
||||
/* format plugin modules to plugin preview module */
|
||||
export async function getPluginPreviewModule({
|
||||
id
|
||||
}: {
|
||||
id: string;
|
||||
}): Promise<FlowModuleTemplateType> {
|
||||
// classify
|
||||
const { type, pluginId } = await splitCombinePluginId(id);
|
||||
|
||||
const plugin = await (async () => {
|
||||
if (type === PluginTypeEnum.community) {
|
||||
return global.communityPlugins?.find((plugin) => plugin.id === pluginId);
|
||||
}
|
||||
if (type === PluginTypeEnum.personal) {
|
||||
const item = await MongoPlugin.findById(id);
|
||||
if (!item) return undefined;
|
||||
return {
|
||||
id: String(item._id),
|
||||
name: item.name,
|
||||
avatar: item.avatar,
|
||||
intro: item.intro,
|
||||
type: PluginTypeEnum.personal,
|
||||
modules: item.modules
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
if (!plugin) return Promise.reject('plugin not found');
|
||||
return {
|
||||
id: String(plugin._id),
|
||||
id: plugin.id,
|
||||
templateType: PluginType2TemplateTypeMap[plugin.type],
|
||||
flowType: FlowNodeTypeEnum.pluginModule,
|
||||
logo: plugin.avatar,
|
||||
avatar: plugin.avatar,
|
||||
name: plugin.name,
|
||||
description: plugin.intro,
|
||||
intro: plugin.intro,
|
||||
showStatus: false,
|
||||
...formatPluginIOModules(String(plugin._id), plugin.modules)
|
||||
showStatus: true,
|
||||
...formatPluginToPreviewModule(plugin.id, plugin.modules)
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPluginRuntimeById(id: string): Promise<PluginTemplateType> {
|
||||
const { type, pluginId } = await splitCombinePluginId(id);
|
||||
|
||||
const plugin = await (async () => {
|
||||
if (type === PluginTypeEnum.community) {
|
||||
return global.communityPlugins?.find((plugin) => plugin.id === pluginId);
|
||||
}
|
||||
if (type === PluginTypeEnum.personal) {
|
||||
const item = await MongoPlugin.findById(id);
|
||||
if (!item) return undefined;
|
||||
return {
|
||||
id: String(item._id),
|
||||
name: item.name,
|
||||
avatar: item.avatar,
|
||||
intro: item.intro,
|
||||
type: PluginTypeEnum.personal,
|
||||
modules: item.modules
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
if (!plugin) return Promise.reject('plugin not found');
|
||||
|
||||
return {
|
||||
id: plugin.id,
|
||||
type: plugin.type,
|
||||
name: plugin.name,
|
||||
avatar: plugin.avatar,
|
||||
intro: plugin.intro,
|
||||
modules: plugin.modules
|
||||
};
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import {
|
||||
TeamMemberCollectionName
|
||||
} from '@fastgpt/global/support/user/team/constant';
|
||||
|
||||
export const ModuleCollectionName = 'plugins';
|
||||
export const PluginCollectionName = 'plugins';
|
||||
|
||||
const PluginSchema = new Schema({
|
||||
userId: {
|
||||
@@ -52,5 +52,5 @@ try {
|
||||
}
|
||||
|
||||
export const MongoPlugin: Model<PluginItemSchema> =
|
||||
models[ModuleCollectionName] || model(ModuleCollectionName, PluginSchema);
|
||||
models[PluginCollectionName] || model(PluginCollectionName, PluginSchema);
|
||||
MongoPlugin.syncIndexes();
|
||||
|
31
packages/service/core/plugin/store/schema.ts
Normal file
31
packages/service/core/plugin/store/schema.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { connectionMongo, type Model } from '../../../common/mongo';
|
||||
const { Schema, model, models } = connectionMongo;
|
||||
import type { PluginItemSchema } from '@fastgpt/global/core/plugin/type.d';
|
||||
|
||||
import { PluginCollectionName } from '../schema';
|
||||
|
||||
export const ModuleCollectionName = 'plugins';
|
||||
|
||||
const PluginStoreSchema = new Schema({
|
||||
pluginId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: PluginCollectionName,
|
||||
required: true
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
updateTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
modules: {
|
||||
type: Array,
|
||||
default: []
|
||||
}
|
||||
});
|
||||
|
||||
export const MongoPluginStore: Model<PluginItemSchema> =
|
||||
models[ModuleCollectionName] || model(ModuleCollectionName, PluginStoreSchema);
|
||||
MongoPluginStore.syncIndexes();
|
5
packages/service/core/plugin/type.d.ts
vendored
Normal file
5
packages/service/core/plugin/type.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PluginTemplateType } from '@fastgpt/global/core/plugin/type.d';
|
||||
|
||||
declare global {
|
||||
var communityPlugins: PluginTemplateType[];
|
||||
}
|
Reference in New Issue
Block a user