adapter

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package adapter defines the contract every agent CLI backend implements, and the registry that turns a config block into a live adapter.

Adapters are pure translators: they build argv and parse CLI output into [ir.Event]s. Process lifecycle belongs to internal/runner, and no adapter holds state across requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRegistered

func IsRegistered(id string) bool

IsRegistered reports whether this build can serve the given adapter id.

func Register

func Register(id string, b Builder)

Register makes an adapter implementation available to the gateway. It is called from the implementation package's init, so linking the package in is what enables the backend.

func Registered

func Registered() []string

Registered lists the adapter ids compiled into this build.

Types

type Adapter

type Adapter interface {
	// ID is the adapter id used to namespace models, e.g. "claude-code".
	ID() string
	// Probe checks that the CLI is installed, runnable and authenticated.
	Probe(ctx context.Context) (Health, error)
	// Run executes one request. It always streams: non-streaming callers just
	// collect events until the terminal one. The returned channel is closed
	// after an [ir.EventDone] or [ir.EventError].
	Run(ctx context.Context, req ir.Request) (<-chan ir.Event, error)
}

Adapter turns one agent CLI into an inference backend.

An adapter advertises no model list. A request carries the model name the caller asked for in ir.Request.Variant; the adapter passes it to the CLI, which is the only authority on which names it accepts. An empty variant means "whatever model the CLI would pick on its own".

func Build

func Build(id string, opts Options) (Adapter, error)

Build constructs the adapter registered under id.

type Builder

type Builder func(Options) (Adapter, error)

Builder constructs an adapter from its resolved configuration.

type Health

type Health struct {
	// Binary is the resolved absolute path of the CLI, when it was found.
	Binary string
	// Version is whatever the CLI reports for --version.
	Version string
	// Account describes the authenticated identity, when the CLI exposes one.
	Account string
	// Notes carry non-fatal remarks, e.g. flags the installed version lacks.
	Notes []string
}

Health is the outcome of probing a backend, as reported by `agent2api doctor`.

type Options

type Options struct {
	ID     string
	Config config.Adapter
	// ScratchRoot is the parent directory for per-request workdirs; empty means
	// the OS temp directory.
	ScratchRoot string
	// RequestTimeout caps a whole run; IdleTimeout caps silence within one.
	RequestTimeout time.Duration
	IdleTimeout    time.Duration
	// Logger is the gateway logger, already scoped to this adapter.
	Logger *slog.Logger
}

Options carries everything an adapter needs from the global config, with inheritance already resolved.

type SchemaEnforcer added in v0.1.3

type SchemaEnforcer interface {
	EnforcesSchema(ctx context.Context) bool
}

SchemaEnforcer is implemented by adapters whose CLI can hold an answer to a JSON Schema.

It is an optional interface rather than a method on Adapter because the answer is a property of the installed binary, not of the adapter: the same adapter reports false against a CLI too old for the flag. Frontends ask before accepting a caller's schema so the refusal can name the backend that cannot do it, instead of reading as a gateway-wide limitation.

Directories

Path Synopsis
Package agentcli holds the plumbing every CLI-backed adapter needs: resolving the binary, learning which flags the installed version actually supports, and turning one subprocess run into a stream of IR events.
Package agentcli holds the plumbing every CLI-backed adapter needs: resolving the binary, learning which flags the installed version actually supports, and turning one subprocess run into a stream of IR events.
Package claudecode adapts the Claude Code CLI (`claude`) into an inference backend.
Package claudecode adapts the Claude Code CLI (`claude`) into an inference backend.
Package codex adapts the Codex CLI (`codex exec`) into an inference backend.
Package codex adapts the Codex CLI (`codex exec`) into an inference backend.
Package cursor adapts the Cursor Agent CLI (`cursor-agent`) into an inference backend.
Package cursor adapts the Cursor Agent CLI (`cursor-agent`) into an inference backend.
Package fake provides an in-memory adapter for tests: it exercises the gateway end to end without spawning a CLI.
Package fake provides an in-memory adapter for tests: it exercises the gateway end to end without spawning a CLI.
Package mock is a scripted backend, compiled in only with the "conformance" build tag.
Package mock is a scripted backend, compiled in only with the "conformance" build tag.
Package qwen adapts the Qwen Code CLI (`qwen`) into an inference backend.
Package qwen adapts the Qwen Code CLI (`qwen`) into an inference backend.

Jump to

Keyboard shortcuts

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