Help us shape the future of Go! Take the 2026 Go Developer Survey

catalog

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package catalog loads, validates, and queries provider and model descriptions.

Index

Constants

View Source
const (
	SectionImageAPI = "ImageAPI"
	SectionVideoAPI = "VideoAPI"
)

Configuration section names used in validation errors.

  • SectionImageAPI: the shared image API settings
  • SectionVideoAPI: the shared video API settings
  • sectionAdapterPoll: the adapter's generation polling settings
  • sectionAdapterFilePoll: the adapter's file polling settings
View Source
const (
	AliasContextForm             = "%s alias %s"
	AllowedValueBelowCount       = "model %s, flag %s: allowed value %q below the minimum count of one"
	AllowedValueFault            = "model %s, flag %s: allowed value %s"
	ConfigMissing                = "no config section holding the request settings"
	ConfigProviderSourceMismatch = "%s: declares provider %q under the %q source"
	FrameMediaIncomplete         = "VideoAPI: incomplete frame-media description"
	ImageAPIMissing              = "no ImageAPI for the declared image medium"
	ImageFallbackExtMissing      = "AdapterAPI: no ImageFallbackExt for the declared image medium"
	InputMediaEncodingConflict   = "%s: input media encoding %q cannot use style %q"
	InputMediaParamMissing       = "%s: required input media field name is missing"
	InputMediaPayloadTypeInvalid = "%s: InputMediaPayloadType %q invalid (want json|form)"
	InputMediaStyleInvalid       = "%s: InputMediaStyle %q invalid (want parts|nested|single-or-array|string)"
	ModelFlagDuplicate           = "model %s: duplicate params entry for flag %s"
	ModelFlagFault               = "model %s, flag %s: %s"
	ModelIDMissing               = "model ID must not be empty"
	ModelMediaInvalid            = "model %s: invalid Media %q (want image|video)"
	ModelNameMissing             = "model %s: no name declared"
	ParamGuidanceMissing         = "model %s, flag %s: no allowed values, range, or size bounds declared, and the flag record has no text hint or example values"
	ParamsFlagUnknown            = "model %s: params entry flagID %q names no enumerated flag"
	PollBudgetNotPositive        = "VideoAPI: PollTimeout %d not positive"
	PollIntervalInvalid          = "%s: interval %d not positive"
	PollIntervalNotPositive      = "VideoAPI: PollInterval %d not positive"
	PollTimeoutInvalid           = "%s: timeout %d not positive"
	ProviderDefaultModelUnknown  = "provider %s: defaultModel %q names no model of the provider"
	RequestPathConflict          = "model %s: request paths %q and %q conflict"
	RequestPathInvalid           = "model %s: request path %q contains an empty segment"
	StringParamsUnknownFlag      = "StringParams: unknown flagID %q"
	VideoAPIMissing              = "no VideoAPI for the declared video medium"
	VideoFallbackExtMissing      = "AdapterAPI: no VideoFallbackExt for the declared video medium"
)

The internal/catalog section of the copy catalog, one constant per entry.

View Source
const (
	InputMediaPayloadForm = "form"
)

The request encodings a configuration may declare for input media.

  • inputMediaPayloadJSON: input media travels inside the JSON body
  • InputMediaPayloadForm: input media travels as multipart form parts
View Source
const KeySeparator = "/"

KeySeparator joins provider and model IDs and separates their searchable tokens.

Variables

This section is empty.

Functions

func CompareProviders

func CompareProviders(firstProvider, secondProvider Provider) int

CompareProviders sorts first-party providers before aggregators, then by display name without regard to case.

Types

type AdapterAPI

type AdapterAPI struct {
	APIBase           string      `json:"apiBase"`
	PollInterval      PollSeconds `json:"pollInterval"`
	PollTimeout       PollSeconds `json:"pollTimeout"`
	FilePollInterval  PollSeconds `json:"filePollInterval"`
	FilePollTimeout   PollSeconds `json:"filePollTimeout"`
	PendingStatusText []string    `json:"pendingStatusText"`
	ReadyStatusText   string      `json:"readyStatusText"`
	FailedStatusText  []string    `json:"failedStatusText"`
	ImageFallbackExt  string      `json:"imageFallbackExt"`
	VideoFallbackExt  string      `json:"videoFallbackExt"`
}

