extproviders

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package extproviders keeps the external model providers a person added by API: a name, an address, the kind of API it speaks (OpenAI-compatible or Anthropic-compatible) and the name of the secret of the machine's safe that holds its key. The key itself is never kept here and never leaves in an answer: the registry file holds a reference, and the value is read from the safe only to make a request to the provider.

A provider is no chat profile (internal/providers): those are the vendor setups an agent CLI runs on. A provider of this registry is what the background features call (internal/bgmodel); one that speaks the Anthropic API is marked as fit for Claude CLI, for the day a chat may pick it.

Index

Constants

View Source
const (
	MaxProviders = 32
	MaxName      = 60
	MaxURL       = 300
	MaxKey       = 4096
	MaxModels    = 500
	MaxModelID   = 200
	// MaxWindow bounds a model's context window (tokens).
	MaxWindow = 100 << 20
)

Limits of what a person may save.

View Source
const (
	ReasonBadName = "bad-name"
	// ReasonNameTaken: another account is called so already.
	ReasonNameTaken = "name-taken"
	ReasonBadURL    = "bad-url"
	// ReasonBadProxy: the account's proxy is not an http, https or socks5 address.
	ReasonBadProxy = "bad-proxy"
	ReasonBadAPI   = "bad-api"
	ReasonBadKey   = "bad-key"
	// ReasonBadMediaKey: a Higgsfield key is the key ID and the secret, "id:secret".
	ReasonBadMediaKey = "bad-media-key"
	ReasonBadModel    = "bad-model"
	ReasonNotFound    = "not-found"
	ReasonTooMany     = "too-many"
	ReasonFailed      = "failed"
)

Reasons of a refusal, as the page is told them.

View Source
const (
	MaxEnv      = 40
	MaxEnvValue = 4096
)

Limits of a provider's variables.

View Source
const (
	// ReasonBadEnv: a name that is no identifier, a value too long or of several lines, a name twice, too many, or a
	// secret variable without a value.
	ReasonBadEnv = "bad-env"
	// ReasonEnvReserved: the variable is the launch's own and is not the person's to set.
	ReasonEnvReserved = "env-reserved"
	// ReasonSubscriptionToken: the key or the value is the token of a Claude subscription's sign-in. A machine has one
	// such sign-in, the CLI's own; a provider takes a key of the API.
	ReasonSubscriptionToken = "subscription-token"
)

Reasons of a refusal of a variable.

View Source
const (
	// ReasonManaged: the provider is the environment's and is changed in the hub, not on the machine.
	ReasonManaged = "managed"
	// ReasonBadSecretRef: a secret is named by neither a name of the safe nor a vault: reference.
	ReasonBadSecretRef = "bad-secret-ref"
	// ReasonSecretUnbound: a secret of the safe that is named was not allowed by the person for this server, or is the
	// organization's and not an agent's to name.
	ReasonSecretUnbound = "secret-unbound"
	// ReasonSecretInSource: a variable that is a credential by its name was given a value instead of a reference.
	ReasonSecretInSource = "secret-in-source"
)

Reasons of a refusal about a provider of the environment.

View Source
const (
	DefaultVideoModel = "kling-video/v3.0/std/image-to-video"
	DefaultTextVideo  = "kling-video/v3.0/std/text-to-video"
	DefaultImageModel = "higgsfield-ai/soul/v2/standard"
)

The models a request starts on when it names none.

View Source
const (
	// CheckUnauthorized: the provider refused the key (401, 403).
	CheckUnauthorized = "unauthorized"
	// CheckUnreachable: the address did not answer (no such host, refused, timed out).
	CheckUnreachable = "unreachable"
	// CheckWrongAPI: the address answers, but not as the chosen kind of API does.
	CheckWrongAPI = "wrong-api"
	// CheckRateLimited: the provider says there were too many requests (429).
	CheckRateLimited = "rate-limited"
	// CheckRejected: the provider answered with another error.
	CheckRejected = "rejected"
)

Reasons a check did not pass.

View Source
const CheckTimeout = 15 * time.Second

CheckTimeout bounds a check of a connection.

View Source
const HiggsfieldBase = "https://api.higgsfield.ai"

