handlers

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package handlers provides HTTP request handlers for the AI Provider Kit backend. It includes handlers for health checks, metrics, provider management, content generation, OAuth authentication, and streaming responses, along with utilities for standardized JSON response formatting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSON

func ParseJSON(r *http.Request, target interface{}) error

ParseJSON parses JSON from request body into target

func SendCreated

func SendCreated(w http.ResponseWriter, r *http.Request, data interface{})

SendCreated sends a 201 Created response

func SendError

func SendError(w http.ResponseWriter, r *http.Request, code string, message string, statusCode int)

SendError sends an error JSON response with APIError

func SendSuccess

func SendSuccess(w http.ResponseWriter, r *http.Request, data interface{})

SendSuccess sends a successful JSON response with data

Types

type GenerateHandler

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

GenerateHandler handles text/chat generation requests

func NewGenerateHandler

func NewGenerateHandler(providers map[string]types.Provider, ext extensions.ExtensionRegistry, defaultProvider string) *GenerateHandler

NewGenerateHandler creates a new generate handler

func (*GenerateHandler) Generate

func (h *GenerateHandler) Generate(w http.ResponseWriter, r *http.Request)

Generate handles POST requests for text/chat generation

type HealthHandler

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

func NewHealthHandler

func NewHealthHandler(providers map[string]types.Provider, version string) *HealthHandler

func (*HealthHandler) Health

func (h *HealthHandler) Health(w http.ResponseWriter, r *http.Request)

Health returns detailed health with provider status

func (*HealthHandler) Status

func (h *HealthHandler) Status(w http.ResponseWriter, r *http.Request)

Status returns simple liveness status

func (*HealthHandler) Version

func (h *HealthHandler) Version(w http.ResponseWriter, r *http.Request)

Version returns version information

type MetricsHandler

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

MetricsHandler handles metrics endpoints

func NewMetricsHandler

func NewMetricsHandler(providers map[string]types.Provider) *MetricsHandler

NewMetricsHandler creates a new metrics handler

func (*MetricsHandler) GetProviderMetrics

func (h *MetricsHandler) GetProviderMetrics(w http.ResponseWriter, r *http.Request)

GetProviderMetrics handles GET /api/metrics/providers Returns metrics for all registered providers

func (*MetricsHandler) GetRacingMetrics

func (h *MetricsHandler) GetRacingMetrics(w http.ResponseWriter, r *http.Request)

GetRacingMetrics handles GET /api/metrics/racing Returns performance stats from racing providers

func (*MetricsHandler) GetSystemMetrics

func (h *MetricsHandler) GetSystemMetrics(w http.ResponseWriter, r *http.Request)

GetSystemMetrics handles GET /api/metrics/system Returns system-level metrics including runtime stats

type OAuthHandler

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

OAuthHandler handles OAuth-related endpoints

func NewOAuthHandler

func NewOAuthHandler(authManager auth.AuthManager) *OAuthHandler

NewOAuthHandler creates a new OAuth handler

func (*OAuthHandler) GetTokenStatus

func (h *OAuthHandler) GetTokenStatus(w http.ResponseWriter, r *http.Request)

GetTokenStatus checks if token exists and is valid for a provider GET /api/oauth/{provider}/status

func (*OAuthHandler) InitiateOAuth

func (h *OAuthHandler) InitiateOAuth(w http.ResponseWriter, r *http.Request)

InitiateOAuth initiates OAuth flow for a provider GET /api/oauth/{provider}/initiate

func (*OAuthHandler) ListOAuthProviders

func (h *OAuthHandler) ListOAuthProviders(w http.ResponseWriter, r *http.Request)

ListOAuthProviders lists all providers that support OAuth GET /api/oauth/providers

func (*OAuthHandler) OAuthCallback

func (h *OAuthHandler) OAuthCallback(w http.ResponseWriter, r *http.Request)

OAuthCallback handles OAuth callback from provider GET /api/oauth/{provider}/callback

func (*OAuthHandler) RefreshToken

func (h *OAuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request)

RefreshToken refreshes an expired token for a provider POST /api/oauth/{provider}/refresh

func (*OAuthHandler) RevokeToken

func (h *OAuthHandler) RevokeToken(w http.ResponseWriter, r *http.Request)

RevokeToken revokes/deletes the OAuth token for a provider DELETE /api/oauth/{provider}/token

