From 3728dc0e8992883822d45ff1ac81de72fdbfc306 Mon Sep 17 00:00:00 2001 From: chenchen Date: Mon, 18 May 2026 21:47:43 +0800 Subject: [PATCH] Revert "fix: route all providers through proxy to patch thinking.type for Claude 4" This reverts commit a3cddb89c697c739a394478971b4233d7cb216cd. --- cc-haha/src/server/proxy/handler.ts | 77 ++++--------------- .../src/server/services/providerService.ts | 2 +- 2 files changed, 17 insertions(+), 62 deletions(-) diff --git a/cc-haha/src/server/proxy/handler.ts b/cc-haha/src/server/proxy/handler.ts index dc3dbe7..36bf7ba 100644 --- a/cc-haha/src/server/proxy/handler.ts +++ b/cc-haha/src/server/proxy/handler.ts @@ -18,17 +18,6 @@ import { openaiChatStreamToAnthropic } from './streaming/openaiChatStreamToAnthr import { openaiResponsesStreamToAnthropic } from './streaming/openaiResponsesStreamToAnthropic.js' import type { AnthropicRequest } from './transform/types.js' -/** - * Patch thinking parameter for newer Claude models (4.x / Opus 4.7+). - * These models require `thinking.type = "adaptive"` instead of `"enabled"`. - */ -function patchThinkingForModel(body: AnthropicRequest): void { - if (!body.thinking) return - if (body.thinking.type === 'enabled') { - body.thinking.type = 'adaptive' - } -} - const providerService = new ProviderService() export async function handleProxyRequest(req: Request, url: URL): Promise { @@ -64,6 +53,21 @@ export async function handleProxyRequest(req: Request, url: URL): Promise { - const url = `${baseUrl}/v1/messages` - - const headers: Record = { - 'Content-Type': 'application/json', - 'x-api-key': apiKey, - 'anthropic-version': originalReq.headers.get('anthropic-version') || '2023-06-01', - } - const authHeader = originalReq.headers.get('authorization') - if (authHeader) { - headers['Authorization'] = authHeader - } - - const upstream = await fetch(url, { - method: 'POST', - headers, - body: JSON.stringify(body), - signal: AbortSignal.timeout(600_000), - }) - - if (isStream && upstream.ok && upstream.body) { - return new Response(upstream.body, { - status: upstream.status, - headers: { - 'Content-Type': upstream.headers.get('Content-Type') || 'text/event-stream', - 'Cache-Control': 'no-cache', - Connection: 'keep-alive', - }, - }) - } - - const text = await upstream.text() - return new Response(text, { - status: upstream.status, - headers: { 'Content-Type': 'application/json; charset=utf-8' }, - }) -} - async function handleOpenaiChat( body: AnthropicRequest, baseUrl: string, diff --git a/cc-haha/src/server/services/providerService.ts b/cc-haha/src/server/services/providerService.ts index 815f787..e72208a 100644 --- a/cc-haha/src/server/services/providerService.ts +++ b/cc-haha/src/server/services/providerService.ts @@ -247,7 +247,7 @@ export class ProviderService { provider: SavedProvider, options?: { proxyPath?: string }, ): Record { - const needsProxy = provider.apiFormat != null + const needsProxy = provider.apiFormat != null && provider.apiFormat !== 'anthropic' const proxyPath = options?.proxyPath ?? '/proxy' const baseUrl = needsProxy ? `http://127.0.0.1:${ProviderService.serverPort}${proxyPath}`