This commit is contained in:
Timothy Jaeryang Baek
2026-07-17 06:34:17 -04:00
parent fd07e3a8e3
commit 9281adc564
5 changed files with 85 additions and 74 deletions
+29 -11
View File
@@ -7,12 +7,13 @@
import { onMount, onDestroy, getContext, tick } from 'svelte';
const i18n = getContext('i18n');
import { config, models as _models, settings, user } from '$lib/stores';
import { config, models as _models, settings, showSettings, user } from '$lib/stores';
import {
createNewModel,
deleteAllModels,
getBaseModelTags,
getBaseModels,
getModelById,
toggleModelById,
updateModelById,
updateModelAccessGrants,
@@ -228,6 +229,7 @@
};
const downloadModels = async (models) => {
models = await Promise.all(models.map(getFullModel));
let blob = new Blob([JSON.stringify(models)], {
type: 'application/json'
});
@@ -483,22 +485,30 @@
};
const hideModelHandler = async (model) => {
model.meta = {
...model.meta,
hidden: !(model?.meta?.hidden ?? false)
const updatedModel = {
...model,
meta: {
...model.meta,
hidden: !(model?.meta?.hidden ?? false)
}
};
console.debug(model);
upsertModelHandler(model, { meta: model.meta }, false);
await upsertModelHandler(updatedModel, { meta: updatedModel.meta }, false);
models = models.map((model) => (model.id === updatedModel.id ? updatedModel : model));
_models.set(
await getModels(
localStorage.token,
$config?.features?.enable_direct_connections && ($settings?.directConnections ?? null)
)
);
toast.success(
model.meta.hidden
updatedModel.meta.hidden
? $i18n.t(`Model {{name}} is now hidden`, {
name: model.id
name: updatedModel.id
})
: $i18n.t(`Model {{name}} is now visible`, {
name: model.id
name: updatedModel.id
})
);
};
@@ -551,17 +561,25 @@
}
};
const getFullModel = async (model) =>
workspaceModels.some((workspaceModel) => workspaceModel.id === model.id)
? ((await getModelById(localStorage.token, model.id).catch(() => null)) ?? model)
: model;
const cloneHandler = async (model) => {
model = await getFullModel(model);
sessionStorage.model = JSON.stringify({
...model,
base_model_id: model.id,
id: `${model.id}-clone`,
name: `${model.name} (Clone)`
});
goto('/workspace/models/create');
showSettings.set(false);
await goto('/workspace/models/create');
};
const exportModelHandler = async (model) => {
model = await getFullModel(model);
let blob = new Blob([JSON.stringify([model])], {
type: 'application/json'
});
@@ -41,6 +41,11 @@
let show = false;
const runAndClose = async (handler: Function) => {
show = false;
await handler();
};
const isPublicModel = (model) =>
(model?.access_grants ?? []).some(
(g) => g.principal_type === 'user' && g.principal_id === '*' && g.permission === 'read'
@@ -63,9 +68,7 @@
<DropdownMenu className="min-w-[170px]">
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
hideHandler();
}}
on:click={() => runAndClose(hideHandler)}
>
{#if model?.meta?.hidden ?? false}
<svg
@@ -115,10 +118,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={async () => {
show = false;
await defaultSelectedHandler();
}}
on:click={() => runAndClose(defaultSelectedHandler)}
>
<Check className="size-3.5" />
@@ -133,10 +133,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={async () => {
show = false;
await defaultPinnedHandler();
}}
on:click={() => runAndClose(defaultPinnedHandler)}
>
{#if isDefaultPinned}
<PinSlash className="size-3.5" />
@@ -155,9 +152,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
privacyHandler();
}}
on:click={() => runAndClose(privacyHandler)}
>
{#if isPublicModel(model)}
<LockClosed className="size-3.5" />
@@ -176,9 +171,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
pinModelHandler(model?.id);
}}
on:click={() => runAndClose(() => pinModelHandler(model?.id))}
>
{#if ($settings?.pinnedModels ?? []).includes(model?.id)}
<PinSlash />
@@ -197,9 +190,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
copyLinkHandler();
}}
on:click={() => runAndClose(copyLinkHandler)}
>
<Link />
@@ -209,9 +200,7 @@
{#if model?.is_active ?? true}
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
cloneHandler();
}}
on:click={() => runAndClose(cloneHandler)}
>
<DocumentDuplicate />
@@ -221,9 +210,7 @@
<button
class="select-none flex w-full gap-2 items-center h-[1.6875rem] px-2 text-[13px] font-normal cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 rounded-xl"
on:click={() => {
exportHandler();
}}
on:click={() => runAndClose(exportHandler)}
>
<Download />