modelcatalog

package
v0.0.35 Latest Latest
Warning

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

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

README

Read-only model directory

This public library has no proxy-server startup or configuration-writing dependency.

  • ReadSource(path, name) reads the existing selected http-proxy provider using the config UI's first-selected / else-first credential rule. Empty path uses the normal llm-proxy config location.
  • Source.Endpoint() returns backend-only GET authentication. Source.Reference describes the existing credential location without copying its private value; public dummy markers are explicitly identified. Do not serve Source, Provider, Credential, or credential references as a UI DTO.
  • Client.Load(ctx, endpoint, refresh) does GET only. It uses a bounded request/response, rejects redirects, redacts the current token from errors, and keys its memory cache by URL plus a SHA256 of the credential. Returned values are defensively copied. It never tests capability with an inference request.
  • Parse preserves opaque upstream IDs and optional advertised reasoning metadata. Invalid/incomplete metadata is not evidence of unsupported reasoning.
  • Source.Reasoning(model) prefers API metadata, then relevant explicit configuration. Config alias keys are translated to their actual wire values; disabled/local aliases are not inferred as direct upstream capability. Provenance remains api, configured, or unknown.
  • Client-specific CLI vocabulary filtering belongs to the caller/runner adapter. Do not copy the historical proxy catalog export's conservative Codex whitelist into a different runtime without wire verification.

Use go test ./pkgs/modelcatalog ./open_ai for public behavior and old config-UI compatibility. Tests use localhost fixtures and check cache/credential isolation, GET-only discovery, cancellation/redaction, reference guards, and unchanged source configuration.

Documentation

Overview

Package modelcatalog reads provider model directories without inference or configuration writes.

Index

Constants

View Source
const MaxBytes = 1 << 20

Variables

View Source
var ErrRunning = errors.New("a probe is already running")

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

func ModelURL

func ModelURL(base string) (string, error)

func SafeURL

func SafeURL(raw string) string

func ValidateReasoning

func ValidateReasoning(m Model) error

ValidateReasoning checks shape, not a particular client's fixed vocabulary. A gateway may add values which an individual client must subsequently filter.

Types

type Catalog

type Catalog struct {
	FetchedAt time.Time
	Models    []Model
	Notes     []string
	Auth      string
}

func Parse

func Parse(body []byte) (Catalog, error)

Parse accepts the OpenAI-style data array. It does not identify products from ids.

type Client

type Client struct {
	HTTP *http.Client
	TTL  time.Duration
	// contains filtered or unexported fields
}

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, e Endpoint) (Catalog, error)

func (*Client) Load

func (c *Client) Load(ctx context.Context, e Endpoint, refresh bool) (Catalog, error)

Load caches by URL and credential fingerprint; callers retain their prior UI snapshot on errors. Neither this method nor Fetch ever makes a POST request.

type Credential

type Credential struct {
	Name       string `json:"name"`
	Selected   bool   `json:"selected"`
	Home       string `json:"home"`
	AuthFile   string `json:"authFile"`
	BaseURL    string `json:"baseUrl"`
	Token      string `json:"token"`
	TokenFile  string `json:"tokenFile"`
	DummyToken string `json:"dummyToken"`
}

Credential and Provider are the configuration schema shared with the config UI. They contain secrets: do not use them as an HTTP response or session record.

type Endpoint

type Endpoint struct {
	URL   string
	Token string `json:"-"`
	Auth  string
}

Endpoint is trusted backend input. Never include Token in a UI payload or logs.

func (Endpoint) GoString

func (e Endpoint) GoString() string

func (Endpoint) String

func (e Endpoint) String() string

type Model

type Model struct {
	ID                     string   `json:"id"`
	Name                   string   `json:"name,omitempty"`
	DisplayName            string   `json:"display_name,omitempty"`
	ContextWindow          int      `json:"context_window,omitempty"`
	ContextLength          int      `json:"context_length,omitempty"`
	MaxTokens              int      `json:"max_tokens,omitempty"`
	MaxOutputTokens        int      `json:"max_output_tokens,omitempty"`
	ReasoningEfforts       []string `json:"reasoning_efforts,omitempty"`
	DefaultReasoningEffort string   `json:"default_reasoning_effort,omitempty"`
}

Model preserves the upstream id verbatim; display names and vendor aliases are not routing ids.

func (Model) Reasoning

func (m Model) Reasoning() Reasoning

type Provider

type Provider struct {
	Name          string       `json:"name"`
	Kind          string       `json:"kind"`
	Subscription  bool         `json:"subscription"`
	Home          string       `json:"home"`
	AuthFile      string       `json:"authFile"`
	Version       string       `json:"version"`
	BaseURL       string       `json:"baseUrl"`
	Protocol      string       `json:"protocol"`
	ModelListMode string       `json:"modelListMode"`
	Token         string       `json:"token"`
	TokenFile     string       `json:"tokenFile"`
	DummyToken    string       `json:"dummyToken"`
	Credentials   []Credential `json:"credentials"`
}

func (*Provider) ApplySelected

func (p *Provider) ApplySelected()

func (Provider) SelectedCredentialIndex

func (p Provider) SelectedCredentialIndex() int

SelectedCredentialIndex preserves the config UI's first-selected, else first policy.

type Reasoning

type Reasoning struct {
	State   string   `json:"state"`
	Source  string   `json:"source"`
	Efforts []string `json:"efforts,omitempty"`
	Default string   `json:"default,omitempty"`
}

Reasoning is advertised or explicitly configured metadata, never an inference result. Unknown is distinct from unsupported. A disabled generated proxy route alone is not evidence that the upstream cannot reason.

type Source

type Source struct {
	Path      string         `json:"-"`
	Name      string         `json:"name"`
	BaseURL   string         `json:"base_url"`
	Protocol  string         `json:"protocol"`
	Reference TokenReference `json:"credential_reference"`
	// contains filtered or unexported fields
}

Source is a backend-only snapshot. JSON and diagnostic formatting do not expose credentials.

func ReadSource

func ReadSource(path, name string) (Source, error)

ReadSource reads only the named provider and relevant explicit model declarations. Invalid unrelated routes do not prevent discovery; no configuration is changed.

func (Source) Endpoint

func (s Source) Endpoint() (Endpoint, error)

func (Source) GoString

func (s Source) GoString() string

func (Source) Reasoning

func (s Source) Reasoning(m Model) Reasoning

func (Source) String

func (s Source) String() string

type TokenReference

type TokenReference struct {
	File        string            `json:"file,omitempty"`
	JSONPointer string            `json:"json_pointer,omitempty"`
	Guards      map[string]string `json:"guards,omitempty"`
	PublicToken string            `json:"public_token,omitempty"`
}

TokenReference describes an existing credential without copying its secret. JSON guards keep a reordered or retargeted config from silently changing identity.

Jump to

Keyboard shortcuts

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