HiggsfieldBase is the address of the Higgsfield API (docs.higgsfield.ai, «Base URL»; the keys are made in console.higgsfield.ai).

View Source
const LocalTimeout = 1500 * time.Millisecond

LocalTimeout bounds the probe of one server: a server on this machine answers at once, so a port that does not is not worth waiting for.

View Source
const LocalWindow = 32 << 10

LocalWindow is the window a local model is given when the server does not say: Claude Code would assume a million tokens for a model it does not know, and never compact a chat that a local model has long lost the start of.

View Source
const MaxManagedModels = 64

MaxManagedModels is how many models a source may list.

View Source
const PresetCustom = "custom"

PresetCustom is the template of an address of the person's own.

View Source
const PresetLocal = "local"

PresetLocal is the template of a local model server (the page offers its own card for it, not a form).

View Source
const ReasonNoSecret = "no-secret"

ReasonNoSecret: a secret that is named is not in the safe yet.

View Source
const ReasonNotLocal = "not-local"

ReasonNotLocal: the address is not on this machine or a private network; a local model is never fetched from there.

View Source
const ReservedPrefixesEnv = "RUNTIME_LAUNCH_ENV_RESERVED"

ReservedPrefixesEnv names more families of a deployment's own variables, comma-separated ("ACME_,WRAPPER_"): what the tools around harnessly set for a chat and no provider may override.

Variables

View Source
var EnvCredentials = []string{"ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY"}

EnvCredentials are the variables Claude Code takes a credential from.

View Source
var HiggsfieldCatalog = []MediaModel{
	{ID: "kling-video/v3.0/std/image-to-video", Label: "Kling 3.0 Std · image → video", Kind: KindVideo, Family: "kling", FromImage: true, MinSec: 3, MaxSec: 15, Audio: "sound"},
	{ID: "kling-video/v3.0/pro/image-to-video", Label: "Kling 3.0 Pro · image → video", Kind: KindVideo, Family: "kling", FromImage: true, MinSec: 3, MaxSec: 15, Audio: "sound"},
	{ID: "kling-video/v3.0-turbo/image-to-video", Label: "Kling 3.0 Turbo · image → video", Kind: KindVideo, Family: "kling", FromImage: true, MinSec: 3, MaxSec: 15, Resolutions: []string{"720p", "1080p"}},
	{ID: "kling-video/v2.5-turbo/standard/image-to-video", Label: "Kling 2.5 Turbo Std · image → video", Kind: KindVideo, Family: "kling", FromImage: true, OnlySec: []int{5, 10}},
	{ID: "kling-video/v3.0/std/text-to-video", Label: "Kling 3.0 Std · text → video", Kind: KindVideo, Family: "kling", MinSec: 3, MaxSec: 15, Audio: "sound", Ratios: []string{"16:9", "9:16", "1:1"}},
	{ID: "bytedance/seedance-2.5/image-to-video", Label: "Seedance 2.5 · image → video", Kind: KindVideo, Family: "seedance", FromImage: true, LastFrame: true, MinSec: 4, MaxSec: 30, Audio: "generate_audio", Resolutions: []string{"480p", "720p", "1080p"}},
	{ID: "bytedance/seedance-2.5/text-to-video", Label: "Seedance 2.5 · text → video", Kind: KindVideo, Family: "seedance", MinSec: 4, MaxSec: 30, Audio: "generate_audio", Resolutions: []string{"480p", "720p", "1080p"}},
	{ID: "lightricks/ltx-2.5/image-to-video/fast", Label: "LTX 2.5 Fast · image → video", Kind: KindVideo, Family: "ltx", FromImage: true, LastFrame: true, OnlySec: []int{6, 8, 10}, Audio: "generate_audio", Ratios: []string{"16:9", "9:16"}, Resolutions: []string{"720p", "1080p", "2k", "4k"}},
	{ID: "lightricks/ltx-2.5/text-to-video/fast", Label: "LTX 2.5 Fast · text → video", Kind: KindVideo, Family: "ltx", OnlySec: []int{6, 8, 10}, Audio: "generate_audio", Ratios: []string{"16:9", "9:16"}, Resolutions: []string{"720p", "1080p", "2k", "4k"}},
	{ID: "higgsfield-ai/soul/v2/standard", Label: "Soul 2.0 · picture", Kind: KindImage, Family: "soul", Ratios: []string{"1:1", "16:9", "9:16", "4:3", "3:4", "2:3", "3:2"}, Resolutions: []string{"720p", "1080p"}},
	{ID: "z-image/turbo", Label: "Z-Image Turbo · picture", Kind: KindImage, Family: "z-image", Ratios: []string{"1:1", "16:9", "9:16", "4:3", "3:4", "2:3", "3:2"}, Resolutions: []string{"1k", "2k"}},
}

