Skip to content

Commit

Permalink
Print agent version name in bottom bar
Browse files Browse the repository at this point in the history
  • Loading branch information
zakiali committed Jan 9, 2025
1 parent cbbb253 commit 3e60fdd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 36 deletions.
31 changes: 18 additions & 13 deletions ui/desktop/src/components/BottomMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import React from 'react';
export default function BottomMenu({hasMessages}) {
return (
<div className="flex relative text-bottom-menu dark:text-bottom-menu-dark pl-[15px] text-[10px] h-[30px] leading-[30px] align-middle bg-bottom-menu-background dark:bg-bottom-menu-background-dark rounded-b-2xl">
<span
className="cursor-pointer"
onClick={async () => {
console.log("Opening directory chooser");
if (hasMessages) {
window.electron.directoryChooser();
} else {
window.electron.directoryChooser(true);
}
}}>
Working in {window.appConfig.get("GOOSE_WORKING_DIR")}
</span>
<div className="flex justify-between w-full pr-[15px]">
<span
className="cursor-pointer"
onClick={async () => {
console.log("Opening directory chooser");
if (hasMessages) {
window.electron.directoryChooser();
} else {
window.electron.directoryChooser(true);
}
}}>
Working in {window.appConfig.get("GOOSE_WORKING_DIR")}
</span>
<span>
Agent {window.appConfig.get("GOOSE_AGENT_VERSION") || "unknown"}
</span>
</div>
</div>
);
}
}
40 changes: 26 additions & 14 deletions ui/desktop/src/goosed.ts
Original file line number Diff line number Diff line change
@@ -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<number> => {
return new Promise((resolve, reject) => {
const server = createServer();


server.listen(0, '127.0.0.1', () => {
const { port } = server.address() as { port: number };
server.close(() => {
Expand All @@ -24,6 +19,21 @@ export const findAvailablePort = (): Promise<number> => {
});
};

// Function to fetch agent version from the server
const fetchAgentVersion = async (port: number): Promise<string> => {
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<boolean> => {
Expand All @@ -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';

Expand All @@ -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
Expand Down Expand Up @@ -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];
};
25 changes: 16 additions & 9 deletions ui/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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(),
};

Expand Down Expand Up @@ -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 },
Expand All @@ -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
})],
},
});

Expand Down

0 comments on commit 3e60fdd

Please sign in to comment.