v0.1.66 9035106

modelsync.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"path/filepath"
6	"time"
7
8	"github.com/patriceckhart/zot/internal/provider"
9)
10
11// ModelCachePath returns the on-disk location of the merged model cache.
12func ModelCachePath() string {
13	return filepath.Join(ZotHome(), "models-cache.json")
14}
15
16// UserModelsPath returns the path to the user's models.json override.
17func UserModelsPath() string {
18	return filepath.Join(ZotHome(), "models.json")
19}
20
21// LoadCachedModels loads the cache file and applies it to the provider
22// package so FindModel / ModelsForProvider see live ids immediately.
23// Safe to call before any credentials are known.
24func LoadCachedModels() {
25	c, err := provider.LoadCache(ModelCachePath())
26	if err != nil {
27		return
28	}
29	if len(c.Models) > 0 {
30		provider.SetLiveModels(c.Models)
31	}
32}
33
34// LoadUserModels reads $ZOT_HOME/models.json and merges any user-defined
35// models into the active catalog. User models take highest precedence.
36func LoadUserModels() {
37	models := provider.LoadUserModels(UserModelsPath())
38	provider.SetUserModels(models)
39}
40
41// RefreshModelsAsync kicks a background discovery for every provider
42// we have credentials for. Refreshed results are merged into the
43// active catalog and persisted to the on-disk cache.
44//
45// Silent on error: discovery is a nice-to-have. Callers can still use
46// the baked-in catalog if this fails.
47func RefreshModelsAsync() {
48	go refreshModels()
49}
50
51func refreshModels() {
52	cached, _ := provider.LoadCache(ModelCachePath())
53	if cached.IsFresh() {
54		return
55	}
56
57	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
58	defer cancel()
59
60	var all []provider.Model
61
62	if cred, method, err := ResolveCredential("anthropic", ""); err == nil && method == "apikey" {
63		// /v1/models on Anthropic is API-key only; OAuth tokens can
64		// also list models via the bearer header, but we skip OAuth
65		// here to avoid surprise rate-limit hits on subscription keys.
66		if live, err := provider.DiscoverAnthropic(ctx, cred, ""); err == nil {
67			all = append(all, live...)
68		}
69	}
70	if cred, method, err := ResolveCredential("openai", ""); err == nil && method == "apikey" {
71		if live, err := provider.DiscoverOpenAI(ctx, cred, ""); err == nil {
72			all = append(all, live...)
73		}
74	}
75	if cred, method, err := ResolveCredential("kimi", ""); err == nil && method == "apikey" {
76		if live, err := provider.DiscoverOpenAI(ctx, cred, "https://api.kimi.com/coding/v1"); err == nil {
77			for i := range live {
78				live[i].Provider = "kimi"
79				live[i].Source = "live"
80			}
81			all = append(all, live...)
82		}
83	}
84
85	if len(all) == 0 {
86		return
87	}
88	provider.SetLiveModels(all)
89	_ = provider.SaveCache(ModelCachePath(), provider.ModelCache{
90		FetchedAt: time.Now().UTC(),
91		Models:    all,
92	})
93}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close