AdapterAPI contains endpoints, polling settings, status values, and fallback extensions for an adapter.

  • APIBase: the base API endpoint
  • PollInterval: seconds between generation status requests
  • PollTimeout: the generation polling budget in seconds
  • FilePollInterval: seconds between file status requests
  • FilePollTimeout: the file polling budget in seconds
  • PendingStatusText: the statuses that indicate pending work
  • ReadyStatusText: the status that indicates completed work
  • FailedStatusText: the statuses that indicate failed work
  • ImageFallbackExt: the fallback extension for downloaded images
  • VideoFallbackExt: the fallback extension for downloaded videos

type Catalog

type Catalog struct {
	Providers []Provider    `json:"providers"`
	Flags     []params.Flag `json:"flags,omitempty"`
	// contains filtered or unexported fields
}

Catalog contains validated providers, their flag definitions, and individual loading failures.

  • Providers: the loaded providers in source order
  • Flags: the parameter flag definitions used for validation

func LoadCatalog

func LoadCatalog(flags []params.Flag, sources ...Source) (*Catalog, error)

LoadCatalog loads provider descriptions in source order and validates them against flags. Individual configuration failures are retained in the catalog and exclude that provider; a source identity mismatch or a conflicting provider/model identifier or alias fails the load.

func (*Catalog) ConfigError

func (catalog *Catalog) ConfigError(providerID string) error

ConfigError returns a provider's stored loading failure, or nil when none was recorded.

func (*Catalog) DefaultModelKey

func (catalog *Catalog) DefaultModelKey(availableProviders map[string]bool) (string, bool)

DefaultModelKey returns the declared default of the first available provider in listing order. It reports false when no available provider declares a default.

func (*Catalog) ModelDirectory

func (catalog *Catalog) ModelDirectory() []ProvModelPair

ModelDirectory returns the provider and model pairs of every loaded provider in load order, each carrying the provider's identity and a deep copy of the model.

func (*Catalog) Provider

func (catalog *Catalog) Provider(providerID string) (Provider, bool)

Provider returns a deep copy of the named provider and whether it was loaded.

func (*Catalog) ResolveModelInput

func (catalog *Catalog) ResolveModelInput(modelSpecifier string) ([]ProvModelPair, error)

ResolveModelInput returns the provider and model pairs named by a model specifier. It checks explicit provider/model pairs, aliases, then unqualified model identifiers.

type ImageAPI

type ImageAPI struct {
	GenURL                  string            `json:"genURL"`
	InputMediaURL           string            `json:"inputMediaURL"`
	InputMediaProvParam     string            `json:"inputMediaProvParam"`
	InputMediaListProvParam string            `json:"inputMediaListProvParam,omitempty"`
	InputMediaPayloadType   string            `json:"inputMediaPayloadType"`
	InputMediaStyle         InputMediaStyle   `json:"inputMediaStyle"`
	FixedProvFields         map[string]string `json:"fixedProvFields"`
	FallbackExt             string            `json:"fallbackExt"`
	RespImageURL            bool              `json:"respImageURL"`
}

ImageAPI describes the endpoints and wire format for image generation.

  • GenURL: the image generation endpoint
  • InputMediaURL: the endpoint used when input media is present
  • InputMediaListProvParam: the array field for multiple single-or-array references
  • InputMediaProvParam: the request field for input media
  • InputMediaPayloadType: the request encoding for input media
  • InputMediaStyle: the JSON layout for input media
  • FixedProvFields: the constant request fields
  • FallbackExt: the file extension used when the response does not identify its media format
  • RespImageURL: whether response image URLs are downloaded

type InputMediaStyle

type InputMediaStyle string

InputMediaStyle identifies the request layout used for input media.

const (
	InputMediaParts  InputMediaStyle = "parts"
	InputMediaSingle InputMediaStyle = "single-or-array"
	InputMediaNested InputMediaStyle = "nested"
	InputMediaString InputMediaStyle = "string"
)

