MessageInput.svelte 46 KB

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