catalogview

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 17 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

Package catalogview builds consumer-facing read projections of catalog data for the admin/UX surface ("API UX"): a model's hosts, its pricing per host, the policies that grant it. These back resource-navigation endpoints (GET /models/{ref}/hosts, .../pricing, .../policies) and, later, ?expand= on the base model read — the same functions serve both.

Source is Postgres (the entity Stores), NOT the in-memory snapshot: detail/UX views intentionally reflect the full persisted state, including disabled rows, the way the CRUD APIs do. This also keeps the package fully decoupled from the hot path — it never touches app/catalog or app/routing. (A lint-rule guard forbids routing/pipeline/keypool from importing it.)

Composition only. No HTTP, no chi/huma — the control plane binds these functions to routes. Pure-ish: I/O is the store reads; no mutation.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("catalogview: not found")

ErrNotFound is returned when {ref} resolves to no model/host. Handlers map it to 404.

Functions

This section is empty.

Types

type BindingView

type BindingView struct {
	ID           string   `json:"id"                     doc:"Host binding id."`
	Adapter      string   `json:"adapter"                doc:"Wire shape relay speaks to the host for the model."`
	UpstreamName string   `json:"upstreamName,omitempty" doc:"Model name sent upstream, when it differs."`
	Enabled      bool     `json:"enabled"                doc:"Whether the binding is enabled."`
	Snapshots    []string `json:"snapshots,omitempty"    doc:"Snapshots the host serves; empty means all."`
}

type DeprecationView

type DeprecationView struct {
	Status      string `json:"status"                enum:"active,deprecated,sunset" doc:"Lifecycle state."`
	SunsetDate  string `json:"sunsetDate,omitempty"  doc:"Date the vendor stops serving the model, YYYY-MM-DD."`
	Replacement string `json:"replacement,omitempty" doc:"Id of the replacement model."`
}

type HostKeyRef

type HostKeyRef struct {
	ID                    string `json:"id"                    doc:"Host key id."`
	Name                  string `json:"name"                  doc:"Host key slug."`
	Enabled               bool   `json:"enabled"               doc:"Whether the key is enabled."`
	SharedWithPolicyCount int    `json:"sharedWithPolicyCount" doc:"How many other policies link this key, directly or through a pool."` // # of OTHER policies linking this key, directly or through a pool
	ReadOnly              bool   ``                                                                                                      /* 209-byte string literal not displayed */
}

type HostKeyView

type HostKeyView struct {
	ID          string `json:"id"                    doc:"Host key id."`
	Name        string `json:"name"                  doc:"Host key slug."`
	Kind        string `json:"kind"                  enum:"env,stored,oauth" doc:"Where the secret comes from; the secret itself is never shown."` // "env" | "stored"
	DefaultTier string `json:"defaultTier,omitempty" deprecated:"true" doc:"Stored but not applied to requests."`
	Enabled     bool   `json:"enabled"               doc:"Whether the key is enabled."`
	Prefix      string `` /* 385-byte string literal not displayed */
	ReadOnly    bool   `` /* 230-byte string literal not displayed */
}

HostKeyView — one upstream credential targeting this host. Secret-free: only the value-mode discriminator and non-sensitive config.

type HostModelRow

type HostModelRow struct {
	Model   ModelRef     `json:"model"   doc:"The model."`
	Binding BindingView  `json:"binding" doc:"The binding of the model at the host."`
	Pricing *PricingView `json:"pricing" doc:"The binding's pricing; null when unpriced."`
}

HostModelRow — one model served by a host, with its binding + pricing.

type HostPolicyRow

type HostPolicyRow struct {
	ID         string               `json:"id"         doc:"Policy id."`
	Name       string               `json:"name"       doc:"Policy slug."`
	Enabled    bool                 `json:"enabled"    doc:"Whether the policy is enabled."`
	RateLimits []PolicyRateLimitRow `json:"rateLimits" doc:"The rate limits the preset links, model-scoped and unscoped."`
}

HostPolicyRow — a host-tier policy this host owns, with its rate-limit rule sets (model-scoped and unscoped links alike).

type HostRef

type HostRef struct {
	ID          string `json:"id"                    doc:"Host id."`
	Name        string `json:"name"                  doc:"Host slug."`
	DisplayName string `json:"displayName,omitempty" doc:"Display name."`
	BaseURL     string `json:"baseURL,omitempty"     doc:"Upstream root URL."`
	// Enabled + Icon are intrinsic host properties, carried on every HostRef
	// so "host off" flags and real logos render everywhere a host appears.
	Enabled bool      `json:"enabled"        doc:"Whether the host is enabled."`
	Icon    *IconView `json:"icon,omitempty" doc:"Host icon."`
}