Input media request layouts.

  • InputMediaParts: local images are sent as multipart file parts
  • InputMediaSingle: one reference uses a single field and multiple references use an array
  • InputMediaNested: references use nested image_url or video_url objects
  • InputMediaString: references use URL or data-URI strings directly

type Model

type Model struct {
	ID            string             `json:"id"`
	Name          string             `json:"name"`
	Description   string             `json:"description,omitempty"`
	Media         media.Kind         `json:"media"`
	Family        string             `json:"family,omitempty"`
	Aliases       []string           `json:"aliases,omitempty"`
	PromptIgnored bool               `json:"promptIgnored,omitempty"`
	DocsURL       string             `json:"docsURL,omitempty"`
	Params        params.Definitions `json:"params,omitempty"`
}

Model contains a model's identity, media kind, family, aliases, and accepted parameters.

  • ID: the provider's model identifier
  • Name: the model's configured display name
  • Description: the optional model description
  • Media: the kind of output the model produces
  • Family: the model family used when a provider varies its request format by family
  • Aliases: alternate model specifiers
  • PromptIgnored: whether the model ignores the prompt and therefore requires none
  • DocsURL: the model's documentation address
  • Params: the parameter definitions accepted by the model

func (*Model) Param

func (model *Model) Param(flagName params.FlagType) (params.Definition, bool)

Param takes a flag name and returns its configuration and whether it is declared.

func (*Model) SupportsParam

func (model *Model) SupportsParam(flagName params.FlagType) bool

SupportsParam takes a parameter name and reports whether the model accepts it.

type PollSeconds

type PollSeconds int

PollSeconds is an interval or timeout expressed in whole seconds in a provider description.

func (PollSeconds) Duration

func (seconds PollSeconds) Duration() time.Duration

Duration returns the configured number of seconds as a duration.

type ProvModelPair

type ProvModelPair struct {
	Provider Provider
	Model    Model
}

ProvModelPair contains a provider and one of its models.

  • Provider: the provider's identity; its models and request settings are read from the catalog
  • Model: the selected model configuration

func SearchDirectory

func SearchDirectory(pairs []ProvModelPair, searchTerm, excludeTerm string, useRegexp bool) ([]ProvModelPair, error)

SearchDirectory selects matching pairs, applies exclusions, and preserves directory order. Prefix terms match key tokens or aliases without regard to case; regular expressions also match complete keys and return an error if invalid. Empty terms impose no filter, and searchResultLimit applies only when a nonempty search term is supplied.

func SelectMedia

func SelectMedia(pairs []ProvModelPair, imageSelected, videoSelected bool) []ProvModelPair

SelectMedia takes provider-model pairs and the media selections, and returns the pairs whose model generates a selected medium, in input order.

func (*ProvModelPair) Label

func (pair *ProvModelPair) Label() string

Label formats the provider and model identifiers for diagnostics.

type Provider

type Provider struct {
	ID           string          `json:"id"`
	DisplayName  string          `json:"displayName"`
	APIKeyEnvVar string          `json:"apiKeyEnvVar"`
	Aggregator   bool            `json:"aggregator,omitempty"`
	DefaultModel string          `json:"defaultModel,omitempty"`
	DocsURL      string          `json:"docsURL,omitempty"`
	Models       []Model         `json:"models,omitempty"`
	Config       *ProviderConfig `json:"config,omitempty"`
}

Provider contains the identity, models, and request settings declared by one provider configuration.

  • ID: the provider's catalog identifier
  • DisplayName: the provider name shown to users
  • APIKeyEnvVar: the environment variable that supplies the provider's API key
  • Aggregator: whether the provider offers models from multiple vendors
  • DefaultModel: the model ID used for default selection, or empty when undeclared
  • DocsURL: the provider's documentation address
  • Models: the models in configuration order
  • Config: the provider's request settings, absent in identity-only copies

func (*Provider) Identity

func (p *Provider) Identity() Provider

Identity returns the provider's identity without its models or request settings.

type ProviderConfig

