Documentation
¶
Overview ¶
Package registry provides capability registration and discovery.
This package implements the factory pattern for dynamic capability loading. Capabilities self-register via init() functions, enabling modular plugin-style architecture.
Index ¶
- Variables
- func ApplyOptions[C any](cfg C, opts ...Option[C]) C
- func FromMap[C any, T any](factory TypedFactory[C, T], parser func(Config) (C, error)) func(Config) (T, error)
- func FromMapNoConfig[T any](factory TypedFactory[NoConfig, T]) func(Config) (T, error)
- func GetAPIKeyWithEnv(cfg Config, envVar string, generatorName string) (string, error)
- func GetBool(cfg Config, key string, defaultValue bool) bool
- func GetFloat32(cfg Config, key string, defaultValue float32) float32
- func GetFloat64(cfg Config, key string, defaultValue float64) float64
- func GetInt(cfg Config, key string, defaultValue int) int
- func GetOptionalAPIKeyWithEnv(cfg Config, envVar string) string
- func GetString(cfg Config, key string, defaultValue string) string
- func GetStringSlice(cfg Config, key string, defaultValue []string) []string
- func MaskAPIKey(key string) string
- func NewWithOptions[C any, T any](defaults C, factory TypedFactory[C, T], opts ...Option[C]) (T, error)
- func RequireString(cfg Config, key string) (string, error)
- func RequireStringSlice(cfg Config, key string) ([]string, error)
- func WarnDeprecatedKeys(cfg Config)
- type Config
- type NoConfig
- type Option
- type PluginCache
- func (c *PluginCache) Clear()
- func (c *PluginCache) Get(category, name string) (PluginMeta, bool)
- func (c *PluginCache) IsValid(category, name, currentHash string) bool
- func (c *PluginCache) List(category string) []PluginMeta
- func (c *PluginCache) Load() error
- func (c *PluginCache) Save() error
- func (c *PluginCache) Set(category, name string, meta PluginMeta) error
- type PluginMeta
- type Registry
- func (r *Registry[T]) Count() int
- func (r *Registry[T]) Create(name string, cfg Config) (T, error)
- func (r *Registry[T]) Get(name string) (func(Config) (T, error), bool)
- func (r *Registry[T]) Has(name string) bool
- func (r *Registry[T]) List() []string
- func (r *Registry[T]) Name() string
- func (r *Registry[T]) Register(name string, factory func(Config) (T, error))
- type TypedFactory
Constants ¶
This section is empty.
Variables ¶
var DeprecatedKeys = map[string]string{
"judge_model": "set model inside judge.config (YAML) or judge_config map instead",
"judge_generator_config": "use judge_config instead",
"judge_generator": "use judge_generator_type instead",
}
DeprecatedKeys lists all deprecated config keys and their migration guidance. This is the single source of truth for deprecated configuration.
var ErrNotFound = fmt.Errorf("capability not found")
ErrNotFound is returned when a capability is not registered.
Functions ¶
func ApplyOptions ¶
ApplyOptions applies a series of options to a config struct. Returns the modified config.
Usage:
cfg := ApplyOptions(DefaultOpenAIConfig(), WithModel("gpt-4"), WithTemp(0.5))
func FromMap ¶
func FromMap[C any, T any](factory TypedFactory[C, T], parser func(Config) (C, error)) func(Config) (T, error)
FromMap adapts a TypedFactory to work with legacy registry.Config (map[string]any). This enables gradual migration: new code uses typed configs, while maintaining backward compatibility with YAML/JSON configuration.
Usage:
typedFactory := func(cfg OpenAIConfig) (*OpenAI, error) { ... }
parser := func(m Config) (OpenAIConfig, error) { ... }
legacyFactory := FromMap(typedFactory, parser)
generators.Register("openai.OpenAI", legacyFactory)
func FromMapNoConfig ¶
func FromMapNoConfig[T any](factory TypedFactory[NoConfig, T]) func(Config) (T, error)
FromMapNoConfig adapts a NoConfig TypedFactory to legacy registry.Config. Use this for factories that ignore configuration.
Usage:
typedFactory := func(_ NoConfig) (*MyProbe, error) { return &MyProbe{}, nil }
legacyFactory := FromMapNoConfig(typedFactory)
probes.Register("myprobe.MyProbe", legacyFactory)
func GetAPIKeyWithEnv ¶
GetAPIKeyWithEnv retrieves an API key from config, falling back to an environment variable. Returns an error if neither source provides a value.
func GetFloat32 ¶
GetFloat32 retrieves a float32 value from Config with a default fallback. Handles both float64 and int.
func GetFloat64 ¶
GetFloat64 retrieves a float64 value from Config with a default fallback. Handles both float64 and int.
func GetInt ¶
GetInt retrieves an int value from Config with a default fallback. Handles both int and float64 (JSON numbers are float64).
func GetOptionalAPIKeyWithEnv ¶
GetOptionalAPIKeyWithEnv retrieves an API key from config or an environment variable. Returns empty string without error if neither is set.
func GetStringSlice ¶
GetStringSlice retrieves a []string from Config with a default fallback. Handles both []string and []any (where elements are strings).
func MaskAPIKey ¶ added in v0.0.2
MaskAPIKey masks an API key for safe display in logs and error messages. Shows only first 3 and last 3 characters. Keys of 6 or fewer characters are fully masked. Empty keys display as "<empty>".
This function uses byte-based indexing (len/slice), which assumes the key contains only ASCII characters. This is standard for API keys (e.g., OpenAI "sk-...", Anthropic "sk-ant-...", Azure hex subscription keys). Do not use with keys containing multi-byte UTF-8 characters.
Examples:
"sk-1234567890abcdef" -> "sk-***def" "short" -> "***" "" -> "<empty>"
func NewWithOptions ¶
func NewWithOptions[C any, T any]( defaults C, factory TypedFactory[C, T], opts ...Option[C], ) (T, error)
NewWithOptions creates a component using functional options. This is a convenience wrapper for common factory patterns.
Usage:
func NewOpenAI(opts ...OpenAIOption) (*OpenAI, error) {
cfg := ApplyOptions(DefaultOpenAIConfig(), opts...)
return newOpenAIFromConfig(cfg)
}
func RequireString ¶
RequireString retrieves a required string value from Config. Returns an error if the key is missing or not a string.
func RequireStringSlice ¶
RequireStringSlice retrieves a required []string from Config. Returns an error if the key is missing or not a slice of strings.
func WarnDeprecatedKeys ¶ added in v0.0.10
func WarnDeprecatedKeys(cfg Config)
WarnDeprecatedKeys checks cfg for any keys in DeprecatedKeys and emits slog.Warn for each. Each key only warns once per process to avoid log spam during scans.
Types ¶
type NoConfig ¶
type NoConfig struct{}
NoConfig is a marker type for factories that don't require configuration. Use this instead of ignoring the registry.Config parameter.
Usage:
var factory TypedFactory[NoConfig, *MyProbe] = func(_ NoConfig) (*MyProbe, error) { return &MyProbe{}, nil }
type Option ¶
type Option[C any] func(*C)
Option is a generic functional option type. Each config struct should define its own Option type alias.
Usage:
type OpenAIOption = Option[OpenAIConfig]
func WithModel(m string) OpenAIOption { return func(c *OpenAIConfig) { c.Model = m } }
type PluginCache ¶
type PluginCache struct {
// contains filtered or unexported fields
}
PluginCache manages cached plugin metadata for fast startup. It is safe for concurrent use.
func NewPluginCache ¶
func NewPluginCache(path string) *PluginCache
NewPluginCache creates a new plugin cache with the given file path.
func (*PluginCache) Get ¶
func (c *PluginCache) Get(category, name string) (PluginMeta, bool)
Get retrieves plugin metadata from the cache. Returns false if the entry does not exist.
func (*PluginCache) IsValid ¶
func (c *PluginCache) IsValid(category, name, currentHash string) bool
IsValid checks if a cached entry is still valid based on file hash. Returns false if the entry doesn't exist or the hash doesn't match.
func (*PluginCache) List ¶
func (c *PluginCache) List(category string) []PluginMeta
List returns all cached metadata for a given category.
func (*PluginCache) Save ¶
func (c *PluginCache) Save() error
Save writes the cache to disk as JSON.
func (*PluginCache) Set ¶
func (c *PluginCache) Set(category, name string, meta PluginMeta) error
Set stores plugin metadata in the cache.
type PluginMeta ¶
type PluginMeta struct {
Name string `json:"name"`
Description string `json:"description"`
Active bool `json:"active"`
FileHash string `json:"file_hash"`
LoadTime time.Duration `json:"load_time"`
CachedAt time.Time `json:"cached_at"`
}
PluginMeta holds cached metadata about a plugin.
type Registry ¶
type Registry[T any] struct { // contains filtered or unexported fields }
Registry manages registered capabilities of a specific type. It is safe for concurrent use.
type TypedFactory ¶
TypedFactory is a generic factory function that creates components from typed configuration. This provides compile-time type safety.
Usage:
type OpenAIConfig struct { Model string; APIKey string }
var factory TypedFactory[OpenAIConfig, *OpenAI] = func(cfg OpenAIConfig) (*OpenAI, error) { ... }