@@ -12,11 +12,13 @@ import (
1212)
1313
1414type configGatewayRow struct {
15- ID string
16- DisplayName string
17- HasKey bool
18- ModelCount int
19- Active bool
15+ ID string
16+ DisplayName string
17+ HasKey bool
18+ ModelCount int
19+ Active bool
20+ RegionLabel string
21+ RegionRequired bool
2022}
2123
2224type configGatewayRefreshMsg struct {
@@ -27,47 +29,52 @@ type configGatewayRefreshMsg struct {
2729
2830func (m chatModel ) configGatewayRows () []configGatewayRow {
2931 ctx := context .Background ()
30- providers := hawkconfig .AllSetupGateways ()
31- configured := configuredGatewayKeys ()
3232 active := strings .TrimSpace (m .configModelProvider )
33+ activeModel := ""
3334 if active == "" && m .session != nil {
3435 active = strings .TrimSpace (m .session .Provider ())
3536 }
36- var rows []configGatewayRow
37- for _ , id := range providers {
38- if id == "" {
37+ if m .session != nil {
38+ activeModel = strings .TrimSpace (m .session .Model ())
39+ }
40+ statuses := hawkconfig .GatewayStatuses (ctx , active , activeModel )
41+ rows := make ([]configGatewayRow , 0 , len (statuses ))
42+ for _ , status := range statuses {
43+ if status .ID == "" {
3944 continue
4045 }
41- count := hawkconfig . CachedModelCountForProvider ( id )
46+ count := status . ModelCount
4247 if count == 0 {
4348 modelCacheMu .RLock ()
44- if cached , ok := modelCache [id ]; ok {
49+ if cached , ok := modelCache [status . ID ]; ok {
4550 count = len (cached )
4651 }
4752 modelCacheMu .RUnlock ()
4853 }
49- hasKey := configured [ id ] || hawkconfig . HasStoredCredentialForProvider ( ctx , id )
50- display := hawkconfig . GatewayDisplayName ( id )
51- if id == hawkconfig .ProviderXiaomiTokenPlan {
52- if reg := hawkconfig . XiaomiTokenPlanRegionLabel () ; reg != "" {
54+ hasKey := status . HasStoredCredential
55+ display := status . DisplayName
56+ if status . ID == hawkconfig .ProviderXiaomiTokenPlan {
57+ if reg := status . RegionLabel ; reg != "" {
5358 display += " · " + reg
5459 } else {
5560 display += " · region required"
5661 }
5762 }
58- if id == hawkconfig .ProviderZAICoding {
59- if reg := hawkconfig . ZAIRegionLabel ( id ) ; reg != "" {
63+ if status . ID == hawkconfig .ProviderZAICoding {
64+ if reg := status . RegionLabel ; reg != "" {
6065 display += " · " + reg
6166 } else {
6267 display += " · region"
6368 }
6469 }
6570 rows = append (rows , configGatewayRow {
66- ID : id ,
67- DisplayName : display ,
68- HasKey : hasKey ,
69- ModelCount : count ,
70- Active : hawkconfig .NormalizeProviderForEngine (id ) == hawkconfig .NormalizeProviderForEngine (active ),
71+ ID : status .ID ,
72+ DisplayName : display ,
73+ HasKey : hasKey ,
74+ ModelCount : count ,
75+ Active : status .Active || hawkconfig .ActiveProviderID (status .ID ) == hawkconfig .ActiveProviderID (active ),
76+ RegionLabel : status .RegionLabel ,
77+ RegionRequired : status .RegionRequired ,
7178 })
7279 }
7380 return rows
@@ -117,11 +124,11 @@ func (m chatModel) refreshConfigGateway() (chatModel, tea.Cmd) {
117124 }
118125 idx := m .configGatewayRefreshTargetIndex (rows )
119126 row := rows [idx ]
120- if row .ID == hawkconfig .ProviderXiaomiTokenPlan && hawkconfig . NeedsXiaomiTokenPlanRegion ( row .ID ) {
127+ if row .ID == hawkconfig .ProviderXiaomiTokenPlan && row .RegionRequired {
121128 m .configNotice = "Pick Token Plan region (cn / sgp / ams) before refresh"
122129 return m .startConfigXiaomiTokenPlanRegion (), nil
123130 }
124- if row .ID == hawkconfig .ProviderZAICoding && hawkconfig . NeedsZAIRegion ( row .ID ) {
131+ if row .ID == hawkconfig .ProviderZAICoding && row .RegionRequired {
125132 m .configNotice = "Pick Coding Plan region (international / cn) before refresh"
126133 return m .startConfigZAIRegion (row .ID ), nil
127134 }
@@ -274,12 +281,12 @@ func (m chatModel) handleConfigGatewaysSelect() (chatModel, tea.Cmd) {
274281 }
275282 row := rows [m .configSel ]
276283 if row .ID == hawkconfig .ProviderXiaomiTokenPlan {
277- if ! row .HasKey || hawkconfig . NeedsXiaomiTokenPlanRegion ( row .ID ) {
284+ if ! row .HasKey || row .RegionRequired {
278285 m .configGatewayFocus = m .configSel
279286 return m .startConfigXiaomiTokenPlanRegion (), nil
280287 }
281288 }
282- if row .ID == hawkconfig .ProviderZAICoding && (! row .HasKey || hawkconfig . NeedsZAIRegion ( row .ID ) ) {
289+ if row .ID == hawkconfig .ProviderZAICoding && (! row .HasKey || row .RegionRequired ) {
283290 m .configGatewayFocus = m .configSel
284291 return m .startConfigZAIRegion (row .ID ), nil
285292 }
@@ -295,7 +302,9 @@ func (m chatModel) handleConfigGatewaysSelect() (chatModel, tea.Cmd) {
295302 m .configGatewayFocus = m .configSel
296303 m .configModelProvider = gw
297304 _ = hawkconfig .SetGlobalSetting ("provider" , gw )
298- m .session .SetProvider (hawkconfig .NormalizeProviderForEngine (gw ))
305+ if active := hawkconfig .ActiveProvider (context .Background ()); active != "" {
306+ m .session .SetProvider (active )
307+ }
299308 m .configTab = configTabModels
300309 m .configSel = 0
301310 m .configScroll = 0
@@ -343,7 +352,15 @@ func (m chatModel) trackConfigGatewayFocus() chatModel {
343352 if m .configTab != configTabGateways {
344353 return m
345354 }
346- rows := len (hawkconfig .AllSetupGateways ())
355+ active := strings .TrimSpace (m .configModelProvider )
356+ activeModel := ""
357+ if m .session != nil {
358+ if active == "" {
359+ active = strings .TrimSpace (m .session .Provider ())
360+ }
361+ activeModel = strings .TrimSpace (m .session .Model ())
362+ }
363+ rows := len (hawkconfig .GatewayStatuses (context .Background (), active , activeModel ))
347364 if m .configSel >= 0 && m .configSel < rows {
348365 m .configGatewayFocus = m .configSel
349366 }
0 commit comments