Documentation
¶
Overview ¶
Package gateway manages model provider lifecycles and instantiates client interfaces for LLM completions, probabilistic decision models, and dense vector embeddings.
The gateway is completely decoupled from configuration manifest formats (such as Warp). It operates purely on strongly-typed in-memory domain configurations (Config), leaving manifest parsing, inheritance, and disk watching to the workspace layer. Provider adapters live in the providers subpackage. The auth subpackage manages credentials, authentication transports, and OAuth sessions.
Content-Addressable Gateway Pool ¶
To maximize connection reuse and eliminate cache invalidation bugs, gateways are pooled by a deterministic configuration hash (Config.Fingerprint). Workspaces, worktrees, or subagents with identical provider configurations and credentials automatically share the same Gateway instance and HTTP connection pools. When configurations change, the pool instantiates a new gateway entry while gracefully draining previous instances.
Workload Systems ¶
The gateway supports three distinct AI workload systems:
System One (Decision): Fast, calibrated probabilistic evaluation models represented by github.com/masterkeysrd/loom/decision.Model. When a provider natively supports decision evaluation (such as Ollama with nimble-v3 or TypeSafe with jev-latest), the gateway constructs a native decision backend. For providers or models supporting only text completion, the gateway transparently wraps the completion model using Loom's structured decision adapter (decision.NewFromLLM).
System Two (Completion): Conversational, reasoning, and tool-augmented models represented by github.com/masterkeysrd/loom/llm.Model. These models power agent planning, interactive dialogues, and complex execution loops.
System Three (Embedding): Dense vector representation models represented by github.com/masterkeysrd/loom/embedding.Model, supporting similarity search, retrieval-augmented generation (RAG), and semantic indexing.
Authentication Guarantees ¶
In TaskSmith v2, security and deterministic behavior are paramount. The gateway enforces strict authentication invariants:
- Zero Implicit Fallbacks: The gateway never inspects process-level environment variables (via os.Getenv) or searches the local filesystem for dot-env files.
- Explicit Credential Injection: All environment credentials must be passed via the injected in-memory map on Config.Env. If a required credential key is missing or empty, initialization fails immediately with a descriptive error.
- File Authentication: If a credential file path is specified, it must point to an explicit, readable file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrProviderNotFound = errors.New("gateway: provider not found") ErrModelNotFound = errors.New("gateway: model not found") ErrUnsupportedCapability = errors.New("gateway: model does not support requested capability") ErrMissingCredential = auth.ErrMissingCredential ErrInvalidConfig = providers.ErrInvalidConfig ErrGatewayClosed = errors.New("gateway: gateway is closed") )
Common errors returned by the gateway package.
Functions ¶
func DecisionQuestions ¶
func DecisionQuestions( dec *warp.Decision, rubric string, rubricTarget string, ) ([]decision.Question, error)
DecisionQuestions translates a WARP Decision manifest's spec.questions into Loom decision.Question values. When rubric is non-empty, it is prepended once to the question named rubricTarget (or the first question when rubricTarget is empty) so multi-question evaluations do not duplicate shared rubric instructions across every question.
func IsRateLimited ¶
IsRateLimited reports whether err represents a provider rejecting a call for lack of capacity: a typed 429 from a provider SDK, or the equivalent wording when a provider has already flattened the status into a message string.
Types ¶
type AuthErrorKind ¶
type AuthErrorKind string
AuthErrorKind classifies structured authentication failures reported to clients on [api.ErrorEvent.Code].
const ( AuthErrorExpired AuthErrorKind = AuthErrorKind(api.ErrCodeProviderAuthExpired) AuthErrorInvalid AuthErrorKind = AuthErrorKind(api.ErrCodeProviderAuthInvalid) )
type AuthObserver ¶
type AuthObserver interface {
RecordAuthFailure(providerName, providerType string, state auth.HealthState, revision, reason string)
RecordAuthSuccess(providerName string)
}
AuthObserver receives live authentication failure and recovery notifications from provider calls. Optional; nil disables runtime health tracking.
type Config ¶
type Config struct {
// Providers lists the configured model providers.
Providers []ProviderConfig `json:"providers"`
// Env contains injected environment variables strictly keyed by name.
// The gateway will only read variables explicitly referenced by a provider's Auth.Env.
Env map[string]string `json:"env,omitempty"`
// Metrics receives a record for every LLM call. It is not part of the
// configuration fingerprint. A nil recorder disables LLM call metrics.
Metrics metrics.Recorder `json:"-"`
// AuthObserver receives live authentication failure and recovery signals.
// It is not part of the configuration fingerprint. Optional.
AuthObserver AuthObserver `json:"-"`
}
Config represents the complete in-memory configuration passed to the Gateway.
func (*Config) Fingerprint ¶
Fingerprint returns a canonical SHA-256 hex fingerprint of the effective configuration. It normalizes provider ordering and isolates only the environment variables that are actually referenced by provider authentication configurations.
func (*Config) Validate ¶
Validate checks the configuration for gateway-level structural integrity (non-nil config, non-empty and unique provider names). Per-provider settings such as provider type and auth scheme are validated and isolated per provider during initialization so one misconfigured manifest cannot disable healthy providers in the same workspace.
type Gateway ¶
type Gateway interface {
LLM(ctx context.Context, model models.Model, cfg llm.ModelConfig) (*llm.Model, error)
Decision(ctx context.Context, model models.Model, cfg llm.ModelConfig) (*decision.Model, error)
Embedding(ctx context.Context, model models.Model) (*embedding.Model, error)
ListProviders() []ProviderInfo
// ListModels returns the configured provider's live models or known profiles.
// The boolean distinguishes an empty live catalog from an unavailable catalog.
ListModels(ctx context.Context, provider string) ([]profile.Profile, bool, error)
GetProfile(id string) (profile.Profile, bool)
// Quota returns the remaining quota buckets for a quota-billed model, or
// (nil, nil) when the model's provider does not report quotas or has no
// quota data.
Quota(ctx context.Context, model models.Model) (*api.ModelQuota, error)
// QuotaSnapshots returns the full multi-bucket quota snapshots across all
// quota-capable workspace providers.
QuotaSnapshots(ctx context.Context) (*api.QuotaSnapshotResponse, error)
// QuotaCapable reports whether the model's provider can report quota at
// all. It is a cheap capability check (no network), used to label models
// as subscription-billed without querying the provider.
QuotaCapable(model models.Model) bool
// Close releases all client resources and connections.
Close() error
}
Gateway provides access to initialized AI models across providers.
type Pool ¶
type Pool interface {
// Acquire returns an existing Gateway matching the configuration fingerprint,
// or initializes and caches a new one.
Acquire(ctx context.Context, cfg Config) (Gateway, error)
// Close shuts down this pool's cached gateways.
Close() error
}
Pool manages a thread-safe cache of Gateway instances keyed by their canonical configuration fingerprint (SHA-256).
type ProviderAuthError ¶
type ProviderAuthError struct {
Provider string
ProviderType string
Kind AuthErrorKind
OAuth bool
Cause error
}
ProviderAuthError wraps an authentication failure with the configured TaskSmith provider identity and an actionable user-facing message.
func ClassifyAuthError ¶
func ClassifyAuthError(err error) (*ProviderAuthError, bool)
ClassifyAuthError inspects err and returns a *ProviderAuthError when it represents an authentication rejection or missing/expired credential. Context cancellation and deadline errors are never classified as auth errors.
func (*ProviderAuthError) Error ¶
func (e *ProviderAuthError) Error() string
Error returns the user-facing authentication message.
func (*ProviderAuthError) Unwrap ¶
func (e *ProviderAuthError) Unwrap() error
Unwrap returns the underlying cause so sentinel checks such as ErrMissingCredential and loomauth.ErrAuthRequired continue to match.
func (*ProviderAuthError) UserMessage ¶
func (e *ProviderAuthError) UserMessage() string
UserMessage returns a concise, actionable message naming the configured TaskSmith provider rather than internal SDK wrapper noise.
type ProviderConfig ¶
type ProviderConfig struct {
Name string `json:"name"`
Type string `json:"type"` // e.g. "ollama", "openai", "anthropic", "genai", "typesafe", "antigravity"
Endpoint string `json:"endpoint,omitempty"`
Auth *auth.Config `json:"auth,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Config map[string]any `json:"config,omitempty"`
}
ProviderConfig configures a single upstream backend provider.
type ProviderInfo ¶
type ProviderInfo struct {
Name string `json:"name"`
Type string `json:"type"`
Endpoint string `json:"endpoint,omitempty"`
Warning string `json:"warning,omitempty"`
InvalidConfig bool `json:"invalid_config,omitempty"`
}
ProviderInfo provides read-only summary information about an initialized provider.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth resolves provider credentials and manages authentication transports and OAuth sessions for the TaskSmith gateway.
|
Package auth resolves provider credentials and manages authentication transports and OAuth sessions for the TaskSmith gateway. |
|
Package providers contains upstream-specific client adapters for the TaskSmith gateway.
|
Package providers contains upstream-specific client adapters for the TaskSmith gateway. |