import fs from "fs"; import path from "path"; const BIN_NAME = "studioE5-agent"; function findVersionFile(): string | null { // Try a few common paths relative to the server workspace and Next.js build output. const candidates = [ path.join(process.cwd(), "..", "agent", "VERSION"), path.join(process.cwd(), "..", "..", "agent", "VERSION"), path.join(process.cwd(), "agent", "VERSION"), path.join(__dirname, "..", "..", "..", "agent", "VERSION"), path.join(__dirname, "..", "..", "agent", "VERSION"), "/app/agent-version", ]; for (const candidate of candidates) { if (fs.existsSync(candidate)) { return candidate; } } return null; } export function getAgentVersion(): string { const versionFile = findVersionFile(); if (versionFile) { return fs.readFileSync(versionFile, "utf-8").trim(); } // Fallback used when the agent workspace is not mounted (should not happen). return "0.3.9"; } export interface AgentDownloadUrls { windows: string; windowsZip: string; linux: string; mac: string; } export function getAgentDownloadUrls(version: string): AgentDownloadUrls { return { windows: `/${BIN_NAME}-v${version}.exe`, windowsZip: `/${BIN_NAME}-v${version}-windows.zip`, linux: `/${BIN_NAME}-v${version}`, mac: `/${BIN_NAME}-v${version}-mac`, }; } export function getAgentVersionInfo() { const version = getAgentVersion(); return { version, downloadUrls: getAgentDownloadUrls(version), }; }