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
This commit is contained in:
kaitranntt
2025-12-18 02:27:11 -05:00
parent 9a8eea82c5
commit fee241d00b
+47 -1
View File
@@ -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<void> => {
try {
@@ -1619,10 +1623,12 @@ apiRoutes.get('/copilot/status', async (_req: Request, res: Response): Promise<v
const copilotConfig = config.copilot ?? DEFAULT_COPILOT_CONFIG;
const status = await getCopilotStatus(copilotConfig);
const installed = isCopilotApiInstalled();
const version = getCopilotInstalledVersion();
res.json({
enabled: copilotConfig.enabled,
installed,
version,
authenticated: status.auth.authenticated,
daemon_running: status.daemon.running,
port: copilotConfig.port,
@@ -1764,6 +1770,46 @@ apiRoutes.post('/copilot/daemon/stop', async (_req: Request, res: Response): Pro
}
});
/**
* POST /api/copilot/install - Install copilot-api
* Auto-installs latest version or specific version if provided
*/
apiRoutes.post('/copilot/install', async (req: Request, res: Response): Promise<void> => {
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