FastGPT/packages/service/core/chat/chatItemSchema.ts
Archer af669a1cfc
4.14.4 features (#6090)
* perf: zod with app log (#6083)

* perf: safe decode

* perf: zod with app log

* fix: text

* remove log

* rename field

* refactor: improve like/dislike interaction (#6080)

* refactor: improve like/dislike interaction

* button style & merge status

* perf

* fix

* i18n

* feedback ui

* format

* api optimize

* openapi

* read status

---------

Co-authored-by: archer <545436317@qq.com>

* perf: remove empty chat

* perf: delete resource tip

* fix: confirm

* feedback filter

* fix: ts

* perf: linker scroll

* perf: feedback ui

* fix: plugin file input store

* fix: max tokens

* update comment

* fix: condition value type

* fix feedback (#6095)

* fix feedback

* text

* list

* fix: versionid

---------

Co-authored-by: archer <545436317@qq.com>

* fix: chat setting render;export logs filter

* add test

* perf: log list api

* perf: redirect check

* perf: log list

* create ui

* create ui

---------

Co-authored-by: heheer <heheer@sealos.io>
2025-12-15 23:36:54 +08:00

106 lines
2.5 KiB
TypeScript

import { connectionMongo, getMongoModel } from '../../common/mongo';
const { Schema } = connectionMongo;
import { type ChatItemSchema as ChatItemType } from '@fastgpt/global/core/chat/type';
import { ChatRoleMap } from '@fastgpt/global/core/chat/constants';
import { getNanoid } from '@fastgpt/global/common/string/tools';
import {
TeamCollectionName,
TeamMemberCollectionName
} from '@fastgpt/global/support/user/team/constant';
import { AppCollectionName } from '../app/schema';
import { userCollectionName } from '../../support/user/schema';
import { DispatchNodeResponseKeyEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import { ChatItemCollectionName } from './constants';
const ChatItemSchema = new Schema({
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
tmbId: {
type: Schema.Types.ObjectId,
ref: TeamMemberCollectionName,
required: true
},
userId: {
type: Schema.Types.ObjectId,
ref: userCollectionName
},
chatId: {
type: String,
require: true
},
dataId: {
type: String,
require: true,
default: () => getNanoid(24)
},
appId: {
type: Schema.Types.ObjectId,
ref: AppCollectionName,
required: true
},
time: {
type: Date,
default: () => new Date()
},
hideInUI: {
type: Boolean,
default: false
},
obj: {
// chat role
type: String,
required: true,
enum: Object.keys(ChatRoleMap)
},
value: {
// chat content
type: Array,
default: []
},
// Field memory
memories: Object,
errorMsg: String,
durationSeconds: Number,
citeCollectionIds: [String],
// Feedback
userGoodFeedback: String,
userBadFeedback: String,
customFeedbacks: [String],
adminFeedback: {
type: {
datasetId: String,
collectionId: String,
dataId: String,
q: String,
a: String
}
},
isFeedbackRead: Boolean,
// @deprecated
[DispatchNodeResponseKeyEnum.nodeResponse]: Array
});
/*
delete by app;
delete by chat id;
get chat list;
get chat logs;
close custom feedback;
*/
ChatItemSchema.index({ appId: 1, chatId: 1, dataId: 1 });
// Anchor filter
ChatItemSchema.index({ appId: 1, chatId: 1, _id: -1 });
// timer, clear history
ChatItemSchema.index({ teamId: 1, time: -1 });
// Admin charts
ChatItemSchema.index({ obj: 1, time: -1 }, { partialFilterExpression: { obj: 'Human' } });
export const MongoChatItem = getMongoModel<ChatItemType>(ChatItemCollectionName, ChatItemSchema);