Documentation
¶
Overview ¶
Package api provides the HTTP API server implementation for the CLI Proxy API. It includes the main server struct, routing setup, middleware for CORS and authentication, and integration with various AI API handlers (OpenAI, Claude, Gemini). The server supports hot-reloading of clients and configuration.
Index ¶
- func AuthMiddleware(manager *sdkaccess.Manager) gin.HandlerFunc
- type ManagementConfigStore
- type Server
- type ServerOption
- func WithEngineConfigurator(fn func(*gin.Engine)) ServerOption
- func WithHomeModelsReader(reader func(context.Context) ([]byte, error)) ServerOption
- func WithKeepAliveEndpoint(timeout time.Duration, onTimeout func()) ServerOption
- func WithLocalManagementPassword(password string) ServerOption
- func WithManagementConfigChangeHook(hook func(*config.Config)) ServerOption
- func WithManagementConfigStore(store managementHandlers.ManagementConfigStore) ServerOption
- func WithMiddleware(mw ...gin.HandlerFunc) ServerOption
- func WithPostAuthHook(hook auth.PostAuthHook) ServerOption
- func WithQuotaAlertSecretCipher(cipher *quotaalert.SecretCipher) ServerOption
- func WithQuotaAlertStore(store quotaalert.Store) ServerOption
- func WithRequestLoggerFactory(factory func(*config.Config, string) logging.RequestLogger) ServerOption
- func WithRouterConfigurator(fn func(*gin.Engine, *handlers.BaseAPIHandler, *config.Config)) ServerOption
- func WithRuntimeSettingsStore(store runtimecontrol.SettingsStore) ServerOption
- func WithRuntimeStoragePolicy(policy runtimepolicy.RuntimeStorage) ServerOption
- func WithSelfUpdateEngine(engine managementHandlers.SelfUpdateEngine) ServerOption
- func WithSelfUpdateRestartRunner(runner func(context.Context) error) ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(manager *sdkaccess.Manager) gin.HandlerFunc
AuthMiddleware returns a Gin middleware handler that authenticates requests using the configured authentication providers. When no providers are available, it allows all requests (legacy behaviour).
Types ¶
type ManagementConfigStore ¶ added in v0.0.7
type ManagementConfigStore = managementHandlers.ManagementConfigStore
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the main API server. It encapsulates the Gin engine, HTTP server, handlers, and configuration.
func NewServer ¶
func NewServer(cfg *config.Config, authManager *auth.Manager, accessManager *sdkaccess.Manager, configFilePath string, opts ...ServerOption) *Server
NewServer creates and initializes a new API server instance. It sets up the Gin engine, middleware, routes, and handlers.
Parameters:
- cfg: The server configuration
- authManager: core runtime auth manager
- accessManager: request authentication manager
Returns:
- *Server: A new server instance
func (*Server) AttachWebsocketRoute ¶
AttachWebsocketRoute registers a websocket upgrade handler on the primary Gin engine. The handler is served as-is without additional middleware beyond the standard stack already configured.
func (*Server) SetWebsocketAuthChangeHandler ¶
func (*Server) Start ¶
Start begins listening for and serving HTTP or HTTPS requests. It's a blocking call and will only return on an unrecoverable error.
Returns:
- error: An error if the server fails to start
func (*Server) Stop ¶
Stop closes listeners and immediately shuts down the API server without waiting for active connections.
Parameters:
- ctx: Context passed for compatibility.
Returns:
- error: An error if the server fails to stop
func (*Server) UpdateClients ¶
UpdateClients updates the server's client list and configuration. This method is called when the configuration or authentication tokens change.
Parameters:
- clients: The new slice of AI service clients
- cfg: The new application configuration
type ServerOption ¶
type ServerOption func(*serverOptionConfig)
ServerOption customises HTTP server construction.
func WithEngineConfigurator ¶
func WithEngineConfigurator(fn func(*gin.Engine)) ServerOption
WithEngineConfigurator allows callers to mutate the Gin engine prior to middleware setup.
func WithHomeModelsReader ¶ added in v0.0.56
func WithHomeModelsReader(reader func(context.Context) ([]byte, error)) ServerOption
WithHomeModelsReader replaces the Home control-center read behind the home model catalog handlers (GET /v1/models, /v1beta/models and their variants).
Test-only: no production construction path sets it, so an unset reader keeps the handlers reading the live Home client unchanged. Tests use it to drive the real handlers without a Home/Redis connection.
func WithKeepAliveEndpoint ¶
func WithKeepAliveEndpoint(timeout time.Duration, onTimeout func()) ServerOption
WithKeepAliveEndpoint enables a keep-alive endpoint with the provided timeout and callback.
func WithLocalManagementPassword ¶
func WithLocalManagementPassword(password string) ServerOption
WithLocalManagementPassword stores a runtime-only management password accepted for localhost requests.
func WithManagementConfigChangeHook ¶ added in v0.0.7
func WithManagementConfigChangeHook(hook func(*config.Config)) ServerOption
func WithManagementConfigStore ¶ added in v0.0.7
func WithManagementConfigStore(store managementHandlers.ManagementConfigStore) ServerOption
func WithMiddleware ¶
func WithMiddleware(mw ...gin.HandlerFunc) ServerOption
WithMiddleware appends additional Gin middleware during server construction.
func WithPostAuthHook ¶
func WithPostAuthHook(hook auth.PostAuthHook) ServerOption
WithPostAuthHook registers a hook to be called after auth record creation.
func WithQuotaAlertSecretCipher ¶ added in v0.0.22
func WithQuotaAlertSecretCipher(cipher *quotaalert.SecretCipher) ServerOption
func WithQuotaAlertStore ¶ added in v0.0.22
func WithQuotaAlertStore(store quotaalert.Store) ServerOption
func WithRequestLoggerFactory ¶
func WithRequestLoggerFactory(factory func(*config.Config, string) logging.RequestLogger) ServerOption
WithRequestLoggerFactory customises request logger creation.
func WithRouterConfigurator ¶
func WithRouterConfigurator(fn func(*gin.Engine, *handlers.BaseAPIHandler, *config.Config)) ServerOption
WithRouterConfigurator appends a callback after default routes are registered.
func WithRuntimeSettingsStore ¶ added in v0.0.22
func WithRuntimeSettingsStore(store runtimecontrol.SettingsStore) ServerOption
func WithRuntimeStoragePolicy ¶ added in v0.0.9
func WithRuntimeStoragePolicy(policy runtimepolicy.RuntimeStorage) ServerOption
func WithSelfUpdateEngine ¶ added in v0.0.24
func WithSelfUpdateEngine(engine managementHandlers.SelfUpdateEngine) ServerOption
WithSelfUpdateEngine wires the staging engine behind POST /v0/management/self-update (R13). The engine resolves ${DATA_DIR} the same way the update CLI does.
func WithSelfUpdateRestartRunner ¶ added in v0.0.24
func WithSelfUpdateRestartRunner(runner func(context.Context) error) ServerOption
WithSelfUpdateRestartRunner overrides the fixed restart command runner used by POST /v0/management/self-update/apply. When unset, the handler runs `sudo -n /usr/bin/systemctl restart llmhub.service` itself (R14).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
handlers
|
|
|
management
Package management provides the management API handlers and middleware for configuring the server and managing auth files.
|
Package management provides the management API handlers and middleware for configuring the server and managing auth files. |
|
Package middleware provides HTTP middleware components for the CLI Proxy API server.
|
Package middleware provides HTTP middleware components for the CLI Proxy API server. |
|
Package modules provides a pluggable routing module system for extending the API server with optional features without modifying core routing logic.
|
Package modules provides a pluggable routing module system for extending the API server with optional features without modifying core routing logic. |