(
toolChoice:
| 'auto'
| 'none'
| { type: 'function'; function?: { name: string }; name?: string }
| { type: 'tool'; name: string }
| { type: 'any'; any: { model: string; name: string } }
| undefined
)
| 128 | * Converts tool_choice to the Responses API format. |
| 129 | */ |
| 130 | export function toResponsesToolChoice( |
| 131 | toolChoice: |
| 132 | | 'auto' |
| 133 | | 'none' |
| 134 | | { type: 'function'; function?: { name: string }; name?: string } |
| 135 | | { type: 'tool'; name: string } |
| 136 | | { type: 'any'; any: { model: string; name: string } } |
| 137 | | undefined |
| 138 | ): 'auto' | 'none' | { type: 'function'; name: string } | undefined { |
| 139 | if (!toolChoice) { |
| 140 | return undefined |
| 141 | } |
| 142 | |
| 143 | if (typeof toolChoice === 'string') { |
| 144 | return toolChoice |
| 145 | } |
| 146 | |
| 147 | if (toolChoice.type === 'function') { |
| 148 | const name = toolChoice.name ?? toolChoice.function?.name |
| 149 | return name ? { type: 'function', name } : undefined |
| 150 | } |
| 151 | |
| 152 | return 'auto' |
| 153 | } |
| 154 | |
| 155 | function isRecord(value: unknown): value is Record<string, unknown> { |
| 156 | return typeof value === 'object' && value !== null |
no outgoing calls
no test coverage detected