From fee241d00be4a573e04011dd84712f90ed2d4a1f Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 18 Dec 2025 02:27:11 -0500 Subject: [PATCH] feat(api): add copilot install and info endpoints - POST /api/copilot/install: install copilot-api (optional version) - GET /api/copilot/info: get install status, version, path - GET /api/copilot/status: include version in response --- src/web-server/routes.ts | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) 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