feat: Add Gemini support with thought_signature fix (#404)
* feat: Add Gemini support with thought_signature fix and branding updates * fix: gate thought_signature preservation strictly to Gemini provider * fix: explicit extra_content destructuring to seal cross-provider tool search leak
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { feature } from 'bun:bundle'
|
import { feature } from 'bun:bundle'
|
||||||
|
import { getAPIProvider } from './model/providers.js'
|
||||||
import type { BetaUsage as Usage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
import type { BetaUsage as Usage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
||||||
import type {
|
import type {
|
||||||
ContentBlock,
|
ContentBlock,
|
||||||
@@ -1765,6 +1766,7 @@ export function stripCallerFieldFromAssistantMessage(
|
|||||||
id: block.id,
|
id: block.id,
|
||||||
name: block.name,
|
name: block.name,
|
||||||
input: block.input,
|
input: block.input,
|
||||||
|
...(getAPIProvider() === 'gemini' && (block as any).extra_content ? { extra_content: (block as any).extra_content } : {})
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@@ -2221,21 +2223,24 @@ export function normalizeMessagesForAPI(
|
|||||||
|
|
||||||
// When tool search is enabled, preserve all fields including 'caller'
|
// When tool search is enabled, preserve all fields including 'caller'
|
||||||
if (toolSearchEnabled) {
|
if (toolSearchEnabled) {
|
||||||
|
const { extra_content, ...restBlock } = block as any
|
||||||
return {
|
return {
|
||||||
...block,
|
...restBlock,
|
||||||
name: canonicalName,
|
name: canonicalName,
|
||||||
input: normalizedInput,
|
input: normalizedInput,
|
||||||
|
...(getAPIProvider() === 'gemini' && extra_content ? { extra_content } : {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When tool search is NOT enabled, explicitly construct tool_use
|
// When tool search is NOT enabled, explicitly construct tool_use
|
||||||
// block with only standard API fields to avoid sending fields like
|
// block with only standard API fields to avoid sending fields like
|
||||||
// 'caller' that may be stored in sessions from tool search runs
|
// 'caller' that may be stored in sessions from tool search runs
|
||||||
return {
|
return {
|
||||||
type: 'tool_use' as const,
|
type: 'tool_use' as const,
|
||||||
id: block.id,
|
id: block.id,
|
||||||
name: canonicalName,
|
name: canonicalName,
|
||||||
input: normalizedInput,
|
input: normalizedInput,
|
||||||
|
...(getAPIProvider() === 'gemini' && (block as any).extra_content ? { extra_content: (block as any).extra_content } : {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return block
|
return block
|
||||||
|
|||||||
Reference in New Issue
Block a user