providerops

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package providerops centralizes the provider/model mutation operations the TUI picker and the cobra `yottacode provider` / `yottacode model` subcommands both perform. Pure functions over config.Config — they don't write to disk, they don't render UI. Callers (TUI picker, CLI) handle persistence + presentation separately so the mutations stay testable in isolation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(cfg config.Config, p AddProvider) (config.Config, error)

Add appends a new provider. Duplicates and invalid kinds are rejected with a clean error so the caller can show the user.

func PickFallback

func PickFallback(cfg config.Config) string

PickFallback returns the name of the first provider remaining in cfg.Providers, or "" if none are left. Used by removal call sites that auto-switch the active profile after deleting the previous active one — declaration order is the chosen heuristic since users already arrange [[providers]] in their preferred order.

func Remove

func Remove(cfg config.Config, name string) (config.Config, error)

Remove deletes the named provider. If it was the active one, Active is cleared so the caller can prompt for a fresh choice.

func SetActive

func SetActive(cfg config.Config, name string) (config.Config, error)

SetActive switches the session-default provider. If the named provider has a default_model, we adopt it as the active model (both legacy Model and canonical DefaultModel) so callers don't also need to make a SetActiveModel call. Returns the modified config; the caller persists.

func SetActiveModel

func SetActiveModel(cfg config.Config, modelName string) (config.Config, error)

SetActiveModel updates the active provider's default_model. Used by `yottacode model use NAME` and the /model picker. Free-form providers (empty Models[]) skip the catalog membership check — the catalog is filled at runtime.

func SuggestAPIKeyEnv

func SuggestAPIKeyEnv(cfg config.Config, profileName, fallback string) string

SuggestAPIKeyEnv picks the env-var name a new profile should use for its bearer token. The first profile of a given vendor keeps the well-known default (e.g. NVIDIA_API_KEY) so existing scripts and CI pipelines keep working. Subsequent profiles get a unique name derived from the new profile's `name` so each profile carries its own key in ~/.yottacode/.env — without this, two NVIDIA NIM profiles share one bearer and switching between models that need different keys fails with a 401.

fallback is the catalog's default env var (empty for keyless providers like Ollama and openai-auth). When fallback is empty, SuggestAPIKeyEnv returns "" — the caller skips API-key handling entirely.

Types

type AddProvider

type AddProvider struct {
	Name         string
	Kind         string
	BaseURL      string
	APIKeyEnv    string
	DefaultModel string
	Models       []config.Model
}

AddProvider is the request shape for Add. The CLI fills it from flags; the TUI picker fills it from collected user input. Models is optional — free-form providers (Ollama, NVIDIA NIM, custom proxies) leave it empty and the catalog is filled at runtime via the live /models fetch.

Jump to

Keyboard shortcuts

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