type OAuthRequest

type OAuthRequest struct {
	Provider string   `json:"provider"`
	Scopes   []string `json:"scopes,omitempty"`
	Code     string   `json:"code,omitempty"`
	State    string   `json:"state,omitempty"`
}

OAuthRequest is used for parsing OAuth-related request bodies

type ProviderHandler

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

ProviderHandler manages provider-related endpoints

func NewProviderHandler

func NewProviderHandler(providers map[string]types.Provider) *ProviderHandler

NewProviderHandler creates a new provider handler

func (*ProviderHandler) GetProvider

func (h *ProviderHandler) GetProvider(w http.ResponseWriter, r *http.Request)

GetProvider returns details for a specific provider GET /api/providers/{name} or GET /api/providers?name={name}

func (*ProviderHandler) HealthCheckProvider

func (h *ProviderHandler) HealthCheckProvider(w http.ResponseWriter, r *http.Request)

HealthCheckProvider checks the health of a specific provider GET /api/providers/{name}/health or GET /api/providers/health?name={name}

func (*ProviderHandler) ListProviders

func (h *ProviderHandler) ListProviders(w http.ResponseWriter, r *http.Request)

ListProviders returns all configured providers with their information GET /api/providers

func (*ProviderHandler) TestProvider

func (h *ProviderHandler) TestProvider(w http.ResponseWriter, r *http.Request)

TestProvider tests a provider with a simple request POST /api/providers/{name}/test or POST /api/providers/test?name={name}

func (*ProviderHandler) UpdateProvider

func (h *ProviderHandler) UpdateProvider(w http.ResponseWriter, r *http.Request)

UpdateProvider updates provider configuration PUT /api/providers/{name} or POST /api/providers?name={name}

type ProviderMetricsResponse

type ProviderMetricsResponse struct {
	Providers map[string]types.ProviderMetrics `json:"providers"`
	Timestamp time.Time                        `json:"timestamp"`
}

ProviderMetricsResponse represents the response for provider metrics

type RacingMetricsResponse

type RacingMetricsResponse struct {
	RacingProviders map[string]map[string]*racing.ProviderStats `json:"racing_providers"`
	Timestamp       time.Time                                   `json:"timestamp"`
}

RacingMetricsResponse represents racing provider performance stats

type SSEWriter added in v1.0.4

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

SSEWriter handles Server-Sent Events (SSE) writing for streaming responses

func NewSSEWriter added in v1.0.4

func NewSSEWriter(w http.ResponseWriter) (*SSEWriter, error)

NewSSEWriter creates a new SSEWriter and sets up SSE headers Returns an error if the http.ResponseWriter does not support flushing

func (*SSEWriter) WriteChunk added in v1.0.4

func (s *SSEWriter) WriteChunk(chunk types.ChatCompletionChunk) error

WriteChunk writes a ChatCompletionChunk as an SSE event

func (*SSEWriter) WriteDone added in v1.0.4

func (s *SSEWriter) WriteDone()

WriteDone sends the SSE completion event

func (*SSEWriter) WriteError added in v1.0.4

func (s *SSEWriter) WriteError(code, message string)

WriteError sends an error as an SSE event

type StreamHandler

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

StreamHandler handles streaming text/chat generation requests using Server-Sent Events (SSE)

func NewStreamHandler

func NewStreamHandler(providers map[string]types.Provider, ext extensions.ExtensionRegistry, defaultProvider string) *StreamHandler

NewStreamHandler creates a new stream handler

func (*StreamHandler) StreamGenerate

func (h *StreamHandler) StreamGenerate(w http.ResponseWriter, r *http.Request)

StreamGenerate handles POST requests for streaming text/chat generation using SSE

type SystemMetricsResponse

type SystemMetricsResponse struct {
	Uptime          string    `json:"uptime"`
	Goroutines      int       `json:"goroutines"`
	MemoryAllocated uint64    `json:"memory_allocated_bytes"`
	MemoryTotal     uint64    `json:"memory_total_bytes"`
	MemorySys       uint64    `json:"memory_sys_bytes"`
	NumGC           uint32    `json:"num_gc"`
	Timestamp       time.Time `json:"timestamp"`
}

SystemMetricsResponse represents system-level metrics

Jump to

Keyboard shortcuts

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