2024-02-05 09:58:54 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { getBackendConfig } from '$lib/apis';
|
|
|
|
import { setDefaultPromptSuggestions } from '$lib/apis/configs';
|
2024-03-26 07:59:57 +00:00
|
|
|
import { config, models, settings, user } from '$lib/stores';
|
2024-03-01 04:40:36 +00:00
|
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
2024-03-01 09:18:07 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2024-05-12 09:47:23 +00:00
|
|
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
2024-06-16 22:32:26 +00:00
|
|
|
import { updateUserInfo } from '$lib/apis/users';
|
|
|
|
import { getUserPosition } from '$lib/utils';
|
2024-02-05 09:58:54 +00:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-03-01 04:40:36 +00:00
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
2024-02-06 05:05:38 +00:00
|
|
|
export let saveSettings: Function;
|
|
|
|
|
|
|
|
// Addons
|
|
|
|
let titleAutoGenerate = true;
|
|
|
|
let responseAutoCopy = false;
|
2024-06-04 18:48:46 +00:00
|
|
|
let widescreenMode = false;
|
2024-04-21 09:45:07 +00:00
|
|
|
let splitLargeChunks = false;
|
2024-06-16 22:32:26 +00:00
|
|
|
let userLocation = false;
|
2024-02-06 05:05:38 +00:00
|
|
|
|
2024-02-05 09:58:54 +00:00
|
|
|
// Interface
|
2024-06-05 16:14:15 +00:00
|
|
|
let defaultModelId = '';
|
2024-02-06 10:22:34 +00:00
|
|
|
let showUsername = false;
|
2024-06-13 04:18:53 +00:00
|
|
|
|
2024-05-15 22:39:41 +00:00
|
|
|
let chatBubble = true;
|
2024-05-16 20:22:30 +00:00
|
|
|
let chatDirection: 'LTR' | 'RTL' = 'LTR';
|
2024-02-06 10:22:34 +00:00
|
|
|
|
2024-06-13 04:18:53 +00:00
|
|
|
let showEmojiInCall = false;
|
|
|
|
|
2024-04-21 09:45:07 +00:00
|
|
|
const toggleSplitLargeChunks = async () => {
|
|
|
|
splitLargeChunks = !splitLargeChunks;
|
|
|
|
saveSettings({ splitLargeChunks: splitLargeChunks });
|
|
|
|
};
|
|
|
|
|
2024-06-04 18:48:46 +00:00
|
|
|
const togglewidescreenMode = async () => {
|
|
|
|
widescreenMode = !widescreenMode;
|
|
|
|
saveSettings({ widescreenMode: widescreenMode });
|
2024-02-15 08:34:55 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 22:39:41 +00:00
|
|
|
const toggleChatBubble = async () => {
|
|
|
|
chatBubble = !chatBubble;
|
|
|
|
saveSettings({ chatBubble: chatBubble });
|
|
|
|
};
|
|
|
|
|
2024-02-06 10:22:34 +00:00
|
|
|
const toggleShowUsername = async () => {
|
|
|
|
showUsername = !showUsername;
|
|
|
|
saveSettings({ showUsername: showUsername });
|
|
|
|
};
|
|
|
|
|
2024-06-13 04:18:53 +00:00
|
|
|
const toggleEmojiInCall = async () => {
|
|
|
|
showEmojiInCall = !showEmojiInCall;
|
|
|
|
saveSettings({ showEmojiInCall: showEmojiInCall });
|
|
|
|
};
|
|
|
|
|
2024-06-16 22:32:26 +00:00
|
|
|
const toggleUserLocation = async () => {
|
|
|
|
userLocation = !userLocation;
|
|
|
|
|
|
|
|
if (userLocation) {
|
|
|
|
const position = await getUserPosition().catch((error) => {
|
|
|
|
toast.error(error.message);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (position) {
|
|
|
|
await updateUserInfo(localStorage.token, { location: position });
|
|
|
|
toast.success('User location successfully retrieved.');
|
|
|
|
} else {
|
|
|
|
userLocation = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSettings({ userLocation });
|
|
|
|
};
|
|
|
|
|
2024-02-06 05:05:38 +00:00
|
|
|
const toggleTitleAutoGenerate = async () => {
|
|
|
|
titleAutoGenerate = !titleAutoGenerate;
|
2024-03-26 07:59:57 +00:00
|
|
|
saveSettings({
|
|
|
|
title: {
|
|
|
|
...$settings.title,
|
|
|
|
auto: titleAutoGenerate
|
|
|
|
}
|
|
|
|
});
|
2024-02-06 05:05:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const toggleResponseAutoCopy = async () => {
|
|
|
|
const permission = await navigator.clipboard
|
|
|
|
.readText()
|
|
|
|
.then(() => {
|
|
|
|
return 'granted';
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
return '';
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(permission);
|
|
|
|
|
|
|
|
if (permission === 'granted') {
|
|
|
|
responseAutoCopy = !responseAutoCopy;
|
|
|
|
saveSettings({ responseAutoCopy: responseAutoCopy });
|
|
|
|
} else {
|
|
|
|
toast.error(
|
|
|
|
'Clipboard write permission denied. Please check your browser settings to grant the necessary access.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-16 20:22:30 +00:00
|
|
|
const toggleChangeChatDirection = async () => {
|
|
|
|
chatDirection = chatDirection === 'LTR' ? 'RTL' : 'LTR';
|
2024-05-18 22:02:47 +00:00
|
|
|
saveSettings({ chatDirection });
|
2024-05-16 20:22:30 +00:00
|
|
|
};
|
|
|
|
|
2024-02-05 09:58:54 +00:00
|
|
|
const updateInterfaceHandler = async () => {
|
2024-02-21 20:51:52 +00:00
|
|
|
saveSettings({
|
2024-06-05 16:14:15 +00:00
|
|
|
models: [defaultModelId]
|
2024-02-21 20:51:52 +00:00
|
|
|
});
|
2024-02-05 09:58:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
onMount(async () => {
|
2024-05-27 05:47:42 +00:00
|
|
|
titleAutoGenerate = $settings?.title?.auto ?? true;
|
2024-06-13 04:18:53 +00:00
|
|
|
|
2024-05-27 05:47:42 +00:00
|
|
|
responseAutoCopy = $settings.responseAutoCopy ?? false;
|
|
|
|
showUsername = $settings.showUsername ?? false;
|
2024-06-13 04:18:53 +00:00
|
|
|
|
|
|
|
showEmojiInCall = $settings.showEmojiInCall ?? false;
|
|
|
|
|
2024-05-27 05:47:42 +00:00
|
|
|
chatBubble = $settings.chatBubble ?? true;
|
2024-06-04 18:48:46 +00:00
|
|
|
widescreenMode = $settings.widescreenMode ?? false;
|
2024-05-27 05:47:42 +00:00
|
|
|
splitLargeChunks = $settings.splitLargeChunks ?? false;
|
|
|
|
chatDirection = $settings.chatDirection ?? 'LTR';
|
2024-06-16 22:32:26 +00:00
|
|
|
userLocation = $settings.userLocation ?? false;
|
2024-06-05 16:14:15 +00:00
|
|
|
|
|
|
|
defaultModelId = ($settings?.models ?? ['']).at(0);
|
2024-02-05 09:58:54 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<form
|
|
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
|
|
|
on:submit|preventDefault={() => {
|
|
|
|
updateInterfaceHandler();
|
|
|
|
dispatch('save');
|
|
|
|
}}
|
|
|
|
>
|
2024-05-15 22:55:13 +00:00
|
|
|
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[25rem]">
|
2024-02-06 05:05:38 +00:00
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('WebUI Add-ons')}</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
|
2024-05-15 22:39:41 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Chat Bubble UI')}</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleChatBubble();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if chatBubble === true}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-06-16 22:32:26 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Widescreen Mode')}</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
togglewidescreenMode();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if widescreenMode === true}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-02-06 05:05:38 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Title Auto-Generation')}</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleTitleAutoGenerate();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if titleAutoGenerate === true}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
2024-02-06 05:05:38 +00:00
|
|
|
{:else}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
2024-02-06 05:05:38 +00:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-03-02 21:53:41 +00:00
|
|
|
<div class=" self-center text-xs font-medium">
|
|
|
|
{$i18n.t('Response AutoCopy to Clipboard')}
|
|
|
|
</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleResponseAutoCopy();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if responseAutoCopy === true}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
2024-02-06 05:05:38 +00:00
|
|
|
{:else}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
2024-02-06 05:05:38 +00:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
2024-02-15 08:34:55 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-06-16 22:32:26 +00:00
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Allow User Location')}</div>
|
2024-02-15 08:34:55 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
2024-06-16 22:32:26 +00:00
|
|
|
toggleUserLocation();
|
2024-02-15 08:34:55 +00:00
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
2024-06-16 22:32:26 +00:00
|
|
|
{#if userLocation === true}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
2024-02-15 08:34:55 +00:00
|
|
|
{:else}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
2024-02-15 08:34:55 +00:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-06-13 04:18:53 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Display Emoji in Call')}</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleEmojiInCall();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if showEmojiInCall === true}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-05-18 23:11:28 +00:00
|
|
|
{#if !$settings.chatBubble}
|
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">
|
|
|
|
{$i18n.t('Display the username instead of You in the Chat')}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleShowUsername();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if showUsername === true}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
2024-02-10 00:00:39 +00:00
|
|
|
</div>
|
2024-02-06 10:22:34 +00:00
|
|
|
</div>
|
2024-05-18 23:11:28 +00:00
|
|
|
{/if}
|
2024-04-21 09:45:07 +00:00
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">
|
|
|
|
{$i18n.t('Fluidly stream large external response chunks')}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleSplitLargeChunks();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if splitLargeChunks === true}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-05 09:58:54 +00:00
|
|
|
</div>
|
|
|
|
|
2024-05-16 20:22:30 +00:00
|
|
|
<div>
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Chat direction')}</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={toggleChangeChatDirection}
|
|
|
|
type="button"
|
|
|
|
>
|
2024-05-18 22:02:47 +00:00
|
|
|
{#if chatDirection === 'LTR'}
|
2024-05-16 20:22:30 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('LTR')}</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">{$i18n.t('RTL')}</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-06-05 16:14:15 +00:00
|
|
|
<hr class=" dark:border-gray-850" />
|
|
|
|
|
|
|
|
<div class=" space-y-1 mb-3">
|
|
|
|
<div class="mb-2">
|
|
|
|
<div class="flex justify-between items-center text-xs">
|
|
|
|
<div class=" text-xs font-medium">{$i18n.t('Default Model')}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex-1 mr-2">
|
|
|
|
<select
|
|
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
|
|
bind:value={defaultModelId}
|
|
|
|
placeholder="Select a model"
|
|
|
|
>
|
|
|
|
<option value="" disabled selected>{$i18n.t('Select a model')}</option>
|
|
|
|
{#each $models.filter((model) => model.id) as model}
|
|
|
|
<option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-05 09:58:54 +00:00
|
|
|
</div>
|
|
|
|
|
2024-03-16 09:24:32 +00:00
|
|
|
<div class="flex justify-end text-sm font-medium">
|
2024-02-05 09:58:54 +00:00
|
|
|
<button
|
2024-03-10 06:02:27 +00:00
|
|
|
class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
|
2024-02-05 09:58:54 +00:00
|
|
|
type="submit"
|
|
|
|
>
|
2024-03-04 08:53:56 +00:00
|
|
|
{$i18n.t('Save')}
|
2024-02-05 09:58:54 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|