HiggsfieldCatalog is the models of Higgsfield an agent may pick, as docs.higgsfield.ai documents them. The provider lists 80; the ones that are not here are named by their endpoint ID and get the common fields of a request only.

View Source
var LocalTargets = []LocalTarget{
	{Kind: "ollama", Name: "Ollama", Root: "http://127.0.0.1:11434"},
	{Kind: "lmstudio", Name: "LM Studio", Root: "http://127.0.0.1:1234"},
	{Kind: "llamacpp", Name: "llama.cpp", Root: "http://127.0.0.1:8080"},
	{Kind: "vllm", Name: "vLLM", Root: "http://127.0.0.1:8000"},
}

LocalTargets are the well-known ports of the servers, on the machine's loopback.

View Source
var ModelEfforts = []string{"low", "medium", "high", "xhigh", "max", "ultra"}

ModelEfforts are the efforts a model may be given, in their order: those of the wire.

Functions

func CleanLocalURL

func CleanLocalURL(raw string) (string, error)

CleanLocalURL is CleanURL for an address a local model is at: it must be this machine or a private network.

func CleanProxy

func CleanProxy(raw string) (string, error)

CleanProxy is a proxy address as kept: http, https or socks5(h) with a host, nothing after it.

func CleanURL

func CleanURL(raw string) (string, error)

CleanURL is a provider's address as it is kept: http or https, a host, no credentials, no query, no trailing slash.

func Endpoint

func Endpoint(base string, api API, path string) string

Endpoint is the address of a path of the provider's API: an Anthropic-compatible address is the root the vendors document (ANTHROPIC_BASE_URL), with or without a trailing /v1; an OpenAI-compatible one already ends with its version.

func EnvAlwaysSecret

func EnvAlwaysSecret(name string) bool

EnvAlwaysSecret says whether a variable is kept in the safe whatever the form says: a credential by its name.

func EnvReserved

func EnvReserved(name string) bool

EnvReserved says whether a variable is the launch's own.

func Headers

func Headers(api API, key string) http.Header

Headers are the headers a request to a provider of that kind carries.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout says whether err is a request that ran out of time.

func LocalHost

func LocalHost(host string) bool

LocalHost says whether the host of an address may be a local model's: «localhost», an address of a private range, or a name that resolves to such addresses only (checked again when it is connected to, see localClient).

func LocalName

func LocalName(server string) string

LocalName is the name an account of a found server is given: «Локальная модель · Ollama».

func OriginOf

func OriginOf(base string) string

OriginOf is the site of a provider's address as the safe binds a secret to it: scheme://host[:port].

func ProxyEnv

func ProxyEnv(proxy string) map[string]string

ProxyEnv are the variables an agent launched on the account takes for its proxy; nil for none. The runtime on this machine (the relay of an OpenAI-compatible account, the hooks) stays reached directly.

func ProxyTransport

func ProxyTransport(proxy string) *http.Transport

ProxyTransport is a transport through proxy; through the machine's settings when it is "" or not an address.

func ReasonOf

func ReasonOf(err error) string

ReasonOf is the reason of any error of the registry.

func SharedRef

func SharedRef(ref string) bool

SharedRef says whether a secret is named by a reference to the safe's server, not by a name of the person's safe.

func ShownProxy

func ShownProxy(proxy string) string

ShownProxy is the proxy as the page shows it: a password in it is not sent back.

func ValidMediaKey

func ValidMediaKey(s string) bool

ValidMediaKey says whether s is a key ID and a secret, "id:secret": both not empty, no spaces.

func ValidSecretRef

func ValidSecretRef(s string) bool

ValidSecretRef says whether s names a secret: a name of the safe, or vault:<path>#<key>.

Types

type API

type API string

API is the protocol a provider speaks.

