mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
parent
527237d019
commit
0d88761378
|
|
@ -616,7 +616,7 @@ event取值:
|
|||
<Tab value="请求示例">
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories' \
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/history/getHistories' \
|
||||
--header 'Authorization: Bearer [apikey]' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
|
|
@ -679,7 +679,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories
|
|||
<Tab value="请求示例">
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistory' \
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/history/updateHistory' \
|
||||
--header 'Authorization: Bearer [apikey]' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
|
|
@ -721,7 +721,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistor
|
|||
<Tab value="请求示例">
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistory' \
|
||||
curl --location --request POST 'http://localhost:3000/api/core/chat/history/updateHistory' \
|
||||
--header 'Authorization: Bearer [apikey]' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
|
|
@ -763,7 +763,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistor
|
|||
<Tab value="请求示例">
|
||||
|
||||
```bash
|
||||
curl --location --request DELETE 'http://localhost:3000/api/core/chat/delHistory?chatId=[chatId]&appId=[appId]' \
|
||||
curl --location --request DELETE 'http://localhost:3000/api/core/chat/history/delHistory?chatId=[chatId]&appId=[appId]' \
|
||||
--header 'Authorization: Bearer [apikey]'
|
||||
```
|
||||
|
||||
|
|
@ -800,7 +800,7 @@ curl --location --request DELETE 'http://localhost:3000/api/core/chat/delHistory
|
|||
<Tab value="请求示例">
|
||||
|
||||
```bash
|
||||
curl --location --request DELETE 'http://localhost:3000/api/core/chat/clearHistories?appId=[appId]' \
|
||||
curl --location --request DELETE 'http://localhost:3000/api/core/chat/history/clearHistories?appId=[appId]' \
|
||||
--header 'Authorization: Bearer [apikey]'
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
"document/content/docs/upgrading/4-14/4142.mdx": "2025-11-18T19:27:14+08:00",
|
||||
"document/content/docs/upgrading/4-14/4143.mdx": "2025-11-26T20:52:05+08:00",
|
||||
"document/content/docs/upgrading/4-14/4144.mdx": "2025-12-16T14:56:04+08:00",
|
||||
"document/content/docs/upgrading/4-14/4145.mdx": "2025-12-18T10:17:10+08:00",
|
||||
"document/content/docs/upgrading/4-14/4145.mdx": "2025-12-18T11:09:13+08:00",
|
||||
"document/content/docs/upgrading/4-8/40.mdx": "2025-08-02T19:38:37+08:00",
|
||||
"document/content/docs/upgrading/4-8/41.mdx": "2025-08-02T19:38:37+08:00",
|
||||
"document/content/docs/upgrading/4-8/42.mdx": "2025-08-02T19:38:37+08:00",
|
||||
|
|
|
|||
|
|
@ -31,12 +31,15 @@ export type updateLogKeysBody = z.infer<typeof UpdateLogKeysBodySchema>;
|
|||
export const ChatLogItemSchema = z.object({
|
||||
_id: z.string().meta({ example: '68ad85a7463006c963799a05', description: '对话日志 ID' }),
|
||||
chatId: z.string().meta({ example: 'chat123', description: '对话 ID' }),
|
||||
title: z.string().optional().meta({ example: '用户对话', description: '对话标题' }),
|
||||
title: z.string().nullish().meta({ example: '用户对话', description: '对话标题' }),
|
||||
customTitle: z.string().nullish().meta({ example: '自定义标题', description: '自定义对话标题' }),
|
||||
source: z.enum(ChatSourceEnum).meta({ example: ChatSourceEnum.api, description: '对话来源' }),
|
||||
sourceName: z.string().nullish().meta({ example: 'API调用', description: '来源名称' }),
|
||||
updateTime: z.date().meta({ example: '2024-01-01T00:30:00.000Z', description: '更新时间' }),
|
||||
createTime: z.date().meta({ example: '2024-01-01T00:00:00.000Z', description: '创建时间' }),
|
||||
createTime: z
|
||||
.date()
|
||||
.nullish()
|
||||
.meta({ example: '2024-01-01T00:00:00.000Z', description: '创建时间' }),
|
||||
messageCount: z.int().nullish().meta({ example: 10, description: '消息数量' }),
|
||||
userGoodFeedbackCount: z.int().nullish().meta({ example: 3, description: '好评反馈数量' }),
|
||||
userBadFeedbackCount: z.int().nullish().meta({ example: 1, description: '差评反馈数量' }),
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ export interface ProcessedError {
|
|||
code: number;
|
||||
statusText: string;
|
||||
message: string;
|
||||
data?: any;
|
||||
shouldClearCookie: boolean;
|
||||
data?: any;
|
||||
zodError?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +33,7 @@ export function processError(params: {
|
|||
defaultCode?: number;
|
||||
}): ProcessedError {
|
||||
const { error, url, defaultCode = 500 } = params;
|
||||
let zodError;
|
||||
|
||||
const errResponseKey = typeof error === 'string' ? error : error?.message;
|
||||
|
||||
|
|
@ -67,7 +69,14 @@ export function processError(params: {
|
|||
if (error instanceof UserError) {
|
||||
addLog.info(`Request error: ${url}, ${msg}`);
|
||||
} else if (error instanceof ZodError) {
|
||||
addLog.error(`[Zod] Error in ${url}`, error.message);
|
||||
zodError = (() => {
|
||||
try {
|
||||
return JSON.parse(error.message);
|
||||
} catch (error) {}
|
||||
})();
|
||||
addLog.error(`[Zod] Error in ${url}`, {
|
||||
data: zodError
|
||||
});
|
||||
msg = error.message;
|
||||
} else {
|
||||
addLog.error(`System unexpected error: ${url}, ${msg}`, error);
|
||||
|
|
@ -78,7 +87,8 @@ export function processError(params: {
|
|||
code: defaultCode,
|
||||
statusText: 'error',
|
||||
message: replaceSensitiveText(msg),
|
||||
shouldClearCookie: false
|
||||
shouldClearCookie: false,
|
||||
zodError
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +117,8 @@ export const jsonRes = <T = any>(
|
|||
code: processedError.code,
|
||||
statusText: processedError.statusText,
|
||||
message: message || processedError.message,
|
||||
data: processedError.data !== undefined ? processedError.data : null
|
||||
data: processedError.data !== undefined ? processedError.data : null,
|
||||
zodError: processedError.zodError
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { LogLevelEnum } from './log/constant';
|
|||
import { connectionMongo } from '../mongo/index';
|
||||
import { getMongoLog } from './log/schema';
|
||||
import { getLogger } from '../otel/log';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
export enum EventTypeEnum {
|
||||
outLinkBot = '[Outlink bot]',
|
||||
|
|
@ -151,7 +152,7 @@ export const addLog = {
|
|||
error(msg: string, error?: any) {
|
||||
this.log(LogLevelEnum.error, msg, {
|
||||
...(error?.data && { data: error?.data }),
|
||||
message: error?.message || error,
|
||||
message: getErrText(error),
|
||||
stack: error?.stack,
|
||||
...(error?.config && {
|
||||
config: {
|
||||
|
|
|
|||
|
|
@ -313,6 +313,7 @@ export async function saveChat(props: Props) {
|
|||
shareId,
|
||||
outLinkUid,
|
||||
metadata: metadataUpdate,
|
||||
createTime: new Date(),
|
||||
updateTime: new Date()
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { handler } from './history/clearHistories';
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { handler } from './history/delHistory';
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { handler } from './history/getHistories';
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
|
@ -9,7 +9,6 @@ import { getS3ChatSource } from '@fastgpt/service/common/s3/sources/chat';
|
|||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { AppReadChatLogPerVal } from '@fastgpt/global/support/permission/app/constant';
|
||||
import { ChatBatchDeleteBodySchema } from '@fastgpt/global/openapi/core/chat/history/api';
|
||||
import { UserError } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
const { appId, chatIds } = ChatBatchDeleteBodySchema.parse(req.body);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
|||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
|
||||
/* clear all chat histories of an app */
|
||||
async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
export async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
const { appId, shareId, outLinkUid, teamId, teamToken } = ClearChatHistoriesSchema.parse(
|
||||
req.query
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { NextAPI } from '@/service/middleware/entry';
|
|||
import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
|
||||
/* delete single chat history (soft delete) */
|
||||
async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
export async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
const { appId, chatId } = DelChatHistorySchema.parse(req.query);
|
||||
|
||||
await authChatCrud({
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import { parsePaginationRequest } from '@fastgpt/service/common/api/pagination';
|
|||
import { addMonths } from 'date-fns';
|
||||
|
||||
/* get chat histories list */
|
||||
async function handler(
|
||||
export async function handler(
|
||||
req: ApiRequestProps,
|
||||
_res: ApiResponseType
|
||||
): Promise<GetHistoriesResponseType> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
|||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* update chat history: title, customTitle, top */
|
||||
async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
export async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||
const { appId, chatId, title, customTitle, top } = UpdateHistoryBodySchema.parse(req.body);
|
||||
await authChatCrud({
|
||||
req,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { handler } from './history/updateHistory';
|
||||
|
||||
export default NextAPI(handler);
|
||||
Loading…
Reference in New Issue