proxy

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBackendAvailable = errors.New("no backend available")
	ErrNoBackendsInPool   = errors.New("consumer has no registries in pool")
)
View Source
var ErrInvalidRequestPayload = errors.New("invalid request payload")
View Source
var ErrModelNotAllowed = errors.New("model not allowed")

Functions

func DetectStream

func DetectStream(req *infracontext.RequestContext) bool

DetectStream reports whether the inbound request asks for a streamed response.

Detection mirrors each wire format's own streaming convention:

  • Gemini / Vertex signal streaming via the URL (":streamGenerateContent" in the path or "alt=sse" in the query); their bodies carry no stream flag.
  • OpenAI / Anthropic / Mistral / Responses carry "stream": true in the body.

The URL signal takes precedence so a Gemini-style streaming request is honored even though its body has no flag; the explicit body flag is consulted only when no URL signal is present.

Types

type ForwardInput

type ForwardInput struct {
	GatewayID ids.GatewayID
	Consumer  *appconsumer.RoutableConsumer
	Data      *appconsumer.Data
	RoleIDs   []ids.RoleID
	Request   *infracontext.RequestContext
}

type ForwardResult

type ForwardResult struct {
	StatusCode int
	Headers    map[string][]string
	Body       []byte
	Stream     iter.Seq2[[]byte, error]
}

type Forwarder

type Forwarder interface {
	Forward(ctx context.Context, in ForwardInput) (*ForwardResult, error)
}

func NewForwarder

func NewForwarder(
	factory loadbalancer.Factory,
	cacheClient cache.Client,
	manager *cache.TTLMapManager,
	invoker ProviderInvoker,
	executor appplugins.Executor,
	sessions appsession.Store,
	resolver approuting.Resolver,
	cfg *config.Config,
	logger *slog.Logger,
) Forwarder

type Outcome

type Outcome int
const (
	OutcomeSuccess Outcome = iota

	OutcomeRetryable

	OutcomeTerminal
)

func (Outcome) String

func (o Outcome) String() string

type ProviderInvoker

type ProviderInvoker interface {
	Invoke(ctx context.Context, bk *registry.Registry, req *infracontext.RequestContext) (*ProviderResponse, error)
	InvokeStream(ctx context.Context, bk *registry.Registry, req *infracontext.RequestContext) (*ProviderResponse, error)
}

func NewProviderInvoker

func NewProviderInvoker(
	locator factory.ProviderLocator,
	registry *adapter.Registry,
	logger *slog.Logger,
) ProviderInvoker

type ProviderResponse

type ProviderResponse struct {
	StatusCode int
	Headers    map[string][]string
	Body       []byte
	// Stream, when non-nil, yields SSE lines (without trailing newline) already
	// adapted to the client's source format. The consumer writes each line + "\n"
	// and is responsible for draining the sequence (which closes the backend
	// body). The second value carries mid-stream errors.
	Stream iter.Seq2[[]byte, error]
	Usage  *adapter.CanonicalUsage
	// Model is the model echoed by the provider in its response. Some providers
	// (e.g. Bedrock Titan/Llama/Mistral) leave it empty.
	Model string
	// SentModel is the model the gateway actually put on the outbound request to
	// the provider, after routing-ref parsing, pool/LB resolution and model
	// enforcement. It is the most reliable identifier for cost attribution.
	SentModel    string
	FinishReason string
	ResponseID   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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