This commit is contained in:
Timothy Jaeryang Baek
2026-07-15 01:59:56 -04:00
parent 581f2f36f4
commit fb2ea27295
5 changed files with 138 additions and 83 deletions
+55 -16
View File
@@ -14,6 +14,7 @@
getBaseModels,
toggleModelById,
updateModelById,
updateModelAccessGrants,
importModels
} from '$lib/apis/models';
import { copyToClipboard } from '$lib/utils';
@@ -82,6 +83,18 @@
);
};
const isSharedModel = (model) => (model?.access_grants ?? []).length > 0 && !isPublicModel(model);
const modelAccessBadge = (model) => {
if (isPublicModel(model)) {
return { type: 'success', content: $i18n.t('Public') };
}
if (isSharedModel(model)) {
return { type: 'info', content: $i18n.t('Shared') };
}
return { type: 'muted', content: $i18n.t('Private') };
};
$: if (models) {
filteredModels = models
.filter((m) => searchValue === '' || m.name.toLowerCase().includes(searchValue.toLowerCase()))
@@ -297,6 +310,43 @@
);
};
const toggleModelPrivacyHandler = async (model) => {
const nextAccessGrants = isPublicModel(model)
? []
: [
...(model?.access_grants ?? []),
{
principal_type: 'user',
principal_id: '*',
permission: 'read'
}
];
const res = await updateModelAccessGrants(
localStorage.token,
model.id,
model.name,
nextAccessGrants
).catch(() => null);
if (res) {
models = models.map((m) =>
m.id === model.id ? { ...m, access_grants: res.access_grants ?? nextAccessGrants } : m
);
_models.set(
await getModels(
localStorage.token,
$config?.features?.enable_direct_connections && ($settings?.directConnections ?? null)
)
);
toast.success(
isPublicModel({ access_grants: nextAccessGrants })
? $i18n.t('Model is now public')
: $i18n.t('Model is now private')
);
}
};
const copyLinkHandler = async (model) => {
const baseUrl = window.location.origin;
const res = await copyToClipboard(`${baseUrl}/?model=${encodeURIComponent(model.id)}`);
@@ -662,22 +712,8 @@
</span>
<Badge
type={(model?.access_grants ?? []).some(
(g) =>
g.principal_type === 'user' &&
g.principal_id === '*' &&
g.permission === 'read'
)
? 'success'
: 'muted'}
content={(model?.access_grants ?? []).some(
(g) =>
g.principal_type === 'user' &&
g.principal_id === '*' &&
g.permission === 'read'
)
? $i18n.t('Public')
: $i18n.t('Private')}
type={modelAccessBadge(model).type}
content={modelAccessBadge(model).content}
/>
</div>
</Tooltip>
@@ -734,6 +770,9 @@
hideHandler={() => {
hideModelHandler(model);
}}
privacyHandler={() => {
toggleModelPrivacyHandler(model);
}}
pinModelHandler={() => {
pinModelHandler(model.id);
}}