clientprofile

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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 clientprofile identifies which coding agent (Claude Code, Codex, OpenCode, …) is calling the relay, so the edge can serve each one the model-list shape, error wording and attribution it expects.

Scope: identification only — a Profile is data plus (later) serializers over neutral value types. Deliberately out of scope: any per-client branching inside app/ (the core resolves a Profile and asks it), and any knowledge of routing, the catalog or the pipeline. The package imports nothing from app/ or internal/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstPathSegment

func FirstPathSegment(p string) string

FirstPathSegment returns the first non-empty path segment of p ("/claude-code/v1/messages" → "claude-code"), without allocating.

func Middleware

func Middleware(reg *Registry) func(http.Handler) http.Handler

Middleware resolves the profile once per request and stores it on the context. A nil or empty registry is a pass-through, and so is a request that resolves to Default — neither allocates a context value.

func Speaks

func Speaks(p Profile, shape string) bool

Speaks reports whether p accepts requests in the named inbound shape, spanning the single- and multi-shape cases so no caller type-asserts MultiShape itself.

func WithProfile

func WithProfile(ctx context.Context, p Profile) context.Context

WithProfile stores p on ctx.

Types

type Attributor

type Attributor interface {
	// AttributionHeaders lists request header names to capture into the
	// request's usage metadata, keyed by the lowercased header name.
	AttributionHeaders() []string
}

Attributor is implemented by a profile whose client sends identifying request headers worth recording against the request's usage.

type ListContext

type ListContext struct {
	// PublicURL is the externally reachable base of the inference API, without a trailing slash. A document that tells its client which endpoint to call has to print the URL the caller reached relay on, not relay's own listen address.
	PublicURL string
}

ListContext carries what a list projection cannot derive from the entries alone.

type ListerWithContext

type ListerWithContext interface {
	ModelsWithContext(lc ListContext, entries []ModelEntry) (body []byte, contentType string, err error)
}

ListerWithContext is ModelLister for a document that must name its own endpoint. The app prefers it over Models when a profile implements both.

type Modalities

type Modalities struct {
	Input  []string
	Output []string
}

Modalities are the media kinds a model reads and writes, in the catalog's own vocabulary ("text", "image", "audio", "video", "pdf", …). A projection filters to whatever its client's document allows rather than assuming the two vocabularies agree.

type ModelEntry

type ModelEntry struct {
	ID          string // catalog model slug, what the client sends as `model`
	Model       string // parent model slug; the prefix the ID's snapshot suffix hangs off
	DisplayName string
	Pointer     bool     // the snapshot the parent model points at — the "latest" one
	Aliases     []string // resolution-only aliases that also route to this model
	Hosts       []ModelHost

	// Catalog metadata a picker can show or size a session against. Zero
	// means the catalog declares nothing, never "zero tokens" — a
	// projection omits the field rather than printing a made-up number.
	ContextWindow   int
	MaxOutputTokens int
	Reasoning       bool
	ToolCall        bool
	Vision          bool
	Temperature     bool
	Modalities      Modalities
	// ReleasedAt is the snapshot's release date as the catalog spells it, "2006-01-02". Empty when the catalog declares none.
	ReleasedAt string
}

ModelEntry is the neutral view of one catalog model the app hands to a profile for its list projection. No catalog types cross into pkg/.

type ModelHost

type ModelHost struct {
	Name             string
	Priced           bool // false = no pricing row; do not print $0
	InputUSDPerMtok  float64
	OutputUSDPerMtok float64

	// Cache meters, nil when the rate sheet prices none — nil is "this host publishes no cache rate", never "cached tokens are free".
	CacheReadUSDPerMtok  *float64
	CacheWriteUSDPerMtok *float64

	// Tiers are the above-base rate rows, ascending by threshold.
	Tiers []PriceTier
}

ModelHost is one host serving the entry, with its base-tier rates.

type ModelListRoute

type ModelListRoute interface {
	// ModelListPath is the endpoint's path relative to the profile's /{Name} prefix.
	ModelListPath() string
}

ModelListRoute is implemented by a profile whose client reads its model list somewhere other than the default /{profile}/v1/models.

type ModelLister

type ModelLister interface {
	// Models renders the client's list-models document. contentType is
	// what to send back; the app writes body verbatim.
	Models(entries []ModelEntry) (body []byte, contentType string, err error)
}

ModelLister is implemented by a profile whose client expects its own list-models document.

type ModelNamer

