extension

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package extension provides the Forge extension adapter for Weave.

It implements the forge.Extension interface to integrate Weave into a Forge application with automatic dependency discovery, route registration, and lifecycle management.

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

Package extension adapts the Weave engine as a Forge extension.

Index

Constants

View Source
const DefaultRecoveryInterval = 5 * time.Minute

DefaultRecoveryInterval is how often the recovery loop sweeps when recovery_interval is unset.

View Source
const ExtensionDescription = "Composable RAG pipeline engine for document ingestion, embedding, and retrieval"

ExtensionDescription is the human-readable description.

View Source
const ExtensionName = "weave"

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.
	DisableRoutes bool `json:"disable_routes" mapstructure:"disable_routes" yaml:"disable_routes"`

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

	// BasePath is the URL prefix for weave routes (default: "/weave").
	BasePath string `json:"base_path" mapstructure:"base_path" yaml:"base_path"`

	// DefaultChunkSize is the default number of tokens per chunk.
	DefaultChunkSize int `json:"default_chunk_size" mapstructure:"default_chunk_size" yaml:"default_chunk_size"`

	// DefaultChunkOverlap is the default token overlap between chunks.
	DefaultChunkOverlap int `json:"default_chunk_overlap" mapstructure:"default_chunk_overlap" yaml:"default_chunk_overlap"`

	// DefaultEmbeddingModel is the default embedding model identifier.
	DefaultEmbeddingModel string `json:"default_embedding_model" mapstructure:"default_embedding_model" yaml:"default_embedding_model"`

	// DefaultChunkStrategy is the default chunking strategy (e.g., "recursive").
	DefaultChunkStrategy string `json:"default_chunk_strategy" mapstructure:"default_chunk_strategy" yaml:"default_chunk_strategy"`

	// DefaultTopK is the default number of results for similarity searches.
	DefaultTopK int `json:"default_top_k" mapstructure:"default_top_k" yaml:"default_top_k"`

	// ShutdownTimeout is the maximum time to wait for graceful shutdown.
	ShutdownTimeout time.Duration `json:"shutdown_timeout" mapstructure:"shutdown_timeout" yaml:"shutdown_timeout"`

	// IngestConcurrency controls how many ingest operations can run in parallel.
	IngestConcurrency int `json:"ingest_concurrency" mapstructure:"ingest_concurrency" yaml:"ingest_concurrency"`

	// RecoveryInterval is how often the engine sweeps for documents a crash
	// left pending, processing or superseded, and recovers them. Zero means
	// the default; a negative value turns the loop off, for a host that runs
	// engine.RecoverStalled from its own scheduler.
	RecoveryInterval time.Duration `json:"recovery_interval" mapstructure:"recovery_interval" yaml:"recovery_interval"` // default 5m; negative disables

	// StalledAfter is how long a pending or processing document may go
	// without a heartbeat before recovery fails it and a keyed ingest of the
	// same content may claim it. Keep it well above the longest embed call.
	StalledAfter time.Duration `json:"stalled_after" mapstructure:"stalled_after" yaml:"stalled_after"` // default 15m (contract.StalledAfter)

	// 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"`

	// 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 Weave extension configuration. Fields can be set programmatically via ExtOption functions or loaded from YAML configuration files (under "extensions.weave" or "weave" keys).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type ExtOption

type ExtOption func(*Extension)

ExtOption configures the Weave Forge extension.

func WithBasePath

func WithBasePath(path string) ExtOption

WithBasePath sets the URL prefix for all weave routes.

func WithConfig

func WithConfig(cfg Config) ExtOption

WithConfig sets the extension configuration.

func WithDashboardTenant

func WithDashboardTenant(fn func(ctx context.Context, p dashcontract.Principal) (string, error)) ExtOption

WithDashboardTenant sets how the dashboard finds the Weave tenant of a request. fn gets the request context and the signed-in principal, and its answer scopes every dashboard intent: lists, counts, gets, writes and retrieval. An empty answer or an error refuses the request with PERMISSION_DENIED, and the error's text never reaches the client.

Without it the dashboard reads weave.TenantFromContext, so a host can also set the tenant in its own middleware. A request that has none is refused either way.

func WithDisableMigrate

func WithDisableMigrate() ExtOption

WithDisableMigrate disables auto-migration on start.

func WithDisableRoutes

func WithDisableRoutes() ExtOption

WithDisableRoutes disables HTTP route registration.

func WithEngineOption

func WithEngineOption(opt engine.Option) ExtOption

WithEngineOption passes an engine option directly.

func WithExtension

func WithExtension(x plugins.Extension) ExtOption

WithExtension registers a Weave plugin (lifecycle hooks).

func WithGroveDatabase

func WithGroveDatabase(name string) ExtOption

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 WithRequireConfig

func WithRequireConfig(require bool) ExtOption

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

func WithStore

func WithStore(s store.Store) ExtOption

WithStore sets the metadata store.

func WithVectorStore

func WithVectorStore(vs vectorstore.VectorStore) ExtOption

WithVectorStore sets the vector store.

type Extension

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

Extension adapts Weave as a Forge extension.

func New

func New(opts ...ExtOption) *Extension

New creates a Weave Forge extension with the given options.

func (*Extension) API

func (e *Extension) API() *api.API

API returns the API handler.

func (*Extension) Engine

func (e *Extension) Engine() *engine.Engine

Engine returns the underlying Weave engine. This is nil until Register is called.

func (*Extension) Handler

func (e *Extension) Handler() http.Handler

Handler returns the HTTP handler for all API routes. Convenience for standalone use outside Forge. Like api.API.Handler, it panics when a route fails to register.

func (*Extension) Health

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

Health implements forge.Extension.

func (*Extension) Register

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

Register implements forge.Extension. It loads configuration, initializes the engine, and registers it in the DI container.

func (*Extension) RegisterContractContributor

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

RegisterContractContributor registers the weave contract contributor, which is what the React dashboard reads. Forge's dashboard discovers it by type assertion during Start.

func (*Extension) RegisterRoutes

func (e *Extension) RegisterRoutes(router forge.Router) error

RegisterRoutes registers all Weave API routes into a Forge router. It returns an error naming every route the router refused, and nil before Register has run.

func (*Extension) Start

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

Start begins the Weave engine and runs auto-migration if enabled.

func (*Extension) Stop

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

Stop gracefully shuts down the Weave engine.

Directories

Path Synopsis
Package contract wires Weave into the Forge dashboard's contract path.
Package contract wires Weave into the Forge dashboard's contract path.

Jump to

Keyboard shortcuts

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