* Builds config for next iteration
( baseConfig: GenerateContentConfig, state: ExecutionState, forcedTools: string[], request: ProviderRequest, logger: ReturnType<typeof createLogger>, model: string )
| 302 | * Builds config for next iteration |
| 303 | */ |
| 304 | function buildNextConfig( |
| 305 | baseConfig: GenerateContentConfig, |
| 306 | state: ExecutionState, |
| 307 | forcedTools: string[], |
| 308 | request: ProviderRequest, |
| 309 | logger: ReturnType<typeof createLogger>, |
| 310 | model: string |
| 311 | ): GenerateContentConfig { |
| 312 | const nextConfig = { ...baseConfig } |
| 313 | const allForcedToolsUsed = |
| 314 | forcedTools.length > 0 && state.usedForcedTools.length === forcedTools.length |
| 315 | |
| 316 | if (allForcedToolsUsed && request.responseFormat) { |
| 317 | nextConfig.tools = undefined |
| 318 | nextConfig.toolConfig = undefined |
| 319 | if (isGemini3Model(model)) { |
| 320 | logger.info('Gemini 3: Stripping tools after forced tool execution, schema already set') |
| 321 | } else { |
| 322 | nextConfig.responseMimeType = 'application/json' |
| 323 | nextConfig.responseSchema = cleanSchemaForGemini(request.responseFormat.schema) as Schema |
| 324 | logger.info('Using structured output for final response after tool execution') |
| 325 | } |
| 326 | } else if (state.currentToolConfig) { |
| 327 | nextConfig.toolConfig = state.currentToolConfig |
| 328 | } else { |
| 329 | nextConfig.toolConfig = { functionCallingConfig: { mode: FunctionCallingConfigMode.AUTO } } |
| 330 | } |
| 331 | |
| 332 | return nextConfig |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Creates streaming execution result template |
no test coverage detected