extension

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package extension provides the Forge extension adapter for Nexus.

It implements the forge.Extension interface to integrate the Nexus AI gateway into a Forge application with automatic dependency discovery, DI registration, and lifecycle management.

Configuration can be provided programmatically via Option functions or via YAML configuration files under "extensions.nexus" or "nexus" keys.

Index

Constants

View Source
const BootstrapAdminKeyEnv = "NEXUS_BOOTSTRAP_ADMIN_KEY"

BootstrapAdminKeyEnv is the environment variable that supplies the bootstrap admin key when the config sets none.

View Source
const ExtensionDescription = "Composable AI gateway — route, cache, guard, and observe LLM traffic"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "nexus"

ExtensionName is the name registered with Forge.

View Source
const ExtensionVersion = "0.1.0"

ExtensionVersion is the semantic version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DisableRoutes prevents HTTP route registration.
	//
	// Deprecated: the extension never mounts routes; mount the api or proxy packages on your router yourself.
	DisableRoutes bool `json:"disable_routes" mapstructure:"disable_routes" yaml:"disable_routes"`

	// DisableMigrate prevents auto-migration of the persistence store on start.
	DisableMigrate bool `json:"disable_migrate" mapstructure:"disable_migrate" yaml:"disable_migrate"`

	// BasePath is the URL prefix for gateway routes (default: "/nexus").
	//
	// Deprecated: the extension never mounts routes; mount the api or proxy packages on your router yourself.
	BasePath string `json:"base_path" mapstructure:"base_path" yaml:"base_path"`

	// DefaultTimeout is the default timeout for provider requests.
	DefaultTimeout time.Duration `json:"default_timeout" mapstructure:"default_timeout" yaml:"default_timeout"`

	// DefaultMaxRetries is the default number of retries per request.
	DefaultMaxRetries int `json:"default_max_retries" mapstructure:"default_max_retries" yaml:"default_max_retries"`

	// GlobalRateLimit is the global rate limit in requests per minute (0 = unlimited).
	GlobalRateLimit int `json:"global_rate_limit" mapstructure:"global_rate_limit" yaml:"global_rate_limit"`

	// LogLevel is the log level for the gateway's internal logger (default: "info").
	LogLevel string `json:"log_level" mapstructure:"log_level" yaml:"log_level"`

	// EnableUsage enables usage tracking (default: true).
	EnableUsage *bool `json:"enable_usage" mapstructure:"enable_usage" yaml:"enable_usage"`

	// RequireAPIKey makes the HTTP edges refuse a request without a valid
	// nxs_ key (default: true).
	RequireAPIKey *bool `json:"require_api_key" mapstructure:"require_api_key" yaml:"require_api_key"`

	// EnableCache enables response caching (default: false).
	EnableCache bool `json:"enable_cache" mapstructure:"enable_cache" yaml:"enable_cache"`

	// GroveDatabase is the name of a grove.DB registered in the DI container.
	// When set, the extension resolves this named database and auto-constructs
	// the appropriate store based on the driver type (pg/sqlite/mongo).
	// When empty and WithGroveDatabase was called, the default (unnamed) DB is used.
	GroveDatabase string `json:"grove_database" mapstructure:"grove_database" yaml:"grove_database"`

	// BootstrapAdminKey is the raw value of the first admin key: "nxs_" and
	// 64 lowercase hex digits, for example "nxs_" plus the output of
	// `openssl rand -hex 32`. On start, after migration, the extension stores
	// it under the "operator" tenant with the admin scope, once. When empty,
	// the NEXUS_BOOTSTRAP_ADMIN_KEY environment variable is used. It is a
	// secret: prefer the env var to a file under source control. The
	// extension never logs it.
	BootstrapAdminKey string `json:"bootstrap_admin_key" mapstructure:"bootstrap_admin_key" yaml:"bootstrap_admin_key"`

	// RequireConfig requires config to be present in YAML files.
	// If true and no config is found, Register returns an error.
	RequireConfig bool `json:"-" yaml:"-"`
}

