on main help sign in
feat: add ability to re-authenticate / edit api key
1615de5Andrey Nering
internal/ui/dialog/actions.go+4−3
@@ -36,9 +36,10 @@ type ActionSelectSession struct {
36
36
37// ActionSelectModel is a message indicating a model has been selected.
37// ActionSelectModel is a message indicating a model has been selected.
38type ActionSelectModel struct {
38type ActionSelectModel struct {
39− Provider catwalk.Provider
39+ Provider catwalk.Provider
40− Model config.SelectedModel
40+ Model config.SelectedModel
41− ModelType config.SelectedModelType
41+ ModelType config.SelectedModelType
42+ ReAuthenticate bool
42}
43}
43
44
44// Messages for commands
45// Messages for commands
internal/ui/dialog/models.go+33−17
@@ -70,7 +70,7 @@ const (
70// ModelsID is the identifier for the model selection dialog.
70// ModelsID is the identifier for the model selection dialog.
71const ModelsID = "models"
71const ModelsID = "models"
72
72
73−const defaultModelsDialogMaxWidth = 70
73+const defaultModelsDialogMaxWidth = 73
74
74
75// Models represents a model selection dialog.
75// Models represents a model selection dialog.
76type Models struct {
76type Models struct {
@@ -84,6 +84,7 @@ type Models struct {
84 Tab key.Binding
84 Tab key.Binding
85 UpDown key.Binding
85 UpDown key.Binding
86 Select key.Binding
86 Select key.Binding
87+ Edit key.Binding
87 Next key.Binding
88 Next key.Binding
88 Previous key.Binding
89 Previous key.Binding
89 Close key.Binding
90 Close key.Binding
@@ -124,6 +125,10 @@ func NewModels(com *common.Common, isOnboarding bool) (*Models, error) {
124 key.WithKeys("enter", "ctrl+y"),
125 key.WithKeys("enter", "ctrl+y"),
125 key.WithHelp("enter", "confirm"),
126 key.WithHelp("enter", "confirm"),
126 )
127 )
128+ m.keyMap.Edit = key.NewBinding(
129+ key.WithKeys("ctrl+e"),
130+ key.WithHelp("ctrl+e", "edit"),
131+ )
127 m.keyMap.UpDown = key.NewBinding(
132 m.keyMap.UpDown = key.NewBinding(
128 key.WithKeys("up", "down"),
133 key.WithKeys("up", "down"),
129 key.WithHelp("↑/↓", "choose"),
134 key.WithHelp("↑/↓", "choose"),
@@ -181,7 +186,7 @@ func (m *Models) HandleMsg(msg tea.Msg) Action {
181 }
186 }
182 m.list.SelectNext()
187 m.list.SelectNext()
183 m.list.ScrollToSelected()
188 m.list.ScrollToSelected()
184− case key.Matches(msg, m.keyMap.Select):
189+ case key.Matches(msg, m.keyMap.Select, m.keyMap.Edit):
185 selectedItem := m.list.SelectedItem()
190 selectedItem := m.list.SelectedItem()
186 if selectedItem == nil {
191 if selectedItem == nil {
187 break
192 break
@@ -192,10 +197,13 @@ func (m *Models) HandleMsg(msg tea.Msg) Action {
192 break
197 break
193 }
198 }
194
199
200+ isEdit := key.Matches(msg, m.keyMap.Edit)
201+
195 return ActionSelectModel{
202 return ActionSelectModel{
196− Provider: modelItem.prov,
203+ Provider: modelItem.prov,
197− Model: modelItem.SelectedModel(),
204+ Model: modelItem.SelectedModel(),
198− ModelType: modelItem.SelectedModelType(),
205+ ModelType: modelItem.SelectedModelType(),
206+ ReAuthenticate: isEdit,
199 }
207 }
200 case key.Matches(msg, m.keyMap.Tab):
208 case key.Matches(msg, m.keyMap.Tab):
201 if m.isOnboarding {
209 if m.isOnboarding {
@@ -309,27 +317,35 @@ func (m *Models) ShortHelp() []key.Binding {
309 m.keyMap.Select,
317 m.keyMap.Select,
310 }
318 }
311 }
319 }
312− return []key.Binding{
320+ h := []key.Binding{
313 m.keyMap.UpDown,
321 m.keyMap.UpDown,
314 m.keyMap.Tab,
322 m.keyMap.Tab,
315 m.keyMap.Select,
323 m.keyMap.Select,
316− m.keyMap.Close,
317 }
324 }
325+ if m.isSelectedConfigured() {
326+ h = append(h, m.keyMap.Edit)
327+ }
328+ h = append(h, m.keyMap.Close)
329+ return h
318}
330}
319
331
320// FullHelp returns the full help view.
332// FullHelp returns the full help view.
321func (m *Models) FullHelp() [][]key.Binding {
333func (m *Models) FullHelp() [][]key.Binding {
322− return [][]key.Binding{
334+ return [][]key.Binding{m.ShortHelp()}
323− {
335+}
324− m.keyMap.Select,
336+
325− m.keyMap.Next,
337+func (m *Models) isSelectedConfigured() bool {
326− m.keyMap.Previous,
338+ selectedItem := m.list.SelectedItem()
327− m.keyMap.Tab,
339+ if selectedItem == nil {
340+ return false
328− },
341+ }
329− {
342+ modelItem, ok := selectedItem.(*ModelItem)
330− m.keyMap.Close,
343+ if !ok {
331− },
344+ return false
332 }
345 }
346+ providerID := string(modelItem.prov.ID)
347+ _, isConfigured := m.com.Config().Providers.Get(providerID)
348+ return isConfigured
333}
349}
334
350
335// setProviderItems sets the provider items in the list.
351// setProviderItems sets the provider items in the list.
internal/ui/model/ui.go+2−2
@@ -1266,11 +1266,11 @@ func (m *UI) handleDialogMsg(msg tea.Msg) tea.Cmd {
1266 )
1266 )
1267
1267
1268 // Attempt to import GitHub Copilot tokens from VSCode if available.
1268 // Attempt to import GitHub Copilot tokens from VSCode if available.
1269− if isCopilot && !isConfigured() {
1269+ if isCopilot && !isConfigured() && !msg.ReAuthenticate {
1270 m.com.Config().ImportCopilot()
1270 m.com.Config().ImportCopilot()
1271 }
1271 }
1272
1272
1273− if !isConfigured() {
1273+ if !isConfigured() || msg.ReAuthenticate {
1274 m.dialog.CloseDialog(dialog.ModelsID)
1274 m.dialog.CloseDialog(dialog.ModelsID)
1275 if cmd := m.openAuthenticationDialog(msg.Provider, msg.Model, msg.ModelType); cmd != nil {
1275 if cmd := m.openAuthenticationDialog(msg.Provider, msg.Model, msg.ModelType); cmd != nil {
1276 cmds = append(cmds, cmd)
1276 cmds = append(cmds, cmd)