|
| 1 | +<script lang="ts"> |
| 2 | + import { onMount } from "svelte"; |
| 3 | + import { base } from "$app/paths"; |
| 4 | + import { afterNavigate, goto } from "$app/navigation"; |
| 5 | + import { page } from "$app/stores"; |
| 6 | + import { useSettingsStore } from "$lib/stores/settings"; |
| 7 | + import CarbonClose from "~icons/carbon/close"; |
| 8 | + import CarbonArrowUpRight from "~icons/carbon/ArrowUpRight"; |
| 9 | + import CarbonAdd from "~icons/carbon/add"; |
| 10 | +
|
| 11 | + import UserIcon from "~icons/carbon/user"; |
| 12 | + import type { LayoutData } from "../$types"; |
| 13 | +
|
| 14 | + export let data: LayoutData; |
| 15 | +
|
| 16 | + let previousPage: string = base; |
| 17 | + let assistantsSection: HTMLHeadingElement; |
| 18 | +
|
| 19 | + onMount(() => { |
| 20 | + if ($page.params?.assistantId) { |
| 21 | + assistantsSection.scrollIntoView(); |
| 22 | + } |
| 23 | + }); |
| 24 | +
|
| 25 | + afterNavigate(({ from }) => { |
| 26 | + if (!from?.url.pathname.includes("settings")) { |
| 27 | + previousPage = from?.url.toString() || previousPage; |
| 28 | + } |
| 29 | + }); |
| 30 | +
|
| 31 | + const settings = useSettingsStore(); |
| 32 | +</script> |
| 33 | + |
| 34 | +<div |
| 35 | + class="grid h-full w-full grid-cols-1 grid-rows-[auto,1fr] content-start gap-x-8 overflow-hidden p-4 md:grid-cols-3 md:grid-rows-[auto,1fr] md:p-8" |
| 36 | +> |
| 37 | + <div class="col-span-1 mb-4 flex items-center justify-between md:col-span-3"> |
| 38 | + <h2 class="text-xl font-bold">Settings</h2> |
| 39 | + <button |
| 40 | + class="btn rounded-lg" |
| 41 | + on:click={() => { |
| 42 | + goto(previousPage); |
| 43 | + }} |
| 44 | + > |
| 45 | + <CarbonClose class="text-xl text-gray-900 hover:text-black" /> |
| 46 | + </button> |
| 47 | + </div> |
| 48 | + <div |
| 49 | + class="col-span-1 flex flex-col overflow-y-auto whitespace-nowrap max-md:-mx-4 max-md:h-[245px] max-md:border max-md:border-b-2 md:pr-6" |
| 50 | + > |
| 51 | + <h3 class="pb-3 pl-3 pt-2 text-[.8rem] text-gray-800 sm:pl-1">Models</h3> |
| 52 | + |
| 53 | + {#each data.models.filter((el) => !el.unlisted) as model} |
| 54 | + <a |
| 55 | + href="{base}/settings/{model.id}" |
| 56 | + class="group flex h-10 flex-none items-center gap-2 pl-3 pr-2 text-sm text-gray-500 hover:bg-gray-100 md:rounded-xl |
| 57 | + {model.id === $page.params.model ? '!bg-gray-100 !text-gray-800' : ''}" |
| 58 | + > |
| 59 | + <div class="truncate">{model.displayName}</div> |
| 60 | + {#if model.id === $settings.activeModel} |
| 61 | + <div |
| 62 | + class="ml-auto rounded-lg bg-black px-2 py-1.5 text-xs font-semibold leading-none text-white" |
| 63 | + > |
| 64 | + Active |
| 65 | + </div> |
| 66 | + {/if} |
| 67 | + </a> |
| 68 | + {/each} |
| 69 | + <!-- if its huggingchat, the number of assistants owned by the user must be non-zero to show the UI --> |
| 70 | + {#if data.enableAssistants} |
| 71 | + <h3 bind:this={assistantsSection} class="pb-3 pl-3 pt-5 text-[.8rem] text-gray-800 sm:pl-1"> |
| 72 | + Assistants |
| 73 | + </h3> |
| 74 | + {#if !data.loginEnabled || (data.loginEnabled && !!data.user)} |
| 75 | + <a |
| 76 | + href="{base}/settings/assistants/new" |
| 77 | + class="group flex h-10 flex-none items-center gap-2 pl-3 pr-2 text-sm text-gray-500 hover:bg-gray-100 md:rounded-xl |
| 78 | + {$page.url.pathname === `${base}/settings/assistants/new` ? '!bg-gray-100 !text-gray-800' : ''}" |
| 79 | + > |
| 80 | + <CarbonAdd /> |
| 81 | + <div class="truncate">Create new assistant</div> |
| 82 | + </a> |
| 83 | + {/if} |
| 84 | + {#each data.assistants as assistant} |
| 85 | + <a |
| 86 | + href="{base}/settings/assistants/{assistant._id.toString()}" |
| 87 | + class="group flex h-10 flex-none items-center gap-2 pl-2 pr-2 text-sm text-gray-500 hover:bg-gray-100 md:rounded-xl |
| 88 | + {assistant._id.toString() === $page.params.assistantId ? '!bg-gray-100 !text-gray-800' : ''}" |
| 89 | + > |
| 90 | + {#if assistant.avatar} |
| 91 | + <img |
| 92 | + src="{base}/settings/assistants/{assistant._id.toString()}/avatar.jpg?hash={assistant.avatar}" |
| 93 | + alt="Avatar" |
| 94 | + class="h-6 w-6 rounded-full object-cover" |
| 95 | + /> |
| 96 | + {:else} |
| 97 | + <div |
| 98 | + class="flex size-6 items-center justify-center rounded-full bg-gray-300 font-bold uppercase text-gray-500" |
| 99 | + > |
| 100 | + {assistant.name[0]} |
| 101 | + </div> |
| 102 | + {/if} |
| 103 | + <div class="truncate">{assistant.name}</div> |
| 104 | + {#if assistant._id.toString() === $settings.activeModel} |
| 105 | + <div |
| 106 | + class="ml-auto rounded-lg bg-black px-2 py-1.5 text-xs font-semibold leading-none text-white" |
| 107 | + > |
| 108 | + Active |
| 109 | + </div> |
| 110 | + {/if} |
| 111 | + </a> |
| 112 | + {/each} |
| 113 | + <a |
| 114 | + href="{base}/assistants" |
| 115 | + class="group flex h-10 flex-none items-center gap-2 pl-3 pr-2 text-sm text-gray-500 hover:bg-gray-100 md:rounded-xl" |
| 116 | + ><CarbonArrowUpRight class="mr-1.5 shrink-0 text-xs " /> |
| 117 | + <div class="truncate">Browse Assistants</div> |
| 118 | + </a> |
| 119 | + {/if} |
| 120 | + |
| 121 | + <a |
| 122 | + href="{base}/settings" |
| 123 | + class="group mt-auto flex h-10 flex-none items-center gap-2 pl-3 pr-2 text-sm text-gray-500 hover:bg-gray-100 max-md:order-first md:rounded-xl |
| 124 | + {$page.url.pathname === `${base}/settings` ? '!bg-gray-100 !text-gray-800' : ''}" |
| 125 | + > |
| 126 | + <UserIcon class="text-sm" /> |
| 127 | + Application Settings |
| 128 | + </a> |
| 129 | + </div> |
| 130 | + <div |
| 131 | + class="col-span-1 w-full overflow-y-auto overflow-x-clip px-1 max-md:pt-4 md:col-span-2 md:row-span-2" |
| 132 | + > |
| 133 | + <slot /> |
| 134 | + </div> |
| 135 | +</div> |
0 commit comments