@@ -8,12 +8,10 @@ import { isDebugEnabled } from "../lib/debug-settings";
88import { isCyberPolicyCode } from "../lib/errors" ;
99import { redactSecretString } from "../lib/redact" ;
1010import { contentPartsToText } from "./image" ;
11- import { EMPTY_TOOL_OUTPUT_ANNOTATION , isWhitespaceOnlyTextPartArray } from "./empty-tool-output-annotation" ;
1211import { identifyRoutedModel } from "./identity" ;
1312import { peekReasoningForCall } from "../responses/reasoning-replay-cache" ;
1413import { buildNonOpenAIToolCatalogNudgeForTools , shouldInjectNonOpenAIToolCatalogNudge } from "./tool-catalog-nudge" ;
1514import { openRouterProviderPayload , resolveOpenRouterRouting } from "../providers/openrouter-routing" ;
16- import { resolveVercelGatewayRouting , vercelGatewayProviderPayload } from "../providers/vercel-gateway-routing" ;
1715import {
1816 canForwardForeignServiceTierForChatModel ,
1917 fastPolicyForModel ,
@@ -28,7 +26,6 @@ import {
2826} from "../providers/fastwire" ;
2927import { openaiChatCompletionsUrl } from "./openai-chat-url" ;
3028import { stripResponsesOnlyEncryptedMarker } from "./responses-tool-schema" ;
31- import { agentRouterDefaultHeaders , frameAgentRouterMessages } from "./agentrouter" ;
3229import {
3330 isXaiSchemaTarget ,
3431 lookupLocalJsonPointer ,
@@ -90,10 +87,7 @@ function openAIChatTransport(provider: OcxProviderConfig): {
9087 if ( ( provider . authMode === "key" || provider . authMode === "oauth" ) && ! provider . keyOptional && ! hasCredential ) {
9188 throw new Error ( `${ provider . adapter } requires a non-empty credential (authMode: ${ provider . authMode } )` ) ;
9289 }
93- const headers : Record < string , string > = {
94- "Content-Type" : "application/json" ,
95- ...agentRouterDefaultHeaders ( provider . baseUrl , provider . headers ) ,
96- } ;
90+ const headers : Record < string , string > = { "Content-Type" : "application/json" } ;
9791 if ( hasCredential ) headers . Authorization = `Bearer ${ provider . apiKey } ` ;
9892 if ( provider . headers ) Object . assign ( headers , provider . headers ) ;
9993 return { url : openaiChatCompletionsUrl ( provider . baseUrl ) , headers, hasCredential } ;
@@ -116,8 +110,8 @@ export function buildOpenAIChatPassthroughRequest(
116110 const { url, headers, hasCredential } = openAIChatTransport ( provider ) ;
117111
118112 const body : Record < string , unknown > = {
119- model : provider . modelSuffixBracketStrip ? stripBracketedModelSuffix ( modelId ) : modelId ,
120- messages : frameAgentRouterMessages ( provider . baseUrl , rawBody . messages ) ,
113+ model : provider . modelSuffixBracketStrip ? stripBracketedModelSuffix ( provider . modelMap ?. [ modelId ] ?? modelId ) : ( provider . modelMap ?. [ modelId ] ?? modelId ) ,
114+ messages : rawBody . messages ,
121115 stream,
122116 } ;
123117 for ( const field of CHAT_PASSTHROUGH_FIELDS ) {
@@ -126,8 +120,6 @@ export function buildOpenAIChatPassthroughRequest(
126120
127121 const openRouterRouting = resolveOpenRouterRouting ( provider , modelId ) ;
128122 if ( openRouterRouting ) body . provider = openRouterProviderPayload ( openRouterRouting ) ;
129- const vercelRouting = resolveVercelGatewayRouting ( provider , modelId ) ;
130- if ( vercelRouting ) body . provider = vercelGatewayProviderPayload ( vercelRouting ) ;
131123
132124 if ( modelInList ( provider . noTemperatureModels , modelId ) ) delete body . temperature ;
133125 if ( modelInList ( provider . noTopPModels , modelId ) ) delete body . top_p ;
@@ -596,22 +588,9 @@ function isNativeOpenAIChatTarget(provider: OcxProviderConfig): boolean {
596588 * being flattened to the "[image]" marker the model can't actually see. Data URLs and remote https
597589 * URLs are both valid in image_url.url, unlike Gemini inline_data which needs base64.
598590 */
599- function toolResultTextForWire ( content : string | OcxContentPart [ ] , annotateEmpty = false ) : string {
600- // An empty content array is a present-but-empty result; `contentPartsToText` would
601- // otherwise fall back to the "[image]" marker and hide the emptiness from the model.
602- if ( annotateEmpty && Array . isArray ( content ) && content . length === 0 ) return EMPTY_TOOL_OUTPUT_ANNOTATION ;
603- if ( typeof content === "string" ) {
604- if ( annotateEmpty && content . trim ( ) === "" ) return EMPTY_TOOL_OUTPUT_ANNOTATION ;
605- return content ;
606- }
591+ function toolResultTextForWire ( content : string | OcxContentPart [ ] ) : string {
592+ if ( typeof content === "string" ) return content ;
607593 const text = content . filter ( ( p ) => p . type === "text" ) . map ( ( p ) => ( p as OcxTextContent ) . text ) . join ( "" ) ;
608- // A whitespace-only text-part array is the array twin of a blank string; the
609- // shared emptiness contract (same module as the Responses adapter) annotates it
610- // instead of forwarding whitespace the model silently accepts. Image parts and
611- // any other non-text part keep the array non-empty.
612- if ( annotateEmpty && isWhitespaceOnlyTextPartArray ( content ) ) {
613- return EMPTY_TOOL_OUTPUT_ANNOTATION ;
614- }
615594 if ( text ) {
616595 const untransportableImages = content . filter ( ( p ) => p . type === "image" && ! p . imageUrl ) . length ;
617596 return `${ text } ${ "[image]" . repeat ( untransportableImages ) } ` ;
@@ -798,7 +777,7 @@ function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProviderCon
798777 out . push ( {
799778 role : "tool" ,
800779 tool_call_id : toolCallId ,
801- content : toolResultTextForWire ( msg . content , provider . annotateEmptyToolOutputs === true ) ,
780+ content : toolResultTextForWire ( msg . content ) ,
802781 } ) ;
803782 pendingToolResultImageParts . push ( ...toolResultImageChatParts ( msg . content ) ) ;
804783 pendingToolCalls . splice ( matchIdx , 1 ) ;
@@ -843,7 +822,7 @@ function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProviderCon
843822 out . push ( {
844823 role : "tool" ,
845824 tool_call_id : toolCallId ,
846- content : toolResultTextForWire ( msg . content , provider . annotateEmptyToolOutputs === true ) ,
825+ content : toolResultTextForWire ( msg . content ) ,
847826 } ) ;
848827 pendingToolResultImageParts . push ( ...toolResultImageChatParts ( msg . content ) ) ;
849828 flushToolResultImages ( ) ;
@@ -1400,12 +1379,12 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
14001379
14011380 buildRequest ( parsed : OcxParsedRequest ) {
14021381 const { url, headers, hasCredential } = openAIChatTransport ( provider ) ;
1403- const messages = frameAgentRouterMessages ( provider . baseUrl , messagesToChatFormat ( parsed , provider ) ) ;
1382+ const messages = messagesToChatFormat ( parsed , provider ) ;
14041383 const tools = toolsToChatFormatForProvider ( parsed , provider ) ;
14051384 const toolChoice = toolChoiceToChatFormat ( parsed . options . toolChoice , parsed . context . tools , provider ) ;
14061385
14071386 const body : Record < string , unknown > = {
1408- model : provider . modelSuffixBracketStrip ? stripBracketedModelSuffix ( parsed . modelId ) : parsed . modelId ,
1387+ model : provider . modelSuffixBracketStrip ? stripBracketedModelSuffix ( provider . modelMap ?. [ parsed . modelId ] ?? parsed . modelId ) : ( provider . modelMap ?. [ parsed . modelId ] ?? parsed . modelId ) ,
14091388 messages,
14101389 stream : parsed . stream ,
14111390 } ;
@@ -1427,8 +1406,6 @@ export function createOpenAIChatAdapter(provider: OcxProviderConfig): ProviderAd
14271406 const maxTokens = resolveMaxTokens ( provider , parsed ) ;
14281407 const openRouterRouting = resolveOpenRouterRouting ( provider , parsed . modelId ) ;
14291408 if ( openRouterRouting ) body . provider = openRouterProviderPayload ( openRouterRouting ) ;
1430- const vercelRouting = resolveVercelGatewayRouting ( provider , parsed . modelId ) ;
1431- if ( vercelRouting ) body . provider = vercelGatewayProviderPayload ( vercelRouting ) ;
14321409 if ( tools ) body . tools = tools ;
14331410 if ( tools && toolChoice !== undefined ) {
14341411 body . tool_choice = modelInList ( provider . autoToolChoiceOnlyModels , parsed . modelId )
0 commit comments