profiles

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 29 Imported by: 1 module, 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

Named endpoint configurations and the credentials that turn them into providers

Index

Constants

View Source
const ConfigDirEnv = "ICEBATH_CONFIG_DIR"

Environment variable naming the directory every icebath configuration file lives in

View Source
const ExecTimeout = 15 * time.Second

Budget for an exec source

Variables

This section is empty.

Functions

func AddCatalog

func AddCatalog(models ...Model)

Adds models whose metadata wins over the built in catalog for the same id

func ConfigDir

func ConfigDir() (string, error)

Directory holding icebath configuration, the environment override, else icebath under the user configuration directory

func DoJSON

func DoJSON(ctx context.Context, p *provider.Provider, call protocol.Call, v any) error

Issues any call through the provider and decodes the JSON body into v

func GetJSON

func GetJSON(ctx context.Context, p *provider.Provider, path string, query url.Values, v any) error

Issues a GET through the provider and decodes the JSON body into v

func Normalize

func Normalize(id string) string

Reduces a vendor or router specific model id to the bare id the catalog keys on

func Register

func Register(p Profile)

Makes a built in profile available to Lookup, panicking on an invalid or duplicate one

func RegisterAuth

func RegisterAuth(kind AuthKind, b AuthBuilder)

Makes an auth kind buildable, panicking on a duplicate or a generic kind

func RegisterVendor

func RegisterVendor(v Vendor)

Makes a vendor available to profiles naming it, panicking on a duplicate

func UserPath

func UserPath() (string, error)

Path of the user profile list inside the configuration directory

func ValidName

func ValidName(name string) bool

Reports whether a name starts with a letter or digit followed by letters, digits, underscores, dots or dashes

func Vendors

func Vendors() []string

Registered vendor names sorted

func WriteFile

func WriteFile(path string, d Document) error

Saves the document as an object with the default and the profile list, readable by the owner alone

Types

type AuthBuilder

type AuthBuilder func(p Profile, key string) (provider.Auth, error)

Builds the credential carrier for an auth kind the generic layer does not know

type AuthKind

type AuthKind string

How a credential travels on the request

const (
	AuthNone   AuthKind = "none"
	AuthBearer AuthKind = "bearer"
	AuthHeader AuthKind = "header"
	AuthQuery  AuthKind = "query"
)
const AuthSigV4 AuthKind = "aws-sigv4"

Auth kind signing requests with AWS credentials

func AuthKinds

func AuthKinds() []AuthKind

Every auth kind a profile may name, the generic ones first and registered ones sorted after

type Capabilities

type Capabilities struct {
	Tools     bool `json:"tools"`
	Vision    bool `json:"vision"`
	Thinking  bool `json:"thinking"`
	Documents bool `json:"documents"`
}

What a model accepts on the request side

type CredentialState

type CredentialState string

Where a profile credential stands

const (
	CredentialUnneeded CredentialState = "none needed"
	CredentialSet      CredentialState = "set"
	CredentialMissing  CredentialState = "missing"
)

type Document

type Document struct {
	Default  string
	Profiles []Profile
}

Profile list as written, with the name of the profile used when the configuration names none

func Read

func Read(r io.Reader) (Document, error)

Reads a list of profiles, or an object holding the list under profiles beside the default name

func ReadFile

func ReadFile(path string) (Document, error)

Reads a profile file, naming the path in every error but a missing file

func (Document) Expanded

func (d Document) Expanded() ([]Profile, error)

Profiles with their templates applied, ready to open

func (Document) Index

func (d Document) Index(name string) int

Index of the profile with the name, -1 when there is none

func (*Document) Move

func (d *Document) Move(name string, delta int) error

Moves the profile delta places through the order, held at either end

func (*Document) Put

func (d *Document) Put(old string, p Profile) error

Replaces the profile named old, or appends p when old is empty, keeping its place in the order

func (*Document) Remove

func (d *Document) Remove(name string) error

Drops the profile with the name and the default when it pointed there

func (Document) Validate

func (d Document) Validate() error

Checks every profile and that no two share a name

type Model

type Model struct {
	ID        string `json:"id"`
	Name      string `json:"name,omitempty"`
	Vendor    string `json:"vendor,omitempty"`
	Context   int    `json:"context,omitempty"`
	MaxOutput int    `json:"max_output,omitempty"`
	// Unix seconds when the endpoint reports a creation time
	Created      int64         `json:"created,omitempty"`
	Pricing      *Pricing      `json:"pricing,omitempty"`
	Capabilities *Capabilities `json:"capabilities,omitempty"`
}

One model an endpoint serves, with zero for limits the endpoint does not report and nil for metadata it does not know

func Catalog

func Catalog() []Model

Every model the built in catalog and any added lists describe, added entries first

func Describe

func Describe(id string) (Model, bool)

Catalog entry for a model id in any vendor spelling, matching the longest known id the normalized form starts with

func Enrich

func Enrich(models []Model) []Model

Fills the context, output limit, pricing and capabilities a listing left blank from the catalog

func LoadCatalog

func LoadCatalog(r io.Reader) ([]Model, error)

Reads a catalog JSON file, a list or an object with a models list, and adds it

func LoadCatalogFile

func LoadCatalogFile(path string) ([]Model, error)

type Pricing

type Pricing struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cache_read,omitempty"`
	CacheWrite float64 `json:"cache_write,omitempty"`
}

Dollars per million tokens of each usage kind, zero where the endpoint charges nothing or the rate is unknown

func (Pricing) Cost

func (p Pricing) Cost(u protocol.Usage) float64

