selectadapter

package
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package selectadapter is the adapter-selection composition layer (ADR-0005, T-014). It maps the neutral model string's "<provider>/" prefix to the concrete Provider adapter, wiring resolved config.Provider options into the adapter. This is the only place that knows both config and the adapter packages; everything downstream sees ports.Provider.

The registry is open for extension: Register(prefix, factory) adds a new adapter. anthropic is registered by default; the OpenAI-compatible adapter (openai, local, custom, …) is registered when T-013 lands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadModel means the model string is missing or has no "/" separator.
	ErrBadModel = errors.New("selectadapter: bad model string (want <provider>/<model>)")
	// ErrNoProvider means the prefix parsed fine but no provider is configured
	// under it in opencode.json.
	ErrNoProvider = errors.New("selectadapter: provider not configured")
	// ErrNoAdapter means the provider is configured but no adapter factory is
	// registered for its prefix (e.g. the openaicompat adapter before T-013).
	ErrNoAdapter = errors.New("selectadapter: no adapter registered for prefix")
)

Sentinel errors returned by Select. Wrap with errors.Is to distinguish "no provider configured" from "no adapter for that provider".

Functions

func Register

func Register(prefix string, f Factory)

Register installs (or replaces) the Factory for a provider prefix. Safe to call concurrently and from init() blocks. T-013 will Register the openaicompat factory for openai/local/custom prefixes.

func Select

func Select(model string, providers map[string]config.Provider) (ports.Provider, error)

Select resolves which adapter serves the model string and returns it, wired with the matching provider's options. model must be "<provider>/<model>". providers is the table from config (cfg.Providers).

Returns a wrapped ErrBadModel / ErrNoProvider / ErrNoAdapter on the corresponding failures.

func Unregister

func Unregister(prefix string)

Unregister removes a prefix's factory. Primarily for tests.

Types

type Factory

type Factory func(p config.Provider) ports.Provider

Factory builds a Provider adapter from a resolved config.Provider. Adapters that ignore some fields (e.g. anthropic ignoring baseURL when empty) are free to do so.

Jump to

Keyboard shortcuts

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