const (
	// APIOpenAI: GET <base>/models and POST <base>/chat/completions, the key as a Bearer token.
	APIOpenAI API = "openai"
	// APIAnthropic: GET <base>/v1/models and POST <base>/v1/messages, the key in x-api-key.
	APIAnthropic API = "anthropic"
	// APIHiggsfield: a media provider (media.go): video and pictures by asynchronous requests, POST <base>/<model> and
	// GET <base>/requests/<id>/status, the key (key ID and secret as "id:secret") in Authorization: Key <id>:<secret>.
	APIHiggsfield API = "higgsfield"
)

func (API) Valid

func (a API) Valid() bool

Valid says whether a is a protocol the registry knows.

type Check

type Check struct {
	OK     bool   `json:"ok"`
	Reason string `json:"reason,omitempty"`
	// Message is the outcome in words for the person.
	Message string `json:"message"`
	Status  int    `json:"status,omitempty"`
	Ms      int64  `json:"ms"`
	// Models are the provider's models when it lists them; empty for one that passes the check without a list (the
	// person then types the model's name).
	Models []Model `json:"models"`
}

Check is how a check of a connection went. It holds neither the key nor the provider's body.

type Declared

type Declared struct {
	// ID is the account's; empty for a new one.
	ID   string `json:"id,omitempty"`
	Name string `json:"name"`
	ManagedSource
	// Default: the account of its provider that is used where none is named.
	Default bool `json:"default,omitempty"`
	// Remove takes the account off (only ID is read then).
	Remove bool `json:"remove,omitempty"`
}

Declared is one account.

func ParseDeclared

func ParseDeclared(raw string) (list []Declared, whole bool, err error)

