mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-13 19:20:04 +00:00
4e522a6e2b
This commit introduces new components, modules, and features related to chat, sessions, and settings. It includes modifications to configuration files, updates to dependencies, adjustments to styles and layouts, and additions of new components and modules. The changes also involve updates to functions, interfaces, selectors, actions, and reducers. Additionally, there are modifications to TypeScript interfaces and types, as well as changes to parameters and functions in certain files.
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { ActionIcon, ChatInputArea, DraggablePanel, Icon, TokenTag } from '@lobehub/ui';
|
|
import { Button } from 'antd';
|
|
import { encode } from 'gpt-tokenizer';
|
|
import { Archive, Eraser, Languages } from 'lucide-react';
|
|
import { memo, useMemo, useState } from 'react';
|
|
import { shallow } from 'zustand/shallow';
|
|
|
|
import { ModelTokens } from '@/const/modelTokens';
|
|
import { agentSelectors, chatSelectors, useChatStore } from '@/store/session';
|
|
import { useSettings } from '@/store/settings';
|
|
|
|
const ChatInput = () => {
|
|
const [expand, setExpand] = useState<boolean>(false);
|
|
const [text, setText] = useState('');
|
|
const textTokenCount = useMemo(() => encode(text).length, [text]);
|
|
|
|
const [inputHeight] = useSettings((s) => [s.inputHeight], shallow);
|
|
const [totalToken, model, sendMessage, clearMessage] = useChatStore(
|
|
(s) => [
|
|
chatSelectors.totalTokenCount(s),
|
|
agentSelectors.currentAgentModel(s),
|
|
s.sendMessage,
|
|
s.clearMessage,
|
|
],
|
|
shallow,
|
|
);
|
|
|
|
return (
|
|
<DraggablePanel
|
|
expandable={false}
|
|
fullscreen={expand}
|
|
minHeight={200}
|
|
onSizeChange={(_, size) => {
|
|
if (!size) return;
|
|
useSettings.setState({
|
|
inputHeight: typeof size.height === 'string' ? Number.parseInt(size.height) : size.height,
|
|
});
|
|
}}
|
|
placement="bottom"
|
|
size={{ height: inputHeight, width: '100%' }}
|
|
>
|
|
<ChatInputArea
|
|
actions={
|
|
<>
|
|
<ActionIcon icon={Languages} />
|
|
<ActionIcon icon={Eraser} onClick={clearMessage} />
|
|
<TokenTag maxValue={ModelTokens[model]} value={totalToken + textTokenCount} />
|
|
</>
|
|
}
|
|
expand={expand}
|
|
footer={<Button icon={<Icon icon={Archive} />} />}
|
|
minHeight={200}
|
|
onExpandChange={setExpand}
|
|
onInputChange={setText}
|
|
onSend={sendMessage}
|
|
/>
|
|
</DraggablePanel>
|
|
);
|
|
};
|
|
|
|
export default memo(ChatInput);
|