diff --git a/src/web-server/routes.ts b/src/web-server/routes.ts index 30e9d4a0..14424d10 100644 --- a/src/web-server/routes.ts +++ b/src/web-server/routes.ts @@ -1606,12 +1606,16 @@ import { stopDaemon as stopCopilotDaemon, getAvailableModels as getCopilotModels, isCopilotApiInstalled, + ensureCopilotApi, + installCopilotApiVersion, + getCopilotApiInfo, + getInstalledVersion as getCopilotInstalledVersion, } from '../copilot'; import { DEFAULT_COPILOT_CONFIG } from '../config/unified-config-types'; import { loadOrCreateUnifiedConfig } from '../config/unified-config-loader'; /** - * GET /api/copilot/status - Get Copilot status (auth + daemon) + * GET /api/copilot/status - Get Copilot status (auth + daemon + install info) */ apiRoutes.get('/copilot/status', async (_req: Request, res: Response): Promise => { try { @@ -1619,10 +1623,12 @@ apiRoutes.get('/copilot/status', async (_req: Request, res: Response): Promise => { + try { + const { version } = req.body || {}; + + if (version) { + // Install specific version + await installCopilotApiVersion(version); + } else { + // Install latest version + await ensureCopilotApi(); + } + + const info = getCopilotApiInfo(); + res.json({ + success: true, + installed: info.installed, + version: info.version, + path: info.path, + }); + } catch (error) { + res.status(500).json({ error: (error as Error).message }); + } +}); + +/** + * GET /api/copilot/info - Get copilot-api installation info + */ +apiRoutes.get('/copilot/info', (_req: Request, res: Response): void => { + try { + const info = getCopilotApiInfo(); + res.json(info); + } catch (error) { + res.status(500).json({ error: (error as Error).message }); + } +}); + /** * GET /api/copilot/settings/raw - Get raw copilot.settings.json * Returns the raw JSON content for editing in the code editor