ParseDeclared reads what an agent wrote: one account (added, changed or removed; the rest stay) or the whole list (whole: the person's accounts become exactly these).

type Discoverer

type Discoverer struct {
	// Targets are the places to look; nil is LocalTargets.
	Targets []LocalTarget
	// Client sends the requests; nil is localClient().
	Client *http.Client
}

Discoverer looks for local servers.

func (*Discoverer) Discover

func (d *Discoverer) Discover(ctx context.Context, custom string) (LocalFound, error)

Discover asks every target and, when the person typed an address, that one too (it must be a local one). Servers that do not answer are left out; the order is the targets' own, the typed address last.

type Draft

type Draft struct {
	ID      string `json:"id"`
	BaseURL string `json:"baseUrl"`
	API     API    `json:"api"`
	Key     string `json:"key"`
	// Proxy is the form's proxy; the saved one of ID when it is the page's copy of it (password hidden).
	Proxy string `json:"proxy"`
}

Draft is a form that is not saved yet: «Проверить» before «Сохранить». With ID and no Key the saved key of that provider is used, so a person who edits an address need not type the key again.

type EnvInput

type EnvInput struct {
	Name   string  `json:"name"`
	Value  *string `json:"value"`
	Secret bool    `json:"secret"`
}

EnvInput is a variable of a patch. A secret one without a Value keeps the value the safe has.

type EnvVar

type EnvVar struct {
	Name   string `json:"name"`
	Value  string `json:"value,omitempty"`
	Secret bool   `json:"secret,omitempty"`
	Ref    string `json:"ref,omitempty"`
}

EnvVar is one variable as the registry file keeps it: the value of a plain one, the name of the safe's secret of a secret one.

type EnvView

type EnvView struct {
	Name   string `json:"name"`
	Value  string `json:"value,omitempty"`
	Secret bool   `json:"secret"`
	Set    bool   `json:"set"`
}

EnvView is a variable as the page sees it: a secret one never has its value, only whether the safe holds it.

type Input

type Input struct {
	Name    string  `json:"name"`
	BaseURL string  `json:"baseUrl"`
	API     API     `json:"api"`
	Preset  string  `json:"preset"`
	Key     string  `json:"key"`
	Models  []Model `json:"models"`
	// Proxy is the account's own HTTP proxy ("" for none).
	Proxy string `json:"proxy"`
}

Input is the form of a new provider. Key may be empty: a local server takes none.

type LocalCustom

type LocalCustom struct {
	Address string `json:"address"`
	Found   bool   `json:"found"`
}

LocalCustom is the answer for the address the person typed.

type LocalFound

type LocalFound struct {
	Servers []LocalServer `json:"servers"`
	// Custom says how the address the person typed went: nil when none was given.
	Custom *LocalCustom `json:"custom,omitempty"`
}

LocalFound is what a discovery found.

type LocalServer

type LocalServer struct {
	Kind string `json:"kind"`
	Name string `json:"name"`
	// BaseURL is the address a provider is made with: the root of a server that speaks the Anthropic API, the /v1 of
	// one that speaks only OpenAI's.
	BaseURL string  `json:"baseUrl"`
	API     API     `json:"api"`
	Models  []Model `json:"models"`
	// Context is the context a loaded model runs with (tokens), when the server says; 0: not known. A server may run a
	// model with far less than the model can take (Ollama's default is 4096 without a big GPU).
	Context int `json:"context,omitempty"`
}

LocalServer is a server that answered.

type LocalTarget

type LocalTarget struct {
	Kind string
	Name string
	Root string
}

LocalTarget is a place a local server is looked for: its kind and the root of its address.

type ManagedSource

type ManagedSource struct {
	API     API    `json:"api"`
	BaseURL string `json:"baseUrl"`
	// Preset is the known provider the form was started from; "" for an address typed by hand.
	Preset string `json:"preset,omitempty"`
	// Models are the models offered; none: the machine asks the provider.
	Models []string `json:"models,omitempty"`
	// Key names the secret with the provider's key; "" for a provider that takes none.
	Key string `json:"key,omitempty"`
	// Env are the plain variables of a launch, NAME=value.
	Env []string `json:"env,omitempty"`
	// SecretEnv are the secret variables of a launch, NAME=<the secret's name or reference>.
	SecretEnv []string `json:"secretEnv,omitempty"`
}

ManagedSource is the source of an environment item of kind provider, as the hub keeps it and the machine reads it.

func ParseManagedSource

func ParseManagedSource(raw json.RawMessage) (ManagedSource, error)

ParseManagedSource reads and checks a source. The answer is in the canonical form: trimmed, without repeats.

func (ManagedSource) Clean

func (m ManagedSource) Clean() (ManagedSource, error)

Clean checks a source and returns it in the canonical form.

func (ManagedSource) SecretRefs

func (m ManagedSource) SecretRefs() []string

SecretRefs are the secrets a source names, each once, in the order they are named.

type MediaKind

type MediaKind string

MediaKind is what a model makes.

const (
	KindVideo MediaKind = "video"
	KindImage MediaKind = "image"
	// KindAudio is music, speech or a sound effect: only Higgsfield's MCP server makes it.
	KindAudio      MediaKind = "audio"
	KindTranscript MediaKind = "transcript"
)

type MediaModel

type MediaModel struct {
	// ID is the endpoint ID of the model at the provider (kling-video/v3.0/std/image-to-video).
	ID    string    `json:"id"`
	Label string    `json:"label"`
	Kind  MediaKind `json:"kind"`
	// Family is the vendor's name of the model (kling, seedance, ltx, soul), the short word agents pick by.
	Family string `json:"family"`
	// FromImage: the model takes the first frame (image_url); one that does not is text to video or to picture.
	FromImage bool `json:"fromImage,omitempty"`
	// LastFrame: the model takes the last frame too (end_image_url).
	LastFrame bool `json:"lastFrame,omitempty"`
	// MinSec and MaxSec: any whole number of seconds between them is a length of a clip the model takes; OnlySec: the lengths
	// it takes when it takes some only. All empty for a picture.
	MinSec  int   `json:"minSec,omitempty"`
	MaxSec  int   `json:"maxSec,omitempty"`
	OnlySec []int `json:"onlySec,omitempty"`
	// Audio names the field that asks for the sound of a clip ("sound": on/off, "generate_audio": true/false); "" for a
	// model without.
	Audio string `json:"audio,omitempty"`
	// Ratios are the aspect ratios it takes (empty: the frame follows the image).
	Ratios []string `json:"ratios,omitempty"`
	// Resolutions are the sizes it takes; the first is the cheapest.
	Resolutions []string `json:"resolutions,omitempty"`
}

MediaModel is one model of a media provider: its endpoint (the model's ID), what it makes, from what, and which settings of the request it takes.

func FindMediaModel

func FindMediaModel(ref string, kind MediaKind, fromImage bool) (MediaModel, bool)

FindMediaModel is the catalog's model of that endpoint ID, or the first of the vendor's family (kling, seedance, ltx, soul) that makes kind from an image or not.

type Model

type Model struct {
	ID    string `json:"id"`
	Label string `json:"label,omitempty"`
	// Efforts are the reasoning efforts the model takes (wire.Efforts, in their order); none: the model has no choice.
	Efforts []string `json:"efforts,omitempty"`
	// EffortKnown distinguishes an explicit lack of selectable levels from an ID-only model list.
	EffortKnown bool `json:"effortKnown,omitempty"`
	// DefaultEffort is the one of Efforts a chat starts on; "" is the model's own.
	DefaultEffort string `json:"defaultEffort,omitempty"`
	// Window is the model's context window in tokens, as the provider lists it or the person typed it; 0: unknown
	// (Claude Code then keeps its own and compacts the chat late on a smaller window).
	Window int `json:"window,omitempty"`
	// Manual: the person added the model; a refresh from the provider keeps it even when the provider does not list it.
	Manual bool `json:"manual,omitempty"`
	// Edited: the person gave the model its name or efforts; a refresh keeps what they gave.
	Edited bool `json:"edited,omitempty"`
}

Model is one model of a provider: as the provider lists it, or as the person typed or corrected it.

func HiggsfieldModels

func HiggsfieldModels() []Model

HiggsfieldModels is the catalog as the models of a provider of the registry.

func MergeModels

func MergeModels(kept, fresh []Model) []Model

MergeModels is a provider's fresh list with what the person did to the kept one: a model they named or gave efforts keeps their name and efforts, a model they added stays when the provider does not list it.

func (Model) Equal

func (m Model) Equal(o Model) bool

Equal says whether two models are the same in every field.

type ModelList

type ModelList struct {
	Models []Model `json:"models"`
	At     int64   `json:"at,omitempty"`
	// Check is how the refresh went, when one was made.
	Check *Check `json:"check,omitempty"`
}

ModelList is the models of a provider and when they were taken from it.

type Patch

type Patch struct {
	Name    *string  `json:"name"`
	BaseURL *string  `json:"baseUrl"`
	API     *API     `json:"api"`
	Key     *string  `json:"key"`
	Models  *[]Model `json:"models"`
	// Env, when given, is the whole list of the launch's variables: one that is not in it is removed.
	Env *[]EnvInput `json:"env"`
	// Default true makes the account the default one of its provider; false is not a change (another is made so).
	Default *bool `json:"default"`
	// Proxy, when given, is the account's own HTTP proxy ("" removes it). The page's own copy, with the password
	// hidden (ShownProxy), keeps the saved one.
	Proxy *string `json:"proxy"`
}

Patch changes a provider: a field left nil stays as it is. An empty Key removes the saved key.

type Preset

type Preset struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	BaseURL string `json:"baseUrl"`
	API     API    `json:"api"`
	// KeyURL is the page of the vendor where a key is made.
	KeyURL string `json:"keyUrl,omitempty"`
	// Models are the models an account of the template starts with when the form names none: a vendor that speaks the
	// Anthropic API may list no models at its address.
	Models []Model `json:"models,omitempty"`
}

Preset is a template of the form: a provider the person only has to give a key for.

func Presets

func Presets() []Preset

Presets are the templates of the form, in the order it lists them.

type Prober

type Prober struct {
	// Client sends the requests; nil is a client with CheckTimeout that follows no redirect (a redirect would carry the
	// key to the host it points at).
	Client *http.Client
	// Proxy is the account's own HTTP proxy the check goes through ("" for the machine's); used when Client is nil.
	Proxy string
}

Prober asks a provider for its models.

func (*Prober) Check

func (p *Prober) Check(ctx context.Context, base string, api API, key string) Check

Check asks the provider at base for its models with key, and says how it went.

func (*Prober) Via

func (p *Prober) Via(proxy string) *Prober

Via is the prober for an account with its own proxy.

type Provider

type Provider struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	BaseURL string `json:"baseUrl"`
	API     API    `json:"api"`
	// Preset is the template it was made from ("" for an address of the person's own).
	Preset string `json:"preset,omitempty"`
	// KeyRef names the secret of the safe that holds the key; "" for a provider that takes none (a local server).
	KeyRef string  `json:"keyRef,omitempty"`
	Models []Model `json:"models"`
	// ManagedModels are the IDs explicitly offered by the environment item. Empty lets the provider supply the list.
	ManagedModels []string `json:"managedModels,omitempty"`
	// ModelsAt is when the models were last taken from the provider (ms); 0 when they never were.
	ModelsAt int64 `json:"modelsAt,omitempty"`
	// Env are the variables the provider adds to the launch of an agent on it (launchenv.go).
	Env []EnvVar `json:"env,omitempty"`
	// Proxy is the account's own HTTP proxy (proxy.go); "" goes as the machine does.
	Proxy string `json:"proxy,omitempty"`
	// Default marks the account of its provider that is used where no account is named: one of every Group.
	Default bool `json:"default,omitempty"`
	// Origin is the environment item the provider comes from; "" for one the person added.
	Origin    string `json:"origin,omitempty"`
	CreatedAt int64  `json:"createdAt"`
	UpdatedAt int64  `json:"updatedAt"`
}

