Skip to content
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
14 changes: 13 additions & 1 deletion packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ export type ChatItemValueItemType =
| AIChatItemValueItemType;
export type ChatItemMergeType = UserChatItemType | SystemChatItemType | AIChatItemType;

export type ChatItemSchema = ChatItemMergeType & {
export type ChatItemSchemaType = ChatItemMergeType & {
dataId: string;
chatId: string;
userId: string;
teamId: string;
tmbId: string;
appId: string;
time: Date;
deleteTime?: Date | null;
};

export type AdminFbkType = {
Expand Down Expand Up @@ -171,6 +172,17 @@ export type ChatSiteItemType = ChatItemMergeType & {
time?: Date;
durationSeconds?: number;
errorMsg?: string;
deleteTime?: Date | null;
collapseTop?: {
count: number;
dataIds: string[];
isExpanded: boolean;
};
collapseBottom?: {
count: number;
dataIds: string[];
isExpanded: boolean;
};
} & ChatBoxInputType &
ResponseTagItemType;

Expand Down
27 changes: 17 additions & 10 deletions packages/service/core/chat/chatItemSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { connectionMongo, getMongoModel } from '../../common/mongo';
const { Schema } = connectionMongo;
import { type ChatItemSchema as ChatItemType } from '@fastgpt/global/core/chat/type';
import { type ChatItemSchemaType } from '@fastgpt/global/core/chat/type';
import { ChatRoleMap } from '@fastgpt/global/core/chat/constants';
import { getNanoid } from '@fastgpt/global/common/string/tools';
import {
Expand Down Expand Up @@ -81,22 +81,29 @@ const ChatItemSchema = new Schema({
}
},
isFeedbackRead: Boolean,
deleteTime: {
type: Date,
default: null
},

// @deprecated
[DispatchNodeResponseKeyEnum.nodeResponse]: Array
});

/*
delete by app;
/*
delete by app;
delete by chat id;
get chat list;
get chat logs;
close custom feedback;
close custom feedback;
*/
ChatItemSchema.index({ appId: 1, chatId: 1, dataId: 1 });
// Anchor filter
// Get histories
ChatItemSchema.index({ appId: 1, chatId: 1, deleteTime: 1 });
// get chatitem list,Anchor filter
ChatItemSchema.index({ appId: 1, chatId: 1, _id: -1 });
// timer, clear history
ChatItemSchema.index({ teamId: 1, time: -1 });
// Query by role (AI/Human), get latest chat item, permission check
ChatItemSchema.index({ appId: 1, chatId: 1, obj: 1, _id: -1 });

export const MongoChatItem = getMongoModel<ChatItemType>(ChatItemCollectionName, ChatItemSchema);
export const MongoChatItem = getMongoModel<ChatItemSchemaType>(
ChatItemCollectionName,
ChatItemSchema
);
5 changes: 3 additions & 2 deletions packages/service/core/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { mongoSessionRun } from '../../common/mongo/sessionRun';
import { UserError } from '@fastgpt/global/common/error/utils';

export async function getChatItems({
includeDeleted = false,
appId,
chatId,
field,
Expand All @@ -21,6 +22,7 @@ export async function getChatItems({
prevId,
nextId
}: {
includeDeleted?: boolean;
appId: string;
chatId?: string;
field: string;
Expand All @@ -42,8 +44,7 @@ export async function getChatItems({

// Extend dataId
field = `dataId ${field}`;

const baseCondition = { appId, chatId };
const baseCondition = includeDeleted ? { appId, chatId } : { appId, chatId, deleteTime: null };

const { histories, total, hasMorePrev, hasMoreNext } = await (async () => {
// Mode 1: offset pagination (original logic)
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"auto_execute_tip": "After turning it on, the workflow will be automatically triggered when the user enters the conversation interface. \nExecution order: 1. Dialogue starter; 2. Global variables; 3. Automatic execution.",
"auto_save": "Auto save",
"change_app_type": "Change App Type",
"chat.collapse_deleted_items": "Collapse deleted records",
"chat.expand_deleted_items": "Expand deleted records",
"chat_debug": "Chat Preview",
"chat_logs": "Logs",
"chat_logs_tips": "Logs will record the online, shared, and API (requires chatId) conversation records of this app.",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/zh-CN/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"auto_execute_tip": "开启后,用户进入对话界面将自动触发工作流。执行顺序:1、对话开场白;2、全局变量;3、自动执行。",
"auto_save": "自动保存",
"change_app_type": "更改应用类型",
"chat.collapse_deleted_items": "收起已删除记录",
"chat.expand_deleted_items": "展开已删除记录",
"chat_debug": "调试预览",
"chat_logs": "对话日志",
"chat_logs_tips": "日志会记录该应用的在线、分享和 API(需填写 chatId)对话记录",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/zh-Hant/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"auto_execute_tip": "開啟後,使用者進入對話式介面將自動觸發工作流程。\n執行順序:1、對話開場白;2、全域變數;3、自動執行。",
"auto_save": "自動儲存",
"change_app_type": "更改應用程式類型",
"chat.collapse_deleted_items": "收起已刪除記錄",
"chat.expand_deleted_items": "展開已刪除記錄",
"chat_debug": "聊天預覽",
"chat_logs": "對話紀錄",
"chat_logs_tips": "紀錄會記錄此應用程式的線上、分享和 API(需填寫 chatId)對話紀錄",
Expand Down
Loading
Loading