host

package
v0.0.0-...-1e0776f Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package host provides gRPC server implementations for host services exposed to plugins.

Package host provides vector storage operations for plugins. This file imports required drivers and the functionality is split across: - storage_vector_store.go: Store operations (VectorStoreEmbedding, VectorStoreBatch) - storage_vector_search.go: Search operations (VectorSearch, VectorSearchText) - storage_vector_crud.go: CRUD operations (VectorGet, VectorDelete, VectorDeleteByType, VectorCount) - storage_vector_helpers.go: Helper functions and table management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithPluginID

func ContextWithPluginID(ctx context.Context, pluginID string) context.Context

ContextWithPluginID returns a context with the plugin ID set.

func GetPluginIDFromContext

func GetPluginIDFromContext(ctx context.Context) string

GetPluginIDFromContext extracts the plugin ID from the context.

Types

type CapabilityProvider

type CapabilityProvider struct {
	PluginID   string // Unique plugin identifier
	PluginName string // Human-readable name
	Enabled    bool   // Whether the plugin is currently enabled
	Configured bool   // Whether the plugin is properly configured
}

CapabilityProvider describes a plugin that provides a specific capability.

type CastMemberInfo

type CastMemberInfo = querier.CastMemberInfo

Type aliases for backward compatibility - types are now defined in querier package.

type DataServer

type DataServer struct {
	pluginv1.UnimplementedHostDataServer
	// contains filtered or unexported fields
}

DataServer implements the HostData gRPC service. This runs in the host process and provides read-only access to media data.

func NewDataServer

func NewDataServer(querier MediaQuerier, logger *slog.Logger) *DataServer

NewDataServer creates a new DataServer.

func (*DataServer) GetFilePath

func (s *DataServer) GetFilePath(ctx context.Context, req *pluginv1.MediaId) (*pluginv1.FilePath, error)

GetFilePath returns the full file path for a media item.

func (*DataServer) GetLibrary

func (s *DataServer) GetLibrary(ctx context.Context, req *pluginv1.LibraryId) (*pluginv1.Library, error)

GetLibrary retrieves library information.

func (*DataServer) GetMedia

func (s *DataServer) GetMedia(ctx context.Context, req *pluginv1.MediaQuery) (*pluginv1.Media, error)

GetMedia retrieves a single media item by ID.

func (*DataServer) GetMediaByExternalId

func (s *DataServer) GetMediaByExternalId(ctx context.Context, req *pluginv1.ExternalIdQuery) (*pluginv1.Media, error)

GetMediaByExternalId looks up media by external ID.

func (*DataServer) GetMediaDetails

func (s *DataServer) GetMediaDetails(ctx context.Context, req *pluginv1.MediaQuery) (*pluginv1.MediaDetails, error)

GetMediaDetails retrieves full metadata for a media item.

func (*DataServer) ListMediaByDirector

func (s *DataServer) ListMediaByDirector(ctx context.Context, req *pluginv1.ListMediaByDirectorRequest) (*pluginv1.MediaList, error)

ListMediaByDirector lists media items directed by a specific person. Used for director-based recommendations and themed collections.

func (*DataServer) ListMediaByGenre

ListMediaByGenre lists media items matching a genre pattern. Used for genre-based recommendations when semantic search is unavailable.

func (*DataServer) ListMediaByLibrary

func (s *DataServer) ListMediaByLibrary(ctx context.Context, req *pluginv1.ListMediaRequest) (*pluginv1.MediaDetailsList, error)

ListMediaByLibrary lists all media in a library with pagination.

func (*DataServer) SearchMedia

func (s *DataServer) SearchMedia(ctx context.Context, req *pluginv1.SearchQuery) (*pluginv1.MediaList, error)

SearchMedia searches for media by title/year.

type LibraryInfo

type LibraryInfo = querier.LibraryInfo

Type aliases for backward compatibility - types are now defined in querier package.

type MediaDetailsInfo

type MediaDetailsInfo = querier.MediaDetailsInfo

Type aliases for backward compatibility - types are now defined in querier package.

type MediaInfo

type MediaInfo = querier.MediaInfo

Type aliases for backward compatibility - types are now defined in querier package.

type MediaQuerier

