compactor

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SystemPrompt = `` /* 275-byte string literal not displayed */

Variables

This section is empty.

Functions

func BuildDistillationPrompt

func BuildDistillationPrompt(manifest RawManifest) string

func CompactDescriptionForTest

func CompactDescriptionForTest(description string) string

Types

type Cache

type Cache interface {
	Get(ctx context.Context, serverName string, originalHash string) (*DistilledManifest, error)
	Set(ctx context.Context, serverName string, manifest *DistilledManifest) error
	Invalidate(ctx context.Context, serverName string) error
}

type Compactor

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

func NewCompactor

func NewCompactor(client LLMClient, cache Cache, cfg CompactorConfig, logger *slog.Logger) *Compactor

func (*Compactor) Compact

func (c *Compactor) Compact(ctx context.Context, manifest RawManifest) (*DistilledManifest, error)

func (*Compactor) CompactWithFallback

func (c *Compactor) CompactWithFallback(ctx context.Context, manifest RawManifest) (*DistilledManifest, error)

func (*Compactor) InvalidateCache

func (c *Compactor) InvalidateCache(ctx context.Context, serverName string) error

func (*Compactor) IsEnabled

func (c *Compactor) IsEnabled() bool

type CompactorConfig

type CompactorConfig struct {
	Enabled  bool
	CacheDir string
}

type Config

type Config struct {
	Enabled     bool   `yaml:"enabled"`
	LLMProvider string `yaml:"llm_provider"`
	LLMEndpoint string `yaml:"llm_endpoint"`
	LLMAPIKey   string `yaml:"llm_api_key"`
	LLMModel    string `yaml:"llm_model"`
	CacheDir    string `yaml:"cache_dir"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

func (*Config) GetAPIKey

func (c *Config) GetAPIKey() string

type DistilledManifest

type DistilledManifest struct {
	ServerName   string          `json:"server_name"`
	Tools        []DistilledTool `json:"tools"`
	OriginalHash string          `json:"original_hash"`
	DistilledAt  time.Time       `json:"distilled_at"`
}

func (DistilledManifest) TokenReduction

func (d DistilledManifest) TokenReduction(originalTokenCount int) float64

type DistilledTool

type DistilledTool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

type FileCache

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

func NewFileCache

func NewFileCache(cacheDir string, logger *slog.Logger) (*FileCache, error)

func (*FileCache) Get

func (c *FileCache) Get(ctx context.Context, serverName string, originalHash string) (*DistilledManifest, error)

func (*FileCache) Invalidate

func (c *FileCache) Invalidate(ctx context.Context, serverName string) error

func (*FileCache) Set

func (c *FileCache) Set(ctx context.Context, serverName string, manifest *DistilledManifest) error

type LLMClient

type LLMClient interface {
	Distill(ctx context.Context, manifest RawManifest) (*DistilledManifest, error)
}

type ManifestProcessor

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

func NewManifestProcessor

func NewManifestProcessor(logger *slog.Logger) *ManifestProcessor

func (*ManifestProcessor) Process

type NoOpCache

type NoOpCache struct{}

func NewNoOpCache

func NewNoOpCache() *NoOpCache

func (*NoOpCache) Get

func (c *NoOpCache) Get(ctx context.Context, serverName string, originalHash string) (*DistilledManifest, error)

func (*NoOpCache) Invalidate

func (c *NoOpCache) Invalidate(ctx context.Context, serverName string) error

func (*NoOpCache) Set

func (c *NoOpCache) Set(ctx context.Context, serverName string, manifest *DistilledManifest) error

type OpenAIClient

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

func NewOpenAIClient

func NewOpenAIClient(cfg OpenAIClientConfig, logger *slog.Logger) *OpenAIClient

func (*OpenAIClient) Distill

func (c *OpenAIClient) Distill(ctx context.Context, manifest RawManifest) (*DistilledManifest, error)

type OpenAIClientConfig

type OpenAIClientConfig struct {
	Endpoint string
	APIKey   string
	Model    string
}

type RawManifest

type RawManifest struct {
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	Tools        []RawTool `json:"tools"`
	OriginalHash string    `json:"-"`
}

func (RawManifest) Hash

func (r RawManifest) Hash() string

type RawTool

type RawTool struct {
	Name        string          `json:"name"`
	Description string          `json:"description"`
	Parameters  json.RawMessage `json:"parameters"`
}

Jump to

Keyboard shortcuts

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