(toolCallId: string, toolNameById: Map<string, string>)
| 144 | } |
| 145 | |
| 146 | function toolCallIdToName(toolCallId: string, toolNameById: Map<string, string>): string { |
| 147 | const name = toolNameById.get(toolCallId); |
| 148 | if (name !== undefined) return name; |
| 149 | // Fallback: ids produced by this provider follow the format |
| 150 | // "{tool_name}_{id_suffix}" where `tool_name` may itself contain |
| 151 | // underscores (e.g. `fetch_image`) and `id_suffix` is a single trailing |
| 152 | // token without underscores (e.g. a random hex / UUID fragment). We strip |
| 153 | // the last "_<suffix>" segment by matching it explicitly — splitting on |
| 154 | // the first underscore would truncate multi-word tool names like |
| 155 | // `fetch_image_<id>` to just `fetch`. |
| 156 | const match = /^(.+)_[^_]+$/.exec(toolCallId); |
| 157 | return match?.[1] ?? toolCallId; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Convert a data URL or HTTP URL to a Google GenAI inline/file data part. |
no test coverage detected