endpoint

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package endpoint owns the set of model endpoints nib can talk to — the config.yaml default, the named endpoints config.yaml declares, and the built-in provider registry — and the rule that decides which one a new session starts on. It holds no session state and makes no request, so the precedence rule is testable on its own.

Index

Constants

View Source
const DefaultID = "config"

DefaultID is the ID of config.yaml's top-level block.

View Source
const DefaultName = "config.yaml"

DefaultName is how the default endpoint is shown.

View Source
const NamedPrefix = "@"

NamedPrefix marks a config.yaml named endpoint, so no yaml name can ever shadow (or be shadowed by) a registry provider ID.

Variables

This section is empty.

Functions

func WriteSaved

func WriteSaved(path string, sv Saved) error

WriteSaved records the pick atomically, creating the directory if needed. An empty path is a no-op, mirroring LoadSaved's treatment of "": a Session built without a state directory (as some low-level tests do) has nowhere to persist to, and must not go writing a stray file into the process's working directory instead.

Types

type Entry

type Entry struct {
	ID   string // DefaultID, "@name", or a registry provider ID
	Name string // display name
	Kind Kind
	// Model is what this entry would run, empty when it must be picked.
	Model string
	// Status is a short human description: an address, or a login state.
	Status string
	// Ready means requests can authenticate right now.
	Ready bool
	// Stored means a /login credential exists (so /logout can remove it).
	Stored bool
	// NeedsBaseURL means logging in must also collect an endpoint.
	NeedsBaseURL bool
	// EnvVar is the environment variable that can hold the key instead.
	EnvVar string
	// Def is the registry definition; the zero value for yaml entries.
	Def provider.Definition
}

Entry is one row of the endpoint picker.

type Kind

type Kind string

Kind classifies an Entry.

const (
	KindDefault  Kind = "default"
	KindNamed    Kind = "named"
	KindProvider Kind = "provider"
)

type Saved

type Saved struct {
	ID    string `json:"id"`
	Model string `json:"model"`

	// Provider is the pre-endpoints field name, read for backward
	// compatibility and never written. An install saved before named
	// endpoints carries a registry ID here.
	Provider string `json:"provider,omitempty"`
}

Saved is the endpoint a previous session picked, kept next to credentials.json so the next session starts on it. It is nib-managed state rather than a config.yaml edit: config.yaml keeps describing its own endpoints, and nib never writes to it.

func LoadSaved

func LoadSaved(path string) Saved

LoadSaved reads the saved pick. Any problem (absent, unreadable, corrupt) is the zero value: a session always has the config.yaml default to fall back to, and a startup must not fail over this file.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is the resolved collection of endpoints for one config.

func New

func New(cfg types.Config, creds *auth.Store) (*Set, []error)

New builds the set. The returned errors are the rejected yaml endpoints, for the caller to show; the set itself is always usable.

func (*Set) Config

func (s *Set) Config(id string) (types.ModelProviderConfig, error)

Config resolves an entry to the connection config a client is built from.

func (*Set) List

func (s *Set) List() []Entry

List returns the default endpoint, the named endpoints in file order, then the provider registry in its display order.

func (*Set) Lookup

func (s *Set) Lookup(id string) (Entry, bool)

Lookup finds one entry by ID.

func (*Set) Startup

func (s *Set) Startup(sv Saved) (Entry, types.ModelProviderConfig, string)

Startup resolves the endpoint a new session starts on: the saved pick when it still resolves, otherwise the config.yaml default. The third return is a user-visible note, non-empty only when a saved pick had to be dropped — silently changing the model between sessions is what this replaces.

Jump to

Keyboard shortcuts

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