Provider is one provider as the registry file keeps it.

func (Provider) ClaudeCLI

func (p Provider) ClaudeCLI() bool

ClaudeCLI says whether Claude Code runs a chat straight on the provider: it speaks the Anthropic API.

func (Provider) Group

func (p Provider) Group() string

Group is what the accounts of one provider share: the template they were made from, or the host of an address of the person's own. A person may add several accounts of a provider, each a record with a key of its own.

func (Provider) HasMediaModel

func (p Provider) HasMediaModel(id string) bool

HasMediaModel says whether the catalog or the provider's own list (a model the person added) has that ID.

func (Provider) HasModel

func (p Provider) HasModel(id string) bool

HasModel says whether the provider lists a model of that id.

func (Provider) Host

func (p Provider) Host() string

Host is the host of the provider's address.

func (Provider) Media

func (p Provider) Media() bool

Media says whether the provider makes video and pictures, not text: no chat and no background feature runs on it.

func (Provider) Proxied

func (p Provider) Proxied() bool

Proxied says whether Claude Code runs a chat on the provider through the runtime's proxy, which turns Anthropic's Messages into the provider's /chat/completions: it speaks the OpenAI API.

type Refusal

type Refusal struct {
	Reason string
	Err    error
}

Refusal is a reason the caller is told.

