MessageInput.svelte 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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 || 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 imageGenerationEnabled}
  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-teal-400 opacity-75"
  370. />
  371. <span class="relative inline-flex rounded-full size-2 bg-teal-500" />
  372. </span>
  373. </div>
  374. <div class=" translate-y-[0.5px]">{$i18n.t('Image generation')}</div>
  375. </div>
  376. </div>
  377. {/if}
  378. {#if codeInterpreterEnabled}
  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-blue-400 opacity-75"
  385. />
  386. <span class="relative inline-flex rounded-full size-2 bg-blue-500" />
  387. </span>
  388. </div>
  389. <div class=" translate-y-[0.5px]">{$i18n.t('Code interpreter')}</div>
  390. </div>
  391. </div>
  392. {/if}
  393. {#if atSelectedModel !== undefined}
  394. <div class="flex items-center justify-between w-full">
  395. <div class="pl-[1px] flex items-center gap-2 text-sm dark:text-gray-500">
  396. <img
  397. crossorigin="anonymous"
  398. alt="model profile"
  399. class="size-3.5 max-w-[28px] object-cover rounded-full"
  400. src={$models.find((model) => model.id === atSelectedModel.id)?.info?.meta
  401. ?.profile_image_url ??
  402. ($i18n.language === 'dg-DG'
  403. ? `/doge.png`
  404. : `${WEBUI_BASE_URL}/static/favicon.png`)}
  405. />
  406. <div class="translate-y-[0.5px]">
  407. Talking to <span class=" font-medium">{atSelectedModel.name}</span>
  408. </div>
  409. </div>
  410. <div>
  411. <button
  412. class="flex items-center dark:text-gray-500"
  413. on:click={() => {
  414. atSelectedModel = undefined;
  415. }}
  416. >
  417. <XMark />
  418. </button>
  419. </div>
  420. </div>
  421. {/if}
  422. </div>
  423. {/if}
  424. <Commands
  425. bind:this={commandsElement}
  426. bind:prompt
  427. bind:files
  428. on:upload={(e) => {
  429. dispatch('upload', e.detail);
  430. }}
  431. on:select={(e) => {
  432. const data = e.detail;
  433. if (data?.type === 'model') {
  434. atSelectedModel = data.data;
  435. }
  436. const chatInputElement = document.getElementById('chat-input');
  437. chatInputElement?.focus();
  438. }}
  439. />
  440. </div>
  441. </div>
  442. </div>
  443. <div class="{transparentBackground ? 'bg-transparent' : 'bg-white dark:bg-gray-900'} ">
  444. <div
  445. class="{($settings?.widescreenMode ?? null)
  446. ? 'max-w-full'
  447. : 'max-w-6xl'} px-2.5 mx-auto inset-x-0"
  448. >
  449. <div class="">
  450. <input
  451. bind:this={filesInputElement}
  452. bind:files={inputFiles}
  453. type="file"
  454. hidden
  455. multiple
  456. on:change={async () => {
  457. if (inputFiles && inputFiles.length > 0) {
  458. const _inputFiles = Array.from(inputFiles);
  459. inputFilesHandler(_inputFiles);
  460. } else {
  461. toast.error($i18n.t(`File not found.`));
  462. }
  463. filesInputElement.value = '';
  464. }}
  465. />
  466. {#if recording}
  467. <VoiceRecording
  468. bind:recording
  469. on:cancel={async () => {
  470. recording = false;
  471. await tick();
  472. document.getElementById('chat-input')?.focus();
  473. }}
  474. on:confirm={async (e) => {
  475. const { text, filename } = e.detail;
  476. prompt = `${prompt}${text} `;
  477. recording = false;
  478. await tick();
  479. document.getElementById('chat-input')?.focus();
  480. if ($settings?.speechAutoSend ?? false) {
  481. dispatch('submit', prompt);
  482. }
  483. }}
  484. />
  485. {:else}
  486. <form
  487. class="w-full flex gap-1.5"
  488. on:submit|preventDefault={() => {
  489. // check if selectedModels support image input
  490. dispatch('submit', prompt);
  491. }}
  492. >
  493. <div
  494. 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"
  495. dir={$settings?.chatDirection ?? 'LTR'}
  496. >
  497. {#if files.length > 0}
  498. <div class="mx-2 mt-2.5 flex items-center flex-wrap gap-2">
  499. {#each files as file, fileIdx}
  500. {#if file.type === 'image'}
  501. <div class=" relative group">
  502. <div class="relative flex items-center">
  503. <Image
  504. src={file.url}
  505. alt="input"
  506. imageClassName=" size-14 rounded-xl object-cover"
  507. />
  508. {#if atSelectedModel ? visionCapableModels.length === 0 : selectedModels.length !== visionCapableModels.length}
  509. <Tooltip
  510. className=" absolute top-1 left-1"
  511. content={$i18n.t('{{ models }}', {
  512. models: [
  513. ...(atSelectedModel ? [atSelectedModel] : selectedModels)
  514. ]
  515. .filter((id) => !visionCapableModels.includes(id))
  516. .join(', ')
  517. })}
  518. >
  519. <svg
  520. xmlns="http://www.w3.org/2000/svg"
  521. viewBox="0 0 24 24"
  522. fill="currentColor"
  523. class="size-4 fill-yellow-300"
  524. >
  525. <path
  526. fill-rule="evenodd"
  527. 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"
  528. clip-rule="evenodd"
  529. />
  530. </svg>
  531. </Tooltip>
  532. {/if}
  533. </div>
  534. <div class=" absolute -top-1 -right-1">
  535. <button
  536. class=" bg-white text-black border border-white rounded-full group-hover:visible invisible transition"
  537. type="button"
  538. on:click={() => {
  539. files.splice(fileIdx, 1);
  540. files = files;
  541. }}
  542. >
  543. <svg
  544. xmlns="http://www.w3.org/2000/svg"
  545. viewBox="0 0 20 20"
  546. fill="currentColor"
  547. class="w-4 h-4"
  548. >
  549. <path
  550. 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"
  551. />
  552. </svg>
  553. </button>
  554. </div>
  555. </div>
  556. {:else}
  557. <FileItem
  558. item={file}
  559. name={file.name}
  560. type={file.type}
  561. size={file?.size}
  562. loading={file.status === 'uploading'}
  563. dismissible={true}
  564. edit={true}
  565. on:dismiss={async () => {
  566. if (file.type !== 'collection' && !file?.collection) {
  567. if (file.id) {
  568. // This will handle both file deletion and Chroma cleanup
  569. await deleteFileById(localStorage.token, file.id);
  570. }
  571. }
  572. // Remove from UI state
  573. files.splice(fileIdx, 1);
  574. files = files;
  575. }}
  576. on:click={() => {
  577. console.log(file);
  578. }}
  579. />
  580. {/if}
  581. {/each}
  582. </div>
  583. {/if}
  584. <div class="px-2.5">
  585. {#if $settings?.richTextInput ?? true}
  586. <div
  587. class="scrollbar-hidden text-left bg-transparent dark:text-gray-100 outline-none w-full pt-2.5 pb-1 px-1 rounded-xl resize-none h-fit max-h-80 overflow-auto"
  588. >
  589. <RichTextInput
  590. bind:this={chatInputElement}
  591. bind:value={prompt}
  592. id="chat-input"
  593. messageInput={true}
  594. shiftEnter={!$mobile ||
  595. !(
  596. 'ontouchstart' in window ||
  597. navigator.maxTouchPoints > 0 ||
  598. navigator.msMaxTouchPoints > 0
  599. )}
  600. placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
  601. largeTextAsFile={$settings?.largeTextAsFile ?? false}
  602. autocomplete={true}
  603. generateAutoCompletion={async (text) => {
  604. if (selectedModelIds.length === 0 || !selectedModelIds.at(0)) {
  605. toast.error($i18n.t('Please select a model first.'));
  606. }
  607. const res = await generateAutoCompletion(
  608. localStorage.token,
  609. selectedModelIds.at(0),
  610. text,
  611. history?.currentId
  612. ? createMessagesList(history, history.currentId)
  613. : null
  614. ).catch((error) => {
  615. console.log(error);
  616. return null;
  617. });
  618. console.log(res);
  619. return res;
  620. }}
  621. on:keydown={async (e) => {
  622. e = e.detail.event;
  623. const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
  624. const commandsContainerElement =
  625. document.getElementById('commands-container');
  626. if (e.key === 'Escape') {
  627. stopResponse();
  628. }
  629. // Command/Ctrl + Shift + Enter to submit a message pair
  630. if (isCtrlPressed && e.key === 'Enter' && e.shiftKey) {
  631. e.preventDefault();
  632. createMessagePair(prompt);
  633. }
  634. // Check if Ctrl + R is pressed
  635. if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') {
  636. e.preventDefault();
  637. console.log('regenerate');
  638. const regenerateButton = [
  639. ...document.getElementsByClassName('regenerate-response-button')
  640. ]?.at(-1);
  641. regenerateButton?.click();
  642. }
  643. if (prompt === '' && e.key == 'ArrowUp') {
  644. e.preventDefault();
  645. const userMessageElement = [
  646. ...document.getElementsByClassName('user-message')
  647. ]?.at(-1);
  648. if (userMessageElement) {
  649. userMessageElement.scrollIntoView({ block: 'center' });
  650. const editButton = [
  651. ...document.getElementsByClassName('edit-user-message-button')
  652. ]?.at(-1);
  653. editButton?.click();
  654. }
  655. }
  656. if (commandsContainerElement) {
  657. if (commandsContainerElement && e.key === 'ArrowUp') {
  658. e.preventDefault();
  659. commandsElement.selectUp();
  660. const commandOptionButton = [
  661. ...document.getElementsByClassName('selected-command-option-button')
  662. ]?.at(-1);
  663. commandOptionButton.scrollIntoView({ block: 'center' });
  664. }
  665. if (commandsContainerElement && e.key === 'ArrowDown') {
  666. e.preventDefault();
  667. commandsElement.selectDown();
  668. const commandOptionButton = [
  669. ...document.getElementsByClassName('selected-command-option-button')
  670. ]?.at(-1);
  671. commandOptionButton.scrollIntoView({ block: 'center' });
  672. }
  673. if (commandsContainerElement && e.key === 'Tab') {
  674. e.preventDefault();
  675. const commandOptionButton = [
  676. ...document.getElementsByClassName('selected-command-option-button')
  677. ]?.at(-1);
  678. commandOptionButton?.click();
  679. }
  680. if (commandsContainerElement && e.key === 'Enter') {
  681. e.preventDefault();
  682. const commandOptionButton = [
  683. ...document.getElementsByClassName('selected-command-option-button')
  684. ]?.at(-1);
  685. if (commandOptionButton) {
  686. commandOptionButton?.click();
  687. } else {
  688. document.getElementById('send-message-button')?.click();
  689. }
  690. }
  691. } else {
  692. if (
  693. !$mobile ||
  694. !(
  695. 'ontouchstart' in window ||
  696. navigator.maxTouchPoints > 0 ||
  697. navigator.msMaxTouchPoints > 0
  698. )
  699. ) {
  700. // Prevent Enter key from creating a new line
  701. // Uses keyCode '13' for Enter key for chinese/japanese keyboards
  702. if (e.keyCode === 13 && !e.shiftKey) {
  703. e.preventDefault();
  704. }
  705. // Submit the prompt when Enter key is pressed
  706. if (prompt !== '' && e.keyCode === 13 && !e.shiftKey) {
  707. dispatch('submit', prompt);
  708. }
  709. }
  710. }
  711. if (e.key === 'Escape') {
  712. console.log('Escape');
  713. atSelectedModel = undefined;
  714. selectedToolIds = [];
  715. webSearchEnabled = false;
  716. imageGenerationEnabled = false;
  717. }
  718. }}
  719. on:paste={async (e) => {
  720. e = e.detail.event;
  721. console.log(e);
  722. const clipboardData = e.clipboardData || window.clipboardData;
  723. if (clipboardData && clipboardData.items) {
  724. for (const item of clipboardData.items) {
  725. if (item.type.indexOf('image') !== -1) {
  726. const blob = item.getAsFile();
  727. const reader = new FileReader();
  728. reader.onload = function (e) {
  729. files = [
  730. ...files,
  731. {
  732. type: 'image',
  733. url: `${e.target.result}`
  734. }
  735. ];
  736. };
  737. reader.readAsDataURL(blob);
  738. } else if (item.type === 'text/plain') {
  739. if ($settings?.largeTextAsFile ?? false) {
  740. const text = clipboardData.getData('text/plain');
  741. if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
  742. e.preventDefault();
  743. const blob = new Blob([text], { type: 'text/plain' });
  744. const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
  745. type: 'text/plain'
  746. });
  747. await uploadFileHandler(file, true);
  748. }
  749. }
  750. }
  751. }
  752. }
  753. }}
  754. />
  755. </div>
  756. {:else}
  757. <textarea
  758. id="chat-input"
  759. bind:this={chatInputElement}
  760. class="scrollbar-hidden bg-transparent dark:text-gray-100 outline-none w-full pt-3 pb-1 px-1 rounded-xl resize-none"
  761. placeholder={placeholder ? placeholder : $i18n.t('Send a Message')}
  762. bind:value={prompt}
  763. on:keypress={(e) => {
  764. if (
  765. !$mobile ||
  766. !(
  767. 'ontouchstart' in window ||
  768. navigator.maxTouchPoints > 0 ||
  769. navigator.msMaxTouchPoints > 0
  770. )
  771. ) {
  772. // Prevent Enter key from creating a new line
  773. if (e.key === 'Enter' && !e.shiftKey) {
  774. e.preventDefault();
  775. }
  776. // Submit the prompt when Enter key is pressed
  777. if (prompt !== '' && e.key === 'Enter' && !e.shiftKey) {
  778. dispatch('submit', prompt);
  779. }
  780. }
  781. }}
  782. on:keydown={async (e) => {
  783. const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
  784. const commandsContainerElement =
  785. document.getElementById('commands-container');
  786. if (e.key === 'Escape') {
  787. stopResponse();
  788. }
  789. // Command/Ctrl + Shift + Enter to submit a message pair
  790. if (isCtrlPressed && e.key === 'Enter' && e.shiftKey) {
  791. e.preventDefault();
  792. createMessagePair(prompt);
  793. }
  794. // Check if Ctrl + R is pressed
  795. if (prompt === '' && isCtrlPressed && e.key.toLowerCase() === 'r') {
  796. e.preventDefault();
  797. console.log('regenerate');
  798. const regenerateButton = [
  799. ...document.getElementsByClassName('regenerate-response-button')
  800. ]?.at(-1);
  801. regenerateButton?.click();
  802. }
  803. if (prompt === '' && e.key == 'ArrowUp') {
  804. e.preventDefault();
  805. const userMessageElement = [
  806. ...document.getElementsByClassName('user-message')
  807. ]?.at(-1);
  808. const editButton = [
  809. ...document.getElementsByClassName('edit-user-message-button')
  810. ]?.at(-1);
  811. console.log(userMessageElement);
  812. userMessageElement.scrollIntoView({ block: 'center' });
  813. editButton?.click();
  814. }
  815. if (commandsContainerElement && e.key === 'ArrowUp') {
  816. e.preventDefault();
  817. commandsElement.selectUp();
  818. const commandOptionButton = [
  819. ...document.getElementsByClassName('selected-command-option-button')
  820. ]?.at(-1);
  821. commandOptionButton.scrollIntoView({ block: 'center' });
  822. }
  823. if (commandsContainerElement && e.key === 'ArrowDown') {
  824. e.preventDefault();
  825. commandsElement.selectDown();
  826. const commandOptionButton = [
  827. ...document.getElementsByClassName('selected-command-option-button')
  828. ]?.at(-1);
  829. commandOptionButton.scrollIntoView({ block: 'center' });
  830. }
  831. if (commandsContainerElement && e.key === 'Enter') {
  832. e.preventDefault();
  833. const commandOptionButton = [
  834. ...document.getElementsByClassName('selected-command-option-button')
  835. ]?.at(-1);
  836. if (e.shiftKey) {
  837. prompt = `${prompt}\n`;
  838. } else if (commandOptionButton) {
  839. commandOptionButton?.click();
  840. } else {
  841. document.getElementById('send-message-button')?.click();
  842. }
  843. }
  844. if (commandsContainerElement && e.key === 'Tab') {
  845. e.preventDefault();
  846. const commandOptionButton = [
  847. ...document.getElementsByClassName('selected-command-option-button')
  848. ]?.at(-1);
  849. commandOptionButton?.click();
  850. } else if (e.key === 'Tab') {
  851. const words = findWordIndices(prompt);
  852. if (words.length > 0) {
  853. const word = words.at(0);
  854. const fullPrompt = prompt;
  855. prompt = prompt.substring(0, word?.endIndex + 1);
  856. await tick();
  857. e.target.scrollTop = e.target.scrollHeight;
  858. prompt = fullPrompt;
  859. await tick();
  860. e.preventDefault();
  861. e.target.setSelectionRange(word?.startIndex, word.endIndex + 1);
  862. }
  863. e.target.style.height = '';
  864. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  865. }
  866. if (e.key === 'Escape') {
  867. console.log('Escape');
  868. atSelectedModel = undefined;
  869. selectedToolIds = [];
  870. webSearchEnabled = false;
  871. imageGenerationEnabled = false;
  872. }
  873. }}
  874. rows="1"
  875. on:input={async (e) => {
  876. e.target.style.height = '';
  877. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  878. }}
  879. on:focus={async (e) => {
  880. e.target.style.height = '';
  881. e.target.style.height = Math.min(e.target.scrollHeight, 320) + 'px';
  882. }}
  883. on:paste={async (e) => {
  884. const clipboardData = e.clipboardData || window.clipboardData;
  885. if (clipboardData && clipboardData.items) {
  886. for (const item of clipboardData.items) {
  887. if (item.type.indexOf('image') !== -1) {
  888. const blob = item.getAsFile();
  889. const reader = new FileReader();
  890. reader.onload = function (e) {
  891. files = [
  892. ...files,
  893. {
  894. type: 'image',
  895. url: `${e.target.result}`
  896. }
  897. ];
  898. };
  899. reader.readAsDataURL(blob);
  900. } else if (item.type === 'text/plain') {
  901. if ($settings?.largeTextAsFile ?? false) {
  902. const text = clipboardData.getData('text/plain');
  903. if (text.length > PASTED_TEXT_CHARACTER_LIMIT) {
  904. e.preventDefault();
  905. const blob = new Blob([text], { type: 'text/plain' });
  906. const file = new File([blob], `Pasted_Text_${Date.now()}.txt`, {
  907. type: 'text/plain'
  908. });
  909. await uploadFileHandler(file, true);
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }}
  916. />
  917. {/if}
  918. </div>
  919. <div class=" flex justify-between mb-2">
  920. <div class="ml-1 self-end gap-0.5 flex items-center">
  921. <InputMenu
  922. bind:selectedToolIds
  923. {screenCaptureHandler}
  924. {inputFilesHandler}
  925. uploadFilesHandler={() => {
  926. filesInputElement.click();
  927. }}
  928. uploadGoogleDriveHandler={async () => {
  929. try {
  930. const fileData = await createPicker();
  931. if (fileData) {
  932. const file = new File([fileData.blob], fileData.name, {
  933. type: fileData.blob.type
  934. });
  935. await uploadFileHandler(file);
  936. } else {
  937. console.log('No file was selected from Google Drive');
  938. }
  939. } catch (error) {
  940. console.error('Google Drive Error:', error);
  941. toast.error(
  942. $i18n.t('Error accessing Google Drive: {{error}}', {
  943. error: error.message
  944. })
  945. );
  946. }
  947. }}
  948. onClose={async () => {
  949. await tick();
  950. const chatInput = document.getElementById('chat-input');
  951. chatInput?.focus();
  952. }}
  953. >
  954. <button
  955. 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"
  956. type="button"
  957. aria-label="More"
  958. >
  959. <svg
  960. xmlns="http://www.w3.org/2000/svg"
  961. viewBox="0 0 20 20"
  962. fill="currentColor"
  963. class="size-5"
  964. >
  965. <path
  966. 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"
  967. />
  968. </svg>
  969. </button>
  970. </InputMenu>
  971. {#if $_user}
  972. {#if $config?.features?.enable_web_search && ($_user.role === 'admin' || $_user?.permissions?.features?.web_search)}
  973. <Tooltip content={$i18n.t('Search the internet')} placement="top">
  974. <button
  975. on:click|preventDefault={() => (webSearchEnabled = !webSearchEnabled)}
  976. type="button"
  977. 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
  978. ? 'bg-blue-100 dark:bg-blue-500/20 text-blue-500 dark:text-blue-400'
  979. : 'bg-transparent text-gray-600 dark:text-gray-400 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800'}"
  980. >
  981. <GlobeAlt className="size-5" strokeWidth="1.75" />
  982. <span
  983. class="hidden sm:block whitespace-nowrap overflow-hidden text-ellipsis translate-y-[0.5px] mr-0.5"
  984. >{$i18n.t('Web Search')}</span
  985. >
  986. </button>
  987. </Tooltip>
  988. {/if}
  989. {#if $config?.features?.enable_image_generation && ($_user.role === 'admin' || $_user?.permissions?.features?.image_generation)}
  990. <Tooltip content={$i18n.t('Generate an image')} placement="top">
  991. <button
  992. on:click|preventDefault={() =>
  993. (imageGenerationEnabled = !imageGenerationEnabled)}
  994. type="button"
  995. 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
  996. ? 'bg-gray-100 dark:bg-gray-500/20 text-gray-600 dark:text-gray-400'
  997. : 'bg-transparent text-gray-600 dark:text-gray-300 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 '}"
  998. >
  999. <Photo className="size-5" strokeWidth="1.75" />
  1000. <span
  1001. class="hidden sm:block whitespace-nowrap overflow-hidden text-ellipsis translate-y-[0.5px] mr-0.5"
  1002. >{$i18n.t('Image')}</span
  1003. >
  1004. </button>
  1005. </Tooltip>
  1006. {/if}
  1007. <Tooltip content={$i18n.t('Executes code for analysis')} placement="top">
  1008. <button
  1009. on:click|preventDefault={() =>
  1010. (codeInterpreterEnabled = !codeInterpreterEnabled)}
  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 {codeInterpreterEnabled
  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. <CommandLine 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('Code Intepreter')}</span
  1020. >
  1021. </button>
  1022. </Tooltip>
  1023. {/if}
  1024. </div>
  1025. <div class="self-end flex space-x-1 mr-1">
  1026. {#if !history?.currentId || history.messages[history.currentId]?.done == true}
  1027. <Tooltip content={$i18n.t('Record voice')}>
  1028. <button
  1029. id="voice-input-button"
  1030. 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"
  1031. type="button"
  1032. on:click={async () => {
  1033. try {
  1034. let stream = await navigator.mediaDevices
  1035. .getUserMedia({ audio: true })
  1036. .catch(function (err) {
  1037. toast.error(
  1038. $i18n.t(
  1039. `Permission denied when accessing microphone: {{error}}`,
  1040. {
  1041. error: err
  1042. }
  1043. )
  1044. );
  1045. return null;
  1046. });
  1047. if (stream) {
  1048. recording = true;
  1049. const tracks = stream.getTracks();
  1050. tracks.forEach((track) => track.stop());
  1051. }
  1052. stream = null;
  1053. } catch {
  1054. toast.error($i18n.t('Permission denied when accessing microphone'));
  1055. }
  1056. }}
  1057. aria-label="Voice Input"
  1058. >
  1059. <svg
  1060. xmlns="http://www.w3.org/2000/svg"
  1061. viewBox="0 0 20 20"
  1062. fill="currentColor"
  1063. class="w-5 h-5 translate-y-[0.5px]"
  1064. >
  1065. <path d="M7 4a3 3 0 016 0v6a3 3 0 11-6 0V4z" />
  1066. <path
  1067. 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"
  1068. />
  1069. </svg>
  1070. </button>
  1071. </Tooltip>
  1072. {/if}
  1073. {#if !history.currentId || history.messages[history.currentId]?.done == true}
  1074. {#if prompt === ''}
  1075. <div class=" flex items-center">
  1076. <Tooltip content={$i18n.t('Call')}>
  1077. <button
  1078. class=" {webSearchEnabled
  1079. ? 'bg-blue-500 text-white hover:bg-blue-400 '
  1080. : '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"
  1081. type="button"
  1082. on:click={async () => {
  1083. if (selectedModels.length > 1) {
  1084. toast.error($i18n.t('Select only one model to call'));
  1085. return;
  1086. }
  1087. if ($config.audio.stt.engine === 'web') {
  1088. toast.error(
  1089. $i18n.t(
  1090. 'Call feature is not supported when using Web STT engine'
  1091. )
  1092. );
  1093. return;
  1094. }
  1095. // check if user has access to getUserMedia
  1096. try {
  1097. let stream = await navigator.mediaDevices.getUserMedia({
  1098. audio: true
  1099. });
  1100. // If the user grants the permission, proceed to show the call overlay
  1101. if (stream) {
  1102. const tracks = stream.getTracks();
  1103. tracks.forEach((track) => track.stop());
  1104. }
  1105. stream = null;
  1106. showCallOverlay.set(true);
  1107. showControls.set(true);
  1108. } catch (err) {
  1109. // If the user denies the permission or an error occurs, show an error message
  1110. toast.error(
  1111. $i18n.t('Permission denied when accessing media devices')
  1112. );
  1113. }
  1114. }}
  1115. aria-label="Call"
  1116. >
  1117. <Headphone className="size-5" />
  1118. </button>
  1119. </Tooltip>
  1120. </div>
  1121. {:else}
  1122. <div class=" flex items-center">
  1123. <Tooltip content={$i18n.t('Send message')}>
  1124. <button
  1125. id="send-message-button"
  1126. class="{prompt !== ''
  1127. ? webSearchEnabled
  1128. ? 'bg-blue-500 text-white hover:bg-blue-400 '
  1129. : 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100 '
  1130. : 'text-white bg-gray-200 dark:text-gray-900 dark:bg-gray-700 disabled'} transition rounded-full p-1.5 self-center"
  1131. type="submit"
  1132. disabled={prompt === ''}
  1133. >
  1134. <svg
  1135. xmlns="http://www.w3.org/2000/svg"
  1136. viewBox="0 0 16 16"
  1137. fill="currentColor"
  1138. class="size-5"
  1139. >
  1140. <path
  1141. fill-rule="evenodd"
  1142. 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"
  1143. clip-rule="evenodd"
  1144. />
  1145. </svg>
  1146. </button>
  1147. </Tooltip>
  1148. </div>
  1149. {/if}
  1150. {:else}
  1151. <div class=" flex items-center">
  1152. <Tooltip content={$i18n.t('Stop')}>
  1153. <button
  1154. 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"
  1155. on:click={() => {
  1156. stopResponse();
  1157. }}
  1158. >
  1159. <svg
  1160. xmlns="http://www.w3.org/2000/svg"
  1161. viewBox="0 0 24 24"
  1162. fill="currentColor"
  1163. class="size-6"
  1164. >
  1165. <path
  1166. fill-rule="evenodd"
  1167. 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"
  1168. clip-rule="evenodd"
  1169. />
  1170. </svg>
  1171. </button>
  1172. </Tooltip>
  1173. </div>
  1174. {/if}
  1175. </div>
  1176. </div>
  1177. </div>
  1178. </form>
  1179. {/if}
  1180. </div>
  1181. </div>
  1182. </div>
  1183. </div>
  1184. {/if}