From 18c1ba6c3c80e289e81c720797d33516f9557528 Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Sat, 20 Dec 2025 18:32:32 +0800 Subject: [PATCH] feat(ampcode): remove localhost-only management toggle --- src/i18n/locales/en.json | 2 -- src/i18n/locales/zh-CN.json | 2 -- src/pages/AiProvidersPage.tsx | 37 +++++++------------------------- src/services/api/ampcode.ts | 3 --- src/services/api/transformers.ts | 9 -------- src/types/ampcode.ts | 1 - 6 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 5af177c..6aa8914 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -200,8 +200,6 @@ "ampcode_upstream_api_key_current": "Current Amp official key: {{key}}", "ampcode_clear_upstream_api_key": "Clear official key", "ampcode_clear_upstream_api_key_confirm": "Are you sure you want to clear the Ampcode upstream API key (Amp official)?", - "ampcode_restrict_management_label": "Restrict Amp management routes to localhost", - "ampcode_restrict_management_hint": "When enabled, Amp management routes (/api/auth, /api/user, /api/threads, etc.) only accept 127.0.0.1/::1 (recommended).", "ampcode_force_model_mappings_label": "Force model mappings", "ampcode_force_model_mappings_hint": "When enabled, mappings override local API-key availability checks.", "ampcode_model_mappings_label": "Model mappings (from → to)", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 624fbb8..d9e8bb8 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -200,8 +200,6 @@ "ampcode_upstream_api_key_current": "当前Amp官方密钥: {{key}}", "ampcode_clear_upstream_api_key": "清除官方密钥", "ampcode_clear_upstream_api_key_confirm": "确定要清除 Ampcode 的 upstream API key(Amp官方)吗?", - "ampcode_restrict_management_label": "仅允许本机访问 Amp 管理路由", - "ampcode_restrict_management_hint": "开启后,/api/auth、/api/user、/api/threads 等 Amp 管理路由仅允许 127.0.0.1/::1 访问(推荐)。", "ampcode_force_model_mappings_label": "强制应用模型映射", "ampcode_force_model_mappings_hint": "开启后,模型映射将覆盖本地 API Key 可用性判断。", "ampcode_model_mappings_label": "模型映射 (from → to)", diff --git a/src/pages/AiProvidersPage.tsx b/src/pages/AiProvidersPage.tsx index 6399b44..76af866 100644 --- a/src/pages/AiProvidersPage.tsx +++ b/src/pages/AiProvidersPage.tsx @@ -49,7 +49,6 @@ interface OpenAIFormState { interface AmpcodeFormState { upstreamUrl: string; upstreamApiKey: string; - restrictManagementToLocalhost: boolean; forceModelMappings: boolean; mappingEntries: ModelEntry[]; } @@ -174,7 +173,6 @@ const entriesToAmpcodeMappings = (entries: ModelEntry[]): AmpcodeModelMapping[] const buildAmpcodeFormState = (ampcode?: AmpcodeConfig | null): AmpcodeFormState => ({ upstreamUrl: ampcode?.upstreamUrl ?? '', upstreamApiKey: '', - restrictManagementToLocalhost: ampcode?.restrictManagementToLocalhost ?? true, forceModelMappings: ampcode?.forceModelMappings ?? false, mappingEntries: ampcodeMappingsToEntries(ampcode?.modelMappings), }); @@ -701,9 +699,6 @@ export function AiProvidersPage() { await ampcodeApi.clearUpstreamUrl(); } - await ampcodeApi.updateRestrictManagementToLocalhost( - ampcodeForm.restrictManagementToLocalhost - ); await ampcodeApi.updateForceModelMappings(ampcodeForm.forceModelMappings); if (ampcodeLoaded || ampcodeMappingsDirty) { @@ -720,12 +715,18 @@ export function AiProvidersPage() { const previous = config?.ampcode ?? {}; const next: AmpcodeConfig = { - ...previous, upstreamUrl: upstreamUrl || undefined, - restrictManagementToLocalhost: ampcodeForm.restrictManagementToLocalhost, forceModelMappings: ampcodeForm.forceModelMappings, }; + if (previous.upstreamApiKey) { + next.upstreamApiKey = previous.upstreamApiKey; + } + + if (Array.isArray(previous.modelMappings)) { + next.modelMappings = previous.modelMappings; + } + if (overrideKey) { next.upstreamApiKey = overrideKey; } @@ -1505,16 +1506,6 @@ export function AiProvidersPage() { : t('common.not_set')} -
- - {t('ai_providers.ampcode_restrict_management_label')}: - - - {(config?.ampcode?.restrictManagementToLocalhost ?? true) - ? t('common.yes') - : t('common.no')} - -
{t('ai_providers.ampcode_force_model_mappings_label')}: @@ -1739,18 +1730,6 @@ export function AiProvidersPage() {
-
- - setAmpcodeForm((prev) => ({ ...prev, restrictManagementToLocalhost: value })) - } - disabled={ampcodeModalLoading || ampcodeSaving} - /> -
{t('ai_providers.ampcode_restrict_management_hint')}
-
-
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 { const data = await apiClient.get('/ampcode/model-mappings'); const list = data?.['model-mappings'] ?? data?.modelMappings ?? data?.items ?? data; diff --git a/src/services/api/transformers.ts b/src/services/api/transformers.ts index 98a1200..852889a 100644 --- a/src/services/api/transformers.ts +++ b/src/services/api/transformers.ts @@ -205,15 +205,6 @@ const normalizeAmpcodeConfig = (payload: any): AmpcodeConfig | undefined => { const upstreamApiKey = source['upstream-api-key'] ?? source.upstreamApiKey ?? source['upstream_api_key']; if (upstreamApiKey) config.upstreamApiKey = String(upstreamApiKey); - const restrictManagementToLocalhost = normalizeBoolean( - source['restrict-management-to-localhost'] ?? - source.restrictManagementToLocalhost ?? - source['restrict_management_to_localhost'] - ); - if (restrictManagementToLocalhost !== undefined) { - config.restrictManagementToLocalhost = restrictManagementToLocalhost; - } - const forceModelMappings = normalizeBoolean( source['force-model-mappings'] ?? source.forceModelMappings ?? source['force_model_mappings'] ); diff --git a/src/types/ampcode.ts b/src/types/ampcode.ts index 2530e8a..7668dee 100644 --- a/src/types/ampcode.ts +++ b/src/types/ampcode.ts @@ -10,7 +10,6 @@ export interface AmpcodeModelMapping { export interface AmpcodeConfig { upstreamUrl?: string; upstreamApiKey?: string; - restrictManagementToLocalhost?: boolean; modelMappings?: AmpcodeModelMapping[]; forceModelMappings?: boolean; }