func (*Refusal) Error

func (r *Refusal) Error() string

func (*Refusal) Unwrap

func (r *Refusal) Unwrap() error

type Secrets

type Secrets interface {
	Put(name, value string) error
	Reveal(name string) (string, error)
	Remove(name string) error
	Has(name string) bool
}

Secrets is the part of the machine's safe the registry uses: the keys go there under the names it makes.

type Service

type Service struct {
	// Bound says whether the person allowed a secret of their safe for a site (scheme://host[:port]): a secret that is
	// only named, by an agent or by the environment, is used for the server it was allowed for and for no other. nil:
	// no secret is.
	Bound   func(name, origin string) bool
	Store   *Store
	Secrets Secrets
	// Probe asks a provider; nil is a Prober of its own.
	Probe *Prober
	// Local looks for local model servers; nil is a Discoverer of its own.
	Local *Discoverer
	// OnChange is told after the registry changed: what happened ("created", "updated", "removed") to which provider.
	OnChange func(what string, before, after *Provider)
}

Service is the registry with the safe its keys live in and the client that asks a provider for its models.

func (*Service) ApplyManaged

func (s *Service) ApplyManaged(origin, name string, src ManagedSource) (bool, []string, error)

ApplyManaged puts the provider of an environment item into the registry, or brings it in line with the item. The name is the item's; when a person's account is called so already, the environment's one gets the next free name. changed is false when the registry had it as it is. waiting are the secrets of the person's safe the source names that the person has not allowed for this server (or does not have): the provider is kept without them until they do.

func (*Service) Check

func (s *Service) Check(ctx context.Context, id string) (Check, error)

Check asks a saved provider for its models and, when it answers, keeps them.

func (*Service) CheckDraft

