provider

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package provider is the one place the environment is mapped onto an LLM backend. Both `whetstone` (authoring, on a developer's machine) and `skael-worker` (scoring, on a server) resolve their gateway here, so a misconfiguration is diagnosed with the same words wherever it is met.

Four provider modes, and no variable outside this file selects one:

  1. Anthropic direct ANTHROPIC_API_KEY
  2. Compatible gateway ANTHROPIC_BASE_URL + ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN
  3. Subscription CLI nothing set, and an agent CLI on PATH
  4. Split mode 2, plus CLAUDE_CODE_OAUTH_TOKEN

The judge and the eval panel share ANTHROPIC_BASE_URL. Mode 4 is the one case where they separate, and it takes both PanelModels and PanelExcludeEnv to do it. Turning it on changes model_panel, which splits a skill's score trend.

Index

Constants

View Source
const (
	APIKeyEnv    = "ANTHROPIC_API_KEY"
	AuthTokenEnv = "ANTHROPIC_AUTH_TOKEN"
	BaseURLEnv   = "ANTHROPIC_BASE_URL"
	// ModelEnv is comma-separated, most capable first: the first entry serves
	// every judge call and the panel's primary member, the rest are the panel's
	// floor members. One list rather than a strong/fast pair, which could be
	// half-set — a panel with one working member and one that 404s is not an
	// error but a complete run that scores and can never release anything.
	ModelEnv = "LLM_MODEL"
	// OAuthTokenEnv selects mode 4 and nothing else. A judge call is never
	// authenticated with it: a subscription is neither metered nor pinned to a
	// model, and a released version's score must be both.
	OAuthTokenEnv = "CLAUDE_CODE_OAUTH_TOKEN"
)

The SDK's and the CLI's own names, not Skael-specific ones: a machine set up for either needs no further configuration, and the panel is a Claude Code CLI reading the same values the worker resolved.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Kind   Kind
	Detail string
	Binary string
	// BaseURL is the panel's gateway as much as the judge's. Empty is
	// Anthropic's own API.
	BaseURL string
	Key     string
	// AuthStyle is inferred from which credential was set rather than
	// configured: a bearer token is only ever presented as a bearer token.
	AuthStyle api.AuthStyle
	// Models is ModelEnv, split and trimmed. Empty means the shipped defaults.
	Models []string
	// PanelSubscription is mode 4: the judge keeps BaseURL, the panel
	// authenticates with OAuthTokenEnv.
	PanelSubscription bool
}

Config is data only: nothing dials anything until Gateway is called.

func APIFromEnv

func APIFromEnv() Config

APIFromEnv is FromEnv with subscription detection off, for a caller whose backend must be metered and reproducible — the worker, whose judge output releases versions. An operator with both a key and a CLI is served by the key.

func FromEnv

func FromEnv() Config

FromEnv resolves from this process's environment, subscription CLI included.

func Resolve

func Resolve(env Getenv, detect Detector) Config

Resolve picks a provider. Explicit gateway configuration beats autodetection: preferring a CLI that happens to be on PATH would bill the wrong account and score against a different model. APIKeyEnv alone stays *below* the CLI — it sits on plenty of machines that also have the CLI, and treating it as an override moves them onto metered billing without anyone asking.

func (Config) Gateway

func (c Config) Gateway(o Options) (llm.Gateway, error)

Gateway builds the resolved backend.

func (Config) PanelExcludeEnv

func (c Config) PanelExcludeEnv() []string

PanelExcludeEnv names the credentials a sandbox must NOT be given, though the adapter declares them. This is the half that actually moves the panel: the adapter forwards every name it declares that is set, so without the exclusion a member asks a subscription for its alias while still pointed at the gateway. The API key goes too — forwarding it leaves the sandbox holding two competing credentials, which is the ambiguity this mode exists to remove.

func (Config) PanelModels

func (c Config) PanelModels() []string

PanelModels is what the panel asks for, empty when the shipped default is right. Gated on BaseURL, not on ModelEnv alone: naming a model to pick a cheaper judge against Anthropic's own API must not change the panel, because a changed panel splits the score trend. A subscription panel is empty for the opposite reason — it serves Anthropic's aliases, not a gateway's ids.

func (Config) Validate

func (c Config) Validate() error

Validate reports a configuration that cannot serve a call. `whetstone doctor` and the worker's startup both report what this returns.

func (Config) Warnings

func (c Config) Warnings() []string

Warnings reports configurations that work often enough not to refuse, and break confusingly when they do.

type Detector

type Detector func() (string, error)

Detector reports the agent CLI serving a subscription provider.

type Getenv

type Getenv func(string) string

Getenv is os.Getenv, injectable so resolution is testable.

type Kind

type Kind string

Kind names the backend serving model calls.

const (
	KindSubscription Kind = "subscription"
	KindAPI          Kind = "api"
	KindNone         Kind = "none"
)

type Options

type Options struct {
	Cache      llm.Cache
	Timeout    time.Duration
	MaxRetries int
}

Options are per-caller settings that are not provider choices: whetstone allows a long timeout and shares a completion cache, the worker does neither.

Jump to

Keyboard shortcuts

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