mirror of
https://github.com/Gitlawb/openclaude.git
synced 2026-08-24 10:14:19 -05:00
test(openai-shim): assert Gemini tool-use stream blocks in adapter test
Extend the responseAdapters geminiSseToAnthropic wrapper test to cover tool_use content_block_start, input_json_delta, and content_block_stop. Remove stale post-extraction imports from the openaiShim facade.
This commit is contained in:
@@ -17,8 +17,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
createOpenAIShimClient,
|
createOpenAIShimClient,
|
||||||
hasMistralApiHost,
|
hasMistralApiHost,
|
||||||
parseTextToolCalls,
|
|
||||||
parseXmlToolCalls,
|
|
||||||
} from './openaiShim.ts'
|
} from './openaiShim.ts'
|
||||||
import * as realGithubModelsCredentials from '../../utils/githubModelsCredentials.js'
|
import * as realGithubModelsCredentials from '../../utils/githubModelsCredentials.js'
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import {
|
|||||||
refreshCodexAccessTokenIfNeeded,
|
refreshCodexAccessTokenIfNeeded,
|
||||||
} from '../../utils/codexCredentials.js'
|
} from '../../utils/codexCredentials.js'
|
||||||
import { logForDebugging } from '../../utils/debug.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'
|
export { getStreamIdleTimeoutMs } from './openaiShim/streamControl.js'
|
||||||
import { isBareMode, isEnvTruthy } from '../../utils/envUtils.js'
|
import { isBareMode, isEnvTruthy } from '../../utils/envUtils.js'
|
||||||
import {
|
import {
|
||||||
@@ -68,10 +68,6 @@ import {
|
|||||||
resolveRouteCredentialValue,
|
resolveRouteCredentialValue,
|
||||||
} from '../../integrations/routeMetadata.js'
|
} from '../../integrations/routeMetadata.js'
|
||||||
import { getSessionId } from '../../bootstrap/state.js'
|
import { getSessionId } from '../../bootstrap/state.js'
|
||||||
import {
|
|
||||||
createThinkTagFilter,
|
|
||||||
stripThinkTags,
|
|
||||||
} from './thinkTagSanitizer.js'
|
|
||||||
import {
|
import {
|
||||||
codexStreamToAnthropic,
|
codexStreamToAnthropic,
|
||||||
collectCodexCompletedResponse,
|
collectCodexCompletedResponse,
|
||||||
@@ -80,19 +76,12 @@ import {
|
|||||||
convertToolsToResponsesTools,
|
convertToolsToResponsesTools,
|
||||||
performCodexRequest,
|
performCodexRequest,
|
||||||
type AnthropicStreamEvent,
|
type AnthropicStreamEvent,
|
||||||
type AnthropicUsage,
|
|
||||||
type ShimCreateParams,
|
type ShimCreateParams,
|
||||||
} from './codexShim.js'
|
} from './codexShim.js'
|
||||||
import {
|
import {
|
||||||
createRequestBodyPlanner,
|
createRequestBodyPlanner,
|
||||||
hydrateOpenAIShimCompatibilityEnv as hydrateRequestPlanningEnv,
|
hydrateOpenAIShimCompatibilityEnv as hydrateRequestPlanningEnv,
|
||||||
} from './openaiShim/requestPlanner.js'
|
} 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 {
|
import {
|
||||||
anthropicSsePassthrough,
|
anthropicSsePassthrough,
|
||||||
convertGeminiToAnthropicResponse,
|
convertGeminiToAnthropicResponse,
|
||||||
@@ -100,8 +89,6 @@ import {
|
|||||||
geminiSseToAnthropic,
|
geminiSseToAnthropic,
|
||||||
makeMessageId,
|
makeMessageId,
|
||||||
openaiStreamToAnthropic as convertOpenAIResponseStream,
|
openaiStreamToAnthropic as convertOpenAIResponseStream,
|
||||||
parseTextToolCalls,
|
|
||||||
parseXmlToolCalls,
|
|
||||||
} from './openaiShim/responseAdapters.js'
|
} from './openaiShim/responseAdapters.js'
|
||||||
export { parseTextToolCalls, parseXmlToolCalls } from './openaiShim/responseAdapters.js'
|
export { parseTextToolCalls, parseXmlToolCalls } from './openaiShim/responseAdapters.js'
|
||||||
import { compressToolHistory } from './compressToolHistory.js'
|
import { compressToolHistory } from './compressToolHistory.js'
|
||||||
@@ -138,10 +125,6 @@ import {
|
|||||||
markOpenAIRequestNonReplayable,
|
markOpenAIRequestNonReplayable,
|
||||||
} from './openaiErrorClassification.js'
|
} from './openaiErrorClassification.js'
|
||||||
import { redactSecretValueForDisplay, type SecretValueSource } from '../../utils/providerProfile.js'
|
import { redactSecretValueForDisplay, type SecretValueSource } from '../../utils/providerProfile.js'
|
||||||
import {
|
|
||||||
normalizeToolArguments,
|
|
||||||
hasToolFieldMapping,
|
|
||||||
} from './toolArgumentNormalization.js'
|
|
||||||
import { logApiCallStart, logApiCallEnd } from '../../utils/requestLogging.js'
|
import { logApiCallStart, logApiCallEnd } from '../../utils/requestLogging.js'
|
||||||
import {
|
import {
|
||||||
createStreamState,
|
createStreamState,
|
||||||
@@ -150,13 +133,6 @@ import {
|
|||||||
} from '../../utils/streamingOptimizer.js'
|
} from '../../utils/streamingOptimizer.js'
|
||||||
import { stableStringifyJson } from '../../utils/stableStringify.js'
|
import { stableStringifyJson } from '../../utils/stableStringify.js'
|
||||||
import {
|
import {
|
||||||
findXmlToolCallOpener as findXmlToolCallOpenerModule,
|
|
||||||
isHy3Model as isHy3ModelModule,
|
|
||||||
parseXmlToolCalls as parseXmlToolCallsModule,
|
|
||||||
trailingXmlOpenerPrefixLen as trailingXmlOpenerPrefixLenModule,
|
|
||||||
} from './openaiShim/xmlToolCallParsing.js'
|
|
||||||
import {
|
|
||||||
convertNonStreamingResponseToAnthropicMessage as convertResponseToAnthropicMessage,
|
|
||||||
type NonStreamingOpenAIResponse,
|
type NonStreamingOpenAIResponse,
|
||||||
} from './openaiShim/responseConversion.js'
|
} from './openaiShim/responseConversion.js'
|
||||||
import {
|
import {
|
||||||
@@ -190,17 +166,6 @@ import {
|
|||||||
convertMessages as convertAnthropicMessages,
|
convertMessages as convertAnthropicMessages,
|
||||||
convertSystemPrompt as convertSystemPromptImpl,
|
convertSystemPrompt as convertSystemPromptImpl,
|
||||||
} from './openaiShim/messageConversion.js'
|
} 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 {
|
import {
|
||||||
convertTools as convertToolsModule,
|
convertTools as convertToolsModule,
|
||||||
normalizeSchemaForOpenAI as normalizeSchemaForOpenAIModule,
|
normalizeSchemaForOpenAI as normalizeSchemaForOpenAIModule,
|
||||||
|
|||||||
@@ -120,6 +120,25 @@ test('geminiSseToAnthropic wrapper emits content, usage, and terminal stop', asy
|
|||||||
event.type === 'content_block_delta' &&
|
event.type === 'content_block_delta' &&
|
||||||
(event.delta as { text?: string })?.text === 'Inspecting.',
|
(event.delta as { text?: string })?.text === 'Inspecting.',
|
||||||
)).toBe(true)
|
)).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({
|
expect(events.at(-2)).toMatchObject({
|
||||||
type: 'message_delta',
|
type: 'message_delta',
|
||||||
delta: { stop_reason: 'tool_use' },
|
delta: { stop_reason: 'tool_use' },
|
||||||
|
|||||||
Reference in New Issue
Block a user