From 48c14f4e1b19660c3e827e4e56a23d7e0cdc5c77 Mon Sep 17 00:00:00 2001 From: shaw Date: Sat, 14 Mar 2026 12:04:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A41m=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=92=8C=E9=85=8D=E5=A5=97=E7=9A=84apikey?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/middleware/auth.js | 1 - src/models/redis.js | 2 +- src/routes/admin/apiKeys.js | 19 ----------- src/routes/api.js | 19 ----------- src/services/apiKeyService.js | 4 --- .../apikeys/BatchEditApiKeyModal.vue | 34 +------------------ .../components/apikeys/CreateApiKeyModal.vue | 25 +------------- .../components/apikeys/EditApiKeyModal.vue | 27 --------------- 8 files changed, 3 insertions(+), 128 deletions(-) diff --git a/src/middleware/auth.js b/src/middleware/auth.js index df4ccaa3..1b446093 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1313,7 +1313,6 @@ const authenticateApiKey = async (req, res, next) => { restrictedModels: validation.keyData.restrictedModels, enableClientRestriction: validation.keyData.enableClientRestriction, allowedClients: validation.keyData.allowedClients, - allow1mContext: validation.keyData.allow1mContext, dailyCostLimit: validation.keyData.dailyCostLimit, dailyCost: validation.keyData.dailyCost, totalCostLimit: validation.keyData.totalCostLimit, diff --git a/src/models/redis.js b/src/models/redis.js index 122011df..10323af6 100644 --- a/src/models/redis.js +++ b/src/models/redis.js @@ -773,7 +773,7 @@ class RedisClient { const parsed = { ...data } // 布尔字段 - const boolFields = ['isActive', 'enableModelRestriction', 'isDeleted', 'allow1mContext'] + const boolFields = ['isActive', 'enableModelRestriction', 'isDeleted'] for (const field of boolFields) { if (parsed[field] !== undefined) { parsed[field] = parsed[field] === 'true' diff --git a/src/routes/admin/apiKeys.js b/src/routes/admin/apiKeys.js index a70776c3..cff0fb65 100644 --- a/src/routes/admin/apiKeys.js +++ b/src/routes/admin/apiKeys.js @@ -1483,7 +1483,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => { restrictedModels, enableClientRestriction, allowedClients, - allow1mContext, dailyCostLimit, totalCostLimit, weeklyOpusCostLimit, @@ -1563,10 +1562,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => { return res.status(400).json({ error: 'Allowed clients must be an array' }) } - if (allow1mContext !== undefined && typeof allow1mContext !== 'boolean') { - return res.status(400).json({ error: 'allow1mContext must be a boolean' }) - } - // 验证标签字段 if (tags !== undefined && !Array.isArray(tags)) { return res.status(400).json({ error: 'Tags must be an array' }) @@ -1667,7 +1662,6 @@ router.post('/api-keys', authenticateAdmin, async (req, res) => { restrictedModels, enableClientRestriction, allowedClients, - allow1mContext, dailyCostLimit, totalCostLimit, weeklyOpusCostLimit, @@ -1719,7 +1713,6 @@ router.post('/api-keys/batch', authenticateAdmin, async (req, res) => { restrictedModels, enableClientRestriction, allowedClients, - allow1mContext, dailyCostLimit, totalCostLimit, weeklyOpusCostLimit, @@ -1785,7 +1778,6 @@ router.post('/api-keys/batch', authenticateAdmin, async (req, res) => { restrictedModels, enableClientRestriction, allowedClients, - allow1mContext, dailyCostLimit, totalCostLimit, weeklyOpusCostLimit, @@ -1947,9 +1939,6 @@ router.put('/api-keys/batch', authenticateAdmin, async (req, res) => { if (updates.serviceRates !== undefined) { finalUpdates.serviceRates = updates.serviceRates } - if (updates.allow1mContext !== undefined) { - finalUpdates.allow1mContext = updates.allow1mContext - } if (updates.weeklyResetDay !== undefined) { const day = Number(updates.weeklyResetDay) if (Number.isInteger(day) && day >= 1 && day <= 7) { @@ -2090,7 +2079,6 @@ router.put('/api-keys/:keyId', authenticateAdmin, async (req, res) => { restrictedModels, enableClientRestriction, allowedClients, - allow1mContext, expiresAt, dailyCostLimit, totalCostLimit, @@ -2224,13 +2212,6 @@ router.put('/api-keys/:keyId', authenticateAdmin, async (req, res) => { updates.allowedClients = allowedClients } - if (allow1mContext !== undefined) { - if (typeof allow1mContext !== 'boolean') { - return res.status(400).json({ error: 'allow1mContext must be a boolean' }) - } - updates.allow1mContext = allow1mContext - } - // 处理过期时间字段 if (expiresAt !== undefined) { if (expiresAt === null) { diff --git a/src/routes/api.js b/src/routes/api.js index b018590a..0ccba4b9 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -197,18 +197,6 @@ async function handleMessagesRequest(req, res) { } } - // 检测 1M 上下文窗口请求(anthropic-beta 包含 context-1m) - const betaHeader = (req.headers['anthropic-beta'] || '').toLowerCase() - const is1mContextRequest = betaHeader.includes('context-1m') - if (is1mContextRequest && !req.apiKey.allow1mContext) { - return res.status(403).json({ - error: { - type: 'forbidden', - message: '该 API Key 未启用 1M 上下文窗口,请联系管理员开启或切换为非 [1m] 模型' - } - }) - } - logger.api('📥 /v1/messages request received', { model: req.body.model || null, forcedVendor, @@ -389,13 +377,6 @@ async function handleMessagesRequest(req, res) { throw error } - // 1M 上下文窗口:记录日志(admin 已通过 allow1mContext 授权,信任其决定) - if (is1mContextRequest) { - logger.api( - `📐 1M context request allowed for key: ${req.apiKey.name}, accountType: ${accountType}` - ) - } - // 🔗 在成功调度后建立会话绑定(仅 claude-official 类型) // claude-official 只接受:1) 新会话 2) 已绑定的会话 if ( diff --git a/src/services/apiKeyService.js b/src/services/apiKeyService.js index 42efcadf..3875b75d 100644 --- a/src/services/apiKeyService.js +++ b/src/services/apiKeyService.js @@ -153,7 +153,6 @@ class ApiKeyService { restrictedModels = [], enableClientRestriction = false, allowedClients = [], - allow1mContext = false, dailyCostLimit = 0, totalCostLimit = 0, weeklyOpusCostLimit = 0, @@ -198,7 +197,6 @@ class ApiKeyService { restrictedModels: JSON.stringify(restrictedModels || []), enableClientRestriction: String(enableClientRestriction || false), allowedClients: JSON.stringify(allowedClients || []), - allow1mContext: String(allow1mContext || false), dailyCostLimit: String(dailyCostLimit || 0), totalCostLimit: String(totalCostLimit || 0), weeklyOpusCostLimit: String(weeklyOpusCostLimit || 0), @@ -453,7 +451,6 @@ class ApiKeyService { restrictedModels, enableClientRestriction: keyData.enableClientRestriction === 'true', allowedClients, - allow1mContext: keyData.allow1mContext === 'true', dailyCostLimit, totalCostLimit, weeklyOpusCostLimit, @@ -1231,7 +1228,6 @@ class ApiKeyService { 'restrictedModels', 'enableClientRestriction', 'allowedClients', - 'allow1mContext', 'dailyCostLimit', 'totalCostLimit', 'weeklyOpusCostLimit', diff --git a/web/admin-spa/src/components/apikeys/BatchEditApiKeyModal.vue b/web/admin-spa/src/components/apikeys/BatchEditApiKeyModal.vue index f6d629a6..18d6b8c8 100644 --- a/web/admin-spa/src/components/apikeys/BatchEditApiKeyModal.vue +++ b/web/admin-spa/src/components/apikeys/BatchEditApiKeyModal.vue @@ -322,32 +322,6 @@ - -
-
- -
- - - -
-
-

- 启用后允许使用 [1m] 模型(需要 Bedrock 账户支持) -

-
-
- -
-
- - -
-

- 启用后允许使用 [1m] 模型(需要 Bedrock 账户支持) -

-
-
- -
-
- - -
-

- 启用后允许使用 [1m] 模型(需要 Bedrock 账户支持) -

-
-