type ProviderConfig struct {
	StringParams []params.FlagType `json:"stringParams,omitempty"`
	ImageAPI     *ImageAPI         `json:"imageAPI,omitempty"`
	VideoAPI     *VideoAPI         `json:"videoAPI,omitempty"`
	AdapterAPI   *AdapterAPI       `json:"adapterAPI,omitempty"`
}

ProviderConfig contains the request settings consumed by generators.

  • StringParams: the parameters sent as strings regardless of their data type
  • ImageAPI: the optional shared image API settings
  • VideoAPI: the optional shared video API settings
  • AdapterAPI: the optional settings for a provider-specific adapter

func (*ProviderConfig) Clone

func (config *ProviderConfig) Clone() ProviderConfig

Clone returns independent copies of the request settings and their nested collections.

type Source

type Source struct {
	ProviderID  string
	ConfigBytes []byte
}

Source identifies an embedded provider description supplied by the command.

  • ProviderID: the provider identifier expected in the document
  • ConfigBytes: the complete encoded provider description

type VideoAPI

type VideoAPI struct {
	AsyncJobsURL            string          `json:"asyncJobsURL"`
	URLStartPath            string          `json:"urlStartPath"`
	JobIDField              string          `json:"jobIDField"`
	ProgressStatusText      []string        `json:"progressStatusText"`
	CompletedStatusText     string          `json:"completedStatusText"`
	FailedStatusText        []string        `json:"failedStatusText"`
	URLPathSeq              []string        `json:"urlPathSeq"`
	URLPathRequired         bool            `json:"urlPathRequired"`
	URLContentPath          string          `json:"urlContentPath"`
	AuthDownload            bool            `json:"authDownload"`
	InputMediaPayloadType   string          `json:"inputMediaPayloadType"`
	InputMediaProvParam     string          `json:"inputMediaProvParam"`
	InputMediaListProvParam string          `json:"inputMediaListProvParam,omitempty"`
	InputMediaStyle         InputMediaStyle `json:"inputMediaStyle"`
	InputMediaMustResize    bool            `json:"inputMediaMustResize"`
	FrameMediaProvParam     string          `json:"frameMediaProvParam"`
	FrameRoleProvParam      string          `json:"frameRoleProvParam"`
	FirstFrameProvValue     string          `json:"firstFrameProvValue"`
	LastFrameProvValue      string          `json:"lastFrameProvValue"`
	FallbackExt             string          `json:"fallbackExt"`
	PollInterval            PollSeconds     `json:"pollInterval"`
	PollTimeout             PollSeconds     `json:"pollTimeout"`
}

VideoAPI describes the endpoints, wire format, and polling settings for video generation.

  • AsyncJobsURL: the base endpoint for video jobs
  • URLStartPath: the path used to start a video job
  • JobIDField: the response field containing the job identifier
  • ProgressStatusText: the statuses that indicate a running job
  • CompletedStatusText: the status that indicates a completed job
  • FailedStatusText: the statuses that indicate a failed job
  • URLPathSeq: the response path leading to the video download URL
  • URLPathRequired: whether a completed response must contain a download URL
  • URLContentPath: the path used to download video content when the response has no URL
  • AuthDownload: whether same-origin downloads receive the provider credential
  • InputMediaPayloadType: the request encoding for input media
  • InputMediaListProvParam: the array field for multiple single-or-array references
  • InputMediaProvParam: the request field for ordinary input media
  • InputMediaStyle: the JSON layout for ordinary input media
  • InputMediaMustResize: whether local input images must match the requested dimensions
  • FrameMediaProvParam: the request field for timed frame images
  • FrameRoleProvParam: the field naming a frame image's role
  • FirstFrameProvValue: the role value for an opening frame
  • LastFrameProvValue: the role value for a closing frame
  • FallbackExt: the file extension used when the response does not identify its media format
  • PollInterval: the number of seconds between job status requests
  • PollTimeout: the maximum number of seconds allowed for job polling

func (*VideoAPI) FrameFields

func (api *VideoAPI) FrameFields() (present, complete bool)

FrameFields reports whether any frame field is present and whether all frame fields are present.

Jump to

Keyboard shortcuts

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