From 5e273341dd3d1f6655c5e0b48a41e259e4ac5b0b Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Tue, 12 Nov 2024 15:56:53 +0800 Subject: [PATCH] perf: outlink config (#3128) * update action * perf: outlink config --- .github/workflows/fastgpt-image.yml | 2 +- packages/global/core/chat/adapt.ts | 3 +- packages/global/support/outLink/api.d.ts | 4 - packages/global/support/outLink/type.d.ts | 4 +- packages/service/core/chat/chatSchema.ts | 2 +- .../service/core/workflow/dispatch/utils.ts | 40 +-- packages/service/support/outLink/schema.ts | 5 +- packages/web/i18n/en/publish.json | 1 + packages/web/i18n/zh/chat.json | 2 +- packages/web/i18n/zh/publish.json | 9 +- .../chat/ChatContainer/ChatBox/Provider.tsx | 10 +- .../ChatBox/components/ChatItem.tsx | 6 +- .../ChatBox/components/ContextModal.tsx | 1 + .../ChatBox/components/QuoteModal.tsx | 26 +- .../ChatBox/components/ResponseTags.tsx | 140 ++++----- .../core/chat/ChatContainer/ChatBox/index.tsx | 2 +- .../chat/components/WholeResponseModal.tsx | 32 +- .../src/components/core/dataset/QuoteItem.tsx | 275 ++++++++--------- .../components/core/dataset/RawSourceBox.tsx | 26 +- .../src/pages/api/core/chat/getHistories.ts | 15 +- .../api/core/chat/getPaginationRecords.ts | 12 +- .../src/pages/api/core/chat/outLink/init.ts | 2 - .../pages/api/core/dataset/collection/read.ts | 12 +- .../src/pages/api/support/outLink/update.ts | 4 +- .../app/src/pages/api/v1/chat/completions.ts | 1 - .../components/Logs/DetailLogsModal.tsx | 2 + .../detail/components/Publish/Link/index.tsx | 281 +++++++++--------- .../app/detail/components/useChatTest.tsx | 3 + projects/app/src/pages/chat/index.tsx | 6 +- projects/app/src/pages/chat/share.tsx | 18 +- projects/app/src/pages/chat/team.tsx | 2 + .../detail/components/InputDataModal.tsx | 2 - .../detail/components/MetaDataCard.tsx | 11 +- .../support/permission/auth/outLink.ts | 6 +- projects/app/src/web/core/app/constants.ts | 2 +- .../src/web/core/chat/context/chatContext.tsx | 8 +- projects/app/src/web/core/dataset/api.ts | 16 +- .../dataset/hooks/readCollectionSource.ts | 13 +- 38 files changed, 469 insertions(+), 537 deletions(-) diff --git a/.github/workflows/fastgpt-image.yml b/.github/workflows/fastgpt-image.yml index 289553070..b8c200887 100644 --- a/.github/workflows/fastgpt-image.yml +++ b/.github/workflows/fastgpt-image.yml @@ -160,7 +160,7 @@ jobs: docker buildx build \ -f projects/app/Dockerfile \ --platform linux/amd64,linux/arm64 \ - --build-arg base_url=fastai \ + --build-arg base_url=/fastai \ --label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/FastGPT" \ --label "org.opencontainers.image.description=fastgpt image" \ --push \ diff --git a/packages/global/core/chat/adapt.ts b/packages/global/core/chat/adapt.ts index 4b4b156d4..02a85fe1c 100644 --- a/packages/global/core/chat/adapt.ts +++ b/packages/global/core/chat/adapt.ts @@ -90,6 +90,7 @@ export const chats2GPTMessages = ({ } } else { const aiResults: ChatCompletionMessageParam[] = []; + //AI item.value.forEach((value, i) => { if (value.type === ChatItemValueTypeEnum.tool && value.tools && reserveTool) { @@ -130,7 +131,7 @@ export const chats2GPTMessages = ({ if ( lastValue && lastValue.type === ChatItemValueTypeEnum.text && - typeof lastResult.content === 'string' + typeof lastResult?.content === 'string' ) { lastResult.content += value.text.content; } else { diff --git a/packages/global/support/outLink/api.d.ts b/packages/global/support/outLink/api.d.ts index 69f2fc540..0088ae7d7 100644 --- a/packages/global/support/outLink/api.d.ts +++ b/packages/global/support/outLink/api.d.ts @@ -10,7 +10,3 @@ export type AuthOutLinkLimitProps = AuthOutLinkChatProps & { outLink: OutLinkSch export type AuthOutLinkResponse = { uid: string; }; -export type AuthOutLinkProps = { - shareId?: string; - outLinkUid?: string; -}; diff --git a/packages/global/support/outLink/type.d.ts b/packages/global/support/outLink/type.d.ts index 77053f36a..4c8435963 100644 --- a/packages/global/support/outLink/type.d.ts +++ b/packages/global/support/outLink/type.d.ts @@ -54,7 +54,7 @@ export type OutLinkSchema = { // whether to hide the node status showNodeStatus: boolean; // whether to show the complete quote - showCompleteQuote: boolean; + showRawSource: boolean; // response when request immediateResponse?: string; @@ -84,7 +84,7 @@ export type OutLinkEditType = { name: string; responseDetail?: OutLinkSchema['responseDetail']; showNodeStatus?: OutLinkSchema['showNodeStatus']; - showCompleteQuote?: OutLinkSchema['showCompleteQuote']; + showRawSource?: OutLinkSchema['showRawSource']; // response when request immediateResponse?: string; // response when error or other situation diff --git a/packages/service/core/chat/chatSchema.ts b/packages/service/core/chat/chatSchema.ts index 325be710c..4aae6eef2 100644 --- a/packages/service/core/chat/chatSchema.ts +++ b/packages/service/core/chat/chatSchema.ts @@ -89,7 +89,7 @@ try { // get chat logs; ChatSchema.index({ teamId: 1, appId: 1, updateTime: -1 }, { background: true }); // get share chat history - ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1, source: 1 }, { background: true }); + ChatSchema.index({ shareId: 1, outLinkUid: 1, updateTime: -1 }, { background: true }); // timer, clear history ChatSchema.index({ teamId: 1, updateTime: -1 }, { background: true }); diff --git a/packages/service/core/workflow/dispatch/utils.ts b/packages/service/core/workflow/dispatch/utils.ts index 4410d065f..3ed92a6e9 100644 --- a/packages/service/core/workflow/dispatch/utils.ts +++ b/packages/service/core/workflow/dispatch/utils.ts @@ -42,27 +42,27 @@ export const getWorkflowResponseWrite = ({ if (!res || res.closed || !useStreamResponse) return; - const detailEvent = [ - SseResponseEventEnum.error, - SseResponseEventEnum.flowNodeStatus, - SseResponseEventEnum.flowResponses, - SseResponseEventEnum.interactive, - SseResponseEventEnum.toolCall, - SseResponseEventEnum.toolParams, - SseResponseEventEnum.toolResponse, - SseResponseEventEnum.updateVariables - ]; + // Forbid show detail + const detailEvent: Record = { + [SseResponseEventEnum.error]: 1, + [SseResponseEventEnum.flowNodeStatus]: 1, + [SseResponseEventEnum.flowResponses]: 1, + [SseResponseEventEnum.interactive]: 1, + [SseResponseEventEnum.toolCall]: 1, + [SseResponseEventEnum.toolParams]: 1, + [SseResponseEventEnum.toolResponse]: 1, + [SseResponseEventEnum.updateVariables]: 1 + }; + if (!detail && detailEvent[event]) return; - if (!detail && detailEvent.includes(event)) return; - - if ( - !showNodeStatus && - (event === SseResponseEventEnum.flowNodeStatus || - event === SseResponseEventEnum.toolCall || - event === SseResponseEventEnum.toolParams || - event === SseResponseEventEnum.toolResponse) - ) - return; + // Forbid show running status + const statusEvent: Record = { + [SseResponseEventEnum.flowNodeStatus]: 1, + [SseResponseEventEnum.toolCall]: 1, + [SseResponseEventEnum.toolParams]: 1, + [SseResponseEventEnum.toolResponse]: 1 + }; + if (!showNodeStatus && statusEvent[event]) return; responseWrite({ res, diff --git a/packages/service/support/outLink/schema.ts b/packages/service/support/outLink/schema.ts index e12ac39fb..f72d3fa75 100644 --- a/packages/service/support/outLink/schema.ts +++ b/packages/service/support/outLink/schema.ts @@ -42,6 +42,7 @@ const OutLinkSchema = new Schema({ lastTime: { type: Date }, + responseDetail: { type: Boolean, default: false @@ -50,7 +51,7 @@ const OutLinkSchema = new Schema({ type: Boolean, default: false }, - showCompleteQuote: { + showRawSource: { type: Boolean, default: false }, @@ -70,6 +71,8 @@ const OutLinkSchema = new Schema({ type: String } }, + + // Third part app config app: { type: Object // could be FeishuAppType | WecomAppType | ... }, diff --git a/packages/web/i18n/en/publish.json b/packages/web/i18n/en/publish.json index 4aebe4aef..c1dd0f127 100644 --- a/packages/web/i18n/en/publish.json +++ b/packages/web/i18n/en/publish.json @@ -20,6 +20,7 @@ "official_account.edit_modal_title": "Edit WeChat Official Account Integration", "official_account.name": "WeChat Official Account Integration", "official_account.params": "WeChat Official Account Parameters", + "private_config": "Visibility configuration", "publish_name": "Name", "qpm_is_empty": "QPM cannot be empty", "qpm_tips": "Maximum number of queries per minute per IP", diff --git a/packages/web/i18n/zh/chat.json b/packages/web/i18n/zh/chat.json index 28ebfb909..a82ce845f 100644 --- a/packages/web/i18n/zh/chat.json +++ b/packages/web/i18n/zh/chat.json @@ -28,7 +28,7 @@ "insert_input_guide,_some_data_already_exists": "有重复数据,已自动过滤,共插入 {{len}} 条数据", "is_chatting": "正在聊天中...请等待结束", "items": "条", - "module_runtime_and": "模块运行时间和", + "module_runtime_and": "工作流总运行时间", "multiple_AI_conversations": "多组 AI 对话", "new_input_guide_lexicon": "新词库", "no_workflow_response": "没有运行数据", diff --git a/packages/web/i18n/zh/publish.json b/packages/web/i18n/zh/publish.json index bd1428711..e24230697 100644 --- a/packages/web/i18n/zh/publish.json +++ b/packages/web/i18n/zh/publish.json @@ -20,10 +20,14 @@ "official_account.edit_modal_title": "编辑微信公众号接入", "official_account.name": "微信公众号接入", "official_account.params": "微信公众号参数", + "private_config": "可见度配置", "publish_name": "名称", "qpm_is_empty": "QPM 不能为空", "qpm_tips": "每个 IP 每分钟最多提问多少次", + "quote_content": "知识库引用", "request_address": "请求地址", + "show_node": "实时运行状态", + "show_origin_content": "查看来源原文", "show_share_link_modal_title": "开始使用", "token_auth": "身份验证", "token_auth_tips": "身份校验服务器地址", @@ -33,8 +37,5 @@ "wecom.bot_desc": "通过 API 直接接入企业微信机器人", "wecom.create_modal_title": "创建企微机器人", "wecom.edit_modal_title": "编辑企微机器人", - "wecom.title": "发布到企业微信机器人", - "show_node": "实时运行状态", - "quote_content": "引用内容", - "show_origin_content": "查看来源原文" + "wecom.title": "发布到企业微信机器人" } diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Provider.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Provider.tsx index 5e692ccc5..2368c818c 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Provider.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Provider.tsx @@ -34,7 +34,9 @@ export type ChatProviderProps = OutLinkChatAuthProps & { // not chat test params chatId?: string; - chatType?: 'log' | 'chat' | 'share' | 'team'; + chatType: 'log' | 'chat' | 'share' | 'team'; + showRawSource: boolean; + showNodeStatus: boolean; }; type useChatStoreType = OutLinkChatAuthProps & @@ -139,6 +141,8 @@ const Provider = ({ setChatHistories, variablesForm, chatType = 'chat', + showRawSource, + showNodeStatus, chatConfig = {}, children, ...props @@ -241,7 +245,9 @@ const Provider = ({ outLinkAuthData, variablesForm, getHistoryResponseData, - chatType + chatType, + showRawSource, + showNodeStatus }; return {children}; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx index 2f6de574c..19b4df901 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx @@ -137,7 +137,9 @@ const ChatItem = (props: Props) => { }; const { t } = useTranslation(); - const { isChatting, chatType } = useContextSelector(ChatBoxContext, (v) => v); + const isChatting = useContextSelector(ChatBoxContext, (v) => v.isChatting); + const chatType = useContextSelector(ChatBoxContext, (v) => v.chatType); + const showNodeStatus = useContextSelector(ChatBoxContext, (v) => v.showNodeStatus); const isChatLog = chatType === 'log'; const { copyData } = useCopyData(); @@ -237,7 +239,7 @@ const ChatItem = (props: Props) => { {/* Workflow status */} - {!!chatStatusMap && statusBoxData && isLastChild && ( + {!!chatStatusMap && statusBoxData && isLastChild && showNodeStatus && ( void; dataId: string border={'base'} _notLast={{ mb: 2 }} position={'relative'} + bg={i % 2 === 0 ? 'white' : 'myGray.50'} > {item.obj} {item.value} diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/QuoteModal.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/QuoteModal.tsx index 970e88183..374ba85c5 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/QuoteModal.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/QuoteModal.tsx @@ -11,12 +11,14 @@ import { getWebReqUrl } from '@fastgpt/web/common/system/utils'; const QuoteModal = ({ rawSearch = [], onClose, - showDetail, + canEditDataset, + showRawSource, metadata }: { rawSearch: SearchDataResponseItemType[]; onClose: () => void; - showDetail: boolean; + canEditDataset: boolean; + showRawSource: boolean; metadata?: { collectionId: string; sourceId?: string; @@ -47,7 +49,7 @@ const QuoteModal = ({ title={ {metadata ? ( - + ) : ( <>{t('common:core.chat.Quote Amount', { amount: rawSearch.length })} )} @@ -58,7 +60,11 @@ const QuoteModal = ({ } > - + @@ -69,10 +75,12 @@ export default QuoteModal; export const QuoteList = React.memo(function QuoteList({ rawSearch = [], - showDetail + canEditDataset, + canViewSource }: { rawSearch: SearchDataResponseItemType[]; - showDetail: boolean; + canEditDataset: boolean; + canViewSource: boolean; }) { const theme = useTheme(); @@ -89,7 +97,11 @@ export const QuoteList = React.memo(function QuoteList({ _hover={{ '& .hover-data': { display: 'flex' } }} bg={i % 2 === 0 ? 'white' : 'myWhite.500'} > - + ))} diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx index 31242e967..f8596d59f 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ResponseTags.tsx @@ -7,13 +7,11 @@ import MyTag from '@fastgpt/web/components/common/Tag/index'; import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils'; import ChatBoxDivider from '@/components/core/chat/Divider'; -import { strIsLink } from '@fastgpt/global/common/string/tools'; import MyIcon from '@fastgpt/web/components/common/Icon'; import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { ChatSiteItemType } from '@fastgpt/global/core/chat/type'; import { addStatisticalDataToHistoryItem } from '@/global/core/chat/utils'; import { useSize } from 'ahooks'; -import { ChatContext } from '@/web/core/chat/context/chatContext'; import { useContextSelector } from 'use-context-selector'; import { ChatBoxContext } from '../Provider'; @@ -23,11 +21,9 @@ const WholeResponseModal = dynamic(() => import('../../../components/WholeRespon const ResponseTags = ({ showTags, - showDetail, historyItem }: { showTags: boolean; - showDetail: boolean; historyItem: ChatSiteItemType; }) => { const { isPc } = useSystem(); @@ -51,12 +47,9 @@ const ResponseTags = ({ }>(); const [quoteFolded, setQuoteFolded] = useState(true); - const showCompleteQuote = useContextSelector(ChatContext, (v) => v.showCompleteQuote); - const { chatType } = useContextSelector(ChatBoxContext, (v) => v); - - const showAllTag = useMemo(() => { - return chatType !== 'share' && chatType !== 'team'; - }, [chatType]); + const chatType = useContextSelector(ChatBoxContext, (v) => v.chatType); + const showRawSource = useContextSelector(ChatBoxContext, (v) => v.showRawSource); + const notSharePage = useMemo(() => chatType !== 'share', [chatType]); const { isOpen: isOpenWholeModal, @@ -88,13 +81,20 @@ const ResponseTags = ({ sourceName: item.sourceName, sourceId: item.sourceId, icon: getSourceNameIcon({ sourceId: item.sourceId, sourceName: item.sourceName }), - canReadQuote: showCompleteQuote || strIsLink(item.sourceId), collectionId: item.collectionId })); - }, [quoteList, showCompleteQuote]); + }, [quoteList]); + + const notEmptyTags = + quoteList.length > 0 || + (llmModuleAccount === 1 && notSharePage) || + (llmModuleAccount > 1 && notSharePage) || + (isPc && runningTime > 0) || + notSharePage; return !showTags ? null : ( <> + {/* quote */} {sourceList.length > 0 && ( <> @@ -188,74 +188,74 @@ const ResponseTags = ({ )} - - {quoteList.length > 0 && ( - - setQuoteModalData({ rawSearch: quoteList })} - > - {t('chat:citations', { num: quoteList.length })} + {notEmptyTags && ( + + {quoteList.length > 0 && ( + + setQuoteModalData({ rawSearch: quoteList })} + > + {t('chat:citations', { num: quoteList.length })} + + + )} + {llmModuleAccount === 1 && notSharePage && ( + <> + {historyPreviewLength > 0 && ( + + + {t('chat:contextual', { num: historyPreviewLength })} + + + )} + + )} + {llmModuleAccount > 1 && notSharePage && ( + + {t('chat:multiple_AI_conversations')} - - )} - {llmModuleAccount === 1 && showAllTag && ( - <> - {historyPreviewLength > 0 && ( - - - {t('chat:contextual', { num: historyPreviewLength })} - - - )} - - )} - {llmModuleAccount > 1 && showAllTag && ( - - {t('chat:multiple_AI_conversations')} - - )} + )} + {isPc && runningTime > 0 && ( + + + {runningTime}s + + + )} - {isPc && runningTime > 0 && ( - - - {runningTime}s - - - )} - - {showAllTag && ( - - - {t('common:core.chat.response.Read complete response')} - - - )} - + {notSharePage && ( + + + {t('common:core.chat.response.Read complete response')} + + + )} + + )} {!!quoteModalData && ( setQuoteModalData(undefined)} /> )} {isOpenContextModal && } - {isOpenWholeModal && ( - - )} + {isOpenWholeModal && } ); }; diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx index a6e142abc..2b12802c0 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx @@ -566,6 +566,7 @@ const ChatBox = ( // tts audio autoTTSResponse && splitText2Audio(responseText, true); } catch (err: any) { + console.log(err); toast({ title: t(getErrText(err, 'core.chat.error.Chat error') as any), status: 'error', @@ -948,7 +949,6 @@ const ChatBox = ( > diff --git a/projects/app/src/components/core/chat/components/WholeResponseModal.tsx b/projects/app/src/components/core/chat/components/WholeResponseModal.tsx index cd07de624..908e19142 100644 --- a/projects/app/src/components/core/chat/components/WholeResponseModal.tsx +++ b/projects/app/src/components/core/chat/components/WholeResponseModal.tsx @@ -31,12 +31,10 @@ type sideTabItemType = { /* Per response value */ export const WholeResponseContent = ({ activeModule, - hideTabs, - showDetail + hideTabs }: { activeModule: ChatHistoryItemResType; hideTabs?: boolean; - showDetail: boolean; }) => { const { t } = useTranslation(); @@ -233,7 +231,7 @@ export const WholeResponseContent = ({ {activeModule.quoteList && activeModule.quoteList.length > 0 && ( } + rawDom={} /> )} @@ -531,12 +529,10 @@ const SideTabItem = ({ /* Modal main container */ export const ResponseBox = React.memo(function ResponseBox({ response, - showDetail, hideTabs = false, useMobile = false }: { response: ChatHistoryItemResType[]; - showDetail: boolean; hideTabs?: boolean; useMobile?: boolean; }) { @@ -659,11 +655,7 @@ export const ResponseBox = React.memo(function ResponseBox({ - + ) : ( @@ -723,11 +715,7 @@ export const ResponseBox = React.memo(function ResponseBox({ - + )} @@ -737,15 +725,7 @@ export const ResponseBox = React.memo(function ResponseBox({ ); }); -const WholeResponseModal = ({ - showDetail, - onClose, - dataId -}: { - showDetail: boolean; - onClose: () => void; - dataId: string; -}) => { +const WholeResponseModal = ({ onClose, dataId }: { onClose: () => void; dataId: string }) => { const { t } = useTranslation(); const { getHistoryResponseData } = useContextSelector(ChatBoxContext, (v) => v); @@ -774,7 +754,7 @@ const WholeResponseModal = ({ } > {!!response?.length ? ( - + ) : ( )} diff --git a/projects/app/src/components/core/dataset/QuoteItem.tsx b/projects/app/src/components/core/dataset/QuoteItem.tsx index 1c3fefaf8..c8f9e4d3b 100644 --- a/projects/app/src/components/core/dataset/QuoteItem.tsx +++ b/projects/app/src/components/core/dataset/QuoteItem.tsx @@ -9,8 +9,6 @@ import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; import dynamic from 'next/dynamic'; import MyBox from '@fastgpt/web/components/common/MyBox'; import { SearchScoreTypeEnum, SearchScoreTypeMap } from '@fastgpt/global/core/dataset/constants'; -import { useContextSelector } from 'use-context-selector'; -import { ChatBoxContext } from '../chat/ChatContainer/ChatBox/Provider'; const InputDataModal = dynamic(() => import('@/pages/dataset/detail/components/InputDataModal')); @@ -47,21 +45,15 @@ const scoreTheme: Record< const QuoteItem = ({ quoteItem, canViewSource, - linkToDataset + canEditDataset }: { quoteItem: SearchDataResponseItemType; canViewSource?: boolean; - linkToDataset?: boolean; + canEditDataset?: boolean; }) => { const { t } = useTranslation(); const [editInputData, setEditInputData] = useState<{ dataId: string; collectionId: string }>(); - const { chatType } = useContextSelector(ChatBoxContext, (v) => v); - - const canEdit = useMemo(() => { - return chatType !== 'share' && chatType !== 'team'; - }, [chatType]); - const score = useMemo(() => { if (!Array.isArray(quoteItem.score)) { return { @@ -118,89 +110,64 @@ const QuoteItem = ({ > {score?.primaryScore && ( - <> - {canViewSource ? ( - - - #{score.primaryScore.index + 1} - - - {t(SearchScoreTypeMap[score.primaryScore.type]?.label as any)} - {SearchScoreTypeMap[score.primaryScore.type]?.showScore - ? ` ${score.primaryScore.value.toFixed(4)}` - : ''} - - - - ) : ( - - #{score.primaryScore.index + 1} - - )} - - )} - {canViewSource && - score.secondaryScore.map((item, i) => ( - - - - - #{item.index + 1} - - - {t(SearchScoreTypeMap[item.type]?.label as any)}: {item.value.toFixed(4)} - - - - {SearchScoreTypeMap[item.type]?.showScore && ( - - )} - + + + #{score.primaryScore.index + 1} + + + {t(SearchScoreTypeMap[score.primaryScore.type]?.label as any)} + {SearchScoreTypeMap[score.primaryScore.type]?.showScore + ? ` ${score.primaryScore.value.toFixed(4)}` + : ''} - - ))} + + + )} + {score.secondaryScore.map((item, i) => ( + + + + + #{item.index + 1} + + + {t(SearchScoreTypeMap[item.type]?.label as any)}: {item.value.toFixed(4)} + + + + {SearchScoreTypeMap[item.type]?.showScore && ( + + )} + + + + ))} @@ -208,73 +175,71 @@ const QuoteItem = ({ {quoteItem.a} - {canViewSource && ( - - - - - {quoteItem.q.length + (quoteItem.a?.length || 0)} - - - - - {quoteItem.id && canEdit && ( - - - - setEditInputData({ - dataId: quoteItem.id, - collectionId: quoteItem.collectionId - }) - } - /> - - - )} - {linkToDataset && canEdit && ( - + + + + {quoteItem.q.length + (quoteItem.a?.length || 0)} + + + + + {quoteItem.id && canEditDataset && ( + + - {t('common:core.dataset.Go Dataset')} - - - )} - - )} + + setEditInputData({ + dataId: quoteItem.id, + collectionId: quoteItem.collectionId + }) + } + /> + + + )} + {canEditDataset && ( + + {t('common:core.dataset.Go Dataset')} + + + )} + {editInputData && ( diff --git a/projects/app/src/components/core/dataset/RawSourceBox.tsx b/projects/app/src/components/core/dataset/RawSourceBox.tsx index e51d88d06..5646fde7c 100644 --- a/projects/app/src/components/core/dataset/RawSourceBox.tsx +++ b/projects/app/src/components/core/dataset/RawSourceBox.tsx @@ -6,37 +6,35 @@ import { getCollectionSourceAndOpen } from '@/web/core/dataset/hooks/readCollect import { getSourceNameIcon } from '@fastgpt/global/core/dataset/utils'; import MyIcon from '@fastgpt/web/components/common/Icon'; import { useI18n } from '@/web/context/I18n'; -import { ChatBoxContext } from '../chat/ChatContainer/ChatBox/Provider'; -import { useContextSelector } from 'use-context-selector'; +import { ShareChatAuthProps } from '@fastgpt/global/support/permission/chat'; -type Props = BoxProps & { - sourceName?: string; - collectionId: string; - sourceId?: string; - canView?: boolean; -}; +type Props = BoxProps & + ShareChatAuthProps & { + sourceName?: string; + collectionId: string; + sourceId?: string; + canView?: boolean; + }; const RawSourceBox = ({ sourceId, collectionId, sourceName = '', canView = true, + shareId, + outLinkUid, ...props }: Props) => { const { t } = useTranslation(); const { fileT } = useI18n(); - const { shareId, outLinkUid, chatType } = useContextSelector(ChatBoxContext, (v) => v); const canPreview = !!sourceId && canView; const icon = useMemo(() => getSourceNameIcon({ sourceId, sourceName }), [sourceId, sourceName]); const read = getCollectionSourceAndOpen({ collectionId, - authProps: { - shareId, - outLinkUid - }, - isShare: chatType === 'share' + shareId, + outLinkUid }); return ( diff --git a/projects/app/src/pages/api/core/chat/getHistories.ts b/projects/app/src/pages/api/core/chat/getHistories.ts index da93fc70a..86a2e7412 100644 --- a/projects/app/src/pages/api/core/chat/getHistories.ts +++ b/projects/app/src/pages/api/core/chat/getHistories.ts @@ -17,16 +17,8 @@ async function handler( req: ApiRequestProps, res: ApiResponseType ): Promise> { - const { - appId, - shareId, - outLinkUid, - teamId, - teamToken, - offset, - pageSize, - source = ChatSourceEnum.online - } = req.body as getHistoriesBody; + const { appId, shareId, outLinkUid, teamId, teamToken, offset, pageSize, source } = + req.body as getHistoriesBody; const match = await (async () => { if (shareId && outLinkUid) { @@ -35,7 +27,6 @@ async function handler( return { shareId, outLinkUid: uid, - source: ChatSourceEnum.share, updateTime: { $gte: new Date(new Date().setDate(new Date().getDate() - 30)) } @@ -55,7 +46,7 @@ async function handler( return { tmbId, appId, - source: source + source }; } })(); diff --git a/projects/app/src/pages/api/core/chat/getPaginationRecords.ts b/projects/app/src/pages/api/core/chat/getPaginationRecords.ts index 30ffdbda5..e32b755e4 100644 --- a/projects/app/src/pages/api/core/chat/getPaginationRecords.ts +++ b/projects/app/src/pages/api/core/chat/getPaginationRecords.ts @@ -9,7 +9,7 @@ import { getChatItems } from '@fastgpt/service/core/chat/controller'; import { authChatCrud } from '@/service/support/permission/auth/chat'; import { MongoApp } from '@fastgpt/service/core/app/schema'; import { AppErrEnum } from '@fastgpt/global/common/error/code/app'; -import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; +import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; import { filterPublicNodeResponseData } from '@fastgpt/global/core/chat/utils'; import { authOutLink } from '@/service/support/permission/auth/outLink'; import { GetChatTypeEnum } from '@/global/core/chat/constants'; @@ -70,9 +70,7 @@ async function handler( [GetChatTypeEnum.normal]: `dataId obj value adminFeedback userBadFeedback userGoodFeedback time ${ DispatchNodeResponseKeyEnum.nodeResponse } ${loadCustomFeedbacks ? 'customFeedbacks' : ''}`, - [GetChatTypeEnum.outLink]: `dataId obj value userGoodFeedback userBadFeedback adminFeedback time ${ - shareChat?.responseDetail || isPlugin ? `${DispatchNodeResponseKeyEnum.nodeResponse}` : '' - } `, + [GetChatTypeEnum.outLink]: `dataId obj value userGoodFeedback userBadFeedback adminFeedback time ${DispatchNodeResponseKeyEnum.nodeResponse}`, [GetChatTypeEnum.team]: `dataId obj value userGoodFeedback userBadFeedback adminFeedback time ${DispatchNodeResponseKeyEnum.nodeResponse}` }; @@ -85,10 +83,14 @@ async function handler( }); // Remove important information - if (type === 'outLink' && app.type !== AppTypeEnum.plugin) { + if (shareChat && app.type !== AppTypeEnum.plugin) { histories.forEach((item) => { if (item.obj === ChatRoleEnum.AI) { item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData }); + + if (shareChat.showNodeStatus === false) { + item.value = item.value.filter((v) => v.type !== ChatItemValueTypeEnum.tool); + } } }); } diff --git a/projects/app/src/pages/api/core/chat/outLink/init.ts b/projects/app/src/pages/api/core/chat/outLink/init.ts index 20487b0e1..6489050d2 100644 --- a/projects/app/src/pages/api/core/chat/outLink/init.ts +++ b/projects/app/src/pages/api/core/chat/outLink/init.ts @@ -2,7 +2,6 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@fastgpt/service/common/response'; import type { InitChatResponse, InitOutLinkChatProps } from '@/global/core/chat/api.d'; import { getGuideModule, getAppChatConfig } from '@fastgpt/global/core/workflow/utils'; -import { getChatModelNameListByModules } from '@/service/core/app/workflow'; import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema'; import { authOutLink } from '@/service/support/permission/auth/outLink'; import { MongoApp } from '@fastgpt/service/core/app/schema'; @@ -54,7 +53,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { storeWelcomeText: chat?.welcomeText, isPublicFetch: false }), - chatModels: getChatModelNameListByModules(nodes), name: app.name, avatar: app.avatar, intro: app.intro, diff --git a/projects/app/src/pages/api/core/dataset/collection/read.ts b/projects/app/src/pages/api/core/dataset/collection/read.ts index 067f3a201..9c1ff985c 100644 --- a/projects/app/src/pages/api/core/dataset/collection/read.ts +++ b/projects/app/src/pages/api/core/dataset/collection/read.ts @@ -5,15 +5,13 @@ import { DatasetCollectionTypeEnum } from '@fastgpt/global/core/dataset/constant import { createFileToken } from '@fastgpt/service/support/permission/controller'; import { BucketNameEnum, ReadFileBaseUrl } from '@fastgpt/global/common/file/constants'; import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant'; -import { AuthOutLinkProps } from '@fastgpt/global/support/outLink/api'; -import { authOutLink } from '@/service/support/permission/auth/outLink'; +import { ShareChatAuthProps } from '@fastgpt/global/support/permission/chat'; export type readCollectionSourceQuery = {}; export type readCollectionSourceBody = { collectionId: string; - isShare?: boolean; -} & AuthOutLinkProps; +} & ShareChatAuthProps; export type readCollectionSourceResponse = { type: 'url'; @@ -23,12 +21,6 @@ export type readCollectionSourceResponse = { async function handler( req: ApiRequestProps ): Promise { - const { isShare, outLinkUid, shareId } = req.body; - - if (isShare) { - await authOutLink({ shareId, outLinkUid }); - } - const { collection, teamId, tmbId } = await authDatasetCollection({ req, authToken: true, diff --git a/projects/app/src/pages/api/support/outLink/update.ts b/projects/app/src/pages/api/support/outLink/update.ts index 9108a46a7..829f556a5 100644 --- a/projects/app/src/pages/api/support/outLink/update.ts +++ b/projects/app/src/pages/api/support/outLink/update.ts @@ -24,7 +24,7 @@ export type OutLinkUpdateResponse = {}; async function handler( req: ApiRequestProps ): Promise { - const { _id, name, responseDetail, limit, app, showCompleteQuote, showNodeStatus } = req.body; + const { _id, name, responseDetail, limit, app, showRawSource, showNodeStatus } = req.body; if (!_id) { return Promise.reject(CommonErrEnum.missingParams); @@ -35,7 +35,7 @@ async function handler( await MongoOutLink.findByIdAndUpdate(_id, { name, responseDetail, - showCompleteQuote, + showRawSource, showNodeStatus, limit, app diff --git a/projects/app/src/pages/api/v1/chat/completions.ts b/projects/app/src/pages/api/v1/chat/completions.ts index 6d9e0fedd..8d017ff27 100644 --- a/projects/app/src/pages/api/v1/chat/completions.ts +++ b/projects/app/src/pages/api/v1/chat/completions.ts @@ -84,7 +84,6 @@ type AuthResponseType = { app: AppSchema; responseDetail?: boolean; showNodeStatus?: boolean; - showCompleteQuote?: boolean; authType: `${AuthUserTypeEnum}`; apikey?: string; canWrite: boolean; diff --git a/projects/app/src/pages/app/detail/components/Logs/DetailLogsModal.tsx b/projects/app/src/pages/app/detail/components/Logs/DetailLogsModal.tsx index 76ed968e3..f21ccf9a0 100644 --- a/projects/app/src/pages/app/detail/components/Logs/DetailLogsModal.tsx +++ b/projects/app/src/pages/app/detail/components/Logs/DetailLogsModal.tsx @@ -181,6 +181,8 @@ const DetailLogsModal = ({ appId={appId} chatId={chatId} chatType="log" + showRawSource + showNodeStatus /> )} diff --git a/projects/app/src/pages/app/detail/components/Publish/Link/index.tsx b/projects/app/src/pages/app/detail/components/Publish/Link/index.tsx index 4acdcb5d7..a438e519b 100644 --- a/projects/app/src/pages/app/detail/components/Publish/Link/index.tsx +++ b/projects/app/src/pages/app/detail/components/Publish/Link/index.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useMemo, useState } from 'react'; import { Flex, Box, @@ -32,7 +32,6 @@ import { useCopyData } from '@/web/common/hooks/useCopyData'; import { useForm } from 'react-hook-form'; import { defaultOutLinkForm } from '@/web/core/app/constants'; import type { OutLinkEditType, OutLinkSchema } from '@fastgpt/global/support/outLink/type.d'; -import { useRequest } from '@/web/common/hooks/useRequest'; import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant'; import { useTranslation } from 'next-i18next'; import { useToast } from '@fastgpt/web/hooks/useToast'; @@ -48,6 +47,7 @@ import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; import EmptyTip from '@fastgpt/web/components/common/EmptyTip'; import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel'; import MyBox from '@fastgpt/web/components/common/MyBox'; +import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; const SelectUsingWayModal = dynamic(() => import('./SelectUsingWayModal')); @@ -183,9 +183,9 @@ const Share = ({ appId }: { appId: string; type: PublishChannelEnum }) => { setEditLinkData({ _id: item._id, name: item.name, - responseDetail: item.responseDetail, - showCompleteQuote: item.showCompleteQuote, - showNodeStatus: item.showNodeStatus, + responseDetail: item.responseDetail ?? false, + showRawSource: item.showRawSource ?? false, + showNodeStatus: item.showNodeStatus ?? false, limit: item.limit }) }, @@ -281,36 +281,23 @@ function EditLinkModal({ }); const responseDetail = watch('responseDetail'); - const showCompleteQuote = watch('showCompleteQuote'); - - useEffect(() => { - if (!responseDetail) { - setValue('showCompleteQuote', false); - } - }, [responseDetail, setValue]); - - useEffect(() => { - if (showCompleteQuote) { - setValue('responseDetail', true); - } - }, [showCompleteQuote, setValue]); + const showRawSource = watch('showRawSource'); const isEdit = useMemo(() => !!defaultData._id, [defaultData]); - const { mutate: onclickCreate, isLoading: creating } = useRequest({ - mutationFn: async (e: OutLinkEditType) => + const { runAsync: onclickCreate, loading: creating } = useRequest2( + async (e: OutLinkEditType) => createShareChat({ ...e, appId, type }), - errorToast: t('common:common.Create Failed'), - onSuccess: onCreate - }); - const { mutate: onclickUpdate, isLoading: updating } = useRequest({ - mutationFn: (e: OutLinkEditType) => { - return putShareChat(e); - }, + { + errorToast: t('common:common.Create Failed'), + onSuccess: onCreate + } + ); + const { runAsync: onclickUpdate, loading: updating } = useRequest2(putShareChat, { errorToast: t('common:common.Update Failed'), onSuccess: onEdit }); @@ -320,131 +307,133 @@ function EditLinkModal({ isOpen={true} iconSrc="/imgs/modal/shareFill.svg" title={isEdit ? publishT('edit_link') : publishT('create_link')} - w={'53.125rem'} + maxW={['90vw', '700px']} + w={'100%'} + h={['90vh', 'auto']} > - - - - - {t('publish:basic_info')} - - - {t('common:Name')} - - - {feConfigs?.isPlus && ( - <> - - - {t('common:common.Expired Time')} - - { - setValue('limit.expiredTime', new Date(e.target.value)); - }} - /> - - - - QPM - - - - - - - {t('common:support.outlink.Max usage points')} - - - - - - - - {publishT('token_auth')} - - - - - - {publishT('token_auth_use_cases')} - - - )} + + + + {t('publish:basic_info')} - - - {t('publish:config')} - - - - {t('publish:show_node')} + + {t('common:Name')} + + + {feConfigs?.isPlus && ( + <> + + + {t('common:common.Expired Time')} + + { + setValue('limit.expiredTime', new Date(e.target.value)); + }} + /> + + + + QPM + + + + + + + {t('common:support.outlink.Max usage points')} + + + - - - - - {t('common:support.outlink.share.Response Quote')} - + + + {publishT('token_auth')} + + + - - - - - - {t('common:support.outlink.share.show_complete_quote')} - - - - + + {publishT('token_auth_use_cases')} + + + )} + + + + {t('publish:private_config')} - + + {t('publish:show_node')} + + + + + {t('common:support.outlink.share.Response Quote')} + + + + + {/* + + {t('common:support.outlink.share.show_complete_quote')} + + + + */} + diff --git a/projects/app/src/pages/app/detail/components/useChatTest.tsx b/projects/app/src/pages/app/detail/components/useChatTest.tsx index 256a2d2ab..8c874ca22 100644 --- a/projects/app/src/pages/app/detail/components/useChatTest.tsx +++ b/projects/app/src/pages/app/detail/components/useChatTest.tsx @@ -113,6 +113,9 @@ export const useChatTest = ({ appAvatar={appDetail.avatar} userAvatar={userInfo?.avatar} showMarkIcon + chatType="chat" + showRawSource + showNodeStatus chatConfig={chatConfig} onStartChat={startChat} onDelMessage={() => {}} diff --git a/projects/app/src/pages/chat/index.tsx b/projects/app/src/pages/chat/index.tsx index 62c67ed28..8e8637bca 100644 --- a/projects/app/src/pages/chat/index.tsx +++ b/projects/app/src/pages/chat/index.tsx @@ -34,6 +34,7 @@ import { useChat } from '@/components/core/chat/ChatContainer/useChat'; import ChatBox from '@/components/core/chat/ChatContainer/ChatBox'; import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { InitChatResponse } from '@/global/core/chat/api'; +import { ChatSourceEnum } from '@fastgpt/global/core/chat/constants'; const CustomPluginRunBox = dynamic(() => import('./components/CustomPluginRunBox')); @@ -283,6 +284,9 @@ const Chat = ({ onDelMessage={({ contentId }) => delChatRecordById({ contentId, appId, chatId })} appId={appId} chatId={chatId} + chatType={'chat'} + showRawSource + showNodeStatus /> )} @@ -341,7 +345,7 @@ const Render = (props: Props) => { } }); - const providerParams = useMemo(() => ({ appId }), [appId]); + const providerParams = useMemo(() => ({ appId, source: ChatSourceEnum.online }), [appId]); return ( diff --git a/projects/app/src/pages/chat/share.tsx b/projects/app/src/pages/chat/share.tsx index 34a933513..76b298422 100644 --- a/projects/app/src/pages/chat/share.tsx +++ b/projects/app/src/pages/chat/share.tsx @@ -42,7 +42,8 @@ type Props = { shareId: string; authToken: string; customUid: string; - showCompleteQuote: boolean; + showRawSource: boolean; + showNodeStatus: boolean; }; const OutLink = ( @@ -52,7 +53,7 @@ const OutLink = ( ) => { const { t } = useTranslation(); const router = useRouter(); - const { outLinkUid } = props; + const { outLinkUid, showRawSource, showNodeStatus } = props; const { shareId = '', chatId = '', @@ -366,6 +367,8 @@ const OutLink = ( shareId={shareId} outLinkUid={outLinkUid} chatType="share" + showRawSource={showRawSource} + showNodeStatus={showNodeStatus} /> )} @@ -377,13 +380,13 @@ const OutLink = ( }; const Render = (props: Props) => { - const { shareId, authToken, customUid, showCompleteQuote } = props; + const { shareId, authToken, customUid } = props; const { localUId, loaded } = useShareChatStore(); const [isLoaded, setIsLoaded] = useState(false); const contextParams = useMemo(() => { - return { shareId, outLinkUid: authToken || localUId || customUid, showCompleteQuote }; - }, [authToken, customUid, localUId, shareId, showCompleteQuote]); + return { shareId, outLinkUid: authToken || localUId || customUid }; + }, [authToken, customUid, localUId, shareId]); useMount(() => { setIsLoaded(true); @@ -417,7 +420,7 @@ export async function getServerSideProps(context: any) { { shareId }, - 'appId showCompleteQuote' + 'appId showRawSource showNodeStatus' ) .populate('appId', 'name avatar intro') .lean()) as OutLinkWithAppType; @@ -433,7 +436,8 @@ export async function getServerSideProps(context: any) { appName: app?.appId?.name ?? 'AI', appAvatar: app?.appId?.avatar ?? '', appIntro: app?.appId?.intro ?? 'AI', - showCompleteQuote: app?.showCompleteQuote ?? false, + showRawSource: app?.showRawSource ?? false, + showNodeStatus: app?.showNodeStatus ?? false, shareId: shareId ?? '', authToken: authToken ?? '', customUid, diff --git a/projects/app/src/pages/chat/team.tsx b/projects/app/src/pages/chat/team.tsx index eea107f05..4867b28a7 100644 --- a/projects/app/src/pages/chat/team.tsx +++ b/projects/app/src/pages/chat/team.tsx @@ -297,6 +297,8 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => { teamId={teamId} teamToken={teamToken} chatType="team" + showRawSource + showNodeStatus /> )} diff --git a/projects/app/src/pages/dataset/detail/components/InputDataModal.tsx b/projects/app/src/pages/dataset/detail/components/InputDataModal.tsx index ba2546469..e77363a17 100644 --- a/projects/app/src/pages/dataset/detail/components/InputDataModal.tsx +++ b/projects/app/src/pages/dataset/detail/components/InputDataModal.tsx @@ -26,11 +26,9 @@ import { useRequest, useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { useConfirm } from '@fastgpt/web/hooks/useConfirm'; import { getDefaultIndex, getSourceNameIcon } from '@fastgpt/global/core/dataset/utils'; import { DatasetDataIndexItemType } from '@fastgpt/global/core/dataset/type'; -import SideTabs from '@/components/SideTabs'; import DeleteIcon from '@fastgpt/web/components/common/Icon/delete'; import { defaultCollectionDetail } from '@/web/core/dataset/constants'; import { getDocPath } from '@/web/common/system/doc'; -import RawSourceBox from '@/components/core/dataset/RawSourceBox'; import MyBox from '@fastgpt/web/components/common/MyBox'; import { getErrText } from '@fastgpt/global/common/error/utils'; import { useSystemStore } from '@/web/common/system/useSystemStore'; diff --git a/projects/app/src/pages/dataset/detail/components/MetaDataCard.tsx b/projects/app/src/pages/dataset/detail/components/MetaDataCard.tsx index a17a92624..092228ce8 100644 --- a/projects/app/src/pages/dataset/detail/components/MetaDataCard.tsx +++ b/projects/app/src/pages/dataset/detail/components/MetaDataCard.tsx @@ -10,8 +10,6 @@ import { formatTime2YMDHM } from '@fastgpt/global/common/string/time'; import { DatasetCollectionTypeMap, TrainingTypeMap } from '@fastgpt/global/core/dataset/constants'; import { getCollectionSourceAndOpen } from '@/web/core/dataset/hooks/readCollectionSource'; import MyIcon from '@fastgpt/web/components/common/Icon'; -import { useContextSelector } from 'use-context-selector'; -import { ChatBoxContext } from '@/components/core/chat/ChatContainer/ChatBox/Provider'; const MetaDataCard = ({ datasetId }: { datasetId: string }) => { const { t } = useTranslation(); @@ -21,15 +19,8 @@ const MetaDataCard = ({ datasetId }: { datasetId: string }) => { datasetId: string; }; - const { shareId, outLinkUid, chatType } = useContextSelector(ChatBoxContext, (v) => v); - const readSource = getCollectionSourceAndOpen({ - collectionId, - authProps: { - shareId, - outLinkUid - }, - isShare: chatType === 'share' + collectionId }); const { data: collection, loading: isLoading } = useRequest2( () => getDatasetCollectionById(collectionId), diff --git a/projects/app/src/service/support/permission/auth/outLink.ts b/projects/app/src/service/support/permission/auth/outLink.ts index 7f0ab1a4e..5362fcf75 100644 --- a/projects/app/src/service/support/permission/auth/outLink.ts +++ b/projects/app/src/service/support/permission/auth/outLink.ts @@ -3,9 +3,9 @@ import type { AuthOutLinkChatProps, AuthOutLinkLimitProps, AuthOutLinkInitProps, - AuthOutLinkResponse, - AuthOutLinkProps + AuthOutLinkResponse } from '@fastgpt/global/support/outLink/api.d'; +import { ShareChatAuthProps } from '@fastgpt/global/support/permission/chat'; import { authOutLinkValid } from '@fastgpt/service/support/permission/publish/authLink'; import { getUserChatInfoAndAuthTeamPoints } from '@/service/support/permission/auth/team'; import { AuthUserTypeEnum } from '@fastgpt/global/support/permission/constant'; @@ -24,7 +24,7 @@ export function authOutLinkChatLimit(data: AuthOutLinkLimitProps): Promise void; - showCompleteQuote: boolean; }; export const ChatContext = createContext({ @@ -86,8 +85,7 @@ export const ChatContext = createContext({ onChangeAppId: function (appId: string): void { throw new Error('Function not implemented.'); }, - isLoading: false, - showCompleteQuote: true + isLoading: false }); const ChatContextProvider = ({ @@ -96,7 +94,6 @@ const ChatContextProvider = ({ }: ChatContextValueType & { children: ReactNode }) => { const router = useRouter(); const { chatId = '' } = router.query as { chatId: string }; - const { showCompleteQuote }: { showCompleteQuote?: boolean } = params; const forbidLoadChat = useRef(false); @@ -228,8 +225,7 @@ const ChatContextProvider = ({ ScrollData, loadHistories, histories, - onUpdateHistoryTitle, - showCompleteQuote: showCompleteQuote ?? true + onUpdateHistoryTitle }; return {children}; }; diff --git a/projects/app/src/web/core/dataset/api.ts b/projects/app/src/web/core/dataset/api.ts index ddc283cc1..00e07e0c3 100644 --- a/projects/app/src/web/core/dataset/api.ts +++ b/projects/app/src/web/core/dataset/api.ts @@ -34,10 +34,7 @@ import type { CreateDatasetParams, InsertOneDatasetDataProps } from '@/global/co import type { DatasetCollectionItemType } from '@fastgpt/global/core/dataset/type'; import { DatasetCollectionSyncResultEnum } from '@fastgpt/global/core/dataset/constants'; import type { DatasetDataItemType } from '@fastgpt/global/core/dataset/type'; -import type { - DatasetCollectionsListItemType, - DatasetDataListItemType -} from '@/global/core/dataset/type.d'; +import type { DatasetCollectionsListItemType } from '@/global/core/dataset/type.d'; import { PagingData } from '@/types'; import type { getDatasetTrainingQueueResponse } from '@/pages/api/core/dataset/training/getDatasetTrainingQueue'; import type { rebuildEmbeddingBody } from '@/pages/api/core/dataset/training/rebuildEmbedding'; @@ -45,7 +42,10 @@ import type { PostPreviewFilesChunksProps, PreviewChunksResponse } from '@/pages/api/core/dataset/file/getPreviewChunks'; -import type { readCollectionSourceResponse } from '@/pages/api/core/dataset/collection/read'; +import type { + readCollectionSourceBody, + readCollectionSourceResponse +} from '@/pages/api/core/dataset/collection/read'; import type { GetDatasetListBody } from '@/pages/api/core/dataset/list'; import type { UpdateDatasetCollectionParams } from '@/pages/api/core/dataset/collection/update'; import type { @@ -56,7 +56,6 @@ import type { UpdateDatasetDataProps } from '@fastgpt/global/core/dataset/contro import type { DatasetFolderCreateBody } from '@/pages/api/core/dataset/folder/create'; import type { PaginationProps, PaginationResponse } from '@fastgpt/web/common/fetch/type'; import type { GetScrollCollectionsProps } from '@/pages/api/core/dataset/collection/scrollList'; -import { AuthOutLinkProps } from '@fastgpt/global/support/outLink/api'; /* ======================== dataset ======================= */ export const getDatasets = (data: GetDatasetListBody) => @@ -198,6 +197,5 @@ export const getPreviewChunks = (data: PostPreviewFilesChunksProps) => POST('/core/dataset/file/getPreviewChunks', data); /* ================== read source ======================== */ -export const getCollectionSource = ( - data: { collectionId: string; isShare?: boolean } & AuthOutLinkProps -) => POST('/core/dataset/collection/read', data); +export const getCollectionSource = (data: readCollectionSourceBody) => + POST('/core/dataset/collection/read', data); diff --git a/projects/app/src/web/core/dataset/hooks/readCollectionSource.ts b/projects/app/src/web/core/dataset/hooks/readCollectionSource.ts index 70f005dc2..4a39de462 100644 --- a/projects/app/src/web/core/dataset/hooks/readCollectionSource.ts +++ b/projects/app/src/web/core/dataset/hooks/readCollectionSource.ts @@ -1,20 +1,17 @@ -import { authOutLink } from '@/service/support/permission/auth/outLink'; import { useSystemStore } from '@/web/common/system/useSystemStore'; import { getCollectionSource } from '@/web/core/dataset/api'; import { getErrText } from '@fastgpt/global/common/error/utils'; -import { AuthOutLinkProps } from '@fastgpt/global/support/outLink/api'; import { useToast } from '@fastgpt/web/hooks/useToast'; import { useTranslation } from 'next-i18next'; +import { ShareChatAuthProps } from '@fastgpt/global/support/permission/chat'; export function getCollectionSourceAndOpen({ collectionId, - authProps, - isShare + shareId, + outLinkUid }: { collectionId: string; - authProps: AuthOutLinkProps; - isShare?: boolean; -}) { +} & ShareChatAuthProps) { const { toast } = useToast(); const { t } = useTranslation(); const { setLoading } = useSystemStore(); @@ -23,7 +20,7 @@ export function getCollectionSourceAndOpen({ try { setLoading(true); - const { value: url } = await getCollectionSource({ collectionId, isShare, ...authProps }); + const { value: url } = await getCollectionSource({ collectionId, shareId, outLinkUid }); if (!url) { throw new Error('No file found');