Files
FastGPT/packages/service/core/app/schema.ts
Archer fb368a581c Perf input guide (#1557)
* perf: input guide code

* perf: input guide ui

* Chat input guide api

* Update app chat config store

* perf: app chat config field

* perf: app context

* perf: params

* fix: ts

* perf: filter private config

* perf: filter private config

* perf: import workflow

* perf: limit max tip amount
2024-05-21 17:52:04 +08:00

116 lines
2.2 KiB
TypeScript

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';
import { PermissionTypeEnum, PermissionTypeMap } from '@fastgpt/global/support/permission/constant';
import {
TeamCollectionName,
TeamMemberCollectionName
} from '@fastgpt/global/support/user/team/constant';
export const AppCollectionName = 'apps';
export const chatConfigType = {
welcomeText: String,
variables: Array,
questionGuide: Boolean,
ttsConfig: Object,
whisperConfig: Object,
scheduledTriggerConfig: Object,
chatInputGuide: Object
};
const AppSchema = new Schema({
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
tmbId: {
type: Schema.Types.ObjectId,
ref: TeamMemberCollectionName,
required: true
},
name: {
type: String,
required: true
},
type: {
type: String,
default: 'advanced',
enum: Object.keys(AppTypeMap)
},
version: {
type: String,
enum: ['v1', 'v2']
},
avatar: {
type: String,
default: '/icon/logo.svg'
},
intro: {
type: String,
default: ''
},
updateTime: {
type: Date,
default: () => new Date()
},
// role and auth
permission: {
type: String,
enum: Object.keys(PermissionTypeMap),
default: PermissionTypeEnum.private
},
teamTags: {
type: [String]
},
// tmp store
modules: {
type: Array,
default: []
},
edges: {
type: Array,
default: []
},
chatConfig: {
type: chatConfigType,
default: {}
},
scheduledTriggerConfig: {
cronString: {
type: String
},
timezone: {
type: String
},
defaultPrompt: {
type: String
}
},
scheduledTriggerNextTime: {
type: Date
},
inited: {
type: Boolean
}
});
try {
AppSchema.index({ updateTime: -1 });
AppSchema.index({ teamId: 1 });
AppSchema.index({ scheduledTriggerConfig: 1, intervalNextTime: -1 });
} catch (error) {
console.log(error);
}
export const MongoApp: Model<AppType> =
models[AppCollectionName] || model(AppCollectionName, AppSchema);
MongoApp.syncIndexes();