type IconView

type IconView struct {
	Path string `json:"path,omitempty" doc:"Icon asset path."`
}

type Limit

type Limit struct {
	Meter    string `json:"meter"    doc:"What the rule counts."`
	Amount   int64  `json:"amount"   doc:"How much of the meter the window allows."`
	Window   string `json:"window"   doc:"The window as a duration string, such as 1m0s."`
	Strategy string `json:"strategy" doc:"Counting algorithm."`
}

type ModelHostRow

type ModelHostRow struct {
	Host    HostRef      `json:"host"    doc:"The host."`
	Binding BindingView  `json:"binding" doc:"The binding of the model at the host."`
	Pricing *PricingView `json:"pricing" doc:"The binding's pricing; null when unpriced."`
}

ModelHostRow — one host serving the model, with its binding + pricing.

type ModelPolicyRow

type ModelPolicyRow struct {
	ID     string   `json:"id"     doc:"Policy id."`
	Name   string   `json:"name"   doc:"Policy slug."`
	Owner  OwnerRef `json:"owner"  doc:"The policy's owner; a host for a tier preset."`
	Limits []Limit  `json:"limits" doc:"Rules of every rate limit the policy applies to this model."`
	// HiddenRateLimits are rate limits that apply but the caller may not see.
	HiddenRateLimits []string `` /* 138-byte string literal not displayed */
}

ModelPolicyRow — flat: a policy that grants this model. Host-tier policies name their host via Owner; user policies grant across hosts (Owner.Kind "user"). Limits are the rules every rate limit linked for THIS model adds.

type ModelPriceRow

type ModelPriceRow struct {
	Host     HostRef `json:"host"     doc:"The pricing host."`
	ID       string  `json:"id"       doc:"Pricing id."`
	Name     string  `json:"name"     doc:"Pricing slug."`
	Currency string  `json:"currency" doc:"Currency of the amounts."`
	Rates    []Rate  `json:"rates"    doc:"The sheet's rates."`
}

ModelPriceRow — flat: one host that prices this model (host inline).

type ModelRef

type ModelRef struct {
	ID          string `json:"id"                    doc:"Model id."`
	Name        string `json:"name"                  doc:"Model slug."`
	DisplayName string `json:"displayName,omitempty" doc:"Display name."`
	// Capabilities/context/deprecation are intrinsic model properties, so
	// they ride along on every ModelRef — the policy, host, and model tabs
	// all render the same capability icons + context window from one shape.
	Capabilities       []string         `json:"capabilities,omitempty"       doc:"Names of the capabilities the model has, such as chat, tools, vision."`
	ContextWindowTotal int              `json:"contextWindowTotal,omitempty" doc:"Context window in tokens."`
	ContextWindowInput int              `json:"contextWindowInput,omitempty" doc:"Published input cap in tokens."`
	Deprecation        *DeprecationView `json:"deprecation,omitempty"        doc:"Lifecycle state; absent means active."`
	Icon               *IconView        `json:"icon,omitempty"               doc:"The model's icon, or its provider's when the model has none."`
}

type OwnerRef

type OwnerRef struct {
	Kind string `json:"kind"           doc:"Owner kind: system, organization, host, user, team or project."` // "user" | "host" | "system" | …
	ID   string `json:"id,omitempty"   doc:"Owner id; for a host's tier preset, the host id."`               // for host-tier policies, the host id
	Name string `json:"name,omitempty" doc:"Owner slug, when it has one."`
}

type PolicyBindingRow

type PolicyBindingRow struct {
	Provider  ProviderRef `json:"provider"  doc:"The model's provider."`
	Host      HostRef     `json:"host"      doc:"The serving host."`
	Model     ModelRef    `json:"model"     doc:"The model."`
	Binding   BindingView `json:"binding"   doc:"The binding of the model at the host."`
	MatchedBy []string    `json:"matchedBy" doc:"The policy's model entries that allow this binding; * when the policy lists no models."`
	Limits    []Limit     `json:"limits"    doc:"Rules of every rate limit the policy applies to this binding."`
	// HiddenRateLimits are rate limits that apply but the caller may not see.
	HiddenRateLimits []string `` /* 138-byte string literal not displayed */
}

PolicyBindingRow — one concrete (provider, model, host) binding this policy grants, fully pre-joined. Mirrors ModelHostRow: the frontend renders rows and groups by host client-side, no catalog round-trip. MatchedBy carries the grant ref(s) that produced this row (raw Spec.Models entries, or "*" for an empty model list) — the one fact the client can't recompute. Limits are resolved for THIS exact triple.

