mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-12 02:37:45 +08:00
Refactor CLI Config Manager and Add Provider Model Routes
- Removed deprecated constants and functions from cli-config-manager.ts. - Introduced new provider model presets in litellm-provider-models.ts for better organization and management of model information. - Created provider-routes.ts to handle API endpoints for retrieving provider information and models. - Added integration tests for provider routes to ensure correct functionality and response structure. - Implemented unit tests for settings persistence functions, covering various scenarios and edge cases. - Enhanced error handling and validation in the new routes and settings functions.
This commit is contained in:
@@ -29,8 +29,7 @@ import {
|
||||
loadCliConfig,
|
||||
getToolConfig,
|
||||
updateToolConfig,
|
||||
getFullConfigResponse,
|
||||
PREDEFINED_MODELS
|
||||
getFullConfigResponse
|
||||
} from '../../tools/cli-config-manager.js';
|
||||
import {
|
||||
loadClaudeCliTools,
|
||||
|
||||
78
ccw/src/core/routes/provider-routes.ts
Normal file
78
ccw/src/core/routes/provider-routes.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Provider Reference Routes Module
|
||||
* Handles read-only provider model reference API endpoints
|
||||
*/
|
||||
|
||||
import type { RouteContext } from './types.js';
|
||||
import {
|
||||
PROVIDER_MODELS,
|
||||
getAllProviders,
|
||||
getProviderModels
|
||||
} from '../../config/provider-models.js';
|
||||
|
||||
/**
|
||||
* Handle Provider Reference routes
|
||||
* @returns true if route was handled, false otherwise
|
||||
*/
|
||||
export async function handleProviderRoutes(ctx: RouteContext): Promise<boolean> {
|
||||
const { pathname, req, res } = ctx;
|
||||
|
||||
// ========== GET ALL PROVIDERS ==========
|
||||
// GET /api/providers
|
||||
if (pathname === '/api/providers' && req.method === 'GET') {
|
||||
try {
|
||||
const providers = getAllProviders().map(id => ({
|
||||
id,
|
||||
name: PROVIDER_MODELS[id].name,
|
||||
modelCount: PROVIDER_MODELS[id].models.length
|
||||
}));
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ success: true, providers }));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
success: false,
|
||||
error: (err as Error).message
|
||||
}));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========== GET MODELS FOR PROVIDER ==========
|
||||
// GET /api/providers/:provider/models
|
||||
const providerMatch = pathname.match(/^\/api\/providers\/([^\/]+)\/models$/);
|
||||
if (providerMatch && req.method === 'GET') {
|
||||
const provider = decodeURIComponent(providerMatch[1]);
|
||||
|
||||
try {
|
||||
const models = getProviderModels(provider);
|
||||
|
||||
if (models.length === 0) {
|
||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
success: false,
|
||||
error: `Provider not found: ${provider}`
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
success: true,
|
||||
provider,
|
||||
providerName: PROVIDER_MODELS[provider].name,
|
||||
models
|
||||
}));
|
||||
} catch (err) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
success: false,
|
||||
error: (err as Error).message
|
||||
}));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user