Skip to content

Commit

Permalink
feat: share page support configuration Whether to allow the original …
Browse files Browse the repository at this point in the history
…view (labring#3194)
  • Loading branch information
c121914yu authored Nov 20, 2024
1 parent 7692b92 commit 6ba751f
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 74 deletions.
3 changes: 2 additions & 1 deletion docSite/content/zh-cn/docs/development/upgrading/4814.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ weight: 810
1.
2. 新增 - 工作流支持进入聊天框/点击开始对话后,自动触发一轮对话。
3. 新增 - 重写 chatContext,对话测试也会有日志,并且刷新后不会丢失对话。
4. 优化 - 工作流 ui 细节。
4. 新增 - 分享链接支持配置是否允许查看原文。
5. 优化 - 工作流 ui 细节。
1 change: 1 addition & 0 deletions packages/global/common/file/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export type FileTokenQuery = {
teamId: string;
uid: string; // tmbId/ share uid/ teamChat uid
fileId: string;
customExpireMinutes?: number;
};
2 changes: 1 addition & 1 deletion packages/global/core/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const filterPublicNodeResponseData = ({
for (let key in item) {
if (key === 'toolDetail' || key === 'pluginDetail') {
// @ts-ignore
obj[key] = filterPublicNodeResponseData({ flowResponses: item[key] });
obj[key] = filterPublicNodeResponseData({ flowResponses: item[key], responseDetail });
} else if (filedList.includes(key)) {
// @ts-ignore
obj[key] = item[key];
Expand Down
3 changes: 2 additions & 1 deletion packages/service/support/permission/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ export const createFileToken = (data: FileTokenQuery) => {
return Promise.reject('System unset FILE_TOKEN_KEY');
}

const expireMinutes = bucketNameMap[data.bucketName].previewExpireMinutes;
const expireMinutes =
data.customExpireMinutes ?? bucketNameMap[data.bucketName].previewExpireMinutes;
const expiredTime = Math.floor(addMinutes(new Date(), expireMinutes).getTime() / 1000);

const key = (process.env.FILE_TOKEN_KEY as string) ?? 'filetoken';
Expand Down
8 changes: 7 additions & 1 deletion packages/web/hooks/useToast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useToast as uToast, UseToastOptions } from '@chakra-ui/react';
import { CSSProperties, useCallback } from 'react';
import { useTranslation } from 'next-i18next';

export const useToast = (props?: UseToastOptions & { containerStyle?: CSSProperties }) => {
const { containerStyle, ...toastProps } = props || {};
const { t } = useTranslation();

const toast = uToast({
position: 'top',
Expand All @@ -17,7 +19,11 @@ export const useToast = (props?: UseToastOptions & { containerStyle?: CSSPropert
const myToast = useCallback(
(options?: UseToastOptions) => {
if (options?.title || options?.description) {
toast(options);
toast({
...(options.title && { title: t(options.title as any) }),
...(options.description && { description: t(options.description as any) }),
...options
});
}
},
[props]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const ContextModal = ({ onClose, dataId }: { onClose: () => void; dataId: string
const flatResData: ChatHistoryItemResType[] =
res
?.map((item) => {
if (item.pluginDetail || item.toolDetail) {
return [item, ...(item.pluginDetail || []), ...(item.toolDetail || [])];
}
return item;
return [
item,
...(item.pluginDetail || []),
...(item.toolDetail || []),
...(item.loopDetail || [])
];
})
.flat() || [];
return flatResData.find(isLLMNode)?.historyPreview || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import type { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/ty
import QuoteItem from '@/components/core/dataset/QuoteItem';
import RawSourceBox from '@/components/core/dataset/RawSourceBox';
import { getWebReqUrl } from '@fastgpt/web/common/system/utils';
import { useContextSelector } from 'use-context-selector';
import { ChatBoxContext } from '../Provider';

const QuoteModal = ({
rawSearch = [],
onClose,
canEditDataset,
showRawSource,
chatItemId,
metadata
}: {
rawSearch: SearchDataResponseItemType[];
onClose: () => void;
canEditDataset: boolean;
showRawSource: boolean;
chatItemId: string;
metadata?: {
collectionId: string;
sourceId?: string;
Expand All @@ -37,6 +41,13 @@ const QuoteModal = ({
[metadata, rawSearch]
);

const RawSourceBoxProps = useContextSelector(ChatBoxContext, (v) => ({
appId: v.appId,
chatId: v.chatId,
chatItemId,
...(v.outLinkAuthData || {})
}));

return (
<>
<MyModal
Expand All @@ -49,7 +60,7 @@ const QuoteModal = ({
title={
<Box>
{metadata ? (
<RawSourceBox {...metadata} canView={showRawSource} />
<RawSourceBox {...metadata} {...RawSourceBoxProps} canView={showRawSource} />
) : (
<>{t('common:core.chat.Quote Amount', { amount: rawSearch.length })}</>
)}
Expand All @@ -64,6 +75,7 @@ const QuoteModal = ({
rawSearch={filterResults}
canEditDataset={canEditDataset}
canViewSource={showRawSource}
chatItemId={chatItemId}
/>
</ModalBody>
</MyModal>
Expand All @@ -74,16 +86,25 @@ const QuoteModal = ({
export default QuoteModal;

export const QuoteList = React.memo(function QuoteList({
chatItemId,
rawSearch = [],
canEditDataset,
canViewSource
}: {
chatItemId?: string;
rawSearch: SearchDataResponseItemType[];
canEditDataset: boolean;
canViewSource: boolean;
}) {
const theme = useTheme();

const RawSourceBoxProps = useContextSelector(ChatBoxContext, (v) => ({
chatItemId,
appId: v.appId,
chatId: v.chatId,
...(v.outLinkAuthData || {})
}));

return (
<>
{rawSearch.map((item, i) => (
Expand All @@ -101,6 +122,7 @@ export const QuoteList = React.memo(function QuoteList({
quoteItem={item}
canViewSource={canViewSource}
canEditDataset={canEditDataset}
{...RawSourceBoxProps}
/>
</Box>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const ResponseTags = ({
{!!quoteModalData && (
<QuoteModal
{...quoteModalData}
chatItemId={historyItem.dataId}
canEditDataset={notSharePage}
showRawSource={showRawSource}
onClose={() => setQuoteModalData(undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RenderResponseDetail = () => {
<>{t('chat:in_progress')}</>
) : (
<Box flex={'1 0 0'} h={'100%'} overflow={'auto'}>
<ResponseBox useMobile={true} response={responseData} />
<ResponseBox useMobile={true} response={responseData} dataId={chatRecords?.[1]?.dataId} />
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ type sideTabItemType = {
/* Per response value */
export const WholeResponseContent = ({
activeModule,
hideTabs
hideTabs,
dataId
}: {
activeModule: ChatHistoryItemResType;
hideTabs?: boolean;
dataId?: string;
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -231,7 +233,14 @@ export const WholeResponseContent = ({
{activeModule.quoteList && activeModule.quoteList.length > 0 && (
<Row
label={t('common:core.chat.response.module quoteList')}
rawDom={<QuoteList canEditDataset canViewSource rawSearch={activeModule.quoteList} />}
rawDom={
<QuoteList
canEditDataset
canViewSource
chatItemId={dataId}
rawSearch={activeModule.quoteList}
/>
}
/>
)}
</>
Expand Down Expand Up @@ -529,10 +538,12 @@ const SideTabItem = ({
/* Modal main container */
export const ResponseBox = React.memo(function ResponseBox({
response,
dataId,
hideTabs = false,
useMobile = false
}: {
response: ChatHistoryItemResType[];
dataId?: string;
hideTabs?: boolean;
useMobile?: boolean;
}) {
Expand Down Expand Up @@ -655,7 +666,7 @@ export const ResponseBox = React.memo(function ResponseBox({
</Box>
</Box>
<Box flex={'5 0 0'} w={0} height={'100%'}>
<WholeResponseContent activeModule={activeModule} hideTabs={hideTabs} />
<WholeResponseContent dataId={dataId} activeModule={activeModule} hideTabs={hideTabs} />
</Box>
</Flex>
) : (
Expand Down Expand Up @@ -715,7 +726,11 @@ export const ResponseBox = React.memo(function ResponseBox({
</Box>
</Flex>
<Box flex={'1 0 0'}>
<WholeResponseContent activeModule={activeModule} hideTabs={hideTabs} />
<WholeResponseContent
dataId={dataId}
activeModule={activeModule}
hideTabs={hideTabs}
/>
</Box>
</Flex>
)}
Expand Down Expand Up @@ -754,7 +769,7 @@ const WholeResponseModal = ({ onClose, dataId }: { onClose: () => void; dataId:
}
>
{!!response?.length ? (
<ResponseBox response={response} />
<ResponseBox response={response} dataId={dataId} />
) : (
<EmptyTip text={t('chat:no_workflow_response')} />
)}
Expand Down
7 changes: 5 additions & 2 deletions projects/app/src/components/core/dataset/QuoteItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 type { readCollectionSourceBody } from '@/pages/api/core/dataset/collection/read';

const InputDataModal = dynamic(() => import('@/pages/dataset/detail/components/InputDataModal'));

Expand Down Expand Up @@ -45,12 +46,13 @@ const scoreTheme: Record<
const QuoteItem = ({
quoteItem,
canViewSource,
canEditDataset
canEditDataset,
...RawSourceBoxProps
}: {
quoteItem: SearchDataResponseItemType;
canViewSource?: boolean;
canEditDataset?: boolean;
}) => {
} & Omit<readCollectionSourceBody, 'collectionId'>) => {
const { t } = useTranslation();
const [editInputData, setEditInputData] = useState<{ dataId: string; collectionId: string }>();

Expand Down Expand Up @@ -196,6 +198,7 @@ const QuoteItem = ({
sourceName={quoteItem.sourceName}
sourceId={quoteItem.sourceId}
canView={canViewSource}
{...RawSourceBoxProps}
/>
<Box flex={1} />
{quoteItem.id && canEditDataset && (
Expand Down
22 changes: 17 additions & 5 deletions projects/app/src/components/core/dataset/RawSourceBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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 { ShareChatAuthProps } from '@fastgpt/global/support/permission/chat';
import type { readCollectionSourceBody } from '@/pages/api/core/dataset/collection/read';

type Props = BoxProps &
ShareChatAuthProps & {
readCollectionSourceBody & {
sourceName?: string;
collectionId: string;
sourceId?: string;
Expand All @@ -18,11 +18,18 @@ type Props = BoxProps &

const RawSourceBox = ({
sourceId,
collectionId,
sourceName = '',
canView = true,

collectionId,
appId,
chatId,
chatItemId,
shareId,
outLinkUid,
teamId,
teamToken,

...props
}: Props) => {
const { t } = useTranslation();
Expand All @@ -33,8 +40,13 @@ const RawSourceBox = ({
const icon = useMemo(() => getSourceNameIcon({ sourceId, sourceName }), [sourceId, sourceName]);
const read = getCollectionSourceAndOpen({
collectionId,
appId,
chatId,
chatItemId,
shareId,
outLinkUid
outLinkUid,
teamId,
teamToken
});

return (
Expand All @@ -56,7 +68,7 @@ const RawSourceBox = ({
: {})}
{...props}
>
<MyIcon name={icon as any} w={['16px', '20px']} mr={2} />
<MyIcon name={icon as any} w={['1rem', '1.25rem']} mr={2} />
<Box
maxW={['200px', '300px']}
className={props.className ?? 'textEllipsis'}
Expand Down
10 changes: 6 additions & 4 deletions projects/app/src/global/core/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export function addStatisticalDataToHistoryItem(historyItem: ChatItemType) {
const flatResData: ChatHistoryItemResType[] =
historyItem.responseData
?.map((item) => {
if (item.pluginDetail || item.toolDetail) {
return [item, ...(item.pluginDetail || []), ...(item.toolDetail || [])];
}
return item;
return [
item,
...(item.pluginDetail || []),
...(item.toolDetail || []),
...(item.loopDetail || [])
];
})
.flat() || [];

Expand Down
Loading

0 comments on commit 6ba751f

Please sign in to comment.