type MediaQuerier interface {
	// GetMediaByID returns a media item by its database ID.
	GetMediaByID(ctx context.Context, id int64) (*MediaInfo, error)

	// GetMediaDetails returns full metadata for a media item (for plugin indexing).
	// mediaType is optional - if empty, it will try to determine the type from the media table.
	GetMediaDetails(ctx context.Context, id int64, mediaType string) (*MediaDetailsInfo, error)

	// GetMediaByExternalID returns a media item by an external ID.
	GetMediaByExternalID(ctx context.Context, provider, externalID string) (*MediaInfo, error)

	// SearchMedia searches for media by title and optional year.
	SearchMedia(ctx context.Context, title string, year int, mediaType string, limit int) ([]*MediaInfo, error)

	// ListMediaByLibrary lists all media in a library with pagination.
	ListMediaByLibrary(ctx context.Context, libraryID int64, limit, offset int) ([]*MediaDetailsInfo, int, error)

	// GetFilePath returns the file path for a media item.
	GetFilePath(ctx context.Context, mediaID int64) (string, error)

	// GetExternalIDs returns all external IDs for a media item.
	GetExternalIDs(ctx context.Context, mediaID int64) (map[string]string, error)

	// GetLibrary returns library information by ID.
	GetLibrary(ctx context.Context, id int64) (*LibraryInfo, error)

	// ListMediaByGenre returns media items matching a genre pattern.
	// mediaType should be "movie" or "tv_show".
	// libraryID=0 means all libraries.
	// excludeIDs are entity IDs to exclude from results.
	ListMediaByGenre(ctx context.Context, mediaType, genre string, libraryID int64, excludeIDs []int64, limit int) ([]*MediaInfo, error)

	// ListMediaByDirector returns media items directed by a specific person.
	// mediaType should be "movie" or "tv_show".
	// libraryID=0 means all libraries.
	// excludeIDs are entity IDs to exclude from results.
	ListMediaByDirector(ctx context.Context, mediaType, directorName string, libraryID int64, excludeIDs []int64, limit int) ([]*MediaInfo, error)
}

MediaQuerier is the interface for querying media data. This abstracts the database layer so plugins don't need direct DB access.

type PluginLookup

type PluginLookup interface {
	// GetPlugin returns a running plugin instance by ID.
	GetPlugin(id string) (*types.Instance, bool)

	// IsPluginEnabled returns true if the plugin is enabled and healthy.
	IsPluginEnabled(id string) bool
}

PluginLookup provides access to running plugin instances. Used to check plugin status and invoke methods on providers.

type PluginsServer

type PluginsServer struct {
	pluginv1.UnimplementedHostPluginsServer
	// contains filtered or unexported fields
}

PluginsServer implements the HostPlugins gRPC service. This allows plugins to discover and invoke methods on other plugins that provide specific capabilities (e.g., "embedding", "chat").

The capability broker enables a plugin architecture where:

  • Provider plugins declare capabilities they provide (e.g., ai-local provides "embedding", "chat")
  • Consumer plugins can invoke methods on capability providers via the host
  • The host manages capability resolution and proxies requests to providers
  • Configuration plugins can set preferences to route capabilities to specific providers

Key design: The host acts as a "dumb pipe" that routes requests to providers. Provider plugins dispatch method calls via a generic Invoke pattern. Consumer plugins use typed protos for requests/responses, while the transport uses generic bytes.

func NewPluginsServer

func NewPluginsServer(lookup PluginLookup, logger *slog.Logger) *PluginsServer

NewPluginsServer creates a new PluginsServer.

func (*PluginsServer) ClearCapabilityPreference

func (s *PluginsServer) ClearCapabilityPreference(ctx context.Context, req *pluginv1.CapabilityPreferenceRequest) (*pluginv1.Empty, error)

ClearCapabilityPreference removes the preference for a capability. After clearing, InvokeCapability falls back to first available provider.

func (*PluginsServer) DescribeCapability

DescribeCapability returns metadata about a capability's available methods. Useful for discovering what methods a capability supports.

func (*PluginsServer) GetCapabilityPreferences

func (s *PluginsServer) GetCapabilityPreferences(ctx context.Context, _ *pluginv1.Empty) (*pluginv1.CapabilityPreferencesResponse, error)

GetCapabilityPreferences returns all configured capability preferences.

func (*PluginsServer) HasCapability

func (s *PluginsServer) HasCapability(capability string) bool

HasCapability returns true if any enabled plugin provides the capability.

func (*PluginsServer) InvokeCapability

