binding

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package binding is the domain layer for the HostBinding entity — the first-class join that declares "Model M is served by Host H, via wire adapter A, under upstream name U, priced by Pricing P."

Bindings used to live embedded in model.Spec.Hosts[]. Promoting them to their own entity gives pricing and routing a real row to reference (the embedded array was unaddressable), and lets one Model be bound by many Hosts — including aggregators re-serving another provider's model — without coupling the binding to who owns the Model.

Identity: a binding is a join, owned by no single side, so Owner is system-kind. The (ModelID, HostID) pair is unique — enforced at the DB (UNIQUE constraint) and re-checked in the catalog composition layer.

store.go is the data-access layer for HostBinding. model_id / host_id / pricing_id are real columns (FK integrity + builder joins without JSONB parsing), so they are the source of truth for those refs — stripped from the JSONB spec on write and rebuilt from the columns on read, mirroring how pricing treats host_id. The rest of the spec (adapter, upstreamName, enabled, the snapshots subset) lives in the JSONB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`
}

Binding declares how one Host serves one Model.

func (*Binding) IsEnabled

func (b *Binding) IsEnabled() bool

IsEnabled returns true when Enabled is unset or explicitly true.

func (*Binding) Serves

func (b *Binding) Serves(snapshotName string) bool

Serves reports whether this binding is eligible to route requests for the given snapshot name. Empty Snapshots means "all"; otherwise membership.

func (*Binding) Validate

func (b *Binding) Validate() error

Validate runs intra-row rules via the shared meta.Validator and enforces the binding-specific invariants:

  • Adapter defaults to OpenAI when omitted, then must be a valid upstream binding (the dispatch key — openai|anthropic|gemini).

Cross-entity checks (ModelID/HostID/PricingID resolve; the (model, host) pair is unique; Snapshots name real model snapshots) live in the catalog composition + catalogvalidate layers.

type Spec

type Spec struct {
	ModelID      string        `json:"modelId"                yaml:"modelId"                validate:"required,uuid"`
	HostID       string        `json:"hostId"                 yaml:"hostId"                 validate:"required,uuid"`
	Adapter      adapters.Name `json:"adapter"                yaml:"adapter"`
	UpstreamName string        `json:"upstreamName,omitempty" yaml:"upstreamName,omitempty"`
	PricingID    string        `json:"pricingId,omitempty"    yaml:"pricingId,omitempty"    validate:"omitempty,uuid"`
	Enabled      *bool         `json:"enabled,omitempty"      yaml:"enabled,omitempty"`
	// Snapshots optionally narrows which of the Model's snapshots this Host
	// serves. Empty/nil means "all snapshots"; a non-empty list filters
	// routing to those names only.
	Snapshots []string `json:"snapshots,omitempty" yaml:"snapshots,omitempty"`
}

Spec carries the (model, host) join plus the per-host serving terms: the wire adapter, the upstream model name, an optional Pricing ref, and an optional snapshot subset. Cross-refs are stored as ids (the manifest layer resolves names↔ids); PricingID is optional.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the HostBinding data-access type.

func NewStore

func NewStore(pool *pgxpool.Pool) *Store

NewStore constructs a Store bound to a pool.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a HostBinding by id.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Binding, error)

Get returns the HostBinding with the given id, or (nil, nil) if not found.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Binding, error)

List returns every HostBinding row.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, b *Binding) error

Upsert writes b. Caller stamps Meta.ID.

Jump to

Keyboard shortcuts

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