diff --git a/ui/apps/chat/src/lib/components/app/dialogs/DialogConversationShare.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogConversationShare.svelte index b8ab9600b32e..c51eeb680c66 100644 --- a/ui/apps/chat/src/lib/components/app/dialogs/DialogConversationShare.svelte +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogConversationShare.svelte @@ -7,8 +7,14 @@ import { Label } from '@ggml-org/llama-ui/ui/label'; import * as RadioGroup from '@ggml-org/llama-ui/ui/radio-group'; import { Check, Copy, ExternalLink, Loader2, Share2, TriangleAlert } from '@lucide/svelte'; - import { HF_NEW_TOKEN_URL, HF_REPO_ID_REGEX, HF_TRACES_DOCS_URL } from '#lib/constants/index.ts'; - import { TraceShareScope } from '#lib/enums/index.ts'; + import { + HF_NEW_TOKEN_URL, + HF_OAUTH_POPUP_FEATURES, + HF_OAUTH_POPUP_NAME, + HF_REPO_ID_REGEX, + HF_TRACES_DOCS_URL + } from '#lib/constants/index.ts'; + import { HfAuthMethod, TraceShareScope } from '#lib/enums/index.ts'; import { conversationsStore, huggingFaceStore, uiStore } from '#lib/stores/index.ts'; import { copyToClipboard, filterByLeafNodeId } from '#lib/utils/index.ts'; import { untrack } from 'svelte'; @@ -46,6 +52,8 @@ shareError = null; sharedUrl = null; messages = []; + + if (!huggingFaceStore.isSigningInWithHf) huggingFaceStore.oauthError = null; }); void huggingFaceStore.restoreSession().then(() => { @@ -57,6 +65,15 @@ }); }); + // a sign-in that finished elsewhere (a popup, another tab) suggests the account's dataset + $effect(() => { + if (!user) return; + + untrack(() => { + if (!dataset) dataset = huggingFaceStore.suggestedDataset; + }); + }); + let leafId = $derived( scope === TraceShareScope.UP_TO_MESSAGE && options?.messageId ? options.messageId @@ -74,7 +91,11 @@ let hasAttachments = $derived(tracePath.some((message) => !!message.extra?.length)); let user = $derived(huggingFaceStore.user); - let isReadOnlyToken = $derived(user?.tokenRole === 'read'); + let isReadOnlyToken = $derived( + huggingFaceStore.authMethod === HfAuthMethod.ACCESS_TOKEN && user?.tokenRole === 'read' + ); + let isSigningInWithHf = $derived(huggingFaceStore.isSigningInWithHf); + let isBusySigningIn = $derived(huggingFaceStore.isCheckingToken || isSigningInWithHf); let isDatasetValid = $derived(HF_REPO_ID_REGEX.test(dataset.trim())); let canShare = $derived( !!user && !isReadOnlyToken && isDatasetValid && tracePath.length > 0 && !isSharing @@ -104,6 +125,15 @@ } } + function handleSignInWithHf() { + signInError = null; + + // opened in the click itself: a popup opened after an await is blocked + const popup = window.open('about:blank', HF_OAUTH_POPUP_NAME, HF_OAUTH_POPUP_FEATURES); + + void huggingFaceStore.signInWithHuggingFace(popup); + } + function handleSignOut() { huggingFaceStore.signOut(); } @@ -184,13 +214,50 @@ {:else if !user}