autoResolve fills missing pinned fields using today's auto-selection logic (first matching endpoint, first model). Used when stdin is not a TTY, or when there's nothing left to ask the user.
(in wizardInput, stderr io.Writer)
| 196 | // when stdin is not a TTY, or when there's nothing left to ask the |
| 197 | // user. |
| 198 | func autoResolve(in wizardInput, stderr io.Writer) (launchSelection, error) { |
| 199 | sel := in.Pinned |
| 200 | |
| 201 | if sel.Tool.Name == "" { |
| 202 | return launchSelection{}, fmt.Errorf("launch: no tool specified and no TTY for interactive selection; pass a tool name") |
| 203 | } |
| 204 | |
| 205 | if sel.EndpointName == "" { |
| 206 | client := sel.Tool.LaunchCommand() |
| 207 | for _, name := range in.Providers.SortedNames() { |
| 208 | ep := in.Providers.Endpoints[name] |
| 209 | if !ep.IsEnabled() { |
| 210 | continue |
| 211 | } |
| 212 | if !ep.SupportsClient(client) { |
| 213 | continue |
| 214 | } |
| 215 | sel.EndpointName = name |
| 216 | sel.Endpoint = ep |
| 217 | if stderr != nil { |
| 218 | fmt.Fprintf(stderr, "[cam] auto-selected endpoint: %s\n", name) |
| 219 | } |
| 220 | break |
| 221 | } |
| 222 | if sel.EndpointName == "" { |
| 223 | return launchSelection{}, fmt.Errorf("no provider supports tool: %s", client) |
| 224 | } |
| 225 | } else { |
| 226 | ep, ok := in.Providers.Endpoints[sel.EndpointName] |
| 227 | if !ok { |
| 228 | return launchSelection{}, fmt.Errorf("Unknown endpoint: %s", sel.EndpointName) |
| 229 | } |
| 230 | if !ep.SupportsClient(sel.Tool.LaunchCommand()) { |
| 231 | return launchSelection{}, fmt.Errorf( |
| 232 | "endpoint %s does not support tool %s (check supported_client)", |
| 233 | sel.EndpointName, sel.Tool.LaunchCommand()) |
| 234 | } |
| 235 | sel.Endpoint = ep |
| 236 | } |
| 237 | |
| 238 | if sel.Model == "" { |
| 239 | models, mErr := in.ResolveModels(sel.Endpoint, sel.EndpointName) |
| 240 | if mErr != nil { |
| 241 | return launchSelection{}, fmt.Errorf( |
| 242 | "launch: discover models for endpoint %s: %w (pass --model to skip discovery)", |
| 243 | sel.EndpointName, mErr) |
| 244 | } |
| 245 | if len(models) == 0 { |
| 246 | return launchSelection{}, fmt.Errorf( |
| 247 | "launch: endpoint %s has no discovered models; pass --model", |
| 248 | sel.EndpointName) |
| 249 | } |
| 250 | sel.Model = models[0] |
| 251 | if stderr != nil { |
| 252 | fmt.Fprintf(stderr, "[cam] auto-selected model: %s\n", sel.Model) |
| 253 | } |
| 254 | } |
| 255 |
no test coverage detected