Skip to content

Commit 45f33d1

Browse files
committed
refactor: reorganize user info retrieval by moving getRunningUserInfoByTmbId to user/team module and updating imports across the codebase
(cherry picked from commit 1cf99ec)
1 parent e77ccc7 commit 45f33d1

File tree

12 files changed

+79
-91
lines changed

12 files changed

+79
-91
lines changed

packages/service/core/workflow/dispatch/child/runApp.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import { authAppByTmbId } from '../../../../support/permission/app/auth';
2020
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
2121
import { getAppVersionById } from '../../../app/version/controller';
2222
import { parseUrlToFileType } from '@fastgpt/global/common/file/tools';
23-
import {
24-
getUserChatInfoAndAuthTeamPoints,
25-
getRunningUserInfoByTmbId
26-
} from '../../../../support/permission/auth/team';
23+
import { getUserChatInfoAndAuthTeamPoints } from '../../../../support/permission/auth/team';
24+
import { getRunningUserInfoByTmbId } from '../../../../support/permission/user/team';
2725

2826
type Props = ModuleDispatchProps<{
2927
[NodeInputKeyEnum.userChatInput]: string;

packages/service/core/workflow/dispatch/child/runTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export const dispatchRunTool = async (props: RunToolProps): Promise<RunToolRespo
9090
systemVar: {
9191
user: {
9292
id: variables.userId,
93-
userId: runningUserInfo.username,
94-
rank: runningUserInfo.contact,
93+
username: runningUserInfo.username,
94+
contact: runningUserInfo.contact,
9595
membername: runningUserInfo.memberName,
9696
teamName: runningUserInfo.teamName,
9797
teamId: runningUserInfo.teamId,

packages/service/support/permission/auth/team.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,3 @@ export async function getUserChatInfoAndAuthTeamPoints(tmbId: string) {
3030
}
3131
};
3232
}
33-
34-
export async function getRunningUserInfoByTmbId(tmbId: string) {
35-
if (tmbId) {
36-
const tmb = await MongoTeamMember.findById(tmbId, 'teamId name userId') // team_members name is the user's name
37-
.populate<{ team: TeamSchema; user: UserModelSchema }>([
38-
{
39-
path: 'team',
40-
select: 'name'
41-
},
42-
{
43-
path: 'user',
44-
select: 'username contact'
45-
}
46-
])
47-
.lean();
48-
49-
if (!tmb) return Promise.reject(TeamErrEnum.notUser);
50-
51-
return {
52-
username: tmb.user.username,
53-
teamName: tmb.team.name,
54-
memberName: tmb.name,
55-
contact: tmb.user.contact || '',
56-
teamId: tmb.teamId,
57-
tmbId: tmb._id
58-
};
59-
}
60-
61-
return Promise.reject(TeamErrEnum.notUser);
62-
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { MongoTeamMember } from '../../user/team/teamMemberSchema';
2+
import { type UserModelSchema } from '@fastgpt/global/support/user/type';
3+
import { type TeamSchema } from '@fastgpt/global/support/user/team/type';
4+
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
5+
6+
export async function getRunningUserInfoByTmbId(tmbId: string) {
7+
if (tmbId) {
8+
const tmb = await MongoTeamMember.findById(tmbId, 'teamId name userId') // team_members name is the user's name
9+
.populate<{ team: TeamSchema; user: UserModelSchema }>([
10+
{
11+
path: 'team',
12+
select: 'name'
13+
},
14+
{
15+
path: 'user',
16+
select: 'username contact'
17+
}
18+
])
19+
.lean();
20+
21+
if (!tmb) return Promise.reject(TeamErrEnum.notUser);
22+
23+
return {
24+
username: tmb.user.username,
25+
teamName: tmb.team.name,
26+
memberName: tmb.name,
27+
contact: tmb.user.contact || '',
28+
teamId: tmb.teamId,
29+
tmbId: tmb._id
30+
};
31+
}
32+
33+
return Promise.reject(TeamErrEnum.notUser);
34+
}

projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,26 @@ const ResponseTags = ({
7070
: true;
7171

7272
// Dataset citation render items
73-
const datasetCitationList = useMemo(() => {
74-
// Keep first item per collectionId and preserve first-seen order
75-
const firstByCollection = new Map<string, SearchDataResponseItemType>();
76-
quoteList.forEach((cur) => {
77-
if (!firstByCollection.has(cur.collectionId)) {
78-
firstByCollection.set(cur.collectionId, cur);
79-
}
80-
});
81-
return Array.from(firstByCollection.values()).map((item) => ({
82-
itemType: 'dataset' as const,
83-
sourceName: item.sourceName,
84-
sourceId: item.sourceId,
85-
icon: item.imageId
86-
? 'core/dataset/imageFill'
87-
: getSourceNameIcon({ sourceId: item.sourceId, sourceName: item.sourceName }),
88-
collectionId: item.collectionId,
89-
datasetId: item.datasetId
90-
}));
73+
const sourceList = useMemo(() => {
74+
return Object.values(
75+
quoteList.reduce((acc: Record<string, SearchDataResponseItemType[]>, cur) => {
76+
if (!acc[cur.collectionId]) {
77+
acc[cur.collectionId] = [cur];
78+
}
79+
return acc;
80+
}, {})
81+
)
82+
.flat()
83+
.map((item) => ({
84+
itemType: 'dataset' as const,
85+
sourceName: item.sourceName,
86+
sourceId: item.sourceId,
87+
icon: item.imageId
88+
? 'core/dataset/imageFill'
89+
: getSourceNameIcon({ sourceId: item.sourceId, sourceName: item.sourceName }),
90+
collectionId: item.collectionId,
91+
datasetId: item.datasetId
92+
}));
9193
}, [quoteList]);
9294

9395
// Merge dataset citations and external link references for unified rendering
@@ -107,8 +109,8 @@ const ResponseTags = ({
107109
...r,
108110
itemType: 'link'
109111
}));
110-
return [...datasetCitationList, ...linkItems];
111-
}, [datasetCitationList, externalLinkList]);
112+
return [...sourceList, ...linkItems];
113+
}, [sourceList, externalLinkList]);
112114

113115
const notEmptyTags = notSharePage || quoteList.length > 0 || (isPc && durationSeconds > 0);
114116

projects/app/src/global/core/chat/utils.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
3737
// Flat children
3838
const flatResData = getFlatAppResponses(historyItem.responseData || []);
3939

40-
const llmModuleAccount = flatResData.filter(isLLMNode).length;
41-
const totalQuoteList = flatResData
42-
.filter((item) => item.moduleType === FlowNodeTypeEnum.datasetSearchNode)
43-
.map((item) => item.quoteList)
44-
.flat()
45-
.filter(Boolean) as SearchDataResponseItemType[];
46-
const historyPreviewLength = flatResData.find(isLLMNode)?.historyPreview?.length;
47-
4840
// Extract external link references from final tool responses in responseData
4941
const externalLinkList = (() => {
5042
try {
@@ -84,9 +76,13 @@ export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
8476

8577
return {
8678
...historyItem,
87-
...(llmModuleAccount ? { llmModuleAccount } : {}),
88-
...(totalQuoteList.length ? { totalQuoteList } : {}),
89-
...(historyPreviewLength ? { historyPreviewLength } : {}),
79+
llmModuleAccount: flatResData.filter(isLLMNode).length,
80+
totalQuoteList: flatResData
81+
.filter((item) => item.moduleType === FlowNodeTypeEnum.datasetSearchNode)
82+
.map((item) => item.quoteList)
83+
.flat()
84+
.filter(Boolean) as SearchDataResponseItemType[],
85+
historyPreviewLength: flatResData.find(isLLMNode)?.historyPreview?.length,
9086
...(externalLinkList.length ? { externalLinkList } : {})
9187
};
9288
}

projects/app/src/pages/api/core/chat/chatTest.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants'
1010
import type { AIChatItemType, UserChatItemType } from '@fastgpt/global/core/chat/type';
1111
import { authApp } from '@fastgpt/service/support/permission/app/auth';
1212
import { dispatchWorkFlow } from '@fastgpt/service/core/workflow/dispatch';
13-
import {
14-
getUserChatInfoAndAuthTeamPoints,
15-
getRunningUserInfoByTmbId
16-
} from '@fastgpt/service/support/permission/auth/team';
13+
import { getUserChatInfoAndAuthTeamPoints } from '@fastgpt/service/support/permission/auth/team';
14+
import { getRunningUserInfoByTmbId } from '@fastgpt/service/support/permission/user/team';
1715
import type { StoreEdgeItemType } from '@fastgpt/global/core/workflow/type/edge';
1816
import {
1917
concatHistories,

projects/app/src/pages/api/core/workflow/debug.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants'
44
import { authApp } from '@fastgpt/service/support/permission/app/auth';
55
import { dispatchWorkFlow } from '@fastgpt/service/core/workflow/dispatch';
66
import { authCert } from '@fastgpt/service/support/permission/auth/common';
7-
import {
8-
getUserChatInfoAndAuthTeamPoints,
9-
getRunningUserInfoByTmbId
10-
} from '@fastgpt/service/support/permission/auth/team';
7+
import { getUserChatInfoAndAuthTeamPoints } from '@fastgpt/service/support/permission/auth/team';
8+
import { getRunningUserInfoByTmbId } from '@fastgpt/service/support/permission/user/team';
119
import type { PostWorkflowDebugProps, PostWorkflowDebugResponse } from '@/global/core/workflow/api';
1210
import { NextAPI } from '@/service/middleware/entry';
1311
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';

projects/app/src/pages/api/v1/chat/completions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ import {
3434
removeEmptyUserInput
3535
} from '@fastgpt/global/core/chat/utils';
3636
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
37-
import {
38-
getUserChatInfoAndAuthTeamPoints,
39-
getRunningUserInfoByTmbId
40-
} from '@fastgpt/service/support/permission/auth/team';
37+
import { getUserChatInfoAndAuthTeamPoints } from '@fastgpt/service/support/permission/auth/team';
38+
import { getRunningUserInfoByTmbId } from '@fastgpt/service/support/permission/user/team';
4139
import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
4240
import { MongoApp } from '@fastgpt/service/core/app/schema';
4341
import { type AppSchema } from '@fastgpt/global/core/app/type';

projects/app/src/pages/api/v2/chat/completions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ import {
3434
removeEmptyUserInput
3535
} from '@fastgpt/global/core/chat/utils';
3636
import { updateApiKeyUsage } from '@fastgpt/service/support/openapi/tools';
37-
import {
38-
getUserChatInfoAndAuthTeamPoints,
39-
getRunningUserInfoByTmbId
40-
} from '@fastgpt/service/support/permission/auth/team';
37+
import { getUserChatInfoAndAuthTeamPoints } from '@fastgpt/service/support/permission/auth/team';
38+
import { getRunningUserInfoByTmbId } from '@fastgpt/service/support/permission/user/team';
4139
import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant';
4240
import { MongoApp } from '@fastgpt/service/core/app/schema';
4341
import { type AppSchema } from '@fastgpt/global/core/app/type';

0 commit comments

Comments
 (0)