v0.3.78 aed6edb

lmstudio.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"strings"
6	"time"
7
8	"github.com/patriceckhart/zot/packages/provider"
9)
10
11// resolveLMStudioConfig never assumes a localhost endpoint. Discovery is
12// enabled only by a saved server URL, independently of whether a key is needed.
13func resolveLMStudioConfig(ctx context.Context, mode apiKeyCommandMode) (string, string, error) {
14	creds, err := AuthStoreFor().Load()
15	if err != nil {
16		return "", "", err
17	}
18	stored, ok := creds.AdditionalAPIKeyCreds[provider.LMStudioProviderID]
19	if !ok || strings.TrimSpace(stored.BaseURL) == "" {
20		return "", "", nil
21	}
22	root, err := provider.NormalizeLMStudioURL(stored.BaseURL)
23	if err != nil {
24		return "", "", err
25	}
26	if stored.APIKeyCommand != nil && mode == apiKeyCommandSkip {
27		return "", "", nil
28	}
29	key, _, err := resolveStoredAPIKey(ctx, provider.LMStudioProviderID, stored, mode)
30	return root, key, err
31}
32
33// LMStudioConfigured checks only saved configuration, never the network.
34func LMStudioConfigured() bool {
35	root, _, err := AuthStoreFor().EndpointCredential(provider.LMStudioProviderID)
36	return err == nil && strings.TrimSpace(root) != ""
37}
38
39func RefreshLMStudioModels(ctx context.Context) error {
40	ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
41	defer cancel()
42	return refreshLMStudioModels(ctx, apiKeyCommandExecute)
43}
44
45func refreshLMStudioModels(ctx context.Context, mode apiKeyCommandMode) error {
46	root, key, err := resolveLMStudioConfig(ctx, mode)
47	if err != nil {
48		return err
49	}
50	if root == "" {
51		if LMStudioConfigured() {
52			return nil
53		}
54		provider.SetManagedModelsForProvider(provider.LMStudioProviderID, nil)
55		return nil
56	}
57	models, err := provider.DiscoverLMStudio(ctx, root, key)
58	if err != nil {
59		return err
60	}
61	// A login or logout may have changed the endpoint during the request.
62	currentRoot, currentKey, err := resolveLMStudioConfig(ctx, mode)
63	if err != nil {
64		return err
65	}
66	if currentRoot != root || currentKey != key {
67		return nil
68	}
69	provider.SetManagedModelsForProvider(provider.LMStudioProviderID, models)
70	return nil
71}

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