From 3e60fdd6ec5a38eaf0c5e9148b62250895d9e68a Mon Sep 17 00:00:00 2001 From: Zaki Ali Date: Fri, 27 Dec 2024 16:17:43 -0800 Subject: [PATCH] Print agent version name in bottom bar --- ui/desktop/src/components/BottomMenu.tsx | 31 ++++++++++-------- ui/desktop/src/goosed.ts | 40 +++++++++++++++--------- ui/desktop/src/main.ts | 25 +++++++++------ 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/ui/desktop/src/components/BottomMenu.tsx b/ui/desktop/src/components/BottomMenu.tsx index 2809188dc..f42b8ad96 100644 --- a/ui/desktop/src/components/BottomMenu.tsx +++ b/ui/desktop/src/components/BottomMenu.tsx @@ -3,18 +3,23 @@ import React from 'react'; export default function BottomMenu({hasMessages}) { return (
- { - console.log("Opening directory chooser"); - if (hasMessages) { - window.electron.directoryChooser(); - } else { - window.electron.directoryChooser(true); - } - }}> - Working in {window.appConfig.get("GOOSE_WORKING_DIR")} - +
+ { + console.log("Opening directory chooser"); + if (hasMessages) { + window.electron.directoryChooser(); + } else { + window.electron.directoryChooser(true); + } + }}> + Working in {window.appConfig.get("GOOSE_WORKING_DIR")} + + + Agent {window.appConfig.get("GOOSE_AGENT_VERSION") || "unknown"} + +
); -} +} \ No newline at end of file diff --git a/ui/desktop/src/goosed.ts b/ui/desktop/src/goosed.ts index 749973702..a01e5e979 100644 --- a/ui/desktop/src/goosed.ts +++ b/ui/desktop/src/goosed.ts @@ -1,19 +1,14 @@ -import path from 'node:path'; -import { execSync, spawn } from 'child_process'; +import { spawn } from 'child_process'; +import { createServer } from 'net'; +import os from 'node:os'; import { getBinaryPath } from './utils/binaryPath'; -import { existsSync } from 'fs'; import log from './utils/logger'; -import os from 'node:os'; -import { createServer } from 'net'; -import { loadZshEnv } from './utils/loadEnv'; - // Find an available port to start goosed on export const findAvailablePort = (): Promise => { return new Promise((resolve, reject) => { const server = createServer(); - server.listen(0, '127.0.0.1', () => { const { port } = server.address() as { port: number }; server.close(() => { @@ -24,6 +19,21 @@ export const findAvailablePort = (): Promise => { }); }; +// Function to fetch agent version from the server +const fetchAgentVersion = async (port: number): Promise => { + try { + const response = await fetch(`http://127.0.0.1:${port}/api/agent/versions`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); + return data.current_version; + } catch (error) { + log.error('Failed to fetch agent version:', error); + return 'unknown'; + } +}; + // Goose process manager. Take in the app, port, and directory to start goosed in. // Check if goosed server is ready by polling the status endpoint const checkServerStatus = async (port: number, maxAttempts: number = 30, interval: number = 100): Promise => { @@ -48,7 +58,7 @@ const checkServerStatus = async (port: number, maxAttempts: number = 30, interva return false; }; -export const startGoosed = async (app, dir=null): Promise<[number, string]> => { +export const startGoosed = async (app, dir=null): Promise<[number, string, string]> => { // In will use this later to determine if we should start process const isDev = process.env.NODE_ENV === 'development'; @@ -61,7 +71,7 @@ export const startGoosed = async (app, dir=null): Promise<[number, string]> => { // Skip starting goosed if configured in dev mode if (isDev && !app.isPackaged && process.env.VITE_START_EMBEDDED_SERVER === 'no') { log.info('Skipping starting goosed in development mode'); - return [3000, dir]; + return [3000, dir, 'dev']; } // Get the goosed binary path using the shared utility @@ -123,8 +133,10 @@ export const startGoosed = async (app, dir=null): Promise<[number, string]> => { goosedProcess.kill(); }); - log.info(`Goosed server successfully started on port ${port}`); - return [port, dir]; -}; - + // Wait for the server to start and fetch the agent version + await new Promise(resolve => setTimeout(resolve, 1000)); // Give the server time to start + const agentVersion = await fetchAgentVersion(port); + log.info(`Goosed server successfully started on port ${port}`); + return [port, dir, agentVersion]; +}; \ No newline at end of file diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 39acfc81c..ee9e06197 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -1,14 +1,14 @@ +import { exec } from 'child_process'; import 'dotenv/config'; -import { loadZshEnv } from './utils/loadEnv'; -import { getBinaryPath } from './utils/binaryPath'; -import { app, BrowserWindow, Tray, Menu, globalShortcut, ipcMain, Notification, MenuItem, dialog, powerSaveBlocker } from 'electron'; +import { app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, MenuItem, Notification, powerSaveBlocker, Tray } from 'electron'; +import started from "electron-squirrel-startup"; import path from 'node:path'; import { startGoosed } from './goosed'; -import started from "electron-squirrel-startup"; +import { getBinaryPath } from './utils/binaryPath'; +import { loadZshEnv } from './utils/loadEnv'; import log from './utils/logger'; -import { exec } from 'child_process'; import { addRecentDir, loadRecentDirs } from './utils/recentDirs'; -import { EnvToggles, loadSettings, saveSettings, updateEnvironmentVariables, createEnvironmentMenu } from './utils/settings'; +import { createEnvironmentMenu, EnvToggles, loadSettings, saveSettings, updateEnvironmentVariables } from './utils/settings'; // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (started) app.quit(); @@ -70,6 +70,7 @@ let appConfig = { GOOSE_API_HOST: 'http://127.0.0.1', GOOSE_SERVER__PORT: 0, GOOSE_WORKING_DIR: '', + GOOSE_AGENT_VERSION: '', secretKey: generateSecretKey(), }; @@ -127,11 +128,11 @@ const createChat = async (app, query?: string, dir?: string) => { if (checkApiCredentials()) { return startGoosed(app, dir); } else { - return [0, '']; + return [0, '', '']; } } - const [port, working_dir] = await maybeStartGoosed(); + const [port, working_dir, agentVersion] = await maybeStartGoosed(); const mainWindow = new BrowserWindow({ titleBarStyle: 'hidden', trafficLightPosition: { x: 16, y: 10 }, @@ -145,7 +146,13 @@ const createChat = async (app, query?: string, dir?: string) => { icon: path.join(__dirname, '../images/icon'), webPreferences: { preload: path.join(__dirname, 'preload.js'), - additionalArguments: [JSON.stringify({ ...appConfig, GOOSE_SERVER__PORT: port, GOOSE_WORKING_DIR: working_dir, REQUEST_DIR: dir })], + additionalArguments: [JSON.stringify({ + ...appConfig, + GOOSE_SERVER__PORT: port, + GOOSE_WORKING_DIR: working_dir, + GOOSE_AGENT_VERSION: agentVersion, + REQUEST_DIR: dir + })], }, });