type PolicyHostRow

type PolicyHostRow struct {
	Host        HostRef      `json:"host"        doc:"The host."`
	HostKeys    []HostKeyRef `json:"hostKeys"    doc:"Host keys reaching it through the policy's pools and keys; empty for a tier preset's own host."`
	Requirement string       `` // "required" | "optional"
	/* 201-byte string literal not displayed */
}

PolicyHostRow — a host this policy can reach, with the host-keys that reach it (empty for a host-tier policy's own host, which needs no key to qualify). Requirement is "required" when this host uniquely serves at least one model the policy grants (losing its key would drop that model), else "optional" — a sibling reachable host covers everything it does.

type PolicyModelExclusion

type PolicyModelExclusion struct {
	Model  ModelRef `json:"model"  doc:"The model."`
	Reason string   `json:"reason" doc:"Why the policy does not allow it, such as no matching entry or no host the policy reaches."`
}

PolicyModelExclusion — a model this policy does NOT grant, with why. Surfaced by PolicyModelExclusions (the ?debug view) to make an empty grant diagnosable — e.g. a host-tier policy whose host has no bindings post-migration.

type PolicyRateLimitRow

type PolicyRateLimitRow struct {
	ID      string   `json:"id"               doc:"Rate limit id."`
	Name    string   `json:"name"             doc:"Rate limit slug; empty when hidden."`
	Hidden  bool     `json:"hidden,omitempty" doc:"The caller may not see the rate limit: its name and rules are left out."`
	Default bool     `json:"default"          doc:"The link has no model scope and applies to every model."`
	Models  []string `json:"models,omitempty" doc:"Model references the link is scoped to."`
	Limits  []Limit  `json:"limits"           doc:"The rate limit's rules."`
}

PolicyRateLimitRow — one rate-limit rule set the policy links. Default is an unscoped link, applying to every model; the others carry the model refs they are scoped to.

type PolicyRateLimitsView

type PolicyRateLimitsView struct {
	RateLimits  []PolicyRateLimitRow `json:"rateLimits"`
	Unthrottled []UnthrottledModel   `json:"unthrottled"`
}

PolicyRateLimitsView is the rate-limits tab payload: the linked rule sets plus the models that slip through uncapped. Every matching link applies, so links never shadow each other.

type PolicyRef

type PolicyRef struct {
	ID          string   `json:"id"                    doc:"Policy id."`
	Name        string   `json:"name"                  doc:"Policy slug."`
	DisplayName string   `json:"displayName,omitempty" doc:"Display name."`
	Owner       OwnerRef `json:"owner"                 doc:"The policy's owner."`
	Enabled     bool     `json:"enabled"               doc:"Whether the policy is enabled."`
}

PolicyRef identifies the policy a sub-resource response belongs to.

type PricingView

type PricingView struct {
	ID       string `json:"id"       doc:"Pricing id."`
	Name     string `json:"name"     doc:"Pricing slug."`
	Currency string `json:"currency" doc:"Currency of the amounts."`
	Rates    []Rate `json:"rates"    doc:"The sheet's rates."`
}

type ProviderRef

type ProviderRef struct {
	ID          string `json:"id"                    doc:"Provider id."`
	Name        string `json:"name"                  doc:"Provider slug."`
	DisplayName string `json:"displayName,omitempty" doc:"Display name."`
}

type Rate

type Rate struct {
	Meter       string  `json:"meter"                 doc:"Usage counter the rate prices."`
	Unit        string  `json:"unit"                  enum:"per_million,per_unit" doc:"Unit the amount prices."`
	Amount      float64 `json:"amount"                doc:"Price per unit."`
	AboveTokens int     `json:"aboveTokens,omitempty" doc:"Context tier threshold in prompt tokens; 0 is the base tier."`
	ServiceTier string  `json:"serviceTier,omitempty" doc:"Upstream service tier the rate applies to; empty is the base rate."`
}

type Service

type Service struct {
	Models     modelStore
	Hosts      hostStore
	Bindings   bindingStore
	Pricings   pricingStore
	Policies   policyStore
	RateLimits rateLimitStore
	Providers  providerStore
	HostKeys   hostKeyStore
	// Pools is optional: without it a policy's pools reach no host.
	Pools poolStore
	// Accounts is optional: without it every account projection is a 404.
	Accounts accountStore
	// PersonalAccountOff optionally reports whether a user's personal accounts are turned off, which closes the provider accounts they own and the shares of them. Nil reads every user as on.
	PersonalAccountOff func(userID string) bool

	// Visible optionally scopes rows per owner: policy-rooted projections
	// 404 on a policy the caller may not see, and host-key / policy rows
	// inside other projections are dropped. Nil leaves every row visible
	// (the single-user default). kind is the singular resource kind
	// ("policy", "host-key"); id is that row's metadata.id.
	Visible func(kind, id string, owner meta.Owner) bool
	// Owns optionally reports whether the caller may edit a row; a host key's owners see more of its secret's start than anyone else. Nil owns every row.
	Owns func(kind, id string, owner meta.Owner) bool
}

Service composes the store reads into views. Construct once with the deployment's stores; methods are read-only.

func (*Service) AccountKeys added in v0.20.0

func (s *Service) AccountKeys(ctx context.Context, ref string) (UpstreamRef, []HostKeyView, error)

AccountKeys returns the host keys that belong to the account: the keys sharing its upstream tier limits.

func (*Service) HostKeyList

func (s *Service) HostKeyList(ctx context.Context, ref string) (HostRef, []HostKeyView, error)

HostKeyList returns the upstream credentials this host owns (by id or slug).

func (*Service) HostModels

func (s *Service) HostModels(ctx context.Context, ref string) (HostRef, []HostModelRow, error)

HostModels returns the models a host serves (by id or slug).

func (*Service) HostPolicies

func (s *Service) HostPolicies(ctx context.Context, ref string) (HostRef, []HostPolicyRow, error)

HostPolicies returns the host-tier policies this host owns, with limits.

func (*Service) ModelHosts

func (s *Service) ModelHosts(ctx context.Context, ref string) (ModelRef, []ModelHostRow, error)

ModelHosts returns the hosts serving the model (by id or slug), each with its binding and resolved pricing.

func (*Service) ModelPolicies

func (s *Service) ModelPolicies(ctx context.Context, ref string) (ModelRef, []ModelPolicyRow, error)

ModelPolicies returns the policies that grant this model, flat: on a host the model is bound to and the policy reaches, its model list is empty or matches. Limits are the rules of every linked rate limit that applies to the model there, resolved to numbers.

func (*Service) ModelPricing

func (s *Service) ModelPricing(ctx context.Context, ref string) (ModelRef, []ModelPriceRow, error)

ModelPricing returns the model's pricing per host, flat (host inline).

func (*Service) PolicyHosts

func (s *Service) PolicyHosts(ctx context.Context, ref string) (PolicyRef, []PolicyHostRow, error)

PolicyHosts returns the hosts this policy can reach: the hosts of its pools and credentials (keys folded in per host), and a host-tier policy's own host. A policy linking neither lists only the hosts it grants models on.

func (*Service) PolicyModelExclusions

func (s *Service) PolicyModelExclusions(ctx context.Context, ref string) (PolicyRef, []PolicyModelExclusion, error)

PolicyModelExclusions returns the models this policy does NOT grant, each with the reason — the diagnostic complement to PolicyModels. Use it to explain an empty grant list (missing bindings, non-matching DSL).

func (*Service) PolicyModels

func (s *Service) PolicyModels(ctx context.Context, ref string) (PolicyRef, []PolicyBindingRow, error)

PolicyModels returns one row per concrete (model, host) binding this policy grants, on the hosts it reaches. Limits are resolved per triple.

func (*Service) PolicyRateLimits

func (s *Service) PolicyRateLimits(ctx context.Context, ref string) (PolicyRef, PolicyRateLimitsView, error)

PolicyRateLimits returns the rate-limit rule sets the policy links, in declared order, plus the unthrottled-models derivation.

func (*Service) PoolKeys added in v0.20.0

func (s *Service) PoolKeys(ctx context.Context, ref string) (UpstreamRef, []HostKeyView, error)

PoolKeys returns the pool's keys in pool order, the preference a prioritized pool tries them in: each listed account's keys in creation order, then the listed keys, a key reached twice at its first place. A shared account's keys are its real account's, listed read-only; other keys the caller may not see are dropped.

type UnthrottledModel

type UnthrottledModel struct {
	Model ModelRef `json:"model" doc:"An allowed model no linked rate limit covers."`
}

UnthrottledModel — a model the policy grants on which no rate-limit applies (every granted binding of it resolves to an empty limit set).

type UpstreamRef added in v0.20.0

type UpstreamRef struct {
	ID     string `json:"id"     doc:"Pool or account id."`
	Name   string `json:"name"   doc:"Pool or account slug."`
	HostID string `json:"hostId" doc:"Id of the host its keys authenticate to."`
}

UpstreamRef names the pool or account a key list belongs to.

Jump to

Keyboard shortcuts

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