savedmodels

package
v0.7.39-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 14 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.

Types

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 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 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.

Jump to

Keyboard shortcuts

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