mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
feat: 添加gemini协议适配 (#125)
* feat: 添加gemini协议适配 * Remove unrelated local files from Gemini PR
This commit is contained in:
@@ -640,26 +640,53 @@ export function assistantMessageToMessageParam(
|
||||
} else {
|
||||
return {
|
||||
role: 'assistant',
|
||||
content: message.message.content.map((_, i) => ({
|
||||
..._,
|
||||
...(i === message.message.content.length - 1 &&
|
||||
_.type !== 'thinking' &&
|
||||
_.type !== 'redacted_thinking' &&
|
||||
(feature('CONNECTOR_TEXT') ? !isConnectorTextBlock(_) : true)
|
||||
? enablePromptCaching
|
||||
? { cache_control: getCacheControl({ querySource }) }
|
||||
: {}
|
||||
: {}),
|
||||
})),
|
||||
content: message.message.content.map((_, i) => {
|
||||
const contentBlock = stripGeminiProviderMetadata(_)
|
||||
return {
|
||||
...contentBlock,
|
||||
...(i === message.message.content.length - 1 &&
|
||||
contentBlock.type !== 'thinking' &&
|
||||
contentBlock.type !== 'redacted_thinking' &&
|
||||
(feature('CONNECTOR_TEXT')
|
||||
? !isConnectorTextBlock(contentBlock)
|
||||
: true)
|
||||
? enablePromptCaching
|
||||
? { cache_control: getCacheControl({ querySource }) }
|
||||
: {}
|
||||
: {}),
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
role: 'assistant',
|
||||
content: message.message.content,
|
||||
content:
|
||||
typeof message.message.content === 'string'
|
||||
? message.message.content
|
||||
: message.message.content.map(stripGeminiProviderMetadata),
|
||||
}
|
||||
}
|
||||
|
||||
function stripGeminiProviderMetadata<T extends BetaContentBlockParam | string>(
|
||||
contentBlock: T,
|
||||
): T {
|
||||
if (
|
||||
typeof contentBlock === 'string' ||
|
||||
!('_geminiThoughtSignature' in contentBlock)
|
||||
) {
|
||||
return contentBlock
|
||||
}
|
||||
|
||||
const {
|
||||
_geminiThoughtSignature: _unusedGeminiThoughtSignature,
|
||||
...rest
|
||||
} = contentBlock as T & {
|
||||
_geminiThoughtSignature?: string
|
||||
}
|
||||
return rest as T
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
getToolPermissionContext: () => Promise<ToolPermissionContext>
|
||||
model: string
|
||||
@@ -1310,6 +1337,19 @@ async function* queryModel(
|
||||
return
|
||||
}
|
||||
|
||||
if (getAPIProvider() === 'gemini') {
|
||||
const { queryModelGemini } = await import('./gemini/index.js')
|
||||
yield* queryModelGemini(
|
||||
messagesForAPI,
|
||||
systemPrompt,
|
||||
filteredTools,
|
||||
signal,
|
||||
options,
|
||||
thinkingConfig,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Instrumentation: Track message count after normalization
|
||||
logEvent('tengu_api_after_normalize', {
|
||||
postNormalizedMessageCount: messagesForAPI.length,
|
||||
|
||||
Reference in New Issue
Block a user