type ModelNamer interface {
	// Inbound maps a picker id back to a catalog model reference, and is the identity for anything this profile did not mint.
	Inbound(model string) string
}

ModelNamer is implemented by a profile whose client needs model ids reshaped for its picker; the app applies Inbound to the `model` field of every request that resolved to this profile, before routing.

type MultiShape

type MultiShape interface {
	Shapes() []string
}

MultiShape is implemented by a profile whose client speaks more than one inbound wire shape off a single base URL; the app mirrors the profile's prefix over every shape it names. Shape() must return the first of them, so that callers who ask for the primary shape get the same answer either way.

type PriceTier

type PriceTier struct {
	AboveTokens          int
	InputUSDPerMtok      float64
	OutputUSDPerMtok     float64
	CacheReadUSDPerMtok  *float64
	CacheWriteUSDPerMtok *float64
}

PriceTier is one above-threshold rate row: what a request pays once its prompt length, cache reads and writes included, reaches AboveTokens. Every meter the host prices is repeated here at its tier value, because a consumer reads a tier as a complete price rather than a patch on the base one. The cache fields follow ModelHost's nil rule.

type Profile

type Profile interface {
	// Name is the URL prefix segment and the X-WR-Client value,
	// e.g. "claude-code". Empty for Default.
	Name() string

	// Shape is the inbound adapter name whose routes are mirrored under
	// /{Name}/, e.g. "anthropic". Empty for Default.
	Shape() string

	// Match sniffs the request (User-Agent, marker headers) when neither
	// the header nor the path prefix named a profile.
	Match(r *http.Request) bool
}

Profile identifies a client and the inbound wire shape it speaks. Later stages add optional interfaces (model-list projection, error envelope, keepalive, attribution); this one stays small.

var Default Profile = defaultProfile{}

Default is the profile for callers that name no client: today's behaviour, byte-identical. Resolve returns it when nothing matches.

func ClaudeCode

func ClaudeCode() Profile

ClaudeCode returns the profile for Anthropic's Claude Code CLI.

func Codex

func Codex() Profile

Codex returns the profile for OpenAI's Codex CLI.

func FromContext

func FromContext(ctx context.Context) Profile

FromContext returns the profile stored on ctx, or Default when unset.

func OpenCode

func OpenCode() Profile

OpenCode returns the profile for the OpenCode CLI.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds the profiles a deployment serves. Built once at boot from the composition root; read-only afterwards, so Resolve needs no lock.

func New

func New() *Registry

New returns an empty Registry.

func (*Registry) ByName

func (reg *Registry) ByName(name string) (Profile, bool)

ByName looks a profile up by its registered name.

func (*Registry) Profiles

func (reg *Registry) Profiles() []Profile

Profiles returns the registered profiles in registration order.

func (*Registry) Register

func (reg *Registry) Register(p Profile) error

Register adds p. The name doubles as a URL path segment and a header value, so it must be a lowercase DNS label and unique.

func (*Registry) Resolve

func (reg *Registry) Resolve(r *http.Request) Profile

Resolve picks the profile for r: the X-WR-Client header wins, then the first path segment, then a User-Agent Match, then Default. An unknown header or prefix value falls through rather than erroring — a client naming a profile this deployment does not serve gets today's behaviour.

type Route

type Route struct {
	Method  string
	Path    string
	Handler http.Handler

	// Public mounts the route without the relay-key auth chain — for
	// endpoints a client probes before it has necessarily attached
	// credentials. Such handlers must stay cheap and say nothing about
	// the deployment.
	Public bool
}

Route is one extra endpoint a profile serves. Path is relative to the profile's /{Name} prefix.

type Router

type Router interface {
	Routes() []Route
}

Router is implemented by a profile needing endpoints beyond the wire shape's own inbound routes (connection probes and the like).

type SessionKeyer

type SessionKeyer interface {
	// SessionKey returns the conversation identifier h carries, or "" when the client sent none.
	SessionKey(h http.Header) string
}

SessionKeyer is implemented by a profile whose client marks the requests of one conversation, so relay can keep per-conversation observations without the app knowing which header carries the mark.

type TokenCountRoute

type TokenCountRoute interface {
	// TokenCountPath is the endpoint's path relative to the profile's /{Name} prefix. The app mounts POST there behind the inference auth chain and answers with the count for the request body.
	TokenCountPath() string
}

TokenCountRoute is implemented by a profile whose client asks the gateway to count a prompt's input tokens before sending it.

Jump to

Keyboard shortcuts

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