From 98b26d41426c178c21bc3d6d79e3fd266018061d Mon Sep 17 00:00:00 2001 From: Lily Delalande <119957291+lily-de@users.noreply.github.com> Date: Mon, 31 Mar 2025 16:18:16 -0400 Subject: [PATCH] ui: copy over base session sharing settings over to settings v2 (#1947) --- .../components/settings_v2/SettingsView.tsx | 3 + .../sessions/SessionSharingSection.tsx | 145 ++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 ui/desktop/src/components/settings_v2/sessions/SessionSharingSection.tsx diff --git a/ui/desktop/src/components/settings_v2/SettingsView.tsx b/ui/desktop/src/components/settings_v2/SettingsView.tsx index 9ccbec72..ffb8e984 100644 --- a/ui/desktop/src/components/settings_v2/SettingsView.tsx +++ b/ui/desktop/src/components/settings_v2/SettingsView.tsx @@ -5,6 +5,7 @@ import type { View } from '../../App'; import ExtensionsSection from './extensions/ExtensionsSection'; import ModelsSection from './models/ModelsSection'; import { ModeSection } from './mode/ModeSection'; +import SessionSharingSection from './sessions/SessionSharingSection'; export type SettingsViewOptions = { extensionId?: string; @@ -39,6 +40,8 @@ export default function SettingsView({ {/* Goose Modes */} + {/*Session sharing*/} + diff --git a/ui/desktop/src/components/settings_v2/sessions/SessionSharingSection.tsx b/ui/desktop/src/components/settings_v2/sessions/SessionSharingSection.tsx new file mode 100644 index 00000000..66942bab --- /dev/null +++ b/ui/desktop/src/components/settings_v2/sessions/SessionSharingSection.tsx @@ -0,0 +1,145 @@ +import React, { useState, useEffect } from 'react'; +import { Input } from '../../ui/input'; +import { Check, Lock } from 'lucide-react'; +import { Switch } from '../../ui/switch'; + +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: envBaseUrlShare ? true : false, + baseUrl: envBaseUrlShare || '', + }); + const [urlError, setUrlError] = useState(''); + // isUrlConfigured is true if the user has configured a baseUrl and it is valid. + const isUrlConfigured = + !envBaseUrlShare && sessionSharingConfig.enabled && isValidUrl(sessionSharingConfig.baseUrl); + + // Only load saved config from localStorage if the env variable is not provided. + useEffect(() => { + 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 + function isValidUrl(value: string): boolean { + if (!value) return false; + try { + new URL(value); + return true; + } catch { + return false; + } + } + + // 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)); + return updated; + }); + }; + + // Handle changes to the base URL field + const handleBaseUrlChange = (e: React.ChangeEvent) => { + const newBaseUrl = e.target.value; + setSessionSharingConfig((prev) => ({ + ...prev, + baseUrl: newBaseUrl, + })); + + if (isValidUrl(newBaseUrl)) { + setUrlError(''); + const updated = { ...sessionSharingConfig, baseUrl: newBaseUrl }; + localStorage.setItem('session_sharing_config', JSON.stringify(updated)); + } else { + setUrlError('Invalid URL format. Please enter a valid URL (e.g. https://example.com/api).'); + } + }; + + return ( +
+ {/*Title*/} +
+

Session sharing

+
+ +
+ {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. +

+ )} + +
+ {/* Toggle for enabling session sharing */} +
+ + {envBaseUrlShare ? ( + + ) : ( + + )} +
+ + {/* Base URL field (only visible if enabled) */} + {sessionSharingConfig.enabled && ( +
+
+ + {isUrlConfigured && } +
+
+ +
+ {urlError &&

{urlError}

} +
+ )} +
+
+
+ ); +}