balibabu
commited on
Commit
·
aa83ea7
1
Parent(s):
ebd60e1
feat: Hide the upload button in the external agent's chat box #1880 (#1984)
Browse files### What problem does this PR solve?
feat: Hide the upload button in the external agent's chat box #1880
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/components/api-service/hooks.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import {
|
2 |
useCreateNextToken,
|
3 |
useFetchTokenList,
|
@@ -71,9 +72,9 @@ export const useShowTokenEmptyError = () => {
|
|
71 |
return { showTokenEmptyError };
|
72 |
};
|
73 |
|
74 |
-
const getUrlWithToken = (token: string) => {
|
75 |
const { protocol, host } = window.location;
|
76 |
-
return `${protocol}//${host}/chat/share?shared_id=${token}`;
|
77 |
};
|
78 |
|
79 |
const useFetchTokenListBeforeOtherStep = (dialogId: string, idKey: string) => {
|
@@ -131,9 +132,18 @@ export const useShowEmbedModal = (dialogId: string, idKey: string) => {
|
|
131 |
export const usePreviewChat = (dialogId: string, idKey: string) => {
|
132 |
const { handleOperate } = useFetchTokenListBeforeOtherStep(dialogId, idKey);
|
133 |
|
134 |
-
const open = useCallback(
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
const handlePreview = useCallback(async () => {
|
139 |
const token = await handleOperate();
|
|
|
1 |
+
import { SharedFrom } from '@/constants/chat';
|
2 |
import {
|
3 |
useCreateNextToken,
|
4 |
useFetchTokenList,
|
|
|
72 |
return { showTokenEmptyError };
|
73 |
};
|
74 |
|
75 |
+
const getUrlWithToken = (token: string, from: string = 'chat') => {
|
76 |
const { protocol, host } = window.location;
|
77 |
+
return `${protocol}//${host}/chat/share?shared_id=${token}&from=${from}`;
|
78 |
};
|
79 |
|
80 |
const useFetchTokenListBeforeOtherStep = (dialogId: string, idKey: string) => {
|
|
|
132 |
export const usePreviewChat = (dialogId: string, idKey: string) => {
|
133 |
const { handleOperate } = useFetchTokenListBeforeOtherStep(dialogId, idKey);
|
134 |
|
135 |
+
const open = useCallback(
|
136 |
+
(t: string) => {
|
137 |
+
window.open(
|
138 |
+
getUrlWithToken(
|
139 |
+
t,
|
140 |
+
idKey === 'canvasId' ? SharedFrom.Agent : SharedFrom.Chat,
|
141 |
+
),
|
142 |
+
'_blank',
|
143 |
+
);
|
144 |
+
},
|
145 |
+
[idKey],
|
146 |
+
);
|
147 |
|
148 |
const handlePreview = useCallback(async () => {
|
149 |
const token = await handleOperate();
|
web/src/components/message-input/index.tsx
CHANGED
@@ -66,6 +66,7 @@ interface IProps {
|
|
66 |
conversationId: string;
|
67 |
uploadUrl?: string;
|
68 |
isShared?: boolean;
|
|
|
69 |
}
|
70 |
|
71 |
const getBase64 = (file: FileType): Promise<string> =>
|
@@ -85,6 +86,7 @@ const MessageInput = ({
|
|
85 |
sendLoading,
|
86 |
onInputChange,
|
87 |
conversationId,
|
|
|
88 |
uploadUrl = '/v1/document/upload_and_parse',
|
89 |
}: IProps) => {
|
90 |
const { t } = useTranslate('chat');
|
@@ -158,7 +160,7 @@ const MessageInput = ({
|
|
158 |
className={classNames({ [styles.inputWrapper]: fileList.length === 0 })}
|
159 |
suffix={
|
160 |
<Space>
|
161 |
-
{conversationId && (
|
162 |
<Upload
|
163 |
action={uploadUrl}
|
164 |
fileList={fileList}
|
|
|
66 |
conversationId: string;
|
67 |
uploadUrl?: string;
|
68 |
isShared?: boolean;
|
69 |
+
showUploadIcon?: boolean;
|
70 |
}
|
71 |
|
72 |
const getBase64 = (file: FileType): Promise<string> =>
|
|
|
86 |
sendLoading,
|
87 |
onInputChange,
|
88 |
conversationId,
|
89 |
+
showUploadIcon = true,
|
90 |
uploadUrl = '/v1/document/upload_and_parse',
|
91 |
}: IProps) => {
|
92 |
const { t } = useTranslate('chat');
|
|
|
160 |
className={classNames({ [styles.inputWrapper]: fileList.length === 0 })}
|
161 |
suffix={
|
162 |
<Space>
|
163 |
+
{conversationId && showUploadIcon && (
|
164 |
<Upload
|
165 |
action={uploadUrl}
|
166 |
fileList={fileList}
|
web/src/constants/chat.ts
CHANGED
@@ -10,3 +10,8 @@ export const variableEnabledFieldMap = {
|
|
10 |
frequencyPenaltyEnabled: 'frequency_penalty',
|
11 |
maxTokensEnabled: 'max_tokens',
|
12 |
};
|
|
|
|
|
|
|
|
|
|
|
|
10 |
frequencyPenaltyEnabled: 'frequency_penalty',
|
11 |
maxTokensEnabled: 'max_tokens',
|
12 |
};
|
13 |
+
|
14 |
+
export enum SharedFrom {
|
15 |
+
Agent = 'agent',
|
16 |
+
Chat = 'chat',
|
17 |
+
}
|
web/src/pages/chat/share/large.tsx
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import MessageInput from '@/components/message-input';
|
2 |
import MessageItem from '@/components/message-item';
|
3 |
-
import { MessageType } from '@/constants/chat';
|
4 |
import { useSendButtonDisabled } from '@/pages/chat/hooks';
|
5 |
import { Flex, Spin } from 'antd';
|
6 |
import { forwardRef } from 'react';
|
7 |
import {
|
8 |
useCreateSharedConversationOnMount,
|
|
|
9 |
useSelectCurrentSharedConversation,
|
10 |
useSendSharedMessage,
|
11 |
} from '../shared-hooks';
|
@@ -37,6 +38,7 @@ const ChatContainer = () => {
|
|
37 |
addNewestAnswer,
|
38 |
);
|
39 |
const sendDisabled = useSendButtonDisabled(value);
|
|
|
40 |
|
41 |
return (
|
42 |
<>
|
@@ -74,6 +76,7 @@ const ChatContainer = () => {
|
|
74 |
onPressEnter={handlePressEnter}
|
75 |
sendLoading={sendLoading}
|
76 |
uploadUrl="/v1/api/document/upload_and_parse"
|
|
|
77 |
></MessageInput>
|
78 |
</Flex>
|
79 |
</>
|
|
|
1 |
import MessageInput from '@/components/message-input';
|
2 |
import MessageItem from '@/components/message-item';
|
3 |
+
import { MessageType, SharedFrom } from '@/constants/chat';
|
4 |
import { useSendButtonDisabled } from '@/pages/chat/hooks';
|
5 |
import { Flex, Spin } from 'antd';
|
6 |
import { forwardRef } from 'react';
|
7 |
import {
|
8 |
useCreateSharedConversationOnMount,
|
9 |
+
useGetSharedChatSearchParams,
|
10 |
useSelectCurrentSharedConversation,
|
11 |
useSendSharedMessage,
|
12 |
} from '../shared-hooks';
|
|
|
38 |
addNewestAnswer,
|
39 |
);
|
40 |
const sendDisabled = useSendButtonDisabled(value);
|
41 |
+
const { from } = useGetSharedChatSearchParams();
|
42 |
|
43 |
return (
|
44 |
<>
|
|
|
76 |
onPressEnter={handlePressEnter}
|
77 |
sendLoading={sendLoading}
|
78 |
uploadUrl="/v1/api/document/upload_and_parse"
|
79 |
+
showUploadIcon={from === SharedFrom.Chat}
|
80 |
></MessageInput>
|
81 |
</Flex>
|
82 |
</>
|
web/src/pages/chat/shared-hooks.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { MessageType } from '@/constants/chat';
|
2 |
import {
|
3 |
useCreateSharedConversation,
|
4 |
useFetchSharedConversation,
|
@@ -225,3 +225,12 @@ export const useSendSharedMessage = (
|
|
225 |
loading: !done,
|
226 |
};
|
227 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MessageType, SharedFrom } from '@/constants/chat';
|
2 |
import {
|
3 |
useCreateSharedConversation,
|
4 |
useFetchSharedConversation,
|
|
|
225 |
loading: !done,
|
226 |
};
|
227 |
};
|
228 |
+
|
229 |
+
export const useGetSharedChatSearchParams = () => {
|
230 |
+
const [searchParams] = useSearchParams();
|
231 |
+
|
232 |
+
return {
|
233 |
+
from: searchParams.get('from') as SharedFrom,
|
234 |
+
sharedId: searchParams.get('shared_id'),
|
235 |
+
};
|
236 |
+
};
|