From 5c605c92e082e87f8ee612e4c2b13d4cf75a3091 Mon Sep 17 00:00:00 2001 From: Salman Mohammed Date: Fri, 28 Mar 2025 18:52:21 -0400 Subject: [PATCH] feat: preconfigure session sharing with GOOSE_BASE_URL_SHARE (#1885) Co-authored-by: Lily Delalande --- .../session/SessionSharingSection.tsx | 109 +++++++++++------- ui/desktop/src/main.ts | 11 ++ 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/ui/desktop/src/components/settings/session/SessionSharingSection.tsx b/ui/desktop/src/components/settings/session/SessionSharingSection.tsx index 0ee27680..3a97dc3e 100644 --- a/ui/desktop/src/components/settings/session/SessionSharingSection.tsx +++ b/ui/desktop/src/components/settings/session/SessionSharingSection.tsx @@ -1,30 +1,37 @@ import React, { useState, useEffect } from 'react'; import { Input } from '../../ui/input'; -import { Check } from 'lucide-react'; +import { Check, Lock } from 'lucide-react'; export default function SessionSharingSection() { + const envBaseUrlShare = window.appConfig.get('GOOSE_BASE_URL_SHARE'); + console.log('envBaseUrlShare', envBaseUrlShare); + + // If env is set, force sharing enabled and set the baseUrl accordingly. const [sessionSharingConfig, setSessionSharingConfig] = useState({ - enabled: false, - baseUrl: '', + enabled: envBaseUrlShare ? true : false, + baseUrl: envBaseUrlShare || '', }); const [urlError, setUrlError] = useState(''); - // Show a checkmark temporarily when the user’s input is valid - const [urlSaved, setUrlSaved] = useState(false); + // isUrlConfigured is true if the user has configured a baseUrl and it is valid. + const isUrlConfigured = + !envBaseUrlShare && sessionSharingConfig.enabled && isValidUrl(sessionSharingConfig.baseUrl); - // Load session sharing config from localStorage + // Only load saved config from localStorage if the env variable is not provided. useEffect(() => { - const savedSessionConfig = localStorage.getItem('session_sharing_config'); - if (savedSessionConfig) { - try { - const config = JSON.parse(savedSessionConfig); - setSessionSharingConfig(config); - } catch (error) { - console.error('Error parsing session sharing config:', error); + if (!envBaseUrlShare) { + const savedSessionConfig = localStorage.getItem('session_sharing_config'); + if (savedSessionConfig) { + try { + const config = JSON.parse(savedSessionConfig); + setSessionSharingConfig(config); + } catch (error) { + console.error('Error parsing session sharing config:', error); + } } } - }, []); + }, [envBaseUrlShare]); - // Helper to check if the user’s input is a valid URL + // Helper to check if the user's input is a valid URL function isValidUrl(value: string): boolean { if (!value) return false; try { @@ -35,8 +42,11 @@ export default function SessionSharingSection() { } } - // Handle toggling "Enable Session Sharing" - const handleEnableToggle = () => { + // Toggle sharing (only allowed when env is not set). + const toggleSharing = () => { + if (envBaseUrlShare) { + return; // Do nothing if the environment variable forces sharing. + } setSessionSharingConfig((prev) => { const updated = { ...prev, enabled: !prev.enabled }; localStorage.setItem('session_sharing_config', JSON.stringify(updated)); @@ -56,12 +66,6 @@ export default function SessionSharingSection() { setUrlError(''); const updated = { ...sessionSharingConfig, baseUrl: newBaseUrl }; localStorage.setItem('session_sharing_config', JSON.stringify(updated)); - - // Show the checkmark temporarily - setUrlSaved(true); - setTimeout(() => { - setUrlSaved(false); - }, 2000); } else { setUrlError('Invalid URL format. Please enter a valid URL (e.g. https://example.com/api).'); } @@ -74,30 +78,46 @@ export default function SessionSharingSection() {
-

- You can enable session sharing to share your sessions with others. You'll then need to - enter the base URL for the session sharing API endpoint. Anyone with access to the same - API and sharing session enabled will be able to see your sessions. -

+ {envBaseUrlShare ? ( +

+ Session sharing is configured but fully opt-in — your sessions are only shared when you + explicitly click the share button. +

+ ) : ( +

+ You can enable session sharing to share your sessions with others. You'll then need to + enter the base URL for the session sharing API endpoint. Anyone with access to the same + API and sharing session enabled will be able to see your sessions. +

+ )}
- {/* Enable Session Sharing toggle */} + {/* Toggle for enabling session sharing */}
- + {envBaseUrlShare ? ( + + ) : ( + + )}
{/* Base URL field (only visible if enabled) */} @@ -110,7 +130,7 @@ export default function SessionSharingSection() { > Base URL - {urlSaved && } + {isUrlConfigured && }
{urlError &&

{urlError}

} diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 325b3742..813b8ad2 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -122,8 +122,18 @@ const generateSecretKey = () => { return key; }; +const getSharingUrl = () => { + // checks app env for sharing url + loadShellEnv(app.isPackaged); // will try to take it from the zshrc file + // if GOOSE_BASE_URL_SHARE is found, we will set process.env.GOOSE_BASE_URL_SHARE, otherwise we return what it is set + // to in the env at bundle time + return process.env.GOOSE_BASE_URL_SHARE; +}; + let [provider, model] = getGooseProvider(); +let sharingUrl = getSharingUrl(); + let appConfig = { GOOSE_PROVIDER: provider, GOOSE_MODEL: model, @@ -170,6 +180,7 @@ const createChat = async ( GOOSE_PORT: port, GOOSE_WORKING_DIR: working_dir, REQUEST_DIR: dir, + GOOSE_BASE_URL_SHARE: sharingUrl, botConfig: botConfig, }), ],