2024-05-09 07:34:57 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { DropdownMenu } from 'bits-ui';
|
2025-08-08 09:56:34 +00:00
|
|
|
import { createEventDispatcher, getContext, onMount, tick } from 'svelte';
|
2024-05-09 07:34:57 +00:00
|
|
|
|
|
|
|
|
import { flyAndScale } from '$lib/utils/transitions';
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { fade, slide } from 'svelte/transition';
|
2025-06-16 06:42:34 +00:00
|
|
|
|
|
|
|
|
import { getUsage } from '$lib/apis';
|
2024-10-24 20:35:29 +00:00
|
|
|
import { userSignOut } from '$lib/apis/auths';
|
2025-06-16 06:42:34 +00:00
|
|
|
|
2025-07-18 08:47:22 +00:00
|
|
|
import { showSettings, mobile, showSidebar, showShortcuts, user } from '$lib/stores';
|
2025-06-16 06:42:34 +00:00
|
|
|
|
|
|
|
|
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
2025-06-14 18:31:20 +00:00
|
|
|
import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
|
2025-05-23 12:49:11 +00:00
|
|
|
import QuestionMarkCircle from '$lib/components/icons/QuestionMarkCircle.svelte';
|
|
|
|
|
import Map from '$lib/components/icons/Map.svelte';
|
|
|
|
|
import Keyboard from '$lib/components/icons/Keyboard.svelte';
|
|
|
|
|
import ShortcutsModal from '$lib/components/chat/ShortcutsModal.svelte';
|
2025-06-14 18:31:20 +00:00
|
|
|
import Settings from '$lib/components/icons/Settings.svelte';
|
|
|
|
|
import Code from '$lib/components/icons/Code.svelte';
|
|
|
|
|
import UserGroup from '$lib/components/icons/UserGroup.svelte';
|
|
|
|
|
import SignOut from '$lib/components/icons/SignOut.svelte';
|
2024-05-09 07:34:57 +00:00
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
|
|
export let show = false;
|
|
|
|
|
export let role = '';
|
2025-05-23 12:49:11 +00:00
|
|
|
export let help = false;
|
2024-05-15 09:45:27 +00:00
|
|
|
export let className = 'max-w-[240px]';
|
2024-05-09 07:34:57 +00:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2025-06-16 06:42:34 +00:00
|
|
|
|
|
|
|
|
let usage = null;
|
|
|
|
|
const getUsageInfo = async () => {
|
|
|
|
|
const res = await getUsage(localStorage.token).catch((error) => {
|
|
|
|
|
console.error('Error fetching usage info:', error);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
usage = res;
|
|
|
|
|
} else {
|
|
|
|
|
usage = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$: if (show) {
|
|
|
|
|
getUsageInfo();
|
|
|
|
|
}
|
2024-05-09 07:34:57 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-07-18 08:47:22 +00:00
|
|
|
<ShortcutsModal bind:show={$showShortcuts} />
|
2025-05-23 12:49:11 +00:00
|
|
|
|
2025-06-16 06:42:34 +00:00
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2024-05-09 07:34:57 +00:00
|
|
|
<DropdownMenu.Root
|
|
|
|
|
bind:open={show}
|
|
|
|
|
onOpenChange={(state) => {
|
|
|
|
|
dispatch('change', state);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DropdownMenu.Trigger>
|
|
|
|
|
<slot />
|
|
|
|
|
</DropdownMenu.Trigger>
|
|
|
|
|
|
|
|
|
|
<slot name="content">
|
|
|
|
|
<DropdownMenu.Content
|
2024-10-21 07:35:51 +00:00
|
|
|
class="w-full {className} text-sm rounded-xl px-1 py-1.5 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg font-primary"
|
2025-05-23 12:49:11 +00:00
|
|
|
sideOffset={4}
|
2024-05-09 07:34:57 +00:00
|
|
|
side="bottom"
|
|
|
|
|
align="start"
|
|
|
|
|
transition={(e) => fade(e, { duration: 100 })}
|
|
|
|
|
>
|
2025-07-02 09:14:12 +00:00
|
|
|
<DropdownMenu.Item
|
2025-07-29 12:15:23 +00:00
|
|
|
class="flex rounded-md py-1.5 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition cursor-pointer"
|
2024-05-09 07:34:57 +00:00
|
|
|
on:click={async () => {
|
|
|
|
|
show = false;
|
2024-09-22 12:50:24 +00:00
|
|
|
|
2025-08-08 09:56:34 +00:00
|
|
|
await showSettings.set(true);
|
|
|
|
|
|
2024-09-22 12:50:24 +00:00
|
|
|
if ($mobile) {
|
2025-08-08 09:56:34 +00:00
|
|
|
await tick();
|
2024-09-22 12:50:24 +00:00
|
|
|
showSidebar.set(false);
|
|
|
|
|
}
|
2024-05-09 07:34:57 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center mr-3">
|
2025-06-14 18:31:20 +00:00
|
|
|
<Settings className="w-5 h-5" strokeWidth="1.5" />
|
2024-05-09 07:34:57 +00:00
|
|
|
</div>
|
2024-11-01 23:32:12 +00:00
|
|
|
<div class=" self-center truncate">{$i18n.t('Settings')}</div>
|
2025-07-02 09:14:12 +00:00
|
|
|
</DropdownMenu.Item>
|
2024-05-09 07:34:57 +00:00
|
|
|
|
2025-07-02 09:14:12 +00:00
|
|
|
<DropdownMenu.Item
|
2025-07-29 12:15:23 +00:00
|
|
|
class="flex rounded-md py-1.5 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition cursor-pointer"
|
2025-08-08 09:56:34 +00:00
|
|
|
on:click={async () => {
|
2024-05-15 09:45:27 +00:00
|
|
|
show = false;
|
2024-09-22 12:50:24 +00:00
|
|
|
|
2025-08-08 09:56:34 +00:00
|
|
|
dispatch('show', 'archived-chat');
|
|
|
|
|
|
2024-09-22 12:50:24 +00:00
|
|
|
if ($mobile) {
|
2025-08-08 09:56:34 +00:00
|
|
|
await tick();
|
|
|
|
|
|
2024-09-22 12:50:24 +00:00
|
|
|
showSidebar.set(false);
|
|
|
|
|
}
|
2024-05-15 09:45:27 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center mr-3">
|
|
|
|
|
<ArchiveBox className="size-5" strokeWidth="1.5" />
|
|
|
|
|
</div>
|
2024-11-01 23:32:12 +00:00
|
|
|
<div class=" self-center truncate">{$i18n.t('Archived Chats')}</div>
|
2025-07-02 09:14:12 +00:00
|
|
|
</DropdownMenu.Item>
|
2024-05-15 09:45:27 +00:00
|
|
|
|
|
|
|
|
{#if role === 'admin'}
|
2025-07-31 13:33:27 +00:00
|
|
|
<DropdownMenu.Item
|
|
|
|
|
as="a"
|
2025-07-29 12:15:23 +00:00
|
|
|
href="/playground"
|
2025-07-31 13:33:27 +00:00
|
|
|
class="flex rounded-md py-1.5 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition select-none"
|
2025-08-08 09:56:34 +00:00
|
|
|
on:click={async () => {
|
2024-06-19 00:41:47 +00:00
|
|
|
show = false;
|
2024-09-22 12:50:24 +00:00
|
|
|
if ($mobile) {
|
2025-08-08 09:56:34 +00:00
|
|
|
await tick();
|
2024-09-22 12:50:24 +00:00
|
|
|
showSidebar.set(false);
|
|
|
|
|
}
|
2024-06-19 00:41:47 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center mr-3">
|
2025-06-14 18:31:20 +00:00
|
|
|
<Code className="size-5" strokeWidth="1.5" />
|
2024-06-19 00:41:47 +00:00
|
|
|
</div>
|
2024-11-01 23:32:12 +00:00
|
|
|
<div class=" self-center truncate">{$i18n.t('Playground')}</div>
|
2025-07-31 13:33:27 +00:00
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
as="a"
|
2025-07-29 12:15:23 +00:00
|
|
|
href="/admin"
|
2025-07-31 13:33:27 +00:00
|
|
|
class="flex rounded-md py-1.5 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition select-none"
|
2025-08-08 09:56:34 +00:00
|
|
|
on:click={async () => {
|
2024-05-15 09:45:27 +00:00
|
|
|
show = false;
|
2024-09-22 12:50:24 +00:00
|
|
|
if ($mobile) {
|
2025-08-08 09:56:34 +00:00
|
|
|
await tick();
|
2024-09-22 12:50:24 +00:00
|
|
|
showSidebar.set(false);
|
|
|
|
|
}
|
2024-05-15 09:45:27 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center mr-3">
|
2025-06-14 18:31:20 +00:00
|
|
|
<UserGroup className="w-5 h-5" strokeWidth="1.5" />
|
2024-05-15 09:45:27 +00:00
|
|
|
</div>
|
2024-11-01 23:32:12 +00:00
|
|
|
<div class=" self-center truncate">{$i18n.t('Admin Panel')}</div>
|
2025-07-31 13:33:27 +00:00
|
|
|
</DropdownMenu.Item>
|
2024-05-15 09:45:27 +00:00
|
|
|
{/if}
|
|
|
|
|
|
2025-05-23 12:49:11 +00:00
|
|
|
{#if help}
|
2025-08-06 19:08:41 +00:00
|
|
|
<hr class=" border-gray-50 dark:border-gray-800 my-1 p-0" />
|
2025-05-23 12:49:11 +00:00
|
|
|
|
|
|
|
|
<!-- {$i18n.t('Help')} -->
|
2025-07-31 13:33:27 +00:00
|
|
|
|
2025-08-06 07:50:35 +00:00
|
|
|
{#if $user?.role === 'admin'}
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
as="a"
|
|
|
|
|
class="flex gap-2 items-center py-1.5 px-3 text-sm select-none w-full cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md transition"
|
|
|
|
|
id="chat-share-button"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
show = false;
|
|
|
|
|
}}
|
|
|
|
|
href="https://docs.openwebui.com"
|
|
|
|
|
>
|
|
|
|
|
<QuestionMarkCircle className="size-5" />
|
|
|
|
|
<div class="flex items-center">{$i18n.t('Documentation')}</div>
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
|
|
|
|
|
<!-- Releases -->
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
as="a"
|
|
|
|
|
class="flex gap-2 items-center py-1.5 px-3 text-sm select-none w-full cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md transition"
|
|
|
|
|
id="chat-share-button"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
show = false;
|
|
|
|
|
}}
|
2025-08-13 13:23:28 +00:00
|
|
|
href="https://github.com/open-webui/open-webui/releases"
|
2025-08-06 07:50:35 +00:00
|
|
|
>
|
|
|
|
|
<Map className="size-5" />
|
|
|
|
|
<div class="flex items-center">{$i18n.t('Releases')}</div>
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
{/if}
|
2025-05-23 12:49:11 +00:00
|
|
|
|
|
|
|
|
<DropdownMenu.Item
|
2025-07-29 12:15:23 +00:00
|
|
|
class="flex gap-2 items-center py-1.5 px-3 text-sm select-none w-full cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md transition cursor-pointer"
|
2025-05-23 12:49:11 +00:00
|
|
|
id="chat-share-button"
|
2025-08-08 09:56:34 +00:00
|
|
|
on:click={async () => {
|
2025-05-23 12:49:11 +00:00
|
|
|
show = false;
|
2025-08-08 09:56:34 +00:00
|
|
|
showShortcuts.set(!$showShortcuts);
|
|
|
|
|
|
|
|
|
|
if ($mobile) {
|
|
|
|
|
await tick();
|
|
|
|
|
showSidebar.set(false);
|
|
|
|
|
}
|
2025-05-23 12:49:11 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Keyboard className="size-5" />
|
|
|
|
|
<div class="flex items-center">{$i18n.t('Keyboard shortcuts')}</div>
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
{/if}
|
|
|
|
|
|
2025-08-06 19:08:41 +00:00
|
|
|
<hr class=" border-gray-50 dark:border-gray-800 my-1 p-0" />
|
2024-05-09 07:34:57 +00:00
|
|
|
|
2025-07-31 13:33:27 +00:00
|
|
|
<DropdownMenu.Item
|
2025-05-23 12:49:11 +00:00
|
|
|
class="flex rounded-md py-1.5 px-3 w-full hover:bg-gray-50 dark:hover:bg-gray-800 transition"
|
2024-10-24 20:35:29 +00:00
|
|
|
on:click={async () => {
|
2025-05-16 20:38:39 +00:00
|
|
|
const res = await userSignOut();
|
2025-03-04 04:31:35 +00:00
|
|
|
user.set(null);
|
2024-05-09 07:34:57 +00:00
|
|
|
localStorage.removeItem('token');
|
2025-03-04 04:31:35 +00:00
|
|
|
|
2025-05-16 20:38:39 +00:00
|
|
|
location.href = res?.redirect_url ?? '/auth';
|
2024-05-09 07:34:57 +00:00
|
|
|
show = false;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" self-center mr-3">
|
2025-06-14 18:31:20 +00:00
|
|
|
<SignOut className="w-5 h-5" strokeWidth="1.5" />
|
2024-05-09 07:34:57 +00:00
|
|
|
</div>
|
2024-11-01 23:32:12 +00:00
|
|
|
<div class=" self-center truncate">{$i18n.t('Sign Out')}</div>
|
2025-07-31 13:33:27 +00:00
|
|
|
</DropdownMenu.Item>
|
2024-05-09 07:34:57 +00:00
|
|
|
|
2025-06-16 06:42:34 +00:00
|
|
|
{#if usage}
|
|
|
|
|
{#if usage?.user_ids?.length > 0}
|
2025-08-06 19:08:41 +00:00
|
|
|
<hr class=" border-gray-50 dark:border-gray-800 my-1 p-0" />
|
2025-06-16 06:42:34 +00:00
|
|
|
|
|
|
|
|
<Tooltip
|
|
|
|
|
content={usage?.model_ids && usage?.model_ids.length > 0
|
|
|
|
|
? `${$i18n.t('Running')}: ${usage.model_ids.join(', ')} ✨`
|
|
|
|
|
: ''}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
class="flex rounded-md py-1 px-3 text-xs gap-2.5 items-center"
|
|
|
|
|
on:mouseenter={() => {
|
|
|
|
|
getUsageInfo();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" flex items-center">
|
|
|
|
|
<span class="relative flex size-2">
|
|
|
|
|
<span
|
|
|
|
|
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
|
|
|
|
|
/>
|
|
|
|
|
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class=" ">
|
|
|
|
|
<span class="">
|
|
|
|
|
{$i18n.t('Active Users')}:
|
|
|
|
|
</span>
|
|
|
|
|
<span class=" font-semibold">
|
|
|
|
|
{usage?.user_ids?.length}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2024-06-04 18:13:43 +00:00
|
|
|
</div>
|
2025-06-16 06:42:34 +00:00
|
|
|
</Tooltip>
|
|
|
|
|
{/if}
|
2024-06-04 08:10:31 +00:00
|
|
|
{/if}
|
|
|
|
|
|
2025-05-23 12:49:11 +00:00
|
|
|
<!-- <DropdownMenu.Item class="flex items-center py-1.5 px-3 text-sm ">
|
2024-05-09 07:34:57 +00:00
|
|
|
<div class="flex items-center">Profile</div>
|
|
|
|
|
</DropdownMenu.Item> -->
|
|
|
|
|
</DropdownMenu.Content>
|
|
|
|
|
</slot>
|
|
|
|
|
</DropdownMenu.Root>
|