@lobehub/chat 0.101.1 → 0.101.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/app/chat/(desktop)/features/ChatInput/InputArea.tsx +5 -44
- package/src/app/chat/(mobile)/features/ChatInput/Files.tsx +17 -0
- package/src/app/chat/(mobile)/features/ChatInput/Mobile.tsx +14 -68
- package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +30 -0
- package/src/app/chat/(mobile)/features/ChatInput/index.tsx +4 -17
- package/src/app/chat/components/FileList/FileItem.style.ts +3 -0
- package/src/app/chat/components/FileList/FileItem.tsx +56 -52
- package/src/app/chat/components/FileList/index.tsx +5 -1
- package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +57 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.101.2](https://github.com/lobehub/lobe-chat/compare/v0.101.1...v0.101.2)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-11-14**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: upload image to vision model adapting to mobile device.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: upload image to vision model adapting to mobile device, closes [#457](https://github.com/lobehub/lobe-chat/issues/457) ([9c4f4ee](https://github.com/lobehub/lobe-chat/commit/9c4f4ee))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.101.1](https://github.com/lobehub/lobe-chat/compare/v0.101.0...v0.101.1)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-11-14**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.2",
|
|
4
4
|
"description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatbot",
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { TextArea } from '@lobehub/ui';
|
|
2
1
|
import { createStyles } from 'antd-style';
|
|
3
|
-
import { memo
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { memo } from 'react';
|
|
5
3
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { useSendMessage } from '../../../features/ChatInput/useSend';
|
|
4
|
+
import InputAreaInner from '@/app/chat/features/ChatInput/InputAreaInner';
|
|
9
5
|
|
|
10
6
|
const useStyles = createStyles(({ css }) => {
|
|
11
7
|
return {
|
|
@@ -22,46 +18,11 @@ const useStyles = createStyles(({ css }) => {
|
|
|
22
18
|
});
|
|
23
19
|
|
|
24
20
|
const InputArea = memo(() => {
|
|
25
|
-
const {
|
|
26
|
-
const { cx, styles } = useStyles();
|
|
27
|
-
|
|
28
|
-
const isChineseInput = useRef(false);
|
|
29
|
-
|
|
30
|
-
const [loading, message, updateInputMessage] = useSessionStore((s) => [
|
|
31
|
-
!!s.chatLoadingId,
|
|
32
|
-
s.inputMessage,
|
|
33
|
-
s.updateInputMessage,
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
const handleSend = useSendMessage();
|
|
21
|
+
const { styles } = useStyles();
|
|
37
22
|
|
|
38
23
|
return (
|
|
39
|
-
<div className={
|
|
40
|
-
<
|
|
41
|
-
className={styles.textarea}
|
|
42
|
-
onBlur={(e) => {
|
|
43
|
-
updateInputMessage(e.target.value);
|
|
44
|
-
}}
|
|
45
|
-
onChange={(e) => {
|
|
46
|
-
updateInputMessage(e.target.value);
|
|
47
|
-
}}
|
|
48
|
-
onCompositionEnd={() => {
|
|
49
|
-
isChineseInput.current = false;
|
|
50
|
-
}}
|
|
51
|
-
onCompositionStart={() => {
|
|
52
|
-
isChineseInput.current = true;
|
|
53
|
-
}}
|
|
54
|
-
onPressEnter={(e) => {
|
|
55
|
-
if (!loading && !e.shiftKey && !isChineseInput.current) {
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
handleSend();
|
|
58
|
-
}
|
|
59
|
-
}}
|
|
60
|
-
placeholder={t('sendPlaceholder', { ns: 'chat' })}
|
|
61
|
-
resize={false}
|
|
62
|
-
type="pure"
|
|
63
|
-
value={message}
|
|
64
|
-
/>
|
|
24
|
+
<div className={styles.textareaContainer}>
|
|
25
|
+
<InputAreaInner className={styles.textarea} />
|
|
65
26
|
</div>
|
|
66
27
|
);
|
|
67
28
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { Flexbox } from 'react-layout-kit';
|
|
3
|
+
|
|
4
|
+
import FileList from '@/app/chat/components/FileList';
|
|
5
|
+
import { useFileStore } from '@/store/files';
|
|
6
|
+
|
|
7
|
+
const Files = memo(() => {
|
|
8
|
+
const inputFilesList = useFileStore((s) => s.inputFilesList);
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Flexbox padding={12}>
|
|
12
|
+
<FileList alwaysShowClose items={inputFilesList} />
|
|
13
|
+
</Flexbox>
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default Files;
|
|
@@ -1,79 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Button, type InputRef } from 'antd';
|
|
3
|
-
import { Loader2, SendHorizonal } from 'lucide-react';
|
|
4
|
-
import { forwardRef, useCallback, useRef } from 'react';
|
|
5
|
-
import { useTranslation } from 'react-i18next';
|
|
1
|
+
import { memo } from 'react';
|
|
6
2
|
import { Flexbox } from 'react-layout-kit';
|
|
7
|
-
import useControlledState from 'use-merge-value';
|
|
8
3
|
|
|
9
4
|
import ActionBar from '@/app/chat/features/ChatInput/ActionBar';
|
|
5
|
+
import InputAreaInner from '@/app/chat/features/ChatInput/InputAreaInner';
|
|
10
6
|
import SaveTopic from '@/app/chat/features/ChatInput/Topic';
|
|
11
7
|
|
|
8
|
+
import SendButton from './SendButton';
|
|
12
9
|
import { useStyles } from './style.mobile';
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
onChange?: (value: string) => void;
|
|
17
|
-
onSend?: (value: string) => void;
|
|
18
|
-
onStop?: () => void;
|
|
19
|
-
value?: string;
|
|
20
|
-
};
|
|
11
|
+
const ChatInputArea = memo(() => {
|
|
12
|
+
const { cx, styles } = useStyles();
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
const { cx, styles } = useStyles();
|
|
30
|
-
const isChineseInput = useRef(false);
|
|
31
|
-
|
|
32
|
-
const handleSend = useCallback(() => {
|
|
33
|
-
if (loading) return;
|
|
34
|
-
if (onSend) onSend(currentValue);
|
|
35
|
-
setCurrentValue('');
|
|
36
|
-
}, [currentValue]);
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Flexbox className={cx(styles.container)} gap={12}>
|
|
40
|
-
<ActionBar rightAreaStartRender={<SaveTopic />} />
|
|
41
|
-
<Flexbox className={styles.inner} gap={8} horizontal>
|
|
42
|
-
<Input
|
|
43
|
-
className={cx(styles.input)}
|
|
44
|
-
onBlur={(e) => {
|
|
45
|
-
setCurrentValue(e.target.value);
|
|
46
|
-
}}
|
|
47
|
-
onChange={(e) => {
|
|
48
|
-
setCurrentValue(e.target.value);
|
|
49
|
-
}}
|
|
50
|
-
onCompositionEnd={() => {
|
|
51
|
-
isChineseInput.current = false;
|
|
52
|
-
}}
|
|
53
|
-
onCompositionStart={() => {
|
|
54
|
-
isChineseInput.current = true;
|
|
55
|
-
}}
|
|
56
|
-
onPressEnter={(e) => {
|
|
57
|
-
if (!loading && !e.shiftKey && !isChineseInput.current) {
|
|
58
|
-
e.preventDefault();
|
|
59
|
-
handleSend();
|
|
60
|
-
}
|
|
61
|
-
}}
|
|
62
|
-
placeholder={t('sendPlaceholder')}
|
|
63
|
-
type={'block'}
|
|
64
|
-
value={currentValue}
|
|
65
|
-
/>
|
|
66
|
-
<div>
|
|
67
|
-
{loading ? (
|
|
68
|
-
<Button icon={loading && <Icon icon={Loader2} spin />} onClick={onStop} />
|
|
69
|
-
) : (
|
|
70
|
-
<Button icon={<Icon icon={SendHorizonal} />} onClick={handleSend} type={'primary'} />
|
|
71
|
-
)}
|
|
72
|
-
</div>
|
|
73
|
-
</Flexbox>
|
|
14
|
+
return (
|
|
15
|
+
<Flexbox className={cx(styles.container)} gap={12}>
|
|
16
|
+
<ActionBar rightAreaStartRender={<SaveTopic />} />
|
|
17
|
+
<Flexbox className={styles.inner} gap={8} horizontal>
|
|
18
|
+
<InputAreaInner mobile />
|
|
19
|
+
<SendButton />
|
|
74
20
|
</Flexbox>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
);
|
|
21
|
+
</Flexbox>
|
|
22
|
+
);
|
|
23
|
+
});
|
|
78
24
|
|
|
79
25
|
export default ChatInputArea;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Icon } from '@lobehub/ui';
|
|
2
|
+
import { Button } from 'antd';
|
|
3
|
+
import { Loader2, SendHorizonal } from 'lucide-react';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
import { useSendMessage } from '@/app/chat/features/ChatInput/useSend';
|
|
7
|
+
import { useSessionStore } from '@/store/session';
|
|
8
|
+
|
|
9
|
+
const SendButton = memo(() => {
|
|
10
|
+
const [loading, onStop] = useSessionStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
|
|
11
|
+
|
|
12
|
+
const handleSend = useSendMessage();
|
|
13
|
+
|
|
14
|
+
return loading ? (
|
|
15
|
+
<Button
|
|
16
|
+
icon={loading && <Icon icon={Loader2} spin />}
|
|
17
|
+
onClick={onStop}
|
|
18
|
+
style={{ flex: 'none' }}
|
|
19
|
+
/>
|
|
20
|
+
) : (
|
|
21
|
+
<Button
|
|
22
|
+
icon={<Icon icon={SendHorizonal} />}
|
|
23
|
+
onClick={handleSend}
|
|
24
|
+
style={{ flex: 'none' }}
|
|
25
|
+
type={'primary'}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default SendButton;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createStyles } from 'antd-style';
|
|
2
|
-
import { memo
|
|
2
|
+
import { memo } from 'react';
|
|
3
3
|
|
|
4
4
|
import SafeSpacing from '@/components/SafeSpacing';
|
|
5
5
|
import { CHAT_TEXTAREA_HEIGHT_MOBILE } from '@/const/layoutTokens';
|
|
6
|
-
import { useSessionStore } from '@/store/session';
|
|
7
6
|
|
|
7
|
+
import Files from './Files';
|
|
8
8
|
import ChatInputArea from './Mobile';
|
|
9
9
|
|
|
10
10
|
const useStyles = createStyles(
|
|
@@ -23,25 +23,12 @@ const useStyles = createStyles(
|
|
|
23
23
|
const ChatInputMobileLayout = memo(() => {
|
|
24
24
|
const { styles } = useStyles();
|
|
25
25
|
|
|
26
|
-
const [message, setMessage] = useState('');
|
|
27
|
-
|
|
28
|
-
const [isLoading, sendMessage, stopGenerateMessage] = useSessionStore((s) => [
|
|
29
|
-
!!s.chatLoadingId,
|
|
30
|
-
s.sendMessage,
|
|
31
|
-
s.stopGenerateMessage,
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
26
|
return (
|
|
35
27
|
<>
|
|
28
|
+
<Files />
|
|
36
29
|
<SafeSpacing height={CHAT_TEXTAREA_HEIGHT_MOBILE} mobile position={'bottom'} />
|
|
37
30
|
<div className={styles}>
|
|
38
|
-
<ChatInputArea
|
|
39
|
-
loading={isLoading}
|
|
40
|
-
onChange={setMessage}
|
|
41
|
-
onSend={sendMessage}
|
|
42
|
-
onStop={stopGenerateMessage}
|
|
43
|
-
value={message}
|
|
44
|
-
/>
|
|
31
|
+
<ChatInputArea />
|
|
45
32
|
</div>
|
|
46
33
|
</>
|
|
47
34
|
);
|
|
@@ -10,60 +10,64 @@ import { useFileStore } from '@/store/files';
|
|
|
10
10
|
|
|
11
11
|
import { IMAGE_SIZE, useStyles } from './FileItem.style';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
interface FileItemProps {
|
|
14
|
+
alwaysShowClose?: boolean;
|
|
15
|
+
editable: boolean;
|
|
16
|
+
id: string;
|
|
17
|
+
onClick: () => void;
|
|
18
|
+
}
|
|
19
|
+
const FileItem = memo<FileItemProps>(({ editable, id, onClick, alwaysShowClose }) => {
|
|
20
|
+
const { styles, cx } = useStyles();
|
|
21
|
+
const [useFetchFile, removeFile] = useFileStore((s) => [s.useFetchFile, s.removeFile]);
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
const { data, isLoading } = useFetchFile(id);
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
25
|
+
return (
|
|
26
|
+
<Flexbox className={styles.container} onClick={onClick}>
|
|
27
|
+
{isLoading ? (
|
|
28
|
+
<Skeleton
|
|
29
|
+
active
|
|
30
|
+
title={{
|
|
31
|
+
style: { borderRadius: 8, height: IMAGE_SIZE },
|
|
32
|
+
width: IMAGE_SIZE,
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
) : (
|
|
36
|
+
<Flexbox className={styles.imageCtn}>
|
|
37
|
+
<div className={styles.imageWrapper}>
|
|
38
|
+
{data ? (
|
|
39
|
+
<Image
|
|
40
|
+
alt={data.name || ''}
|
|
41
|
+
className={styles.image}
|
|
42
|
+
fetchPriority={'high'}
|
|
43
|
+
height={IMAGE_SIZE}
|
|
44
|
+
loading={'lazy'}
|
|
45
|
+
src={data.url}
|
|
46
|
+
width={IMAGE_SIZE}
|
|
47
|
+
/>
|
|
48
|
+
) : (
|
|
49
|
+
<Center className={styles.notFound} height={'100%'}>
|
|
50
|
+
<Icon icon={LucideImageOff} size={{ fontSize: 28 }} />
|
|
51
|
+
</Center>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
</Flexbox>
|
|
55
|
+
)}
|
|
56
|
+
{/* only show close icon when editable */}
|
|
57
|
+
{editable && (
|
|
58
|
+
<Center
|
|
59
|
+
className={cx(styles.closeIcon, alwaysShowClose && styles.alwaysShowClose)}
|
|
60
|
+
onClick={(e) => {
|
|
61
|
+
e.stopPropagation();
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
63
|
+
removeFile(id);
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<CloseCircleFilled />
|
|
67
|
+
</Center>
|
|
68
|
+
)}
|
|
69
|
+
</Flexbox>
|
|
70
|
+
);
|
|
71
|
+
});
|
|
68
72
|
|
|
69
73
|
export default FileItem;
|
|
@@ -14,11 +14,14 @@ import Lightbox from './Lightbox';
|
|
|
14
14
|
// }));
|
|
15
15
|
|
|
16
16
|
interface FileListProps {
|
|
17
|
+
alwaysShowClose?: boolean;
|
|
18
|
+
|
|
17
19
|
editable?: boolean;
|
|
20
|
+
|
|
18
21
|
items: string[];
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
const FileList = memo<FileListProps>(({ items, editable = true }) => {
|
|
24
|
+
const FileList = memo<FileListProps>(({ items, editable = true, alwaysShowClose }) => {
|
|
22
25
|
// const { styles } = useStyles();
|
|
23
26
|
|
|
24
27
|
const [showLightbox, setShowLightbox] = useState(false);
|
|
@@ -38,6 +41,7 @@ const FileList = memo<FileListProps>(({ items, editable = true }) => {
|
|
|
38
41
|
>
|
|
39
42
|
{items.map((i, index) => (
|
|
40
43
|
<FileItem
|
|
44
|
+
alwaysShowClose={alwaysShowClose}
|
|
41
45
|
editable={editable}
|
|
42
46
|
id={i}
|
|
43
47
|
key={i}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Input, TextArea } from '@lobehub/ui';
|
|
2
|
+
import { memo, useRef } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
|
|
5
|
+
import { useSessionStore } from '@/store/session';
|
|
6
|
+
|
|
7
|
+
import { useSendMessage } from '../useSend';
|
|
8
|
+
|
|
9
|
+
export interface InputAreaInnerProps {
|
|
10
|
+
className?: string;
|
|
11
|
+
mobile?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const InputAreaInner = memo<InputAreaInnerProps>(({ className, mobile }) => {
|
|
15
|
+
const { t } = useTranslation('chat');
|
|
16
|
+
const isChineseInput = useRef(false);
|
|
17
|
+
|
|
18
|
+
const [loading, message, updateInputMessage] = useSessionStore((s) => [
|
|
19
|
+
!!s.chatLoadingId,
|
|
20
|
+
s.inputMessage,
|
|
21
|
+
s.updateInputMessage,
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
const handleSend = useSendMessage();
|
|
25
|
+
|
|
26
|
+
const Render = mobile ? Input : TextArea;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Render
|
|
30
|
+
className={className}
|
|
31
|
+
onBlur={(e) => {
|
|
32
|
+
updateInputMessage(e.target.value);
|
|
33
|
+
}}
|
|
34
|
+
onChange={(e) => {
|
|
35
|
+
updateInputMessage(e.target.value);
|
|
36
|
+
}}
|
|
37
|
+
onCompositionEnd={() => {
|
|
38
|
+
isChineseInput.current = false;
|
|
39
|
+
}}
|
|
40
|
+
onCompositionStart={() => {
|
|
41
|
+
isChineseInput.current = true;
|
|
42
|
+
}}
|
|
43
|
+
onPressEnter={(e) => {
|
|
44
|
+
if (!loading && !e.shiftKey && !isChineseInput.current) {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
handleSend();
|
|
47
|
+
}
|
|
48
|
+
}}
|
|
49
|
+
placeholder={t('sendPlaceholder')}
|
|
50
|
+
resize={false}
|
|
51
|
+
type={mobile ? 'block' : 'pure'}
|
|
52
|
+
value={message}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export default InputAreaInner;
|