import React, { useState, useEffect } from 'react'; import { Clock, MessageSquare, Folder, Share, Copy, Check, LoaderCircle } from 'lucide-react'; import { type SessionDetails } from '../../sessions'; import { SessionHeaderCard, SessionMessages } from './SessionViewComponents'; import { createSharedSession } from '../../sharedSessions'; import { Modal, ModalContent, ModalHeader, ModalTitle, ModalFooter } from '../ui/modal'; import { Button } from '../ui/button'; import { toast } from 'react-toastify'; interface SessionHistoryViewProps { session: SessionDetails; isLoading: boolean; error: string | null; onBack: () => void; onResume: () => void; onRetry: () => void; } const SessionHistoryView: React.FC = ({ session, isLoading, error, onBack, onResume, onRetry, }) => { const [isShareModalOpen, setIsShareModalOpen] = useState(false); const [shareLink, setShareLink] = useState(''); const [isSharing, setIsSharing] = useState(false); const [isCopied, setIsCopied] = useState(false); const [canShare, setCanShare] = useState(false); const [shareError, setShareError] = useState(null); useEffect(() => { const savedSessionConfig = localStorage.getItem('session_sharing_config'); if (savedSessionConfig) { try { const config = JSON.parse(savedSessionConfig); // If config.enabled is true and config.baseUrl is non-empty, we can share if (config.enabled && config.baseUrl) { setCanShare(true); } } catch (error) { console.error('Error parsing session sharing config:', error); } } }, []); const handleShare = async () => { setIsSharing(true); setShareError(null); try { // Get the session sharing configuration from localStorage const savedSessionConfig = localStorage.getItem('session_sharing_config'); if (!savedSessionConfig) { throw new Error('Session sharing is not configured. Please configure it in settings.'); } const config = JSON.parse(savedSessionConfig); if (!config.enabled || !config.baseUrl) { throw new Error('Session sharing is not enabled or base URL is not configured.'); } // Create a shared session const shareToken = await createSharedSession( config.baseUrl, session.messages, session.metadata.description || 'Shared Session' ); // Create the shareable link const shareableLink = `goose://sessions/${shareToken}`; setShareLink(shareableLink); setIsShareModalOpen(true); } catch (error) { console.error('Error sharing session:', error); setShareError(error instanceof Error ? error.message : 'Unknown error occurred'); toast.error( `Failed to share session: ${error instanceof Error ? error.message : 'Unknown error'}` ); } finally { setIsSharing(false); } }; const handleCopyLink = () => { navigator.clipboard .writeText(shareLink) .then(() => { setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); }) .catch((err) => { console.error('Failed to copy link:', err); toast.error('Failed to copy link to clipboard'); }); }; return (
{/* Top Row - back, info, reopen thread (fixed) */} {/* Session info row */}

{session.metadata.description || session.session_id}

{new Date(session.messages[0]?.created * 1000).toLocaleString()} {session.metadata.working_dir} {session.metadata.message_count} messages {session.metadata.total_tokens !== null && ( {session.metadata.total_tokens.toLocaleString()} tokens )}
Resume Session
{/* Share Link Modal */} Share Session
{shareLink}

Share this link with others to give them access to this session.
They will need to have Goose installed and session sharing configured.

); }; export default SessionHistoryView;