validatePinned looks up pinned tool/endpoint values up-front so the caller never enters the TUI with garbage. Returns the partially- resolved selection plus per-phase need flags.
(in wizardInput)
| 77 | // caller never enters the TUI with garbage. Returns the partially- |
| 78 | // resolved selection plus per-phase need flags. |
| 79 | func validatePinned(in wizardInput) (sel launchSelection, needTool, needEndpoint, needModel bool, err error) { |
| 80 | pinned := in.Pinned |
| 81 | |
| 82 | // Tool. |
| 83 | switch { |
| 84 | case pinned.Tool.Name == "": |
| 85 | needTool = true |
| 86 | default: |
| 87 | sel.Tool = pinned.Tool |
| 88 | } |
| 89 | |
| 90 | // Endpoint. |
| 91 | switch { |
| 92 | case pinned.EndpointName == "": |
| 93 | needEndpoint = true |
| 94 | default: |
| 95 | ep, ok := in.Providers.Endpoints[pinned.EndpointName] |
| 96 | if !ok { |
| 97 | return launchSelection{}, false, false, false, |
| 98 | fmt.Errorf("Unknown endpoint: %s", pinned.EndpointName) |
| 99 | } |
| 100 | // When the tool is also pinned, validate the supported_client |
| 101 | // match here so we fail fast. |
| 102 | if !needTool && !ep.SupportsClient(sel.Tool.LaunchCommand()) { |
| 103 | return launchSelection{}, false, false, false, |
| 104 | fmt.Errorf("endpoint %s does not support tool %s (check supported_client)", |
| 105 | pinned.EndpointName, sel.Tool.LaunchCommand()) |
| 106 | } |
| 107 | sel.EndpointName = pinned.EndpointName |
| 108 | sel.Endpoint = ep |
| 109 | } |
| 110 | |
| 111 | // Model. |
| 112 | switch { |
| 113 | case pinned.Model == "": |
| 114 | needModel = true |
| 115 | default: |
| 116 | sel.Model = pinned.Model |
| 117 | } |
| 118 | |
| 119 | return sel, needTool, needEndpoint, needModel, nil |
| 120 | } |
| 121 | |
| 122 | // launchWizardPhase identifies the active phase. |
| 123 | type launchWizardPhase int |