dispatcher

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const StatusClientClosedRequest = 499

Variables

This section is empty.

Functions

func IsClientCanceled

func IsClientCanceled(err error) bool

func ListLLMApiHandlerTypes

func ListLLMApiHandlerTypes() []string

ListLLMApiHandlerTypes returns the types of all registered LLM API handlers.

func RegisterLLMApiHandlerType

func RegisterLLMApiHandlerType(handlerType string)

RegisterLLMApiHandlerType registers an available LLM API handler type.

func RewriteRoutePath

func RewriteRoutePath(r *http.Request, prefix string) *http.Request

RewriteRoutePath returns a cloned request with the matched route prefix stripped.

func WriteError

func WriteError(logger *zap.Logger, apiName, routeID, model string, w http.ResponseWriter, r *http.Request, err error, message string) error

func WriteLoggedError

func WriteLoggedError(logger *zap.Logger, ctx ErrorContext, w http.ResponseWriter, r *http.Request, status int, clientMessage string, cause error, fields ...zap.Field) error

func WriteProviderError

func WriteProviderError(logger *zap.Logger, ctx ErrorContext, w http.ResponseWriter, r *http.Request, err error, phase string) error

Types

type ErrorContext

type ErrorContext struct {
	Protocol string
	RouteID  string
	Model    string
}

type Handler

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

Handler dispatches gateway requests to the route-selected LLM API handler.

func NewHandler

func NewHandler(agentGateway *gateway.AgentGateway, apiHandlers map[string]LLMApiHandler, logger *zap.Logger) *Handler

NewHandler constructs a runtime dispatcher handler.

func (*Handler) Dispatch

func (h *Handler) Dispatch(w http.ResponseWriter, r *http.Request, next NextHandler) error

Dispatch handles a request and optionally delegates unmatched requests to next.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler. Requests not handled by the dispatcher receive 404.

func (*Handler) Validate

func (h *Handler) Validate() error

Validate verifies the dispatcher has at least one configured LLM API handler.

type LLMApiHandler

type LLMApiHandler interface {
	Name() string
	MatchLLMApi(*http.Request) bool
	PrepareLLMApiRequest(*http.Request) (*PreparedLLMApiRequest, routepkg.RequestRequirements, error)
	ServeLLMApi(http.ResponseWriter, *http.Request, provider.Provider, *PreparedLLMApiRequest) error
}

type NextHandler

type NextHandler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) error
}

NextHandler is the small subset of a middleware next handler needed by the dispatcher.

type PreparedLLMApiRequest

type PreparedLLMApiRequest struct {
	Type             provider.LLMApiRequestType
	ChatRequest      *provider.ChatRequest
	EmbeddingRequest *provider.EmbeddingRequest
	ResponsesRequest *provider.ResponsesRequest
	StreamRequested  bool
	RawRequest       any
}

func (*PreparedLLMApiRequest) IsValid

func (r *PreparedLLMApiRequest) IsValid() bool

func (*PreparedLLMApiRequest) Model

func (r *PreparedLLMApiRequest) Model() string

func (*PreparedLLMApiRequest) SetModel

func (r *PreparedLLMApiRequest) SetModel(model string)

func (*PreparedLLMApiRequest) Stream

func (r *PreparedLLMApiRequest) Stream() bool

Directories

Path Synopsis
llmapi

Jump to

Keyboard shortcuts

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