v0.0.61 c09a5c5

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// LoadCachedModels loads the cache file and applies it to the provider
17// package so FindModel / ModelsForProvider see live ids immediately.
18// Safe to call before any credentials are known.
19func LoadCachedModels() {
20	c, err := provider.LoadCache(ModelCachePath())
21	if err != nil {
22		return
23	}
24	if len(c.Models) > 0 {
25		provider.SetLiveModels(c.Models)
26	}
27}
28
29// RefreshModelsAsync kicks a background discovery for every provider
30// we have credentials for. Refreshed results are merged into the
31// active catalog and persisted to the on-disk cache.
32//
33// Silent on error: discovery is a nice-to-have. Callers can still use
34// the baked-in catalog if this fails.
35func RefreshModelsAsync() {
36	go refreshModels()
37}
38
39func refreshModels() {
40	cached, _ := provider.LoadCache(ModelCachePath())
41	if cached.IsFresh() {
42		return
43	}
44
45	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
46	defer cancel()
47
48	var all []provider.Model
49
50	if cred, method, err := ResolveCredential("anthropic", ""); err == nil && method == "apikey" {
51		// /v1/models on Anthropic is API-key only; OAuth tokens can
52		// also list models via the bearer header, but we skip OAuth
53		// here to avoid surprise rate-limit hits on subscription keys.
54		if live, err := provider.DiscoverAnthropic(ctx, cred, ""); err == nil {
55			all = append(all, live...)
56		}
57	}
58	if cred, method, err := ResolveCredential("openai", ""); err == nil && method == "apikey" {
59		if live, err := provider.DiscoverOpenAI(ctx, cred, ""); err == nil {
60			all = append(all, live...)
61		}
62	}
63
64	if len(all) == 0 {
65		return
66	}
67	provider.SetLiveModels(all)
68	_ = provider.SaveCache(ModelCachePath(), provider.ModelCache{
69		FetchedAt: time.Now().UTC(),
70		Models:    all,
71	})
72}

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