Documentation
¶
Overview ¶
Package models provides a single, effective description of a model within a workspace.
A model is named by one ID ("provider/model") and described by one immutable Model, built once when the workspace loads (and on reload). The Model merges the workspace manifest layer (a workspace.ProviderModel) with the built-in provider profile layer (a loom profile.Profile), applying a single set of merge rules. After it is built, every lookup is a map read.
Call preferences are validated against a Model by [Configure], a pure function that returns the effective loom configuration. Instances of loom models are cheap to construct, so they are built on demand by the gateway and never cached.
The Catalog holds the built models of one workspace and is the only place resolution happens; clients receive resolved model data and never re-implement resolution.
Index ¶
- Variables
- func RankMatch(rawQuery string, m Model) (tier, score int, ok bool)
- func SuggestClosest(listed []Model, requested string, limit int) []string
- func ToAPIThinkingValues(kind string, values []string) []api.ThinkingValue
- type Capabilities
- type Catalog
- func (c *Catalog) Get(id ID) (Model, bool)
- func (c *Catalog) GetContext(ctx context.Context, id ID) (Model, bool)
- func (c *Catalog) List() []Model
- func (c *Catalog) Resolve(role Role, explicit ...string) (Model, bool)
- func (c *Catalog) ResolveContext(ctx context.Context, role Role, explicit ...string) (Model, bool)
- func (c *Catalog) ResolveDecisionCandidates(ctx context.Context, refs ...string) []Model
- type ID
- type Limits
- type Modalities
- type Model
- func (m Model) AliasRefs() []string
- func (m Model) Clone() Model
- func (m Model) Configure(s Settings) (llm.ModelConfig, []api.SessionDiagnostic, error)
- func (m Model) DefaultThinking() *api.ThinkingSetting
- func (m Model) EffectiveThinking(session, agent *api.ThinkingSetting) *api.ThinkingSetting
- func (m Model) Profile() profile.Profile
- func (m Model) SupportsCompletion() bool
- func (m Model) SupportsInputModality(mod string) bool
- func (m Model) SupportsThinking(setting *api.ThinkingSetting) bool
- func (m Model) ToAPI() api.Model
- type QuotaCapability
- type Role
- type Settings
- type Source
- type ThinkingOption
- type WorkspaceCatalog
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidConfig = errors.New("models: invalid configuration")
ErrInvalidConfig indicates an invalid explicit session override.
Functions ¶
func RankMatch ¶
RankMatch scores how closely rawQuery matches m across its qualified ID, bare model slug, display name/label, @aliases, and description (Tier 0 exact, Tier 1 substring containment within the target, Tier 2 bounded edit distance; descriptions match only by substring containment). Lower (tier, score) sorts first.
func SuggestClosest ¶
SuggestClosest returns up to limit closest model IDs from listed for typo recovery on an unresolved model or @alias reference. When requested carries a valid "<provider>/" prefix, models owned by that provider also qualify as a fallback tier if no closer lexical match exists.
func ToAPIThinkingValues ¶
func ToAPIThinkingValues(kind string, values []string) []api.ThinkingValue
ToAPIThinkingValues projects a list of thinking option values onto the public api.ThinkingValue representation, attaching human-readable descriptions for known reasoning-effort levels.
Types ¶
type Capabilities ¶
type Capabilities struct {
Completion *bool
Decision *bool
Embedding *bool
Tools *bool
Attachment *bool
StructuredOutput *bool
Temperature *bool
Dimensions []int
Thinking []ThinkingOption
}
Capabilities uses *bool: nil means unknown, which is distinct from false.
func (Capabilities) SupportsCompletion ¶
func (c Capabilities) SupportsCompletion() bool
SupportsCompletion reports whether the model supports text/chat completion. Defaults to true when unknown.
func (Capabilities) SupportsDecision ¶
func (c Capabilities) SupportsDecision() bool
SupportsDecision reports whether the model supports native decision evaluation. Defaults to false when unknown.
func (Capabilities) SupportsEmbedding ¶
func (c Capabilities) SupportsEmbedding() bool
SupportsEmbedding reports whether the model supports vector embedding generation. Defaults to false when unknown.
func (Capabilities) SupportsTools ¶
func (c Capabilities) SupportsTools() bool
SupportsTools reports whether the model supports tool calls. Defaults to false when unknown.
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog holds the built models of one workspace. It is safe for concurrent use.
func Build ¶
func Build(cat WorkspaceCatalog, profiles profile.Provider) (*Catalog, error)
Build constructs a Catalog using cat for manifest models and profiles for fallback definitions.
func BuildContext ¶
func (*Catalog) Get ¶
Get returns the model for id, building it on first use when id names a model that is not listed in the manifest but is known to the provider.
Aliases and shorthands ("@fast", "@default", "provider/@alias", and workspace.spec.modelAliases) are canonicalized by delegating to the workspace catalog's ResolveModels rather than re-implementing alias rules here.
A reference naming a listed model — by canonical id, WARP short name, or any casing of either — always resolves to that declared model, so its limits, capabilities, and pricing are never discarded.
func (*Catalog) Resolve ¶
Resolve applies warp's role/priority rules and returns the selected model.
func (*Catalog) ResolveContext ¶
func (*Catalog) ResolveDecisionCandidates ¶
ResolveDecisionCandidates resolves ordered Decision spec.models preferences into deduplicated concrete models. Non-@default references try RoleDecision first, then RoleCompletion (so completion models can be adapted via LLMAdapter). @default resolves strictly against RoleDecision so it never grabs a slow chat default before later fallbacks such as @fast.
type ID ¶
type ID string
ID is the qualified model identifier "<provider>/<model>".
The model part may itself contain "/" (e.g. "openrouter/x-ai/grok-build-0.1"); only the first "/" separates the provider from the model.
func Normalize ¶
Normalize returns the qualified form of a provider/model pair, prefixing the model with the provider name when it is not already qualified.
type Modalities ¶
Modalities lists the supported input and output data modalities of a model.
type Model ¶
type Model struct {
// ID is the qualified identifier "<provider>/<model>".
ID ID
// Name is the display name.
Name string
Label string
// Description is a short human-readable summary of what the model is good
// at, contributed by the built-in profile layer.
Description string
// ProviderType is the provider kind ("anthropic", "openai", "genai", ...).
// It is needed by Configure to apply provider-specific rules.
ProviderType string
// Limits holds token and vector-dimension limits.
Limits Limits
// Capabilities holds the workload capabilities. Each *bool is nil when
// unknown, which is distinct from a known false.
Capabilities Capabilities
// Modalities holds the supported input and output data modalities.
Modalities Modalities
// Pricing is the per-million-token pricing. nil means unpriced.
Pricing *api.ModelPricing
// Aliases lists the alternate names this model answers to, from the
// manifest's `aliases` and the workspace's `spec.modelAliases`.
Aliases []string
// Source records where the model's data came from.
Source Source
// QuotaBilled reports that the model carries no per-token pricing and its
// provider reports subscription/quota capacity.
QuotaBilled bool
}
Model is the complete, effective description of a model in a workspace. It is immutable once built.
func Merge ¶
Merge builds a Model from at most two layers, highest priority first:
- Workspace manifest (a workspace.ProviderModel, from warp Provider resources).
- Built-in profile (a loom provider GetProfile result, models.dev data).
The rules are:
- Scalars (Name, limits): first non-zero value, by priority.
- Capabilities (*bool): first non-nil value, by priority.
- Lists (Thinking, Dimensions, modalities): first non-nil list, by priority (lists are replaced, never merged item by item).
- Pricing: taken whole from the highest-priority layer that has any pricing (tiers are never mixed across layers).
- Limits fallback: if neither layer sets Context/Output, 128000/16384, applied once here.
func (Model) AliasRefs ¶
AliasRefs returns m.Aliases formatted with a leading "@" prefix ("@fast"), matching the syntax accepted by model resolution. Returns nil when m has no aliases.
func (Model) Configure ¶
func (m Model) Configure(s Settings) (llm.ModelConfig, []api.SessionDiagnostic, error)
Configure validates settings against m and returns the effective loom config.
It is a pure function: it moves the gateway's settings resolution out of the gateway, unchanged in behavior. This includes the thinking validation, the Anthropic temperature/thinking conflict, and the unknown/unsupported temperature diagnostics.
func (Model) DefaultThinking ¶
func (m Model) DefaultThinking() *api.ThinkingSetting
DefaultThinking returns the thinking setting implied by the model's own declared thinking capabilities, or nil when the model expresses no default.
It is the lowest-priority layer of thinking resolution: a session override or an agent default always takes precedence over it. A capability explicitly marked as the model's primary strategy wins; otherwise the first capability declaring a usable default is used.
func (Model) EffectiveThinking ¶
func (m Model) EffectiveThinking(session, agent *api.ThinkingSetting) *api.ThinkingSetting
EffectiveThinking resolves the thinking setting a session would actually run with, given an optional session override and the active agent's default.
Precedence is session override, then agent default, then the model's own default. An agent default the model cannot honor resolves to nil, because Model.Configure omits thinking in that case and the provider default applies.
func (Model) Profile ¶
Profile derives the loom profile view of the model. It is the only conversion from TaskSmith to loom and is computed on demand; the result is never stored.
func (Model) SupportsCompletion ¶
SupportsCompletion reports whether the model can serve chat completion. An unreported capability counts as supported, matching how provider profiles default it, so only a model that explicitly opts out is excluded.
func (Model) SupportsInputModality ¶
SupportsInputModality reports whether the model accepts the given input modality ("text", "image", "pdf", "audio", ...). When Modalities.Input is nil (unknown), it defaults to true so custom models without declared profiles are not blocked.
func (Model) SupportsThinking ¶
func (m Model) SupportsThinking(setting *api.ThinkingSetting) bool
SupportsThinking reports whether the model can honor setting.
type QuotaCapability ¶
QuotaCapability is an optional interface a profile source may implement to report whether a model's provider bills against a subscription window. The gateway implements it, which lets the catalog label models without any network query.
type Role ¶
type Role string
Role identifies the cognitive capability role for model resolution.
const ( // RoleCompletion is the role for conversational and tool-calling completion models. RoleCompletion Role = "completion" // RoleDecision is the role for probabilistic decision evaluation models. RoleDecision Role = "decision" // RoleEmbedding is the role for dense vector embedding generation models. RoleEmbedding Role = "embedding" )
type Settings ¶
type Settings struct {
Temperature *float32
Thinking *api.ThinkingSetting
StrictThinking bool
}
Settings holds the caller's desired model execution settings.
type Source ¶
type Source struct {
// BuiltIn reports that a loom built-in profile contributed data.
BuiltIn bool
// Manifest reports that a workspace manifest contributed data.
Manifest bool
}
Source records where the model's data came from.
type ThinkingOption ¶
type ThinkingOption struct {
// Type is "effort" | "budget_tokens" | "toggle" | ...
Type string
// Values lists the allowed values for the option.
Values []string
// Default is the default value.
Default string
// Min is the minimum budget (for budget_tokens).
Min int
// Max is the maximum budget (for budget_tokens).
Max int
// IsDefault marks this option as the model's primary thinking strategy.
IsDefault bool
}
ThinkingOption describes a supported reasoning configuration strategy.
type WorkspaceCatalog ¶
type WorkspaceCatalog interface {
Providers() []*warp.ModelProvider
ResolveModels(role warp.ModelRole, explicit ...string) []warp.ResolvedModel
WorkspaceSpec() *warp.Workspace
}
WorkspaceCatalog defines the interface for querying workspace model providers and role resolution policies.