chat.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. import { useDebouncedCallback } from "use-debounce";
  2. import { useState, useRef, useEffect, useLayoutEffect } from "react";
  3. import SendWhiteIcon from "../icons/send-white.svg";
  4. import BrainIcon from "../icons/brain.svg";
  5. import RenameIcon from "../icons/rename.svg";
  6. import ExportIcon from "../icons/share.svg";
  7. import ReturnIcon from "../icons/return.svg";
  8. import CopyIcon from "../icons/copy.svg";
  9. import DownloadIcon from "../icons/download.svg";
  10. import LoadingIcon from "../icons/three-dots.svg";
  11. import PromptIcon from "../icons/prompt.svg";
  12. import MaskIcon from "../icons/mask.svg";
  13. import MaxIcon from "../icons/max.svg";
  14. import MinIcon from "../icons/min.svg";
  15. import ResetIcon from "../icons/reload.svg";
  16. import LightIcon from "../icons/light.svg";
  17. import DarkIcon from "../icons/dark.svg";
  18. import AutoIcon from "../icons/auto.svg";
  19. import BottomIcon from "../icons/bottom.svg";
  20. import StopIcon from "../icons/pause.svg";
  21. import {
  22. Message,
  23. SubmitKey,
  24. useChatStore,
  25. BOT_HELLO,
  26. ROLES,
  27. createMessage,
  28. useAccessStore,
  29. Theme,
  30. useAppConfig,
  31. ModelConfig,
  32. DEFAULT_TOPIC,
  33. } from "../store";
  34. import {
  35. copyToClipboard,
  36. downloadAs,
  37. selectOrCopy,
  38. autoGrowTextArea,
  39. useMobileScreen,
  40. } from "../utils";
  41. import dynamic from "next/dynamic";
  42. import { ControllerPool } from "../requests";
  43. import { Prompt, usePromptStore } from "../store/prompt";
  44. import Locale from "../locales";
  45. import { IconButton } from "./button";
  46. import styles from "./home.module.scss";
  47. import chatStyle from "./chat.module.scss";
  48. import { ListItem, Modal, showModal } from "./ui-lib";
  49. import { useLocation, useNavigate } from "react-router-dom";
  50. import { Path } from "../constant";
  51. import { Avatar } from "./emoji";
  52. import { MaskAvatar, MaskConfig } from "./mask";
  53. import {
  54. DEFAULT_MASK_AVATAR,
  55. DEFAULT_MASK_ID,
  56. useMaskStore,
  57. } from "../store/mask";
  58. const Markdown = dynamic(async () => (await import("./markdown")).Markdown, {
  59. loading: () => <LoadingIcon />,
  60. });
  61. function exportMessages(messages: Message[], topic: string) {
  62. const mdText =
  63. `# ${topic}\n\n` +
  64. messages
  65. .map((m) => {
  66. return m.role === "user"
  67. ? `## ${Locale.Export.MessageFromYou}:\n${m.content}`
  68. : `## ${Locale.Export.MessageFromChatGPT}:\n${m.content.trim()}`;
  69. })
  70. .join("\n\n");
  71. const filename = `${topic}.md`;
  72. showModal({
  73. title: Locale.Export.Title,
  74. children: (
  75. <div className="markdown-body">
  76. <pre className={styles["export-content"]}>{mdText}</pre>
  77. </div>
  78. ),
  79. actions: [
  80. <IconButton
  81. key="copy"
  82. icon={<CopyIcon />}
  83. bordered
  84. text={Locale.Export.Copy}
  85. onClick={() => copyToClipboard(mdText)}
  86. />,
  87. <IconButton
  88. key="download"
  89. icon={<DownloadIcon />}
  90. bordered
  91. text={Locale.Export.Download}
  92. onClick={() => downloadAs(mdText, filename)}
  93. />,
  94. ],
  95. });
  96. }
  97. export function SessionConfigModel(props: { onClose: () => void }) {
  98. const chatStore = useChatStore();
  99. const session = chatStore.currentSession();
  100. const maskStore = useMaskStore();
  101. const navigate = useNavigate();
  102. return (
  103. <div className="modal-mask">
  104. <Modal
  105. title={Locale.Context.Edit}
  106. onClose={() => props.onClose()}
  107. actions={[
  108. <IconButton
  109. key="reset"
  110. icon={<ResetIcon />}
  111. bordered
  112. text={Locale.Chat.Config.Reset}
  113. onClick={() =>
  114. confirm(Locale.Memory.ResetConfirm) && chatStore.resetSession()
  115. }
  116. />,
  117. <IconButton
  118. key="copy"
  119. icon={<CopyIcon />}
  120. bordered
  121. text={Locale.Chat.Config.SaveAs}
  122. onClick={() => {
  123. navigate(Path.Masks);
  124. setTimeout(() => {
  125. maskStore.create(session.mask);
  126. }, 500);
  127. }}
  128. />,
  129. ]}
  130. >
  131. <MaskConfig
  132. mask={session.mask}
  133. updateMask={(updater) => {
  134. const mask = { ...session.mask };
  135. updater(mask);
  136. chatStore.updateCurrentSession((session) => (session.mask = mask));
  137. }}
  138. extraListItems={
  139. session.mask.modelConfig.sendMemory ? (
  140. <ListItem
  141. title={`${Locale.Memory.Title} (${session.lastSummarizeIndex} of ${session.messages.length})`}
  142. subTitle={session.memoryPrompt || Locale.Memory.EmptyContent}
  143. ></ListItem>
  144. ) : (
  145. <></>
  146. )
  147. }
  148. ></MaskConfig>
  149. </Modal>
  150. </div>
  151. );
  152. }
  153. function PromptToast(props: {
  154. showToast?: boolean;
  155. showModal?: boolean;
  156. setShowModal: (_: boolean) => void;
  157. }) {
  158. const chatStore = useChatStore();
  159. const session = chatStore.currentSession();
  160. const context = session.mask.context;
  161. return (
  162. <div className={chatStyle["prompt-toast"]} key="prompt-toast">
  163. {props.showToast && (
  164. <div
  165. className={chatStyle["prompt-toast-inner"] + " clickable"}
  166. role="button"
  167. onClick={() => props.setShowModal(true)}
  168. >
  169. <BrainIcon />
  170. <span className={chatStyle["prompt-toast-content"]}>
  171. {Locale.Context.Toast(context.length)}
  172. </span>
  173. </div>
  174. )}
  175. {props.showModal && (
  176. <SessionConfigModel onClose={() => props.setShowModal(false)} />
  177. )}
  178. </div>
  179. );
  180. }
  181. function useSubmitHandler() {
  182. const config = useAppConfig();
  183. const submitKey = config.submitKey;
  184. const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
  185. if (e.key !== "Enter") return false;
  186. if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
  187. return (
  188. (config.submitKey === SubmitKey.AltEnter && e.altKey) ||
  189. (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
  190. (config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) ||
  191. (config.submitKey === SubmitKey.MetaEnter && e.metaKey) ||
  192. (config.submitKey === SubmitKey.Enter &&
  193. !e.altKey &&
  194. !e.ctrlKey &&
  195. !e.shiftKey &&
  196. !e.metaKey)
  197. );
  198. };
  199. return {
  200. submitKey,
  201. shouldSubmit,
  202. };
  203. }
  204. export function PromptHints(props: {
  205. prompts: Prompt[];
  206. onPromptSelect: (prompt: Prompt) => void;
  207. }) {
  208. if (props.prompts.length === 0) return null;
  209. return (
  210. <div className={styles["prompt-hints"]}>
  211. {props.prompts.map((prompt, i) => (
  212. <div
  213. className={styles["prompt-hint"]}
  214. key={prompt.title + i.toString()}
  215. onClick={() => {
  216. console.log("click hint");
  217. props.onPromptSelect(prompt);
  218. }}
  219. >
  220. <div className={styles["hint-title"]}>{prompt.title}</div>
  221. <div className={styles["hint-content"]}>{prompt.content}</div>
  222. </div>
  223. ))}
  224. </div>
  225. );
  226. }
  227. function useScrollToBottom() {
  228. // for auto-scroll
  229. const scrollRef = useRef<HTMLDivElement>(null);
  230. const [autoScroll, setAutoScroll] = useState(true);
  231. const scrollToBottom = () => {
  232. const dom = scrollRef.current;
  233. if (dom) {
  234. setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1);
  235. }
  236. };
  237. // auto scroll
  238. useLayoutEffect(() => {
  239. autoScroll && scrollToBottom();
  240. });
  241. return {
  242. scrollRef,
  243. autoScroll,
  244. setAutoScroll,
  245. scrollToBottom,
  246. };
  247. }
  248. export function ChatActions(props: {
  249. showPromptModal: () => void;
  250. scrollToBottom: () => void;
  251. showPromptHints: () => void;
  252. hitBottom: boolean;
  253. }) {
  254. const config = useAppConfig();
  255. const navigate = useNavigate();
  256. // switch themes
  257. const theme = config.theme;
  258. function nextTheme() {
  259. const themes = [Theme.Auto, Theme.Light, Theme.Dark];
  260. const themeIndex = themes.indexOf(theme);
  261. const nextIndex = (themeIndex + 1) % themes.length;
  262. const nextTheme = themes[nextIndex];
  263. config.update((config) => (config.theme = nextTheme));
  264. }
  265. // stop all responses
  266. const couldStop = ControllerPool.hasPending();
  267. const stopAll = () => ControllerPool.stopAll();
  268. return (
  269. <div className={chatStyle["chat-input-actions"]}>
  270. {couldStop && (
  271. <div
  272. className={`${chatStyle["chat-input-action"]} clickable`}
  273. onClick={stopAll}
  274. >
  275. <StopIcon />
  276. </div>
  277. )}
  278. {!props.hitBottom && (
  279. <div
  280. className={`${chatStyle["chat-input-action"]} clickable`}
  281. onClick={props.scrollToBottom}
  282. >
  283. <BottomIcon />
  284. </div>
  285. )}
  286. {props.hitBottom && (
  287. <div
  288. className={`${chatStyle["chat-input-action"]} clickable`}
  289. onClick={props.showPromptModal}
  290. >
  291. <BrainIcon />
  292. </div>
  293. )}
  294. <div
  295. className={`${chatStyle["chat-input-action"]} clickable`}
  296. onClick={nextTheme}
  297. >
  298. {theme === Theme.Auto ? (
  299. <AutoIcon />
  300. ) : theme === Theme.Light ? (
  301. <LightIcon />
  302. ) : theme === Theme.Dark ? (
  303. <DarkIcon />
  304. ) : null}
  305. </div>
  306. <div
  307. className={`${chatStyle["chat-input-action"]} clickable`}
  308. onClick={props.showPromptHints}
  309. >
  310. <PromptIcon />
  311. </div>
  312. <div
  313. className={`${chatStyle["chat-input-action"]} clickable`}
  314. onClick={() => {
  315. navigate(Path.Masks);
  316. }}
  317. >
  318. <MaskIcon />
  319. </div>
  320. </div>
  321. );
  322. }
  323. export function Chat() {
  324. type RenderMessage = Message & { preview?: boolean };
  325. const chatStore = useChatStore();
  326. const [session, sessionIndex] = useChatStore((state) => [
  327. state.currentSession(),
  328. state.currentSessionIndex,
  329. ]);
  330. const config = useAppConfig();
  331. const fontSize = config.fontSize;
  332. const inputRef = useRef<HTMLTextAreaElement>(null);
  333. const [userInput, setUserInput] = useState("");
  334. const [beforeInput, setBeforeInput] = useState("");
  335. const [isLoading, setIsLoading] = useState(false);
  336. const { submitKey, shouldSubmit } = useSubmitHandler();
  337. const { scrollRef, setAutoScroll, scrollToBottom } = useScrollToBottom();
  338. const [hitBottom, setHitBottom] = useState(true);
  339. const isMobileScreen = useMobileScreen();
  340. const navigate = useNavigate();
  341. const onChatBodyScroll = (e: HTMLElement) => {
  342. const isTouchBottom = e.scrollTop + e.clientHeight >= e.scrollHeight - 100;
  343. setHitBottom(isTouchBottom);
  344. };
  345. // prompt hints
  346. const promptStore = usePromptStore();
  347. const [promptHints, setPromptHints] = useState<Prompt[]>([]);
  348. const onSearch = useDebouncedCallback(
  349. (text: string) => {
  350. setPromptHints(promptStore.search(text));
  351. },
  352. 100,
  353. { leading: true, trailing: true },
  354. );
  355. const onPromptSelect = (prompt: Prompt) => {
  356. setPromptHints([]);
  357. inputRef.current?.focus();
  358. setTimeout(() => setUserInput(prompt.content), 60);
  359. };
  360. // auto grow input
  361. const [inputRows, setInputRows] = useState(2);
  362. const measure = useDebouncedCallback(
  363. () => {
  364. const rows = inputRef.current ? autoGrowTextArea(inputRef.current) : 1;
  365. const inputRows = Math.min(
  366. 20,
  367. Math.max(2 + Number(!isMobileScreen), rows),
  368. );
  369. setInputRows(inputRows);
  370. },
  371. 100,
  372. {
  373. leading: true,
  374. trailing: true,
  375. },
  376. );
  377. // eslint-disable-next-line react-hooks/exhaustive-deps
  378. useEffect(measure, [userInput]);
  379. // only search prompts when user input is short
  380. const SEARCH_TEXT_LIMIT = 30;
  381. const onInput = (text: string) => {
  382. setUserInput(text);
  383. const n = text.trim().length;
  384. // clear search results
  385. if (n === 0) {
  386. setPromptHints([]);
  387. } else if (!config.disablePromptHint && n < SEARCH_TEXT_LIMIT) {
  388. // check if need to trigger auto completion
  389. if (text.startsWith("/")) {
  390. let searchText = text.slice(1);
  391. onSearch(searchText);
  392. }
  393. }
  394. };
  395. // submit user input
  396. const onUserSubmit = () => {
  397. if (userInput.length <= 0) return;
  398. setIsLoading(true);
  399. chatStore.onUserInput(userInput).then(() => setIsLoading(false));
  400. setBeforeInput(userInput);
  401. setUserInput("");
  402. setPromptHints([]);
  403. if (!isMobileScreen) inputRef.current?.focus();
  404. setAutoScroll(true);
  405. };
  406. // stop response
  407. const onUserStop = (messageId: number) => {
  408. ControllerPool.stop(sessionIndex, messageId);
  409. };
  410. // check if should send message
  411. const onInputKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
  412. // if ArrowUp and no userInput
  413. if (e.key === "ArrowUp" && userInput.length <= 0) {
  414. setUserInput(beforeInput);
  415. e.preventDefault();
  416. return;
  417. }
  418. if (shouldSubmit(e)) {
  419. onUserSubmit();
  420. e.preventDefault();
  421. }
  422. };
  423. const onRightClick = (e: any, message: Message) => {
  424. // auto fill user input
  425. if (message.role === "user") {
  426. setUserInput(message.content);
  427. }
  428. // copy to clipboard
  429. if (selectOrCopy(e.currentTarget, message.content)) {
  430. e.preventDefault();
  431. }
  432. };
  433. const findLastUserIndex = (messageId: number) => {
  434. // find last user input message and resend
  435. let lastUserMessageIndex: number | null = null;
  436. for (let i = 0; i < session.messages.length; i += 1) {
  437. const message = session.messages[i];
  438. if (message.id === messageId) {
  439. break;
  440. }
  441. if (message.role === "user") {
  442. lastUserMessageIndex = i;
  443. }
  444. }
  445. return lastUserMessageIndex;
  446. };
  447. const deleteMessage = (userIndex: number) => {
  448. chatStore.updateCurrentSession((session) =>
  449. session.messages.splice(userIndex, 2),
  450. );
  451. };
  452. const onDelete = (botMessageId: number) => {
  453. const userIndex = findLastUserIndex(botMessageId);
  454. if (userIndex === null) return;
  455. deleteMessage(userIndex);
  456. };
  457. const onResend = (botMessageId: number) => {
  458. // find last user input message and resend
  459. const userIndex = findLastUserIndex(botMessageId);
  460. if (userIndex === null) return;
  461. setIsLoading(true);
  462. const content = session.messages[userIndex].content;
  463. deleteMessage(userIndex);
  464. chatStore.onUserInput(content).then(() => setIsLoading(false));
  465. inputRef.current?.focus();
  466. };
  467. const context: RenderMessage[] = session.mask.context.slice();
  468. const accessStore = useAccessStore();
  469. if (
  470. context.length === 0 &&
  471. session.messages.at(0)?.content !== BOT_HELLO.content
  472. ) {
  473. const copiedHello = Object.assign({}, BOT_HELLO);
  474. if (!accessStore.isAuthorized()) {
  475. copiedHello.content = Locale.Error.Unauthorized;
  476. }
  477. context.push(copiedHello);
  478. }
  479. // preview messages
  480. const messages = context
  481. .concat(session.messages as RenderMessage[])
  482. .concat(
  483. isLoading
  484. ? [
  485. {
  486. ...createMessage({
  487. role: "assistant",
  488. content: "……",
  489. }),
  490. preview: true,
  491. },
  492. ]
  493. : [],
  494. )
  495. .concat(
  496. userInput.length > 0 && config.sendPreviewBubble
  497. ? [
  498. {
  499. ...createMessage({
  500. role: "user",
  501. content: userInput,
  502. }),
  503. preview: true,
  504. },
  505. ]
  506. : [],
  507. );
  508. const [showPromptModal, setShowPromptModal] = useState(false);
  509. const renameSession = () => {
  510. const newTopic = prompt(Locale.Chat.Rename, session.topic);
  511. if (newTopic && newTopic !== session.topic) {
  512. chatStore.updateCurrentSession((session) => (session.topic = newTopic!));
  513. }
  514. };
  515. const location = useLocation();
  516. const isChat = location.pathname === Path.Chat;
  517. const autoFocus = isChat; // only focus in chat page
  518. return (
  519. <div className={styles.chat} key={session.id}>
  520. <div className="window-header">
  521. <div className="window-header-title">
  522. <div
  523. className={`window-header-main-title " ${styles["chat-body-title"]}`}
  524. onClickCapture={renameSession}
  525. >
  526. {!session.topic ? DEFAULT_TOPIC : session.topic}
  527. </div>
  528. <div className="window-header-sub-title">
  529. {Locale.Chat.SubTitle(session.messages.length)}
  530. </div>
  531. </div>
  532. <div className="window-actions">
  533. <div className={"window-action-button" + " " + styles.mobile}>
  534. <IconButton
  535. icon={<ReturnIcon />}
  536. bordered
  537. title={Locale.Chat.Actions.ChatList}
  538. onClick={() => navigate(Path.Home)}
  539. />
  540. </div>
  541. <div className="window-action-button">
  542. <IconButton
  543. icon={<RenameIcon />}
  544. bordered
  545. onClick={renameSession}
  546. />
  547. </div>
  548. <div className="window-action-button">
  549. <IconButton
  550. icon={<ExportIcon />}
  551. bordered
  552. title={Locale.Chat.Actions.Export}
  553. onClick={() => {
  554. exportMessages(
  555. session.messages.filter((msg) => !msg.isError),
  556. session.topic,
  557. );
  558. }}
  559. />
  560. </div>
  561. {!isMobileScreen && (
  562. <div className="window-action-button">
  563. <IconButton
  564. icon={config.tightBorder ? <MinIcon /> : <MaxIcon />}
  565. bordered
  566. onClick={() => {
  567. config.update(
  568. (config) => (config.tightBorder = !config.tightBorder),
  569. );
  570. }}
  571. />
  572. </div>
  573. )}
  574. </div>
  575. <PromptToast
  576. showToast={!hitBottom}
  577. showModal={showPromptModal}
  578. setShowModal={setShowPromptModal}
  579. />
  580. </div>
  581. <div
  582. className={styles["chat-body"]}
  583. ref={scrollRef}
  584. onScroll={(e) => onChatBodyScroll(e.currentTarget)}
  585. onMouseDown={() => inputRef.current?.blur()}
  586. onWheel={(e) => setAutoScroll(hitBottom && e.deltaY > 0)}
  587. onTouchStart={() => {
  588. inputRef.current?.blur();
  589. setAutoScroll(false);
  590. }}
  591. >
  592. {messages.map((message, i) => {
  593. const isUser = message.role === "user";
  594. const showActions =
  595. !isUser &&
  596. i > 0 &&
  597. !(message.preview || message.content.length === 0);
  598. const showTyping = message.preview || message.streaming;
  599. return (
  600. <div
  601. key={i}
  602. className={
  603. isUser ? styles["chat-message-user"] : styles["chat-message"]
  604. }
  605. >
  606. <div className={styles["chat-message-container"]}>
  607. <div className={styles["chat-message-avatar"]}>
  608. {message.role === "user" ? (
  609. <Avatar avatar={config.avatar} />
  610. ) : (
  611. <MaskAvatar mask={session.mask} />
  612. )}
  613. </div>
  614. {showTyping && (
  615. <div className={styles["chat-message-status"]}>
  616. {Locale.Chat.Typing}
  617. </div>
  618. )}
  619. <div className={styles["chat-message-item"]}>
  620. {showActions && (
  621. <div className={styles["chat-message-top-actions"]}>
  622. {message.streaming ? (
  623. <div
  624. className={styles["chat-message-top-action"]}
  625. onClick={() => onUserStop(message.id ?? i)}
  626. >
  627. {Locale.Chat.Actions.Stop}
  628. </div>
  629. ) : (
  630. <>
  631. <div
  632. className={styles["chat-message-top-action"]}
  633. onClick={() => onDelete(message.id ?? i)}
  634. >
  635. {Locale.Chat.Actions.Delete}
  636. </div>
  637. <div
  638. className={styles["chat-message-top-action"]}
  639. onClick={() => onResend(message.id ?? i)}
  640. >
  641. {Locale.Chat.Actions.Retry}
  642. </div>
  643. </>
  644. )}
  645. <div
  646. className={styles["chat-message-top-action"]}
  647. onClick={() => copyToClipboard(message.content)}
  648. >
  649. {Locale.Chat.Actions.Copy}
  650. </div>
  651. </div>
  652. )}
  653. <Markdown
  654. content={message.content}
  655. loading={
  656. (message.preview || message.content.length === 0) &&
  657. !isUser
  658. }
  659. onContextMenu={(e) => onRightClick(e, message)}
  660. onDoubleClickCapture={() => {
  661. if (!isMobileScreen) return;
  662. setUserInput(message.content);
  663. }}
  664. fontSize={fontSize}
  665. parentRef={scrollRef}
  666. defaultShow={i >= messages.length - 10}
  667. />
  668. </div>
  669. {!isUser && !message.preview && (
  670. <div className={styles["chat-message-actions"]}>
  671. <div className={styles["chat-message-action-date"]}>
  672. {message.date.toLocaleString()}
  673. </div>
  674. </div>
  675. )}
  676. </div>
  677. </div>
  678. );
  679. })}
  680. </div>
  681. <div className={styles["chat-input-panel"]}>
  682. <PromptHints prompts={promptHints} onPromptSelect={onPromptSelect} />
  683. <ChatActions
  684. showPromptModal={() => setShowPromptModal(true)}
  685. scrollToBottom={scrollToBottom}
  686. hitBottom={hitBottom}
  687. showPromptHints={() => {
  688. inputRef.current?.focus();
  689. onSearch("");
  690. }}
  691. />
  692. <div className={styles["chat-input-panel-inner"]}>
  693. <textarea
  694. ref={inputRef}
  695. className={styles["chat-input"]}
  696. placeholder={Locale.Chat.Input(submitKey)}
  697. onInput={(e) => onInput(e.currentTarget.value)}
  698. value={userInput}
  699. onKeyDown={onInputKeyDown}
  700. onFocus={() => setAutoScroll(true)}
  701. onBlur={() => setAutoScroll(false)}
  702. rows={inputRows}
  703. autoFocus={autoFocus}
  704. />
  705. <IconButton
  706. icon={<SendWhiteIcon />}
  707. text={Locale.Chat.Send}
  708. className={styles["chat-input-send"]}
  709. type="primary"
  710. onClick={onUserSubmit}
  711. />
  712. </div>
  713. </div>
  714. </div>
  715. );
  716. }