( response: any, toolChoice: any, forcedTools: string[], usedForcedTools: string[] )
| 58 | } |
| 59 | |
| 60 | export function checkForForcedToolUsage( |
| 61 | response: any, |
| 62 | toolChoice: any, |
| 63 | forcedTools: string[], |
| 64 | usedForcedTools: string[] |
| 65 | ): { hasUsedForcedTool: boolean; usedForcedTools: string[] } | null { |
| 66 | if (typeof toolChoice === 'object' && toolChoice !== null && Array.isArray(response.content)) { |
| 67 | const toolUses = response.content.filter((item: any) => item.type === 'tool_use') |
| 68 | |
| 69 | if (toolUses.length > 0) { |
| 70 | const adaptedToolCalls = toolUses.map((tool: any) => ({ name: tool.name })) |
| 71 | const adaptedToolChoice = |
| 72 | toolChoice.type === 'tool' ? { function: { name: toolChoice.name } } : toolChoice |
| 73 | |
| 74 | return trackForcedToolUsage( |
| 75 | adaptedToolCalls, |
| 76 | adaptedToolChoice, |
| 77 | logger, |
| 78 | 'anthropic', |
| 79 | forcedTools, |
| 80 | usedForcedTools |
| 81 | ) |
| 82 | } |
| 83 | } |
| 84 | return null |
| 85 | } |
no test coverage detected