(messages []map[string]any)
| 44 | } |
| 45 | |
| 46 | func BuildToolNameMap(messages []map[string]any) map[string]string { |
| 47 | nameMap := make(map[string]string) |
| 48 | for _, msg := range messages { |
| 49 | if msg["role"] != "assistant" { |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | content, ok := contentBlocks(msg["content"]) |
| 54 | if !ok { |
| 55 | continue |
| 56 | } |
| 57 | for _, item := range content { |
| 58 | itemType, _ := item["type"].(string) |
| 59 | |
| 60 | if itemType != "tool_use" { |
| 61 | continue |
| 62 | } |
| 63 | toolID := getValueFrom(item, "id") |
| 64 | toolName := getValueFrom(item, "name") |
| 65 | if toolID != "" { |
| 66 | nameMap[toolID] = toolName |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | return nameMap |
| 71 | } |
| 72 | |
| 73 | func getValueFrom(item map[string]any, k string) string { |
| 74 | value, ok := item[k].(string) |
no test coverage detected