Dollars the usage cost at these rates, reasoning tokens counting as output already

func (Pricing) Known

func (p Pricing) Known() bool

Reports whether any rate is set

type Profile

type Profile struct {
	Name string `json:"name"`
	// Built in profile this one starts from, filling every field left empty
	Template string `json:"template,omitempty"`
	// Kept out of pickers and refused when chosen
	Disabled bool `json:"disabled,omitempty"`
	// Family of the endpoint, naming the registered vendor whose conventions apply
	Vendor   string      `json:"vendor,omitempty"`
	Protocol protocol.ID `json:"protocol,omitempty"`
	BaseURL  string      `json:"base_url,omitempty"`
	Auth     AuthKind    `json:"auth,omitempty"`
	// Header or query parameter name carrying the credential
	AuthName string `json:"auth_name,omitempty"`
	// Where the credential comes from
	Key Source `json:"key,omitzero"`
	// Static headers the endpoint expects on every request
	Header http.Header `json:"header,omitempty"`
	// Static query parameters the endpoint expects on every request
	Query url.Values `json:"query,omitempty"`
	// Model ids the endpoint is known to serve, the first being the default
	Models []string `json:"models,omitempty"`
	// Environment variable whose value replaces the base URL when set
	BaseURLEnv string `json:"base_url_env,omitempty"`
	// Request fields merged into every turn sent through the endpoint
	Extra map[string]json.RawMessage `json:"extra,omitempty"`
	// Base prompt sent in place of the built in one, none sending no prompt at all
	System Source `json:"system,omitzero"`
	// Leaves the environment block about the machine and session out of the system prompt
	NoContext bool `json:"no_context,omitempty"`
	// Asks the endpoint to add no prompt or tools of its own
	Bare bool `json:"bare,omitempty"`
	// Keeps sessions off disk and asks the endpoint to keep nothing of them
	Ghost bool `json:"ghost,omitempty"`
	// Hands the model's thinking to the transcript, false keeping every thinking event out of the window, nil taking the template's
	Thinking *bool `json:"thinking,omitempty"`
	// Headers and body fields that ask the endpoint to keep nothing, nil taking the template's
	GhostDirective *provider.Directive `json:"ghost_directive,omitempty"`
	// Headers and body fields that ask the endpoint to add nothing of its own, nil taking the template's
	BareDirective *provider.Directive `json:"bare_directive,omitempty"`
	// Settings read by registered auth builders and vendors
	Options map[string]string `json:"options,omitempty"`
}

Declarative description of one endpoint and where its credential comes from

func Defaults

func Defaults() []Profile

Built in profiles sorted by name, each a copy that leaves the registry untouched

func Lookup

func Lookup(name string) (Profile, bool)

Finds a built in profile by name, returning a copy that leaves the registry untouched

func (Profile) Build

func (p Profile) Build(key string) (*provider.Provider, error)

Builds a provider from the profile and a credential, resolving the protocol from the registry

func (Profile) Clone

func (p Profile) Clone() Profile

Deep copy whose maps and slices share nothing with the original

func (Profile) Credential

func (p Profile) Credential(ctx context.Context) (CredentialState, string, error)

Checks that the profile can produce its credential without sending a request, naming the source rather than the key

func (Profile) Expand

func (p Profile) Expand() (Profile, error)

Profile with every empty field taken from its template, unchanged without one

func (Profile) ListModels

func (p Profile) ListModels(ctx context.Context, prov *provider.Provider) ([]Model, error)

Lists the models the endpoint serves through the vendor the profile names

func (Profile) Model

func (p Profile) Model() string

Default model id, the first listed, or empty

func (Profile) Open

func (p Profile) Open(ctx context.Context) (*provider.Provider, error)

Builds a provider with the credential read from the key source and the base URL override applied

func (Profile) Resolved

func (p Profile) Resolved() Profile

Profile with the base URL override from the environment applied when the variable is set

func (Profile) ShowsThinking

func (p Profile) ShowsThinking() bool

Reports whether thinking reaches the transcript, which it does unless the profile turns it off

func (Profile) Validate

func (p Profile) Validate() error

Checks that the profile names everything a build will need

type Source

type Source struct {
	Kind  SourceKind `json:"kind,omitempty"`
	Value string     `json:"value,omitempty"`
}

One source of text, the zero value yielding none

func Env

func Env(name string) Source

func (Source) Describe

func (s Source) Describe() string

Names the source without revealing static text

func (Source) Resolve

func (s Source) Resolve(ctx context.Context) (string, error)

Produces the text, empty with no error for the zero source

func (*Source) UnmarshalJSON

func (s *Source) UnmarshalJSON(data []byte) error

Accepts the object form or a string joining kind and value with a colon

type SourceKind

type SourceKind string

Where a text such as a credential or a prompt comes from

const (
	// Value names an environment variable
	SourceEnv SourceKind = "env"
	// Value is the text itself
	SourceStatic SourceKind = "static"
	// Value is a path whose trimmed contents are the text
	SourceFile SourceKind = "file"
	// Value is a shell command whose trimmed output is the text
	SourceExec SourceKind = "exec"
	// No text, kept over the source of a template
	SourceNone SourceKind = "none"
)

type Vendor

type Vendor struct {
	Name string
	// Lists the models an endpoint of this family serves
	Models func(ctx context.Context, p *provider.Provider) ([]Model, error)
}

Conventions of one endpoint family registered by its package

func LookupVendor

func LookupVendor(name string) (Vendor, bool)

Jump to

Keyboard shortcuts

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