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="请求示例">
|
<Tab value="请求示例">
|
||||||
|
|
||||||
```bash
|
```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 'Authorization: Bearer [apikey]' \
|
||||||
--header 'Content-Type: application/json' \
|
--header 'Content-Type: application/json' \
|
||||||
--data-raw '{
|
--data-raw '{
|
||||||
|
|
@ -679,7 +679,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories
|
||||||
<Tab value="请求示例">
|
<Tab value="请求示例">
|
||||||
|
|
||||||
```bash
|
```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 'Authorization: Bearer [apikey]' \
|
||||||
--header 'Content-Type: application/json' \
|
--header 'Content-Type: application/json' \
|
||||||
--data-raw '{
|
--data-raw '{
|
||||||
|
|
@ -721,7 +721,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistor
|
||||||
<Tab value="请求示例">
|
<Tab value="请求示例">
|
||||||
|
|
||||||
```bash
|
```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 'Authorization: Bearer [apikey]' \
|
||||||
--header 'Content-Type: application/json' \
|
--header 'Content-Type: application/json' \
|
||||||
--data-raw '{
|
--data-raw '{
|
||||||
|
|
@ -763,7 +763,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/updateHistor
|
||||||
<Tab value="请求示例">
|
<Tab value="请求示例">
|
||||||
|
|
||||||
```bash
|
```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]'
|
--header 'Authorization: Bearer [apikey]'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -800,7 +800,7 @@ curl --location --request DELETE 'http://localhost:3000/api/core/chat/delHistory
|
||||||
<Tab value="请求示例">
|
<Tab value="请求示例">
|
||||||
|
|
||||||
```bash
|
```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]'
|
--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/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/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/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/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/41.mdx": "2025-08-02T19:38:37+08:00",
|
||||||
"document/content/docs/upgrading/4-8/42.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({
|
export const ChatLogItemSchema = z.object({
|
||||||
_id: z.string().meta({ example: '68ad85a7463006c963799a05', description: '对话日志 ID' }),
|
_id: z.string().meta({ example: '68ad85a7463006c963799a05', description: '对话日志 ID' }),
|
||||||
chatId: z.string().meta({ example: 'chat123', 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: '自定义对话标题' }),
|
customTitle: z.string().nullish().meta({ example: '自定义标题', description: '自定义对话标题' }),
|
||||||
source: z.enum(ChatSourceEnum).meta({ example: ChatSourceEnum.api, description: '对话来源' }),
|
source: z.enum(ChatSourceEnum).meta({ example: ChatSourceEnum.api, description: '对话来源' }),
|
||||||
sourceName: z.string().nullish().meta({ example: 'API调用', description: '来源名称' }),
|
sourceName: z.string().nullish().meta({ example: 'API调用', description: '来源名称' }),
|
||||||
updateTime: z.date().meta({ example: '2024-01-01T00:30:00.000Z', 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: '消息数量' }),
|
messageCount: z.int().nullish().meta({ example: 10, description: '消息数量' }),
|
||||||
userGoodFeedbackCount: z.int().nullish().meta({ example: 3, description: '好评反馈数量' }),
|
userGoodFeedbackCount: z.int().nullish().meta({ example: 3, description: '好评反馈数量' }),
|
||||||
userBadFeedbackCount: z.int().nullish().meta({ example: 1, description: '差评反馈数量' }),
|
userBadFeedbackCount: z.int().nullish().meta({ example: 1, description: '差评反馈数量' }),
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ export interface ProcessedError {
|
||||||
code: number;
|
code: number;
|
||||||
statusText: string;
|
statusText: string;
|
||||||
message: string;
|
message: string;
|
||||||
data?: any;
|
|
||||||
shouldClearCookie: boolean;
|
shouldClearCookie: boolean;
|
||||||
|
data?: any;
|
||||||
|
zodError?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,6 +33,7 @@ export function processError(params: {
|
||||||
defaultCode?: number;
|
defaultCode?: number;
|
||||||
}): ProcessedError {
|
}): ProcessedError {
|
||||||
const { error, url, defaultCode = 500 } = params;
|
const { error, url, defaultCode = 500 } = params;
|
||||||
|
let zodError;
|
||||||
|
|
||||||
const errResponseKey = typeof error === 'string' ? error : error?.message;
|
const errResponseKey = typeof error === 'string' ? error : error?.message;
|
||||||
|
|
||||||
|
|
@ -67,7 +69,14 @@ export function processError(params: {
|
||||||
if (error instanceof UserError) {
|
if (error instanceof UserError) {
|
||||||
addLog.info(`Request error: ${url}, ${msg}`);
|
addLog.info(`Request error: ${url}, ${msg}`);
|
||||||
} else if (error instanceof ZodError) {
|
} 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;
|
msg = error.message;
|
||||||
} else {
|
} else {
|
||||||
addLog.error(`System unexpected error: ${url}, ${msg}`, error);
|
addLog.error(`System unexpected error: ${url}, ${msg}`, error);
|
||||||
|
|
@ -78,7 +87,8 @@ export function processError(params: {
|
||||||
code: defaultCode,
|
code: defaultCode,
|
||||||
statusText: 'error',
|
statusText: 'error',
|
||||||
message: replaceSensitiveText(msg),
|
message: replaceSensitiveText(msg),
|
||||||
shouldClearCookie: false
|
shouldClearCookie: false,
|
||||||
|
zodError
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,7 +117,8 @@ export const jsonRes = <T = any>(
|
||||||
code: processedError.code,
|
code: processedError.code,
|
||||||
statusText: processedError.statusText,
|
statusText: processedError.statusText,
|
||||||
message: message || processedError.message,
|
message: message || processedError.message,
|
||||||
data: processedError.data !== undefined ? processedError.data : null
|
data: processedError.data !== undefined ? processedError.data : null,
|
||||||
|
zodError: processedError.zodError
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { LogLevelEnum } from './log/constant';
|
||||||
import { connectionMongo } from '../mongo/index';
|
import { connectionMongo } from '../mongo/index';
|
||||||
import { getMongoLog } from './log/schema';
|
import { getMongoLog } from './log/schema';
|
||||||
import { getLogger } from '../otel/log';
|
import { getLogger } from '../otel/log';
|
||||||
|
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||||
|
|
||||||
export enum EventTypeEnum {
|
export enum EventTypeEnum {
|
||||||
outLinkBot = '[Outlink bot]',
|
outLinkBot = '[Outlink bot]',
|
||||||
|
|
@ -151,7 +152,7 @@ export const addLog = {
|
||||||
error(msg: string, error?: any) {
|
error(msg: string, error?: any) {
|
||||||
this.log(LogLevelEnum.error, msg, {
|
this.log(LogLevelEnum.error, msg, {
|
||||||
...(error?.data && { data: error?.data }),
|
...(error?.data && { data: error?.data }),
|
||||||
message: error?.message || error,
|
message: getErrText(error),
|
||||||
stack: error?.stack,
|
stack: error?.stack,
|
||||||
...(error?.config && {
|
...(error?.config && {
|
||||||
config: {
|
config: {
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,7 @@ export async function saveChat(props: Props) {
|
||||||
shareId,
|
shareId,
|
||||||
outLinkUid,
|
outLinkUid,
|
||||||
metadata: metadataUpdate,
|
metadata: metadataUpdate,
|
||||||
|
createTime: new Date(),
|
||||||
updateTime: 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 { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||||
import { AppReadChatLogPerVal } from '@fastgpt/global/support/permission/app/constant';
|
import { AppReadChatLogPerVal } from '@fastgpt/global/support/permission/app/constant';
|
||||||
import { ChatBatchDeleteBodySchema } from '@fastgpt/global/openapi/core/chat/history/api';
|
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) {
|
async function handler(req: ApiRequestProps, res: NextApiResponse) {
|
||||||
const { appId, chatIds } = ChatBatchDeleteBodySchema.parse(req.body);
|
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';
|
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||||
|
|
||||||
/* clear all chat histories of an app */
|
/* 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(
|
const { appId, shareId, outLinkUid, teamId, teamToken } = ClearChatHistoriesSchema.parse(
|
||||||
req.query
|
req.query
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { NextAPI } from '@/service/middleware/entry';
|
||||||
import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
||||||
|
|
||||||
/* delete single chat history (soft delete) */
|
/* 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);
|
const { appId, chatId } = DelChatHistorySchema.parse(req.query);
|
||||||
|
|
||||||
await authChatCrud({
|
await authChatCrud({
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import { parsePaginationRequest } from '@fastgpt/service/common/api/pagination';
|
||||||
import { addMonths } from 'date-fns';
|
import { addMonths } from 'date-fns';
|
||||||
|
|
||||||
/* get chat histories list */
|
/* get chat histories list */
|
||||||
async function handler(
|
export async function handler(
|
||||||
req: ApiRequestProps,
|
req: ApiRequestProps,
|
||||||
_res: ApiResponseType
|
_res: ApiResponseType
|
||||||
): Promise<GetHistoriesResponseType> {
|
): Promise<GetHistoriesResponseType> {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { type ApiRequestProps } from '@fastgpt/service/type/next';
|
||||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||||
|
|
||||||
/* update chat history: title, customTitle, top */
|
/* 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);
|
const { appId, chatId, title, customTitle, top } = UpdateHistoryBodySchema.parse(req.body);
|
||||||
await authChatCrud({
|
await authChatCrud({
|
||||||
req,
|
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