MessageInput.svelte 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { v4 as uuidv4 } from 'uuid';
  4. import { createPicker, getAuthToken } from '$lib/utils/google-drive-picker';
  5. import { onMount, tick, getContext, createEventDispatcher, onDestroy } from 'svelte';
  6. const dispatch = createEventDispatcher();
  7. import {
  8. type Model,
  9. mobile,
  10. settings,
  11. showSidebar,
  12. models,
  13. config,
  14. showCallOverlay,
  15. tools,
  16. user as _user,
  17. showControls
  18. } from '$lib/stores';
  19. import { blobToFile, compressImage, createMessagesList, findWordIndices } from '$lib/utils';
  20. import { transcribeAudio } from '$lib/apis/audio';
  21. import { uploadFile } from '$lib/apis/files';
  22. import { generateAutoCompletion } from '$lib/apis';
  23. import { deleteFileById } from '$lib/apis/files';
  24. import { WEBUI_BASE_URL, WEBUI_API_BASE_URL, PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants';
  25. import InputMenu from './MessageInput/InputMenu.svelte';
  26. import VoiceRecording from './MessageInput/VoiceRecording.svelte';
  27. import FilesOverlay from './MessageInput/FilesOverlay.svelte';
  28. import Commands from './MessageInput/Commands.svelte';
  29. import RichTextInput from '../common/RichTextInput.svelte';
  30. import Tooltip from '../common/Tooltip.svelte';
  31. import FileItem from '../common/FileItem.svelte';
  32. import Image from '../common/Image.svelte';
  33. import XMark from '../icons/XMark.svelte';
  34. import Headphone from '../icons/Headphone.svelte';
  35. import GlobeAlt from '../icons/GlobeAlt.svelte';
  36. import PhotoSolid from '../icons/PhotoSolid.svelte';
  37. import Photo from '../icons/Photo.svelte';
  38. import CommandLine from '../icons/CommandLine.svelte';
  39. const i18n = getContext('i18n');
  40. export let transparentBackground = false;
  41. export let onChange: Function = () => {};
  42. export let createMessagePair: Function;
  43. export let stopResponse: Function;
  44. export let autoScroll = false;
  45. export let atSelectedModel: Model | undefined = undefined;
  46. export let selectedModels: [''];
  47. let selectedModelIds = [];
  48. $: selectedModelIds = atSelectedModel !== undefined ? [atSelectedModel.id] : selectedModels;
  49. export let history;
  50. export let prompt = '';
  51. export let files = [];
  52. export let selectedToolIds = [];
  53. export let imageGenerationEnabled = false;
  54. export let webSearchEnabled = false;
  55. export let codeInterpreterEnabled = false;
  56. $: onChange({
  57. prompt,
  58. files,
  59. selectedToolIds,
  60. imageGenerationEnabled,
  61. webSearchEnabled
  62. });
  63. let loaded = false;
  64. let recording = false;
  65. let chatInputContainerElement;
  66. let chatInputElement;
  67. let filesInputElement;
  68. let commandsElement;
  69. let inputFiles;
  70. let dragged = false;
  71. let user = null;
  72. export let placeholder = '';
  73. let visionCapableModels = [];
  74. $: visionCapableModels = [...(atSelectedModel ? [atSelectedModel] : selectedModels)].filter(
  75. (model) => $models.find((m) => m.id === model)?.info?.meta?.capabilities?.vision ?? true
  76. );
  77. const scrollToBottom = () => {
  78. const element = document.getElementById('messages-container');
  79. element.scrollTo({
  80. top: element.scrollHeight,
  81. behavior: 'smooth'
  82. });
  83. };
  84. const screenCaptureHandler = async () => {
  85. try {
  86. // Request screen media
  87. const mediaStream = await navigator.mediaDevices.getDisplayMedia({
  88. video: { cursor: 'never' },
  89. audio: false
  90. });
  91. // Once the user selects a screen, temporarily create a video element
  92. const video = document.createElement('video');
  93. video.srcObject = mediaStream;
  94. // Ensure the video loads without affecting user experience or tab switching
  95. await video.play();
  96. // Set up the canvas to match the video dimensions
  97. const canvas = document.createElement('canvas');
  98. canvas.width = video.videoWidth;
  99. canvas.height = video.videoHeight;
  100. // Grab a single frame from the video stream using the canvas
  101. const context = canvas.getContext('2d');
  102. context.drawImage(video, 0, 0, canvas.width, canvas.height);
  103. // Stop all video tracks (stop screen sharing) after capturing the image
  104. mediaStream.getTracks().forEach((track) => track.stop());
  105. // bring back focus to this current tab, so that the user can see the screen capture
  106. window.focus();
  107. // Convert the canvas to a Base64 image URL
  108. const imageUrl = canvas.toDataURL('image/png');
  109. // Add the captured image to the files array to render it
  110. files = [...files, { type: 'image', url: imageUrl }];
  111. // Clean memory: Clear video srcObject
  112. video.srcObject = null;
  113. } catch (error) {
  114. // Handle any errors (e.g., user cancels screen sharing)
  115. console.error('Error capturing screen:', error);
  116. }
  117. };
  118. const uploadFileHandler = async (file, fullContext: boolean = false) => {
  119. if ($_user?.role !== 'admin' && !($_user?.permissions?.chat?.file_upload ?? true)) {
  120. toast.error($i18n.t('You do not have permission to upload files.'));
  121. return null;
  122. }
  123. const tempItemId = uuidv4();
  124. const fileItem = {
  125. type: 'file',
  126. file: '',
  127. id: null,
  128. url: '',
  129. name: file.name,
  130. collection_name: '',
  131. status: 'uploading',
  132. size: file.size,
  133. error: '',
  134. itemId: tempItemId,
  135. ...(fullContext ? { context: 'full' } : {})
  136. };
  137. if (fileItem.size == 0) {
  138. toast.error($i18n.t('You cannot upload an empty file.'));
  139. return null;
  140. }
  141. files = [...files, fileItem];
  142. // Check if the file is an audio file and transcribe/convert it to text file
  143. if (['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/x-m4a'].includes(file['type'])) {
  144. const res = await transcribeAudio(localStorage.token, file).catch((error) => {
  145. toast.error(`${error}`);
  146. return null;
  147. });
  148. if (res) {
  149. console.log(res);
  150. const blob = new Blob([res.text], { type: 'text/plain' });
  151. file = blobToFile(blob, `${file.name}.txt`);
  152. fileItem.name = file.name;
  153. fileItem.size = file.size;
  154. }
  155. }
  156. try {
  157. // During the file upload, file content is automatically extracted.
  158. const uploadedFile = await uploadFile(localStorage.token, file);
  159. if (uploadedFile) {
  160. console.log('File upload completed:', {
  161. id: uploadedFile.id,
  162. name: fileItem.name,
  163. collection: uploadedFile?.meta?.collection_name
  164. });
  165. if (uploadedFile.error) {
  166. console.warn('File upload warning:', uploadedFile.error);
  167. toast.warning(uploadedFile.error);
  168. }
  169. fileItem.status = 'uploaded';
  170. fileItem.file = uploadedFile;
  171. fileItem.id = uploadedFile.id;
  172. fileItem.collection_name =
  173. uploadedFile?.meta?.collection_name || uploadedFile?.collection_name;
  174. fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
  175. files = files;
  176. } else {
  177. files = files.filter((item) => item?.itemId !== tempItemId);
  178. }
  179. } catch (e) {
  180. toast.error(`${e}`);
  181. files = files.filter((item) => item?.itemId !== tempItemId);
  182. }
  183. };
  184. const inputFilesHandler = async (inputFiles) => {
  185. console.log('Input files handler called with:', inputFiles);
  186. inputFiles.forEach((file) => {
  187. console.log('Processing file:', {
  188. name: file.name,
  189. type: file.type,
  190. size: file.size,
  191. extension: file.name.split('.').at(-1)
  192. });
  193. if (
  194. ($config?.file?.max_size ?? null) !== null &&
  195. file.size > ($config?.file?.max_size ?? 0) * 1024 * 1024
  196. ) {
  197. console.log('File exceeds max size limit:', {
  198. fileSize: file.size,
  199. maxSize: ($config?.file?.max_size ?? 0) * 1024 * 1024
  200. });
  201. toast.error(
  202. $i18n.t(`File size should not exceed {{maxSize}} MB.`, {
  203. maxSize: $config?.file?.max_size
  204. })
  205. );
  206. return;
  207. }
  208. if (['image/gif', 'image/webp', 'image/jpeg', 'image/png'].includes(file['type'])) {
  209. if (visionCapableModels.length === 0) {
  210. toast.error($i18n.t('Selected model(s) do not support image inputs'));
  211. return;
  212. }
  213. let reader = new FileReader();
  214. reader.onload = async (event) => {
  215. let imageUrl = event.target.result;
  216. if ($settings?.imageCompression ?? false) {
  217. const width = $settings?.imageCompressionSize?.width ?? null;
  218. const height = $settings?.imageCompressionSize?.height ?? null;
  219. if (width || height) {
  220. imageUrl = await compressImage(imageUrl, width, height);
  221. }
  222. }
  223. files = [
  224. ...files,
  225. {
  226. type: 'image',
  227. url: `${imageUrl}`
  228. }
  229. ];
  230. };
  231. reader.readAsDataURL(file);
  232. } else {
  233. uploadFileHandler(file);
  234. }
  235. });
  236. };
  237. const handleKeyDown = (event: KeyboardEvent) => {
  238. if (event.key === 'Escape') {
  239. console.log('Escape');
  240. dragged = false;
  241. }
  242. };
  243. const onDragOver = (e) => {
  244. e.preventDefault();
  245. // Check if a file is being dragged.
  246. if (e.dataTransfer?.types?.includes('Files')) {
  247. dragged = true;
  248. } else {
  249. dragged = false;
  250. }
  251. };
  252. const onDragLeave = () => {
  253. dragged = false;
  254. };
  255. const onDrop = async (e) => {
  256. e.preventDefault();
  257. console.log(e);
  258. if (e.dataTransfer?.files) {
  259. const inputFiles = Array.from(e.dataTransfer?.files);
  260. if (inputFiles && inputFiles.length > 0) {
  261. console.log(inputFiles);
  262. inputFilesHandler(inputFiles);
  263. }
  264. }
  265. dragged = false;
  266. };
  267. onMount(async () => {
  268. loaded = true;
  269. window.setTimeout(() => {
  270. const chatInput = document.getElementById('chat-input');
  271. chatInput?.focus();
  272. }, 0);
  273. window.addEventListener('keydown', handleKeyDown);
  274. await tick();
  275. const dropzoneElement = document.getElementById('chat-container');
  276. dropzoneElement?.addEventListener('dragover', onDragOver);
  277. dropzoneElement?.addEventListener('drop', onDrop);
  278. dropzoneElement?.addEventListener('dragleave', onDragLeave);
  279. });
  280. onDestroy(() => {
  281. console.log('destroy');
  282. window.removeEventListener('keydown', handleKeyDown);
  283. const dropzoneElement = document.getElementById('chat-container');
  284. if (dropzoneElement) {
  285. dropzoneElement?.removeEventListener('dragover', onDragOver);
  286. dropzoneElement?.removeEventListener('drop', onDrop);
  287. dropzoneElement?.removeEventListener('dragleave', onDragLeave);
  288. }
  289. });
  290. </script>
  291. <FilesOverlay show={dragged} />
  292. {#if loaded}
  293. <div class="w-full font-primary">
  294. <div class=" mx-auto inset-x-0 bg-transparent flex justify-center">
  295. <div
  296. class="flex flex-col px-3 {($settings?.widescreenMode ?? null)
  297. ? 'max-w-full'
  298. : 'max-w-6xl'} w-full"
  299. >
  300. <div class="relative">
  301. {#if autoScroll === false && history?.currentId}
  302. <div
  303. class=" absolute -top-12 left-0 right-0 flex justify-center z-30 pointer-events-none"
  304. >
  305. <button
  306. class=" bg-white border border-gray-100 dark:border-none dark:bg-white/20 p-1.5 rounded-full pointer-events-auto"
  307. on:click={() => {
  308. autoScroll = true;
  309. scrollToBottom();
  310. }}
  311. >
  312. <svg
  313. xmlns="http://www.w3.org/2000/svg"
  314. viewBox="0 0 20 20"
  315. fill="currentColor"
  316. class="w-5 h-5"
  317. >
  318. <path
  319. fill-rule="evenodd"
  320. d="M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z"
  321. clip-rule="evenodd"
  322. />
  323. </svg>
  324. </button>
  325. </div>
  326. {/if}
  327. </div>
  328. <div class="w-full relative">
  329. {#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || ($settings?.webSearch ?? false) === 'always' || imageGenerationEnabled || codeInterpreterEnabled}
  330. <div
  331. class="px-3 pb-0.5 pt-1.5 text-left w-full flex flex-col absolute bottom-0 left-0 right-0 bg-gradient-to-t from-white dark:from-gray-900 z-10"
  332. >
  333. {#if selectedToolIds.length > 0}
  334. <div class="flex items-center justify-between w-full">
  335. <div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
  336. <div class="pl-1">
  337. <span class="relative flex size-2">
  338. <span
  339. class="animate-ping absolute inline-flex h-full w-full rounded-full bg-yellow-400 opacity-75"
  340. />
  341. <span class="relative inline-flex rounded-full size-2 bg-yellow-500" />
  342. </span>
  343. </div>
  344. <div class=" text-ellipsis line-clamp-1 flex">
  345. {#each selectedToolIds.map((id) => {
  346. return $tools ? $tools.find((t) => t.id === id) : { id: id, name: id };
  347. }) as tool, toolIdx (toolIdx)}
  348. <Tooltip
  349. content={tool?.meta?.description ?? ''}
  350. className=" {toolIdx !== 0 ? 'pl-0.5' : ''} flex-shrink-0"
  351. placement="top"
  352. >
  353. {tool.name}
  354. </Tooltip>
  355. {#if toolIdx !== selectedToolIds.length - 1}
  356. <span>, </span>
  357. {/if}
  358. {/each}
  359. </div>
  360. </div>
  361. </div>
  362. {/if}
  363. {#if webSearchEnabled || ($settings?.webSearch ?? false) === 'always'}
  364. <div class="flex items-center justify-between w-full">
  365. <div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
  366. <div class="pl-1">
  367. <span class="relative flex size-2">
  368. <span
  369. class="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"
  370. />
  371. <span class="relative inline-flex rounded-full size-2 bg-blue-500" />
  372. </span>
  373. </div>
  374. <div class=" translate-y-[0.5px]">{$i18n.t('Search the internet')}</div>
  375. </div>
  376. </div>
  377. {/if}
  378. {#if imageGenerationEnabled}
  379. <div class="flex items-center justify-between w-full">
  380. <div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
  381. <div class="pl-1">
  382. <span class="relative flex size-2">
  383. <span
  384. class="animate-ping absolute inline-flex h-full w-full rounded-full bg-teal-400 opacity-75"
  385. />
  386. <span class="relative inline-flex rounded-full size-2 bg-teal-500" />
  387. </span>
  388. </div>
  389. <div class=" translate-y-[0.5px]">{$i18n.t('Generate an image')}</div>
  390. </div>
  391. </div>
  392. {/if}
  393. {#if codeInterpreterEnabled}
  394. <div class="flex items-center justify-between w-full">
  395. <div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
  396. <div class="pl-1">
  397. <span class="relative flex size-2">
  398. <span
  399. class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
  400. />
  401. <span class="relative inline-flex rounded-full size-2 bg-green-500" />
  402. </span>
  403. </div>
  404. <div class=" translate-y-[0.5px]">{$i18n.t('Execute code for analysis')}</div>
  405. </div>
  406. </div>
  407. {/if}
  408. {#if atSelectedModel !== undefined}
  409. <div class="flex items-center justify-between w-full">
  410. <div class="pl-[1px] flex items-center gap-2 text-sm dark:text-gray-500">
  411. <img
  412. crossorigin="anonymous"
  413. alt="model profile"
  414. class="size-3.5 max-w-[28px] object-cover rounded-full"
  415. src={$models.find((model) => model.id === atSelectedModel.id)?.info?.meta
  416. ?.profile_image_url ??
  417. ($i18n.language === 'dg-DG'
  418. ? `/doge.png`
  419. : `${WEBUI_BASE_URL}/static/favicon.png`)}
  420. />
  421. <div class="translate-y-[0.5px]">
  422. Talking to <span class=" font-medium">{atSelectedModel.name}</span>
  423. </div>
  424. </div>
  425. <div>
  426. <button
  427. class="flex items-center dark:text-gray-500"
  428. on:click={() => {
  429. atSelectedModel = undefined;
  430. }}
  431. >
  432. <XMark />
  433. </button>
  434. </div>
  435. </div>
  436. {/if}
  437. </div>
  438. {/if}
  439. <Commands
  440. bind:this={commandsElement}
  441. bind:prompt
  442. bind:files
  443. on:upload={(e) => {
  444. dispatch('upload', e.detail);
  445. }}
  446. on:select={(e) => {
  447. const data = e.detail;
  448. if (data?.type === 'model') {
  449. atSelectedModel = data.data;
  450. }
  451. const chatInputElement = document.getElementById('chat-input');
  452. chatInputElement?.focus();
  453. }}
  454. />
  455. </div>
  456. </div>
  457. </div>
  458. <div class="{transparentBackground ? 'bg-transparent' : 'bg-white dark:bg-gray-900'} ">
  459. <div
  460. class="{($settings?.widescreenMode ?? null)
  461. ? 'max-w-full'
  462. : 'max-w-6xl'} px-2.5 mx-auto inset-x-0"
  463. >
  464. <div class="">
  465. <input
  466. bind:this={filesInputElement}
  467. bind:files={inputFiles}
  468. type="file"
  469. hidden
  470. multiple
  471. on:change={async () => {
  472. if (inputFiles && inputFiles.length > 0) {
  473. const _inputFiles = Array.from(inputFiles);
  474. inputFilesHandler(_inputFiles);
  475. } else {
  476. toast.error($i18n.t(`File not found.`));
  477. }
  478. filesInputElement.value = '';
  479. }}
  480. />
  481. {#if recording}
  482. <VoiceRecording
  483. bind:recording
  484. on:cancel={async () => {
  485. recording = false;
  486. await tick();
  487. document.getElementById('chat-input')?.focus();
  488. }}
  489. on:confirm={async (e) => {
  490. const { text, filename } = e.detail;
  491. prompt = `${prompt}${text} `;
  492. recording = false;
  493. await tick();
  494. document.getElementById('chat-input')?.focus();
  495. if ($settings?.speechAutoSend ?? false) {
  496. dispatch('submit', prompt);
  497. }
  498. }}
  499. />
  500. {:else}
  501. <form
  502. class="w-full flex gap-1.5"
  503. on:submit|preventDefault={() => {
  504. // check if selectedModels support image input
  505. dispatch('submit', prompt);
  506. }}
  507. >
  508. <div
  509. class="flex-1 flex flex-col relative w-full rounded-3xl px-1 bg-gray-600/5 dark:bg-gray-400/5 dark:text-gray-100"
  510. dir={$settings?.chatDirection ?? 'LTR'}
  511. >
  512. {#if files.length > 0}
  513. <div class="mx-2 mt-2.5 -mb-1 flex items-center flex-wrap gap-2">
  514. {#each files as file, fileIdx}
  515. {#if file.type === 'image'}
  516. <div class=" relative group">
  517. <div class="relative flex items-center">
  518. <Image
  519. src={file.url}
  520. alt="input"
  521. imageClassName=" size-14 rounded-xl object-cover"
  522. />
  523. {#if atSelectedModel ? visionCapableModels.length === 0 : selectedModels.length !== visionCapableModels.length}
  524. <Tooltip
  525. className=" absolute top-1 left-1"
  526. content={$i18n.t('{{ models }}', {
  527. models: [
  528. ...(atSelectedModel ? [atSelectedModel] : selectedModels)
  529. ]
  530. .filter((id) => !visionCapableModels.includes(id))
  531. .join(', ')
  532. })}
  533. >
  534. <svg
  535. xmlns="http://www.w3.org/2000/svg"
  536. viewBox="0 0 24 24"
  537. fill="currentColor"
  538. class="size-4 fill-yellow-300"
  539. >
  540. <path
  541. fill-rule="evenodd"
  542. d="M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z"
  543. clip-rule="evenodd"
  544. />
  545. </svg>
  546. </Tooltip>
  547. {/if}
  548. </div>
  549. <div class=" absolute -top-1 -right-1">
  550. <button
  551. class=" bg-white text-black border border-white rounded-full group-hover:visible invisible transition"
  552. type="button"
  553. on:click={() => {
  554. files.splice(fileIdx, 1);
  555. files = files;
  556. }}
  557. >
  558. <svg
  559. xmlns="http://www.w3.org/2000/svg"
  560. viewBox="0 0 20 20"
  561. fill="currentColor"
  562. class="w-4 h-4"
  563. >
  564. <path
  565. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  566. />
  567. </svg>
  568. </button>
  569. </div>
  570. </div>
  571. {:else}
  572. <FileItem
  573. item={file}
  574. name={file.name}
  575. type={file.type}
  576. size={file?.size}
  577. loading={file.status === 'uploading'}
  578. dismissible={true}
  579. edit={true}
  580. on:dismiss={async () => {
  581. if (file.type !== 'collection' && !file?.collection) {
  582. if (file.id) {
  583. // This will handle both file deletion and Chroma cleanup
  584. await deleteFileById(localStorage.token, file.id);
  585. }
  586. }
  587. // Remove from UI state
  588. files.splice(fileIdx, 1);
  589. files = files;
  590. }}
  591. on:click={() => {
  592. console.log(file);
  593. }}
  594. />
  595. {/if}
  596. {/each}
  597. </div>
  598. {/if}
  599. <div class="px-2.5">
  600. {#if $settings?.richTextInput ?? true}
  601. <div
  602. class="scrollbar-hidden text-left bg-transparent dark:text-gray-100 outline-none w-full pt-3 px-1 resize-none h-fit max-h-80 overflow-auto"
  603. >
  604. <RichTextInput
  605. bind:this={chatInputElement}
  606. bind:value={prompt}
  607. id="chat-input"
  608. messageInput={true}
  609. shiftEnter={!$mobile ||
  610. !(
  611. 'ontouchstart' in window ||
  612. navigator.maxTouchPoints > 0 ||
  613. navigator.msMaxTouchPoints > 0
  614. )}
  615. placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
  616. largeTextAsFile={$settings?.largeTextAsFile ?? false}
  617. autocomplete={$config?.features.enable_autocomplete_generation}
  618. generateAutoCompletion={async (text) => {
  619. if (selectedModelIds.length === 0 || !selectedModelIds.at(0)) {
  620. toast.error($i18n.t('Please select a model first.'));
  621. }
  622. const res = await generateAutoCompletion(
  623. localStorage.token,
  624. selectedModelIds.at(0),
  625. text,
  626. history?.currentId
  627. ? createMessagesList(history, history.currentId)
  628. : null
  629. ).catch((error) => {
  630. console.log(error);
  631. return null;
  632. });
  633. console.log(res);
  634. return res;
  635. }}
  636. on:keydown={async (e) => {
  637. e = e.detail.event;
  638. const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
  639. const commandsContainerElement =
  640. document.getElementById('commands-container');
  641. if (e.key === 'Escape') {
  642. stopResponse();
  643. }
  644. // Command/Ctrl + Shift + Enter to submit a message pair
  645. if (isCtrlPressed && e.key === 'Enter' && e.shiftKey) {
  646. e.preventDefault();
  647. createMessagePair(prompt);
  648. }
  649. // Check if Ctrl + R is pressed
  650. if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') {
  651. e.preventDefault();
  652. console.log('regenerate');
  653. const regenerateButton = [
  654. ...document.getElementsByClassName('regenerate-response-button')
  655. ]?.at(-1);
  656. regenerateButton?.click();
  657. }
  658. if (prompt === '' && e.key == 'ArrowUp') {
  659. e.preventDefault();
  660. const userMessageElement = [
  661. ...document.getElementsByClassName('user-message')
  662. ]?.at(-1);
  663. if (userMessageElement) {
  664. userMessageElement.scrollIntoView({ block: 'center' });
  665. const editButton = [
  666. ...document.getElementsByClassName('edit-user-message-button')
  667. ]?.at(-1);
  668. editButton?.click();
  669. }
  670. }
  671. if (commandsContainerElement) {
  672. if (commandsContainerElement && e.key === 'ArrowUp') {
  673. e.preventDefault();
  674. commandsElement.selectUp();
  675. const commandOptionButton = [
  676. ...document.getElementsByClassName('selected-command-option-button')
  677. ]?.at(-1);
  678. commandOptionButton.scrollIntoView({ block: 'center' });
  679. }
  680. if (commandsContainerElement && e.key === 'ArrowDown') {
  681. e.preventDefault();
  682. commandsElement.selectDown();
  683. const commandOptionButton = [
  684. ...document.getElementsByClassName('selected-command-option-button')
  685. ]?.at(-1);
  686. commandOptionButton.scrollIntoView({ block: 'center' });
  687. }
  688. if (commandsContainerElement && e.key === 'Tab') {
  689. e.preventDefault();
  690. const commandOptionButton = [
  691. ...document.getElementsByClassName('selected-command-option-button')
  692. ]?.at(-1);
  693. commandOptionButton?.click();
  694. }
  695. if (commandsContainerElement && e.key === 'Enter') {
  696. e.preventDefault();
  697. const commandOptionButton = [
  698. ...document.getElementsByClassName('selected-command-option-button')
  699. ]?.at(-1);
  700. if (commandOptionButton) {
  701. commandOptionButton?.click();
  702. } else {
  703. document.getElementById('send-message-button')?.click();
  704. }
  705. }
  706. } else {
  707. if (
  708. !$mobile ||
  709. !(
  710. 'ontouchstart' in window ||
  711. navigator.maxTouchPoints > 0 ||
  712. navigator.msMaxTouchPoints > 0
  713. )
  714. ) {
  715. // Prevent Enter key from creating a new line
  716. // Uses keyCode '13' for Enter key for chinese/japanese keyboards
  717. if (e.keyCode === 13 && !e.shiftKey) {
  718. e.preventDefault();
  719. }
  720. // Submit the prompt when Enter key is pressed
  721. if (prompt !== '' && e.keyCode === 13 && !e.shiftKey) {
  722. dispatch('submit', prompt);
  723. }
  724. }
  725. }
  726. if (e.key === 'Escape') {
  727. console.log('Escape');
  728. atSelectedModel = undefined;
  729. selectedToolIds = [];
  730. webSearchEnabled = false;
  731. imageGenerationEnabled = false;
  732. }
  733. }}
  734. on:paste={async (e) => {
  735. e = e.detail.event;
  736. console.log(e);
  737. const clipboardData = e.clipboardData || window.clipboardData;
  738. if (clipboardData && clipboardData.items) {
  739. for (const item of clipboardData.items) {
  740. if (item.type.indexOf('image') !== -1) {
  741. const blob = item.getAsFile();
  742. const reader = new FileReader();
  743. reader.onload = function (e) {
  744. files = [
  745. ...files,
  746. {
  747. type: 'image',
  748. url: `${e.target.result}`
  749. }
  750. ];
  751. };
  752. reader.readAsDataURL(blob);
  753. } else if (item.type === 'text/plain') {
  754. if ($settings?.largeTextAsFile ?? false) {
  755. const text = clipboardData.getData('text/plain');
  756. if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
  757. e.preventDefault();
  758. const blob = new Blob([text], { type: 'text/plain' });
  759. const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
  760. type: 'text/plain'
  761. });
  762. await uploadFileHandler(file, true);
  763. }
  764. }
  765. }
  766. }
  767. }
  768. }}
  769. />
  770. </div>
  771. {:else}
  772. <textarea
  773. id="chat-input"
  774. bind:this={chatInputElement}
  775. class="scrollbar-hidden bg-transparent dark:text-gray-100 outline-none w-full pt-3 px-1 resize-none"
  776. placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
  777. bind:value={prompt}
  778. on:keypress={(e) => {
  779. if (
  780. !$mobile ||
  781. !(
  782. 'ontouchstart' in window ||
  783. navigator.maxTouchPoints > 0 ||
  784. navigator.msMaxTouchPoints > 0
  785. )
  786. ) {
  787. // Prevent Enter key from creating a new line
  788. if (e.key === 'Enter' && !e.shiftKey) {
  789. e.preventDefault();
  790. }
  791. // Submit the prompt when Enter key is pressed
  792. if (prompt !== '' && e.key === 'Enter' && !e.shiftKey) {
  793. dispatch('submit', prompt);
  794. }
  795. }
  796. }}
  797. on:keydown={async (e) => {
  798. const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
  799. const commandsContainerElement =
  800. document.getElementById('commands-container');
  801. if (e.key === 'Escape') {
  802. stopResponse();
  803. }
  804. // Command/Ctrl + Shift + Enter to submit a message pair
  805. if (isCtrlPressed && e.key === 'Enter' && e.shiftKey) {
  806. e.preventDefault();
  807. createMessagePair(prompt);
  808. }
  809. // Check if Ctrl + R is pressed
  810. if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') {
  811. e.preventDefault();
  812. console.log('regenerate');
  813. const regenerateButton = [
  814. ...document.getElementsByClassName('regenerate-response-button')
  815. ]?.at(-1);
  816. regenerateButton?.click();
  817. }
  818. if (prompt === '' && e.key == 'ArrowUp') {
  819. e.preventDefault();
  820. const userMessageElement = [
  821. ...document.getElementsByClassName('user-message')
  822. ]?.at(-1);
  823. const editButton = [
  824. ...document.getElementsByClassName('edit-user-message-button')
  825. ]?.at(-1);
  826. console.log(userMessageElement);
  827. userMessageElement.scrollIntoView({ block: 'center' });
  828. editButton?.click();
  829. }
  830. if (commandsContainerElement && e.key === 'ArrowUp') {
  831. e.preventDefault();
  832. commandsElement.selectUp();
  833. const commandOptionButton = [
  834. ...document.getElementsByClassName('selected-command-option-button')
  835. ]?.at(-1);
  836. commandOptionButton.scrollIntoView({ block: 'center' });
  837. }
  838. if (commandsContainerElement && e.key === 'ArrowDown') {
  839. e.preventDefault();
  840. commandsElement.selectDown();
  841. const commandOptionButton = [
  842. ...document.getElementsByClassName('selected-command-option-button')
  843. ]?.at(-1);
  844. commandOptionButton.scrollIntoView({ block: 'center' });
  845. }
  846. if (commandsContainerElement && e.key === 'Enter') {
  847. e.preventDefault();
  848. const commandOptionButton = [
  849. ...document.getElementsByClassName('selected-command-option-button')
  850. ]?.at(-1);
  851. if (e.shiftKey) {
  852. prompt = `${prompt}\n`;
  853. } else if (commandOptionButton) {
  854. commandOptionButton?.click();
  855. } else {
  856. document.getElementById('send-message-button')?.click();
  857. }
  858. }
  859. if (commandsContainerElement && e.key === 'Tab') {
  860. e.preventDefault();
  861. const commandOptionButton = [
  862. ...document.getElementsByClassName('selected-command-option-button')
  863. ]?.at(-1);
  864. commandOptionButton?.click();
  865. } else if (e.key === 'Tab') {
  866. const words = findWordIndices(prompt);
  867. if (words.length > 0) {
  868. const word = words.at(0);
  869. const fullPrompt = prompt;
  870. prompt = prompt.substring(0, word?.endIndex + 1);
  871. await tick();
  872. e.target.scrollTop = e.target.scrollHeight;
  873. prompt = fullPrompt;
  874. await tick();
  875. e.preventDefault();
  876. e.target.setSelectionRange(word?.startIndex, word.endIndex + 1);
  877. }
  878. e.target.style.height = '';
  879. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  880. }
  881. if (e.key === 'Escape') {
  882. console.log('Escape');
  883. atSelectedModel = undefined;
  884. selectedToolIds = [];
  885. webSearchEnabled = false;
  886. imageGenerationEnabled = false;
  887. }
  888. }}
  889. rows="1"
  890. on:input={async (e) => {
  891. e.target.style.height = '';
  892. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  893. }}
  894. on:focus={async (e) => {
  895. e.target.style.height = '';
  896. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  897. }}
  898. on:paste={async (e) => {
  899. const clipboardData = e.clipboardData || window.clipboardData;
  900. if (clipboardData && clipboardData.items) {
  901. for (const item of clipboardData.items) {
  902. if (item.type.indexOf('image') !== -1) {
  903. const blob = item.getAsFile();
  904. const reader = new FileReader();
  905. reader.onload = function (e) {
  906. files = [
  907. ...files,
  908. {
  909. type: 'image',
  910. url: `${e.target.result}`
  911. }
  912. ];
  913. };
  914. reader.readAsDataURL(blob);
  915. } else if (item.type === 'text/plain') {
  916. if ($settings?.largeTextAsFile ?? false) {
  917. const text = clipboardData.getData('text/plain');
  918. if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
  919. e.preventDefault();
  920. const blob = new Blob([text], { type: 'text/plain' });
  921. const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
  922. type: 'text/plain'
  923. });
  924. await uploadFileHandler(file, true);
  925. }
  926. }
  927. }
  928. }
  929. }
  930. }}
  931. />
  932. {/if}
  933. </div>
  934. <div class=" flex justify-between mt-1.5 mb-2.5 mx-0.5 max-w-full">
  935. <div class="ml-1 self-end gap-0.5 flex items-center flex-1 max-w-[80%]">
  936. <InputMenu
  937. bind:selectedToolIds
  938. {screenCaptureHandler}
  939. {inputFilesHandler}
  940. uploadFilesHandler={() => {
  941. filesInputElement.click();
  942. }}
  943. uploadGoogleDriveHandler={async () => {
  944. try {
  945. const fileData = await createPicker();
  946. if (fileData) {
  947. const file = new File([fileData.blob], fileData.name, {
  948. type: fileData.blob.type
  949. });
  950. await uploadFileHandler(file);
  951. } else {
  952. console.log('No file was selected from Google Drive');
  953. }
  954. } catch (error) {
  955. console.error('Google Drive Error:', error);
  956. toast.error(
  957. $i18n.t('Error accessing Google Drive: {{error}}', {
  958. error: error.message
  959. })
  960. );
  961. }
  962. }}
  963. onClose={async () => {
  964. await tick();
  965. const chatInput = document.getElementById('chat-input');
  966. chatInput?.focus();
  967. }}
  968. >
  969. <button
  970. class="bg-transparent hover:bg-gray-100 text-gray-800 dark:text-white dark:hover:bg-gray-800 transition rounded-full p-1.5 outline-none focus:outline-none"
  971. type="button"
  972. aria-label="More"
  973. >
  974. <svg
  975. xmlns="http://www.w3.org/2000/svg"
  976. viewBox="0 0 20 20"
  977. fill="currentColor"
  978. class="size-5"
  979. >
  980. <path
  981. d="M10.75 4.75a.75.75 0 0 0-1.5 0v4.5h-4.5a.75.75 0 0 0 0 1.5h4.5v4.5a.75.75 0 0 0 1.5 0v-4.5h4.5a.75.75 0 0 0 0-1.5h-4.5v-4.5Z"
  982. />
  983. </svg>
  984. </button>
  985. </InputMenu>
  986. <div class="flex gap-0.5 items-center overflow-x-auto scrollbar-none flex-1">
  987. {#if $_user}
  988. {#if $config?.features?.enable_web_search && ($_user.role === 'admin' || $_user?.permissions?.features?.web_search)}
  989. <Tooltip content={$i18n.t('Search the internet')} placement="top">
  990. <button
  991. on:click|preventDefault={() => (webSearchEnabled = !webSearchEnabled)}
  992. type="button"
  993. class="px-1.5 @sm:px-2.5 py-1.5 flex gap-1.5 items-center text-sm rounded-full font-medium transition-colors duration-300 focus:outline-none max-w-full overflow-hidden {webSearchEnabled ||
  994. ($settings?.webSearch ?? false) === 'always'
  995. ? 'bg-blue-100 dark:bg-blue-500/20 text-blue-500 dark:text-blue-400'
  996. : 'bg-transparent text-gray-600 dark:text-gray-400 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800'}"
  997. >
  998. <GlobeAlt className="size-5" strokeWidth="1.75" />
  999. <span
  1000. class="hidden @sm:block whitespace-nowrap overflow-hidden text-ellipsis translate-y-[0.5px] mr-0.5"
  1001. >{$i18n.t('Web Search')}</span
  1002. >
  1003. </button>
  1004. </Tooltip>
  1005. {/if}
  1006. {#if $config?.features?.enable_image_generation && ($_user.role === 'admin' || $_user?.permissions?.features?.image_generation)}
  1007. <Tooltip content={$i18n.t('Generate an image')} placement="top">
  1008. <button
  1009. on:click|preventDefault={() =>
  1010. (imageGenerationEnabled = !imageGenerationEnabled)}
  1011. type="button"
  1012. class="px-1.5 @sm:px-2.5 py-1.5 flex gap-1.5 items-center text-sm rounded-full font-medium transition-colors duration-300 focus:outline-none max-w-full overflow-hidden {imageGenerationEnabled
  1013. ? 'bg-gray-100 dark:bg-gray-500/20 text-gray-600 dark:text-gray-400'
  1014. : 'bg-transparent text-gray-600 dark:text-gray-300 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 '}"
  1015. >
  1016. <Photo className="size-5" strokeWidth="1.75" />
  1017. <span
  1018. class="hidden @sm:block whitespace-nowrap overflow-hidden text-ellipsis translate-y-[0.5px] mr-0.5"
  1019. >{$i18n.t('Image')}</span
  1020. >
  1021. </button>
  1022. </Tooltip>
  1023. {/if}
  1024. {#if $_user.role === 'admin' || $_user?.permissions?.features?.code_interpreter}
  1025. <Tooltip content={$i18n.t('Execute code for analysis')} placement="top">
  1026. <button
  1027. on:click|preventDefault={() =>
  1028. (codeInterpreterEnabled = !codeInterpreterEnabled)}
  1029. type="button"
  1030. class="px-1.5 @sm:px-2.5 py-1.5 flex gap-1.5 items-center text-sm rounded-full font-medium transition-colors duration-300 focus:outline-none max-w-full overflow-hidden {codeInterpreterEnabled
  1031. ? 'bg-gray-100 dark:bg-gray-500/20 text-gray-600 dark:text-gray-400'
  1032. : 'bg-transparent text-gray-600 dark:text-gray-300 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 '}"
  1033. >
  1034. <CommandLine className="size-5" strokeWidth="1.75" />
  1035. <span
  1036. class="hidden @sm:block whitespace-nowrap overflow-hidden text-ellipsis translate-y-[0.5px] mr-0.5"
  1037. >{$i18n.t('Code Interpreter')}</span
  1038. >
  1039. </button>
  1040. </Tooltip>
  1041. {/if}
  1042. {/if}
  1043. </div>
  1044. </div>
  1045. <div class="self-end flex space-x-1 mr-1 flex-shrink-0">
  1046. {#if !history?.currentId || history.messages[history.currentId]?.done == true}
  1047. <Tooltip content={$i18n.t('Record voice')}>
  1048. <button
  1049. id="voice-input-button"
  1050. class=" text-gray-600 dark:text-gray-300 hover:text-gray-700 dark:hover:text-gray-200 transition rounded-full p-1.5 mr-0.5 self-center"
  1051. type="button"
  1052. on:click={async () => {
  1053. try {
  1054. let stream = await navigator.mediaDevices
  1055. .getUserMedia({ audio: true })
  1056. .catch(function (err) {
  1057. toast.error(
  1058. $i18n.t(
  1059. `Permission denied when accessing microphone: {{error}}`,
  1060. {
  1061. error: err
  1062. }
  1063. )
  1064. );
  1065. return null;
  1066. });
  1067. if (stream) {
  1068. recording = true;
  1069. const tracks = stream.getTracks();
  1070. tracks.forEach((track) => track.stop());
  1071. }
  1072. stream = null;
  1073. } catch {
  1074. toast.error($i18n.t('Permission denied when accessing microphone'));
  1075. }
  1076. }}
  1077. aria-label="Voice Input"
  1078. >
  1079. <svg
  1080. xmlns="http://www.w3.org/2000/svg"
  1081. viewBox="0 0 20 20"
  1082. fill="currentColor"
  1083. class="w-5 h-5 translate-y-[0.5px]"
  1084. >
  1085. <path d="M7 4a3 3 0 016 0v6a3 3 0 11-6 0V4z" />
  1086. <path
  1087. d="M5.5 9.643a.75.75 0 00-1.5 0V10c0 3.06 2.29 5.585 5.25 5.954V17.5h-1.5a.75.75 0 000 1.5h4.5a.75.75 0 000-1.5h-1.5v-1.546A6.001 6.001 0 0016 10v-.357a.75.75 0 00-1.5 0V10a4.5 4.5 0 01-9 0v-.357z"
  1088. />
  1089. </svg>
  1090. </button>
  1091. </Tooltip>
  1092. {/if}
  1093. {#if !history.currentId || history.messages[history.currentId]?.done == true}
  1094. {#if prompt === ''}
  1095. <div class=" flex items-center">
  1096. <Tooltip content={$i18n.t('Call')}>
  1097. <button
  1098. class=" {webSearchEnabled ||
  1099. ($settings?.webSearch ?? false) === 'always'
  1100. ? 'bg-blue-500 text-white hover:bg-blue-400 '
  1101. : 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100'} transition rounded-full p-1.5 self-center"
  1102. type="button"
  1103. on:click={async () => {
  1104. if (selectedModels.length > 1) {
  1105. toast.error($i18n.t('Select only one model to call'));
  1106. return;
  1107. }
  1108. if ($config.audio.stt.engine === 'web') {
  1109. toast.error(
  1110. $i18n.t(
  1111. 'Call feature is not supported when using Web STT engine'
  1112. )
  1113. );
  1114. return;
  1115. }
  1116. // check if user has access to getUserMedia
  1117. try {
  1118. let stream = await navigator.mediaDevices.getUserMedia({
  1119. audio: true
  1120. });
  1121. // If the user grants the permission, proceed to show the call overlay
  1122. if (stream) {
  1123. const tracks = stream.getTracks();
  1124. tracks.forEach((track) => track.stop());
  1125. }
  1126. stream = null;
  1127. showCallOverlay.set(true);
  1128. showControls.set(true);
  1129. } catch (err) {
  1130. // If the user denies the permission or an error occurs, show an error message
  1131. toast.error(
  1132. $i18n.t('Permission denied when accessing media devices')
  1133. );
  1134. }
  1135. }}
  1136. aria-label="Call"
  1137. >
  1138. <Headphone className="size-5" />
  1139. </button>
  1140. </Tooltip>
  1141. </div>
  1142. {:else}
  1143. <div class=" flex items-center">
  1144. <Tooltip content={$i18n.t('Send message')}>
  1145. <button
  1146. id="send-message-button"
  1147. class="{prompt !== ''
  1148. ? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
  1149. ? 'bg-blue-500 text-white hover:bg-blue-400 '
  1150. : 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100 '
  1151. : 'text-white bg-gray-200 dark:text-gray-900 dark:bg-gray-700 disabled'} transition rounded-full p-1.5 self-center"
  1152. type="submit"
  1153. disabled={prompt === ''}
  1154. >
  1155. <svg
  1156. xmlns="http://www.w3.org/2000/svg"
  1157. viewBox="0 0 16 16"
  1158. fill="currentColor"
  1159. class="size-5"
  1160. >
  1161. <path
  1162. fill-rule="evenodd"
  1163. d="M8 14a.75.75 0 0 1-.75-.75V4.56L4.03 7.78a.75.75 0 0 1-1.06-1.06l4.5-4.5a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1-1.06 1.06L8.75 4.56v8.69A.75.75 0 0 1 8 14Z"
  1164. clip-rule="evenodd"
  1165. />
  1166. </svg>
  1167. </button>
  1168. </Tooltip>
  1169. </div>
  1170. {/if}
  1171. {:else}
  1172. <div class=" flex items-center">
  1173. <Tooltip content={$i18n.t('Stop')}>
  1174. <button
  1175. class="bg-white hover:bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-800 transition rounded-full p-1.5"
  1176. on:click={() => {
  1177. stopResponse();
  1178. }}
  1179. >
  1180. <svg
  1181. xmlns="http://www.w3.org/2000/svg"
  1182. viewBox="0 0 24 24"
  1183. fill="currentColor"
  1184. class="size-5"
  1185. >
  1186. <path
  1187. fill-rule="evenodd"
  1188. d="M2.25 12c0-5.385 4.365-9.75 9.75-9.75s9.75 4.365 9.75 9.75-4.365 9.75-9.75 9.75S2.25 17.385 2.25 12zm6-2.438c0-.724.588-1.312 1.313-1.312h4.874c.725 0 1.313.588 1.313 1.313v4.874c0 .725-.588 1.313-1.313 1.313H9.564a1.312 1.312 0 01-1.313-1.313V9.564z"
  1189. clip-rule="evenodd"
  1190. />
  1191. </svg>
  1192. </button>
  1193. </Tooltip>
  1194. </div>
  1195. {/if}
  1196. </div>
  1197. </div>
  1198. </div>
  1199. </form>
  1200. {/if}
  1201. </div>
  1202. </div>
  1203. </div>
  1204. </div>
  1205. {/if}