Repository navigation
Expand file tree
/
Copy pathchat_config_hub.go
More file actions
86 lines (78 loc) · 2.73 KB
/
Copy pathchat_config_hub.go
File metadata and controls
86 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"strings"
tea "charm.land/bubbletea/v2"
reflectconfig "github.com/GrayCodeAI/reflect/internal/config"
)
func (m chatModel) openConfigPanel() (chatModel, tea.Cmd) {
return m.openConfigAtTab(-1)
}
func (m chatModel) beginConfigModelsTab() (chatModel, tea.Cmd) {
m.configTab = configTabModels
m.configSel = 0
m.configScroll = 0
m.configModelSearch = ""
m.configModelSearchActive = false
m.useConfigInput = false
if strings.TrimSpace(m.configModelProvider) == "" {
m.configModelProvider = firstRunModelProvider(m)
}
if strings.TrimSpace(m.configModelProvider) == "" {
m.configTab = configTabGateways
m.configNotice = "Select a gateway · press enter · paste your API key"
return m.focusConfigActiveGateway(), nil
}
m.configModelOptions = loadConfigModelOptions(m.configModelProvider)
if len(m.configModelOptions) == 0 {
m.configSaving = true
m.configNotice = "Loading models…"
return m, refreshGatewayAsync(m.configModelProvider)
} else if providerHasLiveFetcher(m.configModelProvider) && catalogPricesAreStale(m.configModelOptions) {
// Cached catalog has entries but prices are all zero (pre-live-fetcher).
// Refresh the full catalog (offerings + pricing) via RefreshGatewayCatalog,
// then invalidate the model cache so the models tab reloads from the catalog.
m.configSaving = true
m.configNotice = "Refreshing prices…"
return m, refreshGatewayAsync(m.configModelProvider)
}
if m.configSaving {
var cmds []tea.Cmd
cmds = append(cmds, fetchModelsAsync(m.configModelProvider))
if isXiaomiMimoProvider(m.configModelProvider) {
cmds = append(cmds, fetchPlatformContextIndexCmd())
}
return m, tea.Batch(cmds...)
}
m = m.focusConfigActiveModelSelection()
return m, nil
}
// catalogPricesAreStale returns true when every model entry has zero pricing
// despite having context metadata — the compiled catalog was cached before
// live fetcher pricing was available.
func catalogPricesAreStale(opts []configModelOption) bool {
if len(opts) == 0 {
return false
}
for _, o := range opts {
if o.InputPricePer1M > 0 || o.OutputPricePer1M > 0 {
return false // at least one entry has real pricing
}
}
// All entries are zero-priced — likely stale if a live fetcher exists.
return true
}
func providerHasLiveFetcher(providerID string) bool {
return reflectconfig.GatewaySupportsLiveDiscovery(providerID)
}
func (m chatModel) returnToOllamaURLAfterError(err error) (chatModel, tea.Cmd) {
m.configSaving = false
m.configTab = configTabGateways
url := strings.TrimSpace(m.configPendingOllamaURL)
if url == "" {
url = configDefaultOllamaURL
}
if err != nil {
m.configNotice = reflectconfig.FormatConfigProviderError(configProviderOllama, err)
}
return m.startConfigOllamaURLWithValue(url)
}