InvokeCapability forwards a request to a capability provider. The host resolves the capability to an available provider and proxies the request. This is the core of the cross-plugin RPC system.

func (*PluginsServer) InvokeCapabilityStream

InvokeCapabilityStream forwards a streaming request to a capability provider. Used for server-streaming methods like ChatStream.

func (*PluginsServer) InvokeVectorSearch

InvokeVectorSearch forwards a vector search request to a plugin providing vector_search capability. This enables plugin-to-plugin semantic search operations (e.g., recommendations → semantic-search).

func (*PluginsServer) ListCapabilities

ListCapabilities returns all available capabilities and their providers.

func (*PluginsServer) ListProviders

ListProviders returns all plugins providing a specific capability.

func (*PluginsServer) RegisterCapability

func (s *PluginsServer) RegisterCapability(pluginID, pluginName, capability string)

RegisterCapability registers a plugin as providing a capability. Called when a plugin is loaded and declares capabilities in its manifest.

func (*PluginsServer) SetCapabilityPreference

func (s *PluginsServer) SetCapabilityPreference(ctx context.Context, req *pluginv1.CapabilityPreferenceRequest) (*pluginv1.Empty, error)

SetCapabilityPreference sets the preferred plugin for a capability. Used by configuration plugins (e.g., ai-local) to route capabilities to specific providers. The preference is used when InvokeCapability is called without a preferred_plugin.

func (*PluginsServer) UnregisterPlugin

func (s *PluginsServer) UnregisterPlugin(pluginID string)

UnregisterPlugin removes all capabilities for a plugin. Called when a plugin is unloaded.

func (*PluginsServer) UpdatePluginStatus

func (s *PluginsServer) UpdatePluginStatus(pluginID string, enabled, configured bool)

UpdatePluginStatus updates the enabled/configured status for a plugin.

type ProgressServer

type ProgressServer struct {
	pluginv1.UnimplementedHostProgressServer
	// contains filtered or unexported fields
}

ProgressServer implements the HostProgress gRPC service. It provides read-only access to user watch progress for plugins.

func NewProgressServer

func NewProgressServer(progressRepo progress.Repository, mediaRepo media.Repository, logger *slog.Logger) *ProgressServer

NewProgressServer creates a new ProgressServer.

func (*ProgressServer) GetWatchedEntityIDs

GetWatchedEntityIDs returns entity IDs of watched items.

func (*ProgressServer) HasWatchHistory

HasWatchHistory returns whether a user has any watch history.

func (*ProgressServer) ListInProgressItems

ListInProgressItems returns items the user is currently watching.

func (*ProgressServer) ListWatchedItems

ListWatchedItems returns all watched items for a user.

type RatingsServer

type RatingsServer struct {
	pluginv1.UnimplementedHostRatingsServer
	// contains filtered or unexported fields
}

RatingsServer implements the HostRatings gRPC service. It provides read-only access to user ratings for plugins.

func NewRatingsServer

func NewRatingsServer(repo ratings.Repository, logger *slog.Logger) *RatingsServer

NewRatingsServer creates a new RatingsServer.

func (*RatingsServer) GetPositivelyRatedIDs

GetPositivelyRatedIDs returns entity IDs with positive ratings (favorite or up).

func (*RatingsServer) GetRatedEntityIDs

GetRatedEntityIDs returns entity IDs with a specific rating type.

func (*RatingsServer) HasRatings

HasRatings returns whether a user has any ratings.

func (*RatingsServer) ListRatings

ListRatings returns all ratings for a user, optionally filtered.

type StorageConfig

type StorageConfig struct {
	// BaseDir is the base directory for plugin data files.
	BaseDir string

	// DefaultQuota is the default storage quota per plugin in bytes.
	// Defaults to 100 MB if not set.
	DefaultQuota int64
}

StorageConfig configures the host storage server.

type StorageServer

type StorageServer struct {
	pluginv1.UnimplementedHostStorageServer
	// contains filtered or unexported fields
}

StorageServer implements the HostStorage gRPC service. Each plugin gets an isolated namespace for key-value storage.

func NewStorageServer

func NewStorageServer(cfg StorageConfig, db *sql.DB, driver string, logger *slog.Logger) (*StorageServer, error)

NewStorageServer creates a new StorageServer.

func (*StorageServer) CleanupExpiredEntries

func (s *StorageServer) CleanupExpiredEntries(ctx context.Context) error

