mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-11 02:21:58 +00:00
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:
@@ -1606,12 +1606,16 @@ import {
|
|||||||
stopDaemon as stopCopilotDaemon,
|
stopDaemon as stopCopilotDaemon,
|
||||||
getAvailableModels as getCopilotModels,
|
getAvailableModels as getCopilotModels,
|
||||||
isCopilotApiInstalled,
|
isCopilotApiInstalled,
|
||||||
|
ensureCopilotApi,
|
||||||
|
installCopilotApiVersion,
|
||||||
|
getCopilotApiInfo,
|
||||||
|
getInstalledVersion as getCopilotInstalledVersion,
|
||||||
} from '../copilot';
|
} from '../copilot';
|
||||||
import { DEFAULT_COPILOT_CONFIG } from '../config/unified-config-types';
|
import { DEFAULT_COPILOT_CONFIG } from '../config/unified-config-types';
|
||||||
import { loadOrCreateUnifiedConfig } from '../config/unified-config-loader';
|
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> => {
|
apiRoutes.get('/copilot/status', async (_req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
@@ -1619,10 +1623,12 @@ apiRoutes.get('/copilot/status', async (_req: Request, res: Response): Promise<v
|
|||||||
const copilotConfig = config.copilot ?? DEFAULT_COPILOT_CONFIG;
|
const copilotConfig = config.copilot ?? DEFAULT_COPILOT_CONFIG;
|
||||||
const status = await getCopilotStatus(copilotConfig);
|
const status = await getCopilotStatus(copilotConfig);
|
||||||
const installed = isCopilotApiInstalled();
|
const installed = isCopilotApiInstalled();
|
||||||
|
const version = getCopilotInstalledVersion();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
enabled: copilotConfig.enabled,
|
enabled: copilotConfig.enabled,
|
||||||
installed,
|
installed,
|
||||||
|
version,
|
||||||
authenticated: status.auth.authenticated,
|
authenticated: status.auth.authenticated,
|
||||||
daemon_running: status.daemon.running,
|
daemon_running: status.daemon.running,
|
||||||
port: copilotConfig.port,
|
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
|
* GET /api/copilot/settings/raw - Get raw copilot.settings.json
|
||||||
* Returns the raw JSON content for editing in the code editor
|
* Returns the raw JSON content for editing in the code editor
|
||||||
|
|||||||
Reference in New Issue
Block a user