discovery

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package discovery provides model discovery interfaces and implementations.

Index

Constants

View Source
const DefaultAPITTL = 60 * 60

DefaultAPITTL is 1 hour for API sources.

View Source
const DefaultGitHubTTL = 24 * 60 * 60

DefaultGitHubTTL is 24 hours for GitHub sources.

View Source
const GracePeriodDays = 7

GracePeriodDays is how long stale cache is considered valid.

Variables

View Source
var GitHubSources = []SourceConfig{
	{
		ProviderID: constant.GeminiCLI,
		URL:        "https://raw.githubusercontent.com/google-gemini/gemini-cli/main/packages/core/src/config/models.ts",
		SourceType: "github",
		TTLSeconds: DefaultGitHubTTL,
	},
}

GitHubSources contains the verified GitHub URLs for CLI model discovery.

Functions

This section is empty.

Types

type Cache

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

Cache provides file-based caching for discovered models.

func NewCache

func NewCache(dir string) (*Cache, error)

NewCache creates a new cache with the given directory. If the directory does not exist, it will be created.

func (*Cache) Clear

func (c *Cache) Clear(providerID string) error

Clear removes a specific provider from the cache.

func (*Cache) ClearAll

func (c *Cache) ClearAll() error

ClearAll removes all cache entries.

func (*Cache) Get

func (c *Cache) Get(providerID string) *CacheEntry

Get retrieves a cached entry for the given provider. Returns nil if not found or expired.

func (*Cache) GetWithGrace

func (c *Cache) GetWithGrace(providerID string, graceDays int) *CacheEntry

GetWithGrace retrieves a cached entry, allowing grace period for stale data. graceDays specifies how many days old the cache can be before it's rejected.

func (*Cache) Set

func (c *Cache) Set(entry *CacheEntry) error

Set stores a cache entry for the given provider.

type CacheEntry

type CacheEntry struct {
	ProviderID string                `json:"provider_id"`
	FetchedAt  time.Time             `json:"fetched_at"`
	TTLSeconds int                   `json:"ttl_seconds"`
	Models     []*registry.ModelInfo `json:"models"`
	SourceURL  string                `json:"source_url,omitempty"`
	SourceType string                `json:"source_type"` // "github" or "api"
}

CacheEntry represents a cached discovery result.

type Discoverer

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

Discoverer orchestrates model discovery from multiple sources.

func NewDiscoverer

func NewDiscoverer(cacheDir string) (*Discoverer, error)

NewDiscoverer creates a new Discoverer with the given cache directory.

func (*Discoverer) AddSource

func (d *Discoverer) AddSource(src SourceConfig)

AddSource adds a new discovery source dynamically.

func (*Discoverer) DiscoverAll

func (d *Discoverer) DiscoverAll(ctx context.Context) (map[string][]*registry.ModelInfo, error)

DiscoverAll runs discovery for all configured sources. Returns a map of provider ID to discovered models.

func (*Discoverer) GetCachedModels

func (d *Discoverer) GetCachedModels(providerID string) []*registry.ModelInfo

GetCachedModels returns cached models for a provider if available.

func (*Discoverer) Refresh

func (d *Discoverer) Refresh(ctx context.Context, providerID string) error

Refresh forces a refresh for a specific provider or all providers. If providerID is empty, refreshes all.

type Fetcher

type Fetcher interface {
	// Fetch retrieves the content from the given URL.
	Fetch(ctx context.Context, url string) ([]byte, error)
}

Fetcher is the interface for retrieving raw content from a remote source (URL).

type ModelDiscoverer

type ModelDiscoverer interface {
	// Discover returns a list of available models.
	Discover(ctx context.Context) ([]*registry.ModelInfo, error)

	// ProviderID returns the identifier for this discoverer's provider.
	ProviderID() string
}

ModelDiscoverer is the interface that all discovery strategies must implement. It returns a list of discovered model definitions.

type Parser

type Parser interface {
	// Parse extracts model definitions from the given raw content.
	Parse(content []byte) ([]*registry.ModelInfo, error)
}

Parser is the interface for parsing raw content into model definitions.

type SourceConfig

type SourceConfig struct {
	ProviderID string
	URL        string
	SourceType string // "github" or "api"
	TTLSeconds int
	Parser     Parser
	AuthHeader string // Optional Authorization header
}

SourceConfig defines a discovery source configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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