perf: push chat log (#3109)

This commit is contained in:
Archer
2024-11-10 11:22:03 +08:00
committed by archer
parent e9f0d5dad5
commit 0201e63cfd
12 changed files with 134 additions and 81 deletions

View File

@@ -53,5 +53,5 @@ WORKFLOW_MAX_LOOP_TIMES=50
# CHAT_LOG_URL=http://localhost:8080
# # 日志推送间隔
# CHAT_LOG_INTERVAL=10000
# # 日志来源前缀
# SOURCE_ID_PREFIX=fastgpt-
# # 日志来源ID前缀
# CHAT_LOG_SOURCE_ID_PREFIX=fastgpt-

View File

@@ -87,6 +87,7 @@ type AuthResponseType = {
apikey?: string;
canWrite: boolean;
outLinkUserId?: string;
sourceName?: string;
};
async function handler(req: NextApiRequest, res: NextApiResponse) {
@@ -156,6 +157,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
app,
responseDetail,
authType,
sourceName,
apikey,
canWrite,
outLinkUserId = customUid
@@ -343,7 +345,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
newTitle,
shareId,
outLinkUid: outLinkUserId,
source,
source: sourceName || source,
content: [userQuestion, aiResponse],
metadata: {
originIp,
@@ -459,7 +461,7 @@ const authShareChat = async ({
shareId: string;
chatId?: string;
}): Promise<AuthResponseType> => {
const { teamId, tmbId, user, appId, authType, responseDetail, uid } =
const { teamId, tmbId, user, appId, authType, responseDetail, uid, sourceName } =
await authOutLinkChatStart(data);
const app = await MongoApp.findById(appId).lean();
@@ -474,6 +476,7 @@ const authShareChat = async ({
}
return {
sourceName,
teamId,
tmbId,
user,
@@ -541,6 +544,7 @@ const authHeaderRequest = async ({
teamId,
tmbId,
authType,
sourceName,
apikey
} = await authCert({
req,
@@ -607,6 +611,7 @@ const authHeaderRequest = async ({
responseDetail: true,
apikey,
authType,
sourceName,
canWrite: true
};
};

View File

@@ -129,15 +129,16 @@ const Logs = () => {
onClick={() => setDetailLogsId(item.id)}
>
<Td>
<Box>{t(ChatSourceMap[item.source]?.name || ('UnKnow' as any))}</Box>
{/* @ts-ignore */}
<Box>{t(ChatSourceMap[item.source]?.name) || item.source}</Box>
<Box color={'myGray.500'}>{dayjs(item.time).format('YYYY/MM/DD HH:mm')}</Box>
</Td>
<Td>
<Box>
{item.source === 'share' ? (
{!!item.outLinkUid ? (
item.outLinkUid
) : (
<Tag key={item._id} type={'fill'} colorSchema="white">
<HStack>
<Avatar
src={teamMembers.find((v) => v.tmbId === item.tmbId)?.avatar}
w="1.25rem"
@@ -145,7 +146,7 @@ const Logs = () => {
<Box fontSize={'sm'} ml={1}>
{teamMembers.find((v) => v.tmbId === item.tmbId)?.memberName}
</Box>
</Tag>
</HStack>
)}
</Box>
</Td>

View File

@@ -57,6 +57,7 @@ const OutLink = ({
showHistory = '1',
showHead = '1',
authToken,
customUid,
...customVariables
} = router.query as {
shareId: string;

View File

@@ -65,6 +65,7 @@ export async function authOutLinkChatStart({
]);
return {
sourceName: shareChat.name,
teamId: shareChat.teamId,
tmbId: shareChat.tmbId,
authType: AuthUserTypeEnum.token,

View File

@@ -35,7 +35,7 @@ export type AppItemType = {
export type AppLogsListItemType = {
_id: string;
id: string;
source: ChatSchema['source'];
source: string;
time: Date;
title: string;
messageCount: number;