Files
claudecodeui/server/routes/cursor.js
Haileyesus 556cbd1a03 feat: load models through provider adapters
Provider model selection had outgrown a single hardcoded service.

The old service mixed shared caching with provider catalogs and CLI lookup details.

That made stale model lists more likely as providers changed on separate schedules.

Move model discovery behind each provider so lookup lives next to the integration.

The shared service now focuses on provider resolution, caching, persistence, and dedupe.

Return cache metadata and add bypassCache because model availability changes outside the app.

The UI and /models command can show freshness and let users force a provider refresh.

Surface model descriptions while keeping fallback catalogs for unavailable CLIs or SDKs.
2026-05-18 12:40:24 +03:00

53 lines
1.4 KiB
JavaScript

import express from 'express';
import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';
import { CURSOR_FALLBACK_MODELS } from '../modules/providers/list/cursor/cursor-models.provider.js';
const router = express.Router();
// GET /api/cursor/config - Read Cursor CLI configuration.
router.get('/config', async (req, res) => {
try {
const configPath = path.join(os.homedir(), '.cursor', 'cli-config.json');
try {
const configContent = await fs.readFile(configPath, 'utf8');
const config = JSON.parse(configContent);
res.json({
success: true,
config,
path: configPath,
});
} catch (error) {
// Config doesn't exist or is invalid, so return the UI default shape.
console.log('Cursor config not found or invalid:', error.message);
res.json({
success: true,
config: {
version: 1,
model: {
modelId: CURSOR_FALLBACK_MODELS.DEFAULT,
displayName: 'GPT-5',
},
permissions: {
allow: [],
deny: [],
},
},
isDefault: true,
});
}
} catch (error) {
console.error('Error reading Cursor config:', error);
res.status(500).json({
error: 'Failed to read Cursor configuration',
details: error.message,
});
}
});
export default router;