CleanupExpiredEntries removes expired KV entries. Should be called periodically (e.g., daily).

func (*StorageServer) DeletePluginStorage

func (s *StorageServer) DeletePluginStorage(ctx context.Context, pluginID string) error

DeletePluginStorage removes all storage for a plugin. Called when a plugin is uninstalled.

func (*StorageServer) ExecuteSQL

ExecuteSQL runs DDL/DML statements on plugin's namespaced tables.

func (*StorageServer) GetBaseDir

func (s *StorageServer) GetBaseDir() string

GetBaseDir returns the base directory for plugin data.

func (*StorageServer) GetDB

func (s *StorageServer) GetDB() *sql.DB

GetDB returns the database connection for advanced operations.

func (*StorageServer) GetDBType

func (s *StorageServer) GetDBType() string

GetDBType returns the database type.

func (*StorageServer) GetDatabasePath

func (s *StorageServer) GetDatabasePath(ctx context.Context, _ *pluginv1.Empty) (*pluginv1.DatabasePath, error)

GetDatabasePath returns the path to the plugin's SQLite database. Plugins can use this for their own local caching needs.

func (*StorageServer) GetDatabaseStats

func (s *StorageServer) GetDatabaseStats(ctx context.Context, _ *pluginv1.Empty) (*pluginv1.DatabaseStats, error)

GetDatabaseStats returns storage usage statistics for the plugin.

func (*StorageServer) KVDelete

func (s *StorageServer) KVDelete(ctx context.Context, req *pluginv1.KVKey) (*pluginv1.Empty, error)

KVDelete removes a value from the plugin's key-value store.

func (*StorageServer) KVGet

func (s *StorageServer) KVGet(ctx context.Context, req *pluginv1.KVKey) (*pluginv1.KVValue, error)

KVGet retrieves a value from the plugin's key-value store.

func (*StorageServer) KVList

KVList lists keys with an optional prefix.

func (*StorageServer) KVSet

func (s *StorageServer) KVSet(ctx context.Context, req *pluginv1.KVEntry) (*pluginv1.Empty, error)

KVSet stores a value in the plugin's key-value store.

func (*StorageServer) QuerySQL

QuerySQL runs SELECT queries on plugin's namespaced tables.

func (*StorageServer) RegisterSchema

func (s *StorageServer) RegisterSchema(ctx context.Context, req *pluginv1.SchemaVersion) (*pluginv1.Empty, error)

RegisterSchema is a no-op - plugins manage their own database schemas.

func (*StorageServer) VectorCount

VectorCount returns the number of embeddings.

func (*StorageServer) VectorDelete

func (s *StorageServer) VectorDelete(ctx context.Context, req *pluginv1.VectorQuery) (*pluginv1.Empty, error)

VectorDelete removes an embedding.

func (*StorageServer) VectorDeleteByType

VectorDeleteByType removes all embeddings for an entity type.

func (*StorageServer) VectorGet

VectorGet retrieves an embedding.

func (*StorageServer) VectorSearch

VectorSearch performs similarity search.

func (*StorageServer) VectorSearchText

VectorSearchText performs text-based search on embedding text field.

func (*StorageServer) VectorStoreBatch

func (s *StorageServer) VectorStoreBatch(ctx context.Context, req *pluginv1.VectorStoreBatchRequest) (*pluginv1.Empty, error)

VectorStoreBatch stores multiple embeddings in a single transaction.

func (*StorageServer) VectorStoreEmbedding

func (s *StorageServer) VectorStoreEmbedding(ctx context.Context, req *pluginv1.VectorStoreRequest) (*pluginv1.Empty, error)

VectorStoreEmbedding stores or updates an embedding for an entity.

type WeatherServer

type WeatherServer struct {
	pluginv1.UnimplementedHostWeatherServer
	// contains filtered or unexported fields
}

WeatherServer implements the HostWeather gRPC service.

func NewWeatherServer

func NewWeatherServer(locationRepo *location.Repository, weatherService *weather.Service, logger *slog.Logger) *WeatherServer

NewWeatherServer creates a new WeatherServer.

func (*WeatherServer) GetCurrentWeather

func (s *WeatherServer) GetCurrentWeather(ctx context.Context, req *pluginv1.WeatherRequest) (*pluginv1.WeatherResponse, error)

GetCurrentWeather returns current weather for a user's location.

Jump to

Keyboard shortcuts

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