Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
c3cc51c9
authored
Nov 13, 2024
by
Archer
Committed by
GitHub
Nov 13, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: share page data;Adapt findLastIndex api (#3147)
* perf: share page data * perf: adapt findLastIndex
parent
519b5194
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
56 deletions
+100
-56
packages/global/core/chat/utils.ts
+6
-2
packages/service/core/workflow/dispatch/dataset/search.ts
+12
-0
packages/web/hooks/useWidthVariable.ts
+6
-3
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx
+1
-0
projects/app/src/global/core/chat/utils.ts
+7
-2
projects/app/src/pages/api/core/chat/getPaginationRecords.ts
+7
-2
projects/app/src/pages/api/core/chat/getResData.ts
+44
-30
projects/app/src/pages/api/v1/chat/completions.ts
+5
-7
projects/app/src/service/support/permission/auth/chat.ts
+12
-10
No files found.
packages/global/core/chat/utils.ts
View file @
c3cc51c9
...
@@ -78,11 +78,15 @@ export const getHistoryPreview = (
...
@@ -78,11 +78,15 @@ export const getHistoryPreview = (
};
};
export
const
filterPublicNodeResponseData
=
({
export
const
filterPublicNodeResponseData
=
({
flowResponses
=
[]
flowResponses
=
[],
responseDetail
=
false
}:
{
}:
{
flowResponses
?:
ChatHistoryItemResType
[];
flowResponses
?:
ChatHistoryItemResType
[];
responseDetail
?:
boolean
;
})
=>
{
})
=>
{
const
filedList
=
[
'quoteList'
,
'moduleType'
,
'pluginOutput'
,
'runningTime'
];
const
filedList
=
responseDetail
?
[
'quoteList'
,
'moduleType'
,
'pluginOutput'
,
'runningTime'
]
:
[
'moduleType'
,
'pluginOutput'
,
'runningTime'
];
const
filterModuleTypeList
:
any
[]
=
[
const
filterModuleTypeList
:
any
[]
=
[
FlowNodeTypeEnum
.
pluginModule
,
FlowNodeTypeEnum
.
pluginModule
,
FlowNodeTypeEnum
.
datasetSearchNode
,
FlowNodeTypeEnum
.
datasetSearchNode
,
...
...
packages/service/core/workflow/dispatch/dataset/search.ts
View file @
c3cc51c9
...
@@ -65,6 +65,18 @@ export async function dispatchDatasetSearch(
...
@@ -65,6 +65,18 @@ export async function dispatchDatasetSearch(
}
}
if
(
!
userChatInput
)
{
if
(
!
userChatInput
)
{
return
{
quoteQA
:
[],
[
DispatchNodeResponseKeyEnum
.
nodeResponse
]:
{
totalPoints
:
0
,
query
:
''
,
limit
,
searchMode
},
nodeDispatchUsages
:
[],
[
DispatchNodeResponseKeyEnum
.
toolResponses
]:
[]
};
return
Promise
.
reject
(
i18nT
(
'common:core.chat.error.User input empty'
));
return
Promise
.
reject
(
i18nT
(
'common:core.chat.error.User input empty'
));
}
}
...
...
packages/web/hooks/useWidthVariable.ts
View file @
c3cc51c9
...
@@ -11,11 +11,14 @@ export const useWidthVariable = <T = any>({
...
@@ -11,11 +11,14 @@ export const useWidthVariable = <T = any>({
})
=>
{
})
=>
{
const
value
=
useMemo
(()
=>
{
const
value
=
useMemo
(()
=>
{
// 根据 width 计算,找到第一个大于 width 的值
// 根据 width 计算,找到第一个大于 width 的值
const
index
=
widthList
.
findLastIndex
((
item
)
=>
width
>
item
);
const
reversedWidthList
=
[...
widthList
].
reverse
();
const
reversedList
=
[...
list
].
reverse
();
const
index
=
reversedWidthList
.
findIndex
((
item
)
=>
width
>
item
);
if
(
index
===
-
1
)
{
if
(
index
===
-
1
)
{
return
l
ist
[
0
];
return
reversedL
ist
[
0
];
}
}
return
l
ist
[
index
];
return
reversedL
ist
[
index
];
},
[
list
,
width
,
widthList
]);
},
[
list
,
width
,
widthList
]);
return
value
;
return
value
;
...
...
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx
View file @
c3cc51c9
...
@@ -30,6 +30,7 @@ const ResponseTags = ({
...
@@ -30,6 +30,7 @@ const ResponseTags = ({
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
quoteListRef
=
React
.
useRef
<
HTMLDivElement
>
(
null
);
const
quoteListRef
=
React
.
useRef
<
HTMLDivElement
>
(
null
);
const
dataId
=
historyItem
.
dataId
;
const
dataId
=
historyItem
.
dataId
;
const
{
const
{
totalQuoteList
:
quoteList
=
[],
totalQuoteList
:
quoteList
=
[],
llmModuleAccount
=
0
,
llmModuleAccount
=
0
,
...
...
projects/app/src/global/core/chat/utils.ts
View file @
c3cc51c9
...
@@ -6,11 +6,15 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
...
@@ -6,11 +6,15 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
const
isLLMNode
=
(
item
:
ChatHistoryItemResType
)
=>
const
isLLMNode
=
(
item
:
ChatHistoryItemResType
)
=>
item
.
moduleType
===
FlowNodeTypeEnum
.
chatNode
||
item
.
moduleType
===
FlowNodeTypeEnum
.
tools
;
item
.
moduleType
===
FlowNodeTypeEnum
.
chatNode
||
item
.
moduleType
===
FlowNodeTypeEnum
.
tools
;
export
function
transformPreviewHistories
(
histories
:
ChatItemType
[]):
ChatItemType
[]
{
export
function
transformPreviewHistories
(
histories
:
ChatItemType
[],
responseDetail
:
boolean
):
ChatItemType
[]
{
return
histories
.
map
((
item
)
=>
{
return
histories
.
map
((
item
)
=>
{
return
{
return
{
...
addStatisticalDataToHistoryItem
(
item
),
...
addStatisticalDataToHistoryItem
(
item
),
responseData
:
undefined
responseData
:
undefined
,
...(
responseDetail
?
{}
:
{
totalQuoteList
:
undefined
})
};
};
});
});
}
}
...
@@ -18,6 +22,7 @@ export function transformPreviewHistories(histories: ChatItemType[]): ChatItemTy
...
@@ -18,6 +22,7 @@ export function transformPreviewHistories(histories: ChatItemType[]): ChatItemTy
export
function
addStatisticalDataToHistoryItem
(
historyItem
:
ChatItemType
)
{
export
function
addStatisticalDataToHistoryItem
(
historyItem
:
ChatItemType
)
{
if
(
historyItem
.
obj
!==
ChatRoleEnum
.
AI
)
return
historyItem
;
if
(
historyItem
.
obj
!==
ChatRoleEnum
.
AI
)
return
historyItem
;
if
(
historyItem
.
totalQuoteList
!==
undefined
)
return
historyItem
;
if
(
historyItem
.
totalQuoteList
!==
undefined
)
return
historyItem
;
if
(
!
historyItem
.
responseData
)
return
historyItem
;
// Flat children
// Flat children
const
flatResData
:
ChatHistoryItemResType
[]
=
const
flatResData
:
ChatHistoryItemResType
[]
=
...
...
projects/app/src/pages/api/core/chat/getPaginationRecords.ts
View file @
c3cc51c9
...
@@ -82,11 +82,16 @@ async function handler(
...
@@ -82,11 +82,16 @@ async function handler(
limit
:
pageSize
limit
:
pageSize
});
});
const
responseDetail
=
!
shareChat
||
shareChat
.
responseDetail
;
// Remove important information
// Remove important information
if
(
shareChat
&&
app
.
type
!==
AppTypeEnum
.
plugin
)
{
if
(
shareChat
&&
app
.
type
!==
AppTypeEnum
.
plugin
)
{
histories
.
forEach
((
item
)
=>
{
histories
.
forEach
((
item
)
=>
{
if
(
item
.
obj
===
ChatRoleEnum
.
AI
)
{
if
(
item
.
obj
===
ChatRoleEnum
.
AI
)
{
item
.
responseData
=
filterPublicNodeResponseData
({
flowResponses
:
item
.
responseData
});
item
.
responseData
=
filterPublicNodeResponseData
({
flowResponses
:
item
.
responseData
,
responseDetail
});
if
(
shareChat
.
showNodeStatus
===
false
)
{
if
(
shareChat
.
showNodeStatus
===
false
)
{
item
.
value
=
item
.
value
.
filter
((
v
)
=>
v
.
type
!==
ChatItemValueTypeEnum
.
tool
);
item
.
value
=
item
.
value
.
filter
((
v
)
=>
v
.
type
!==
ChatItemValueTypeEnum
.
tool
);
...
@@ -96,7 +101,7 @@ async function handler(
...
@@ -96,7 +101,7 @@ async function handler(
}
}
return
{
return
{
list
:
isPlugin
?
histories
:
transformPreviewHistories
(
histories
),
list
:
isPlugin
?
histories
:
transformPreviewHistories
(
histories
,
responseDetail
),
total
total
};
};
}
}
...
...
projects/app/src/pages/api/core/chat/getResData.ts
View file @
c3cc51c9
...
@@ -11,6 +11,7 @@ import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
...
@@ -11,6 +11,7 @@ import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
import
{
OutLinkChatAuthProps
}
from
'@fastgpt/global/support/permission/chat'
;
import
{
OutLinkChatAuthProps
}
from
'@fastgpt/global/support/permission/chat'
;
import
{
authApp
}
from
'@fastgpt/service/support/permission/app/auth'
;
import
{
authApp
}
from
'@fastgpt/service/support/permission/app/auth'
;
import
{
filterPublicNodeResponseData
}
from
'@fastgpt/global/core/chat/utils'
;
import
{
filterPublicNodeResponseData
}
from
'@fastgpt/global/core/chat/utils'
;
import
{
MongoOutLink
}
from
'@fastgpt/service/support/outLink/schema'
;
export
type
getResDataQuery
=
OutLinkChatAuthProps
&
{
export
type
getResDataQuery
=
OutLinkChatAuthProps
&
{
chatId
?:
string
;
chatId
?:
string
;
...
@@ -26,44 +27,57 @@ async function handler(
...
@@ -26,44 +27,57 @@ async function handler(
req
:
ApiRequestProps
<
getResDataBody
,
getResDataQuery
>
,
req
:
ApiRequestProps
<
getResDataBody
,
getResDataQuery
>
,
res
:
ApiResponseType
<
any
>
res
:
ApiResponseType
<
any
>
):
Promise
<
getResDataResponse
>
{
):
Promise
<
getResDataResponse
>
{
const
{
appId
,
chatId
,
dataId
}
=
req
.
query
;
const
{
appId
,
chatId
,
dataId
,
shareId
}
=
req
.
query
;
if
(
!
appId
||
!
chatId
||
!
dataId
)
{
if
(
!
appId
||
!
chatId
||
!
dataId
)
{
return
{};
return
{};
}
}
// 1. Un login api: share chat, team chat
// 1. Un login api: share chat, team chat
// 2. Login api: account chat, chat log
// 2. Login api: account chat, chat log
try
{
const
authData
=
await
(()
=>
{
await
authChatCrud
({
try
{
req
,
return
authChatCrud
({
authToken
:
true
,
req
,
authApiKey
:
true
,
authToken
:
true
,
...
req
.
query
,
authApiKey
:
true
,
per
:
ReadPermissionVal
...
req
.
query
,
});
per
:
ReadPermissionVal
}
catch
(
error
)
{
});
await
authApp
({
}
catch
(
error
)
{
req
,
return
authApp
({
authToken
:
true
,
req
,
authApiKey
:
true
,
authToken
:
true
,
appId
,
authApiKey
:
true
,
per
:
ManagePermissionVal
appId
,
});
per
:
ManagePermissionVal
}
});
}
})();
const
[
chatData
]
=
await
Promise
.
all
([
MongoChatItem
.
findOne
(
{
appId
,
chatId
,
dataId
},
'obj responseData'
).
lean
(),
shareId
?
MongoOutLink
.
findOne
({
shareId
}).
lean
()
:
Promise
.
resolve
(
null
)
]);
const
chatData
=
await
MongoChatItem
.
findOne
(
if
(
chatData
?.
obj
!==
ChatRoleEnum
.
AI
)
{
{
return
{};
appId
,
}
chatId
,
dataId
},
'obj responseData'
).
lean
();
if
(
chatData
?.
obj
===
ChatRoleEnum
.
AI
)
{
const
flowResponses
=
chatData
.
responseData
??
{};
const
data
=
chatData
.
responseData
||
{};
return
req
.
query
.
shareId
return
req
.
query
.
shareId
?
filterPublicNodeResponseData
(
data
)
:
data
;
?
filterPublicNodeResponseData
({
}
else
return
{};
// @ts-ignore
responseDetail
:
authData
.
responseDetail
,
flowResponses
:
chatData
.
responseData
})
:
flowResponses
;
}
}
export
default
NextAPI
(
handler
);
export
default
NextAPI
(
handler
);
projects/app/src/pages/api/v1/chat/completions.ts
View file @
c3cc51c9
...
@@ -363,7 +363,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -363,7 +363,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
/* select fe response field */
/* select fe response field */
const
feResponseData
=
canWrite
const
feResponseData
=
canWrite
?
flowResponses
?
flowResponses
:
filterPublicNodeResponseData
({
flowResponses
});
:
filterPublicNodeResponseData
({
flowResponses
,
responseDetail
});
if
(
stream
)
{
if
(
stream
)
{
workflowResponseWrite
({
workflowResponseWrite
({
...
@@ -380,12 +380,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -380,12 +380,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
});
});
if
(
detail
)
{
if
(
detail
)
{
if
(
responseDetail
||
isPlugin
)
{
workflowResponseWrite
({
workflowResponseWrite
({
event
:
SseResponseEventEnum
.
flowResponses
,
event
:
SseResponseEventEnum
.
flowResponses
,
data
:
feResponseData
data
:
feResponseData
});
});
}
}
}
res
.
end
();
res
.
end
();
...
...
projects/app/src/service/support/permission/auth/chat.ts
View file @
c3cc51c9
...
@@ -42,18 +42,19 @@ export async function authChatCrud({
...
@@ -42,18 +42,19 @@ export async function authChatCrud({
chat
?:
ChatSchema
;
chat
?:
ChatSchema
;
isOutLink
:
boolean
;
isOutLink
:
boolean
;
uid
?:
string
;
uid
?:
string
;
responseDetail
:
boolean
;
}
>
{
}
>
{
const
isOutLink
=
Boolean
((
shareId
||
spaceTeamId
)
&&
outLinkUid
);
const
isOutLink
=
Boolean
((
shareId
||
spaceTeamId
)
&&
outLinkUid
);
if
(
!
chatId
)
return
{
isOutLink
,
uid
:
outLinkUid
};
if
(
!
chatId
)
return
{
isOutLink
,
uid
:
outLinkUid
,
responseDetail
:
true
};
const
chat
=
await
MongoChat
.
findOne
({
appId
,
chatId
}).
lean
();
const
chat
=
await
MongoChat
.
findOne
({
appId
,
chatId
}).
lean
();
const
{
uid
}
=
await
(
async
()
=>
{
const
{
uid
,
responseDetail
}
=
await
(
async
()
=>
{
// outLink Auth
// outLink Auth
if
(
shareId
&&
outLinkUid
)
{
if
(
shareId
&&
outLinkUid
)
{
const
{
uid
}
=
await
authOutLink
({
shareId
,
outLinkUid
});
const
{
uid
,
shareChat
}
=
await
authOutLink
({
shareId
,
outLinkUid
});
if
(
!
chat
||
(
chat
.
shareId
===
shareId
&&
chat
.
outLinkUid
===
uid
))
{
if
(
!
chat
||
(
chat
.
shareId
===
shareId
&&
chat
.
outLinkUid
===
uid
))
{
return
{
uid
};
return
{
uid
,
responseDetail
:
shareChat
.
responseDetail
};
}
}
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
}
}
...
@@ -62,12 +63,12 @@ export async function authChatCrud({
...
@@ -62,12 +63,12 @@ export async function authChatCrud({
const
{
uid
}
=
await
authTeamSpaceToken
({
teamId
:
spaceTeamId
,
teamToken
});
const
{
uid
}
=
await
authTeamSpaceToken
({
teamId
:
spaceTeamId
,
teamToken
});
addLog
.
debug
(
'Auth team token'
,
{
uid
,
spaceTeamId
,
teamToken
,
chatUid
:
chat
?.
outLinkUid
});
addLog
.
debug
(
'Auth team token'
,
{
uid
,
spaceTeamId
,
teamToken
,
chatUid
:
chat
?.
outLinkUid
});
if
(
!
chat
||
(
String
(
chat
.
teamId
)
===
String
(
spaceTeamId
)
&&
chat
.
outLinkUid
===
uid
))
{
if
(
!
chat
||
(
String
(
chat
.
teamId
)
===
String
(
spaceTeamId
)
&&
chat
.
outLinkUid
===
uid
))
{
return
{
uid
};
return
{
uid
,
responseDetail
:
true
};
}
}
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
}
}
if
(
!
chat
)
return
{
id
:
outLinkUid
};
if
(
!
chat
)
return
{
id
:
outLinkUid
,
responseDetail
:
true
};
// auth req
// auth req
const
{
teamId
,
tmbId
,
permission
}
=
await
authApp
({
const
{
teamId
,
tmbId
,
permission
}
=
await
authApp
({
...
@@ -80,18 +81,19 @@ export async function authChatCrud({
...
@@ -80,18 +81,19 @@ export async function authChatCrud({
if
(
String
(
teamId
)
!==
String
(
chat
.
teamId
))
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
if
(
String
(
teamId
)
!==
String
(
chat
.
teamId
))
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
if
(
permission
.
hasManagePer
)
return
{
uid
:
outLinkUid
};
if
(
permission
.
hasManagePer
)
return
{
uid
:
outLinkUid
,
responseDetail
:
true
};
if
(
String
(
tmbId
)
===
String
(
chat
.
tmbId
))
return
{
uid
:
outLinkUid
};
if
(
String
(
tmbId
)
===
String
(
chat
.
tmbId
))
return
{
uid
:
outLinkUid
,
responseDetail
:
true
};
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
return
Promise
.
reject
(
ChatErrEnum
.
unAuthChat
);
})();
})();
if
(
!
chat
)
return
{
isOutLink
,
uid
};
if
(
!
chat
)
return
{
isOutLink
,
uid
,
responseDetail
};
return
{
return
{
chat
,
chat
,
isOutLink
,
isOutLink
,
uid
uid
,
responseDetail
};
};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment