pickToolByPriority checks a priority list first, then falls back to the first tool whose lowercased name matches the given predicate function.
(sess *Session, priority []string, fallbackMatch func(string) bool)
| 163 | // pickToolByPriority checks a priority list first, then falls back to the first tool |
| 164 | // whose lowercased name matches the given predicate function. |
| 165 | func pickToolByPriority(sess *Session, priority []string, fallbackMatch func(string) bool) string { |
| 166 | if sess == nil { |
| 167 | return "" |
| 168 | } |
| 169 | sess.mu.Lock() |
| 170 | tools := make([]observedtools.ObservedTool, len(sess.Tools)) |
| 171 | copy(tools, sess.Tools) |
| 172 | sess.mu.Unlock() |
| 173 | |
| 174 | nameSet := make(map[string]bool, len(tools)) |
| 175 | for _, t := range tools { |
| 176 | nameSet[t.Name] = true |
| 177 | } |
| 178 | |
| 179 | for _, name := range priority { |
| 180 | if nameSet[name] { |
| 181 | return name |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // Fallback: first tool matching the predicate. |
| 186 | for _, t := range tools { |
| 187 | if fallbackMatch(strings.ToLower(t.Name)) { |
| 188 | return t.Name |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return "" |
| 193 | } |
| 194 | |
| 195 | // BuildReadArguments constructs the arguments map for a file-read tool invocation. |
| 196 | func BuildReadArguments(sess *Session, toolName, filePath string) map[string]any { |
no outgoing calls
no test coverage detected