savedmodels

package
v0.7.46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package savedmodels holds the rules a client applies to the saved models and providers on a computer beyond what the policy file itself holds: what on the computer names a saved model, how a saved model or a provider is removed while something names it, whether a provider's credential is here, and the provider an endpoint of the person's own makes. The CLI's models and providers commands and Agentry Desktop's Settings both call it, so the two apply the same rules.

A removal never moves anything to the default on its own: while a schedule or a persistent agent names a model being removed, the removal is refused with them listed, unless the person names the saved model they move to. Removing the default needs the new default, named the same way.

Index

Constants

View Source
const (
	KindSchedule = "schedule"
	KindAgent    = "agent"
)

The kinds of thing that name a saved model.

View Source
const (
	// Ready: the credential is here.
	Ready = "ready"
	// KeyMissing: the key is neither in its variable nor in the keychain.
	KeyMissing = "key-missing"
	// NeedsSignIn: the sign-in is not kept, no longer works, or (Agentry
	// credits) this computer is not signed in to the registry.
	NeedsSignIn = "needs-sign-in"
)

The states a provider's credential is in.

Variables

This section is empty.

Functions

func CustomKeyEnv

func CustomKeyEnv(id string) string

CustomKeyEnv is the variable an endpoint of the person's own, provider id custom-<slug>, reads its key from before the keychain.

func CustomProvider

func CustomProvider(name, baseURL string, keychain bool) (id string, pr policy.Provider, warning string, err error)

CustomProvider is the provider an endpoint of the person's own called name at baseURL makes, under its id custom-<slug>. keychain says its key is kept in the OS keychain, read after the variable CustomKeyEnv names; without it the endpoint takes no key, and a run on it is given none. warning is the plain-http sentence for an address the key and the prompts reach unencrypted.

func SignInVendor

func SignInVendor(id string, pr policy.Provider) string

SignInVendor is the model sign-in store's vendor a provider's credential is kept under: a model sign-in's vendor, or a connectable vendor's own id; "" for a key or credits.

func Target

func Target(pol *policy.Policy, ref string, removed []policy.SavedModel) (policy.SavedModel, error)

Target is the saved model ref names as the one to move to, which must not be among the ones removed.

func Usable

func Usable(home string, rm localrun.RunModel, other string, here Here) error

Usable refuses a run on rm whose saved model's credential is not on this computer (exit 11), naming the saved model, its provider and the fix, before anything is laid down for it; other is the fix of running on another saved model instead, in the caller's words. What it cannot tell from here (a sign-in that no longer renews, a key the provider revoked) the run refuses when it meets it. The error unwraps to an UnusableError when the credential is missing.

Types

type Here

type Here struct {
	// Getenv reads a key's variable; nil is os.Getenv.
	Getenv func(string) string
	// SignInKept reports whether a model sign-in of kind is kept under the
	// runner home home; nil asks the home's sign-in store.
	SignInKept func(home, kind string) bool
	// KeyKept reports whether the OS keychain keeps provider's key; nil is
	// modelkey.Present.
	KeyKept func(provider string) (bool, error)
}

Here is where Usable looks for a saved model's credential on this computer. A nil field reads the computer's own.

type InUseError

type InUseError struct{ Users []User }

InUseError is a removal refused because something names a saved model it would remove, and no saved model to move them to was named.

func (*InUseError) Error

func (e *InUseError) Error() string

type KeptSignIn added in v0.7.41

type KeptSignIn struct {
	Record modelsignin.Record
	// Provider is the provider id the credential pays for.
	Provider string
	// InUse says a provider on this computer is paid by it. One that is
	// not is kept for nothing, and removing it changes no provider.
	InUse bool
	// ProviderHere says a provider of that id is here, paid another way
	// when InUse is false (an openai key beside a kept ChatGPT sign-in).
	ProviderHere bool
}

KeptSignIn is a model sign-in or connected account kept on this computer, with the provider it pays for and whether that provider is here and paid by it.

func SignIns added in v0.7.41

func SignIns(home string, providers map[string]policy.Provider) ([]KeptSignIn, error)

SignIns is every sign-in and connected account kept on this computer, by vendor, each against providers (the policy's).

type Removal

type Removal struct {
	// Removed are the saved models removed.
	Removed []policy.SavedModel
	// Moved are the schedules and agents moved, to MovedTo.
	Moved   []User
	MovedTo policy.SavedModel
}

Removal is what a removal did.

func Remove

func Remove(ctx context.Context, home string, pol *policy.Policy, path string, sms []policy.SavedModel, moveTo, client string, remove func(newDefault string) error) (Removal, error)

Remove removes the saved models sms from pol and writes it to path, with remove doing the policy's part (policy.RemoveModel or RemoveProvider), given the new default. What names them moves to the saved model moveTo, which is also the new default when the default is among them; with no moveTo, a removal of anything something names is refused with an InUseError, and nothing changes. The schedules and agents move before the policy is written, so none ever names a model that is gone; a running agent takes the move at its next turn. client is who asks (persistent.ClientCLI, persistent.ClientDesktop).

The errors carry the CLI's exit classes: usage for a move target or a removal the policy refuses, the CLI's for an agent that could not be moved, the policy's for the write. An InUseError is the caller's to word.

type State

type State struct {
	Kind    string
	Words   string
	Code    string
	Account string
	Broken  string
	// Vendor is the model sign-in store's vendor the credential is kept
	// under, "" for a key or credits.
	Vendor string
}

State is whether a provider's credential is here, never the credential: Kind says what it is paid with, Words the state as the CLI lists it, and Code the state a client acts on (Ready, KeyMissing, NeedsSignIn). Account is a sign-in's account or Agentry credits' registry, where known; Broken is why a kept sign-in no longer works.

func ProviderState

func ProviderState(home, id string, pr policy.Provider, token func(registry string) (string, error)) State

ProviderState says whether the provider id's credential is here. token is this computer's sign-in token for a registry ("" when signed out), which Agentry credits are paid through.

type UnusableError

type UnusableError struct {
	// Saved is the saved model; its ID is empty for a policy with none.
	Saved policy.SavedModel
	// Provider is the provider id the credential is kept under.
	Provider string
	Code     string
	// contains filtered or unexported fields
}

UnusableError is a saved model whose credential is not on this computer, so a run, a fire or a turn on it is refused by its name. Code is KeyMissing or NeedsSignIn, as ProviderState says of its provider.

func IsUnusable

func IsUnusable(err error) (*UnusableError, bool)

IsUnusable reports whether err is Usable's refusal of a saved model whose credential is not on this computer, and gives it.

func (*UnusableError) Error

func (e *UnusableError) Error() string

type User

type User struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
	Name string `json:"name"`
	// Model is the id of the saved model it names.
	Model string `json:"model"`
}

User is something on this computer that names a saved model: a schedule (by its id) or a persistent agent (by its name).

func Users

func Users(home string, pol *policy.Policy, sms []policy.SavedModel) ([]User, error)

Users are the schedules on this computer that name one of the saved models sms, by id or by name, or that run on the harness whose block in pol one of them was read from and name no saved model, which run on it; then the persistent agents that name one of them, Agentry Desktop's own included.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL