|
1 | 1 | import { NextResponse, type NextResponse as NextResponseType } from 'next/server'; |
2 | 2 | import { type NextRequest } from 'next/server'; |
3 | | -import { isOpenCodeBasedClient, stripRequiredPrefix } from '@/lib/utils'; |
4 | | -import { applyTrackingIds } from '@/lib/ai-gateway/providerHash'; |
| 3 | +import { stripRequiredPrefix } from '@/lib/utils'; |
5 | 4 | import { extractPromptInfo } from '@/lib/ai-gateway/extractPromptInfo'; |
6 | 5 | import { determineFallbackFeature } from '@/lib/ai-gateway/determineFallbackFeature'; |
7 | 6 | import { |
@@ -57,7 +56,6 @@ import { |
57 | 56 | } from '@/lib/ai-gateway/llm-proxy-helpers'; |
58 | 57 | import { ProxyErrorType } from '@/lib/proxy-error-types'; |
59 | 58 | import { getBalanceAndOrgSettings } from '@/lib/organizations/organization-usage'; |
60 | | -import { repairTools, sanitizeBinaryToolResults } from '@/lib/ai-gateway/tool-calling'; |
61 | 59 | import { isDataCollectionExplicitlyDisallowed } from '@/lib/ai-gateway/providers/openrouter/types'; |
62 | 60 | import { |
63 | 61 | rewriteFreeModelResponse_ChatCompletions, |
@@ -98,11 +96,8 @@ import { isForbiddenFreeModel } from '@/lib/ai-gateway/forbidden-free-models'; |
98 | 96 | import { isCloudflareIP } from '@/lib/cloudflare-ip'; |
99 | 97 | import { isKiloAutoModel, KILO_AUTO_FREE_MODEL } from '@/lib/ai-gateway/auto-model'; |
100 | 98 | import { applyResolvedAutoModel } from '@/lib/ai-gateway/auto-model/resolution'; |
101 | | -import { fixOpenCodeDuplicateReasoning } from '@/lib/ai-gateway/providers/fixOpenCodeDuplicateReasoning'; |
102 | 99 | import type { MicrodollarUsageContext } from '@/lib/ai-gateway/processUsage.types'; |
103 | 100 | import { |
104 | | - enableReasoningSummaries, |
105 | | - fixResponsesRequest, |
106 | 101 | getMaxTokens, |
107 | 102 | hasMiddleOutTransform, |
108 | 103 | } from '@/lib/ai-gateway/providers/openrouter/request-helpers'; |
@@ -678,39 +673,21 @@ export async function POST(request: NextRequest): Promise<NextResponseType<unkno |
678 | 673 | op: 'http.client', |
679 | 674 | }); |
680 | 675 |
|
681 | | - applyTrackingIds(requestBodyParsed, effectiveProviderContext.provider, user.id, taskId ?? null); |
682 | | - |
683 | | - sanitizeBinaryToolResults(requestBodyParsed); |
684 | | - |
685 | | - if (requestBodyParsed.kind === 'chat_completions') { |
686 | | - // Mostly a workaround for bugs in the old extension. |
687 | | - repairTools(requestBodyParsed.body); |
688 | | - |
689 | | - if (isOpenCodeBasedClient(fraudHeaders)) { |
690 | | - // Workaround for bugs in the chat completions client. |
691 | | - fixOpenCodeDuplicateReasoning(effectiveModelIdLowerCased, requestBodyParsed.body, taskId); |
692 | | - } |
693 | | - } |
694 | | - |
695 | | - if (requestBodyParsed.kind === 'responses') { |
696 | | - fixResponsesRequest(requestBodyParsed.body); |
697 | | - } |
698 | | - |
699 | | - enableReasoningSummaries(requestBodyParsed); |
700 | | - |
701 | | - const toolsAvailable = getToolsAvailable(requestBodyParsed); |
702 | | - const toolsUsed = getToolsUsed(requestBodyParsed); |
703 | | - |
704 | 676 | const extraHeaders: Record<string, string> = {}; |
705 | 677 | applyProviderSpecificLogic( |
706 | 678 | effectiveProviderContext.provider, |
707 | 679 | effectiveModelIdLowerCased, |
708 | 680 | requestBodyParsed, |
709 | 681 | extraHeaders, |
710 | 682 | effectiveProviderContext.userByok, |
711 | | - fraudHeaders |
| 683 | + fraudHeaders, |
| 684 | + user.id, |
| 685 | + taskId ?? null |
712 | 686 | ); |
713 | 687 |
|
| 688 | + const toolsAvailable = getToolsAvailable(requestBodyParsed); |
| 689 | + const toolsUsed = getToolsUsed(requestBodyParsed); |
| 690 | + |
714 | 691 | // Capture the bounded prompt for experimented requests AFTER provider |
715 | 692 | // transforms have produced the canonical upstream body. Stored on the |
716 | 693 | // usage context so the async `after()` hook can persist it without |
|
0 commit comments