dispatcher

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 22 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 RewriteLLMRoutePath added in v0.1.0

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

RewriteLLMRoutePath returns a cloned request with the matched LLM route prefix stripped.

func WriteDispatchError added in v0.1.0

func WriteDispatchError(logger *zap.Logger, protocol, routeID, model string, status int, w http.ResponseWriter, r *http.Request, phase string, clientMessage string, err error, fields ...zap.Field) error

func WriteHttpErrorLog added in v0.1.0

func WriteHttpErrorLog(logger *zap.Logger, w http.ResponseWriter, r *http.Request, status int, phase string, err error, fields ...zap.Field)

func WriteProviderErrorLog added in v0.1.0

func WriteProviderErrorLog(logger *zap.Logger, w http.ResponseWriter, r *http.Request, protocol string, model string, phase string, err error) (int, string)

Types

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, opts HandlerOptions) *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 ingress protocol handler.

type HandlerOptions added in v0.1.0

type HandlerOptions struct {
	EnableMCP bool
}

type LLMApiHandler

type LLMApiHandler interface {
	Name() string
	MatchLLMApi(*http.Request) bool
	PrepareLLMApiRequest(*http.Request) (*PreparedLLMApiRequest, llmroutepkg.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
cc
Package cc provides the Claude Code CLI LLM API profile.
Package cc provides the Claude Code CLI LLM API profile.

Jump to

Keyboard shortcuts

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