Documentation
¶
Overview ¶
Package adapter defines the contract every upstream provider satisfies and a registry that lets the server look adapters up by name.
Adding a new provider is a single self-contained sub-package:
package myprovider
import "github.com/1mb-dev/shim/internal/adapter"
func New(opts Opts) (adapter.Adapter, error) { ... }
cmd/shim/main.go constructs the adapter via its New, then calls adapter.Register with the returned instance — no init()-time registration, no blank-import side effects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface {
// Name returns the lookup key used by config (e.g. "deepseek").
Name() string
// MapModel converts an Anthropic-style model name (which may be e.g.
// "claude-3-5-sonnet-20240620") into the upstream's expected name.
// Adapters handle the empty-input case themselves — typically by
// returning a "default" model — so callers never need a separate
// DefaultModel() probe.
MapModel(anthropicModel string) string
// Validate confirms the adapter has all configuration it needs to serve
// requests. Called once at server startup; non-nil error blocks startup.
// Replaces the prior substring-match preflight backchannel on the
// request path.
Validate() error
// BuildRequest takes an already-translated OpenAI ChatCompletions body
// and returns an http.Request bound to {BaseURL}/chat/completions with
// auth headers set. Adapter must call req.WithContext(ctx).
BuildRequest(ctx context.Context, body []byte) (*http.Request, error)
// NormalizeResponse reads the upstream response and returns a canonical
// OpenAI-shape JSON body. Used by the translator. Adapter is responsible
// for unwrapping any provider-specific envelope.
NormalizeResponse(resp *http.Response) ([]byte, error)
}
Adapter normalises one OpenAI-compatible upstream. The translator emits a canonical OpenAI ChatCompletions request body; the adapter wraps it in an http.Request bound to its upstream, then normalises the response back to canonical OpenAI shape so the translator can convert to Anthropic Messages.
Quirks (model-name format, header peculiarities, response-shape variances) live INSIDE the adapter. The translator stays pure.