diff --git a/src/services/api/openaiShim.test.ts b/src/services/api/openaiShim.test.ts index 01e3c534b..baa973aa0 100644 --- a/src/services/api/openaiShim.test.ts +++ b/src/services/api/openaiShim.test.ts @@ -17,8 +17,6 @@ import { import { createOpenAIShimClient, hasMistralApiHost, - parseTextToolCalls, - parseXmlToolCalls, } from './openaiShim.ts' import * as realGithubModelsCredentials from '../../utils/githubModelsCredentials.js' diff --git a/src/services/api/openaiShim.ts b/src/services/api/openaiShim.ts index 8612bd558..00bd14627 100644 --- a/src/services/api/openaiShim.ts +++ b/src/services/api/openaiShim.ts @@ -42,7 +42,7 @@ import { refreshCodexAccessTokenIfNeeded, } from '../../utils/codexCredentials.js' import { logForDebugging } from '../../utils/debug.js' -import { anthropicSsePassthrough as parseAnthropicSsePassthrough, createReaderCanceller, createStreamAbortError, getStreamIdleTimeoutMs, readWithIdleTimeout, StreamIdleTimeoutError, throwIfStreamAborted } from './openaiShim/streamControl.js' +import { createStreamAbortError, getStreamIdleTimeoutMs, readWithIdleTimeout, StreamIdleTimeoutError } from './openaiShim/streamControl.js' export { getStreamIdleTimeoutMs } from './openaiShim/streamControl.js' import { isBareMode, isEnvTruthy } from '../../utils/envUtils.js' import { @@ -68,10 +68,6 @@ import { resolveRouteCredentialValue, } from '../../integrations/routeMetadata.js' import { getSessionId } from '../../bootstrap/state.js' -import { - createThinkTagFilter, - stripThinkTags, -} from './thinkTagSanitizer.js' import { codexStreamToAnthropic, collectCodexCompletedResponse, @@ -80,19 +76,12 @@ import { convertToolsToResponsesTools, performCodexRequest, type AnthropicStreamEvent, - type AnthropicUsage, type ShimCreateParams, } from './codexShim.js' import { createRequestBodyPlanner, hydrateOpenAIShimCompatibilityEnv as hydrateRequestPlanningEnv, } from './openaiShim/requestPlanner.js' -import { buildAnthropicUsageFromRawUsage } from './cacheMetrics.js' -import { - convertOpenAIStreamUsage, - openaiStreamToAnthropic as convertOpenAIStream, -} from './openaiShim/streamConversion.js' -import { geminiSseToAnthropic as convertGeminiStream } from './openaiShim/geminiStreamConversion.js' import { anthropicSsePassthrough, convertGeminiToAnthropicResponse, @@ -100,8 +89,6 @@ import { geminiSseToAnthropic, makeMessageId, openaiStreamToAnthropic as convertOpenAIResponseStream, - parseTextToolCalls, - parseXmlToolCalls, } from './openaiShim/responseAdapters.js' export { parseTextToolCalls, parseXmlToolCalls } from './openaiShim/responseAdapters.js' import { compressToolHistory } from './compressToolHistory.js' @@ -138,10 +125,6 @@ import { markOpenAIRequestNonReplayable, } from './openaiErrorClassification.js' import { redactSecretValueForDisplay, type SecretValueSource } from '../../utils/providerProfile.js' -import { - normalizeToolArguments, - hasToolFieldMapping, -} from './toolArgumentNormalization.js' import { logApiCallStart, logApiCallEnd } from '../../utils/requestLogging.js' import { createStreamState, @@ -150,13 +133,6 @@ import { } from '../../utils/streamingOptimizer.js' import { stableStringifyJson } from '../../utils/stableStringify.js' import { - findXmlToolCallOpener as findXmlToolCallOpenerModule, - isHy3Model as isHy3ModelModule, - parseXmlToolCalls as parseXmlToolCallsModule, - trailingXmlOpenerPrefixLen as trailingXmlOpenerPrefixLenModule, -} from './openaiShim/xmlToolCallParsing.js' -import { - convertNonStreamingResponseToAnthropicMessage as convertResponseToAnthropicMessage, type NonStreamingOpenAIResponse, } from './openaiShim/responseConversion.js' import { @@ -190,17 +166,6 @@ import { convertMessages as convertAnthropicMessages, convertSystemPrompt as convertSystemPromptImpl, } from './openaiShim/messageConversion.js' -import { - JSON_REPAIR_SUFFIXES, - couldBeRawToolCallsRequestedPrefix, - extractBalancedJson, - parseRawToolCallsRequestedText, - parseTextToolCalls as parseTextToolCallsModule, - repairPossiblyTruncatedObjectJson, - stripRanges, - type ParsedRawToolCall, - type ParsedTextToolCall, -} from './openaiShim/rawToolCallParsing.js' import { convertTools as convertToolsModule, normalizeSchemaForOpenAI as normalizeSchemaForOpenAIModule, diff --git a/src/services/api/openaiShim/responseAdapters.test.ts b/src/services/api/openaiShim/responseAdapters.test.ts index eebe5a0c6..b61dbaf90 100644 --- a/src/services/api/openaiShim/responseAdapters.test.ts +++ b/src/services/api/openaiShim/responseAdapters.test.ts @@ -120,6 +120,25 @@ test('geminiSseToAnthropic wrapper emits content, usage, and terminal stop', asy event.type === 'content_block_delta' && (event.delta as { text?: string })?.text === 'Inspecting.', )).toBe(true) + + const toolStartIndex = events.findIndex(event => + event.type === 'content_block_start' && + (event.content_block as { type?: string; name?: string })?.type === 'tool_use' && + (event.content_block as { name?: string })?.name === 'Read', + ) + expect(toolStartIndex).toBeGreaterThan(-1) + expect(events[toolStartIndex + 1]).toMatchObject({ + type: 'content_block_delta', + delta: { + type: 'input_json_delta', + partial_json: '{"file_path":"a.ts"}', + }, + }) + expect(events[toolStartIndex + 2]).toEqual({ + type: 'content_block_stop', + index: (events[toolStartIndex] as { index: number }).index, + }) + expect(events.at(-2)).toMatchObject({ type: 'message_delta', delta: { stop_reason: 'tool_use' },