( functionCalls: FunctionCall[] | undefined, toolConfig: ToolConfig | undefined, forcedTools: string[], usedForcedTools: string[] )
| 363 | * Checks for forced tool usage in Google Gemini responses |
| 364 | */ |
| 365 | export function checkForForcedToolUsage( |
| 366 | functionCalls: FunctionCall[] | undefined, |
| 367 | toolConfig: ToolConfig | undefined, |
| 368 | forcedTools: string[], |
| 369 | usedForcedTools: string[] |
| 370 | ): ForcedToolResult | null { |
| 371 | if (!functionCalls?.length) return null |
| 372 | |
| 373 | const adaptedToolCalls = functionCalls.map((fc) => ({ |
| 374 | name: fc.name ?? '', |
| 375 | arguments: (fc.args ?? {}) as Record<string, unknown>, |
| 376 | })) |
| 377 | |
| 378 | const result = trackForcedToolUsage( |
| 379 | adaptedToolCalls, |
| 380 | toolConfig, |
| 381 | logger, |
| 382 | 'google', |
| 383 | forcedTools, |
| 384 | usedForcedTools |
| 385 | ) |
| 386 | |
| 387 | if (!result) return null |
| 388 | |
| 389 | const nextToolConfig: ToolConfig | undefined = result.nextToolConfig?.functionCallingConfig?.mode |
| 390 | ? { |
| 391 | functionCallingConfig: { |
| 392 | mode: mapToFunctionCallingMode(result.nextToolConfig.functionCallingConfig.mode), |
| 393 | allowedFunctionNames: result.nextToolConfig.functionCallingConfig.allowedFunctionNames, |
| 394 | }, |
| 395 | } |
| 396 | : undefined |
| 397 | |
| 398 | return { |
| 399 | hasUsedForcedTool: result.hasUsedForcedTool, |
| 400 | usedForcedTools: result.usedForcedTools, |
| 401 | nextToolConfig, |
| 402 | } |
| 403 | } |
no test coverage detected