func (s *Service) CheckDraft(ctx context.Context, d Draft) (Check, error)

CheckDraft asks the address of a form for its models.

func (*Service) Create

func (s *Service) Create(in Input) (View, error)

Create adds a provider and puts its key into the safe.

func (*Service) Declare

func (s *Service) Declare(list []Declared, whole, dry bool) error

Declare writes accounts. All of it is taken or none: a refusal leaves the registry and the safe as they were. dry only checks: the answer is what a write would say, and nothing changes.

func (*Service) Declared

func (s *Service) Declared() ([]Declared, error)

Declared lists the person's own accounts; the environment's ones are not theirs to write and are left out.

func (*Service) DefaultOf

func (s *Service) DefaultOf(p Provider) (Provider, bool)

DefaultOf is the default account of the provider that p is (or was) an account of; false when it has none left.

func (*Service) Discover

func (s *Service) Discover(ctx context.Context, custom string) (LocalFound, error)

Discover looks for the local model servers of this machine and, when custom is an address, for one there too.

func (*Service) Get

func (s *Service) Get(id string) (Provider, error)

Get is one provider as the registry keeps it.

func (*Service) HasManaged

func (s *Service) HasManaged(origin string) bool

HasManaged says whether the registry has the provider of an environment item.

func (*Service) Key

func (s *Service) Key(p Provider) (string, error)

Key is the provider's key from the safe; "" for a provider that takes none.

func (*Service) List

func (s *Service) List() ([]View, error)

List is the providers as the page sees them.

func (*Service) Models

func (s *Service) Models(ctx context.Context, id string, refresh bool) (ModelList, error)

Models is the models of a provider: the kept ones, or (refresh, or none kept yet) the provider's own answer. A provider that does not answer leaves the kept ones.

func (*Service) PruneManaged

func (s *Service) PruneManaged(keep []string) ([]string, error)

PruneManaged takes off the providers of the environment whose items are not in keep and says which went. Their secrets are not the registry's to remove: they are the person's own, or the organization's.

func (*Service) Remove

func (s *Service) Remove(id string) error

Remove deletes a provider and its key.

func (*Service) Update

func (s *Service) Update(id string, patch Patch) (View, error)

Update changes a provider. A new address or kind of API drops the models taken from the old one, unless the patch brings its own.

func (*Service) ViewOf

func (s *Service) ViewOf(p Provider) View

ViewOf is a provider as the page sees it.

type Store

type Store struct {
	Dir string
	Now func() time.Time
	// contains filtered or unexported fields
}

Store is the registry file of one data folder: <Dir>/providers.json, written whole beside and renamed over.

func (*Store) Get

func (s *Store) Get(id string) (Provider, error)

Get is the provider of that id.

func (*Store) List

func (s *Store) List() ([]Provider, error)

List is the providers in the order they were added.

type View

type View struct {
	ID       string  `json:"id"`
	Name     string  `json:"name"`
	BaseURL  string  `json:"baseUrl"`
	Host     string  `json:"host"`
	API      API     `json:"api"`
	Preset   string  `json:"preset,omitempty"`
	HasKey   bool    `json:"hasKey"`
	Models   []Model `json:"models"`
	ModelsAt int64   `json:"modelsAt,omitempty"`
	// ClaudeCLI: Claude Code runs a chat on the provider; Proxied: through the runtime's proxy (an OpenAI-compatible
	// one), not straight to its address.
	ClaudeCLI bool `json:"claudeCli"`
	Proxied   bool `json:"proxied"`
	// Env are the variables of a launch on the provider; a secret one comes without its value.
	Env []EnvView `json:"env"`
	// Proxy is the account's own proxy, without its password.
	Proxy string `json:"proxy,omitempty"`
	// Group is shared by the accounts of one provider; Default marks the one used where no account is named.
	Group   string `json:"group"`
	Default bool   `json:"default"`
	// Managed: the provider is the environment's; the page shows it and does not let it be changed or removed.
	Managed   bool  `json:"managed"`
	CreatedAt int64 `json:"createdAt"`
	UpdatedAt int64 `json:"updatedAt"`
}

View is a provider as the page sees it: everything but the name of its secret, and whether a key is saved.

Jump to

Keyboard shortcuts

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