Skip to content

Commit

Permalink
feat: Hide the upload button in the external agent's chat box infinif…
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Aug 16, 2024
1 parent 4121636 commit ee2b7f8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
20 changes: 15 additions & 5 deletions web/src/components/api-service/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SharedFrom } from '@/constants/chat';
import {
useCreateNextToken,
useFetchTokenList,
Expand Down Expand Up @@ -71,9 +72,9 @@ export const useShowTokenEmptyError = () => {
return { showTokenEmptyError };
};

const getUrlWithToken = (token: string) => {
const getUrlWithToken = (token: string, from: string = 'chat') => {
const { protocol, host } = window.location;
return `${protocol}//${host}/chat/share?shared_id=${token}`;
return `${protocol}//${host}/chat/share?shared_id=${token}&from=${from}`;
};

const useFetchTokenListBeforeOtherStep = (dialogId: string, idKey: string) => {
Expand Down Expand Up @@ -131,9 +132,18 @@ export const useShowEmbedModal = (dialogId: string, idKey: string) => {
export const usePreviewChat = (dialogId: string, idKey: string) => {
const { handleOperate } = useFetchTokenListBeforeOtherStep(dialogId, idKey);

const open = useCallback((t: string) => {
window.open(getUrlWithToken(t), '_blank');
}, []);
const open = useCallback(
(t: string) => {
window.open(
getUrlWithToken(
t,
idKey === 'canvasId' ? SharedFrom.Agent : SharedFrom.Chat,
),
'_blank',
);
},
[idKey],
);

const handlePreview = useCallback(async () => {
const token = await handleOperate();
Expand Down
4 changes: 3 additions & 1 deletion web/src/components/message-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface IProps {
conversationId: string;
uploadUrl?: string;
isShared?: boolean;
showUploadIcon?: boolean;
}

const getBase64 = (file: FileType): Promise<string> =>
Expand All @@ -85,6 +86,7 @@ const MessageInput = ({
sendLoading,
onInputChange,
conversationId,
showUploadIcon = true,
uploadUrl = '/v1/document/upload_and_parse',
}: IProps) => {
const { t } = useTranslate('chat');
Expand Down Expand Up @@ -158,7 +160,7 @@ const MessageInput = ({
className={classNames({ [styles.inputWrapper]: fileList.length === 0 })}
suffix={
<Space>
{conversationId && (
{conversationId && showUploadIcon && (
<Upload
action={uploadUrl}
fileList={fileList}
Expand Down
5 changes: 5 additions & 0 deletions web/src/constants/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export const variableEnabledFieldMap = {
frequencyPenaltyEnabled: 'frequency_penalty',
maxTokensEnabled: 'max_tokens',
};

export enum SharedFrom {
Agent = 'agent',
Chat = 'chat',
}
5 changes: 4 additions & 1 deletion web/src/pages/chat/share/large.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import MessageInput from '@/components/message-input';
import MessageItem from '@/components/message-item';
import { MessageType } from '@/constants/chat';
import { MessageType, SharedFrom } from '@/constants/chat';
import { useSendButtonDisabled } from '@/pages/chat/hooks';
import { Flex, Spin } from 'antd';
import { forwardRef } from 'react';
import {
useCreateSharedConversationOnMount,
useGetSharedChatSearchParams,
useSelectCurrentSharedConversation,
useSendSharedMessage,
} from '../shared-hooks';
Expand Down Expand Up @@ -37,6 +38,7 @@ const ChatContainer = () => {
addNewestAnswer,
);
const sendDisabled = useSendButtonDisabled(value);
const { from } = useGetSharedChatSearchParams();

return (
<>
Expand Down Expand Up @@ -74,6 +76,7 @@ const ChatContainer = () => {
onPressEnter={handlePressEnter}
sendLoading={sendLoading}
uploadUrl="/v1/api/document/upload_and_parse"
showUploadIcon={from === SharedFrom.Chat}
></MessageInput>
</Flex>
</>
Expand Down
11 changes: 10 additions & 1 deletion web/src/pages/chat/shared-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageType } from '@/constants/chat';
import { MessageType, SharedFrom } from '@/constants/chat';
import {
useCreateSharedConversation,
useFetchSharedConversation,
Expand Down Expand Up @@ -225,3 +225,12 @@ export const useSendSharedMessage = (
loading: !done,
};
};

export const useGetSharedChatSearchParams = () => {
const [searchParams] = useSearchParams();

return {
from: searchParams.get('from') as SharedFrom,
sharedId: searchParams.get('shared_id'),
};
};

0 comments on commit ee2b7f8

Please sign in to comment.