From c4e6d4c3ef9b26f0541000d1514a34a56226a0a8 Mon Sep 17 00:00:00 2001 From: Mic Neale Date: Wed, 4 Dec 2024 19:02:44 +1100 Subject: [PATCH] show recent ones always --- ui/desktop/src/LauncherWindow.tsx | 2 +- ui/desktop/src/components/SessionPIlls.tsx | 68 +++++++++++++++++----- ui/desktop/src/main.ts | 4 +- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/ui/desktop/src/LauncherWindow.tsx b/ui/desktop/src/LauncherWindow.tsx index b3054fa5b..adfadc485 100644 --- a/ui/desktop/src/LauncherWindow.tsx +++ b/ui/desktop/src/LauncherWindow.tsx @@ -5,7 +5,7 @@ declare global { electron: { getConfig(): object; getSession(sessionId: string): object; - listSessions(dir: string): Array; + listSessions(dir?: string): Array; logInfo(info: string): object; saveSession(sessionData: { name: string; messages: Array; directory: string }): object; hideWindow: () => void; diff --git a/ui/desktop/src/components/SessionPIlls.tsx b/ui/desktop/src/components/SessionPIlls.tsx index 9179c7b42..647a88425 100644 --- a/ui/desktop/src/components/SessionPIlls.tsx +++ b/ui/desktop/src/components/SessionPIlls.tsx @@ -2,39 +2,81 @@ import React, { useEffect, useState } from "react" export default function SessionPills() { const [sessions, setSessions] = useState([]); + const [latestSessions, setLatestSessions] = useState([]); - const dir = window.appConfig.get("GOOSE_WORKING_DIR"); + const workingDir = window.appConfig.get("GOOSE_WORKING_DIR"); + useEffect(() => { async function loadSessions() { - - window.electron.logInfo(`_------______________ Looking for sessions related to ${dir}`); - const sessions = await window.electron.listSessions(dir); + window.electron.logInfo(`_------______________ Looking for sessions related to ${workingDir}`); + const sessions = await window.electron.listSessions(workingDir); - window.electron.logInfo(`_------______________ Found ${sessions.length} sessions in ${dir}`); + window.electron.logInfo(`_------______________ Found ${sessions.length} sessions in ${workingDir}`); window.electron.logInfo(`Sessions: ${JSON.stringify(sessions)}`); setSessions(sessions); }; loadSessions(); }, []); - if (sessions.length === 0) { + useEffect(() => { + async function loadSessions() { + const sessions = await window.electron.listSessions(); + setLatestSessions(sessions); + }; + loadSessions(); + }, []); + + if (sessions.length === 0 && latestSessions.length === 0) { return null; } + // Create a combined list of sessions, prioritizing latest ones and removing duplicates + const combinedSessions = []; + const seenNames = new Set(); + + // Add at least one latest session if available + if (latestSessions.length > 0) { + const latest = latestSessions[0]; + combinedSessions.push({ ...latest, isLatest: true }); + seenNames.add(latest.name); + } + + // Add remaining latest sessions (up to 5 total) + for (let i = 1; i < latestSessions.length && combinedSessions.length < 5; i++) { + const session = latestSessions[i]; + if (!seenNames.has(session.name)) { + combinedSessions.push({ ...session, isLatest: true }); + seenNames.add(session.name); + } + } + + // Fill remaining slots with regular sessions (up to 5 total) + for (const session of sessions) { + if (combinedSessions.length >= 5) break; + if (!seenNames.has(session.name)) { + combinedSessions.push({ ...session, isLatest: false }); + seenNames.add(session.name); + } + } + return (
-
-
Previous gooses:
- {sessions.map((session) => ( + {combinedSessions.map((session) => (
{ - window.electron.createChatWindow(undefined, dir, session); - }}> - {session} + window.electron.createChatWindow(undefined, session.directory, session.name); + }} + title={session.directory}> + + {`${session.name.slice(0, 50)}`} + {session.isLatest && !(session.directory === workingDir) && ( + (recent) + )}
- ))} + ))}
) diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 2ddd34c1c..ceb42fc71 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -385,11 +385,11 @@ app.whenReady().then(async () => { if (dir) { console.log("server: looking for sessions that match directory", dir); const results = sessions - .map(session => session.name); + .map(session => ({ name: session.name, directory: session.directory })); console.log("server: found sessions:", results); return results; } else { - return sessions.map(session => session.name); + return sessions.map(session => ({ name: session.name, directory: session.directory })); } } catch (error) { console.error('Failed to load sessions:', error);