Config holds the Nexus Forge extension configuration. Fields can be set programmatically via Option functions or loaded from YAML configuration files (under "extensions.nexus" or "nexus" keys).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Extension

type Extension struct {
	*forge.BaseExtension
	// contains filtered or unexported fields
}

Extension adapts Nexus as a Forge extension.

func New

func New(opts ...Option) *Extension

New creates a new Nexus Forge extension with the given options.

func (*Extension) Gateway

func (e *Extension) Gateway() *nexus.Gateway

Gateway returns the underlying Nexus gateway instance. It is non-nil after Register and is the same pointer the DI container provides. Its engine returns nexus.ErrNotInitialized until Start.

func (*Extension) Health

func (e *Extension) Health(_ context.Context) error

Health implements forge.Extension. It reports not ready until Start has initialized the gateway, and again after Stop.

func (*Extension) Register

func (e *Extension) Register(fapp forge.App) error

Register implements forge.Extension. It loads configuration and registers the gateway constructor in the DI container.

func (*Extension) RegisterContractContributor

func (e *Extension) RegisterContractContributor(d *dispatcher.Dispatcher, reg dash.Registry, wreg dash.WardenRegistry) error

RegisterContractContributor registers the Nexus dashboard before startup; its handlers resolve the gateway only after Start succeeds.

func (*Extension) Start

func (e *Extension) Start(ctx context.Context) error

Start implements forge.Extension. It creates and initializes the gateway.

func (*Extension) Stop

func (e *Extension) Stop(ctx context.Context) error

Stop implements forge.Extension. It gracefully shuts down the gateway. A gateway that never finished Initialize has nothing to shut down.

type Option

type Option func(*Extension)

Option configures the Nexus Forge extension.

func WithBasePath deprecated

func WithBasePath(path string) Option

WithBasePath sets the HTTP base path for gateway routes.

Deprecated: the extension never mounts routes; mount the api or proxy packages on your router yourself.

func WithConfig

func WithConfig(cfg Config) Option

WithConfig sets the Forge extension configuration.

func WithDatabase

func WithDatabase(s store.Store) Option

WithDatabase sets the persistence store.

func WithDisableMigrate

func WithDisableMigrate() Option

WithDisableMigrate prevents auto-migration on start.

func WithDisableRoutes deprecated

func WithDisableRoutes() Option

WithDisableRoutes prevents HTTP route registration.

Deprecated: the extension never mounts routes; mount the api or proxy packages on your router yourself.

func WithGatewayOption

func WithGatewayOption(opt nexus.Option) Option

WithGatewayOption adds a raw nexus.Option directly to the gateway.

func WithGroveDatabase

func WithGroveDatabase(name string) Option

WithGroveDatabase sets the name of the grove.DB to resolve from the DI container. The extension will auto-construct the appropriate store backend (postgres/sqlite/mongo) based on the grove driver type. Pass an empty string to use the default (unnamed) grove.DB.

func WithProvider

func WithProvider(p provider.Provider) Option

WithProvider adds an LLM provider to the gateway.

func WithRequireConfig

func WithRequireConfig(require bool) Option

WithRequireConfig requires config to be present in YAML files. If true and no config is found, Register returns an error.

func WithStreamCache

func WithStreamCache(sc cache.StreamCache, opts cache.StreamCacheOptions) Option

WithStreamCache enables stream record-and-replay caching backed by sc. Convenience wrapper around nexus.WithStreamCache.

func WithStreamLifecycleConfig

func WithStreamLifecycleConfig(cfg middlewares.StreamLifecycleConfig) Option

WithStreamLifecycleConfig tunes per-chunk plugin hook fan-out and per-tenant stream quotas. Convenience wrapper around nexus.WithStreamLifecycleConfig.

Directories

Path Synopsis
Package contract serves the operator-wide Nexus dashboard contract.
Package contract serves the operator-wide Nexus dashboard contract.

Jump to

Keyboard shortcuts

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