Files
Cli-Proxy-API-Management-Ce…/src/services/api/ampcode.ts
Supra4E8C e0584af365 feat: add Ampcode (Amp CLI Integration) support with configuration UI and i18n
- Add ampcodeApi service for upstream URL, API key, and model mappings management
  - Implement Ampcode configuration modal in AiProvidersPage
  - Add complete i18n translations for Ampcode features (en and zh-CN)
  - Enhance UsagePage with mobile-responsive chart improvements and legend display
  - Optimize chart rendering for smaller screens
  - Improve page layout styles (SystemPage, AiProvidersPage alignment)
2025-12-14 00:31:05 +08:00

41 lines
1.7 KiB
TypeScript

/**
* Amp CLI Integration (ampcode) 相关 API
*/
import { apiClient } from './client';
import { normalizeAmpcodeConfig, normalizeAmpcodeModelMappings } from './transformers';
import type { AmpcodeConfig, AmpcodeModelMapping } from '@/types';
export const ampcodeApi = {
async getAmpcode(): Promise<AmpcodeConfig> {
const data = await apiClient.get('/ampcode');
return normalizeAmpcodeConfig(data) ?? {};
},
updateUpstreamUrl: (url: string) => apiClient.put('/ampcode/upstream-url', { value: url }),
clearUpstreamUrl: () => apiClient.delete('/ampcode/upstream-url'),
updateUpstreamApiKey: (apiKey: string) => apiClient.put('/ampcode/upstream-api-key', { value: apiKey }),
clearUpstreamApiKey: () => apiClient.delete('/ampcode/upstream-api-key'),
updateRestrictManagementToLocalhost: (enabled: boolean) =>
apiClient.put('/ampcode/restrict-management-to-localhost', { value: enabled }),
async getModelMappings(): Promise<AmpcodeModelMapping[]> {
const data = await apiClient.get('/ampcode/model-mappings');
const list = data?.['model-mappings'] ?? data?.modelMappings ?? data?.items ?? data;
return normalizeAmpcodeModelMappings(list);
},
saveModelMappings: (mappings: AmpcodeModelMapping[]) =>
apiClient.put('/ampcode/model-mappings', { value: mappings }),
patchModelMappings: (mappings: AmpcodeModelMapping[]) =>
apiClient.patch('/ampcode/model-mappings', { value: mappings }),
clearModelMappings: () => apiClient.delete('/ampcode/model-mappings'),
deleteModelMappings: (fromList: string[]) =>
apiClient.delete('/ampcode/model-mappings', { data: { value: fromList } }),
updateForceModelMappings: (enabled: boolean) => apiClient.put('/ampcode/force-model-mappings', { value: enabled })
};